Skip to content

Instantly share code, notes, and snippets.

@mzyy94
Last active December 31, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzyy94/8017373 to your computer and use it in GitHub Desktop.
Save mzyy94/8017373 to your computer and use it in GitHub Desktop.
Last login: Wed Dec 18 12:10:55 on ttys006
mzyy94:~ mzyy94$ cd /Volumes/RamDisk/
mzyy94:RamDisk mzyy94$ gcc -g bus_error.c
mzyy94:RamDisk mzyy94$ lldb -- a.out
Current executable set to 'a.out' (x86_64).
(lldb) settings set target.run-args 0
(lldb) run
Process 67334 launched: '/Volumes/RamDisk/a.out' (x86_64)
Process 67334 stopped
* thread #1: tid = 0x50c5f, 0x0000000100000f43 a.out`main(argc=2, argv=0x00007fff5fbff838) + 115 at bus_error.c:9, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=2, address=0x100005000)
frame #0: 0x0000000100000f43 a.out`main(argc=2, argv=0x00007fff5fbff838) + 115 at bus_error.c:9
6 for(int i = 0; ; i++){
7 switch(mode) {
8 case '0':
-> 9 c[0] = s[i];
10 break;
11 case '1':
12 s[i] = '\0';
(lldb) disassemble --line
a.out`main + 111 at bus_error.c:9
8 case '0':
9 c[0] = s[i];
10 break;
0x100000f3f: movslq -24(%rbp), %rcx
-> 0x100000f43: movb (%rax,%rcx), %dl
0x100000f46: movb %dl, -17(%rbp)
(lldb) settings set target.run-args 1
(lldb) run
There is a running process, kill it and restart?: [Y/n]
Process 87838 launched: '/Volumes/RamDisk/a.out' (x86_64)
Process 87838 stopped
* thread #1: tid = 0x56584, 0x0000000100000f59 a.out`main(argc=2, argv=0x00007fff5fbff838) + 137 at bus_error.c:12, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=2, address=0x100002000)
frame #0: 0x0000000100000f59 a.out`main(argc=2, argv=0x00007fff5fbff838) + 137 at bus_error.c:12
9 c[0] = s[i];
10 break;
11 case '1':
-> 12 s[i] = '\0';
13 break;
14 case '2':
15 s[0] = c[i];
(lldb) disassemble --line
a.out`main + 133 at bus_error.c:12
11 case '1':
12 s[i] = '\0';
13 break;
0x100000f55: movslq -24(%rbp), %rcx
-> 0x100000f59: movb $0, (%rax,%rcx)
(lldb) settings set target.run-args 2
(lldb) run
There is a running process, kill it and restart?: [Y/n]
Process 94596 launched: '/Volumes/RamDisk/a.out' (x86_64)
Process 94596 stopped
* thread #1: tid = 0x5820c, 0x0000000100000f66 a.out`main(argc=2, argv=0x00007fff5fbff838) + 150 at bus_error.c:15, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x7fff5fc87000)
frame #0: 0x0000000100000f66 a.out`main(argc=2, argv=0x00007fff5fbff838) + 150 at bus_error.c:15
12 s[i] = '\0';
13 break;
14 case '2':
-> 15 s[0] = c[i];
16 break;
17 default:
18 c[i] = '\0';
(lldb) disassemble --line
a.out`main + 146 at bus_error.c:15
14 case '2':
15 s[0] = c[i];
16 break;
0x100000f62: movslq -24(%rbp), %rax
-> 0x100000f66: movb -17(%rbp,%rax), %cl
0x100000f6a: movb %cl, 144(%rip)
(lldb) settings set target.run-args 3
(lldb) run
There is a running process, kill it and restart?: [Y/n]
Process 95499 launched: '/Volumes/RamDisk/a.out' (x86_64)
Process 95499 stopped
* thread #1: tid = 0x585d2, 0x0000000100000f79 a.out`main(argc=0, argv=0x0000000000000000) + 169 at bus_error.c:18, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=2, address=0x7fff5fc00000)
frame #0: 0x0000000100000f79 a.out`main(argc=0, argv=0x0000000000000000) + 169 at bus_error.c:18
15 s[0] = c[i];
16 break;
17 default:
-> 18 c[i] = '\0';
19 }
20 }
21 return 0;
(lldb) disassemble --line
a.out`main + 165 at bus_error.c:18
17 default:
18 c[i] = '\0';
19 }
0x100000f75: movslq -24(%rbp), %rax
-> 0x100000f79: movb $0, -17(%rbp,%rax)
(lldb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment