gdb在完成main之后跳到前几行 [英] gdb jumps previous lines after finish main

查看:74
本文介绍了gdb在完成main之后跳到前几行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚为什么gdb的行为不符合预期.不知道是什么触发了这一点.看到此问题后,我编写了main函数的最小版本.它完成了最后一行并正确退出.增加了一项功能后,跳跃又回来了.即使在注释掉添加的行之后,跳回也不会消失.

I am trying to figure out why gdb is not behaving as expected. Not sure what triggered this. After seeing this problem, I wrote a minimal version of the main function. It finished the last line and exited properly. After adding one more function, the jumping came back. Even after commenting out the added line the jumping back does not go away.

即使在注释掉大部分代码(不是我自己的库的单行引用)之后,我不确定这是否与链接到我自己的库有关,构建过程仍然使用链接(automake):

I am not sure this is related the the linking to my own library even after commenting out most of the code (not a single line reference my own library), the build process still use the linking (automake):

LDADD = ../libmyown.la

此行用于将库添加到此目录中内置的许多其他程序中.我测试了gdb和gcc的不同版本,两个程序的最新版本均为8.2.使用了-g -O0,-ggdb -O0选项.我已经在Stackoverflow中看到有关此类行为的帖子.不知道我是否遇到了这种现象,或者是我自己的库中的某个错误,该错误的链接导致了这种回跳行为.尽管此发布似乎多余,但是我试图提供更多的上下文信息.希望我自己的其他人能够找到解决方案并帮助其他人.

This line was used to add libs to to many other programs built in this directory. I tested different versions of gdb and gcc, with the latest being 8.2 for both programs. Have used the -g -O0, -ggdb -O0 option. I have seen postings in Stackoverflow about this type of behavior. Not sure I am hitting this behavior or it was some bug in my own library whose linking caused this jumping back behavior. Although this posting appears to be redundant, but I am trying to provide more context information. Hopefully some else of myself will find a solution and help others.

除了gdb中的跳转问题外,二进制程序都可以正确执行.

Except for the jumping problem in gdb, the binary program execute properly.

以下是主体的略微扩展版本,显示了跳跃问题:

Here is a slightly expanded version of the main demonstrating the jumping issue:

Breakpoint 1, main (argc=1, argv=0x7fffffffdeb8) at alnlocalmany.cpp:66
66     if (isDNA(reffile)) {
(gdb) n
67        alignDNAMany(reffile, dbfile, outfile);
(gdb) 
68        return 0;
(gdb) s
39     string reffile, dbfile, outfile;
(gdb) s
73  }
(gdb) s
0x00007ffff6d97b97 in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) s
Single stepping until exit from function __libc_start_main,
which has no line number information.
[Inferior 1 (process 15621) exited normally]

请注意,它从68跳到39(main的第一行),然后跳到73(main的大括号结尾)

Note it jump from 68 to 39 (first line in main) then 73 (ending curly bracket of main)

推荐答案

有类似的gcc https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49951#c20 .

There was a similar gcc bug 49951 in the past which was later closed with the status RESOLVED FIXED. However it can be reproduced as of now with the current version of gcc (I tested with gcc 8.2.1). Other people also claim that the bug was not fixed, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49951#c20.

作为一种解决方法,您可以尝试使用clang而不是gcc,至少该错误未在gcc的测试示例中重现

As a workaround you can try to use clang instead of gcc, at least the bug was not reproduced on test example from gcc bug 49951 when building with clang. You can also downgrade gcc to version 4.4 but it is too old for now.

这篇关于gdb在完成main之后跳到前几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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