gpt4 book ai didi

c - gdb 'info types' 不打印 C 结构

转载 作者:行者123 更新时间:2023-12-02 20:18:18 26 4
gpt4 key购买 nike

我想使用 gdb 的信息类型来了解结构的外观。

看到以下行为:
如果结构体定义为:

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

info types 命令显示结构格式。

但是如果它没有经过 typedef 编辑,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)

关于c - gdb 'info types' 不打印 C 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48925628/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com