gpt4 book ai didi

debugging - 从 gdbinit 脚本步进时如何设置跳过无趣的函数?

转载 作者:行者123 更新时间:2023-12-05 05:25:11 26 4
gpt4 key购买 nike

我正在尝试设置一组函数,让 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以及在对 this question 的评论中建议的 set confirm off .但是这些对 skip 命令没有帮助。

如何在 .gdbinit 脚本中设置 skip,回答关于 future 库加载的 Y

最佳答案

可以使用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

文档引用:

关于debugging - 从 gdbinit 脚本步进时如何设置跳过无趣的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31959867/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com