从 gdbinit 脚本步进时如何设置跳过无趣的功能?
How to set skipping of uninteresting functions while stepping from gdbinit script?
我正在尝试设置一组函数,让 gdb 在执行以下命令时跳过这些函数:
skip myfunction
。但是如果我把它们放在 ~/.gdbinit
而不是在终端 gdb 提示符中说,我会得到错误:
No function found named myfunction.
Ignore function pending future shared library load? (y or [n]) [answered N; input not from terminal]
所以我需要 GDB 来获得 Y
答案。我试过 suggested for breakpoints as well as set confirm off
suggested in a comment to this question。但是这些对 skip
命令没有帮助。
如何在 .gdbinit
脚本中设置 skip
,回答 Y
关于未来库加载的问题?
此处已提出此功能:
https://sourceware.org/ml/gdb-prs/2015-q2/msg00417.html
https://sourceware.org/bugzilla/show_bug.cgi?id=18531
到目前为止,activity 已经有 6 个月没有关于该问题的讨论了。在撰写本文时,该功能尚未包含在 GDB 7.10 中。
可以用Python等待执行开始,相当于pending on
:
import gdb
to_skip = []
def try_pending_skips(evt=None):
for skip in list(to_skip): # make a copy for safe remove
try:
# test if the function (aka symbol is defined)
symb, _ = gdb.lookup_symbol(skip)
if not symb:
continue
except gdb.error:
# no frame ?
continue
# yes, we can skip it
gdb.execute("skip {}".format(skip))
to_skip.remove(skip)
if not to_skip:
# no more functions to skip
try:
gdb.events.new_objfile.disconnect(try_pending_skips) # event fired when the binary is loaded
except ValueError:
pass # was not connected
class cmd_pending_skip(gdb.Command):
self = None
def __init__ (self):
gdb.Command.__init__(self, "pending_skip", gdb.COMMAND_OBSCURE)
def invoke (self, args, from_tty):
global to_skip
if not args:
if not to_skip:
print("No pending skip.")
else:
print("Pending skips:")
for skip in to_skip:
print("\t{}".format(skip))
return
new_skips = args.split()
to_skip += new_skips
for skip in new_skips:
print("Pending skip for function '{}' registered.".format(skip))
try:
gdb.events.new_objfile.disconnect(try_pending_skips)
except ValueError: pass # was not connected
# new_objfile event fired when the binary and libraries are loaded in memory
gdb.events.new_objfile.connect(try_pending_skips)
# try right away, just in case
try_pending_skips()
cmd_pending_skip()
将此代码保存到 Python 文件 pending_skip.py
(或在 .gdbinit
中用 python ... end
包围),然后:
source pending_skip.py
pending_skip fct1
pending_skip fct2 fct3
pending_skip # to list pending skips
文档参考:
我正在尝试设置一组函数,让 gdb 在执行以下命令时跳过这些函数:
skip myfunction
。但是如果我把它们放在 ~/.gdbinit
而不是在终端 gdb 提示符中说,我会得到错误:
No function found named myfunction.
Ignore function pending future shared library load? (y or [n]) [answered N; input not from terminal]
所以我需要 GDB 来获得 Y
答案。我试过 suggested for breakpoints as well as set confirm off
suggested in a comment to this question。但是这些对 skip
命令没有帮助。
如何在 .gdbinit
脚本中设置 skip
,回答 Y
关于未来库加载的问题?
此处已提出此功能:
https://sourceware.org/ml/gdb-prs/2015-q2/msg00417.html https://sourceware.org/bugzilla/show_bug.cgi?id=18531
到目前为止,activity 已经有 6 个月没有关于该问题的讨论了。在撰写本文时,该功能尚未包含在 GDB 7.10 中。
可以用Python等待执行开始,相当于pending on
:
import gdb
to_skip = []
def try_pending_skips(evt=None):
for skip in list(to_skip): # make a copy for safe remove
try:
# test if the function (aka symbol is defined)
symb, _ = gdb.lookup_symbol(skip)
if not symb:
continue
except gdb.error:
# no frame ?
continue
# yes, we can skip it
gdb.execute("skip {}".format(skip))
to_skip.remove(skip)
if not to_skip:
# no more functions to skip
try:
gdb.events.new_objfile.disconnect(try_pending_skips) # event fired when the binary is loaded
except ValueError:
pass # was not connected
class cmd_pending_skip(gdb.Command):
self = None
def __init__ (self):
gdb.Command.__init__(self, "pending_skip", gdb.COMMAND_OBSCURE)
def invoke (self, args, from_tty):
global to_skip
if not args:
if not to_skip:
print("No pending skip.")
else:
print("Pending skips:")
for skip in to_skip:
print("\t{}".format(skip))
return
new_skips = args.split()
to_skip += new_skips
for skip in new_skips:
print("Pending skip for function '{}' registered.".format(skip))
try:
gdb.events.new_objfile.disconnect(try_pending_skips)
except ValueError: pass # was not connected
# new_objfile event fired when the binary and libraries are loaded in memory
gdb.events.new_objfile.connect(try_pending_skips)
# try right away, just in case
try_pending_skips()
cmd_pending_skip()
将此代码保存到 Python 文件 pending_skip.py
(或在 .gdbinit
中用 python ... end
包围),然后:
source pending_skip.py
pending_skip fct1
pending_skip fct2 fct3
pending_skip # to list pending skips
文档参考: