Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lldb on Linux leaves inferior stopped at breakpoint even after detaching #60408

Open
godlygeek opened this issue Jan 31, 2023 · 1 comment
Open
Labels

Comments

@godlygeek
Copy link

godlygeek commented Jan 31, 2023

Given this C++11 program in a file called test.cpp:

#include <thread>
#include <vector>

#include <unistd.h>

void getpid_eventually()
{
    sleep(2);
    getpid();
}

int main()
{
    std::vector<std::thread> threads;
    for (int i = 0; i < 5; ++i) {
        threads.emplace_back(getpid_eventually);
    }
    for (auto& thread: threads) {
        thread.join();
    }
}

Compiled with g++ -std=c++11 test.cpp -lpthread -o test

This lldb command line consistently results in the inferior process remaining in a stopped state even after lldb has detached and exited:

./test & sleep 1; lldb --batch -o "br set -b getpid -C 'breakpoint disable' -C 'thread list'"  -o "continue" -p $! 

That is, run the executable in the background, sleep 1 second (until threads have been spawned and are blocked in sleep), and then attach to it in batch mode, set a breakpoint with commands, and continue.

The full output is:

(lldb) process attach --pid 16532                                                                                                                                                                                                     [35/6718]
Process 16532 stopped
* thread #1, name = 'test', stop reason = signal SIGSTOP
    frame #0: 0x00007fe7a656b017 libpthread.so.0`pthread_join + 167
libpthread.so.0`pthread_join:
->  0x7fe7a656b017 <+167>: cmpl   $0x0, (%rdi)
    0x7fe7a656b01a <+170>: jne    0x7fe7a656b00e            ; <+158>
    0x7fe7a656b01c <+172>: movl   %r8d, %edi
    0x7fe7a656b01f <+175>: callq  0x7fe7a65704a0            ; __pthread_disable_asynccancel
  thread #2, name = 'test', stop reason = signal SIGSTOP
    frame #0: 0x00007fe7a5a399fd libc.so.6`__nanosleep + 45
libc.so.6`__nanosleep:
->  0x7fe7a5a399fd <+45>: movq   (%rsp), %rdi
    0x7fe7a5a39a01 <+49>: movq   %rax, %rdx
    0x7fe7a5a39a04 <+52>: callq  0x7fe7a5a80890            ; __libc_disable_asynccancel
    0x7fe7a5a39a09 <+57>: movq   %rdx, %rax
  thread #3, name = 'test', stop reason = signal SIGSTOP
    frame #0: 0x00007fe7a5a399fd libc.so.6`__nanosleep + 45
libc.so.6`__nanosleep:
->  0x7fe7a5a399fd <+45>: movq   (%rsp), %rdi
    0x7fe7a5a39a01 <+49>: movq   %rax, %rdx
    0x7fe7a5a39a04 <+52>: callq  0x7fe7a5a80890            ; __libc_disable_asynccancel
    0x7fe7a5a39a09 <+57>: movq   %rdx, %rax
  thread #4, name = 'test', stop reason = signal SIGSTOP
    frame #0: 0x00007fe7a5a399fd libc.so.6`__nanosleep + 45
libc.so.6`__nanosleep:
->  0x7fe7a5a399fd <+45>: movq   (%rsp), %rdi
    0x7fe7a5a39a01 <+49>: movq   %rax, %rdx
    0x7fe7a5a39a04 <+52>: callq  0x7fe7a5a80890            ; __libc_disable_asynccancel
    0x7fe7a5a39a09 <+57>: movq   %rdx, %rax
  thread #5, name = 'test', stop reason = signal SIGSTOP
    frame #0: 0x00007fe7a5a399fd libc.so.6`__nanosleep + 45
libc.so.6`__nanosleep:
->  0x7fe7a5a399fd <+45>: movq   (%rsp), %rdi
    0x7fe7a5a39a01 <+49>: movq   %rax, %rdx
    0x7fe7a5a39a04 <+52>: callq  0x7fe7a5a80890            ; __libc_disable_asynccancel
    0x7fe7a5a39a09 <+57>: movq   %rdx, %rax
  thread #6, name = 'test', stop reason = signal SIGSTOP
    frame #0: 0x00007fe7a5a399fd libc.so.6`__nanosleep + 45
libc.so.6`__nanosleep:
->  0x7fe7a5a399fd <+45>: movq   (%rsp), %rdi
    0x7fe7a5a39a01 <+49>: movq   %rax, %rdx
    0x7fe7a5a39a04 <+52>: callq  0x7fe7a5a80890            ; __libc_disable_asynccancel
    0x7fe7a5a39a09 <+57>: movq   %rdx, %rax
Executable module set to "/home/mwoznisk/sandbox/lldb_breakpoint_after_detach/test".
Architecture set to: x86_64-unknown-linux-gnu.
(lldb) breakpoint set -b getpid -C 'breakpoint disable' -C 'thread list'
Breakpoint 1: 2 locations.
(lldb) continue
(lldb)  breakpoint disable
All breakpoints disabled. (1 breakpoints)
(lldb)  thread list
Process 16532 stopped
* thread #1: tid = 16532, 0x00007fe7a656b017 libpthread.so.0`pthread_join + 167, name = 'test'
  thread #2: tid = 16534, 0x00007fe7a5a3a9a0 libc.so.6`getpid, name = 'test', stop reason = breakpoint 1.
  thread #3: tid = 16535, 0x00007fe7a5a3a9a0 libc.so.6`getpid, name = 'test', stop reason = breakpoint 1.
  thread #4: tid = 16536, 0x00007fe7a5a3a9a0 libc.so.6`getpid, name = 'test', stop reason = breakpoint 1.
  thread #5: tid = 16537, 0x00007fe7a5a3a9a0 libc.so.6`getpid, name = 'test', stop reason = breakpoint 1.
  thread #6: tid = 16538, 0x00007fe7a5a3a9a0 libc.so.6`getpid, name = 'test', stop reason = breakpoint 1.
Process 16532 resuming
Process 16532 stopped
* thread #2, name = 'test', stop reason = breakpoint 1.
    frame #0: 0x00007fe7a5a3a9a0 libc.so.6`getpid
libc.so.6`getpid:
->  0x7fe7a5a3a9a0 <+0>:  movl   %fs:0x2d4, %edx
    0x7fe7a5a3a9a8 <+8>:  cmpl   $0x0, %edx
    0x7fe7a5a3a9ab <+11>: movl   %edx, %eax
    0x7fe7a5a3a9ad <+13>: jle    0x7fe7a5a3a9b1            ; <+17>
  thread #3, name = 'test', stop reason = breakpoint 1.
    frame #0: 0x00007fe7a5a3a9a0 libc.so.6`getpid
libc.so.6`getpid:
->  0x7fe7a5a3a9a0 <+0>:  movl   %fs:0x2d4, %edx
    0x7fe7a5a3a9a8 <+8>:  cmpl   $0x0, %edx
    0x7fe7a5a3a9ab <+11>: movl   %edx, %eax
    0x7fe7a5a3a9ad <+13>: jle    0x7fe7a5a3a9b1            ; <+17>
  thread #4, name = 'test', stop reason = breakpoint 1.
    frame #0: 0x00007fe7a5a3a9a0 libc.so.6`getpid
libc.so.6`getpid:
->  0x7fe7a5a3a9a0 <+0>:  movl   %fs:0x2d4, %edx
    0x7fe7a5a3a9a8 <+8>:  cmpl   $0x0, %edx
    0x7fe7a5a3a9ab <+11>: movl   %edx, %eax
    0x7fe7a5a3a9ad <+13>: jle    0x7fe7a5a3a9b1            ; <+17>
  thread #5, name = 'test', stop reason = breakpoint 1.
    frame #0: 0x00007fe7a5a3a9a0 libc.so.6`getpid
libc.so.6`getpid:
->  0x7fe7a5a3a9a0 <+0>:  movl   %fs:0x2d4, %edx
    0x7fe7a5a3a9a8 <+8>:  cmpl   $0x0, %edx
    0x7fe7a5a3a9ab <+11>: movl   %edx, %eax
    0x7fe7a5a3a9ad <+13>: jle    0x7fe7a5a3a9b1            ; <+17>
  thread #6, name = 'test', stop reason = breakpoint 1.
    frame #0: 0x00007fe7a5a3a9a0 libc.so.6`getpid
libc.so.6`getpid:
->  0x7fe7a5a3a9a0 <+0>:  movl   %fs:0x2d4, %edx
    0x7fe7a5a3a9a8 <+8>:  cmpl   $0x0, %edx
    0x7fe7a5a3a9ab <+11>: movl   %edx, %eax
    0x7fe7a5a3a9ad <+13>: jle    0x7fe7a5a3a9b1            ; <+17>
[2]  + suspended (signal)  ./test

After which, listing the jobs in my zsh shell shows:

[2]  + suspended (signal)  ./test

until I foreground it or prod it with a SIGCONT.

This reproduces on Linux in lldb 10.0.0, lldb 15.0.4, and in a debug build of main.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 31, 2023

@llvm/issue-subscribers-lldb

@godlygeek godlygeek changed the title lldb leaves inferior stopped at breakpoint even after detaching lldb on Linux leaves inferior stopped at breakpoint even after detaching Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants