gdb&x27;信息类型';不打印C结构
我想使用gdb的gdb&x27;信息类型';不打印C结构,c,gdb,C,Gdb,我想使用gdb的信息类型来理解结构的外观 看到以下行为: 如果结构定义为: typedef struct { ... ... } XX; info-types命令显示结构格式 但是如果它没有类型定义,info-types只是告诉它是一个结构。 未提供其成员的详细信息 这是预期的行为吗?我是不是忽略了什么? 是否要通过信息类型使结构可见?(不带更改代码)。您可以使用ptype,请参阅内置帮助: (gdb) help ptype Print definition of type TYPE. Us
信息类型来理解结构的外观
看到以下行为:
如果结构定义为:
typedef struct {
...
...
} XX;
info-types
命令显示结构格式
但是如果它没有类型定义,info-types
只是告诉它是一个结构。
未提供其成员的详细信息
这是预期的行为吗?我是不是忽略了什么?
是否要通过信息类型使结构可见?(不带更改代码)。您可以使用ptype
,请参阅内置帮助:
(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)
以下是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)
谢谢@ks1322。请注意,不需要“ptype struct redisContext”吗?这是C++吗?另外,“信息类型”的行为是否符合预期?否,ptype struct redisContext
不是必需的,您可以同时使用这两种类型redisContext
是redis客户端C API的一部分。我在info-types
output中没有看到任何结构定义,我想应该是这样的。