gdb does not hit any breakpoints when I run it from inside Docker container

后端 未结 3 2034
天涯浪人
天涯浪人 2020-12-30 04:09

The problem

I am able to set and reach a breakpoint if I compile and run from the host, but if I do it from within the docker container gdb does not

相关标签:
3条回答
  • 2020-12-30 04:33

    thanks the answer from @rubicks.

    and if you can't use --privileged option(e.g. you are using a container from cloud), you can print stacktrace from your program:

    How to automatically generate a stacktrace when my gcc C++ program crashes

    0 讨论(0)
  • 2020-12-30 04:47

    Rather than elevating the entire container, I was able to use the option

    --security-opt seccomp=unconfined
    

    to fix address space randomization problems.

    Some also recommend enabling the ptrace capability with

    --cap-add=SYS_PTRACE
    

    but this didn't seem to have any effect for me.

    Here are the same settings for Docker compose:

    security_opt:
      - seccomp:unconfined
    cap_add:
      - SYS_PTRACE
    

    Details are taken from this Stack Overflow post.

    0 讨论(0)
  • 2020-12-30 04:51

    update 2020.01.04: Use the answer given by Kevin W Matthews --- it's better because it grants the necessary individual capabilities without elevating the entire container.


    tldr; use

    docker run --privileged
    

    Longer: I was having some problems with gdb in docker---it was attempting (and failing) to disable address space layout randomization---but only on docker-machine, not on my native linux host.

    When gdb failed to disable ASLR, all of my breakpoints would be ignored. Using the --privileged flag fixed my issue. Your mileage may vary.

    0 讨论(0)
提交回复
热议问题