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:

  • Cannot connect to Jenkins docker container running inside Vagrant on Mac
  • How to move Images and Containers to new Server with historical data
  • Yarn warning on docker build
  • Docker + nginx multi-domain configuration problems
  • How to delete logs in IBM Containers service (BlueMix)
  • rg.apache.spark.SparkException: Invalid master URL: spark://tasks.501393358-spark-master:7077
  • $ 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?

  • Configure dockerfile with postgres
  • Reflecting code changes in docker containers
  • PostgreSQL UNIQUE constraint not being applied on Docker container
  • How specify the size of a shared Docker volume?
  • docker-compose.yml to start containers on multiple VM's
  • Docker Wordpress CPU jumps when selecting featured image
  • 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.