杨勇勇
2014-Feb-19 07:10 UTC
[LLVMdev] [lldb-dev] How is variable info retrieved in debugging for executables generated by llvm backend?
Sorry, this is the attachment. 2014-02-19 15:08 GMT+08:00 杨勇勇 <triple.yang at gmail.com>:> Thank you. > > Here is an example and the attchment contains extra files including object > file and executable file. > I want to print for example the value of "a", but lldb command "frame > variable a" displays "0" and so does "b", and "c". > Meanwhile, the value is correct if I directly check registers or memory. > > Following content is composed of three part: > 1. C program. > 2. assembly file including directives of dwarf debug info. > 3. dwarf debug info dumpped from executable file with llvm-dwarfdump. > > > /////////////////////////////////////////////////////////////////////////////////////////// > // C > int > main(int argc, char *argv[]) > { > int a = 11; > int b = 22; > int c = a+b; > return c; > } > > ###################################### > # asm including dwarf debugging info > .file "test.c" > .section .debug_info,"", at progbits > Lsection_info: > .section .debug_abbrev,"", at progbits > Lsection_abbrev: > .section .debug_aranges,"", at progbits > .section .debug_macinfo,"", at progbits > .section .debug_line,"", at progbits > Lsection_line: > .section .debug_loc,"", at progbits > .section .debug_pubtypes,"", at progbits > .section .debug_str,"MS", at progbits,1 > Linfo_string: > .section .debug_ranges,"", at progbits > Ldebug_range: > .section .debug_loc,"", at progbits > Lsection_debug_loc: > .text > Ltext_begin: > .data > .file 1 "test.c" > .text > .global main > .type main, at function > main: # @main > Lfunc_begin0: > .loc 1 3 0 # test.c:3:0 > # BB#0: # %entry > .loc 1 2 0 prologue_end # test.c:2:0 > [SP + -4] = FP;; > [SP + -8] = J30;; > FP = SP;; > J31 = -40;; > SP = SP + J31;; > #DEBUG_VALUE: main:argc <- undef > #DEBUG_VALUE: main:argv <- undef > R2 = 0;; > R3 = 11;; > [FP + -12] = R2;; > [FP + -16] = R0;; > [FP + -20] = R1;; > .loc 1 4 0 # test.c:4:0 > [FP + -24] = R3;; > R2 = 22;; > .loc 1 5 0 # test.c:5:0 > [FP + -28] = R2;; > .loc 1 6 0 # test.c:6:0 > R3 = [FP + -24];; > R2 = R3 + R2 (T);; > [FP + -32] = R2;; > .loc 1 7 0 # test.c:7:0 > [FP + -36] = R0;; > R0 = R2;; > [FP + -40] = R1;; > SP = FP;; > J30 = [SP + -8];; > FP = [SP + -4];; > jump J30;; > Ltmp0: > Ltmp1: > .size main, Ltmp1-main > Lfunc_end0: > > Ltext_end: > .data > Ldata_end: > .text > Lsection_end1: > .section .debug_info,"", at progbits > L.debug_info_begin0: > .int 148 # Length of Compilation Unit Info > .short 2 # DWARF version number > .int L.debug_abbrev_begin # Offset Into Abbrev. Section > .byte 4 # Address Size (in bytes) > .byte 1 # Abbrev [1] 0xb:0x8d DW_TAG_compile_unit > .int Linfo_string0 # DW_AT_producer > .short 12 # DW_AT_language > .int Linfo_string1 # DW_AT_name > .int 0 # DW_AT_low_pc > .int Lsection_line # DW_AT_stmt_list > .int Linfo_string2 # DW_AT_comp_dir > .byte 2 # Abbrev [2] 0x22:0x5d DW_TAG_subprogram > .int Linfo_string3 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 2 # DW_AT_decl_line > # DW_AT_prototyped > .int 127 # DW_AT_type > # DW_AT_external > .int Lfunc_begin0 # DW_AT_low_pc > .int Lfunc_end0 # DW_AT_high_pc > .byte 2 # DW_AT_frame_base > .byte 144 > .byte 60 > .byte 3 # Abbrev [3] 0x38:0xe > DW_TAG_formal_parameter > .int Linfo_string5 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 2 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 24 > .byte 3 # Abbrev [3] 0x46:0xe > DW_TAG_formal_parameter > .int Linfo_string6 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 2 # DW_AT_decl_line > .int 146 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 20 > .byte 4 # Abbrev [4] 0x54:0xe DW_TAG_variable > .int Linfo_string8 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 4 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 16 > .byte 4 # Abbrev [4] 0x62:0xe DW_TAG_variable > .int Linfo_string9 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 5 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 12 > .byte 4 # Abbrev [4] 0x70:0xe DW_TAG_variable > .int Linfo_string10 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 6 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 8 > .byte 0 # End Of Children Mark > .byte 5 # Abbrev [5] 0x7f:0x7 DW_TAG_base_type > .int Linfo_string4 # DW_AT_name > .byte 5 # DW_AT_encoding > .byte 4 # DW_AT_byte_size > .byte 5 # Abbrev [5] 0x86:0x7 DW_TAG_base_type > .int Linfo_string7 # DW_AT_name > .byte 6 # DW_AT_encoding > .byte 1 # DW_AT_byte_size > .byte 6 # Abbrev [6] 0x8d:0x5 DW_TAG_pointer_type > .int 134 # DW_AT_type > .byte 6 # Abbrev [6] 0x92:0x5 DW_TAG_pointer_type > .int 141 # DW_AT_type > .byte 0 # End Of Children Mark > L.debug_info_end0: > .section .debug_abbrev,"", at progbits > L.debug_abbrev_begin: > .byte 1 # Abbreviation Code > .byte 17 # DW_TAG_compile_unit > .byte 1 # DW_CHILDREN_yes > .byte 37 # DW_AT_producer > .byte 14 # DW_FORM_strp > .byte 19 # DW_AT_language > .byte 5 # DW_FORM_data2 > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 17 # DW_AT_low_pc > .byte 1 # DW_FORM_addr > .byte 16 # DW_AT_stmt_list > .byte 6 # DW_FORM_data4 > .byte 27 # DW_AT_comp_dir > .byte 14 # DW_FORM_strp > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 2 # Abbreviation Code > .byte 46 # DW_TAG_subprogram > .byte 1 # DW_CHILDREN_yes > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 58 # DW_AT_decl_file > .byte 11 # DW_FORM_data1 > .byte 59 # DW_AT_decl_line > .byte 11 # DW_FORM_data1 > .byte 39 # DW_AT_prototyped > .byte 25 # DW_FORM_flag_present > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 63 # DW_AT_external > .byte 25 # DW_FORM_flag_present > .byte 17 # DW_AT_low_pc > .byte 1 # DW_FORM_addr > .byte 18 # DW_AT_high_pc > .byte 1 # DW_FORM_addr > .byte 64 # DW_AT_frame_base > .byte 10 # DW_FORM_block1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 3 # Abbreviation Code > .byte 5 # DW_TAG_formal_parameter > .byte 0 # DW_CHILDREN_no > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 58 # DW_AT_decl_file > .byte 11 # DW_FORM_data1 > .byte 59 # DW_AT_decl_line > .byte 11 # DW_FORM_data1 > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 2 # DW_AT_location > .byte 10 # DW_FORM_block1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 4 # Abbreviation Code > .byte 52 # DW_TAG_variable > .byte 0 # DW_CHILDREN_no > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 58 # DW_AT_decl_file > .byte 11 # DW_FORM_data1 > .byte 59 # DW_AT_decl_line > .byte 11 # DW_FORM_data1 > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 2 # DW_AT_location > .byte 10 # DW_FORM_block1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 5 # Abbreviation Code > .byte 36 # DW_TAG_base_type > .byte 0 # DW_CHILDREN_no > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 62 # DW_AT_encoding > .byte 11 # DW_FORM_data1 > .byte 11 # DW_AT_byte_size > .byte 11 # DW_FORM_data1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 6 # Abbreviation Code > .byte 15 # DW_TAG_pointer_type > .byte 0 # DW_CHILDREN_no > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 0 # EOM(3) > L.debug_abbrev_end: > .section .debug_aranges,"", at progbits > .section .debug_ranges,"", at progbits > .section .debug_macinfo,"", at progbits > .section .debug_str,"MS", at progbits,1 > Linfo_string0: > .asciz "clang version 3.3 (/opt/git.repo/clang.git/ > b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ > 57b428f0a6be7b81bc364b0088992b1f820b516e)" > Linfo_string1: > .asciz "test.c" > Linfo_string2: > .asciz "/home/yangyy/workspace/newlib" > Linfo_string3: > .asciz "main" > Linfo_string4: > .asciz "int" > Linfo_string5: > .asciz "argc" > Linfo_string6: > .asciz "argv" > Linfo_string7: > .asciz "char" > Linfo_string8: > .asciz "a" > Linfo_string9: > .asciz "b" > Linfo_string10: > .asciz "c" > > ######################################### > # dwarf debug info dumpped from its executable file with llvm-dwarfdump > mspu.out: file format ELF32-mspu > > .debug_abbrev contents: > Abbrev table for offset: 0x00000000 > [1] DW_TAG_compile_unit DW_CHILDREN_yes > DW_AT_producer DW_FORM_strp > DW_AT_language DW_FORM_data2 > DW_AT_name DW_FORM_strp > DW_AT_low_pc DW_FORM_addr > DW_AT_stmt_list DW_FORM_data4 > DW_AT_comp_dir DW_FORM_strp > > [2] DW_TAG_subprogram DW_CHILDREN_yes > DW_AT_name DW_FORM_strp > DW_AT_decl_file DW_FORM_data1 > DW_AT_decl_line DW_FORM_data1 > DW_AT_prototyped DW_FORM_flag_present > DW_AT_type DW_FORM_ref4 > DW_AT_external DW_FORM_flag_present > DW_AT_low_pc DW_FORM_addr > DW_AT_high_pc DW_FORM_addr > DW_AT_frame_base DW_FORM_block1 > > [3] DW_TAG_formal_parameter DW_CHILDREN_no > DW_AT_name DW_FORM_strp > DW_AT_decl_file DW_FORM_data1 > DW_AT_decl_line DW_FORM_data1 > DW_AT_type DW_FORM_ref4 > DW_AT_location DW_FORM_block1 > > [4] DW_TAG_variable DW_CHILDREN_no > DW_AT_name DW_FORM_strp > DW_AT_decl_file DW_FORM_data1 > DW_AT_decl_line DW_FORM_data1 > DW_AT_type DW_FORM_ref4 > DW_AT_location DW_FORM_block1 > > [5] DW_TAG_base_type DW_CHILDREN_no > DW_AT_name DW_FORM_strp > DW_AT_encoding DW_FORM_data1 > DW_AT_byte_size DW_FORM_data1 > > [6] DW_TAG_pointer_type DW_CHILDREN_no > DW_AT_type DW_FORM_ref4 > > > .debug_info contents: > 0x00000000: Compile Unit: length = 0x00000094 version = 0x0002 abbr_offset > = 0x0000 addr_size = 0x04 (next CU at 0x00000098) > > 0x0000000b: DW_TAG_compile_unit [1] * > 0x0000000c: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] > "clang version 3.3 (/opt/git.repo/clang.git/ > b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ > 57b428f0a6be7b81bc364b0088992b1f820b516e)") > 0x00000010: DW_AT_language [DW_FORM_data2] (0x000c) > 0x00000012: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000099] > "test.c") > 0x00000016: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000) > 0x0000001a: DW_AT_stmt_list [DW_FORM_data4] (0x00000000) > 0x0000001e: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x000000a0] > "/home/yangyy/workspace/newlib") > > 0x00000022: DW_TAG_subprogram [2] * > 0x00000023: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000be] > "main") > 0x00000027: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x00000028: DW_AT_decl_line [DW_FORM_data1] (0x02) > 0x00000029: DW_AT_prototyped [DW_FORM_flag_present] (true) > 0x00000029: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000002d: DW_AT_external [DW_FORM_flag_present] (true) > 0x0000002d: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000028) > 0x00000031: DW_AT_high_pc [DW_FORM_addr] (0x0000000000000084) > 0x00000035: DW_AT_frame_base [DW_FORM_block1] (<0x02> 90 3c ) > > 0x00000038: DW_TAG_formal_parameter [3] > 0x00000039: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c7] > "argc") > 0x0000003d: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x0000003e: DW_AT_decl_line [DW_FORM_data1] (0x02) > 0x0000003f: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x00000043: DW_AT_location [DW_FORM_block1] (<0x02> 91 18 ) > > 0x00000046: DW_TAG_formal_parameter [3] > 0x00000047: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000cc] > "argv") > 0x0000004b: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x0000004c: DW_AT_decl_line [DW_FORM_data1] (0x02) > 0x0000004d: DW_AT_type [DW_FORM_ref4] (cu + 0x0092 => {0x00000092}) > 0x00000051: DW_AT_location [DW_FORM_block1] (<0x02> 91 14 ) > > 0x00000054: DW_TAG_variable [4] > 0x00000055: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d6] > "a") > 0x00000059: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x0000005a: DW_AT_decl_line [DW_FORM_data1] (0x04) > 0x0000005b: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000005f: DW_AT_location [DW_FORM_block1] (<0x02> 91 10 ) > > 0x00000062: DW_TAG_variable [4] > 0x00000063: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d8] > "b") > 0x00000067: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x00000068: DW_AT_decl_line [DW_FORM_data1] (0x05) > 0x00000069: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000006d: DW_AT_location [DW_FORM_block1] (<0x02> 91 0c ) > > 0x00000070: DW_TAG_variable [4] > 0x00000071: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000da] > "c") > 0x00000075: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x00000076: DW_AT_decl_line [DW_FORM_data1] (0x06) > 0x00000077: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000007b: DW_AT_location [DW_FORM_block1] (<0x02> 91 08 ) > > 0x0000007e: NULL > > 0x0000007f: DW_TAG_base_type [5] > 0x00000080: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c3] > "int") > 0x00000084: DW_AT_encoding [DW_FORM_data1] (0x05) > 0x00000085: DW_AT_byte_size [DW_FORM_data1] (0x04) > > 0x00000086: DW_TAG_base_type [5] > 0x00000087: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d1] > "char") > 0x0000008b: DW_AT_encoding [DW_FORM_data1] (0x06) > 0x0000008c: DW_AT_byte_size [DW_FORM_data1] (0x01) > > 0x0000008d: DW_TAG_pointer_type [6] > 0x0000008e: DW_AT_type [DW_FORM_ref4] (cu + 0x0086 => {0x00000086}) > > 0x00000092: DW_TAG_pointer_type [6] > 0x00000093: DW_AT_type [DW_FORM_ref4] (cu + 0x008d => {0x0000008d}) > > 0x00000097: NULL > > .debug_frame contents: > > > .debug_aranges contents: > > .debug_line contents: > Line table prologue: > total_length: 0x00000037 > version: 2 > prologue_length: 0x0000001d > min_inst_length: 1 > default_is_stmt: 1 > line_base: -5 > line_range: 14 > opcode_base: 13 > standard_opcode_lengths[DW_LNS_copy] = 0 > standard_opcode_lengths[DW_LNS_advance_pc] = 1 > standard_opcode_lengths[DW_LNS_advance_line] = 1 > standard_opcode_lengths[DW_LNS_set_file] = 1 > standard_opcode_lengths[DW_LNS_set_column] = 1 > standard_opcode_lengths[DW_LNS_negate_stmt] = 0 > standard_opcode_lengths[DW_LNS_set_basic_block] = 0 > standard_opcode_lengths[DW_LNS_const_add_pc] = 0 > standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1 > standard_opcode_lengths[DW_LNS_set_prologue_end] = 0 > standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0 > standard_opcode_lengths[DW_LNS_set_isa] = 1 > Dir Mod Time File Len File Name > ---- ---------- ---------- --------------------------- > file_names[ 1] 0 0x00000000 0x00000000 test.c > > Address Line Column File ISA Flags > ------------------ ------ ------ ------ --- ------------- > 0x0000000000000028 2 0 1 0 is_stmt prologue_end > 0x0000000000000050 4 0 1 0 is_stmt > 0x0000000000000058 5 0 1 0 is_stmt > 0x000000000000005c 6 0 1 0 is_stmt > 0x0000000000000068 7 0 1 0 is_stmt > 0x0000000000000084 7 0 1 0 is_stmt end_sequence > > .debug_str contents: > 0x00000000: "clang version 3.3 (/opt/git.repo/clang.git/ > b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ > 57b428f0a6be7b81bc364b0088992b1f820b516e)" > 0x00000099: "test.c" > 0x000000a0: "/home/yangyy/workspace/newlib" > 0x000000be: "main" > 0x000000c3: "int" > 0x000000c7: "argc" > 0x000000cc: "argv" > 0x000000d1: "char" > 0x000000d6: "a" > 0x000000d8: "b" > 0x000000da: "c" > > .debug_ranges contents: > > .debug_pubnames contents: > Length: 0 > Version: 0 > Offset in .debug_info: 0 > Size: 0 > > Offset Name > > .debug_abbrev.dwo contents: > < EMPTY > > > > > 2014-02-19 2:28 GMT+08:00 Greg Clayton <gclayton at apple.com>: > > All of this information is contained in the DWARF debug info that you must >> generate. Are you generating DWARF? If not, you will need to. If so, please >> attach an example program that contains DWARF and specify which function >> you are having trouble getting variable information for. >> >> Greg Clayton >> >> On Feb 18, 2014, at 12:44 AM, 杨勇勇 <triple.yang at gmail.com> wrote: >> >> > Hi, all >> > >> > I ported llvm backend and lldb recently. Both tools can basically work. >> > lldb is able to debug programs in asm style and frame unwinding is OK. >> > >> > But "frame variable XX" does not work because lldb is not able to >> determine the address of >> > XX from debug info. >> > >> > Can someone give any clue? >> > Thanks in advance. >> > >> > -- >> > 杨勇勇 (Yang Yong-Yong) >> > _______________________________________________ >> > lldb-dev mailing list >> > lldb-dev at cs.uiuc.edu >> > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev >> >> > > > -- > 杨勇勇 (Yang Yong-Yong) >-- 杨勇勇 (Yang Yong-Yong) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140219/09066e6f/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: example.tar.bz2 Type: application/x-bzip2 Size: 4779 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140219/09066e6f/attachment.bin>
Greg Clayton
2014-Feb-19 19:03 UTC
[LLVMdev] [lldb-dev] How is variable info retrieved in debugging for executables generated by llvm backend?
If I had to guess, I would venture to say your problem is one of: 1 - you don't have your registers correctly defined and didn't specify the DWARF register numbers for your register context 2 - your DWARF is incorrect I am guessing #1 is your issue. How are you debugging your program? Are you using the GDB remote protocol? If so, how did you tell LLDB about all of your CPU registers? Did you use the LLDB specific GDB remote extensions? Did you specify a target definition python file? You will need to make sure that you tell LLDB about all of your CPU registers and also tell LLDB the DWARF register number for each register accurately. Variable "a" has debug info: 0x00000054: DW_TAG_variable [4] DW_AT_name( "a" ) DW_AT_decl_file( "/home/yangyy/workspace/newlib/test.c" ) DW_AT_decl_line( 4 ) DW_AT_type( {0x0000007f} ( int ) ) DW_AT_location( fbreg +16 ) The location says it is at the frame base register + 16 bytes. The frame base is defined in the parent DIE: 0x00000022: DW_TAG_subprogram [2] * DW_AT_name( "main" ) DW_AT_decl_file( "/home/yangyy/workspace/newlib/test.c" ) DW_AT_decl_line( 2 ) DW_AT_prototyped( true ) DW_AT_type( {0x0000007f} ( int ) ) DW_AT_external( true ) DW_AT_low_pc( 0x00000028 ) DW_AT_high_pc( 0x00000084 ) DW_AT_frame_base( regx 0x0000003c ) So it says the frame base register is DWARF register 0x3c. In your target definition you will need to have told us which register has the DWARF register number 0x3c, otherwise we will fail to evaluate the expression. Greg On Feb 18, 2014, at 11:10 PM, 杨勇勇 <triple.yang at gmail.com> wrote:> Sorry, this is the attachment. > > > 2014-02-19 15:08 GMT+08:00 杨勇勇 <triple.yang at gmail.com>: > Thank you. > > Here is an example and the attchment contains extra files including object file and executable file. > I want to print for example the value of "a", but lldb command "frame variable a" displays "0" and so does "b", and "c". > Meanwhile, the value is correct if I directly check registers or memory. > > Following content is composed of three part: > 1. C program. > 2. assembly file including directives of dwarf debug info. > 3. dwarf debug info dumpped from executable file with llvm-dwarfdump. > > /////////////////////////////////////////////////////////////////////////////////////////// > // C > int > main(int argc, char *argv[]) > { > int a = 11; > int b = 22; > int c = a+b; > return c; > } > > ###################################### > # asm including dwarf debugging info > .file "test.c" > .section .debug_info,"", at progbits > Lsection_info: > .section .debug_abbrev,"", at progbits > Lsection_abbrev: > .section .debug_aranges,"", at progbits > .section .debug_macinfo,"", at progbits > .section .debug_line,"", at progbits > Lsection_line: > .section .debug_loc,"", at progbits > .section .debug_pubtypes,"", at progbits > .section .debug_str,"MS", at progbits,1 > Linfo_string: > .section .debug_ranges,"", at progbits > Ldebug_range: > .section .debug_loc,"", at progbits > Lsection_debug_loc: > .text > Ltext_begin: > .data > .file 1 "test.c" > .text > .global main > .type main, at function > main: # @main > Lfunc_begin0: > .loc 1 3 0 # test.c:3:0 > # BB#0: # %entry > .loc 1 2 0 prologue_end # test.c:2:0 > [SP + -4] = FP;; > [SP + -8] = J30;; > FP = SP;; > J31 = -40;; > SP = SP + J31;; > #DEBUG_VALUE: main:argc <- undef > #DEBUG_VALUE: main:argv <- undef > R2 = 0;; > R3 = 11;; > [FP + -12] = R2;; > [FP + -16] = R0;; > [FP + -20] = R1;; > .loc 1 4 0 # test.c:4:0 > [FP + -24] = R3;; > R2 = 22;; > .loc 1 5 0 # test.c:5:0 > [FP + -28] = R2;; > .loc 1 6 0 # test.c:6:0 > R3 = [FP + -24];; > R2 = R3 + R2 (T);; > [FP + -32] = R2;; > .loc 1 7 0 # test.c:7:0 > [FP + -36] = R0;; > R0 = R2;; > [FP + -40] = R1;; > SP = FP;; > J30 = [SP + -8];; > FP = [SP + -4];; > jump J30;; > Ltmp0: > Ltmp1: > .size main, Ltmp1-main > Lfunc_end0: > > Ltext_end: > .data > Ldata_end: > .text > Lsection_end1: > .section .debug_info,"", at progbits > L.debug_info_begin0: > .int 148 # Length of Compilation Unit Info > .short 2 # DWARF version number > .int L.debug_abbrev_begin # Offset Into Abbrev. Section > .byte 4 # Address Size (in bytes) > .byte 1 # Abbrev [1] 0xb:0x8d DW_TAG_compile_unit > .int Linfo_string0 # DW_AT_producer > .short 12 # DW_AT_language > .int Linfo_string1 # DW_AT_name > .int 0 # DW_AT_low_pc > .int Lsection_line # DW_AT_stmt_list > .int Linfo_string2 # DW_AT_comp_dir > .byte 2 # Abbrev [2] 0x22:0x5d DW_TAG_subprogram > .int Linfo_string3 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 2 # DW_AT_decl_line > # DW_AT_prototyped > .int 127 # DW_AT_type > # DW_AT_external > .int Lfunc_begin0 # DW_AT_low_pc > .int Lfunc_end0 # DW_AT_high_pc > .byte 2 # DW_AT_frame_base > .byte 144 > .byte 60 > .byte 3 # Abbrev [3] 0x38:0xe DW_TAG_formal_parameter > .int Linfo_string5 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 2 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 24 > .byte 3 # Abbrev [3] 0x46:0xe DW_TAG_formal_parameter > .int Linfo_string6 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 2 # DW_AT_decl_line > .int 146 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 20 > .byte 4 # Abbrev [4] 0x54:0xe DW_TAG_variable > .int Linfo_string8 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 4 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 16 > .byte 4 # Abbrev [4] 0x62:0xe DW_TAG_variable > .int Linfo_string9 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 5 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 12 > .byte 4 # Abbrev [4] 0x70:0xe DW_TAG_variable > .int Linfo_string10 # DW_AT_name > .byte 1 # DW_AT_decl_file > .byte 6 # DW_AT_decl_line > .int 127 # DW_AT_type > .byte 2 # DW_AT_location > .byte 145 > .byte 8 > .byte 0 # End Of Children Mark > .byte 5 # Abbrev [5] 0x7f:0x7 DW_TAG_base_type > .int Linfo_string4 # DW_AT_name > .byte 5 # DW_AT_encoding > .byte 4 # DW_AT_byte_size > .byte 5 # Abbrev [5] 0x86:0x7 DW_TAG_base_type > .int Linfo_string7 # DW_AT_name > .byte 6 # DW_AT_encoding > .byte 1 # DW_AT_byte_size > .byte 6 # Abbrev [6] 0x8d:0x5 DW_TAG_pointer_type > .int 134 # DW_AT_type > .byte 6 # Abbrev [6] 0x92:0x5 DW_TAG_pointer_type > .int 141 # DW_AT_type > .byte 0 # End Of Children Mark > L.debug_info_end0: > .section .debug_abbrev,"", at progbits > L.debug_abbrev_begin: > .byte 1 # Abbreviation Code > .byte 17 # DW_TAG_compile_unit > .byte 1 # DW_CHILDREN_yes > .byte 37 # DW_AT_producer > .byte 14 # DW_FORM_strp > .byte 19 # DW_AT_language > .byte 5 # DW_FORM_data2 > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 17 # DW_AT_low_pc > .byte 1 # DW_FORM_addr > .byte 16 # DW_AT_stmt_list > .byte 6 # DW_FORM_data4 > .byte 27 # DW_AT_comp_dir > .byte 14 # DW_FORM_strp > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 2 # Abbreviation Code > .byte 46 # DW_TAG_subprogram > .byte 1 # DW_CHILDREN_yes > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 58 # DW_AT_decl_file > .byte 11 # DW_FORM_data1 > .byte 59 # DW_AT_decl_line > .byte 11 # DW_FORM_data1 > .byte 39 # DW_AT_prototyped > .byte 25 # DW_FORM_flag_present > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 63 # DW_AT_external > .byte 25 # DW_FORM_flag_present > .byte 17 # DW_AT_low_pc > .byte 1 # DW_FORM_addr > .byte 18 # DW_AT_high_pc > .byte 1 # DW_FORM_addr > .byte 64 # DW_AT_frame_base > .byte 10 # DW_FORM_block1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 3 # Abbreviation Code > .byte 5 # DW_TAG_formal_parameter > .byte 0 # DW_CHILDREN_no > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 58 # DW_AT_decl_file > .byte 11 # DW_FORM_data1 > .byte 59 # DW_AT_decl_line > .byte 11 # DW_FORM_data1 > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 2 # DW_AT_location > .byte 10 # DW_FORM_block1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 4 # Abbreviation Code > .byte 52 # DW_TAG_variable > .byte 0 # DW_CHILDREN_no > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 58 # DW_AT_decl_file > .byte 11 # DW_FORM_data1 > .byte 59 # DW_AT_decl_line > .byte 11 # DW_FORM_data1 > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 2 # DW_AT_location > .byte 10 # DW_FORM_block1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 5 # Abbreviation Code > .byte 36 # DW_TAG_base_type > .byte 0 # DW_CHILDREN_no > .byte 3 # DW_AT_name > .byte 14 # DW_FORM_strp > .byte 62 # DW_AT_encoding > .byte 11 # DW_FORM_data1 > .byte 11 # DW_AT_byte_size > .byte 11 # DW_FORM_data1 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 6 # Abbreviation Code > .byte 15 # DW_TAG_pointer_type > .byte 0 # DW_CHILDREN_no > .byte 73 # DW_AT_type > .byte 19 # DW_FORM_ref4 > .byte 0 # EOM(1) > .byte 0 # EOM(2) > .byte 0 # EOM(3) > L.debug_abbrev_end: > .section .debug_aranges,"", at progbits > .section .debug_ranges,"", at progbits > .section .debug_macinfo,"", at progbits > .section .debug_str,"MS", at progbits,1 > Linfo_string0: > .asciz "clang version 3.3 (/opt/git.repo/clang.git/ b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ 57b428f0a6be7b81bc364b0088992b1f820b516e)" > Linfo_string1: > .asciz "test.c" > Linfo_string2: > .asciz "/home/yangyy/workspace/newlib" > Linfo_string3: > .asciz "main" > Linfo_string4: > .asciz "int" > Linfo_string5: > .asciz "argc" > Linfo_string6: > .asciz "argv" > Linfo_string7: > .asciz "char" > Linfo_string8: > .asciz "a" > Linfo_string9: > .asciz "b" > Linfo_string10: > .asciz "c" > > ######################################### > # dwarf debug info dumpped from its executable file with llvm-dwarfdump > mspu.out: file format ELF32-mspu > > .debug_abbrev contents: > Abbrev table for offset: 0x00000000 > [1] DW_TAG_compile_unit DW_CHILDREN_yes > DW_AT_producer DW_FORM_strp > DW_AT_language DW_FORM_data2 > DW_AT_name DW_FORM_strp > DW_AT_low_pc DW_FORM_addr > DW_AT_stmt_list DW_FORM_data4 > DW_AT_comp_dir DW_FORM_strp > > [2] DW_TAG_subprogram DW_CHILDREN_yes > DW_AT_name DW_FORM_strp > DW_AT_decl_file DW_FORM_data1 > DW_AT_decl_line DW_FORM_data1 > DW_AT_prototyped DW_FORM_flag_present > DW_AT_type DW_FORM_ref4 > DW_AT_external DW_FORM_flag_present > DW_AT_low_pc DW_FORM_addr > DW_AT_high_pc DW_FORM_addr > DW_AT_frame_base DW_FORM_block1 > > [3] DW_TAG_formal_parameter DW_CHILDREN_no > DW_AT_name DW_FORM_strp > DW_AT_decl_file DW_FORM_data1 > DW_AT_decl_line DW_FORM_data1 > DW_AT_type DW_FORM_ref4 > DW_AT_location DW_FORM_block1 > > [4] DW_TAG_variable DW_CHILDREN_no > DW_AT_name DW_FORM_strp > DW_AT_decl_file DW_FORM_data1 > DW_AT_decl_line DW_FORM_data1 > DW_AT_type DW_FORM_ref4 > DW_AT_location DW_FORM_block1 > > [5] DW_TAG_base_type DW_CHILDREN_no > DW_AT_name DW_FORM_strp > DW_AT_encoding DW_FORM_data1 > DW_AT_byte_size DW_FORM_data1 > > [6] DW_TAG_pointer_type DW_CHILDREN_no > DW_AT_type DW_FORM_ref4 > > > .debug_info contents: > 0x00000000: Compile Unit: length = 0x00000094 version = 0x0002 abbr_offset = 0x0000 addr_size = 0x04 (next CU at 0x00000098) > > 0x0000000b: DW_TAG_compile_unit [1] * > 0x0000000c: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] = "clang version 3.3 (/opt/git.repo/clang.git/ b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ 57b428f0a6be7b81bc364b0088992b1f820b516e)") > 0x00000010: DW_AT_language [DW_FORM_data2] (0x000c) > 0x00000012: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000099] = "test.c") > 0x00000016: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000) > 0x0000001a: DW_AT_stmt_list [DW_FORM_data4] (0x00000000) > 0x0000001e: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x000000a0] = "/home/yangyy/workspace/newlib") > > 0x00000022: DW_TAG_subprogram [2] * > 0x00000023: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000be] = "main") > 0x00000027: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x00000028: DW_AT_decl_line [DW_FORM_data1] (0x02) > 0x00000029: DW_AT_prototyped [DW_FORM_flag_present] (true) > 0x00000029: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000002d: DW_AT_external [DW_FORM_flag_present] (true) > 0x0000002d: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000028) > 0x00000031: DW_AT_high_pc [DW_FORM_addr] (0x0000000000000084) > 0x00000035: DW_AT_frame_base [DW_FORM_block1] (<0x02> 90 3c ) > > 0x00000038: DW_TAG_formal_parameter [3] > 0x00000039: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c7] = "argc") > 0x0000003d: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x0000003e: DW_AT_decl_line [DW_FORM_data1] (0x02) > 0x0000003f: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x00000043: DW_AT_location [DW_FORM_block1] (<0x02> 91 18 ) > > 0x00000046: DW_TAG_formal_parameter [3] > 0x00000047: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000cc] = "argv") > 0x0000004b: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x0000004c: DW_AT_decl_line [DW_FORM_data1] (0x02) > 0x0000004d: DW_AT_type [DW_FORM_ref4] (cu + 0x0092 => {0x00000092}) > 0x00000051: DW_AT_location [DW_FORM_block1] (<0x02> 91 14 ) > > 0x00000054: DW_TAG_variable [4] > 0x00000055: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d6] = "a") > 0x00000059: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x0000005a: DW_AT_decl_line [DW_FORM_data1] (0x04) > 0x0000005b: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000005f: DW_AT_location [DW_FORM_block1] (<0x02> 91 10 ) > > 0x00000062: DW_TAG_variable [4] > 0x00000063: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d8] = "b") > 0x00000067: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x00000068: DW_AT_decl_line [DW_FORM_data1] (0x05) > 0x00000069: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000006d: DW_AT_location [DW_FORM_block1] (<0x02> 91 0c ) > > 0x00000070: DW_TAG_variable [4] > 0x00000071: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000da] = "c") > 0x00000075: DW_AT_decl_file [DW_FORM_data1] (0x01) > 0x00000076: DW_AT_decl_line [DW_FORM_data1] (0x06) > 0x00000077: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => {0x0000007f}) > 0x0000007b: DW_AT_location [DW_FORM_block1] (<0x02> 91 08 ) > > 0x0000007e: NULL > > 0x0000007f: DW_TAG_base_type [5] > 0x00000080: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c3] = "int") > 0x00000084: DW_AT_encoding [DW_FORM_data1] (0x05) > 0x00000085: DW_AT_byte_size [DW_FORM_data1] (0x04) > > 0x00000086: DW_TAG_base_type [5] > 0x00000087: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d1] = "char") > 0x0000008b: DW_AT_encoding [DW_FORM_data1] (0x06) > 0x0000008c: DW_AT_byte_size [DW_FORM_data1] (0x01) > > 0x0000008d: DW_TAG_pointer_type [6] > 0x0000008e: DW_AT_type [DW_FORM_ref4] (cu + 0x0086 => {0x00000086}) > > 0x00000092: DW_TAG_pointer_type [6] > 0x00000093: DW_AT_type [DW_FORM_ref4] (cu + 0x008d => {0x0000008d}) > > 0x00000097: NULL > > .debug_frame contents: > > > .debug_aranges contents: > > .debug_line contents: > Line table prologue: > total_length: 0x00000037 > version: 2 > prologue_length: 0x0000001d > min_inst_length: 1 > default_is_stmt: 1 > line_base: -5 > line_range: 14 > opcode_base: 13 > standard_opcode_lengths[DW_LNS_copy] = 0 > standard_opcode_lengths[DW_LNS_advance_pc] = 1 > standard_opcode_lengths[DW_LNS_advance_line] = 1 > standard_opcode_lengths[DW_LNS_set_file] = 1 > standard_opcode_lengths[DW_LNS_set_column] = 1 > standard_opcode_lengths[DW_LNS_negate_stmt] = 0 > standard_opcode_lengths[DW_LNS_set_basic_block] = 0 > standard_opcode_lengths[DW_LNS_const_add_pc] = 0 > standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1 > standard_opcode_lengths[DW_LNS_set_prologue_end] = 0 > standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0 > standard_opcode_lengths[DW_LNS_set_isa] = 1 > Dir Mod Time File Len File Name > ---- ---------- ---------- --------------------------- > file_names[ 1] 0 0x00000000 0x00000000 test.c > > Address Line Column File ISA Flags > ------------------ ------ ------ ------ --- ------------- > 0x0000000000000028 2 0 1 0 is_stmt prologue_end > 0x0000000000000050 4 0 1 0 is_stmt > 0x0000000000000058 5 0 1 0 is_stmt > 0x000000000000005c 6 0 1 0 is_stmt > 0x0000000000000068 7 0 1 0 is_stmt > 0x0000000000000084 7 0 1 0 is_stmt end_sequence > > .debug_str contents: > 0x00000000: "clang version 3.3 (/opt/git.repo/clang.git/ b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ 57b428f0a6be7b81bc364b0088992b1f820b516e)" > 0x00000099: "test.c" > 0x000000a0: "/home/yangyy/workspace/newlib" > 0x000000be: "main" > 0x000000c3: "int" > 0x000000c7: "argc" > 0x000000cc: "argv" > 0x000000d1: "char" > 0x000000d6: "a" > 0x000000d8: "b" > 0x000000da: "c" > > .debug_ranges contents: > > .debug_pubnames contents: > Length: 0 > Version: 0 > Offset in .debug_info: 0 > Size: 0 > > Offset Name > > .debug_abbrev.dwo contents: > < EMPTY > > > > > 2014-02-19 2:28 GMT+08:00 Greg Clayton <gclayton at apple.com>: > > All of this information is contained in the DWARF debug info that you must generate. Are you generating DWARF? If not, you will need to. If so, please attach an example program that contains DWARF and specify which function you are having trouble getting variable information for. > > Greg Clayton > > On Feb 18, 2014, at 12:44 AM, 杨勇勇 <triple.yang at gmail.com> wrote: > > > Hi, all > > > > I ported llvm backend and lldb recently. Both tools can basically work. > > lldb is able to debug programs in asm style and frame unwinding is OK. > > > > But "frame variable XX" does not work because lldb is not able to determine the address of > > XX from debug info. > > > > Can someone give any clue? > > Thanks in advance. > > > > -- > > 杨勇勇 (Yang Yong-Yong) > > _______________________________________________ > > lldb-dev mailing list > > lldb-dev at cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev > > > > > -- > 杨勇勇 (Yang Yong-Yong) > > > > -- > 杨勇勇 (Yang Yong-Yong) > <example.tar.bz2>
杨勇勇
2014-Feb-20 09:28 UTC
[LLVMdev] [lldb-dev] How is variable info retrieved in debugging for executables generated by llvm backend?
Thank you, Clayton. This is very helpful. We use the LLDB specific GDB remote extensions, and our debugger server supports "qRegisterInfo" package. "reg 0x3c" is the frame pointer. In the example mentioned above, we have SP = FP - 40 for current call frame. And variable "a" is stored at address (FP + -24) from asm instruction [FP + -24] = R3;; Thus we can conclude that SP + 16 = FP - 40 + 16 = FP -24 is the desired address. Here "16" is the offset obtained from debug info. So I guess there is something incompatible between our compiler backend and debug info generator. Here is my questions: 1. How can we specify which register should be DW_AT_frame_base? 2. How can we adjust the offset in DW_AT_location for variables? Best regards. 2014-02-20 3:03 GMT+08:00 Greg Clayton <gclayton at apple.com>:> If I had to guess, I would venture to say your problem is one of: > 1 - you don't have your registers correctly defined and didn't specify the > DWARF register numbers for your register context > 2 - your DWARF is incorrect > > I am guessing #1 is your issue. > > How are you debugging your program? Are you using the GDB remote protocol? > If so, how did you tell LLDB about all of your CPU registers? Did you use > the LLDB specific GDB remote extensions? Did you specify a target > definition python file? You will need to make sure that you tell LLDB about > all of your CPU registers and also tell LLDB the DWARF register number for > each register accurately. > > Variable "a" has debug info: > > 0x00000054: DW_TAG_variable [4] > DW_AT_name( "a" ) > DW_AT_decl_file( > "/home/yangyy/workspace/newlib/test.c" ) > DW_AT_decl_line( 4 ) > DW_AT_type( {0x0000007f} ( int ) ) > DW_AT_location( fbreg +16 ) > > The location says it is at the frame base register + 16 bytes. The frame > base is defined in the parent DIE: > > 0x00000022: DW_TAG_subprogram [2] * > DW_AT_name( "main" ) > DW_AT_decl_file( "/home/yangyy/workspace/newlib/test.c" ) > DW_AT_decl_line( 2 ) > DW_AT_prototyped( true ) > DW_AT_type( {0x0000007f} ( int ) ) > DW_AT_external( true ) > DW_AT_low_pc( 0x00000028 ) > DW_AT_high_pc( 0x00000084 ) > DW_AT_frame_base( regx 0x0000003c ) > > So it says the frame base register is DWARF register 0x3c. In your target > definition you will need to have told us which register has the DWARF > register number 0x3c, otherwise we will fail to evaluate the expression. > > Greg > > > On Feb 18, 2014, at 11:10 PM, 杨勇勇 <triple.yang at gmail.com> wrote: > > > Sorry, this is the attachment. > > > > > > 2014-02-19 15:08 GMT+08:00 杨勇勇 <triple.yang at gmail.com>: > > Thank you. > > > > Here is an example and the attchment contains extra files including > object file and executable file. > > I want to print for example the value of "a", but lldb command "frame > variable a" displays "0" and so does "b", and "c". > > Meanwhile, the value is correct if I directly check registers or memory. > > > > Following content is composed of three part: > > 1. C program. > > 2. assembly file including directives of dwarf debug info. > > 3. dwarf debug info dumpped from executable file with llvm-dwarfdump. > > > > > /////////////////////////////////////////////////////////////////////////////////////////// > > // C > > int > > main(int argc, char *argv[]) > > { > > int a = 11; > > int b = 22; > > int c = a+b; > > return c; > > } > > > > ###################################### > > # asm including dwarf debugging info > > .file "test.c" > > .section .debug_info,"", at progbits > > Lsection_info: > > .section .debug_abbrev,"", at progbits > > Lsection_abbrev: > > .section .debug_aranges,"", at progbits > > .section .debug_macinfo,"", at progbits > > .section .debug_line,"", at progbits > > Lsection_line: > > .section .debug_loc,"", at progbits > > .section .debug_pubtypes,"", at progbits > > .section .debug_str,"MS", at progbits,1 > > Linfo_string: > > .section .debug_ranges,"", at progbits > > Ldebug_range: > > .section .debug_loc,"", at progbits > > Lsection_debug_loc: > > .text > > Ltext_begin: > > .data > > .file 1 "test.c" > > .text > > .global main > > .type main, at function > > main: # @main > > Lfunc_begin0: > > .loc 1 3 0 # test.c:3:0 > > # BB#0: # %entry > > .loc 1 2 0 prologue_end # test.c:2:0 > > [SP + -4] = FP;; > > [SP + -8] = J30;; > > FP = SP;; > > J31 = -40;; > > SP = SP + J31;; > > #DEBUG_VALUE: main:argc <- undef > > #DEBUG_VALUE: main:argv <- undef > > R2 = 0;; > > R3 = 11;; > > [FP + -12] = R2;; > > [FP + -16] = R0;; > > [FP + -20] = R1;; > > .loc 1 4 0 # test.c:4:0 > > [FP + -24] = R3;; > > R2 = 22;; > > .loc 1 5 0 # test.c:5:0 > > [FP + -28] = R2;; > > .loc 1 6 0 # test.c:6:0 > > R3 = [FP + -24];; > > R2 = R3 + R2 (T);; > > [FP + -32] = R2;; > > .loc 1 7 0 # test.c:7:0 > > [FP + -36] = R0;; > > R0 = R2;; > > [FP + -40] = R1;; > > SP = FP;; > > J30 = [SP + -8];; > > FP = [SP + -4];; > > jump J30;; > > Ltmp0: > > Ltmp1: > > .size main, Ltmp1-main > > Lfunc_end0: > > > > Ltext_end: > > .data > > Ldata_end: > > .text > > Lsection_end1: > > .section .debug_info,"", at progbits > > L.debug_info_begin0: > > .int 148 # Length of Compilation Unit Info > > .short 2 # DWARF version number > > .int L.debug_abbrev_begin # Offset Into Abbrev. Section > > .byte 4 # Address Size (in bytes) > > .byte 1 # Abbrev [1] 0xb:0x8d > DW_TAG_compile_unit > > .int Linfo_string0 # DW_AT_producer > > .short 12 # DW_AT_language > > .int Linfo_string1 # DW_AT_name > > .int 0 # DW_AT_low_pc > > .int Lsection_line # DW_AT_stmt_list > > .int Linfo_string2 # DW_AT_comp_dir > > .byte 2 # Abbrev [2] 0x22:0x5d > DW_TAG_subprogram > > .int Linfo_string3 # DW_AT_name > > .byte 1 # DW_AT_decl_file > > .byte 2 # DW_AT_decl_line > > # DW_AT_prototyped > > .int 127 # DW_AT_type > > # DW_AT_external > > .int Lfunc_begin0 # DW_AT_low_pc > > .int Lfunc_end0 # DW_AT_high_pc > > .byte 2 # DW_AT_frame_base > > .byte 144 > > .byte 60 > > .byte 3 # Abbrev [3] 0x38:0xe > DW_TAG_formal_parameter > > .int Linfo_string5 # DW_AT_name > > .byte 1 # DW_AT_decl_file > > .byte 2 # DW_AT_decl_line > > .int 127 # DW_AT_type > > .byte 2 # DW_AT_location > > .byte 145 > > .byte 24 > > .byte 3 # Abbrev [3] 0x46:0xe > DW_TAG_formal_parameter > > .int Linfo_string6 # DW_AT_name > > .byte 1 # DW_AT_decl_file > > .byte 2 # DW_AT_decl_line > > .int 146 # DW_AT_type > > .byte 2 # DW_AT_location > > .byte 145 > > .byte 20 > > .byte 4 # Abbrev [4] 0x54:0xe > DW_TAG_variable > > .int Linfo_string8 # DW_AT_name > > .byte 1 # DW_AT_decl_file > > .byte 4 # DW_AT_decl_line > > .int 127 # DW_AT_type > > .byte 2 # DW_AT_location > > .byte 145 > > .byte 16 > > .byte 4 # Abbrev [4] 0x62:0xe > DW_TAG_variable > > .int Linfo_string9 # DW_AT_name > > .byte 1 # DW_AT_decl_file > > .byte 5 # DW_AT_decl_line > > .int 127 # DW_AT_type > > .byte 2 # DW_AT_location > > .byte 145 > > .byte 12 > > .byte 4 # Abbrev [4] 0x70:0xe > DW_TAG_variable > > .int Linfo_string10 # DW_AT_name > > .byte 1 # DW_AT_decl_file > > .byte 6 # DW_AT_decl_line > > .int 127 # DW_AT_type > > .byte 2 # DW_AT_location > > .byte 145 > > .byte 8 > > .byte 0 # End Of Children Mark > > .byte 5 # Abbrev [5] 0x7f:0x7 > DW_TAG_base_type > > .int Linfo_string4 # DW_AT_name > > .byte 5 # DW_AT_encoding > > .byte 4 # DW_AT_byte_size > > .byte 5 # Abbrev [5] 0x86:0x7 > DW_TAG_base_type > > .int Linfo_string7 # DW_AT_name > > .byte 6 # DW_AT_encoding > > .byte 1 # DW_AT_byte_size > > .byte 6 # Abbrev [6] 0x8d:0x5 > DW_TAG_pointer_type > > .int 134 # DW_AT_type > > .byte 6 # Abbrev [6] 0x92:0x5 > DW_TAG_pointer_type > > .int 141 # DW_AT_type > > .byte 0 # End Of Children Mark > > L.debug_info_end0: > > .section .debug_abbrev,"", at progbits > > L.debug_abbrev_begin: > > .byte 1 # Abbreviation Code > > .byte 17 # DW_TAG_compile_unit > > .byte 1 # DW_CHILDREN_yes > > .byte 37 # DW_AT_producer > > .byte 14 # DW_FORM_strp > > .byte 19 # DW_AT_language > > .byte 5 # DW_FORM_data2 > > .byte 3 # DW_AT_name > > .byte 14 # DW_FORM_strp > > .byte 17 # DW_AT_low_pc > > .byte 1 # DW_FORM_addr > > .byte 16 # DW_AT_stmt_list > > .byte 6 # DW_FORM_data4 > > .byte 27 # DW_AT_comp_dir > > .byte 14 # DW_FORM_strp > > .byte 0 # EOM(1) > > .byte 0 # EOM(2) > > .byte 2 # Abbreviation Code > > .byte 46 # DW_TAG_subprogram > > .byte 1 # DW_CHILDREN_yes > > .byte 3 # DW_AT_name > > .byte 14 # DW_FORM_strp > > .byte 58 # DW_AT_decl_file > > .byte 11 # DW_FORM_data1 > > .byte 59 # DW_AT_decl_line > > .byte 11 # DW_FORM_data1 > > .byte 39 # DW_AT_prototyped > > .byte 25 # DW_FORM_flag_present > > .byte 73 # DW_AT_type > > .byte 19 # DW_FORM_ref4 > > .byte 63 # DW_AT_external > > .byte 25 # DW_FORM_flag_present > > .byte 17 # DW_AT_low_pc > > .byte 1 # DW_FORM_addr > > .byte 18 # DW_AT_high_pc > > .byte 1 # DW_FORM_addr > > .byte 64 # DW_AT_frame_base > > .byte 10 # DW_FORM_block1 > > .byte 0 # EOM(1) > > .byte 0 # EOM(2) > > .byte 3 # Abbreviation Code > > .byte 5 # DW_TAG_formal_parameter > > .byte 0 # DW_CHILDREN_no > > .byte 3 # DW_AT_name > > .byte 14 # DW_FORM_strp > > .byte 58 # DW_AT_decl_file > > .byte 11 # DW_FORM_data1 > > .byte 59 # DW_AT_decl_line > > .byte 11 # DW_FORM_data1 > > .byte 73 # DW_AT_type > > .byte 19 # DW_FORM_ref4 > > .byte 2 # DW_AT_location > > .byte 10 # DW_FORM_block1 > > .byte 0 # EOM(1) > > .byte 0 # EOM(2) > > .byte 4 # Abbreviation Code > > .byte 52 # DW_TAG_variable > > .byte 0 # DW_CHILDREN_no > > .byte 3 # DW_AT_name > > .byte 14 # DW_FORM_strp > > .byte 58 # DW_AT_decl_file > > .byte 11 # DW_FORM_data1 > > .byte 59 # DW_AT_decl_line > > .byte 11 # DW_FORM_data1 > > .byte 73 # DW_AT_type > > .byte 19 # DW_FORM_ref4 > > .byte 2 # DW_AT_location > > .byte 10 # DW_FORM_block1 > > .byte 0 # EOM(1) > > .byte 0 # EOM(2) > > .byte 5 # Abbreviation Code > > .byte 36 # DW_TAG_base_type > > .byte 0 # DW_CHILDREN_no > > .byte 3 # DW_AT_name > > .byte 14 # DW_FORM_strp > > .byte 62 # DW_AT_encoding > > .byte 11 # DW_FORM_data1 > > .byte 11 # DW_AT_byte_size > > .byte 11 # DW_FORM_data1 > > .byte 0 # EOM(1) > > .byte 0 # EOM(2) > > .byte 6 # Abbreviation Code > > .byte 15 # DW_TAG_pointer_type > > .byte 0 # DW_CHILDREN_no > > .byte 73 # DW_AT_type > > .byte 19 # DW_FORM_ref4 > > .byte 0 # EOM(1) > > .byte 0 # EOM(2) > > .byte 0 # EOM(3) > > L.debug_abbrev_end: > > .section .debug_aranges,"", at progbits > > .section .debug_ranges,"", at progbits > > .section .debug_macinfo,"", at progbits > > .section .debug_str,"MS", at progbits,1 > > Linfo_string0: > > .asciz "clang version 3.3 (/opt/git.repo/clang.git/ > b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ > 57b428f0a6be7b81bc364b0088992b1f820b516e)" > > Linfo_string1: > > .asciz "test.c" > > Linfo_string2: > > .asciz "/home/yangyy/workspace/newlib" > > Linfo_string3: > > .asciz "main" > > Linfo_string4: > > .asciz "int" > > Linfo_string5: > > .asciz "argc" > > Linfo_string6: > > .asciz "argv" > > Linfo_string7: > > .asciz "char" > > Linfo_string8: > > .asciz "a" > > Linfo_string9: > > .asciz "b" > > Linfo_string10: > > .asciz "c" > > > > ######################################### > > # dwarf debug info dumpped from its executable file with llvm-dwarfdump > > mspu.out: file format ELF32-mspu > > > > .debug_abbrev contents: > > Abbrev table for offset: 0x00000000 > > [1] DW_TAG_compile_unit DW_CHILDREN_yes > > DW_AT_producer DW_FORM_strp > > DW_AT_language DW_FORM_data2 > > DW_AT_name DW_FORM_strp > > DW_AT_low_pc DW_FORM_addr > > DW_AT_stmt_list DW_FORM_data4 > > DW_AT_comp_dir DW_FORM_strp > > > > [2] DW_TAG_subprogram DW_CHILDREN_yes > > DW_AT_name DW_FORM_strp > > DW_AT_decl_file DW_FORM_data1 > > DW_AT_decl_line DW_FORM_data1 > > DW_AT_prototyped DW_FORM_flag_present > > DW_AT_type DW_FORM_ref4 > > DW_AT_external DW_FORM_flag_present > > DW_AT_low_pc DW_FORM_addr > > DW_AT_high_pc DW_FORM_addr > > DW_AT_frame_base DW_FORM_block1 > > > > [3] DW_TAG_formal_parameter DW_CHILDREN_no > > DW_AT_name DW_FORM_strp > > DW_AT_decl_file DW_FORM_data1 > > DW_AT_decl_line DW_FORM_data1 > > DW_AT_type DW_FORM_ref4 > > DW_AT_location DW_FORM_block1 > > > > [4] DW_TAG_variable DW_CHILDREN_no > > DW_AT_name DW_FORM_strp > > DW_AT_decl_file DW_FORM_data1 > > DW_AT_decl_line DW_FORM_data1 > > DW_AT_type DW_FORM_ref4 > > DW_AT_location DW_FORM_block1 > > > > [5] DW_TAG_base_type DW_CHILDREN_no > > DW_AT_name DW_FORM_strp > > DW_AT_encoding DW_FORM_data1 > > DW_AT_byte_size DW_FORM_data1 > > > > [6] DW_TAG_pointer_type DW_CHILDREN_no > > DW_AT_type DW_FORM_ref4 > > > > > > .debug_info contents: > > 0x00000000: Compile Unit: length = 0x00000094 version = 0x0002 > abbr_offset = 0x0000 addr_size = 0x04 (next CU at 0x00000098) > > > > 0x0000000b: DW_TAG_compile_unit [1] * > > 0x0000000c: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] > "clang version 3.3 (/opt/git.repo/clang.git/ > b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ > 57b428f0a6be7b81bc364b0088992b1f820b516e)") > > 0x00000010: DW_AT_language [DW_FORM_data2] (0x000c) > > 0x00000012: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000099] > "test.c") > > 0x00000016: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000) > > 0x0000001a: DW_AT_stmt_list [DW_FORM_data4] (0x00000000) > > 0x0000001e: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x000000a0] > "/home/yangyy/workspace/newlib") > > > > 0x00000022: DW_TAG_subprogram [2] * > > 0x00000023: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000be] > "main") > > 0x00000027: DW_AT_decl_file [DW_FORM_data1] (0x01) > > 0x00000028: DW_AT_decl_line [DW_FORM_data1] (0x02) > > 0x00000029: DW_AT_prototyped [DW_FORM_flag_present] (true) > > 0x00000029: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => > {0x0000007f}) > > 0x0000002d: DW_AT_external [DW_FORM_flag_present] (true) > > 0x0000002d: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000028) > > 0x00000031: DW_AT_high_pc [DW_FORM_addr] (0x0000000000000084) > > 0x00000035: DW_AT_frame_base [DW_FORM_block1] (<0x02> 90 3c ) > > > > 0x00000038: DW_TAG_formal_parameter [3] > > 0x00000039: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c7] > "argc") > > 0x0000003d: DW_AT_decl_file [DW_FORM_data1] (0x01) > > 0x0000003e: DW_AT_decl_line [DW_FORM_data1] (0x02) > > 0x0000003f: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => > {0x0000007f}) > > 0x00000043: DW_AT_location [DW_FORM_block1] (<0x02> 91 18 ) > > > > 0x00000046: DW_TAG_formal_parameter [3] > > 0x00000047: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000cc] > "argv") > > 0x0000004b: DW_AT_decl_file [DW_FORM_data1] (0x01) > > 0x0000004c: DW_AT_decl_line [DW_FORM_data1] (0x02) > > 0x0000004d: DW_AT_type [DW_FORM_ref4] (cu + 0x0092 => > {0x00000092}) > > 0x00000051: DW_AT_location [DW_FORM_block1] (<0x02> 91 14 ) > > > > 0x00000054: DW_TAG_variable [4] > > 0x00000055: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d6] > "a") > > 0x00000059: DW_AT_decl_file [DW_FORM_data1] (0x01) > > 0x0000005a: DW_AT_decl_line [DW_FORM_data1] (0x04) > > 0x0000005b: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => > {0x0000007f}) > > 0x0000005f: DW_AT_location [DW_FORM_block1] (<0x02> 91 10 ) > > > > 0x00000062: DW_TAG_variable [4] > > 0x00000063: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d8] > "b") > > 0x00000067: DW_AT_decl_file [DW_FORM_data1] (0x01) > > 0x00000068: DW_AT_decl_line [DW_FORM_data1] (0x05) > > 0x00000069: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => > {0x0000007f}) > > 0x0000006d: DW_AT_location [DW_FORM_block1] (<0x02> 91 0c ) > > > > 0x00000070: DW_TAG_variable [4] > > 0x00000071: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000da] > "c") > > 0x00000075: DW_AT_decl_file [DW_FORM_data1] (0x01) > > 0x00000076: DW_AT_decl_line [DW_FORM_data1] (0x06) > > 0x00000077: DW_AT_type [DW_FORM_ref4] (cu + 0x007f => > {0x0000007f}) > > 0x0000007b: DW_AT_location [DW_FORM_block1] (<0x02> 91 08 ) > > > > 0x0000007e: NULL > > > > 0x0000007f: DW_TAG_base_type [5] > > 0x00000080: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000c3] > "int") > > 0x00000084: DW_AT_encoding [DW_FORM_data1] (0x05) > > 0x00000085: DW_AT_byte_size [DW_FORM_data1] (0x04) > > > > 0x00000086: DW_TAG_base_type [5] > > 0x00000087: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d1] > "char") > > 0x0000008b: DW_AT_encoding [DW_FORM_data1] (0x06) > > 0x0000008c: DW_AT_byte_size [DW_FORM_data1] (0x01) > > > > 0x0000008d: DW_TAG_pointer_type [6] > > 0x0000008e: DW_AT_type [DW_FORM_ref4] (cu + 0x0086 => > {0x00000086}) > > > > 0x00000092: DW_TAG_pointer_type [6] > > 0x00000093: DW_AT_type [DW_FORM_ref4] (cu + 0x008d => > {0x0000008d}) > > > > 0x00000097: NULL > > > > .debug_frame contents: > > > > > > .debug_aranges contents: > > > > .debug_line contents: > > Line table prologue: > > total_length: 0x00000037 > > version: 2 > > prologue_length: 0x0000001d > > min_inst_length: 1 > > default_is_stmt: 1 > > line_base: -5 > > line_range: 14 > > opcode_base: 13 > > standard_opcode_lengths[DW_LNS_copy] = 0 > > standard_opcode_lengths[DW_LNS_advance_pc] = 1 > > standard_opcode_lengths[DW_LNS_advance_line] = 1 > > standard_opcode_lengths[DW_LNS_set_file] = 1 > > standard_opcode_lengths[DW_LNS_set_column] = 1 > > standard_opcode_lengths[DW_LNS_negate_stmt] = 0 > > standard_opcode_lengths[DW_LNS_set_basic_block] = 0 > > standard_opcode_lengths[DW_LNS_const_add_pc] = 0 > > standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1 > > standard_opcode_lengths[DW_LNS_set_prologue_end] = 0 > > standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0 > > standard_opcode_lengths[DW_LNS_set_isa] = 1 > > Dir Mod Time File Len File Name > > ---- ---------- ---------- --------------------------- > > file_names[ 1] 0 0x00000000 0x00000000 test.c > > > > Address Line Column File ISA Flags > > ------------------ ------ ------ ------ --- ------------- > > 0x0000000000000028 2 0 1 0 is_stmt prologue_end > > 0x0000000000000050 4 0 1 0 is_stmt > > 0x0000000000000058 5 0 1 0 is_stmt > > 0x000000000000005c 6 0 1 0 is_stmt > > 0x0000000000000068 7 0 1 0 is_stmt > > 0x0000000000000084 7 0 1 0 is_stmt end_sequence > > > > .debug_str contents: > > 0x00000000: "clang version 3.3 (/opt/git.repo/clang.git/ > b422d20530588813b09057b45d5b383f0b175ced) (/opt/git.repo/llvm.git/ > 57b428f0a6be7b81bc364b0088992b1f820b516e)" > > 0x00000099: "test.c" > > 0x000000a0: "/home/yangyy/workspace/newlib" > > 0x000000be: "main" > > 0x000000c3: "int" > > 0x000000c7: "argc" > > 0x000000cc: "argv" > > 0x000000d1: "char" > > 0x000000d6: "a" > > 0x000000d8: "b" > > 0x000000da: "c" > > > > .debug_ranges contents: > > > > .debug_pubnames contents: > > Length: 0 > > Version: 0 > > Offset in .debug_info: 0 > > Size: 0 > > > > Offset Name > > > > .debug_abbrev.dwo contents: > > < EMPTY > > > > > > > > > 2014-02-19 2:28 GMT+08:00 Greg Clayton <gclayton at apple.com>: > > > > All of this information is contained in the DWARF debug info that you > must generate. Are you generating DWARF? If not, you will need to. If so, > please attach an example program that contains DWARF and specify which > function you are having trouble getting variable information for. > > > > Greg Clayton > > > > On Feb 18, 2014, at 12:44 AM, 杨勇勇 <triple.yang at gmail.com> wrote: > > > > > Hi, all > > > > > > I ported llvm backend and lldb recently. Both tools can basically work. > > > lldb is able to debug programs in asm style and frame unwinding is OK. > > > > > > But "frame variable XX" does not work because lldb is not able to > determine the address of > > > XX from debug info. > > > > > > Can someone give any clue? > > > Thanks in advance. > > > > > > -- > > > 杨勇勇 (Yang Yong-Yong) > > > _______________________________________________ > > > lldb-dev mailing list > > > lldb-dev at cs.uiuc.edu > > > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev > > > > > > > > > > -- > > 杨勇勇 (Yang Yong-Yong) > > > > > > > > -- > > 杨勇勇 (Yang Yong-Yong) > > <example.tar.bz2> > >-- 杨勇勇 (Yang Yong-Yong) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140220/3476dcb2/attachment.html>
Apparently Analagous Threads
- [LLVMdev] [lldb-dev] How is variable info retrieved in debugging for executables generated by llvm backend?
- [LLVMdev] Runtime linker issue wtih X11R6 on i386 with -O3 optimization
- GDB doesn't work with IR-originated debug info
- Debug info scope of explicit casting type does not seem correct
- [LLVMdev] [lldb-dev] How is variable info retrieved in debugging for executables generated by llvm backend?