public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
@ 2023-02-24 12:35 Tom de Vries
  2023-02-24 19:33 ` Tom Tromey
  0 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2023-02-24 12:35 UTC (permalink / raw)
  To: gdb-patches

[ 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 <http://www.gnu.org/licenses/>.  */
+
+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 <http://www.gnu.org/licenses/>.  */
+
+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 <http://www.gnu.org/licenses/>.
+
+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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-02-24 12:35 [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off Tom de Vries
@ 2023-02-24 19:33 ` Tom Tromey
  2023-02-25  8:42   ` Tom de Vries
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2023-02-24 19:33 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom de Vries

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> The setting is off by default, preserving current behaviour.

Tom> A bit of background on the relevance of reading order: the formats have a
Tom> priority relationship between them, where reading earlier means lower
Tom> priority.  By reading the format with the most detail last, we ensure it has
Tom> the highest priority, which makes sure that in case there is overlapping info,
Tom> the most detailed info is found.  This explains the current reading order of
Tom> mdebug, stabs and dwarf2.

Tom> Add the unconditional reading of ctf before dwarf2, because it's less detailed
Tom> than dwarf2.  The conditional reading of ctf is still done after the attempt to
Tom> read dwarf2, necessarily so because we only know whether there's dwarf2 after
Tom> we've tried to read it.

I'm sorry I didn't comment on the earlier thread.

I wonder if the current behavior is important.  Why not just always read
all the debug info that gdb supports?  This is how stabs+DWARF works and
it makes a certain kind of sense -- due to separate compilation, you can
wind up with an aggregate object (like an executable) where each
individual part was made differently.

That is, instead of the option, why not make it unconditional?

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-02-24 19:33 ` Tom Tromey
@ 2023-02-25  8:42   ` Tom de Vries
  2023-02-25 12:34     ` Tom Tromey
  0 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2023-02-25  8:42 UTC (permalink / raw)
  To: Tom Tromey, Tom de Vries via Gdb-patches

On 2/24/23 20:33, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Tom> The setting is off by default, preserving current behaviour.
> 
> Tom> A bit of background on the relevance of reading order: the formats have a
> Tom> priority relationship between them, where reading earlier means lower
> Tom> priority.  By reading the format with the most detail last, we ensure it has
> Tom> the highest priority, which makes sure that in case there is overlapping info,
> Tom> the most detailed info is found.  This explains the current reading order of
> Tom> mdebug, stabs and dwarf2.
> 
> Tom> Add the unconditional reading of ctf before dwarf2, because it's less detailed
> Tom> than dwarf2.  The conditional reading of ctf is still done after the attempt to
> Tom> read dwarf2, necessarily so because we only know whether there's dwarf2 after
> Tom> we've tried to read it.
> 
> I'm sorry I didn't comment on the earlier thread.
> 
> I wonder if the current behavior is important.  Why not just always read
> all the debug info that gdb supports?  This is how stabs+DWARF works and
> it makes a certain kind of sense -- due to separate compilation, you can
> wind up with an aggregate object (like an executable) where each
> individual part was made differently.
> 
> That is, instead of the option, why not make it unconditional?

I found this ( https://lwn.net/Articles/795384/ ) article stating:
...
CTF was created out of a desire to be able to perform most debugging 
tasks even in the absence of debuginfo packages
...

So, I think CTF support in GDB was added with the following model in mind:
- a package is compiled with both ctf and dwarf info, each covering the
   entire package.
- the ctf stays in the package, the dwarf is split off into a debuginfo
   package
- if the debuginfo package is installed, use it, so read dwarf and skip
    ctf
- if debuginfo package is not installed, use ctf

If we'd both read dwarf and ctf, in the described scenario reading the 
ctf would be a waste of time and memory (though I'm not sure how much. 
maybe it's acceptable?), because you'd have the dwarf anyway.

Hmm, I'm starting to wonder now, perhaps a way to cover both scenarios 
(the one described above and the non-overlapping dwarf+ctf one I'm 
trying to fix) is to check where the dwarf came from:
- if the dwarf resides in the same object file as the ctf, read both
- if the dwarf doesn't come from the same object file (so, it comes from
   a debug info package or debug info server), skip the ctf

I suppose that'll work, but even so I still think it makes sense to make 
it configurable.  For instance, the added test-case in combination with 
target board cc-with-gnu-debuglink will need convincing to read both ctf 
an dwarf, even if the dwarf has been split off.

WDYT?

Thanks,
- Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-02-25  8:42   ` Tom de Vries
@ 2023-02-25 12:34     ` Tom Tromey
  2023-02-26  8:25       ` Tom de Vries
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2023-02-25 12:34 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Tom Tromey, Tom de Vries via Gdb-patches

Tom> Hmm, I'm starting to wonder now, perhaps a way to cover both scenarios
Tom> (the one described above and the non-overlapping dwarf+ctf one I'm
Tom> trying to fix) is to check where the dwarf came from:
Tom> - if the dwarf resides in the same object file as the ctf, read both
Tom> - if the dwarf doesn't come from the same object file (so, it comes from
Tom>   a debug info package or debug info server), skip the ctf

Tom> I suppose that'll work, but even so I still think it makes sense to
Tom> make it configurable.  For instance, the added test-case in
Tom> combination with target board cc-with-gnu-debuglink will need
Tom> convincing to read both ctf an dwarf, even if the dwarf has been split
Tom> off.

Tom> WDYT?

I think your original approach is fine as well, and I'd hate to make it
more complicated for you.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-02-25 12:34     ` Tom Tromey
@ 2023-02-26  8:25       ` Tom de Vries
  2023-03-02  1:56         ` Tom Tromey
  0 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2023-02-26  8:25 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Tom de Vries via Gdb-patches

On 2/25/23 13:34, Tom Tromey wrote:
> Tom> Hmm, I'm starting to wonder now, perhaps a way to cover both scenarios
> Tom> (the one described above and the non-overlapping dwarf+ctf one I'm
> Tom> trying to fix) is to check where the dwarf came from:
> Tom> - if the dwarf resides in the same object file as the ctf, read both
> Tom> - if the dwarf doesn't come from the same object file (so, it comes from
> Tom>   a debug info package or debug info server), skip the ctf
> 
> Tom> I suppose that'll work, but even so I still think it makes sense to
> Tom> make it configurable.  For instance, the added test-case in
> Tom> combination with target board cc-with-gnu-debuglink will need
> Tom> convincing to read both ctf an dwarf, even if the dwarf has been split
> Tom> off.
> 
> Tom> WDYT?
> 
> I think your original approach is fine as well, and I'd hate to make it
> more complicated for you.
> 

OK, then let's go with that.

As for syntax, I went now first for the simplest approach, an on/off 
setting:
...
set always-read-ctf <on|off>
...
which itself for instance could be reformulated as read-ctf-always or 
ctf-read-always, I'm not sure if there's a preferred scheme for things 
like that.

Furthermore, I wonder, if we want to keep the possibility open of adding 
additional ways to handle this in the future, should we go instead with 
something like:
...
set read-ctf <no-dwarf2|yes>
...
or:
...
set ctf-read <no-dwarf2|yes>
...
or:
...
set ctf-read <no-dwarf2|always>
...
such that we could add the strategy proposed above as say 
no-external-dwarf2.

Or am I unnecessarily complicating things?

Thanks,
- Tom


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-02-26  8:25       ` Tom de Vries
@ 2023-03-02  1:56         ` Tom Tromey
  2023-03-02  7:18           ` Tom de Vries
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2023-03-02  1:56 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Tom Tromey, Tom de Vries via Gdb-patches

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> As for syntax, I went now first for the simplest approach, an on/off
Tom> setting:
Tom> ...
Tom> set always-read-ctf <on|off>
Tom> ...
Tom> which itself for instance could be reformulated as read-ctf-always or
Tom> ctf-read-always, I'm not sure if there's a preferred scheme for things
Tom> like that.

Is it something normal users will want?  If not we can make it a maint
setting and then our future options are open.

Tom> Furthermore, I wonder, if we want to keep the possibility open of
Tom> adding additional ways to handle this in the future, should we go
Tom> instead with something like:
Tom> ...
Tom> set read-ctf <no-dwarf2|yes>

We can always turn it into a deprecated alias and rename it if we later
change our minds, so I wouldn't worry excessively about it.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-03-02  1:56         ` Tom Tromey
@ 2023-03-02  7:18           ` Tom de Vries
  2023-03-02  9:38             ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2023-03-02  7:18 UTC (permalink / raw)
  To: Tom Tromey, Eli Zaretskii; +Cc: Tom de Vries via Gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1583 bytes --]

On 3/2/23 02:56, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> As for syntax, I went now first for the simplest approach, an on/off
> Tom> setting:
> Tom> ...
> Tom> set always-read-ctf <on|off>
> Tom> ...
> Tom> which itself for instance could be reformulated as read-ctf-always or
> Tom> ctf-read-always, I'm not sure if there's a preferred scheme for things
> Tom> like that.
> 
> Is it something normal users will want?  If not we can make it a maint
> setting and then our future options are open.
> 

I think normal users will want it.

On openSUSE, due the the startfiles containing DWARF, a simple exec 
created with:
...
$ gcc -gctf hello.c
...
will contain both dwarf and ctf, and gdb will only read the dwarf.

There are a couple of ways to get around that:
- use -nostartfiles/-nostdlib, or
- use Wl,--strip-debug
- use strip -g

But eventually, somebody will be in the position of having to debug an 
exec containing both dwarf and ctf, and needing info from both.

> Tom> Furthermore, I wonder, if we want to keep the possibility open of
> Tom> adding additional ways to handle this in the future, should we go
> Tom> instead with something like:
> Tom> ...
> Tom> set read-ctf <no-dwarf2|yes>
> 
> We can always turn it into a deprecated alias and rename it if we later
> change our minds, so I wouldn't worry excessively about it.

Ack, in that case let's go with the current approach.

I've updated the doc by mentioning the default, and added a NEWS item.

Eli, could you please review the doc and NEWS bits?

Thanks,
- Tom




[-- Attachment #2: 0001-gdb-symtab-Add-set-show-always-read-ctf-on-off.patch --]
[-- Type: text/x-patch, Size: 9922 bytes --]

From ecacfe80ff6e71cb35619254d00f54a110409b01 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Wed, 22 Feb 2023 16:54:18 +0100
Subject: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off

[ 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/NEWS                                 |  5 +++
 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 ++++++++++++++++++++++++
 6 files changed, 141 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/NEWS b/gdb/NEWS
index bea604d7e75..c32ff92c98a 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -68,6 +68,11 @@ maintenance info frame-unwinders
   List the frame unwinders currently in effect, starting with the highest
   priority.
 
+set always-read-ctf on|off
+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.  Off by default.
+
 * New convenience function "$_shell", to execute a shell command and
   return the result.  This lets you run shell commands in expressions.
   Some examples:
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c1ca45521ea..85fe2158ce8 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.  The default value if off.
+
 @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 <http://www.gnu.org/licenses/>.  */
+
+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 <http://www.gnu.org/licenses/>.  */
+
+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 <http://www.gnu.org/licenses/>.
+
+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: 14ade916606152d67689842eef8b4b4f2a5eadf7
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-03-02  7:18           ` Tom de Vries
@ 2023-03-02  9:38             ` Eli Zaretskii
  2023-03-02  9:58               ` Tom de Vries
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2023-03-02  9:38 UTC (permalink / raw)
  To: Tom de Vries; +Cc: tom, gdb-patches

> Date: Thu, 2 Mar 2023 08:18:45 +0100
> Cc: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
> From: Tom de Vries <tdevries@suse.de>
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index bea604d7e75..c32ff92c98a 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -68,6 +68,11 @@ maintenance info frame-unwinders
>    List the frame unwinders currently in effect, starting with the highest
>    priority.
>  
> +set always-read-ctf on|off
> +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.  Off by default.
> +
>  * New convenience function "$_shell", to execute a shell command and
>    return the result.  This lets you run shell commands in expressions.
>    Some examples:

This part is OK.

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index c1ca45521ea..85fe2158ce8 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

I'd add a @cindex entry that begins with CTF, something like

  @cindex CTF info, when to read

> +When off, CTF is only read if DWARF is not present.  When on, CTF is
> +read regardless of whether DWARF is present.  The default value if off.

It's probably "CTF debug info" and "DWARF debug info", right?

Thanks.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off
  2023-03-02  9:38             ` Eli Zaretskii
@ 2023-03-02  9:58               ` Tom de Vries
  0 siblings, 0 replies; 9+ messages in thread
From: Tom de Vries @ 2023-03-02  9:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: tom, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1865 bytes --]

On 3/2/23 10:38, Eli Zaretskii wrote:
>> Date: Thu, 2 Mar 2023 08:18:45 +0100
>> Cc: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
>> From: Tom de Vries <tdevries@suse.de>
>>
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index bea604d7e75..c32ff92c98a 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -68,6 +68,11 @@ maintenance info frame-unwinders
>>     List the frame unwinders currently in effect, starting with the highest
>>     priority.
>>   
>> +set always-read-ctf on|off
>> +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.  Off by default.
>> +
>>   * New convenience function "$_shell", to execute a shell command and
>>     return the result.  This lets you run shell commands in expressions.
>>     Some examples:
> 
> This part is OK.
> 
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index c1ca45521ea..85fe2158ce8 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
> 
> I'd add a @cindex entry that begins with CTF, something like
> 
>    @cindex CTF info, when to read
> 

Added.

>> +When off, CTF is only read if DWARF is not present.  When on, CTF is
>> +read regardless of whether DWARF is present.  The default value if off.
> 
> It's probably "CTF debug info" and "DWARF debug info", right?
> 

Fixed, as well as the "value if off" typo.

> Thanks.
> 
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>

Thanks for the review, committed as attached.

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-symtab-Add-set-show-always-read-ctf-on-off.patch --]
[-- Type: text/x-patch, Size: 10084 bytes --]

From 0d5adb56c85da38a0f95e872fda05cc6446010c3 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Thu, 2 Mar 2023 10:56:40 +0100
Subject: [pushed] [gdb/symtab] Add set/show always-read-ctf on/off

[ 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.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Tom Tromey <tom@tromey.com>
---
 gdb/NEWS                                 |  5 +++
 gdb/doc/gdb.texinfo                      | 11 +++++
 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 ++++++++++++++++++++++++
 6 files changed, 143 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/NEWS b/gdb/NEWS
index bea604d7e75..c32ff92c98a 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -68,6 +68,11 @@ maintenance info frame-unwinders
   List the frame unwinders currently in effect, starting with the highest
   priority.
 
+set always-read-ctf on|off
+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.  Off by default.
+
 * New convenience function "$_shell", to execute a shell command and
   return the result.  This lets you run shell commands in expressions.
   Some examples:
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c1ca45521ea..bfda7edc4f7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20365,6 +20365,17 @@ 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
+@cindex CTF info, when to read
+@item set always-read-ctf [on|off]
+@itemx show always-read-ctf
+
+When off, CTF debug info is only read if DWARF debug info is not
+present.  When on, CTF debug info is read regardless of whether DWARF
+debug info is present.  The default value is off.
+
 @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 <http://www.gnu.org/licenses/>.  */
+
+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 <http://www.gnu.org/licenses/>.  */
+
+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 <http://www.gnu.org/licenses/>.
+
+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: 14ade916606152d67689842eef8b4b4f2a5eadf7
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-03-02  9:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 12:35 [PATCH] [gdb/symtab] Add set/show always-read-ctf on/off Tom de Vries
2023-02-24 19:33 ` Tom Tromey
2023-02-25  8:42   ` Tom de Vries
2023-02-25 12:34     ` Tom Tromey
2023-02-26  8:25       ` Tom de Vries
2023-03-02  1:56         ` Tom Tromey
2023-03-02  7:18           ` Tom de Vries
2023-03-02  9:38             ` Eli Zaretskii
2023-03-02  9:58               ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).