gdb debugger

A

a

In .C or .h file we have #define some constant.
While using the gdb debugger, how to show the value of these constant?
Thanx
 
K

Keith Thompson

a said:
In .C or .h file we have #define some constant.
While using the gdb debugger, how to show the value of these constant?

We don't know; that's not a C question. gdb comes with extensive
documentation. If that doesn't help, you might try the gnu.utils.help
newsgroup.
 
F

Flash Gordon

a said:
In .C or .h file we have #define some constant.
While using the gdb debugger, how to show the value of these constant?
Thanx

This is a question about a specific tool chain, not the C language
itself. You should therefore ask in a group or mailing list dealing with
your tool chain. You should also read the manuals for the compiler and
debugger.

<OT>
Some compilers have an option to provide this information to the
debugger and some versions of gdb can use the information. However, not
all versions and not all compilers.
</OT>
 
A

Anonymous 7843

In .C or .h file we have #define some constant.
While using the gdb debugger, how to show the value of these constant?
Thanx

That's off-topic (as others have pointed out) but I would
do something like this:

(gdb) shell grep NAME *.c *.h
 
J

John Bode

Keith said:
We don't know; that's not a C question. gdb comes with extensive
documentation. If that doesn't help, you might try the gnu.utils.help
newsgroup.

Actually, I'll argue that it is topical, in that it touches on what
happens to preprocessor macros when code is compiled.

To the OP: remember that preprocessor macros are simply text
substitutions to make your life as the coder a little easier; during
preprocessing, they are expanded into the replacement text, and that
replacement text is what's fed to the compiler.

For example, take the following code fragment:

#define SIZE 10

void foo(void)
{
int arr[SIZE];
...
}

After the preprocessing stage, all occurrences of SIZE are replaced by
the text "10", as below:

void foo(void)
{
int arr[10];
...
}

This is the text that is actually fed to the compiler; the preprocessor
symbol SIZE no longer exists. Therefore, I would not expect it to be
accessible from a debugger.

Now, specific compilers may allow you to preserve that information for
debugging purposes, but that's beyond the scope of the C language.
FWIW, my experience with gdb leads me to say "you can't do that."
 
F

Flash Gordon

John Bode wrote:

This is the text that is actually fed to the compiler; the preprocessor
symbol SIZE no longer exists. Therefore, I would not expect it to be
accessible from a debugger.

Now, specific compilers may allow you to preserve that information for
debugging purposes, but that's beyond the scope of the C language.
FWIW, my experience with gdb leads me to say "you can't do that."

Which is exactly why the OP should ask the question where it is topical
so that those who know how and on which versions it is or is not
possible. Since with the right combination of versions of gdb, compiler
and switches it *is* possible.
 
R

revival

a said:
In .C or .h file we have #define some constant.
While using the gdb debugger, how to show the value of these constant?
Thanx
You should be asking in the gcc mailing lists as mentioned.
<OT>
If you see the gdb manual ,using the flags "-gdwarf2 -g3" while
compiling the sources using gcc should make you see #define
constants.Ofcourse you need to use specific gdb commands to see the
macros and macro expansions.
</OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top