Difference between revisions of "GDB"
Jump to navigation
Jump to search
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | [[Category:Software]] | + | [[Category:Software]][[Category:Programming]] |
{|<!--CONFIGURATION: REQUIRED--> | {|<!--CONFIGURATION: REQUIRED--> | ||
|{{#vardefine:app|gdb}} | |{{#vardefine:app|gdb}} | ||
Line 5: | Line 5: | ||
<!--CONFIGURATION: OPTIONAL (|1}} means it's ON)--> | <!--CONFIGURATION: OPTIONAL (|1}} means it's ON)--> | ||
|{{#vardefine:conf|}} <!--CONFIGURATION--> | |{{#vardefine:conf|}} <!--CONFIGURATION--> | ||
− | |{{#vardefine:exe|}} <!--ADDITIONAL INFO--> | + | |{{#vardefine:exe|1}} <!--ADDITIONAL INFO--> |
|{{#vardefine:job|}} <!--JOB SCRIPTS--> | |{{#vardefine:job|}} <!--JOB SCRIPTS--> | ||
|{{#vardefine:policy|}} <!--POLICY--> | |{{#vardefine:policy|}} <!--POLICY--> | ||
Line 31: | Line 31: | ||
Run <code>module spider {{#var:app}}</code> to find out what environment modules are available for this application. | Run <code>module spider {{#var:app}}</code> to find out what environment modules are available for this application. | ||
==System Variables== | ==System Variables== | ||
− | * HPC_{{ | + | * HPC_{{uc:{{#var:app}}}}_DIR - installation directory |
− | * HPC_{{ | + | * HPC_{{uc:{{#var:app}}}}_BIN - executable directory |
<!--Configuration--> | <!--Configuration--> | ||
{{#if: {{#var: conf}}|==Configuration== | {{#if: {{#var: conf}}|==Configuration== | ||
Line 40: | Line 40: | ||
{{#if: {{#var: exe}}|==Additional Information== | {{#if: {{#var: exe}}|==Additional Information== | ||
− | + | ===Pretty Printing=== | |
+ | See https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html#Pretty-Printing for information on pretty printers in GDB. | ||
+ | |||
+ | Pretty printers are provided by the compiler module (i.e. gcc/9.3.0), so you will need to load the GCC module and customize your ~/.gdbinit file: | ||
+ | |||
+ | ====Create or modify ".gdbinit" in your home directory so that it contains the following code to look for and load the compiler module's pretty-print driver:==== | ||
+ | python | ||
+ | import os, sys | ||
+ | gcc_python_dir = os.environ.get('HPC_GCC_PYTHON_DIR') | ||
+ | if gcc_python_dir: | ||
+ | sys.path.insert(0, gcc_python_dir) | ||
+ | from libstdcxx.v6.printers import register_libstdcxx_printers | ||
+ | register_libstdcxx_printers (None) | ||
+ | end | ||
+ | |||
+ | {{note|it is Python, so indentation matters!|warn}} | ||
+ | |||
+ | ====Whenever you load the GDB module, load the appropriate GCC module along with it:==== | ||
+ | module load gdb/9.2 gcc/9.3.0 | ||
+ | |||
+ | Now, when you start GDB, the libstdcxx pretty-printers will be available: | ||
+ | $ gdb -q | ||
+ | |||
+ | (gdb) info pretty-printer | ||
+ | global pretty-printers: | ||
+ | builtin | ||
+ | mpx_bound128 | ||
+ | libstdc++-v6 | ||
+ | __gnu_cxx::_Slist_iterator | ||
+ | __gnu_cxx::__8::_Slist_iterator | ||
+ | ... | ||
+ | ... | ||
|}} | |}} | ||
<!--Job Scripts--> | <!--Job Scripts--> |
Latest revision as of 16:13, 9 January 2023
Description
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:
- Start your program, specifying anything that might affect its behavior.
- Make your program stop on specified conditions.
- Examine what has happened, when your program has stopped.
- Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.
Environment Modules
Run module spider gdb
to find out what environment modules are available for this application.
System Variables
- HPC_GDB_DIR - installation directory
- HPC_GDB_BIN - executable directory
Additional Information
Pretty Printing
See https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html#Pretty-Printing for information on pretty printers in GDB.
Pretty printers are provided by the compiler module (i.e. gcc/9.3.0), so you will need to load the GCC module and customize your ~/.gdbinit file:
Create or modify ".gdbinit" in your home directory so that it contains the following code to look for and load the compiler module's pretty-print driver:
python import os, sys gcc_python_dir = os.environ.get('HPC_GCC_PYTHON_DIR') if gcc_python_dir: sys.path.insert(0, gcc_python_dir) from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (None) end
it is Python, so indentation matters!
Whenever you load the GDB module, load the appropriate GCC module along with it:
module load gdb/9.2 gcc/9.3.0
Now, when you start GDB, the libstdcxx pretty-printers will be available:
$ gdb -q
(gdb) info pretty-printer global pretty-printers: builtin mpx_bound128 libstdc++-v6 __gnu_cxx::_Slist_iterator __gnu_cxx::__8::_Slist_iterator ... ...