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
本文介绍了在GDB调试器中如何循环输出链表的值,并通过设置GDB脚本来自动化这一过程。经过一些尝试和错误,最终成功创建了一个接受链表地址作为参数的GDB脚本,无需指定链表长度。
1222

被折叠的 条评论
为什么被折叠?



