您现在的位置是:网站首页 -> Windows 文章内容
gdb调试C++标准库-itarticl.cc-IT技术类文章记录&分享
发布时间: 8年前【Windows】 135人已围观【返回】
define pvector
if $argc == 0
help pvector
else
set $size = $arg0._M_impl._M_finish - $arg0._M_impl._M_start
set $capacity = $arg0._M_impl._M_end_of_storage - $arg0._M_impl._M_start
set $size_max = $size - 1
end
if $argc == 1
set $i = 0
while $i < $size
printf "elem[%u]: ", $i
p *($arg0._M_impl._M_start + $i)
set $i++
end
end
if $argc == 2
set $idx = $arg1
if $idx < 0 || $idx > $size_max
printf "idx1, idx2 are not in acceptable range: [0..%u].\n", $size_max
else
printf "elem[%u]: ", $idx
p *($arg0._M_impl._M_start + $idx)
end
end
if $argc == 3
set $start_idx = $arg1
set $stop_idx = $arg2
if $start_idx > $stop_idx
set $tmp_idx = $start_idx
set $start_idx = $stop_idx
set $stop_idx = $tmp_idx
end
if $start_idx < 0 || $stop_idx < 0 || $start_idx > $size_max || $stop_idx > $size_max
printf "idx1, idx2 are not in acceptable range: [0..%u].\n", $size_max
else
set $i = $start_idx
while $i <= $stop_idx
printf "elem[%u]: ", $i
p *($arg0._M_impl._M_start + $i)
set $i++
end
end
end
if $argc > 0
printf "Vector size = %u\n", $size
printf "Vector capacity = %u\n", $capacity
printf "Element "
whatis $arg0._M_impl._M_start
end
end
document pvector
Prints std::vector<T> information.
Syntax: pvector <vector> <idx1> <idx2>
Note: idx, idx1 and idx2 must be in acceptable range [0..<vector>.size()-1].
Examples:
pvector v - Prints vector content, size, capacity and T typedef
pvector v 0 - Prints element[idx] from vector
pvector v 1 2 - Prints elements in range [idx1..idx2] from vector
end
define pvector
if $argc == 0 # 如果没有带参数,那么就打印帮助提示信息
help pvector
else # 如果有参数,那么接下来准备一下size, capacity, size_max 这三个重要的参数。
set $size = $arg0._M_impl._M_finish - $arg0._M_impl._M_start # arg0 就是第一个参数,也就是vstr数组对象。注重 size 是怎么计算的。
set $capacity = $arg0._M_impl._M_end_of_storage - $arg0._M_impl._M_start
set $size_max = $size - 1
end
if $argc == 1 # 如果只有一个参数,说明要求打印出vector中所有的元素
set $i = 0
while $i < $size # 用一个 while 循环,用printf与p,打印出列表中的所有元素
printf "elem[%u]: ", $i
p *($arg0._M_impl._M_start + $i) # 注意看哦!!!!
set $i++
end
end
发布时间: 8年前【Windows】135人已围观【返回】【回到顶端】
很赞哦! (1)
相关文章
点击排行

站长推荐

猜你喜欢
站点信息
- 建站时间:2016-04-01
- 文章统计:728条
- 文章评论:82条
- QQ群二维码:扫描二维码,互相交流
