Lldb break at SIGSEGV

From the Linux / gdb world, by default gdb interrupts program execution when SEGV is detected before the default handler clears the process.

How can lldb do a similar trick? Currently, the process just ends, making it impossible to request a return line, etc.


Edit : proccess handle -p true -n true -s true try - no result: (

 (lldb) process handle -p true -n true -s true SIGSEGV NAME PASS STOP NOTIFY ========== ===== ===== ====== SIGSEGV true true true (lldb) run Process 97630 launched: '/Volumes/My Finder Extensions 1/My_Daemon.app/Contents/PlugIns/My_ShellExt.appex/Contents/MacOS/My_ShellExt' (x86_64) Process 97630 exited with status = 0 (0x00000000) Terminated due to signal 9 

Edit : additional information:

 (lldb) bt all error: invalid thread 

I suspect lldb not playing well with damaged stacks - I am trying to track down a problem with the _NSExtensionMain entry _NSExtensionMain or something down the line from there.

+5
source share
2 answers

you should type process handle SIGSEGV --notify true --pass true --stop true on lldb accordingly.

(lldb) SIGSEGV process handler --notify true --pass true --stop true

+3
source

I made a quick test program,

 #include <signal.h> #include <stdio.h> #include <unistd.h> void handler (int in) { puts ("signal received"); } int main () { signal (SIGSEGV, handler); kill (getpid (), SIGSEGV); return 0; } 

Then I will try to debug it, where I will tell lldb so that it stops at SIGSEGV :

 (lldb) br s -n main (lldb) r (lldb) pr h -p true -n true -s true SIGSEGV NAME PASS STOP NOTIFY ========== ===== ===== ====== SIGSEGV true true true (lldb) c Process 5024 resuming Process 5024 stopped (lldb) bt * thread #1: tid = 0x19d6ae, 0x00007fff8f27fc7e libsystem_kernel.dylib`__kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGSEGV * #0: 0x00007fff8f27fc7e libsystem_kernel.dylib`__kill + 10 #1: 0x0000000100000f25 a.out`main + 53 at ac:13 #2: 0x00007fff8c0e65c9 libdyld.dylib`start + 1 (lldb) c Process 5024 resuming signal received Process 5024 exited with status = 0 (0x00000000) (lldb) 

OK, so it looks like we expected. I can also ask lldb to just send a signal without stopping:

 (lldb) br s -n main (lldb) r (lldb) pr h -p true -n true -s false SIGSEGV NAME PASS STOP NOTIFY ========== ===== ===== ====== SIGSEGV true false true (lldb) c Process 5055 resuming Process 5055 stopped and restarted: thread 1 received signal: SIGSEGV signal received Process 5055 exited with status = 0 (0x00000000) (lldb) 

and it looks like he did what we wanted: lldb notified us that the signal was received and then sent to the program.

This is on Mac OS X with Xcode 6 installed.

0
source

Source: https://habr.com/ru/post/1205362/


All Articles