gpt4 book ai didi

c++ - 调试:跟踪(和区分)同一程序的两个版本的函数调用树

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:58:45 24 4
gpt4 key购买 nike

我正在重写一些C++ 命令行程序中的代码。

我改变了底层数据结构它使用并且新版本通过了所有测试(相当多)没有任何问题,我得到了正确的输出无论是新版本还是旧版本...不过,当提供某些输入时,他们会提供不同的行为。

进入正题:有点一个我不知道的大项目如何追踪执行时间流量发散,所以...有没有办法追踪函数调用树(可能不包括std 电话)连同,我不知道,行源文件和源中的编号姓名?也许一些 gcc 或宏功夫?

我需要一个 Linux 解决方案,因为这是程序运行的地方。

最佳答案

Still, when give certain input, they give different behaviour

我会在您的旧版本和新版本中扩展日志记录,以便更好地理解您的算法对某些输入 的工作。当它变得更清晰时,例如,如果您仍然需要它,您可以使用 gdb。

更新

好的,至于我的日志记录是可以的,但是你不想添加它。

另一种方法是追踪。实际上我只在 Solaris 上使用它,但我发现它也存在于 Linux 上。我没有在 Linux 上使用过它,所以它只是一个您可以测试的想法。

您可以使用 SystemTap

User-Space Probing
SystemTap initially focused on kernel-space probing. However, there are many instances where userspace probing can help diagnose a problem. SystemTap 0.6 added support to allow probing userspace processes. SystemTap includes support for probing the entry into and return from a function in user-space processes, probing predefined markers in user-space code, and monitoring user-process events.

我可以保证它会起作用,但为什么不试一试呢?

文档中甚至有一个示例:

If you want to see how the function xmalloc function is being called by the command ls, you could use the user-space backtrack functions to provide that information.

stap -d /bin/ls --ldd \
-e 'probe process("ls").function("xmalloc") {print_ustack(ubacktrace())}' \
-c "ls /"

关于c++ - 调试:跟踪(和区分)同一程序的两个版本的函数调用树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13496094/

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