Main debuggers for Windows:

  • CDB, which can only debug user programs, has a console interface, and works in command line form
  • NTSD, can only debug user programs, only console interface, work in command line form
  • KD, mainly used for kernel debugging, but sometimes also for user-mode debugging, has a console interface and works on the command line
  • WinDbg, in user mode, kernel mode can play debugging function, using a visual user interface

The Qt Creator debugger can be GDB or CDB, and this article only covers CDB.

 

First, install CDB

The Command Line Debugger (CDB) is used for debugging code on the console. CDB is the younger brother of WinDbg. Since the debugger used by MSVC is C:\Windows\System32\ vsjitDebugger.exe, there is no CDB for installing Visual Studio. You must install Debugging Tools for Windows from the WDK.

Developer.microsoft.com/en-us/windo…

Docs.microsoft.com/zh-cn/windo…

After installation, cdb.exe and gdb.exe can be found in C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x86.

 

Qt. IO /Qt_Creator_…

1. The 32-bit version of cdb.exe can only debug 32-bit executable files. The 64-bit version can debug both 64-bit and 32-bit executables, but interrupting the 32-bit executable using the 64-bit debugger may result in a stack trace of the Wow64 32-bit emulation layer being displayed.

Qt Creator extends the command line debugger by loading the extension library (qtCreatorcdbext.dll). This library must be provided for the 32-bit and 64-bit versions of the debugger in the folder libs \ qTCreatorCDBext64 or libs \ qTCreatorCDBext32.

D: \ Qt \ Qt5.9.8 \ Tools \ QtCreator \ lib \ qtcreatorcdbext32 \ qtcreatorcdbext DLL

D: \ Qt \ Qt5.9.8 \ Tools \ QtCreator \ lib \ qtcreatorcdbext64 \ qtcreatorcdbext DLL

3. The first time you start debugging, you are prompted to set up the Symbol server, which adds a special entry to the debugger’s Symbol path. Symbol Server provides debugging information for the operating system and compiler runtime libraries. The initial download can be time-consuming.

Docs.microsoft.com/zh-cn/windo…

Docs.microsoft.com/en-us/windo…

Outdated.pDB files can slow down debugging. A clean build can help. In addition, incremental linking may affect debugging (check “checksum of module cannot be verified…” in log) ). You can add the disable delta link in the. Pro project file by adding:

QMAKE_LFLAGS_DEBUG += /INCREMENTAL:NO
Copy the code

 

What are symbols? What is it for?

Symbols is used for data of program debugging. It contains various data needed in debugging, such as global variable, local variable, function name, function type, source code line and program entry address….. All of these things are called Symbol Files. On Windows, Windows 2000 keeps this information in.pdb and.dbg files, whereas Windows XP and later versions keep this information in.pdb files. Symbol is a Symbol that allows both Public and Private data. When we release products, we can release Symbol data at the same time, and we can also check and control the granularity of Symbol data release (PDBCopy and Symchk will be introduced below). In NET, we can also see Symbols generated by VS, and in the directory of DLLS generated by VS, we can also see another class of files besides DLLS. PDB (as shown in the figure below), VS can provide us with so much debugging ability because of it.

Program Database (PDB) is a file format developed by Microsoft for storing Program debugging information. PDB files are generated by source code at compile time and store the source file name, variable name, function name, FPO (frame pointer), corresponding line number, etc. Exe or DLL files are unsigned due to their large size and security.

In plain English, symbol files help you debug programs by tracing the compiler’s libraries and the operating system’s own code. Debug symbols are the symbols inside the code; Debug symbol database, which records the relationship between symbols such as variables and functions and memory location, so that variable names and function names can be traced with address related information; Convenient debugging. In summary, symbol files contain a lot of data that is not really needed when running binaries, but is useful when debugging code.

 

4. Configure CDB in QtCreator

Doc. Qt. IO/qtCreator /c

  • Open theTools >Options > DebuggerCDB Paths
  • In the Symbol Paths panel, selectInsert
  • Select the directory where you want to store the cached information. Use a subfolder in a temporary directory, such as 
  • The SRV * D: \ Qt \ symbolcache * msdl.microsoft.com/download/sy…
  • Select OK.

The SRV * D: \ Qt \ symbolcache * msdl.microsoft.com/download/sy…

Specify the symbols that are used for the symbol resolution path for the local path D: \ Qt \ symbolcache, but if they don’t go to http://msdl.microsoft.com/download/symbols to download. So the first time you debug breakpoints, it takes a long time to download, and after the second time it doesn’t. The downloaded folder looks like this:

2, How to download all Symbol Files at one time (not recommended) usually we just view Ntdll function, or view Service Descriptor Table, Then CDB will only download ntDLL. PDB and ntkrNLmp. PDB or win32k.pdb to :\< user path >\Symbol. But what about the others, in case you need them one day and Microsoft stops supporting them? Download them all at once to :\< user path >\Symbol. To start the DOS Command Line (cmd.exe), jump into the CDB installation directory and type in DOS

CD C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x86

Symchk. Exe/r C: \ Windows \ system32 / s the SRV * D: \ Qt \ Symbols * msdl.microsoft.com/download/sy…

Find all symbol files in C:\ Windows \ System32 folder and all subfolders and download D:\Qt\Symbols from Microsoft official website.

The whole process may take more than N hours, because there are too many dynamic libraries under Win32, I feel that there is no need to download all of them. Qt Creator->Tools->Options->Debugger->CDB Paths->Symbol Paths

Add D:\Qt\Symbols to the symbol path so that Symbols needed for debugging are searched locally and no longer linked to the symbol server.

 

Personal skills and suggestions

If the compiler uses MSVC 32bit, CDB debugging can be done in 64bit. No test. Wait for observation.

2, CDB breakpoint debugging, solve the problem of unable to view the QString value. Open Tools -> Options -> Debugger ->CDB, deselect “Use Python Dumper” and save it.

Qt Creator- Tools- Options- Debugger- Debugger- CDB Paths- Symbol Paths- Clear Symbol Paths. The disadvantage is that when the symbol server is turned off, it cannot be traced when debugging into the system runtime.

4. Symbol files downloaded before are stored in D:\Qt\Symbols. Note that these files are not universal. Different operating systems (large systems have WinXP/Win7/Win10, while large systems have many smaller versions) have different PDB files, so different systems are required to download their own symbol files. In addition, when the operating system is updated or upgraded, it is likely that the previous symbol files will become obsolete.

VS debug symbol file (.pdb) Settings

Set the values of the add system environment variables _NT_SYMBOL_PATH and _NT_ALT_SYMBOL_PATH to:

_NT_SYMBOL_PATH=C:\Symbols; srv*C:\Symbols*http://msdl.microsoft.com/download/symbols _NT_ALT_SYMBOL_PATH=cache*C:\SymbolsCopy the code

When VS is started, it will automatically look for this variable, and then download the corresponding symbol file from the corresponding URL. Finally, the downloaded symbol file is saved under C:/Symbols. This path must be C:/Symbols. Of course, you can change the path as required, using the mklink command. Open CMD with administrator privileges (Windows Start menu – All Programs – Attachments – Command prompt – right click, run as administrator) and type the command:

mklink /D C:\Symbols E:\software\Qt\symbolcache
Copy the code

 

Welcome to the sister section

Introduction to Windbg/ X64DBg /OllyDbg debugger for Windows platform and summary of symbol file *.pDB

“VC++ memory leak detection method (5) : using the powerful Windbg tool”

 

References:

[Windbg Basics]- Understand Symbols

Blog.csdn.net/kelsel/arti…

Qtcreator + VS2008 +CDB debugging too card problem research

Blog.csdn.net/superzhaifd…

Microsoft Symbols server download symbols summary

Blog.csdn.net/fishmai/art…

Debug Qt code using CDB

Blog.csdn.net/ubiter/arti…