Dijo John
Dijo John

Reputation: 55

gdb 'info types' not printing C structure

I wanted to use gdb's info types to understand how a structure looks.

Saw the following behavior:
If the struct is defined as :

typedef struct {
...
...
} XX;

the info types command displays the structure format.

But if it's not typedef-ed, info types just tells that it's a struct. Gives no details of it's members.

Is this the expected behavior? Am I overlooking something? Anyway to make the structure visible via info types? (w/o changing code).

Upvotes: 3

Views: 654

Answers (1)

ks1322
ks1322

Reputation: 35785

You can use ptype, see builtin help:

(gdb) help ptype 
Print definition of type TYPE.
Usage: ptype[/FLAGS] TYPE | EXPRESSION
Argument may be any type (for example a type name defined by typedef,
or "struct STRUCT-TAG" or "class CLASS-NAME" or "union UNION-TAG"
or "enum ENUM-TAG") or an expression.
The selected stack frame's lexical context is used to look up the name.
Contrary to "whatis", "ptype" always unrolls any typedefs.

Available FLAGS are:
  /r    print in "raw" form; do not substitute typedefs
  /m    do not print methods defined in a class
  /M    print methods defined in a class
  /t    do not print typedefs defined in a class
  /T    print typedefs defined in a class
(gdb) 

Here is an example for redisContext:

(gdb) ptype redisContext
type = struct redisContext {
    int err;
    char errstr[128];
    int fd;
    int flags;
    char *obuf;
    redisReader *reader;
    enum redisConnectionType connection_type;
    struct timeval *timeout;
    struct {
        char *host;
        char *source_addr;
        int port;
    } tcp;
    struct {
        char *path;
    } unix_sock;
}
(gdb) 

Upvotes: 2

Related Questions