1

I go this simple code to test my GDB ( GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1), my linux runs within docker, and the code is:

// hello.cc
#include <iostream>

int main() {
    std::cout << "hello world!" << std::endl;
}

I compiled it with:

$ g++ -g -o out.a hello.cc

and debug it like:

(gdb) file out.a
(gdb) b main
Note: breakpoint 1 also set at pc 0x40084a.
(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000000000040084a in main() at hello.cc:3
(gdb) r
hello world!
During startup program exited normally.

Why gdb not stopped on main?

ks1322
  • 33,961
  • 14
  • 109
  • 164
coanor
  • 3,746
  • 4
  • 50
  • 67
  • 3
    Probably not your main problem, but `out.a` is a really bad naming choice for an executable. – Paul R Sep 16 '16 at 08:42
  • 1
    Looks very similar to this question http://stackoverflow.com/q/34856092/72178. Try `docker run --privileged`. – ks1322 Sep 16 '16 at 09:40
  • @PaulR: just a joke to the famous `a.out`, I think GDB will not treat it like a static library :) – coanor Sep 16 '16 at 19:17

1 Answers1

0

Couple of reasons i can think of:

  • The gdb version i use is 7.0-0.4.16, and it worked as expected (ie., stopped at main). Probably it is related to version of gdb you have.
  • I am bit surprised on the info output in your gdb case. It showed the line number as '3' for breakpoint. Ideally it should be 4.

Ruling out the other two options mentioned above. Just observed that your linux is running on a docker. In this case, your test program is a process running on the docker and i assume gdb is invoked on native machine. You might need to attach the docker to gdb using lxc-attach.

Sravan
  • 131
  • 1
  • 2
  • 10