From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 6BDC7385840F for ; Fri, 24 Feb 2023 12:35:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BDC7385840F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A526838C72 for ; Fri, 24 Feb 2023 12:35:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677242101; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DT5z6s+Kc5hJDyd4yv1QjOcgHmK1ssAcvVTMT/JI1qI=; b=Dyjq11P8L9D8V4ERTIz82FOJfQunIAiDIB3sP3QvWXXLTgNtFKKjXMAjD7SwpgUBAh+zrh YauLacByYfv2j4T3FxaOgvAH+JRytFqTm6FUSYgcrKpDNLC3o/kWwcG7tEFIcKSrEMS9ZQ ozMMwvJJB/1jODT4yw+KPaWdXq6iId8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677242101; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DT5z6s+Kc5hJDyd4yv1QjOcgHmK1ssAcvVTMT/JI1qI=; b=HRBd+iieLHhm3t/EsUIF1BfuG9n1Qvdb2G1BJaW8wsOcJGiqqIqMdC3PSNJ6WVrC30tM7W ikPzaOYt1LCMFWCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9315313246 for ; Fri, 24 Feb 2023 12:35:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WP+2IvWu+GNjKAAAMHmgww (envelope-from ) for ; Fri, 24 Feb 2023 12:35:01 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off Date: Fri, 24 Feb 2023 13:35:22 +0100 Message-Id: <20230224123522.21756-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: [ This is a simplified rewrite of an earlier submission "[RFC][gdb/symtab] Add maint set symbol-read-order", submitted here ( https://sourceware.org/pipermail/gdb-patches/2022-September/192044.html ). ] With the test-case included in this patch, we run into: ... (gdb) file dwarf2-and-ctf (gdb) print var_ctf^M 'var_ctf' has unknown type; cast it to its declared type^M ... The problem is that the executable contains both ctf and dwarf2, so the ctf info (which contains the type information about var_ctf) is ignored. GDB has support for handling multiple debug formats, but the common use case for ctf is to be used when dwarf2 is not present, and gdb reflects that, assuming that by reading ctf in addition there won't be any extra information, so it's not worth the additional cycles and memory. Add a new command "set/show always-read-ctf on/off", that when on forces unconditional reading of ctf, allowing us to do: ... (gdb) set always-read-ctf on (gdb) file dwarf2-and-ctf (gdb) print var_ctf^M $2 = 2^M ... The setting is off by default, preserving current behaviour. A bit of background on the relevance of reading order: the formats have a priority relationship between them, where reading earlier means lower priority. By reading the format with the most detail last, we ensure it has the highest priority, which makes sure that in case there is overlapping info, the most detailed info is found. This explains the current reading order of mdebug, stabs and dwarf2. Add the unconditional reading of ctf before dwarf2, because it's less detailed than dwarf2. The conditional reading of ctf is still done after the attempt to read dwarf2, necessarily so because we only know whether there's dwarf2 after we've tried to read it. The new command allow us to replace uses of -Wl,--strip-debug added in commit 908a926ec4e ("[gdb/testsuite] Fix ctf test-cases on openSUSE Tumbleweed") by uses of "set always-read-ctf on", but I've left that for another commit. Tested on x86_64-linux. --- gdb/doc/gdb.texinfo | 9 ++++ gdb/elfread.c | 24 ++++++++++- gdb/testsuite/gdb.ctf/dwarf2-and-ctf-2.c | 24 +++++++++++ gdb/testsuite/gdb.ctf/dwarf2-and-ctf.c | 26 ++++++++++++ gdb/testsuite/gdb.ctf/dwarf2-and-ctf.exp | 54 ++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.ctf/dwarf2-and-ctf-2.c create mode 100644 gdb/testsuite/gdb.ctf/dwarf2-and-ctf.c create mode 100644 gdb/testsuite/gdb.ctf/dwarf2-and-ctf.exp diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index c1ca45521ea..38bdc0369bc 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20365,6 +20365,15 @@ location to represent a line or a statement. The @samp{PROLOGUE-END} column indicates that a given address is an adequate place to set a breakpoint at the first instruction following a function prologue. +@kindex set always-read-ctf [on|off] +@kindex show always-read-ctf +@cindex always-read-ctf +@item set always-read-ctf [on|off] +@itemx show always-read-ctf + +When off, CTF is only read if DWARF is not present. When on, CTF is +read regardless of whether DWARF is present. + @kindex maint set symbol-cache-size @cindex symbol cache size @item maint set symbol-cache-size @var{size} diff --git a/gdb/elfread.c b/gdb/elfread.c index ca684aab57e..00939a0f13a 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -51,6 +51,10 @@ #include "gdbsupport/scoped_fd.h" #include "debuginfod-support.h" #include "dwarf2/public.h" +#include "cli/cli-cmds.h" + +/* Whether ctf should always be read, or only if no dwarf is present. */ +static bool always_read_ctf; /* The struct elfinfo is available only during ELF symbol table and psymtab reading. It is destroyed at the completion of psymtab-reading. @@ -1349,10 +1353,16 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) bfd_section_size (str_sect)); } + /* Read the CTF section only if there is no DWARF info. */ + if (always_read_ctf && ei.ctfsect) + { + elfctf_build_psymtabs (objfile); + } + bool has_dwarf2 = elf_symfile_read_dwarf2 (objfile, symfile_flags); /* Read the CTF section only if there is no DWARF info. */ - if (!has_dwarf2 && ei.ctfsect) + if (!always_read_ctf && !has_dwarf2 && ei.ctfsect) { elfctf_build_psymtabs (objfile); } @@ -1449,4 +1459,16 @@ _initialize_elfread () add_symtab_fns (bfd_target_elf_flavour, &elf_sym_fns); gnu_ifunc_fns_p = &elf_gnu_ifunc_fns; + + /* Add "set always-read-ctf on/off". */ + add_setshow_boolean_cmd ("always-read-ctf", class_support, &always_read_ctf, + _("\ +Set whether CTF is always read."), + _("\ +Show whether CTF is always read."), + _("\ +When off, CTF is only read if DWARF is not present. When on, CTF is read\ + regardless of whether DWARF is present."), + nullptr /* set_func */, nullptr /* show_func */, + &setlist, &showlist); } diff --git a/gdb/testsuite/gdb.ctf/dwarf2-and-ctf-2.c b/gdb/testsuite/gdb.ctf/dwarf2-and-ctf-2.c new file mode 100644 index 00000000000..daa45be3311 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/dwarf2-and-ctf-2.c @@ -0,0 +1,24 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 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 . */ + +int var_ctf = 2; + +int +foo (void) +{ + return var_ctf; +} diff --git a/gdb/testsuite/gdb.ctf/dwarf2-and-ctf.c b/gdb/testsuite/gdb.ctf/dwarf2-and-ctf.c new file mode 100644 index 00000000000..436ebcc741a --- /dev/null +++ b/gdb/testsuite/gdb.ctf/dwarf2-and-ctf.c @@ -0,0 +1,26 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 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 . */ + +int var_dwarf = 1; + +extern int foo (); + +int +main (void) +{ + return var_dwarf + foo (); +} diff --git a/gdb/testsuite/gdb.ctf/dwarf2-and-ctf.exp b/gdb/testsuite/gdb.ctf/dwarf2-and-ctf.exp new file mode 100644 index 00000000000..22162cfc070 --- /dev/null +++ b/gdb/testsuite/gdb.ctf/dwarf2-and-ctf.exp @@ -0,0 +1,54 @@ +# Copyright 2023 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 . + +require allow_ctf_tests + +standard_testfile .c -2.c + +set objfile [standard_output_file ${testfile}.o] +set objfile2 [standard_output_file ${testfile}-2.o] + +set s1 ${srcdir}/${subdir}/${srcfile} +set s2 ${srcdir}/${subdir}/${srcfile2} + +set opts {} +lappend opts debug +if { [gdb_compile $s1 ${objfile} object $opts] != "" } { + untested "failed to compile" + return -1 +} + +set opts {} +lappend opts "additional_flags=-gctf" +if { [gdb_compile $s2 ${objfile2} object $opts] != "" } { + untested "failed to compile" + return -1 +} + +set opts {} +lappend opts "additional_flags=-Wl,-ctf-variables" +if { [gdb_compile [list ${objfile} ${objfile2}] $binfile executable $opts] != "" } { + unsupported "failed to link" + return -1 +} + +clean_restart + +gdb_test_no_output "set always-read-ctf on" + +gdb_load $binfile + +gdb_test "print var_dwarf" " = 1" +gdb_test "print var_ctf" " = 2" base-commit: 18e7a6587e3f111e9367ea707f9eb21acf4b9af7 -- 2.35.3