Qt调试

来源:互联网 发布:淘宝psd素材免费下载 编辑:程序博客网 时间:2024/05/22 15:27

Locals and Expressions

Whenever a program stops under the control of the debugger, it retrieves information about the topmost stack frame and displays it in the Locals and Expressions view. The Locals and Expressions view typically includes information about parameters of the function in that frame as well as the local variables.

"Locals and Expressions view"

Compound variables of struct or class type are displayed as expandable in the view. Expand entries to show all members. Together with the display of value and type, you can examine and traverse the low-level layout of object data.

Note:GDB, and therefore Qt Creator's debugger works for optimized builds on Linux and Mac OS X. Optimization can lead to re-ordering of instructions or removal of some local variables, causing the Locals and Expressionsview to show unexpected data.The debug information provided by GCC does not include enough information about the time when a variable is initialized. Therefore, Qt Creator can not tell whether the contents of a local variable contains "real data", or "initial noise". If a QObject appears uninitialized, its value is reported as not in scope. Not all uninitialized objects, however, can be recognized as such.

The Locals and Expressions view also provides access to the most powerful feature of the debugger: comprehensive display of data belonging to Qt's basic objects.

To enable Qt's basic objects data display feature:

  • Select Tools > Options > Debugger > Debugging Helper and check the Use Debugging Helper checkbox.
  • The Locals and Expressions view is reorganized to provide a high-level view of the objects.

For example, in case of QObject, instead of displaying a pointer to some private data structure, you see a list of children, signals and slots.

Similarly, instead of displaying many pointers and integers, Qt Creator's debugger displays the contents of a QHash or QMap in an orderly manner. Also, the debugger displays access data for QFileInfo and provides access to the "real" contents of QVariant.

You can use the Locals and Expressions view to change the contents of variables of simple data types, for example, int or float when the program is interrupted. To do so, click the Value column, modify the value with the inplace editor, and press Enter (or Return).

You can enable tooltips in the main editor displaying this information. For more information, see Showing Tooltips in Debug Mode.

Note: The set of evaluated expressions is saved in your session.

Directly Interacting with Native Debuggers

In some cases, it is convenient to directly interact with the command line of the native debugger. In Qt Creator, you can use the left pane of the Debugger Log view for that purpose. When you press Ctrl+Return, the contents of the line under the text cursor are sent directly to the native debugger. Alternatively, you can use the line edit at the bottom of the view. Output is displayed in the right pane of the Debugger Log view.

Note: Usually, you do not need this feature, because Qt Creator provides you with better ways to handle the task. For example, instead of using the GDB print command from the command line, you can evaluate an expression in the Locals and Expressions view.

Debugging C++ Based Applications

The following sections describe additional debugging functions that apply only to debugging C++.

Starting the Debugger from the Command Line

You can use the Qt Creator debugger interface from the command line. To attach it to a running process, specify the process ID as a parameter for the -debug option. To examine a core file, specify the file name. Qt Creator executes all the necessary steps, such as searching for the binary that belongs to a core file.

For example:

  • C:\qtcreator\bin>qtcreator -debug 2000
  • C:\qtcreator\bin>qtcreator -debug core.2000

For more information, see Using Command Line Options.

Stepping into Frameworks in Mac OS

In Mac OS X, external libraries are usually built into so-called Frameworks, which may contain both release and debug versions of the library. When you run applications on the Mac OS desktop, the release version of Frameworks is used by default. To step into Frameworks, select the Use debug versions of Frameworks option in the project run settings for Desktop and Qt Simulator targets.

Viewing Threads

If a multi-threaded program is interrupted, the Thread view or the combobox named Thread in the debugger's status bar can be used to switch from one thread to another. The Stack view adjusts itself accordingly.

Viewing Modules

The Modules view displays information that the debugger plugin has about modules included in the application that is being debugged. A module is a dynamic link library (.dll) in Windows, a shared object (.so) in Linux, and a dynamic shared library (.dylib) in Mac OS.

In addition, the view displays symbols within the modules and indicates where each module was loaded.

Right-click the view to open a context menu that contains menu items for:

  • Updating the module list
  • Loading symbols for modules
  • Examining modules
  • Editing module files
  • Showing symbols in modules
  • Showing dependencies between modules (Windows only)

By default, the Modules view is hidden.

Viewing Source Files

The Source Files view lists all the source files included in the project. If you cannot step into an instruction, you can check whether the source file is actually part of the project, or whether it was compiled elsewhere. The view shows the path to each file in the file system.

Right-click the view to open a context menu that contains menu items for reloading data and opening files.

By default, the Source Files view is hidden.

Viewing Disassembled Code and Register State

The Disassembler view displays disassembled code for the current function. The Registers view displays the current state of the CPU's registers.

The Disassembler view and the Registers view are both useful for low-level commands for checking single instructions, such as Step Into and Step Over. By default, both Disassembler and Registers view are hidden.

原创粉丝点击