Why GDB not stopped on break point?

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:

  • Docker - Enable Remote HTTP API with SystemD and “daemon.json”
  • Wildfly: AMQ214016: Failed to create netty connect ion java.nio.channels.UnresolvedAddressException from client on natted network
  • Set locale in Docker container
  • How to implement CPU & memory docker container restrictions on GCE + MYSQL backup/restore?
  • How can I run bash in a new container of a docker image?
  • DC/OS on top of a docker container cluster
  • $ 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?

  • Updating PATH environment variable permanently in Docker container
  • Docker daemon and DNS
  • Journalctl : add _SYSTEMD_UNIT field into log printout
  • Unable to finding the option to set docker workspace option when running the docker image
  • specify sysctl values using docker-compose
  • If images in Docker are untagged, are they used at all or just orphans?
  • One Solution collect form web for “Why GDB not stopped on break point?”

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.