c - 使用 GDB 打印复杂结构

标签 c gdb structure

请考虑以下结构:

/* Complex Structure */
typedef struct
{
char_t  s4_1 [15];
int_t   s4_2;
} struct4_st;

typedef struct
{
char_t  s3_1 [15];
int_t s3_2;
} struct3_st;

typedef struct
{
struct3_st  s2_1;
struct4_st  s2_2;
} struct2_st;


typedef struct
{
int_t   s1_1;
char_t  s1_2;
struct2_st s1_3;
} struct1_st;

struct sample
{
    int_t sample1;
    int_t sample2;
char_t sample3[20];
struct1_st sample4;
} test;

如果我在包含该结构的函数上放置一个断点,我可以以 pretty-print 格式打印该结构的参数。

我的要求是:

我想使用 GDB 输出来编写代码来填充这些结构。

是否有任何高级命令可以将每个结构成员放在单独的行上,例如:

gdb$ <command> test

所需输出:

test.sample1=1
test.sample2=2;
test.sample3="hello"
test.sample4.s1_1=3
test.sample4.s1_2='t'

谢谢。

最佳答案

gdb 中没有内置命令可以执行此操作。

如果您的 gdb 支持 Python,那么您自己编写它并不太难。

关于c - 使用 GDB 打印复杂结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17968549/

相关文章:

c - 将两条短裤存放在一条短裤中

c - 数组的最后一个元素不同的值

c - 使用 strcat 在字符串文字上添加空格?

c - 在 Unix 内核中发现的 C 语言的匿名结构

c++ - Android 中的 C/C++?

c - malloc() 如何导致 SIGSEGV?

c - 打开/关闭文件时出现段错误?

c++ - 调试 C++ 库

swift - 无法在没有参数的情况下为类型 Height 调用初始值设定项

C++:两个指向相同结构的指针 vector ,每个 vector 的排序不同