Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?? ()
like image 284
Quark Avatar asked Apr 11 '17 16:04

Quark


1 Answers

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.

like image 136
Bob Condon Avatar answered Oct 05 '22 06:10

Bob Condon