admin管理员组文章数量:1389757
Since gdb has only one global set print elements
that affects all array-like types, it has been necessary to use a very short value like set print elements 4
. But in certain specific cases it can be useful to see the entire string without changing the global setting:
(gdb) p "a string longer than the current 'print elements'"
$3 = "a st"...
Adding a python command is simple enough:
import gdb
class WholeString(gdb.Function):
def __init__(self):
super(WholeString, self).__init__("wholestring")
def invoke(self, m):
elements = gdb.execute("show print elements", True, True)[:-2].split(" ")[-1]
gdb.execute("set print elements 0")
print("[whole entire string: {}]".format(m))
if int(elements) > 0:
gdb.execute("set print elements {}".format(elements))
return ""
WholeString()
While this works, the only way to invoke the wholestring
command is by printing it, which litters the terminal with a useless empty string:
(gdb) p $wholestring("a string longer than the current 'print elements'")
[whole entire string: "a string longer than the current 'print elements'"]
$2 = ""
Same result for (gdb) call $wholestring("...")
. Is there any way to invoke the command without printing it?
(gdb) $wholestring("a string longer than the current 'print elements'")
Undefined command: "$wholestring". Try "help".
本文标签: gdb invoke custom python command without printing itStack Overflow
版权声明:本文标题:gdb: invoke custom python command without printing it - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744583061a2614038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论