gdb debugger

Discussion in 'C Programming' started by a, Oct 2, 2005.

  1. a

    a Guest

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

  2. "a" <> writes:
    > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 2, 2005
    #2
    1. Advertising

  3. a wrote on 02/10/05 :
    > In .C or .h file we have #define some constant.
    > While using the gdb debugger, how to show the value of these constant?


    You don't (macros are just text replacements). If the constant value is
    an int, use an enum.

    --
    Emmanuel
    The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
    The C-library: http://www.dinkumware.com/refxc.html

    "Mal nommer les choses c'est ajouter du malheur au
    monde." -- Albert Camus.
     
    Emmanuel Delahaye, Oct 2, 2005
    #3
  4. a

    Flash Gordon Guest

    a wrote:
    > 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>
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Oct 2, 2005
    #4
  5. In article <OUL%e.38606$1i.37904@pd7tw2no>, a <> wrote:
    >
    > 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
     
    Anonymous 7843, Oct 3, 2005
    #5
  6. a

    John Bode Guest

    Keith Thompson wrote:
    > "a" <> writes:
    > > 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.
    >


    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."
     
    John Bode, Oct 3, 2005
    #6
  7. a

    Flash Gordon Guest

    John Bode wrote:

    <snip question on making #defines available in gdb>

    > 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.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Oct 4, 2005
    #7
  8. a

    revival Guest

    a wrote:
    > 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>
     
    revival, Oct 13, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Surendra
    Replies:
    0
    Views:
    512
    Surendra
    Mar 23, 2006
  2. seba
    Replies:
    1
    Views:
    1,449
    mlimber
    Mar 22, 2007
  3. mohi

    GDB debugger problem

    mohi, Apr 1, 2008, in forum: C++
    Replies:
    4
    Views:
    306
    James Kanze
    Apr 2, 2008
  4. Timothy Madden
    Replies:
    1
    Views:
    1,638
    Timothy Madden
    Sep 17, 2009
  5. console kid

    GDB debugger problem

    console kid, Aug 15, 2010, in forum: C++
    Replies:
    1
    Views:
    298
    Jorgen Grahn
    Aug 15, 2010
Loading...

Share This Page