gdb jumps previous lines after finish main

删除回忆录丶 提交于 2021-02-04 21:12:12

问题


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.

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

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.

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]

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/53899747/gdb-jumps-previous-lines-after-finish-main

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!