You get a bonus - 1 coin for daily activity. Now you have 1 coin

Debugger Setup. For Qt Environment

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.

Supported Debugger Versions

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

Install debuggers

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.

Configure Symbol Server on Windows

Add the Microsoft-provided Symbol Server to the debugger symbol search path to get debug information for operating system libraries when debugging Windows applications.

  1. Select Tools > Options ... > Debugger > Cdb .
  2. In the Character paths field, click the Insert menu ... and select Character Server ....
  3. Select the directory where you want to store the cached information and click OK .

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.

Using debugging helpers

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.

C ++ Debugger Assistants

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.

Python Debugging Helpers

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:

  • d-type dumper
  • Item type Item

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))

Item class

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:

  • __init __ (self, value, parentiname, iname, name = None) - Constructor. The internal name of the object is created by combining parentiname and iname. If None is passed as an argument to name, the serial number is used.
  • value is an object of type gdb.Value representing the display value.
  • iname is the internal name of the object, consisting of a list of identifiers separated by dots corresponding to the position of the object being represented as.
  • name - Additional name. If it is set, it will be used in the View Name column. If not specified, a simple number in brackets will be used instead.

Dumper class

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:

  • __init __ (self) - Initializes the output with an empty string and clears the stack of children.
  • put (self, value) is a low-level method for directly adding to the output string.
  • putCommaIfNeeded (self) - adds a comma if the current output ends with '}', '"' or ']'.
  • putField (self, name, value) - adds, if necessary, a comma and the name = 'value' field.
  • beginItem (self, name) - Begins the field with the entry name = '.
  • endItem (self) - Ends field entry with '.
  • endChildren (self) - Ends record of the list of descendants.
  • childRange (self) - Returns the number of children specified in the current Children space.
  • putItemCount (self, count) - Adds the value = '<% d items' field to the output.
  • putEllipsis (self) - Adds the field '{name = "<incomplete>", value = "", type = "", numchild = "0"}'. This is automatically done by endChildren if the number of descendants for output is less than the current number of descendants.
  • putName (self, name) - Adds a field name = '...'.
  • putType (self, type) - Adds a field type = '...' if type does not match the type of the descendant of the parent by default.
  • putNumChild (self, numchild) - Adds the numchild = '...' field if numchild does not match the value of the descendant of the parent numchild by default.
  • putValue (self, value, encoding = None) - Adds a field value = '...' with an optional field valueencoding = '...'. The value value must be convertible to a string consisting entirely of numeric and alphabetic values. The encoding parameter can be used to specify the encoding method in case the present value should be encoded in some way to fulfill the requirement of containing only numeric and alphabetic values. The following encoding methods are currently supported:
    • 0: unencrypted 8-bit data interpreted as Latin1.
    • 1: Base64-encrypted 8-bit data used for QByteArray will add double quotes.
    • 2: Base64-encrypted 16-bit data used for a QString will be added with double quotes.
    • 3: 32-bit data encrypted with base64, double quotes will be added.
    • 4: base64-encrypted 16-bit data, without quotes (see 2).
    • 5: Base64-encrypted 8-bit data, without quotes (see 1).
    • 6: 8-bit data encrypted as% 02x (as with QByteArray :: toHex), double quotes will be added.
    • 7: 16-bit data encrypted as% 04x (as with QByteArray :: toHex), double quotes will be added.
  • putStringValue (self, value) - Encodes a QString and calls putValue with the appropriate encoding method.
  • putByteArrayValue (self, value) - Encodes QByteArray and calls putValue with the appropriate encoding method encoding.
  • isExpanded (self, item) - Checks if an item with the internal name item.iname is expanded as.
  • isExpandedIName (self, iname) - Checks whether the element with the internal name iname is expanded in the form.
  • putIntItem (self, name, value) - Equivalent to:

self.beginHash ()

self.putName (name)

self.putValue (value)

self.putType ("int")

self.putNumChild (0)

self.endHash ()

  • putBoolItem (self, name, value) - Equivalent to:

self.beginHash ()

self.putName (name)

self.putValue (value)

self.putType ("bool")

self.putNumChild (0)

self.endHash ()

  • pushOutput (self) - Moves the output line to a safe place from where it will be sent to the plug-in debugger even if further operations cause an exception.
  • putCallItem (self, name, item, func) - Uses gdb to call the func function for the value specified in item.value , and displays the result. This feature is not available when debugging core dumps and is not available for the Symbian platform due to limitations imposed by AppTRK.
  • putItemHelper (self, item) is the "Main function", which immediately processes the basic types, references, pointers and enumerations, passes through all descendants and members of the classes of composite types, and calls the appropriate functions qdump __ *.
  • putItem (self, item) - Equivalent to:

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",')

Class of descendants and subitems

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"))

created: 2016-01-17
updated: 2024-11-12
343



Rating 9 of 10. count vote: 2
Are you satisfied?:



Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Cross platform programming

Terms: Cross platform programming