Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this possible to let GDB recognise preprocessor symbols?

Tags:

c

gdb

I have lots and lots of C preprocessor #define statements, which make my C programming much easier. However, when debugging with GDB, the preprocessor "labels" are not accounted for in the symbols list.

Is there are way to have GDB recognise the #defined labels?

like image 737
Randomblue Avatar asked Mar 20 '12 14:03

Randomblue


People also ask

How does GDB find symbols?

Normally, when GDB looks up symbols, it matches their names with case sensitivity determined by the current source language. Occasionally, you may wish to control that. The command set case-sensitive lets you do that by specifying on for case-sensitive matches or off for case-insensitive ones.

What are debugging symbols in GDB?

A debugging symbol table is information included in the binary file that maps the compiled instructions to the corresponding line, function, and/or variable in the original source code. This is not something you would want to do with your final builds of any code, as it makes the final executable larger and slower.

What is a symbol table GDB?

A Debugging Symbol Table maps instructions in the compiled binary program to their corresponding variable, function, or line in the source code. This mapping could be something like: Program instruction ⇒ item name, item type, original file, line number defined.

What is debug symbols in C?

A debug symbol is a special kind of symbol that attaches additional information to the symbol table of an object file, such as a shared library or an executable.


2 Answers

You can try compiling with g3, as described here.

gcc -gdwarf-2 -g3

We pass the -gdwarf-2 and -g3 flags to ensure the compiler includes information about preprocessor macros in the debugging information.

Or you can try -ggdb.

like image 65
cnicutar Avatar answered Sep 19 '22 17:09

cnicutar


#define symbols are not usually included as part of the debug information. const variables (or inline functions for function-like macros) are usually a better idea, and for more reasons than this (e.g., scoping, type safety, multiple evaluations, etc.). I recommend using them in favor of preprocessor symbols whenever you can.

like image 26
Fred Larson Avatar answered Sep 19 '22 17:09

Fred Larson