0

I'm really new on LLDB. I'm trying to figure out why my C application sometimes breaks on a segmentation fault.

I've compiled my application with -g and started lldb pointing to the binary. So I ran the app with "run" code and when it crashes, LLDB shows me the message:

* thread #1: tid = 0x8817, 0x00007fffae0feb52 libsystem_c.dylib`strlen + 18, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00007fffae0feb52 libsystem_c.dylib`strlen + 18
libsystem_c.dylib`strlen:
->  0x7fffae0feb52 <+18>: pcmpeqb (%rdi), %xmm0
    0x7fffae0feb56 <+22>: pmovmskb %xmm0, %esi
    0x7fffae0feb5a <+26>: andq   $0xf, %rcx
    0x7fffae0feb5e <+30>: orq    $-0x1, %rax

I saw a "tutorial" where the person did the same thing as me, but for him LLDB showed his C source code and pointed the line where it crashed. For me I can only see this hex with assembly that I cannot trace.

What am I doing wrong?

Thank you guys.

EDIT:

Forgot to say that my app is only printing c* chars on terminal each second. Sometimes it take a few minutes to crash, sometimes it crashes after hours.

Gilbert
  • 443
  • 1
  • 4
  • 11
  • 2
    It's showing you the code in `strlen()` in the standard library, which is where the actual segfault is happening, but this isn't usually very useful to you. You should type `thread backtrace` and then `frame select n`, where `n` is the lowest numbered stack frame you see that's actually in the code you wrote. Then you can type `list` and get your actual source code where the problem is originating. – Crowman Mar 03 '17 at 23:32
  • Maybe take a look at how to get the correct debugging symbols when you compile: http://stackoverflow.com/questions/31122871/lldb-error-unable-to-resolve-breakpoint-to-any-actual-locations/31124996#31124996 – l'L'l Mar 04 '17 at 00:42
  • the most likely root cause of the seg fault event is the string that is being passed to `strlen()` does not have terminating `NUL` character within the bounds of the array containing the string. – user3629249 Mar 05 '17 at 02:54
  • This is crashing dereferencing rdi, which is the first argument passing register on x86_64, and the address accessed is 0x0 (which you can see from the stop reason.) So it is more likely a case where you passed strlen a null pointer. – Jim Ingham Mar 07 '17 at 02:44

0 Answers0