Lecture
Normally, the interaction between Qt Creator and the debugger is configured automatically and no action is required from you. However, you may have an unsupported version of gdb installed, your Linux environment may not contain gdb at all, or you may want to use Debugging Tools for Windows.
Note: To use the Debugging Tools for Windows, you must install them and add the Symbol Server provided by Microsoft to the debugger symbol search path. For more information, see Configuring Symbol Server in Windows.
This section describes features for debugging C ++ code and provides notes on installing supported debuggers.
The debugger plugin supports various gdb debugger builds, with or without the use of Python scripts. Versions with Python support are preferred, but they are not available for Mac and older versions of Linux. On Windows, Symbian and Maemo, only the version with Python is supported.
Non-Python versions use compiled debugging helpers that you should include separately. For more information, see Debugger Assistants in C ++.
The version with Python support uses the version of debugging helpers written in scripts, so you do not need additional configuration.
The CDB debugger has similar functionality to the gdb debugger without Python support. It uses C ++ code for the debugging helpers library.
The following table describes the supported debuggers for C ++ code:
Platform | Compiler | Debugger | Python | Debugger Modes |
Linux | gcc | gdb | Not necessary | Terminal, Simple, Connected (only with Python), Remote |
Unix | gcc | gdb | Yes | Terminal, Simple, Connected, Remote |
Mac os | gcc | gdb | Not | Terminal, Simple, Connected |
Windows / MinGW | gcc | gdb | Not | Terminal, Simple, Connected, Remote |
Windows / MSVC | Microsoft Visual C ++ Compiler | Debugging Tools for Windows / CDB | Not applicable | Terminal, Simple, Connected, Post-Mortem |
Symbian | gcc | gdb | Yes | TRK |
Maemo | gcc | gdb | Yes | Remote |
There are several different reasons why a debugger plug-in will not automatically select a suitable debugger. The debugger may be missing (which most often happens from CDB to Windows, which is always required to be installed manually by the user) or the installed version may not be supported. For a list of supported versions and other important important information about debugger installation, see the table below.
Debugger | Remarks |
Gdb | On Linux, install version 6.8, 7.0.1 (version 7.0 is not supported), 7.1 or later. On Mac OS X, install Apple gdb version 6.3.50-20050815 (build 1344) or later. |
Debugging Tools for Windows | Using this debugger requires installing the 32-bit or 64-bit Debugging Tools for Windows (version 6.11.1.404 for 32-bit or 64-bit versions of Qt Creator, respectively), which is available for free download from the Microsoft Developer Network. Note: Visual Studio does not include the required Debugging Tools, and therefore you must install them separately. The compiled version of the Qt SDK for Windows will use this library if it is present in the system. When manually building Qt Creator using the Microsoft Visual C ++ compiler, the build process looks for the required files in "% ProgramFiles% \ Debugging Tools for Windows". It is strongly recommended that you add the Symbol Server provided by Microsoft to the debugger symbol search path. Symbol Server provides you with debugging information for operating system libraries when debugging Windows applications. For more information, see Configuring Symbol Server in Windows. |
Debugging Tools for Mac OS X | Qt binary distribution contains debug and release versions of libraries. But if you directly specify the linker that you want to use debug libraries even if your application is compiled as debug and release, the debug library will be used by the default library. If you use qmake-based projects in Qt Creator, you can set a flag in your launch configuration in the Projects mode. In the launch configuration, select Use debug version of frameworks . For more information about debugging on Mac, see: http: //developer.apple.com/mac/library/technotes/tn2004/tn2124.html Note: On Mac OS X, Snow Leopard (10.6) has an error that you can work around using the method described here: http: //bugreports.qt.nokia.com/browse/QTBUG-4962. |
Add the Microsoft-provided Symbol Server to the debugger symbol search path to get debug information for operating system libraries when debugging Windows applications.
Use a subdirectory in the temporary directory, for example, C: \ temp \ symbolcache.
Note: Filling the cache can take a lot of time on slow connections.
Note: When debugging with Debugging tools for Windows for the first time, Qt Creator will ask you to add Symbol Server.
Qt Creator can display complex structures in a special way that can be modified by the user. To do this, it uses two technologies, called Debugging Helpers .
Using debugging helpers is not necessary for debugging with Qt Creator, but they greatly help the user to quickly view complex data types.
This is the first approach to display complex data types. Although it has been replaced on most platforms by a simpler and more flexible second approach using Python scripts, it is the only possible approach for Windows / MSVC, Mac OS, and older Linux distributions. Moreover, this approach will be automatically selected as a fallback if the approach based on Python scripts does not work.
When debugging with debugging helpers in C ++, Qt Creator dynamically loads the helper library as a DLL or shared object into the process being debugged. The Qt SDK already contains a pre-compiled debugging helper library. To create your own debugging helper library, select Tools > Options ... > Qt4 > Qt Profiles . Since Qt's internal data structures may vary for different versions, the debugging helper library is compiled for each version of Qt.
On platforms with a Python-capable version of the gdb debugger, data is retrieved using a Python script. This is more reliable since script execution is separate from the debugging process. This method is also easier to extend, since the script is weakly dependent on the current version of Qt and does not require compilation.
To extend the supplied Python debugging helpers to support custom types, define one Python function for each user type in the gdb boot file. By default, the following boot file is used: ~ / .gdbinit. To use another file, select Tools> Options ...> Debugger> Gdb and specify the file name in the Gdb Startup Script field.
The name of the function should be qdump__NS__Foo where NS :: Foo is a class or class template for viewing. You can use nested namespaces.
The debugger plugin calls this function to display an object of this type. The following parameters are passed to this function:
The function should fill the Dumper object with certain information that will be used to build the Variable type of this object and its descendants.
Example:
def qdump__QVector (d, item):
d_ptr = item.value ["d"]
p_ptr = item.value ["p"]
alloc = d_ptr ["alloc"]
size = d_ptr ["size"]
check (0 <= size and size <= alloc and alloc <= 1000 * 1000 * 1000)
check (d_ptr ["ref"] ["_ q_value"]> 0)
innerType = item.value.type.template_argument (0)
d.putItemCount (size)
d.putNumChild (size)
if d.isExpanded (item):
p = gdb.Value (p_ptr ["array"]). cast (innerType.pointer ())
with Children (d, [size, 2000], innerType)
for i in d.childRange ():
d.putItem (Item (p.dereference (), item.iname, i))
The Python Item class is a small wrapper around values corresponding to one line of the form Variables . The Item class has the following members:
For each line in the Variables view, a line of the following content must be created and connected to the debug plug-in.
"{iname = 'some internal name',
addr = 'address of an object in memory',
name = 'Name column',
value = 'the contents of the column Value',
type = 'Type column contents',
numchild = 'number of descendants', // it is enough to specify zero / non zero
childtype = 'type of child by default', // not necessary
childnumchild = 'default number of grandchildren', // not necessary
children = [// required only if the item is expanded as
{iname = 'internal name of the first child',
...},
{iname = 'internal name of the second child',
...},
...
]} "
Although, in principle, you can assemble the entire line above manually, it is much easier to use the Python Dumper class for this purpose. The Python Dumper class contains a full framework for processing iname and addr fields, for processing descendants of simple types, references, pointers, enumerations, known and unknown structures, as well as some auxiliary methods for handling common situations.
The Dumper class has the following members:
self.beginHash ()
self.putName (name)
self.putValue (value)
self.putType ("int")
self.putNumChild (0)
self.endHash ()
self.beginHash ()
self.putName (name)
self.putValue (value)
self.putType ("bool")
self.putNumChild (0)
self.endHash ()
with SubItem (self):
self.putItemHelper (item)
The exceptions that appear in subsequent calls to functions are caught, and the entire output of putItemHelper is replaced with the output:
...
except RuntimeError:
d.put ('value = "<invalid>", type = "<unknown>", numchild = "0",')
Attempting to create child elements may lead to errors if the data is not initialized or damaged. For successful recovery in such situations, use Children and SubItem to create nested items.
The Children __init __ constructor (self, dumper, numChild = 1, childType = None, childNumChild = None) takes one mandatory and three optional arguments. A required argument refers to the current Dumper object. Optional arguments can be used to specify the number of descendants of numChild with the type childType_ and the number of grandchildren childNumChild_ each. If numChild_ is a list of two integers, then the first one will indicate the current number of descendants, and the second - the maximum number of descendants for output.
Similarly, using the SubItem class helps protect individual items.
Example:
d.putNumChild (2)
if d.isExpanded (item):
with Children (d):
with SubItem (d):
d.putName ("key")
d.putItemHelper (Item (key, item.iname, "key"))
with SubItem (d):
d.putName ("value")
d.putItemHelper (Item (value, item.iname, "value"))
Comments
To leave a comment
Cross platform programming
Terms: Cross platform programming