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-compose.yml vs docker-stack.yml what difference?
  • Mongo doesn't run after installing on Docker Centos image: Failed to connect to 127.0.0.1:27017
  • How to set an environment variable in a running docker container
  • Error trying to install Ansible in Jenkins image
  • Docker application deployment
  • Error: Cannot Start Container: stat /bin/sh: no such file or directory"
  • $ 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?

  • Dockerfile if else condition with external arguments
  • Protocol for “docker pull” command
  • AEM is installed under /var in DOCKER , I need to move the same to /opt as I am facing space issue
  • How to check if a process is running inside docker container
  • Apparmor on Docker Swarm
  • How to downloaded from remote location and execute script on container start Docker?
  • 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.