器:gdb 循环输出链表值直接固定成脚本命令

本文介绍了在GDB调试器中如何循环输出链表的值,并通过设置GDB脚本来自动化这一过程。经过一些尝试和错误,最终成功创建了一个接受链表地址作为参数的GDB脚本,无需指定链表长度。
AI助手已提取文章相关产品:

 

 gdb 调试模式下,循环输出

(gdb) set $x=13
(gdb) while $x--
 >p $x
 >end
$6 = 12
$7 = 11
$8 = 10
$9 = 9
$10 = 8
$11 = 7
$12 = 6
$13 = 5
$14 = 4
$15 = 3
$16 = 2
$17 = 1
$18 = 0

 

 

实际用起来:

真是打击啊,,,

(gdb) set $x=13
(gdb) while $x--
 >set $PCur=0x614c20
 >set $data=$PCur->mData
 >p $data
 >set $PCur=PCur->mNext
 >end
Attempt to extract a component of a value that is not a structure pointer.
(gdb) set $x=13
(gdb) while $x--
 >if(PCur->mData)
  >PCur=PCur->mNext
  >p PCur->mData
  >end
 >end
(gdb) 

 

nm

我的锅,要set啦!!!

 

Attempt to extract a component of a value that is not a structure pointer.
(gdb) set $x=13
(gdb) while $x--
 >if(PCur->mData)
  >PCur=PCur->mNext
  >p PCur->mData
  >end
 >end
(gdb) p PCur->mData
$19 = 0
(gdb) PCur=PCur->mNext
Undefined command: "PCur".  Try "help".
(gdb) PCur=(PCur->mNext)
Undefined command: "PCur".  Try "help".
(gdb) set PCur=(PCur->mNext)
(gdb) p PCur->mData
$20 = 5

 

再来:

(gdb) set $x=13
(gdb) while $x--
 >p PCur->mData
 >set PCur=(PCur->mNext)
 >end
$21 = 5
$22 = 8
$23 = 666
$24 = 666
$25 = 12
$26 = 6
$27 = 4
$28 = 6
$29 = 9
$30 = 1
$31 = 4
$32 = 8
$33 = 2
(gdb) 

成功打印,,

如何直接写成个gdb脚本呢,两个参数,链表地址,不用长度

实验:

define plist

set $x=13
while $x--
	p PCur->mData
set PCur=(PCur->mNext)
	end
end

document plist
	to list the list by travel 
end

source printlist.gdb

可以用:

(gdb) source printlist.gdb
...
(gdb) plist 
$1 = 5
$2 = 8
$3 = 666
$4 = 666
$5 = 12
$6 = 6
$7 = 4
$8 = 6
$9 = 9
$10 = 1
$11 = 4
$12 = 8
$13 = 2
(gdb) c
Continuing.

 

 

 

 

 

 

https://blog.youkuaiyun.com/ruixj/article/details/5698270

https://blog.youkuaiyun.com/justlinux2010/article/details/9453151

 

 

 

您可能感兴趣的与本文相关内容

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值