使用GDB调试源文件(和本地函数),而不必进入库调用? [英] Debug a source file(and functions local to it) using GDB without stepping into Library calls?

查看:123
本文介绍了使用GDB调试源文件(和本地函数),而不必进入库调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试一个程序,但是我不希望GDB打印它在我的本地源文件范围内访问的代码。 步骤 (进入每个调用)和 下一步 (即使在同一个源代码中跳过功能文件)在这种情况下是没有用的。



任何点都一样吗?



谢谢

解决方案

你可以看到我对
GDB是否有下一步调用指令?
:没有原生的GDB命令(据我所知,他们可能已经在这方面工作了),但在Python中很容易:

  import gdb 
$ b $ class StepNoLibrary(gdb.Command):
def __init__(self):
super(StepNoLibrary,自我).__ init__(step-no-library,
gdb.COMMAND_OBSCURE)

def invoke(self,arg,from_tty):
step_msg = gdb.execute(步骤,to_string = True)

fname = gdb.newest_frame()。function()。symtab.objfile.filename
$ b $ if fname.startswith(/ usr) :库中的

SILENT = False
gdb.execute(finish,to_string = SILENT)
else:
#在应用程序中
print(step_msg [: - 1])$ ​​b
$ b StepNoLibrary()

just把它放在一个文件中,用GDB(或者在你的.gdbinit中)来源,这将提供de你的新命令 step-no-library



很容易阅读它的功能, step forward,如果该步骤结束于存储在 / usr / * 中的文件,则<$ c $



当然,如果你的需求与刚刚编辑的需求不同,这是一个天真的实现功能代码!

I want to debug a program but i don't want GDB to print the code it visits out of my local source file scope. The options step(goes into every call) and next(skips stepping into the functions even in the same source file) aren't useful in this case.

Any points on the same?

Thanks

解决方案

You can see my answer to Does GDB have a "step-to-next-call" instruction? : there is no native GDB command for that (as far as I know, they may have worked on that), but it's easy to do in Python:

import gdb

class StepNoLibrary (gdb.Command):
    def __init__ (self):
        super (StepNoLibrary, self).__init__ ("step-no-library",
                                              gdb.COMMAND_OBSCURE)

    def invoke (self, arg, from_tty):
        step_msg = gdb.execute("step", to_string=True)

        fname = gdb.newest_frame().function().symtab.objfile.filename

        if fname.startswith("/usr"):
            # inside a library
            SILENT=False
            gdb.execute("finish", to_string=SILENT)
        else:
            # inside the application
            print(step_msg[:-1])

    StepNoLibrary()

just put that in a file, source it with GDB (or in your .gdbinit) and that will provide you the new command step-no-library.

It's easy to read what it does, it goes one step forward, and if the step ends up in a file stored in /usr/*, it finishes it to come back to the application.

Of course that's a naive implementation, if you requirements are different from that just edit the function code!

这篇关于使用GDB调试源文件(和本地函数),而不必进入库调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆