Home > Backend Development > C++ > body text

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

DDD
Release: 2024-10-30 02:52:29
Original
783 people have browsed it

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

Enabling GDB Pretty Printing for C STL Objects in Eclipse CDT

Debugging C programs with STL objects can be challenging when the default GDB output is not readily interpretable. Enabling pretty printing addresses this issue by providing a more user-friendly representation of STL data structures.

Prerequisites

  • Install the latest version of GDB with Python scripting support.
  • Obtain the Python pretty printers by checking out the "libstdcxx-v3/python" directory from the GCC SVN repository.

Setting Up Pretty Printing

  1. Configure GDBinit File: Create a .gdbinit file in your project directory and add the following content:

    <code class="python">import sys
    sys.path.insert(0, '/home/<path_to_pretty_printers>')
    from libstdcxx.v6.printers import register_libstdcxx_printers
    register_libstdcxx_printers(None)</code>
    Copy after login
  2. Enable Pretty Printing in Eclipse CDT: In Eclipse, navigate to Window -> Preferences -> C/C -> Debug -> GDB.

    • Set the path to GDB and .gdbinit file.
    • Enable the "Pretty Printing" option.
  3. Additional GDB Commands: For further customization, execute these commands in GDB:

    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
    Copy after login

Additional Tips

  • For older projects, ensure that the source code is compiled with at least GCC 4.9 or later to support the required Python module.
  • If you encounter the Python module import error, make sure the module path in your gdbinit file is correct and the module is installed in the specified location.

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template