From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 1FDA7383E53F for ; Wed, 26 Jun 2024 18:50:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FDA7383E53F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1FDA7383E53F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719427837; cv=none; b=X2SwaTycGgRFwW9fUWutWhBTkHEB8EQpwOgiWXrqYfHyWgaZJmCYDKrhuwnfH+olq2pTsvr3moD2qfaQ6MFAeDVWQi5e8qAJwbQrAhQYaxDmwV8q6NLinTWCGys5B9xDxBx/zCxJWfrTOLrJgGbLB2jUYKsz38+bBaNfgnQffX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719427837; c=relaxed/simple; bh=Uif9O96haiVijreyRKNySRyQydNUlTnb2RoX6BLa2SQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=CATjRobvBZ5T1f9GkhRjJAxpzgEEdsoyXApPXoUgrNtaTjQid8f8H5HiMik7HVshQVYBfRLbAHfHuqTGegFhycDO0Km5oMhKtRKHyqpcGONT8jJ8lqZjoRtzB+YohZ8eHxQFOfLiwmI6umH8hIgcZWQS4txfZiLd+pTmKC4bJyM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 32AEC1FB6B for ; Wed, 26 Jun 2024 18:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719427834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IeKld4FlHdvW2jY5Tiqc8fi0h8LX7nlT/P/CjruFL+s=; b=SMmyt+GpabOyJ2aREPVhEMm62o1nwId5S3eZ3VCtxFKBjs/pAXA2A6G8JkHXs+doqUpfu6 FaYf1Qkpuhxb8ExyBTMrmkB49JZG/O8c5v+HtFxK5SKxjrDMtdSEK+Du5KUcalP9aVvEUL LwLUGpRZEcOINUs+dIJdYf/K3+YIgfg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719427834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IeKld4FlHdvW2jY5Tiqc8fi0h8LX7nlT/P/CjruFL+s=; b=MTgbiqpoZSflfqVlRPZA//b7R8KumvqJMN626LyyqY1e6zVSssh0+9V98oAFbU6vUMQjd8 lHL+/RSUCCtanNDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719427834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IeKld4FlHdvW2jY5Tiqc8fi0h8LX7nlT/P/CjruFL+s=; b=SMmyt+GpabOyJ2aREPVhEMm62o1nwId5S3eZ3VCtxFKBjs/pAXA2A6G8JkHXs+doqUpfu6 FaYf1Qkpuhxb8ExyBTMrmkB49JZG/O8c5v+HtFxK5SKxjrDMtdSEK+Du5KUcalP9aVvEUL LwLUGpRZEcOINUs+dIJdYf/K3+YIgfg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719427834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IeKld4FlHdvW2jY5Tiqc8fi0h8LX7nlT/P/CjruFL+s=; b=MTgbiqpoZSflfqVlRPZA//b7R8KumvqJMN626LyyqY1e6zVSssh0+9V98oAFbU6vUMQjd8 lHL+/RSUCCtanNDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 18BFB139C2 for ; Wed, 26 Jun 2024 18:50:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gAWtBPpifGZKKAAAD6G6ig (envelope-from ) for ; Wed, 26 Jun 2024 18:50:34 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/3] [gdb/symtab] Fix incorrect complaint for imported definition Date: Wed, 26 Jun 2024 20:50:20 +0200 Message-Id: <20240626185021.12421-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240626185021.12421-1-tdevries@suse.de> References: <20240626185021.12421-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: With a minimal test-case test.c: ... int main (void) { return 0; } ... compiled like this: ... $ gcc test.c -g3 -gdwarf-5 ... I get: ... $ gdb -q -batch -iex "set complaints 100" a.out -ex "p main" During symbol reading: debug info gives source 2 included from file at zero line 0 During symbol reading: debug info gives command-line macro definition with non-zero line 19: _STDC_PREDEF_H 1 During symbol reading: debug info gives command-line macro definition with non-zero line 38: __STDC_IEC_559__ 1 During symbol reading: debug info gives command-line macro definition with non-zero line 39: __STDC_IEC_60559_BFP__ 201404L During symbol reading: debug info gives command-line macro definition with non-zero line 48: __STDC_IEC_559_COMPLEX__ 1 During symbol reading: debug info gives command-line macro definition with non-zero line 49: __STDC_IEC_60559_COMPLEX__ 201404L During symbol reading: debug info gives command-line macro definition with non-zero line 62: __STDC_ISO_10646__ 201706L $1 = {int (void)} 0x4101ac
... The complaint about _STDC_PREDEF_H is incorrect. The macro is defined in this macro unit: ... Offset: 0xb1c Version: 5 Offset size: 4 DW_MACRO_define_strp - lineno : 19 macro : _STDC_PREDEF_H 1 ... which is imported from here: ... Contents of the .debug_macro section: Offset: 0 Version: 5 Offset size: 4 Offset into .debug_line: 0 DW_MACRO_import - offset : 0x1a DW_MACRO_start_file - lineno: 0 filenum: 1 DW_MACRO_start_file - lineno: 0 filenum: 2 DW_MACRO_import - offset : 0xb1c DW_MACRO_end_file DW_MACRO_end_file ... The import happens after the first start_file, which means that the imported definition for _STDC_PREDEF_H is not a "command-line macro definition". This before/after first start_file concept is tracked in the variable at_commandline, and the problem is that it's reset when processing an import. Fix this by not resetting at_commandline when processing an import. Tested on aarch64-linux. --- gdb/dwarf2/macro.c | 28 ++++++++++--------- gdb/testsuite/gdb.dwarf2/macro-complaints.exp | 19 +++++++++++-- gdb/testsuite/lib/dwarf.exp | 12 +++++++- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index 495f30195fb..f72201ebc08 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -442,11 +442,11 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *str_section, struct dwarf2_section_info *str_offsets_section, std::optional str_offsets_base, - htab_t include_hash, struct dwarf2_cu *cu) + htab_t include_hash, struct dwarf2_cu *cu, + int &at_commandline) { struct objfile *objfile = per_objfile->objfile; enum dwarf_macro_record_type macinfo_type; - int at_commandline; const gdb_byte *opcode_definitions[256]; mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, @@ -457,15 +457,6 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, return; } - /* Determines if GDB is still before first DW_MACINFO_start_file. If true - GDB is still reading the definitions from command line. First - DW_MACINFO_start_file will need to be ignored as it was already executed - to create CURRENT_FILE for the main source holding also the command line - definitions. On first met DW_MACINFO_start_file this flag is reset to - normally execute all the remaining DW_MACINFO_start_file macinfos. */ - - at_commandline = 1; - do { /* Do we at least have room for a macinfo type byte? */ @@ -757,7 +748,8 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, current_file, lh, section, section_is_gnu, is_dwz, offset_size, str_section, str_offsets_section, - str_offsets_base, include_hash, cu); + str_offsets_base, include_hash, cu, + at_commandline); htab_remove_elt (include_hash, (void *) new_mac_ptr); } @@ -959,8 +951,18 @@ dwarf_decode_macros (dwarf2_per_objfile *per_objfile, mac_ptr = section->buffer + offset; slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT); *slot = (void *) mac_ptr; + + /* Determines if GDB is still before first DW_MACINFO_start_file. If true + GDB is still reading the definitions from command line. First + DW_MACINFO_start_file will need to be ignored as it was already executed + to create CURRENT_FILE for the main source holding also the command line + definitions. On first met DW_MACINFO_start_file this flag is reset to + normally execute all the remaining DW_MACINFO_start_file macinfos. */ + int at_commandline = 1; + dwarf_decode_macro_bytes (per_objfile, builder, abfd, mac_ptr, mac_end, current_file, lh, section, section_is_gnu, 0, offset_size, str_section, str_offsets_section, - str_offsets_base, include_hash.get (), cu); + str_offsets_base, include_hash.get (), cu, + at_commandline); } diff --git a/gdb/testsuite/gdb.dwarf2/macro-complaints.exp b/gdb/testsuite/gdb.dwarf2/macro-complaints.exp index 4e74c153a83..1a2dde36de0 100644 --- a/gdb/testsuite/gdb.dwarf2/macro-complaints.exp +++ b/gdb/testsuite/gdb.dwarf2/macro-complaints.exp @@ -31,7 +31,7 @@ set asm_file [standard_output_file $srcfile2] set line [gdb_get_line_number "return 0;"] Dwarf::assemble $asm_file { - declare_labels L cu_macro1 + declare_labels L cu_macro1 cu_macro2 cu {} { DW_TAG_compile_unit { @@ -92,8 +92,15 @@ Dwarf::assemble $asm_file { define 1 "M1_13_MALFORMED(ARG,)" define 1 "M1_14_MALFORMED()1" + import $cu_macro2 end_file } + + cu_macro2: unit { + } { + define 1 "M2_1_IMPORTED_OK 1" + define 0 "M2_2_IMPORTED_BAD 2" + } } } @@ -136,6 +143,9 @@ set re_complaint8 \ "macro debug info contains a malformed macro definition:" \ [string_to_regexp "`M1_14_MALFORMED()1'"]] +set re_complaint9 \ + "debug info gives in-file macro definition with zero line 0: M2_2_IMPORTED_BAD 2" + set prefix \ "During symbol reading" @@ -149,6 +159,7 @@ set re \ "$prefix: $re_complaint6" \ "$prefix: $re_complaint7" \ "$prefix: $re_complaint8" \ + "$prefix: $re_complaint9" \ [string cat [string_to_regexp {$}] "$decimal = \[^\r\n\]+"]] with_complaints 10 { @@ -179,7 +190,11 @@ set re_explicit \ "Defined at $srcfile:1" \ [string_to_regexp "#define M1_10_OK(ARG1, ARG2) (ARG1+ARG2)"] \ "Defined at $srcfile:1" \ - [string_to_regexp "#define M1_13_MALFORMED(ARG) "]] + [string_to_regexp "#define M1_13_MALFORMED(ARG) "] \ + "Defined at $srcfile:1" \ + "#define M2_1_IMPORTED_OK 1" \ + "Defined at $srcfile:0" \ + "-DM2_2_IMPORTED_BAD=2"] set re_implicit \ [multi_line \ diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 995cdcac941..466ae033503 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -2249,9 +2249,10 @@ namespace eval Dwarf { with_override Dwarf::define_strp Dwarf::_macro_unit_define_strp { with_override Dwarf::define Dwarf::_macro_unit_define { with_override Dwarf::start_file Dwarf::_macro_unit_start_file { + with_override Dwarf::import Dwarf::_macro_unit_import { with_override Dwarf::end_file Dwarf::_macro_unit_end_file { uplevel $body - }}}} + }}}}} _op .byte 0x0 "# End macro unit" } @@ -2292,6 +2293,15 @@ namespace eval Dwarf { _op .uleb128 $file_idx } + # Emit a DW_MACRO_import entry. + + proc _macro_unit_import { offset } { + _op .byte 0x7 "DW_MACRO_import" + + variable _mu_offset_size + _op_offset $_mu_offset_size "$offset" "import" + } + # Emit a DW_MACRO_end_file entry. proc _macro_unit_end_file {} { -- 2.35.3