From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 56E3B384A00F; Mon, 1 Feb 2021 10:40:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56E3B384A00F From: "mpoulhies at kalray dot eu" To: gdb-prs@sourceware.org Subject: [Bug gdb/27306] New: macro definition not found except when using -a Date: Mon, 01 Feb 2021 10:40:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: 10.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mpoulhies at kalray dot eu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Feb 2021 10:40:58 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D27306 Bug ID: 27306 Summary: macro definition not found except when using -a Product: gdb Version: 10.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: gdb Assignee: unassigned at sourceware dot org Reporter: mpoulhies at kalray dot eu Target Milestone: --- Created attachment 13186 --> https://sourceware.org/bugzilla/attachment.cgi?id=3D13186&action=3Ded= it objdump -g test.o (gcc version) We have ported both GCC and CLANG for a proprietary processor. Macro debugging with GCC works correctly, but not with CLANG. Looking a DWARF dumps does not show any problem (at least not for me). Applying this little patch fixes our issue : 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- diff --git a/gdb/macroscope.c b/gdb/macroscope.c index 3b02c97528e..ac906c6ecdb 100644 --- a/gdb/macroscope.c +++ b/gdb/macroscope.c @@ -52,6 +52,9 @@ sal_macro_scope (struct symtab_and_line sal) main_file =3D macro_main (COMPUNIT_MACRO_TABLE (cust)); inclusion =3D macro_lookup_inclusion (main_file, sal.symtab->filename); + if (!inclusion) + inclusion =3D macro_lookup_inclusion (main_file, sal.symtab->fullname); + if (inclusion) { ms->file =3D inclusion; 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- But that may not be the correct fix for our problem. For some reason, main_file is the full path and GDB compares it to ->filena= me which is only the last component of the full path. Adding an extra comparis= on with ->fullname allows GDB to match it as expected. Example source used: 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- #define SUM(a, b) a+b int main() { int a=3DSUM(1,2); return a; } 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- The code emitted by GCC 7 (-gdwarf-4 -g3) works without modifying GDB: 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- kvx-gdb ./test.gcc GNU gdb (GDB) 10.1 Kalray gdb version 4.4.0-6.unstable.0497f39.coolidge.dirty 0497f395-dirty Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=3Dx86_64-pc-linux-gnu --target=3Dkvx-elf= ". Type "show configuration" for configuration details. Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./test.gcc... (gdb) b main Breakpoint 1 at 0x19f64: file ../test.c, line 5. (gdb) r Starting program: /work1/mpoulhies/scratch/T15367_dwarf_clang/dw4/test.gcc Thread 2 "PE 0 of Cluster0 (mppa 0; board 0)" hit Breakpoint 1, main () at ../test.c:5 5 int a=3DSUM(1,2); (gdb) list 1 #define SUM(a, b) a+b 2 3 int main() 4 { 5 int a=3DSUM(1,2); 6 return a; 7 } (gdb) info macro SUM Defined at /work1/mpoulhies/scratch/T15367_dwarf_clang/dw4/../test.c:1 #define SUM(a, b) a+b (gdb) quit A debugging session is active. Inferior 1 [process 1] will be killed. 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- test.o: file format elf64-kvx Contents of the .debug_info section (loaded from test.o): Compilation Unit @ offset 0x0: Length: 0x63 (32-bit) Version: 4 Abbrev Offset: 0x0 Pointer Size: 8 <0>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_producer : (indirect string, offset: 0x210): GNU C11 7.5= .0 -gdwarf-4 -g3 <10> DW_AT_language : 12 (ANSI C99) <11> DW_AT_name : (indirect string, offset: 0x5eb): test.c <15> DW_AT_comp_dir : (indirect string, offset: 0x3d5): /work1/mpoulhies/scratch/T15367_dwarf_clang/dw4/retest/gcc <19> DW_AT_low_pc : 0x0 <21> DW_AT_high_pc : 0x18 <29> DW_AT_stmt_list : 0x0 <2d> DW_AT_GNU_macros : 0x0 <1><31>: Abbrev Number: 2 (DW_TAG_subprogram) <32> DW_AT_external : 1 <32> DW_AT_name : (indirect string, offset: 0x1f48): main <36> DW_AT_decl_file : 1 <37> DW_AT_decl_line : 3 <38> DW_AT_type : <0x5f> <3c> DW_AT_low_pc : 0x0 <44> DW_AT_high_pc : 0x18 <4c> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_c= fa) <4e> DW_AT_GNU_all_call_sites: 1 <4e> DW_AT_sibling : <0x5f> <2><52>: Abbrev Number: 3 (DW_TAG_variable) <53> DW_AT_name : a <55> DW_AT_decl_file : 1 <56> DW_AT_decl_line : 5 <57> DW_AT_type : <0x5f> <5b> DW_AT_location : 2 byte block: 91 7c (DW_OP_fbreg: -4) <2><5e>: Abbrev Number: 0 <1><5f>: Abbrev Number: 4 (DW_TAG_base_type) <60> DW_AT_byte_size : 4 <61> DW_AT_encoding : 5 (signed) <62> DW_AT_name : int <1><66>: Abbrev Number: 0 Contents of the .debug_abbrev section (loaded from test.o): Number TAG (0x0) 1 DW_TAG_compile_unit [has children] DW_AT_producer DW_FORM_strp DW_AT_language DW_FORM_data1 DW_AT_name DW_FORM_strp DW_AT_comp_dir DW_FORM_strp DW_AT_low_pc DW_FORM_addr DW_AT_high_pc DW_FORM_data8 DW_AT_stmt_list DW_FORM_sec_offset DW_AT_GNU_macros DW_FORM_sec_offset DW_AT value: 0 DW_FORM value: 0 2 DW_TAG_subprogram [has children] DW_AT_external DW_FORM_flag_present 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_low_pc DW_FORM_addr DW_AT_high_pc DW_FORM_data8 DW_AT_frame_base DW_FORM_exprloc DW_AT_GNU_all_call_sites DW_FORM_flag_present DW_AT_sibling DW_FORM_ref4 DW_AT value: 0 DW_FORM value: 0 3 DW_TAG_variable [no children] DW_AT_name DW_FORM_string 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_exprloc DW_AT value: 0 DW_FORM value: 0 4 DW_TAG_base_type [no children] DW_AT_byte_size DW_FORM_data1 DW_AT_encoding DW_FORM_data1 DW_AT_name DW_FORM_string DW_AT value: 0 DW_FORM value: 0 Contents of the .debug_aranges section (loaded from test.o): Length: 44 Version: 2 Offset into .debug_info: 0x0 Pointer Size: 8 Segment Size: 0 Address Length 0000000000000000 0000000000000018 0000000000000000 0000000000000000 Contents of the .debug_macro section (loaded from test.o): Offset: 0x0 Version: 4 Offset size: 4 Offset into .debug_line: 0x0 DW_MACRO_import - offset : 0x0 DW_MACRO_start_file - lineno: 0 filenum: 1 filename: test.c DW_MACRO_define_strp - lineno : 1 macro : SUM(a,b) a+b DW_MACRO_end_file Contents of the .debug_macro section (loaded from test.o): Offset: 0x0 Version: 4 Offset size: 4 DW_MACRO_define_strp - lineno : 0 macro : __STDC__ 1 DW_MACRO_define_strp - lineno : 0 macro : __STDC_VERSION__ 201112L DW_MACRO_define_strp - lineno : 0 macro : __STDC_UTF_16__ 1 DW_MACRO_define_strp - lineno : 0 macro : __STDC_UTF_32__ 1 DW_MACRO_define_strp - lineno : 0 macro : __STDC_HOSTED__ 1 DW_MACRO_define_strp - lineno : 0 macro : __GNUC__ 7 DW_MACRO_define_strp - lineno : 0 macro : __GNUC_MINOR__ 5 ... DW_MACRO_define_strp - lineno : 0 macro : __CLUSTER_OS__ 1 DW_MACRO_define_strp - lineno : 0 macro : __ELF__ 1 Raw dump of debug contents of section .debug_line (loaded from test.o): Offset: 0x0 Length: 55 DWARF Version: 3 Prologue Length: 29 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: -5 Line Range: 14 Opcode Base: 13 Opcodes: Opcode 1 has 0 args Opcode 2 has 1 arg Opcode 3 has 1 arg Opcode 4 has 1 arg Opcode 5 has 1 arg Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 arg Opcode 10 has 0 args Opcode 11 has 0 args Opcode 12 has 1 arg The Directory Table is empty. The File Name Table (offset 0x1c): Entry Dir Time Size Name 1 0 0 0 test.c Line Number Statements: [0x00000027] Extended opcode 2: set Address to 0x0 [0x00000032] Special opcode 8: advance Address by 0 to 0x0 and Line by 3= to 4 [0x00000033] Special opcode 62: advance Address by 4 to 0x4 and Line by = 1 to 5 [0x00000034] Special opcode 118: advance Address by 8 to 0xc and Line by= 1 to 6 [0x00000035] Special opcode 62: advance Address by 4 to 0x10 and Line by= 1 to 7 [0x00000036] Advance PC by 8 to 0x18 [0x00000038] Extended opcode 1: End of Sequence Contents of the .debug_str section (loaded from test.o): 0x00000000 5f5f5549 4e545f46 41535438 5f4d4158 __UINT_FAST8_MAX 0x00000010 5f5f2030 78666666 66666666 6655005f __ 0xffffffffU._ 0x00000020 5f464c54 36345f48 41535f44 454e4f52 _FLT64_HAS_DENOR 0x00000030 4d5f5f20 31005f5f 494e545f 46415354 M__ 1.__INT_FAST ... 0x00002040 2031005f 5f464c54 36345f4d 41585f31 1.__FLT64_MAX_1 0x00002050 305f4558 505f5f20 33303800 5f5f464c 0_EXP__ 308.__FL 0x00002060 545f4d41 4e545f44 49475f5f 20323400 T_MANT_DIG__ 24. Contents of the .debug_frame section (loaded from test.o): 00000000 000000000000000c ffffffff CIE Version: 1 Augmentation: "" Code alignment factor: 1 Data alignment factor: -4 Return address column: 67 DW_CFA_def_cfa: r12 ofs 0 00000010 000000000000001c 00000000 FDE cie=3D00000000 pc=3D0000000000000000..0000000000000018 DW_CFA_advance_loc: 4 to 0000000000000004 DW_CFA_def_cfa_offset: 32 DW_CFA_advance_loc: 16 to 0000000000000014 DW_CFA_def_cfa_offset: 0 DW_CFA_nop DW_CFA_nop 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- But the code emitted by clang (-g3 -fdebug-macro -gdwarf-4) does not (only clang is used from LLVM, GNU binutils are used for assembling/linking): 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- kvx-gdb ./test.clang GNU gdb (GDB) 10.1 Kalray gdb version 4.4.0-6.unstable.0497f39.coolidge.dirty 0497f395-dirty Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=3Dx86_64-pc-linux-gnu --target=3Dkvx-elf= ". Type "show configuration" for configuration details. Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./test.clang... (gdb) b main Breakpoint 1 at 0x19f90: file ../test.c, line 5. (gdb) r Starting program: /work1/mpoulhies/scratch/T15367_dwarf_clang/dw4/test.clang Thread 2 "PE 0 of Cluster0 (mppa 0; board 0)" hit Breakpoint 1, main () at ../test.c:5 5 int a=3DSUM(1,2); (gdb) info macro SUM The symbol `SUM' has no definition as a C/C++ preprocessor macro at /work1/mpoulhies/scratch/T15367_dwarf_clang/dw4/../test.c:-1 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- test.o: file format elf64-kvx Contents of the .debug_str section (loaded from test.o): 0x00000000 4b616c72 61792063 6c616e67 20766572 Kalray clang ver 0x00000010 73696f6e 2031302e 302e3120 28676974 sion 10.0.1 (git 0x00000020 3a736f66 74776172 652f746f 6f6c732f :software/tools/ 0x00000030 6c6c766d 2d70726f 6a656374 20303335 llvm-project 035 0x00000040 33306631 38386334 61663930 38336330 30f188c4af9083c0 0x00000050 39366633 66326630 31646365 38353734 96f3f2f01dce8574 0x00000060 36663939 66290074 6573742e 63002f77 6f99f).test.c./w 0x00000070 6f726b31 2f6d706f 756c6869 65732f73 ork1/mpoulhies/s 0x00000080 63726174 63682f54 31353336 375f6477 cratch/T15367_dw 0x00000090 6172665f 636c616e 672f6477 342f7265 arf_clang/dw4/re 0x000000a0 74657374 2f636c61 6e67006d 61696e00 test/clang.main. 0x000000b0 696e7400 6100 int.a. Contents of the .debug_abbrev section (loaded from test.o): Number TAG (0x0) 1 DW_TAG_compile_unit [has children] DW_AT_producer DW_FORM_strp DW_AT_language DW_FORM_data2 DW_AT_name DW_FORM_strp DW_AT_stmt_list DW_FORM_data4 DW_AT_comp_dir DW_FORM_strp DW_AT_low_pc DW_FORM_addr DW_AT_high_pc DW_FORM_addr DW_AT_macro_info DW_FORM_data4 DW_AT value: 0 DW_FORM value: 0 2 DW_TAG_subprogram [has children] DW_AT_low_pc DW_FORM_addr DW_AT_high_pc DW_FORM_addr DW_AT_frame_base DW_FORM_block1 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_external DW_FORM_flag DW_AT value: 0 DW_FORM value: 0 3 DW_TAG_variable [no children] DW_AT_location DW_FORM_block1 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 value: 0 DW_FORM value: 0 4 DW_TAG_base_type [no children] DW_AT_name DW_FORM_strp DW_AT_encoding DW_FORM_data1 DW_AT_byte_size DW_FORM_data1 DW_AT value: 0 DW_FORM value: 0 Contents of the .debug_info section (loaded from test.o): Compilation Unit @ offset 0x0: Length: 0x63 (32-bit) Version: 2 Abbrev Offset: 0x0 Pointer Size: 8 <0>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_producer : (indirect string, offset: 0x0): Kalray clang version 10.0.1 (git:software/tools/llvm-project 03530f188c4af9083c096f3f2f01dce85746f99f) <10> DW_AT_language : 12 (ANSI C99) <12> DW_AT_name : (indirect string, offset: 0x67): test.c <16> DW_AT_stmt_list : 0x0 <1a> DW_AT_comp_dir : (indirect string, offset: 0x6e): /work1/mpoulhies/scratch/T15367_dwarf_clang/dw4/retest/clang <1e> DW_AT_low_pc : 0x0 <26> DW_AT_high_pc : 0x20 <2e> DW_AT_macro_info : 0x0 <1><32>: Abbrev Number: 2 (DW_TAG_subprogram) <33> DW_AT_low_pc : 0x0 <3b> DW_AT_high_pc : 0x20 <43> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_c= fa) <45> DW_AT_name : (indirect string, offset: 0xab): main <49> DW_AT_decl_file : 1 <4a> DW_AT_decl_line : 3 <4b> DW_AT_type : <0x5f> <4f> DW_AT_external : 1 <2><50>: Abbrev Number: 3 (DW_TAG_variable) <51> DW_AT_location : 2 byte block: 91 64 (DW_OP_fbreg: -28) <54> DW_AT_name : (indirect string, offset: 0xb4): a <58> DW_AT_decl_file : 1 <59> DW_AT_decl_line : 5 <5a> DW_AT_type : <0x5f> <2><5e>: Abbrev Number: 0 <1><5f>: Abbrev Number: 4 (DW_TAG_base_type) <60> DW_AT_name : (indirect string, offset: 0xb0): int <64> DW_AT_encoding : 5 (signed) <65> DW_AT_byte_size : 4 <1><66>: Abbrev Number: 0 Contents of the .debug_macinfo section (loaded from test.o): DW_MACINFO_start_file - lineno: 0 filenum: 1 DW_MACINFO_define - lineno : 1 macro : SUM(a,b) a+b DW_MACINFO_end_file DW_MACINFO_define - lineno : 0 macro : __llvm__ 1 DW_MACINFO_define - lineno : 0 macro : __clang__ 1 DW_MACINFO_define - lineno : 0 macro : __clang_major__ 10 DW_MACINFO_define - lineno : 0 macro : __clang_minor__ 0 DW_MACINFO_define - lineno : 0 macro : __clang_patchlevel__ 1 ... DW_MACINFO_define - lineno : 0 macro : __STDC_UTF_32__ 1 Raw dump of debug contents of section .debug_line (loaded from test.o): Offset: 0x0 Length: 124 DWARF Version: 3 Prologue Length: 90 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: -5 Line Range: 14 Opcode Base: 13 Opcodes: Opcode 1 has 0 args Opcode 2 has 1 arg Opcode 3 has 1 arg Opcode 4 has 1 arg Opcode 5 has 1 arg Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 arg Opcode 10 has 0 args Opcode 11 has 0 args Opcode 12 has 1 arg The Directory Table (offset 0x1b): 1 /work1/mpoulhies/scratch/T15367_dwarf_clang/dw4/retest/clang The File Name Table (offset 0x59): Entry Dir Time Size Name 1 1 0 0 test.c Line Number Statements: [0x00000064] Extended opcode 2: set Address to 0x0 [0x0000006f] Special opcode 8: advance Address by 0 to 0x0 and Line by 3= to 4 [0x00000070] Set column to 7 [0x00000072] Set prologue_end to true [0x00000073] Special opcode 230: advance Address by 16 to 0x10 and Line = by 1 to 5 [0x00000074] Set column to 10 [0x00000076] Special opcode 62: advance Address by 4 to 0x14 and Line by= 1 to 6 [0x00000077] Set column to 3 [0x00000079] Set is_stmt to 0 [0x0000007a] Special opcode 61: advance Address by 4 to 0x18 and Line by= 0 to 6 [0x0000007b] Advance PC by 8 to 0x20 [0x0000007d] Extended opcode 1: End of Sequence Contents of the .debug_frame section (loaded from test.o): 00000000 000000000000000c ffffffff CIE Version: 1 Augmentation: "" Code alignment factor: 1 Data alignment factor: -4 Return address column: 67 DW_CFA_def_cfa: r12 ofs 0 00000010 000000000000001c 00000000 FDE cie=3D00000000 pc=3D0000000000000000..0000000000000020 DW_CFA_advance_loc: 4 to 0000000000000004 DW_CFA_def_cfa_offset: 32 DW_CFA_advance_loc: 24 to 000000000000001c DW_CFA_def_cfa_offset: 0 DW_CFA_nop DW_CFA_nop 8<----8<----8<----8<----8<----8<----8<----8<----8<----8<---- Executing the testsuite with and without the patch shows no difference. --=20 You are receiving this mail because: You are on the CC list for the bug.=