Skip to content

Instantly share code, notes, and snippets.

@joesavage joesavage/commands.txt
Last active Aug 11, 2016

Embed
What would you like to do?
`dwarfdump` on macOS and Linux
=== macOS
$ clang -v
Apple LLVM version 7.0.2 (clang-700.1.81)
<snip>
$ clang hello.c -g -o hello.out
$ dwarfdump hello.out # NOTE: macOS-specific binary that reads Mach-O rather than ELF executables
----------------------------------------------------------------------
File: hello.out (x86_64)
----------------------------------------------------------------------
.debug_info contents:
< EMPTY >
$ nm hello.out
0000000100000000 T __mh_execute_header
0000000100000f20 T _main
U _printf
0000000100000ed0 T _send_message
U dyld_stub_binder
=== Linux
$ gcc -v
<snip>
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
$ gcc hello.c -g -o hello.out
$ dwarfdump hello.out
.debug_info
COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000b> DW_TAG_compile_unit
DW_AT_producer "GNU C 4.8.4 -mtune=generic -march=x86-64 -g -fstack-protector"
DW_AT_language DW_LANG_C89
DW_AT_name "hello.c"
DW_AT_comp_dir "/home/deploy"
DW_AT_low_pc 0x0040052d
DW_AT_high_pc <offset-from-lowpc>121
DW_AT_stmt_list 0x00000000
LOCAL_SYMBOLS:
< 1><0x0000002d> DW_TAG_base_type
DW_AT_byte_size 0x00000008
DW_AT_encoding DW_ATE_unsigned
DW_AT_name "long unsigned int"
< 1><0x00000034> DW_TAG_base_type
DW_AT_byte_size 0x00000001
DW_AT_encoding DW_ATE_unsigned_char
DW_AT_name "unsigned char"
< 1><0x0000003b> DW_TAG_base_type
DW_AT_byte_size 0x00000002
DW_AT_encoding DW_ATE_unsigned
DW_AT_name "short unsigned int"
< 1><0x00000042> DW_TAG_base_type
DW_AT_byte_size 0x00000004
DW_AT_encoding DW_ATE_unsigned
DW_AT_name "unsigned int"
< 1><0x00000049> DW_TAG_base_type
DW_AT_byte_size 0x00000001
DW_AT_encoding DW_ATE_signed_char
DW_AT_name "signed char"
< 1><0x00000050> DW_TAG_base_type
DW_AT_byte_size 0x00000002
DW_AT_encoding DW_ATE_signed
DW_AT_name "short int"
< 1><0x00000057> DW_TAG_base_type
DW_AT_byte_size 0x00000004
DW_AT_encoding DW_ATE_signed
DW_AT_name "int"
< 1><0x0000005e> DW_TAG_base_type
DW_AT_byte_size 0x00000008
DW_AT_encoding DW_ATE_signed
DW_AT_name "long int"
< 1><0x00000065> DW_TAG_base_type
DW_AT_byte_size 0x00000008
DW_AT_encoding DW_ATE_unsigned
DW_AT_name "sizetype"
< 1><0x0000006c> DW_TAG_pointer_type
DW_AT_byte_size 0x00000008
DW_AT_type <0x00000072>
< 1><0x00000072> DW_TAG_base_type
DW_AT_byte_size 0x00000001
DW_AT_encoding DW_ATE_signed_char
DW_AT_name "char"
< 1><0x00000079> DW_TAG_structure_type
DW_AT_name "message"
DW_AT_byte_size 0x00000010
DW_AT_decl_file 0x00000001 /home/deploy/hello.c
DW_AT_decl_line 0x00000003
DW_AT_sibling <0x0000009e>
< 2><0x00000085> DW_TAG_member
DW_AT_name "text"
DW_AT_decl_file 0x00000001 /home/deploy/hello.c
DW_AT_decl_line 0x00000004
DW_AT_type <0x0000006c>
DW_AT_data_member_location 0
< 2><0x00000091> DW_TAG_member
DW_AT_name "recipient"
DW_AT_decl_file 0x00000001 /home/deploy/hello.c
DW_AT_decl_line 0x00000005
DW_AT_type <0x0000006c>
DW_AT_data_member_location 8
< 1><0x0000009e> DW_TAG_subprogram
DW_AT_external yes(1)
DW_AT_name "send_message"
DW_AT_decl_file 0x00000001 /home/deploy/hello.c
DW_AT_decl_line 0x00000008
DW_AT_prototyped yes(1)
DW_AT_low_pc 0x0040052d
DW_AT_high_pc <offset-from-lowpc>71
DW_AT_frame_base len 0x0001: 9c: DW_OP_call_frame_cfa
DW_AT_GNU_all_tail_call_sitesyes(1)
DW_AT_sibling <0x000000c8>
< 2><0x000000bb> DW_TAG_formal_parameter
DW_AT_name "m"
DW_AT_decl_file 0x00000001 /home/deploy/hello.c
DW_AT_decl_line 0x00000008
DW_AT_type <0x00000079>
DW_AT_location len 0x0002: 9160: DW_OP_fbreg -32
< 1><0x000000c8> DW_TAG_subprogram
DW_AT_external yes(1)
DW_AT_name "main"
DW_AT_decl_file 0x00000001 /home/deploy/hello.c
DW_AT_decl_line 0x0000000d
DW_AT_prototyped yes(1)
DW_AT_type <0x00000057>
DW_AT_low_pc 0x00400574
DW_AT_high_pc <offset-from-lowpc>50
DW_AT_frame_base len 0x0001: 9c: DW_OP_call_frame_cfa
DW_AT_GNU_all_tail_call_sitesyes(1)
< 2><0x000000e5> DW_TAG_variable
DW_AT_name "m"
DW_AT_decl_file 0x00000001 /home/deploy/hello.c
DW_AT_decl_line 0x0000000e
DW_AT_type <0x00000079>
DW_AT_location len 0x0002: 9160: DW_OP_fbreg -32
.debug_line: line number info for a single cu
Source lines (from CU-DIE at .debug_info offset 0x0000000b):
<pc> [row,col] NS BB ET PE EB IS= DI= uri: "filepath"
NS new statement, BB new basic block, ET end of text sequence
PE prologue end, EB epilogue begin
IA=val ISA number, DI=val discriminator value
0x0040052d [ 8, 0] NS uri: "/home/deploy/hello.c"
0x00400546 [ 9, 0] NS
0x0040055c [ 10, 0] NS
0x00400572 [ 11, 0] NS
0x00400574 [ 13, 0] NS
0x0040057c [ 15, 0] NS
0x00400584 [ 16, 0] NS
0x0040058c [ 17, 0] NS
0x0040059f [ 18, 0] NS
0x004005a4 [ 19, 0] NS
0x004005a6 [ 19, 0] NS ET
.debug_pubnames
.debug_macinfo
.debug_string
name at offset 0x00000000, length 61 is 'GNU C 4.8.4 -mtune=generic -march=x86-64 -g -fstack-protector'
name at offset 0x0000003e, length 17 is 'long unsigned int'
name at offset 0x00000050, length 4 is 'text'
name at offset 0x00000055, length 9 is 'recipient'
name at offset 0x0000005f, length 13 is 'unsigned char'
name at offset 0x0000006d, length 4 is 'main'
name at offset 0x00000072, length 8 is 'long int'
name at offset 0x0000007b, length 12 is 'send_message'
name at offset 0x00000088, length 18 is 'short unsigned int'
name at offset 0x0000009b, length 9 is 'short int'
name at offset 0x000000a5, length 12 is '/home/deploy'
name at offset 0x000000b2, length 7 is 'hello.c'
name at offset 0x000000ba, length 8 is 'sizetype'
.debug_aranges
COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000b> DW_TAG_compile_unit
DW_AT_producer "GNU C 4.8.4 -mtune=generic -march=x86-64 -g -fstack-protector"
DW_AT_language DW_LANG_C89
DW_AT_name "hello.c"
DW_AT_comp_dir "/home/deploy"
DW_AT_low_pc 0x0040052d
DW_AT_high_pc <offset-from-lowpc>121
DW_AT_stmt_list 0x00000000
arange starts at 0x0040052d, length of 0x00000079, cu_die_offset = 0x0000000b
arange end
.debug_frame
.debug_static_func
.debug_static_vars
.debug_weaknames
$ nm hello.out
0000000000601040 B __bss_start
0000000000601040 b completed.6973
0000000000601030 D __data_start
0000000000601030 W data_start
0000000000400470 t deregister_tm_clones
00000000004004e0 t __do_global_dtors_aux
0000000000600e18 t __do_global_dtors_aux_fini_array_entry
0000000000601038 D __dso_handle
0000000000600e28 d _DYNAMIC
0000000000601040 D _edata
0000000000601048 B _end
0000000000400624 T _fini
0000000000400500 t frame_dummy
0000000000600e10 t __frame_dummy_init_array_entry
00000000004007a0 r __FRAME_END__
0000000000601000 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
00000000004003e0 T _init
0000000000600e18 t __init_array_end
0000000000600e10 t __init_array_start
0000000000400630 R _IO_stdin_used
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
0000000000600e20 d __JCR_END__
0000000000600e20 d __JCR_LIST__
w _Jv_RegisterClasses
0000000000400620 T __libc_csu_fini
00000000004005b0 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000400574 T main
U printf@@GLIBC_2.2.5
00000000004004a0 t register_tm_clones
000000000040052d T send_message
0000000000400440 T _start
0000000000601040 D __TMC_END__
$ nm hello.out
0000000000601040 B __bss_start
0000000000601040 b completed.6973
0000000000601030 D __data_start
0000000000601030 W data_start
0000000000400470 t deregister_tm_clones
00000000004004e0 t __do_global_dtors_aux
0000000000600e18 t __do_global_dtors_aux_fini_array_entry
0000000000601038 D __dso_handle
0000000000600e28 d _DYNAMIC
0000000000601040 D _edata
0000000000601048 B _end
0000000000400624 T _fini
0000000000400500 t frame_dummy
0000000000600e10 t __frame_dummy_init_array_entry
00000000004007a0 r __FRAME_END__
0000000000601000 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
00000000004003e0 T _init
0000000000600e18 t __init_array_end
0000000000600e10 t __init_array_start
0000000000400630 R _IO_stdin_used
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
0000000000600e20 d __JCR_END__
0000000000600e20 d __JCR_LIST__
w _Jv_RegisterClasses
0000000000400620 T __libc_csu_fini
00000000004005b0 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000400574 T main
U printf@@GLIBC_2.2.5
00000000004004a0 t register_tm_clones
000000000040052d T send_message
0000000000400440 T _start
0000000000601040 D __TMC_END__
#include <stdio.h>
struct message {
char *text;
char *recipient;
};
void send_message(struct message m) {
printf("To %s:\n", m.recipient);
printf("\t%s\n", m.text);
}
int main(void) {
struct message m;
m.text = "Hello, World!";
m.recipient = "Joe";
send_message(m);
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.