Send Ctrl-C to app in LLDB
Asked Answered
S

2

7

I have an CLI app that is seg faulting during termination (After sending a Ctrl-C)

Pressing Ctrl-C in lldb naturally pauses execution.

Then I try: (lldb)process signal SIGINT (lldb)process continue

But that doesn't actually seem to do anything to terminate the app.

Also tried: (lldb)process signal 2

Snappy answered 21/8, 2014 at 15:26 Comment(0)
S
9

The debugger uses ^C for interrupting the target, so it assumes that you don't actually want the ^C propagated to the target. You can change this behavior by using the "process handle" command:

(lldb) process handle SIGINT -p true

telling lldb to "pass" SIGINT to the process.

If you had stopped the process in lldb by issuing a ^C, then when you change the process handle as shown here and continue, that SIGINT will be forwarded to the process.

If you stopped for some other reason, after specifying SIGINT to be passed to the process, you can generate a SIGINT by getting the PID of the debugee using the process status and send a SIGINT directly to said process using platform shell:

(lldb) process status 
(lldb) platform shell kill -INT {{PID from previous step}}
(lldb) continue
Socialist answered 26/9, 2014 at 16:36 Comment(3)
In my case, I have to also disable the debugger from stopping by issuing the command process handle SIGINT -s false.Seminarian
This gives error: No current process; cannot handle signals until you have a valid process. for me.Underpass
Even if you run that command after starting the process, it still doesn't cause ^C to be sent to the app as a SIGINT.Happenstance
U
2

The easiest way I found was just to send the process a SIGINT directly. Take the pid of the debuggee process (which process status will show you) and run

kill -INT <pid>

from another terminal.

Ultimately answered 21/8, 2014 at 15:30 Comment(2)
Note, you can also do platform shell kill -INT <pid> from within lldb. Note that this different from running ^C or "process interrupt" in lldb, which know that the interrupt signal is to implement the interrupt, and so will be suppressed.Socialist
This does not seem to work and it just ends up pausing the debugger. If done with platform shell, as nothing will seem to happen but as soon as you continue, it will immediately stop again in order to handle the interrupt signal.Jacquejacquelin

© 2022 - 2024 — McMap. All rights reserved.