Skip to content

Instantly share code, notes, and snippets.

@HarryWeppner HarryWeppner/lldb Secret
Last active Jan 3, 2016

Embed
What would you like to do?
Compiled mytest with FreeBSD clang version 3.3 that uses a shared library (based on mylib.c). The assembly and the lldb symbol lookup don't seem to match, i.e. the instruction at address 0x400878 uses "a" in 0x600c08, which is in the range of mytest (rather than the shared library where "a" is held at 0x0000000800a1b820). Note: using gdb shows t…
(lldb) bt
* thread #1: tid = 12678, 0x0000000000400878 mytest`main + 40 at mytest.c:10, stop reason = breakpoint 1.1
frame #0: 0x0000000000400878 mytest`main + 40 at mytest.c:10
frame #1: 0x000000000040076f mytest`_start + 335
(lldb) di -l
mytest`main + 40 at mytest.c:10
9 j=get_a();
-> 10 if (a==i) {
11 // nop
-> 0x400878: movl 0x600c08, %eax
0x40087f: cmpl -0x8(%rbp), %eax
0x400882: jne 0x40088d ; main + 61 at mytest.c:12
(lldb) im loo -a 0x600c080
(lldb) p/x &a
(int *) $1 = 0x0000000800a1b820
(lldb) im loo -a 0x800a1b820
Address: libbss.so.1[0x0000000000200820] (libbss.so.1..bss + 0)
Summary: libbss.so.1`a
(lldb) p/x a
(int) $2 = 0x00000000
(lldb) p/x i
(int) $3 = 0x00000001
(lldb) expr -- a == i
(bool) $4 = false
(lldb) expr -- i == j
(bool) $5 = true
(lldb) c
(lldb) a: 1, i: 1, j:1
#include "mylib.h"
int a;
void set_a(int i){
a=i;
}
int get_a(){
return a;
}
extern int a;
void set_a(int i);
int get_a();
#include <stdio.h>
#include "../lib/mylib.h"
int main () {
int i,j;
i=1;
set_a(i);
j=get_a();
if (a==i) {
// nop
}
printf("a: %d, i: %d, j:%d\n",a, i, j);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.