159bb9b91SPavel Labath# REQUIRES: x86 259bb9b91SPavel Labath 359bb9b91SPavel Labath# RUN: split-file %s %t 459bb9b91SPavel Labath# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %t/input.s -o %t/input.o 559bb9b91SPavel Labath# RUN: %lldb %t/input.o -o "command script import %t/script.py" -o exit | FileCheck %s 659bb9b91SPavel Labath 759bb9b91SPavel Labath# CHECK: Found 1 function(s). 851b74bb9SPavel Labath# CHECK: foo: [input.o[0x0-0xe), input.o[0x14-0x1c)] 9*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0x0]: cmpl $0x0, %edi 10*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0x3]: je 0x14 11*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0x5]: jmp 0x7 12*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0x7]: callq 0xe 13*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0xc]: jmp 0x1b 14*eb96c8c1SPavel Labath# CHECK-EMPTY: 15*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0x14]: callq 0x19 16*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0x19]: jmp 0x1b 17*eb96c8c1SPavel Labath# CHECK-NEXT: input.o[0x1b]: retq 18*eb96c8c1SPavel Labath 1959bb9b91SPavel Labath 2059bb9b91SPavel Labath#--- script.py 2159bb9b91SPavel Labathimport lldb 2259bb9b91SPavel Labath 2359bb9b91SPavel Labathdef __lldb_init_module(debugger, internal_dict): 2459bb9b91SPavel Labath target = debugger.GetSelectedTarget() 2559bb9b91SPavel Labath sym_ctxs = target.FindFunctions("foo") 2659bb9b91SPavel Labath print(f"Found {len(sym_ctxs)} function(s).") 2759bb9b91SPavel Labath for ctx in sym_ctxs: 2859bb9b91SPavel Labath fn = ctx.function 2959bb9b91SPavel Labath print(f"{fn.name}: {fn.GetRanges()}") 30*eb96c8c1SPavel Labath print(fn.GetInstructions(target)) 3159bb9b91SPavel Labath 3259bb9b91SPavel Labath#--- input.s 3359bb9b91SPavel Labath# An example of a function which has been split into two parts. Roughly 3459bb9b91SPavel Labath# corresponds to this C code. 3559bb9b91SPavel Labath# int baz(); 3659bb9b91SPavel Labath# int bar() { return 47; } 3759bb9b91SPavel Labath# int foo(int flag) { return flag ? bar() : baz(); } 3859bb9b91SPavel Labath# The function bar has been placed "in the middle" of foo. 3959bb9b91SPavel Labath 4059bb9b91SPavel Labath .text 4159bb9b91SPavel Labath 4259bb9b91SPavel Labath .type foo,@function 4359bb9b91SPavel Labathfoo: 4459bb9b91SPavel Labath .cfi_startproc 4559bb9b91SPavel Labath cmpl $0, %edi 4659bb9b91SPavel Labath je foo.__part.2 4759bb9b91SPavel Labath jmp foo.__part.1 4859bb9b91SPavel Labath .cfi_endproc 4959bb9b91SPavel Labath.Lfoo_end: 5059bb9b91SPavel Labath .size foo, .Lfoo_end-foo 5159bb9b91SPavel Labath 5259bb9b91SPavel Labathfoo.__part.1: 5359bb9b91SPavel Labath .cfi_startproc 5459bb9b91SPavel Labath callq bar 5559bb9b91SPavel Labath jmp foo.__part.3 5659bb9b91SPavel Labath.Lfoo.__part.1_end: 5759bb9b91SPavel Labath .size foo.__part.1, .Lfoo.__part.1_end-foo.__part.1 5859bb9b91SPavel Labath .cfi_endproc 5959bb9b91SPavel Labath 6059bb9b91SPavel Labathbar: 6159bb9b91SPavel Labath .cfi_startproc 6259bb9b91SPavel Labath movl $47, %eax 6359bb9b91SPavel Labath retq 6459bb9b91SPavel Labath .cfi_endproc 6559bb9b91SPavel Labath.Lbar_end: 6659bb9b91SPavel Labath .size bar, .Lbar_end-bar 6759bb9b91SPavel Labath 6859bb9b91SPavel Labathfoo.__part.2: 6959bb9b91SPavel Labath .cfi_startproc 7059bb9b91SPavel Labath callq baz 7159bb9b91SPavel Labath jmp foo.__part.3 7259bb9b91SPavel Labath.Lfoo.__part.2_end: 7359bb9b91SPavel Labath .size foo.__part.2, .Lfoo.__part.2_end-foo.__part.2 7459bb9b91SPavel Labath .cfi_endproc 7559bb9b91SPavel Labath 7659bb9b91SPavel Labathfoo.__part.3: 7759bb9b91SPavel Labath .cfi_startproc 7859bb9b91SPavel Labath retq 7959bb9b91SPavel Labath.Lfoo.__part.3_end: 8059bb9b91SPavel Labath .size foo.__part.3, .Lfoo.__part.3_end-foo.__part.3 8159bb9b91SPavel Labath .cfi_endproc 8259bb9b91SPavel Labath 8359bb9b91SPavel Labath 8459bb9b91SPavel Labath .section .debug_abbrev,"",@progbits 8559bb9b91SPavel Labath .byte 1 # Abbreviation Code 8659bb9b91SPavel Labath .byte 17 # DW_TAG_compile_unit 8759bb9b91SPavel Labath .byte 1 # DW_CHILDREN_yes 8859bb9b91SPavel Labath .byte 37 # DW_AT_producer 8959bb9b91SPavel Labath .byte 8 # DW_FORM_string 9059bb9b91SPavel Labath .byte 19 # DW_AT_language 9159bb9b91SPavel Labath .byte 5 # DW_FORM_data2 9259bb9b91SPavel Labath .byte 17 # DW_AT_low_pc 9359bb9b91SPavel Labath .byte 1 # DW_FORM_addr 9459bb9b91SPavel Labath .byte 85 # DW_AT_ranges 9559bb9b91SPavel Labath .byte 35 # DW_FORM_rnglistx 9659bb9b91SPavel Labath .byte 116 # DW_AT_rnglists_base 9759bb9b91SPavel Labath .byte 23 # DW_FORM_sec_offset 9859bb9b91SPavel Labath .byte 0 # EOM(1) 9959bb9b91SPavel Labath .byte 0 # EOM(2) 10059bb9b91SPavel Labath .byte 2 # Abbreviation Code 10159bb9b91SPavel Labath .byte 46 # DW_TAG_subprogram 10259bb9b91SPavel Labath .byte 0 # DW_CHILDREN_no 10359bb9b91SPavel Labath .byte 17 # DW_AT_low_pc 10459bb9b91SPavel Labath .byte 1 # DW_FORM_addr 10559bb9b91SPavel Labath .byte 18 # DW_AT_high_pc 10659bb9b91SPavel Labath .byte 1 # DW_FORM_addr 10759bb9b91SPavel Labath .byte 3 # DW_AT_name 10859bb9b91SPavel Labath .byte 8 # DW_FORM_string 10959bb9b91SPavel Labath .byte 0 # EOM(1) 11059bb9b91SPavel Labath .byte 0 # EOM(2) 11159bb9b91SPavel Labath .byte 3 # Abbreviation Code 11259bb9b91SPavel Labath .byte 46 # DW_TAG_subprogram 11359bb9b91SPavel Labath .byte 0 # DW_CHILDREN_no 11459bb9b91SPavel Labath .byte 85 # DW_AT_ranges 11559bb9b91SPavel Labath .byte 35 # DW_FORM_rnglistx 11659bb9b91SPavel Labath .byte 64 # DW_AT_frame_base 11759bb9b91SPavel Labath .byte 24 # DW_FORM_exprloc 11859bb9b91SPavel Labath .byte 3 # DW_AT_name 11959bb9b91SPavel Labath .byte 8 # DW_FORM_string 12059bb9b91SPavel Labath .byte 0 # EOM(1) 12159bb9b91SPavel Labath .byte 0 # EOM(2) 12259bb9b91SPavel Labath .byte 0 # EOM(3) 12359bb9b91SPavel Labath 12459bb9b91SPavel Labath .section .debug_info,"",@progbits 12559bb9b91SPavel Labath.Lcu_begin0: 12659bb9b91SPavel Labath .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit 12759bb9b91SPavel Labath.Ldebug_info_start0: 12859bb9b91SPavel Labath .short 5 # DWARF version number 12959bb9b91SPavel Labath .byte 1 # DWARF Unit Type 13059bb9b91SPavel Labath .byte 8 # Address Size (in bytes) 13159bb9b91SPavel Labath .long .debug_abbrev # Offset Into Abbrev. Section 13259bb9b91SPavel Labath .byte 1 # Abbrev [1] DW_TAG_compile_unit 13359bb9b91SPavel Labath .asciz "Hand-written DWARF" # DW_AT_producer 13459bb9b91SPavel Labath .short 29 # DW_AT_language 13559bb9b91SPavel Labath .quad 0 # DW_AT_low_pc 13659bb9b91SPavel Labath .byte 1 # DW_AT_ranges 13759bb9b91SPavel Labath .long .Lrnglists_table_base0 # DW_AT_rnglists_base 13859bb9b91SPavel Labath .byte 2 # Abbrev [2] DW_TAG_subprogram 13959bb9b91SPavel Labath .quad bar # DW_AT_low_pc 14059bb9b91SPavel Labath .quad .Lbar_end # DW_AT_high_pc 14159bb9b91SPavel Labath .asciz "bar" # DW_AT_name 14259bb9b91SPavel Labath .byte 3 # Abbrev [3] DW_TAG_subprogram 14359bb9b91SPavel Labath .byte 0 # DW_AT_ranges 14459bb9b91SPavel Labath .byte 1 # DW_AT_frame_base 14559bb9b91SPavel Labath .byte 86 14659bb9b91SPavel Labath .asciz "foo" # DW_AT_name 14759bb9b91SPavel Labath .byte 0 # End Of Children Mark 14859bb9b91SPavel Labath.Ldebug_info_end0: 14959bb9b91SPavel Labath 15059bb9b91SPavel Labath .section .debug_rnglists,"",@progbits 15159bb9b91SPavel Labath .long .Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length 15259bb9b91SPavel Labath.Ldebug_list_header_start0: 15359bb9b91SPavel Labath .short 5 # Version 15459bb9b91SPavel Labath .byte 8 # Address size 15559bb9b91SPavel Labath .byte 0 # Segment selector size 15659bb9b91SPavel Labath .long 2 # Offset entry count 15759bb9b91SPavel Labath.Lrnglists_table_base0: 15859bb9b91SPavel Labath .long .Ldebug_ranges0-.Lrnglists_table_base0 15959bb9b91SPavel Labath .long .Ldebug_ranges1-.Lrnglists_table_base0 16059bb9b91SPavel Labath.Ldebug_ranges0: 16159bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 16259bb9b91SPavel Labath .quad foo 16359bb9b91SPavel Labath .quad .Lfoo_end 16459bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 16559bb9b91SPavel Labath .quad foo.__part.1 16659bb9b91SPavel Labath .quad .Lfoo.__part.1_end 16759bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 16859bb9b91SPavel Labath .quad foo.__part.2 16959bb9b91SPavel Labath .quad .Lfoo.__part.2_end 17059bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 17159bb9b91SPavel Labath .quad foo.__part.3 17259bb9b91SPavel Labath .quad .Lfoo.__part.3_end 17359bb9b91SPavel Labath .byte 0 # DW_RLE_end_of_list 17459bb9b91SPavel Labath.Ldebug_ranges1: 17559bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 17659bb9b91SPavel Labath .quad bar 17759bb9b91SPavel Labath .quad .Lbar_end 17859bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 17959bb9b91SPavel Labath .quad foo.__part.1 18059bb9b91SPavel Labath .quad .Lfoo.__part.1_end 18159bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 18259bb9b91SPavel Labath .quad foo.__part.2 18359bb9b91SPavel Labath .quad .Lfoo.__part.2_end 18459bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 18559bb9b91SPavel Labath .quad foo.__part.3 18659bb9b91SPavel Labath .quad .Lfoo.__part.3_end 18759bb9b91SPavel Labath .byte 6 # DW_RLE_start_end 18859bb9b91SPavel Labath .quad foo 18959bb9b91SPavel Labath .quad .Lfoo_end 19059bb9b91SPavel Labath .byte 0 # DW_RLE_end_of_list 19159bb9b91SPavel Labath.Ldebug_list_header_end0: 19259bb9b91SPavel Labath 19359bb9b91SPavel Labath .section ".note.GNU-stack","",@progbits 194