Home >Backend Development >C++ >How to Debug C STL Objects with Pretty Printing in Eclipse CDT?

How to Debug C STL Objects with Pretty Printing in Eclipse CDT?

Susan Sarandon
Susan SarandonOriginal
2024-10-30 22:17:29721browse

How to Debug C   STL Objects with Pretty Printing in Eclipse CDT?

How to Enable GDB Pretty Printing for C STL Objects in Eclipse CDT

Introduction

GDB pretty printing makes it easier to debug C programs by displaying STL objects in a human-readable format. This guide provides a step-by-step solution to enable this feature in Eclipse CDT.

Solution

1. Install Python Scripting Support for GDB

Download and install the latest version of GDB with Python scripting support. On Linux, this can be done using the following command:

sudo apt-get install gdb python-gdb

2. Get Python Pretty Printers

Execute the following Git command to download the pretty printers:

svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

3. Edit .gdbinit File

Create a .gdbinit file in your home directory and add the following lines:

python
import sys 
sys.path.insert(0, '/home/YOUR_NAME_HERE/distribs/gdb_printers/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

Replace '/home/YOUR_NAME_HERE/distribs/gdb_printers/python' with the correct path to the python subdirectory in your checkout directory.

4. Using Pretty Printing in Eclipse CDT

  • Open Eclipse and install Eclipse CDT.
  • Configure Eclipse to use GDB and the .gdbinit file:

    • Window -> Preferences -> C/C -> Debug -> GDB
    • Set the GDB command to 'gdb' and choose your .gdbinit file.
    • Enable the "Pretty Printing" option.

Additional Commands for Improved Output

You can enhance GDB's output with these commands:

set print pretty on
set print object on
set print static-members on
set print vtbl on
set print demangle on
set demangle-style gnu-v3
set print sevenbit-strings off

With these settings, you should now be able to debug C programs with improved STL object representation in Eclipse CDT.

The above is the detailed content of How to Debug C STL Objects with Pretty Printing in Eclipse CDT?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn