1

I frequently run matlab in lldb to debug some shared libraries and would like to make a lldb script so rather than typing out the following two lines.

process handle --pass true --stop false --notify true SIGSEGV process handle --pass true --stop false --notify true SIGBUS

I could create a file at ~/.lldb/ignore_sigs but im not sure what to put in that file.

Sam P
  • 681
  • 5
  • 19

4 Answers4

1

The way "process handle" works, you have to have a running process to attach the signal behaviors to; it doesn't adhere to the target. So you will need to do this once you have a process. The easiest way to do that is to set a breakpoint on main in your .lldbinit file, and add the commands to that breakpoint:

break set -n main -C "process handle..." -C "process handle..."

Breakpoints set in the .lldbinit file get inherited by all lldb debugging sessions. If you only want this to apply to your matlab debugging sessions, you could make a Python command that checks the name of your target executable and only does the process handle if it is matlab, and then runs the process handle commands. You could then call that Python command from the breakpoint as shown above.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
0

I ended up creating a file in ~/.lldb/ignoreSigs.py

with the following content

import lldb

def ignoreSigs(debugger, command, result, dict):
    debugger.HandleCommand("process handle --pass true --stop false --notify true SIGSEGV")
    debugger.HandleCommand("process handle --pass true --stop false --notify true SIGBUS")

def __lldb_init_module (debugger, dict):
  debugger.HandleCommand('command script add -f ignoreSigs.ignoreSigs ignoreSigs')

Then I added the following line to ~/.lldbinit

comma script import ~/.lldb/ignoreSigs.py

After launching matlab I am able to disable signals via

matlab -Dlldb
run 
#Wait for first signal to occur.
ignoreSigs
Sam P
  • 681
  • 5
  • 19
  • You can actually pass multiple signal names to the same `process handle` command. So for example, you can use just `process handle --pass true --stop false --notify true SIGSEGV SIGBUS` and even add more at the end. Run this command in the lldb console to see more info: `help process handle` – Ben Baron Mar 03 '20 at 00:41
  • You can also just omit the signal name entirely to apply to all signals if you want that behavior. Though I'm not sure it'll work in a script since it prompts asking if you are sure (and setting it in a breakpoint in Xcode didn't work for me, but running it manually did). – Ben Baron Mar 03 '20 at 00:43
0

Jim Ingham's approach worked for me, the only downside was that the breakpoint in main got hit multiple times in different functions, e.g. when iOS app got in the background. I added -o true and now it hits only once:

break set -n main -o true -C "process handle --stop false --notify false SIGUSR1 SIGUSR2"

Got it from lldb's help:

lldb

help breakpoint set

-o <boolean> ( --one-shot <boolean> )
       The breakpoint is deleted the first time it stop causes a stop.
0

It is possible to configure lldb with a script so that there won't be a need to enter any commands manually.

Find a script in the other question: https://stackoverflow.com/a/70312647/147805

Codeguard
  • 7,787
  • 2
  • 38
  • 41