使功能GDB打印控制流程,他们被称为 [英] Make GDB print control flow of functions as they are called

查看:238
本文介绍了使功能GDB打印控制流程,他们被称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使利益gdb的打印功能,因为他们是所谓的,根据他们是多么深的堆栈缩进?

How do I make gdb print functions of interest as they are called, indented according to how deep in the stack they are?

我希望能够这样说(由):

I want to be able to say something like (made up):

(gdb) trace Foo* Bar* printf

和有GDB打印它与富或酒吧开始,因为他们是所谓的所有功能。有点像GNU cflow的,除非使用调试符号,只有打印功能实际上被调用,并非所有可能的呼叫流程。

And have gdb print all functions which begin with Foo or Bar, as they are called. Kind of like gnu cflow, except using the debugging symbols and only printing functions which actually get called, not all possible call flows.

工具这将不利于包括cachegrind,callgrind和oprofile的,它下令由函数的调用最常见的结果。我需要调用preserved的顺序。

Tools which won't help include cachegrind, callgrind and oprofile, which order the results by which functions were called most often. I need the order of calling preserved.

该通配符(或同等学历)是必不可少的,因为有很多Foo和酒吧funcs中的。虽然我会满足于绝对记录每一个功能。或者,也许告诉GDB记录在一个特定的库中的所有功能。

The wildcarding (or equivalent) is essential, as there are a lot of Foo and Bar funcs. Although I would settle for recording absolutely every function. Or, perhaps telling gdb to record all functions in a particular library.

GDB的某些向导必须有一个剧本,这个共同的事业!

Some GDB wizard must have a script for this common job!

推荐答案

在你的情况我会谈谈定义GDB 命令,它允许你定义一个函数,这可能需要长达10个参数。

In your case I would turn to the define command in gdb, which allows you to define a function, which can take up to 10 arguments.

您可以在函数名传递给跟踪作为参数来定义,或者记录他们所有的函数本身的功能。我会做类似下面的

You can pass in the names of functions to "trace" as arguments to the function you define, or record them all in the function itself. I'd do something like the following

define functiontrace
if $arg0
    break $arg0
    commands
        where
        continue
        end
    end

if $arg1
...

参数给用户定义的函数在GDB作为$ arg0- $ arg9引用。另外,你可以只是记录,而不是使用$ arg0-9你想要的功能来跟踪每一个功能。

Arguments to a user-defined function in gdb are referenced as $arg0-$arg9. Alternatively, you could just record every function you wanted to trace in the function, instead of using $arg0-9.

请注意:这不会缩进到堆栈跟踪深度,而是将打印堆栈跟踪每次函数被调用的时间。我发现这种方法比使用strace等更多有用的...因为它会记录的您想要的任何的功能,系统,图书馆,地方或其他。

Note: this will not indent as to depth in the stack trace, but will print the stack trace every time the function is called. I find this approach more useful than strace etc... because it will log any function you want, system, library, local, or otherwise.

这篇关于使功能GDB打印控制流程,他们被称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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