From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 154E1383E53A for ; Wed, 26 Jun 2024 18:50:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 154E1383E53A 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 154E1383E53A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719427837; cv=none; b=V3B02VecegDOy0Blz85cvnPW1XRo59MPMBBQN4akTpFX8/6P+JZmkj7ao1JLayyUyIYC4SJohMLBFLoSwltY2nUddWPdabt0+DQH//Q2fF8r5eLRRNcLtPyCaHrpOoKO7V6Dtu26KjHOqG/YYQv1fald4Ftj7CcvywVVcGmMc8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719427837; c=relaxed/simple; bh=599u+zCV966nuZMMGA8u/7UnhOLKlt7Bw4jxFY5QC04=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=sBCII/3pzHw6ZkAPb9sXh0PZpAlUOtxJxNUEFb1zqIbwOBR0YaRuEKAp3rqq3vYBwFmOF34lyrwFNov0vYqP8sPlWFpU9bMWmB0rLKiJBWLVMq0y9qVgJstVYMxK8ZX0jj96fP1Ff93wO7n0E80pHkmvaMJp9qApj5ywkvQP7WA= 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-out1.suse.de (Postfix) with ESMTPS id 0FCD421ADE 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=ltIay2Eltk1tZwD3VA42Z/8MtBm9S2FFMDqIoTskGLk=; b=se/se5FHH6CRqkUelcNosj5O9Iv1vmV20nnsCoj3VdPgH8iemW8uEEqxMLqsVDMXR3XQGG TbdnBsp2YL3+qxaAW75NBz2sAeTxC5XpvVDRP18ljoCmqntPb4l/IFVYPcPE87C/GD3ppo n31HPuqDH3jL8Uu/GT+TfB6WdxGw2OY= 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=ltIay2Eltk1tZwD3VA42Z/8MtBm9S2FFMDqIoTskGLk=; b=E4xLb7an2SJkkiKXGEfFnTN3tJ/9l4MH081mMawJhNY7wdzowKfI43f0b6ipSnkC2Ig20/ gZVhaVg+CBiVhGBQ== Authentication-Results: smtp-out1.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=ltIay2Eltk1tZwD3VA42Z/8MtBm9S2FFMDqIoTskGLk=; b=se/se5FHH6CRqkUelcNosj5O9Iv1vmV20nnsCoj3VdPgH8iemW8uEEqxMLqsVDMXR3XQGG TbdnBsp2YL3+qxaAW75NBz2sAeTxC5XpvVDRP18ljoCmqntPb4l/IFVYPcPE87C/GD3ppo n31HPuqDH3jL8Uu/GT+TfB6WdxGw2OY= 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=ltIay2Eltk1tZwD3VA42Z/8MtBm9S2FFMDqIoTskGLk=; b=E4xLb7an2SJkkiKXGEfFnTN3tJ/9l4MH081mMawJhNY7wdzowKfI43f0b6ipSnkC2Ig20/ gZVhaVg+CBiVhGBQ== 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 ED1C813AD2 for ; Wed, 26 Jun 2024 18:50:33 +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 gKV+OPlifGZKKAAAD6G6ig (envelope-from ) for ; Wed, 26 Jun 2024 18:50:33 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 1/3] [gdb/symtab] Emit malformed macro definition complaint once Date: Wed, 26 Jun 2024 20:50:19 +0200 Message-Id: <20240626185021.12421-2-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-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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[sourceware.org:url,gnu.org:url]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Level: 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,KAM_SHORT,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: Add a test-case gdb.dwarf2/macro-complaints.exp, that checks complaints for the .debug_macro section. For one malformed macro definition, I get two identical complaints: ... During symbol reading: macro debug info contains a malformed macro definition:^M `M1_11_MALFORMED(ARG'^M During symbol reading: macro debug info contains a malformed macro definition:^M `M1_11_MALFORMED(ARG'^M ... Fix this by bailing out after the first one. [ This causes a memory leak, addressed by this proposed patch ( https://sourceware.org/pipermail/gdb-patches/2024-June/210218.html ). So, the idea is to commit this series after that one. ] Tested on aarch64-linux. --- gdb/dwarf2/macro.c | 5 +- gdb/testsuite/gdb.dwarf2/macro-complaints.exp | 194 ++++++++++++++++++ 2 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.dwarf2/macro-complaints.exp diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index bc781c2cb92..495f30195fb 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -178,7 +178,10 @@ parse_macro_definition (struct macro_source_file *file, int line, p++; if (! *p || p == arg_start) - dwarf2_macro_malformed_definition_complaint (body); + { + dwarf2_macro_malformed_definition_complaint (body); + return; + } else { /* Make sure argv has room for the new argument. */ diff --git a/gdb/testsuite/gdb.dwarf2/macro-complaints.exp b/gdb/testsuite/gdb.dwarf2/macro-complaints.exp new file mode 100644 index 00000000000..4e74c153a83 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/macro-complaints.exp @@ -0,0 +1,194 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test complaints about .debug_macro section. + +load_lib dwarf.exp + +require dwarf2_support + +standard_testfile main.c .S + +lassign [function_range main $srcdir/$subdir/$srcfile] \ + main_start main_len + +set asm_file [standard_output_file $srcfile2] + +set line [gdb_get_line_number "return 0;"] + +Dwarf::assemble $asm_file { + declare_labels L cu_macro1 + + cu {} { + DW_TAG_compile_unit { + {DW_AT_name $::srcfile} + {DW_AT_macros $cu_macro1 DW_FORM_sec_offset} + {DW_AT_stmt_list $L DW_FORM_sec_offset} + } { + declare_labels int_type + + int_type: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name int} + } + DW_TAG_subprogram { + {MACRO_AT_func {main}} + {type :$int_type} + } + } + } + + lines {version 2} L { + file_name $::srcfile 1 + program { + DW_LNE_set_address $::main_start + line $::line + DW_LNS_copy + DW_LNE_set_address "$::main_start + $::main_len" + DW_LNE_end_sequence + } + } + + # Define the .debug_macro section. + macro { + cu_macro1: unit { + "debug-line-offset-label" $L + } { + define 0 "M1_01_BUILTIN_OK 1" + define 1 "M1_02_BUILTIN_BADLINE 1" + + start_file 0 1 + + define 1 "M1_03_OK 1" + define 0 "M1_04_BADLINE 1" + + start_file 1 1234 + define 1 "M1_05_BADFILE 1" + end_file + + define 1 "M1_06_OK " + define 1 "M1_07_MALFORMED" + define 1 "M1_08_OK() 1" + define 1 "M1_09_OK(ARG) (ARG)" + define 1 "M1_10_OK(ARG1,ARG2) (ARG1+ARG2)" + + define 1 "M1_11_MALFORMED(ARG" + define 1 "M1_12_MALFORMED(ARG," + define 1 "M1_13_MALFORMED(ARG,)" + define 1 "M1_14_MALFORMED()1" + + end_file + } + } +} + +if { [prepare_for_testing "failed to prepare" $testfile \ + [list $srcfile $asm_file] {nodebug}] } { + return +} + +set re_complaint1 \ + "debug info gives command-line macro definition with non-zero line 1: M1_02_BUILTIN_BADLINE 1" + +set re_complaint2 \ + "debug info gives in-file macro definition with zero line 0: M1_04_BADLINE 1" + +set re_complaint3 \ + [string_to_regexp "bad file number in macro information (1234)"] + +set re_complaint4 \ + [multi_line \ + "macro debug info contains a malformed macro definition:" \ + "`M1_07_MALFORMED'"] + +set re_complaint5 \ + [multi_line \ + "macro debug info contains a malformed macro definition:" \ + [string_to_regexp "`M1_11_MALFORMED(ARG'"]] + +set re_complaint6 \ + [multi_line \ + "macro debug info contains a malformed macro definition:" \ + [string_to_regexp "`M1_12_MALFORMED(ARG,'"]] + +set re_complaint7 \ + [multi_line \ + "macro debug info contains a malformed macro definition:" \ + [string_to_regexp "`M1_13_MALFORMED(ARG,)'"]] + +set re_complaint8 \ + [multi_line \ + "macro debug info contains a malformed macro definition:" \ + [string_to_regexp "`M1_14_MALFORMED()1'"]] + +set prefix \ + "During symbol reading" + +set re \ + [multi_line \ + "$prefix: $re_complaint1" \ + "$prefix: $re_complaint2" \ + "$prefix: $re_complaint3" \ + "$prefix: $re_complaint4" \ + "$prefix: $re_complaint5" \ + "$prefix: $re_complaint6" \ + "$prefix: $re_complaint7" \ + "$prefix: $re_complaint8" \ + [string cat [string_to_regexp {$}] "$decimal = \[^\r\n\]+"]] + +with_complaints 10 { + gdb_test "print main" ^$re "complaints" +} + +set re_explicit \ + [multi_line \ + "Defined at $srcfile:0" \ + "-DM1_01_BUILTIN_OK=1" \ + "Defined at $srcfile:1" \ + "#define M1_02_BUILTIN_BADLINE 1" \ + "Defined at $srcfile:1" \ + "#define M1_03_OK 1" \ + "Defined at $srcfile:0" \ + "-DM1_04_BADLINE=1" \ + "Defined at :1" \ + " included at $srcfile:1" \ + "#define M1_05_BADFILE 1" \ + "Defined at $srcfile:1" \ + "#define M1_06_OK " \ + "Defined at $srcfile:1" \ + "#define M1_07_MALFORMED " \ + "Defined at $srcfile:1" \ + [string_to_regexp "#define M1_08_OK() 1"] \ + "Defined at $srcfile:1" \ + [string_to_regexp "#define M1_09_OK(ARG) (ARG)"] \ + "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) "]] + +set re_implicit \ + [multi_line \ + "Defined at $srcfile:-1" \ + "#define __FILE__ \"$srcfile\"" \ + "Defined at $srcfile:-1" \ + "#define __LINE__ $line"] + +gdb_test "info macros $line" \ + [multi_line \ + $re_explicit \ + $re_implicit] -- 2.35.3