简体   繁体   中英

Why gdb is not working for this simple hello world program?

Code (m1.cpp):

#include <iostream>
using namespace std;

int main (int argc, char *argv[])
{
   cout << "running m1" << endl;

   return 0;
}

GDB Version: GNU gdb (GDB) 7.6.2

Built using: g++ -g m1.cpp

Command line history:

(gdb) b main
Breakpoint 1 at 0x40087b: file m1.cpp, line 6.
(gdb) r
Starting program: .../a.out

Program received signal SIGSEGV, Segmentation fault.
0x00002aaaaaac16a0 in strcmp () from /lib64/ld-linux-x86-64.so.2
(gdb) c
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb)

When I run without setting any breakpoints, it runs without errors.

As requested:

(gdb) bt
#0  strcmp () from /lib64/ld-linux-x86-64.so.2
#1  in check_match.12104 () from /lib64/ld-linux-x86-64.so.2
#2  in do_lookup_x () from /lib64/ld-linux-x86-64.so.2
#3  in _dl_lookup_symbol_x () from /lib64/ld-linux-x86-64.so.2
#4  in _dl_relocate_object () from /lib64/ld-linux-x86-64.so.2
#5  in dl_main () from /lib64/ld-linux-x86-64.so.2
#6  in _dl_sysdep_start () from /lib64/ld-linux-x86-64.so.2
#7  in _dl_start () from /lib64/ld-linux-x86-64.so.2
#8  in _start () from /lib64/ld-linux-x86-64.so.2
#9  in ?? ()

I was able to replicate the OP's observed behavior (using the same compile and getting the same backtrace). The behavior was persistent across a range GDBs and GCCs. I noticed that the symptom goes away when I unset SHELL. In my normal environment I use tcsh (version 1.15.00). If SHELL is set, then (I believe) gdb launches using tcsh. If I unset SHELL, gdb launches using sh. This is enough for me to make forward progress. I don't have a crisp explanation for what would be different in tcsh to manifest the issue but if others have the same behavior, it may shed more light on the issue.

I checked that in my GNU gdb version 7.11.1. It worked really fine in it. I first compiled the same program and built it using:

g++ -g m1.cpp

Then, ran the executable in the gdb as follows:

gdb -q ./a.out

And did the same things you mentioned. It worked fine. Update your gdb, and check that again and let know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM