Sunday, August 24, 2014

Qt Creator (GDB) No Watch Variables With GCC 4.8

The next set of changes are rather complicated and required debugging.  Upon reaching the first breakpoint, no variables were displayed in the Locals and Expressions debugging window in Qt Creator.  After a little research, the problem was determined to be with GCC 4.8.1, which is using a new format (named DWARF-4) to write debugging symbols to the executable.

The problem is that GDB (debugger) does not support this newer format, at least older versions prior to GDB 7.5.  Mint 13 (Ubuntu 12.04) has only version 7.4.  This problem does not affect Windows with the programs installed as recently described (see the Windows tagged posts).  The latest MSYS with MinGW has GDB 7.6.1 and MinGW-w64 has GDB 7.7.  Mint 17 (Ubuntu 14.04) is also fine with GDB 7.7.

There are two ways to solve this problem.  The GCC compiler has an option for generating the older DWARF-3 format debugging symbols.  Instead of permanently adding this option to the CMake build file, the following option can be added to the CMake command line or in Arguments field in the Run CMake wizard within Qt Creator:
-DCMAKE_CXX_FLAGS_DEBUG='-g -gdwarf-3'
The other solution is to build and install GDB from source code.  Click Continue... for details on the procedure for this.

The source code for the latest GDB debugger source can be found on GNU's FTP site.  The latest version at this moment is 7.8.0.  Once downloaded, change to the directory with the downloaded file and execute the following commands (adjust accordingly for the version downloaded):
tar xvaf ../Downloads/gdb-7.8.tar.xz
cd gdb-7.8
./configure
make -j4        (adjust 4 for the number cores for a faster building)
sudo make install
This will install GDB into the /usr/local/bin directory by default.  The system GDB is at /usr/bin.  My system is setup so that the /usr/local/bin directory is before the /usr/bin directory in the PATH environment variable, so the new version will be found first.  (Reconfiguring the PATH environment variable is beyond the scope of this post.)

To install GDB to a different path (for example, off your home directory like in ~/bin), use the --prefix=<PATH> option on the ./configure command line for the desired directory.  This directory has to be before the /usr/bin directory in the PATH environment variable so that the new version will be found before the system version.  Alternatively, the prefix could be set to /usr/bin to overwrite the system versions, but this is not something I recommend.

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)