Question

I wrote a simple c program that makes use of the assert() call. I'd like to analyze it using lldb.

OS in use: OS X Mavericks

Compiler used to compile: Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin13.0.0 Thread model: posix

The -g compiler option generated a .DSYM directory. I wanted to know how to how to analyze this core using lldb.

PS: I have compiled using the -g option (clang -g test.c)

Was it helpful?

Solution

Start lldb and then execute the command

target create --core /cores/core.NNNN

where "/cores/core.NNNN" is your core file. A simple example:

$ lldb

(lldb) target create --core /cores/core.5884
Core file '/cores/core.5884' (x86_64) was loaded.
Process 0 stopped
* thread #1: tid = 0x0000, 0x00007fff8873c866 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGSTOP
    frame #0: 0x00007fff8873c866 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill + 10:
-> 0x7fff8873c866:  jae    0x7fff8873c870            ; __pthread_kill + 20
   0x7fff8873c868:  movq   %rax, %rdi
   0x7fff8873c86b:  jmpq   0x7fff88739175            ; cerror_nocancel
   0x7fff8873c870:  ret    

(lldb) bt
* thread #1: tid = 0x0000, 0x00007fff8873c866 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGSTOP
    frame #0: 0x00007fff8873c866 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff85de835c libsystem_pthread.dylib`pthread_kill + 92
    frame #2: 0x00007fff87554bba libsystem_c.dylib`abort + 125
    frame #3: 0x00007fff8751ea5f libsystem_c.dylib`__assert_rtn + 321
    frame #4: 0x000000010c867f59 a.out`main(argc=1, argv=0x00007fff53398c50) + 89 at prog.c:7
    frame #5: 0x00007fff872b65fd libdyld.dylib`start + 1

(lldb) frame select 4
frame #4: 0x000000010c867f59 a.out`main(argc=1, argv=0x00007fff53398c50) + 89 at prog.c:7
   4    int main(int argc, char **argv)
   5    {
   6        int i = 0;
-> 7        assert(i != 0);
   8        return 0;
   9    }
   10   

(lldb) p i
(int) $0 = 0

OTHER TIPS

At the command prompt, in the same directory where you have the symbols directory, type

lldb program-name 

then use the commands you want as in this official gdb to lldb command map:

lldb-gdb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top