Skip to content

Instantly share code, notes, and snippets.

@LnL7
Created March 27, 2020 22:14
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 LnL7/f0669b6fff02af1df535e8fc6f91d8bd to your computer and use it in GitHub Desktop.
Save LnL7/f0669b6fff02af1df535e8fc6f91d8bd to your computer and use it in GitHub Desktop.
$ lldb ./result/bin/hello
(lldb) target create "./result/bin/hello"
Current executable set to './result/bin/hello' (x86_64).
(lldb) run
Process 27935 launched: '/src/nixpkgs/result/bin/hello' (x86_64)
warning: (x86_64) /src/nixpkgs/result/bin/hello(0x0000000100000000) address 0x0000000100000000 maps to more than one section: hello.__TEXT and hello.__TEXT
warning: (x86_64) /src/nixpkgs/result/bin/hello(0x0000000100000000) address 0x0000000100001000 maps to more than one section: hello.__DATA and hello.__DATA
Process 27935 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x42)
frame #0: 0x0000000100000f64 hello`main + 4
hello`main:
-> 0x100000f64 <+4>: movl $0x1, 0x42
0x100000f6f <+15>: leaq 0x2c(%rip), %rdi ; "Hello, %s\n"
0x100000f76 <+22>: xorl %eax, %eax
0x100000f78 <+24>: callq 0x100000f82 ; symbol stub for: printf
Target 0: (hello) stopped.
$ lldb ./result/bin/hello
(lldb) target create "./result/bin/hello"
Current executable set to './result/bin/hello' (x86_64).
(lldb) add-dsym ./result-debug/lib/debug/hello.dSYM
symbol file '/src/nixpkgs/result-debug/lib/debug/hello.dSYM/Contents/Resources/DWARF/hello' has been added to '/src/nixpkgs/result/bin/hello'
(lldb) run
Process 27955 launched: '/src/nixpkgs/result/bin/hello' (x86_64)
warning: (x86_64) /src/nixpkgs/result/bin/hello address 0x0000000100000000 maps to more than one section: hello.__TEXT and hello.__TEXT
warning: (x86_64) /src/nixpkgs/result/bin/hello address 0x0000000100001000 maps to more than one section: hello.__DATA and hello.__DATA
hello was compiled with optimization - stepping may behave oddly; variables may not be available.
Process 27955 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x42)
frame #0: 0x0000000100000f64 hello`main [inlined] there_is_no_spoon at bmrwi0065zqf48kn4qjcfpafa3d1kxir-hello.c:5:10 [opt]
2
3 void there_is_no_spoon() {
4 int* ptr = 0x42;
-> 5 *ptr = 1;
6 }
7
8 int main(int argc, char* argv[]) {
Target 0: (hello) stopped.
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "hello-0.0.0";
src = ./hello.c;
outputs = [ "out" "debug" ];
unpackPhase = ":";
buildPhase = ''
$CC -g -o hello $src
'';
installPhase = ''
mkdir -p $out/bin $debug/lib/debug
cp hello $out/bin
cp -r hello.dSYM $debug/lib/debug
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment