Thread: GDB: how to print

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    53

    GDB: how to print

    Hot to not print fields with specific word filter.
    I mean, have TBigStructureWithSoManyFields *a;
    and now under gdb

    Code:
    p a[0]
    OMG! Only few (but still many) i want see. So i don't want to do
    Code:
    p a->field1
    p a->field2
    p a->field3
    ...

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    53
    Sorry, i don't knowe python at all What means "registering" in gdb. Besides my version of gdb returns
    (gdb) info pretty-printer
    Undefined info command: "pretty-printer". Try "help info".

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That's what mine says too (from Ubuntu 10.10). Section 23.2 of the above manual says you have to give --with-python as an option when you configure gdb. (It also says that's supposed to happen automatically if you have python installed already.) Perhaps the people managing your distro's packages have deliberately set it up without it?

    I'm guessing instead you can try and set up some macros.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You can write a function which prints the information you are interested in to stdout, then call this function from inside the debugger:

    Code:
    void PrintInterestingInfo(TBigStructureWithSoManyFields *x)
    {
        printf("%d\n", x->field0);
        printf("%d\n", x->field1);
        ... etc ...
    }
    Then inside gdb, when you are at a breakpoint or stepping somewhere:

    Code:
    > call PrintInterestingInfo(foo)
    Obviously you probably don't want to include the debugging function in your final build.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. gdb problem in multi-threaded app
    By IfYouSaySo in forum Linux Programming
    Replies: 1
    Last Post: 10-12-2006, 08:22 PM
  3. Too much output in GDB
    By MacNilly in forum Tech Board
    Replies: 0
    Last Post: 09-13-2006, 12:45 PM
  4. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM