Context: I am programming an interpreter for another platform, and this means that often, my program will load pointers from arbitrary integer data. When it comes to branches, I try to dereference for reading the next instruction’s address immediately, so that if the address is invalid, I get the segmentation fault inside the branch instruction’s method, and not some time later. This should make debugging easier.
However, this is not as helpful as I would have hoped for. When a segfault occurs there, it should be completely recoverable, since it was triggered by a dummy read, so I would like to be able to move the program’s instruction pointer back to the beginning of the method and reset the segfault.
Can I tell LLDB to ignore a SIGSEGV that has already made it to my program? I know that I can use process handle ... to decide which signals make it to my program, but that does not apply to signals the process is currently handling (or rather not handling).
(If it is not possible, I guess I could still ask lldb to stop on segfaults and not pass them to the program, but I’d at least like to know if it’s possible or not.)
I think you’re trying to work around an
EXC_BAD_ACCESSto put it properly. For instance, it sounds like you’re describing the dataptr in this example programYou’ll hit the first EXC_BAD_ACCESS on the
dataptrdereference in theprintfcall. You can change the variable to a valid value to continue execution. The one trick here is that the variabledataptrlives on the stack in my-O0compiled example, so you need to set the register that is being read at this point to get past it. Here I just use the start address ofmain()as a valid address in this program as a simple example.Now I’m stopped because I called through a NULL function pointer. Unwinding this takes a little extra x86_64 ABI knowledge but it’s not all that hard — set the pc to the caller’s return address, pop the stack one word and you’re back.
of course this is very by-hand tweaking here – not so easy to automate. You could express the null function pointer deref with a python function and add an lldb command to do it easily, but the null data pointer deref requires that you know what register was being accessed – maybe some clever pattern matching of the disassembly instruction could do the same thing with some python extension for common cases.
Hope that helps.