【求助】GDB:如何连续打印结构数组中的某一项

软件和网站开发以及相关技术探讨
回复
fightyz
帖子: 35
注册时间: 2012-02-09 21:47

【求助】GDB:如何连续打印结构数组中的某一项

#1

帖子 fightyz » 2012-03-25 19:02

比如:

代码: 全选

typedef struct index_list_str {
  int pos;
  int list; 
} *indexed_list_ptr;

indexed_list_ptr index = (indexed_list_ptr) malloc ((size_t)20 * (sizeof(struct index_list_str)));
我想只打印出index数组的每一个pos,而不打印出list值。应该怎么做啊?跪谢~ :em42
头像
sgsdxzy
帖子: 430
注册时间: 2008-07-19 11:14

Re: 【求助】GDB:如何连续打印结构数组中的某一项

#2

帖子 sgsdxzy » 2012-04-12 15:21

p index->pos 或p index.pos 不行吗?
fightyz
帖子: 35
注册时间: 2012-02-09 21:47

Re: 【求助】GDB:如何连续打印结构数组中的某一项

#3

帖子 fightyz » 2012-04-19 16:58

sgsdxzy 写了:p index->pos 或p index.pos 不行吗?

p index->pos只会打印第一个的pos,即index[0].pos
p index.pos也只能打印第i个的pos值啊。

目前我是用while循环:
set $x=0
while $x<20
p index[$x].pos
set $x += 1
end

但是每次打印都要写个while循环,好烦啊 :em20

不知道有没有更简便的方法。。。
背泳的鱼
帖子: 54
注册时间: 2011-07-01 9:29

Re: 【求助】GDB:如何连续打印结构数组中的某一项

#4

帖子 背泳的鱼 » 2012-07-23 14:08

在.c/cpp文件里面写个函数,需要查看变量的时候call一下?
回复