<p dir="ltr">Thanks for the report Eugene.</p>
<p dir="ltr">I think because it's an exception on Darwin.</p>
<p dir="ltr">I think that it should be reported as a signal because that's what it is. Interested to hear from the apple guys though.</p>
<p dir="ltr">Vince<br>
</p>
<div class="gmail_quote">On May 19, 2015 3:37 AM, "Pavel Labath" <<a href="mailto:labath@google.com">labath@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Eugene,<br>
<br>
thanks for the report. What you are describing sounds like a genuine<br>
LLDB problem. I have created a bug<br>
<<a href="https://llvm.org/bugs/show_bug.cgi?id=23571" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=23571</a>> so we don't forget about<br>
this. It looks like LLGS (server component of lldb) is reporting this<br>
segfault to LLDB as an "exception" rather than a signal<br>
(reason:expection in the stop-reply packet). This causes LLDB to not<br>
reinject the signal when continuing the inferior. Now there are two<br>
places we can fix this:<br>
- have LLGS report this event as a signal. Then LLDB should be able to<br>
reinject the signal correctly.<br>
- teach LLDB to reinject the signal even in when the stop was reported<br>
as an exception.<br>
<br>
I'm inclined to do the first thing but I am not sure. Could somebody<br>
with more LLDB knowledge shed some light on this? What is the intended<br>
usage/behavior in case LLGS reports reason:exception?<br>
<br>
cheers,<br>
pl<br>
<br>
<br>
<br>
On 18 May 2015 at 18:27, Eugene Birukov <<a href="mailto:eugenebi@hotmail.com">eugenebi@hotmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> I am running Linux Ubuntu 14.04 and I tried both LLDB-3.6 (installed<br>
> binaries using apt-get) and LLDB-3.7 (built from sources sync'ed to trunk),<br>
> the result is the same.<br>
><br>
> I have a simple program (the source code is at the bottom of the message)<br>
> that maps a page of memory as not accessible, installs a SIGSEGV handler<br>
> that remaps this page as read-write, and then tries to read from it. So, the<br>
> expected result is that program initially receives SIGSEGV but happily<br>
> continues after the handler fixes the problem.<br>
><br>
> The program runs as expected, both standalone and under GDB:<br>
><br>
><br>
> $ ./mm<br>
> signal 11 received<br>
> success 777<br>
><br>
><br>
> $ gdb --quiet ./mm<br>
> Reading symbols from ./mm...done.<br>
> (gdb) r<br>
> Starting program: /home/eugene/tmp/mm<br>
> Program received signal SIGSEGV, Segmentation fault.<br>
> 0x0000000000400acc in main () at mm.cpp:27<br>
> 27 int x = *(int*)address;<br>
> (gdb) c<br>
> Continuing.<br>
> signal 11 received<br>
> success 777<br>
> [Inferior 1 (process 14155) exited normally]<br>
> (gdb) q<br>
><br>
> But under LLDB it spins forever on failing instruction without invoking the<br>
> signal handler. Also, setting "process handle" does not have any effect at<br>
> all:<br>
><br>
><br>
> $ ~/llvm/bin/lldb ./mm<br>
> (lldb) target create "./mm"<br>
> Current executable set to './mm' (x86_64).<br>
> (lldb) br se -b main<br>
> Breakpoint 1: where = mm`main + 30 at mm.cpp:24, address =<br>
> 0x0000000000400a7e<br>
> (lldb) pr lau<br>
> Process 14194 launched: './mm' (x86_64)<br>
> Process 14194 stopped<br>
> * thread #1: tid = 14194, 0x0000000000400a7e mm`main + 30 at mm.cpp:24, name<br>
> = 'mm', stop reason = breakpoint 1.1<br>
> frame #0: 0x0000000000400a7e mm`main + 30 at mm.cpp:24<br>
> 21<br>
> 22 int main()<br>
> 23 {<br>
> -> 24 sigset(SIGSEGV, handler);<br>
> 25<br>
> 26 address = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS |<br>
> MAP_PRIVATE, -1, 0);<br>
> 27 int x = *(int*)address;<br>
> (lldb) pr ha SIGSEGV -s false -p true -n false<br>
> NAME PASS STOP NOTIFY<br>
> ========== ===== ===== ======<br>
> SIGSEGV true false false<br>
> (lldb) c<br>
> Process 14194 resuming<br>
> Process 14194 stopped<br>
> * thread #1: tid = 14194, 0x0000000000400acc mm`main + 108 at mm.cpp:27,<br>
> name = 'mm', stop reason = address access protected (fault address:<br>
> 0x7ffff7ff7000)<br>
> frame #0: 0x0000000000400acc mm`main + 108 at mm.cpp:27<br>
> 24 sigset(SIGSEGV, handler);<br>
> 25<br>
> 26 address = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS |<br>
> MAP_PRIVATE, -1, 0);<br>
> -> 27 int x = *(int*)address;<br>
> 28 std::cout << (signaled ? "success " : "failure ") << x << "\n";<br>
> 29 }<br>
> (lldb) c<br>
> Process 14194 resuming<br>
> Process 14194 stopped<br>
> * thread #1: tid = 14194, 0x0000000000400acc mm`main + 108 at mm.cpp:27,<br>
> name = 'mm', stop reason = address access protected (fault address:<br>
> 0x7ffff7ff7000)<br>
> frame #0: 0x0000000000400acc mm`main + 108 at mm.cpp:27<br>
> 24 sigset(SIGSEGV, handler);<br>
> 25<br>
> 26 address = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS |<br>
> MAP_PRIVATE, -1, 0);<br>
> -> 27 int x = *(int*)address;<br>
> 28 std::cout << (signaled ? "success " : "failure ") << x << "\n";<br>
> 29 }<br>
> (lldb) c<br>
> Process 14194 resuming<br>
> Process 14194 stopped<br>
> * thread #1: tid = 14194, 0x0000000000400acc mm`main + 108 at mm.cpp:27,<br>
> name = 'mm', stop reason = address access protected (fault address:<br>
> 0x7ffff7ff7000)<br>
> frame #0: 0x0000000000400acc mm`main + 108 at mm.cpp:27<br>
> 24 sigset(SIGSEGV, handler);<br>
> 25<br>
> 26 address = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS |<br>
> MAP_PRIVATE, -1, 0);<br>
> -> 27 int x = *(int*)address;<br>
> 28 std::cout << (signaled ? "success " : "failure ") << x << "\n";<br>
> 29 }<br>
> (lldb)<br>
><br>
> So, do I miss some LLDB setting?<br>
> Here is the program code:<br>
><br>
><br>
> $ cat mm.cpp<br>
> #include <iostream><br>
> #include <sys/mman.h><br>
> #include <signal.h><br>
> #include <assert.h><br>
> #include <sys/types.h><br>
> #include <unistd.h><br>
><br>
> void* address;<br>
> size_t size = 0x1000;<br>
> bool signaled = false;<br>
><br>
> void handler(int sig)<br>
> {<br>
> std::cout << "signal " << sig << " received\n";<br>
> signaled = true;<br>
> munmap(address, size);<br>
> void* newaddr = mmap(address, size, PROT_READ | PROT_WRITE,<br>
> MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, -1, 0);<br>
> assert(newaddr == address);<br>
> *(int*)newaddr = 777;<br>
> }<br>
><br>
> int main()<br>
> {<br>
> sigset(SIGSEGV, handler);<br>
> address = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1,<br>
> 0);<br>
> int x = *(int*)address;<br>
> std::cout << (signaled ? "success " : "failure ") << x << "\n";<br>
> }<br>
> $<br>
><br>
> Thanks,<br>
> Eugene<br>
><br>
><br>
><br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
><br>
_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
</blockquote></div>