How to effectively rollback a segment error using lldb?

I am new to LLDB (well, actually new to most command line tools). When I followed this extremely simple and helpful article to return a segmentation fault, I found my output on Mac OS X 10.10 using LLDB is different from the output of the author who used gdb as a debugger.

To make the problem clearer. After I ran the same code in the above article using lldb, encountered a segment error error and used the bt

lldb command , I got this message.

* thread #1: tid = 0x208541, 0x00007fff8869a05a libsystem_platform.dylib`_platform_memmove$VARIANT$Unknown + 186, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00007fff8869a05a libsystem_platform.dylib`_platform_memmove$VARIANT$Unknown + 186
    frame #1: 0x00007fff8fc08866 libsystem_c.dylib`fgets + 243
    frame #2: 0x0000000100000f34 sf`main + 68
    frame #3: 0x00007fff8e6535c9 libdyld.dylib`start + 1

      

Since I named my executable as "sf" (short for segment error), I followed the idea in the article and used the command f 2

.

Now things have gone wrong because I received this message.

frame #2: 0x0000000100000f34 sf`main + 68
sf`main:
    0x100000f34 <+68>: leaq   0x5f(%rip), %rdi          ; "%s\n"
    0x100000f3b <+75>: movq   -0x18(%rbp), %rsi
    0x100000f3f <+79>: movq   %rax, -0x20(%rbp)
    0x100000f43 <+83>: movb   $0x0, %al

      

It looks like assembly language and is really useless compared to the C language given by gdb, as shown in the article above, which:

#3  0x80484b2 in main (argc=1, argv=0xbffffaf4) at segfault.c:10
10        fgets(buf, 1024, stdin)

      

So my question is, can I get the C language backlink using LLDB?

+3


source to share


1 answer


When compiling, you need to add a flag -g

. Also, I would recommend using a flag -O0

that tells the compiler to do minimal optimization. With more aggressive optimizations, you can get strange behavior in the debugger. Usually, when I try to track down seg errors and similar errors, I find the conditional breakpoint and watchpoint to be the most useful of the commands. You can set a conditional breakpoint at the line number by executing breakpoint set --file <filename> --line <line number> --condition '<some C expression>'

. Viewpoints can be set using w s e -- <address>

, where <address>

is the viewpoint.



+1


source







All Articles