public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: use actual DWARF version in compunit's debugformat field
@ 2021-11-19  2:08 Simon Marchi
  2021-11-19  2:10 ` Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Simon Marchi @ 2021-11-19  2:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

The "info source" command, with a DWARF-compile program, always show
that the debug info is "DWARF 2":

    (gdb) info source
    Current source file is test.c
    Compilation directory is /home/smarchi/build/binutils-gdb/gdb
    Located in /home/smarchi/build/binutils-gdb/gdb/test.c
    Contains 2 lines.
    Source language is c.
    Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
    Compiled with DWARF 2 debugging format.
    Includes preprocessor macro info.

Change it to display the actual DWARF version:

    (gdb) info source
    Current source file is test.c
    Compilation directory is /home/smarchi/build/binutils-gdb/gdb
    Located in /home/smarchi/build/binutils-gdb/gdb/test.c
    Contains 2 lines.
    Source language is c.
    Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
    Compiled with DWARF 5 debugging format.
    Includes preprocessor macro info.

The debug format strings need to live as long as the obfile itself, so
the most straightforward thing to do is to save those strings on the
objfile's obstack.  But it seems like we don't have an equivalent of
"obstack_printf".  An obstack_printf function is provided by glibc:

  https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html

... and there's even a gnulib module for it:

  https://www.gnu.org/software/gnulib/manual/html_node/obstack_005fprintf.html

However, since GDB uses its own obstack implementation (include/obstack.h), I
don't think it would be safe to use a glibc obstack function and pass it a GDB
obstack.  The obstack struct layouts might not be the same.

Implement some simple gdb_obstack_printf/gdb_obstack_vprintf functions
to work around that.

Change-Id: I3270b7ebf5e9a17b4215405bd2e365662a4d6172
---
 gdb/dwarf2/cu.c   |  5 ++++-
 gdb/gdb_obstack.c | 32 ++++++++++++++++++++++++++++++++
 gdb/gdb_obstack.h |  8 ++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index e7aed774c25..371005ab7ce 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -64,7 +64,10 @@ dwarf2_cu::start_symtab (const char *name, const char *comp_dir,
 
   list_in_scope = get_builder ()->get_file_symbols ();
 
-  get_builder ()->record_debugformat ("DWARF 2");
+  get_builder ()->record_debugformat
+    (gdb_obstack_printf
+       (&this->per_objfile->objfile->objfile_obstack,
+	"DWARF %u", this->header.version));
   get_builder ()->record_producer (producer);
 
   processing_has_namespace_info = false;
diff --git a/gdb/gdb_obstack.c b/gdb/gdb_obstack.c
index 3833a6d69a1..d06942884e6 100644
--- a/gdb/gdb_obstack.c
+++ b/gdb/gdb_obstack.c
@@ -19,6 +19,7 @@
 
 #include "defs.h"
 #include "gdb_obstack.h"
+#include <stdio.h>
 
 /* Concatenate NULL terminated variable argument list of `const char *'
    strings; return the new string.  Space is found in the OBSTACKP.
@@ -45,3 +46,34 @@ obconcat (struct obstack *obstackp, ...)
 
   return (char *) obstack_finish (obstackp);
 }
+
+/* See gdb_obstack.h.  */
+
+const char *
+gdb_obstack_vprintf (obstack *ob, const char *fmt, va_list args)
+{
+  va_list args_copy;
+
+  va_copy (args_copy, args);
+  size_t size = vsnprintf (nullptr, 0, fmt, args_copy);
+  va_end (args_copy);
+
+  char *str = XOBNEWVEC (ob, char, size + 1);
+  vsprintf (str, fmt, args);
+
+  return str;
+}
+
+/* See gdb_obstack.h.  */
+
+const char *
+gdb_obstack_printf (obstack *ob, const char *fmt, ...)
+{
+  va_list args;
+
+  va_start (args, fmt);
+  const char *str = gdb_obstack_vprintf (ob, fmt, args);
+  va_end (args);
+
+  return str;
+}
diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h
index f743bdd3eb1..dc752853dcf 100644
--- a/gdb/gdb_obstack.h
+++ b/gdb/gdb_obstack.h
@@ -21,6 +21,7 @@
 #define GDB_OBSTACK_H 1
 
 #include "obstack.h"
+#include <stdarg.h>
 
 /* Utility macros - wrap obstack alloc into something more robust.  */
 
@@ -116,6 +117,13 @@ obstack_strndup (struct obstack *obstackp, const char *string, size_t n)
   return (char *) obstack_copy0 (obstackp, string, n);
 }
 
+/* Write a formatted string to obstack OB.  */
+
+const char *gdb_obstack_vprintf (obstack *ob, const char *fmt, va_list args)
+  ATTRIBUTE_PRINTF (2, 0);
+const char *gdb_obstack_printf (obstack *ob, const char *fmt, ...)
+  ATTRIBUTE_PRINTF (2, 3);
+
 /* An obstack that frees itself on scope exit.  */
 struct auto_obstack : obstack
 {
-- 
2.33.1


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

* Re: [PATCH] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-19  2:08 [PATCH] gdb: use actual DWARF version in compunit's debugformat field Simon Marchi
@ 2021-11-19  2:10 ` Simon Marchi
  2021-11-19 18:32 ` Pedro Alves
  2021-11-19 20:41 ` Tom Tromey
  2 siblings, 0 replies; 12+ messages in thread
From: Simon Marchi @ 2021-11-19  2:10 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2021-11-18 21:08, Simon Marchi via Gdb-patches wrote:
> The "info source" command, with a DWARF-compile program, always show
> that the debug info is "DWARF 2":
> 
>     (gdb) info source
>     Current source file is test.c
>     Compilation directory is /home/smarchi/build/binutils-gdb/gdb
>     Located in /home/smarchi/build/binutils-gdb/gdb/test.c
>     Contains 2 lines.
>     Source language is c.
>     Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
>     Compiled with DWARF 2 debugging format.
>     Includes preprocessor macro info.
> 
> Change it to display the actual DWARF version:
> 
>     (gdb) info source
>     Current source file is test.c
>     Compilation directory is /home/smarchi/build/binutils-gdb/gdb
>     Located in /home/smarchi/build/binutils-gdb/gdb/test.c
>     Contains 2 lines.
>     Source language is c.
>     Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
>     Compiled with DWARF 5 debugging format.
>     Includes preprocessor macro info.
> 
> The debug format strings need to live as long as the obfile itself, so
> the most straightforward thing to do is to save those strings on the
> objfile's obstack.  But it seems like we don't have an equivalent of
> "obstack_printf".  An obstack_printf function is provided by glibc:
> 
>   https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html
> 
> ... and there's even a gnulib module for it:
> 
>   https://www.gnu.org/software/gnulib/manual/html_node/obstack_005fprintf.html
> 
> However, since GDB uses its own obstack implementation (include/obstack.h), I
> don't think it would be safe to use a glibc obstack function and pass it a GDB
> obstack.  The obstack struct layouts might not be the same.
> 
> Implement some simple gdb_obstack_printf/gdb_obstack_vprintf functions
> to work around that.

And I forgot to add: this should not cause a change in behavior.  The
only places where GDB checks that string, it checks whether the string
starts with "dwarf" (case insensitive).  So the version doesn't matter.

Simon

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

* Re: [PATCH] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-19  2:08 [PATCH] gdb: use actual DWARF version in compunit's debugformat field Simon Marchi
  2021-11-19  2:10 ` Simon Marchi
@ 2021-11-19 18:32 ` Pedro Alves
  2021-11-19 20:41 ` Tom Tromey
  2 siblings, 0 replies; 12+ messages in thread
From: Pedro Alves @ 2021-11-19 18:32 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2021-11-19 02:08, Simon Marchi via Gdb-patches wrote:
> The "info source" command, with a DWARF-compile program, always show
> that the debug info is "DWARF 2":
> 
>     (gdb) info source
>     Current source file is test.c
>     Compilation directory is /home/smarchi/build/binutils-gdb/gdb
>     Located in /home/smarchi/build/binutils-gdb/gdb/test.c
>     Contains 2 lines.
>     Source language is c.
>     Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
>     Compiled with DWARF 2 debugging format.
>     Includes preprocessor macro info.
> 
> Change it to display the actual DWARF version:
> 
>     (gdb) info source
>     Current source file is test.c
>     Compilation directory is /home/smarchi/build/binutils-gdb/gdb
>     Located in /home/smarchi/build/binutils-gdb/gdb/test.c
>     Contains 2 lines.
>     Source language is c.
>     Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
>     Compiled with DWARF 5 debugging format.
>     Includes preprocessor macro info.
> 
> The debug format strings need to live as long as the obfile itself, so
> the most straightforward thing to do is to save those strings on the
> objfile's obstack.  But it seems like we don't have an equivalent of
> "obstack_printf".  An obstack_printf function is provided by glibc:
> 
>   https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html
> 
> ... and there's even a gnulib module for it:
> 
>   https://www.gnu.org/software/gnulib/manual/html_node/obstack_005fprintf.html
> 
> However, since GDB uses its own obstack implementation (include/obstack.h), I
> don't think it would be safe to use a glibc obstack function and pass it a GDB
> obstack.  The obstack struct layouts might not be the same.
> 
> Implement some simple gdb_obstack_printf/gdb_obstack_vprintf functions
> to work around that.
> 
> Change-Id: I3270b7ebf5e9a17b4215405bd2e365662a4d6172

LGTM.  OK.

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

* Re: [PATCH] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-19  2:08 [PATCH] gdb: use actual DWARF version in compunit's debugformat field Simon Marchi
  2021-11-19  2:10 ` Simon Marchi
  2021-11-19 18:32 ` Pedro Alves
@ 2021-11-19 20:41 ` Tom Tromey
  2021-11-19 23:00   ` Simon Marchi
  2 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2021-11-19 20:41 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> -  get_builder ()->record_debugformat ("DWARF 2");
Simon> +  get_builder ()->record_debugformat
Simon> +    (gdb_obstack_printf
Simon> +       (&this->per_objfile->objfile->objfile_obstack,
Simon> +	"DWARF %u", this->header.version));
Simon>    get_builder ()->record_producer (producer);

If you use objfile::intern, you'll end up with just a single copy of
this string on the obstack, instead of one per CU.

Tom

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

* Re: [PATCH] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-19 20:41 ` Tom Tromey
@ 2021-11-19 23:00   ` Simon Marchi
  2021-11-20  1:10     ` [PATCH v2] " Simon Marchi
  2021-11-22 19:32     ` [PATCH] gdb: use actual DWARF version in compunit's debugformat field Tom Tromey
  0 siblings, 2 replies; 12+ messages in thread
From: Simon Marchi @ 2021-11-19 23:00 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches



On 2021-11-19 15:41, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> -  get_builder ()->record_debugformat ("DWARF 2");
> Simon> +  get_builder ()->record_debugformat
> Simon> +    (gdb_obstack_printf
> Simon> +       (&this->per_objfile->objfile->objfile_obstack,
> Simon> +	"DWARF %u", this->header.version));
> Simon>    get_builder ()->record_producer (producer);
> 
> If you use objfile::intern, you'll end up with just a single copy of
> this string on the obstack, instead of one per CU.

Ohhh, that seems nice, I'll try that.

Simon

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

* [PATCH v2] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-19 23:00   ` Simon Marchi
@ 2021-11-20  1:10     ` Simon Marchi
  2021-11-23  1:57       ` [PATCH v3] " Simon Marchi
  2021-11-22 19:32     ` [PATCH] gdb: use actual DWARF version in compunit's debugformat field Tom Tromey
  1 sibling, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2021-11-20  1:10 UTC (permalink / raw)
  To: gdb-patches

The "info source" command, with a DWARF-compile program, always show
that the debug info is "DWARF 2":

    (gdb) info source
    Current source file is test.c
    Compilation directory is /home/smarchi/build/binutils-gdb/gdb
    Located in /home/smarchi/build/binutils-gdb/gdb/test.c
    Contains 2 lines.
    Source language is c.
    Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
    Compiled with DWARF 2 debugging format.
    Includes preprocessor macro info.

Change it to display the actual DWARF version:

    (gdb) info source
    Current source file is test.c
    Compilation directory is /home/smarchi/build/binutils-gdb/gdb
    Located in /home/smarchi/build/binutils-gdb/gdb/test.c
    Contains 2 lines.
    Source language is c.
    Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
    Compiled with DWARF 5 debugging format.
    Includes preprocessor macro info.

The debug format strings need to live as long as the obfile itself, so
the most straightforward thing to do is to save those strings on the
objfile's obstack.  Since these strings will likely be duplicated a lot
(say "DWARF 5" for all CUs of an objfile, for example), use
objfile::intern, so that a single string is allocated.

Change-Id: I3270b7ebf5e9a17b4215405bd2e365662a4d6172
---
 gdb/dwarf2/cu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index e7aed774c25c..11e4c373bb04 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -64,7 +64,10 @@ dwarf2_cu::start_symtab (const char *name, const char *comp_dir,
 
   list_in_scope = get_builder ()->get_file_symbols ();
 
-  get_builder ()->record_debugformat ("DWARF 2");
+  const char *debugformat = this->per_objfile->objfile->intern
+    (string_printf ("DWARF %u", this->header.version));
+  get_builder ()->record_debugformat (debugformat);
+
   get_builder ()->record_producer (producer);
 
   processing_has_namespace_info = false;
-- 
2.33.1


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

* Re: [PATCH] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-19 23:00   ` Simon Marchi
  2021-11-20  1:10     ` [PATCH v2] " Simon Marchi
@ 2021-11-22 19:32     ` Tom Tromey
  1 sibling, 0 replies; 12+ messages in thread
From: Tom Tromey @ 2021-11-22 19:32 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, Simon Marchi via Gdb-patches

Simon> Ohhh, that seems nice, I'll try that.

Another option that occurred to me is to just have an array of strings
for the DWARF versions gdb supports.  I think there's just versions 2-5,
so this isn't so burdensome.

Tom

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

* [PATCH v3] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-20  1:10     ` [PATCH v2] " Simon Marchi
@ 2021-11-23  1:57       ` Simon Marchi
  2021-12-02 15:09         ` Tom de Vries
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2021-11-23  1:57 UTC (permalink / raw)
  To: gdb-patches

The "info source" command, with a DWARF-compile program, always show
that the debug info is "DWARF 2":

    (gdb) info source
    Current source file is test.c
    Compilation directory is /home/smarchi/build/binutils-gdb/gdb
    Located in /home/smarchi/build/binutils-gdb/gdb/test.c
    Contains 2 lines.
    Source language is c.
    Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
    Compiled with DWARF 2 debugging format.
    Includes preprocessor macro info.

Change it to display the actual DWARF version:

    (gdb) info source
    Current source file is test.c
    Compilation directory is /home/smarchi/build/binutils-gdb/gdb
    Located in /home/smarchi/build/binutils-gdb/gdb/test.c
    Contains 2 lines.
    Source language is c.
    Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
    Compiled with DWARF 5 debugging format.
    Includes preprocessor macro info.

The comp_unit_head::version field is guaranteed to be between 2 and 5,
thanks to the check in read_comp_unit_head.  So we can still use static
strings to pass to record_debugformat, and keep it efficient.

In the future, when somebody will update GDB to support DWARF 6, they'll
hit this assert and have to update this code.

Change-Id: I3270b7ebf5e9a17b4215405bd2e365662a4d6172
---
 gdb/dwarf2/cu.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index e7aed774c25c..61981a45f8a8 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -64,7 +64,18 @@ dwarf2_cu::start_symtab (const char *name, const char *comp_dir,
 
   list_in_scope = get_builder ()->get_file_symbols ();
 
-  get_builder ()->record_debugformat ("DWARF 2");
+  /* DWARF versions are restricted to [2, 5], thanks to the check in
+     read_comp_unit_head.  */
+  gdb_assert (this->header.version >= 2 && this->header.version <= 5);
+  static const char *debugformat_strings[] = {
+    "DWARF 2",
+    "DWARF 3",
+    "DWARF 4",
+    "DWARF 5",
+  };
+  const char *debugformat = debugformat_strings[this->header.version - 2];
+
+  get_builder ()->record_debugformat (debugformat);
   get_builder ()->record_producer (producer);
 
   processing_has_namespace_info = false;
-- 
2.33.1


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

* Re: [PATCH v3] gdb: use actual DWARF version in compunit's debugformat field
  2021-11-23  1:57       ` [PATCH v3] " Simon Marchi
@ 2021-12-02 15:09         ` Tom de Vries
  2021-12-02 16:09           ` [PATCH] gdb/testsuite: update tests looking for "DWARF 2" debug format Simon Marchi
  0 siblings, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2021-12-02 15:09 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 11/23/21 2:57 AM, Simon Marchi via Gdb-patches wrote:
> The "info source" command, with a DWARF-compile program, always show
> that the debug info is "DWARF 2":
> 
>     (gdb) info source
>     Current source file is test.c
>     Compilation directory is /home/smarchi/build/binutils-gdb/gdb
>     Located in /home/smarchi/build/binutils-gdb/gdb/test.c
>     Contains 2 lines.
>     Source language is c.
>     Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
>     Compiled with DWARF 2 debugging format.
>     Includes preprocessor macro info.
> 
> Change it to display the actual DWARF version:
> 
>     (gdb) info source
>     Current source file is test.c
>     Compilation directory is /home/smarchi/build/binutils-gdb/gdb
>     Located in /home/smarchi/build/binutils-gdb/gdb/test.c
>     Contains 2 lines.
>     Source language is c.
>     Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection.
>     Compiled with DWARF 5 debugging format.
>     Includes preprocessor macro info.
> 

There's fallout, sort of, from this patch in the test-case:
...
XPASS: gdb.base/included.exp: list integer
XPASS: gdb.base/included.exp: info variables integer
XPASS: gdb.cp/m-static.exp: static const int initialized in class definition
XPASS: gdb.cp/m-static.exp: static const float initialized in class
definition
XPASS: gdb.cp/m-static.exp: info variable everywhere
...

The test-cases contain:
...
get_debug_format
set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
...

Thanks,
- Tom


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

* [PATCH] gdb/testsuite: update tests looking for "DWARF 2" debug format
  2021-12-02 15:09         ` Tom de Vries
@ 2021-12-02 16:09           ` Simon Marchi
  2021-12-02 16:14             ` Tom de Vries
  0 siblings, 1 reply; 12+ messages in thread
From: Simon Marchi @ 2021-12-02 16:09 UTC (permalink / raw)
  To: gdb-patches

Commit ab557072b8ec ("gdb: use actual DWARF version in compunit's
debugformat field") change the debug format string in "info source" to
show the actual DWARF version, rather than always show "DWARF 2".

However, it failed to consider that some tests checked for the "DWARF 2"
string to see if the test program is compiled with DWARF debug
information.  Since everything is compiled with DWARF 4 or 5 nowadays,
that changed the behavior of those tests.  Notably, it prevent the
tests using skip_inline_var_tests to run.

Grep through the testsuite for "DWARF 2" and change all occurrences I
could find to use "DWARF [0-9]" instead (that string is passed to TCL's
string match).

Change-Id: Ic7fb0217fb9623880c6f155da6becba0f567a885
---
 gdb/testsuite/gdb.base/complex.exp   | 2 +-
 gdb/testsuite/gdb.base/constvars.exp | 2 +-
 gdb/testsuite/gdb.base/included.exp  | 2 +-
 gdb/testsuite/gdb.base/structs.exp   | 8 ++++----
 gdb/testsuite/gdb.base/volatile.exp  | 2 +-
 gdb/testsuite/gdb.cp/class2.exp      | 2 +-
 gdb/testsuite/gdb.cp/m-static.exp    | 2 +-
 gdb/testsuite/gdb.dwarf2/pr10770.exp | 4 ++--
 gdb/testsuite/lib/gdb.exp            | 8 ++++----
 9 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/gdb/testsuite/gdb.base/complex.exp b/gdb/testsuite/gdb.base/complex.exp
index bcea6ad9ce34..776a69fe7579 100644
--- a/gdb/testsuite/gdb.base/complex.exp
+++ b/gdb/testsuite/gdb.base/complex.exp
@@ -26,7 +26,7 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
 
 if [runto f2] then {
     get_debug_format
-    if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } then {
+    if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF \[0-9\]"] } then {
 	setup_xfail "*-*-*"
     }
     gdb_test "p *y" "\\\$\[0-9\]* = \{c = 42 '\\*', f = 1 \\+ 0i\}" \
diff --git a/gdb/testsuite/gdb.base/constvars.exp b/gdb/testsuite/gdb.base/constvars.exp
index 1f99595128e0..8d7bf6059798 100644
--- a/gdb/testsuite/gdb.base/constvars.exp
+++ b/gdb/testsuite/gdb.base/constvars.exp
@@ -59,7 +59,7 @@ get_debug_format
 proc local_compiler_xfail_check { } {
     if { [test_compiler_info gcc-2-*] } then {
 	if { ![test_debug_format "HP"] \
-		&& ![test_debug_format "DWARF 2"] } then {
+		&& ![test_debug_format "DWARF \[0-9\]"] } then {
 	    setup_xfail "*-*-*" 
 	}
     }
diff --git a/gdb/testsuite/gdb.base/included.exp b/gdb/testsuite/gdb.base/included.exp
index 85b39a653ebb..0c04362dcff2 100644
--- a/gdb/testsuite/gdb.base/included.exp
+++ b/gdb/testsuite/gdb.base/included.exp
@@ -22,7 +22,7 @@ gdb_test_no_output "set listsize 1"
 
 gdb_test "list -q main" ".*"
 get_debug_format
-set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
+set non_dwarf [expr ! [test_debug_format "DWARF \[0-9\]"]]
 
 # We should be able to find the source file containing the definition,
 # even though it was an included header.
diff --git a/gdb/testsuite/gdb.base/structs.exp b/gdb/testsuite/gdb.base/structs.exp
index ae847f85a501..0e4a7ec2cb1a 100644
--- a/gdb/testsuite/gdb.base/structs.exp
+++ b/gdb/testsuite/gdb.base/structs.exp
@@ -232,8 +232,8 @@ proc test_struct_calls { n } {
     set tests "call $n ${testfile}"
 
     # Call fun${n}, checking the printed return-value.
-    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
-    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
+    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
+    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
     gdb_test "p/c fun${n}()"  "[foo ${n}]" "p/c fun<n>(); ${tests}"
 
     # Check that GDB can always pass a structure to an inferior function.
@@ -244,8 +244,8 @@ proc test_struct_calls { n } {
     # examining that global to confirm that the value is as expected.
 
     gdb_test_no_output "call Fun${n}(foo${n})" "call Fun<n>(foo<n>); ${tests}"
-    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
-    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
+    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
+    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
     gdb_test "p/c L${n}" [foo ${n}] "p/c L<n>; ${tests}"
 }
 
diff --git a/gdb/testsuite/gdb.base/volatile.exp b/gdb/testsuite/gdb.base/volatile.exp
index ae701340aa90..212ceaf34d66 100644
--- a/gdb/testsuite/gdb.base/volatile.exp
+++ b/gdb/testsuite/gdb.base/volatile.exp
@@ -60,7 +60,7 @@ get_debug_format
 proc local_compiler_xfail_check { } {
     if { [test_compiler_info gcc-2-*] } then {
 	if { ![test_debug_format "HP"] \
-		&& ![test_debug_format "DWARF 2"] } then {
+		&& ![test_debug_format "DWARF \[0-9\]"] } then {
 	    setup_xfail "*-*-*" 
 	}
     }
diff --git a/gdb/testsuite/gdb.cp/class2.exp b/gdb/testsuite/gdb.cp/class2.exp
index 9dae91777e58..92715ddd29a4 100644
--- a/gdb/testsuite/gdb.cp/class2.exp
+++ b/gdb/testsuite/gdb.cp/class2.exp
@@ -67,7 +67,7 @@ gdb_test_multiple "print * aap" "print * aap at marker return 0" {
 	pass "print * aap at marker return 0"
     }
     -re "= {.*a1 = .*}\r\n$gdb_prompt $" {
-	if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } {
+	if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF \[0-9\]"] } {
 	    # gcc 2.95.3 -gdwarf-2
 	    setup_kfail "gdb/1465" "*-*-*"
 	}
diff --git a/gdb/testsuite/gdb.cp/m-static.exp b/gdb/testsuite/gdb.cp/m-static.exp
index 159320384879..98df116e6ec7 100644
--- a/gdb/testsuite/gdb.cp/m-static.exp
+++ b/gdb/testsuite/gdb.cp/m-static.exp
@@ -48,7 +48,7 @@ if ![runto_main] then {
 }
 
 get_debug_format
-set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
+set non_dwarf [expr ! [test_debug_format "DWARF \[0-9\]"]]
 
 # First, run to after we've constructed all the objects:
 
diff --git a/gdb/testsuite/gdb.dwarf2/pr10770.exp b/gdb/testsuite/gdb.dwarf2/pr10770.exp
index 89542ffbabc6..26644a57b440 100644
--- a/gdb/testsuite/gdb.dwarf2/pr10770.exp
+++ b/gdb/testsuite/gdb.dwarf2/pr10770.exp
@@ -25,9 +25,9 @@ if {![runto_main]} {
     return -1
 }
 
-# This test also requires DWARF 2.
+# This test also requires DWARF.
 get_debug_format
-if {![test_debug_format "DWARF 2"]} {
+if {![test_debug_format "DWARF \[0-9\]"]} {
     return -1
 }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index b145fe8e2e83..70fa2b3a8013 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3683,8 +3683,8 @@ gdb_caching_proc skip_ifunc_tests {
 # backtraces.  Requires get_compiler_info and get_debug_format.
 
 proc skip_inline_frame_tests {} {
-    # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
-    if { ! [test_debug_format "DWARF 2"] } {
+    # GDB only recognizes inlining information in DWARF.
+    if { ! [test_debug_format "DWARF \[0-9\]"] } {
 	return 1
     }
 
@@ -3702,8 +3702,8 @@ proc skip_inline_frame_tests {} {
 # inlined functions.  Requires get_compiler_info and get_debug_format.
 
 proc skip_inline_var_tests {} {
-    # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
-    if { ! [test_debug_format "DWARF 2"] } {
+    # GDB only recognizes inlining information in DWARF.
+    if { ! [test_debug_format "DWARF \[0-9\]"] } {
 	return 1
     }
 
-- 
2.33.1


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

* Re: [PATCH] gdb/testsuite: update tests looking for "DWARF 2" debug format
  2021-12-02 16:09           ` [PATCH] gdb/testsuite: update tests looking for "DWARF 2" debug format Simon Marchi
@ 2021-12-02 16:14             ` Tom de Vries
  2021-12-02 16:56               ` Simon Marchi
  0 siblings, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2021-12-02 16:14 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 12/2/21 5:09 PM, Simon Marchi via Gdb-patches wrote:
> Commit ab557072b8ec ("gdb: use actual DWARF version in compunit's
> debugformat field") change the debug format string in "info source" to

typo: change -> changes

> show the actual DWARF version, rather than always show "DWARF 2".
> 
> However, it failed to consider that some tests checked for the "DWARF 2"
> string to see if the test program is compiled with DWARF debug
> information.  Since everything is compiled with DWARF 4 or 5 nowadays,
> that changed the behavior of those tests.  Notably, it prevent the
> tests using skip_inline_var_tests to run.
> 
> Grep through the testsuite for "DWARF 2" and change all occurrences I
> could find to use "DWARF [0-9]" instead (that string is passed to TCL's
> string match).
> 

LGTM.

Thanks,
- Tom

> Change-Id: Ic7fb0217fb9623880c6f155da6becba0f567a885
> ---
>  gdb/testsuite/gdb.base/complex.exp   | 2 +-
>  gdb/testsuite/gdb.base/constvars.exp | 2 +-
>  gdb/testsuite/gdb.base/included.exp  | 2 +-
>  gdb/testsuite/gdb.base/structs.exp   | 8 ++++----
>  gdb/testsuite/gdb.base/volatile.exp  | 2 +-
>  gdb/testsuite/gdb.cp/class2.exp      | 2 +-
>  gdb/testsuite/gdb.cp/m-static.exp    | 2 +-
>  gdb/testsuite/gdb.dwarf2/pr10770.exp | 4 ++--
>  gdb/testsuite/lib/gdb.exp            | 8 ++++----
>  9 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.base/complex.exp b/gdb/testsuite/gdb.base/complex.exp
> index bcea6ad9ce34..776a69fe7579 100644
> --- a/gdb/testsuite/gdb.base/complex.exp
> +++ b/gdb/testsuite/gdb.base/complex.exp
> @@ -26,7 +26,7 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
>  
>  if [runto f2] then {
>      get_debug_format
> -    if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } then {
> +    if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF \[0-9\]"] } then {
>  	setup_xfail "*-*-*"
>      }
>      gdb_test "p *y" "\\\$\[0-9\]* = \{c = 42 '\\*', f = 1 \\+ 0i\}" \
> diff --git a/gdb/testsuite/gdb.base/constvars.exp b/gdb/testsuite/gdb.base/constvars.exp
> index 1f99595128e0..8d7bf6059798 100644
> --- a/gdb/testsuite/gdb.base/constvars.exp
> +++ b/gdb/testsuite/gdb.base/constvars.exp
> @@ -59,7 +59,7 @@ get_debug_format
>  proc local_compiler_xfail_check { } {
>      if { [test_compiler_info gcc-2-*] } then {
>  	if { ![test_debug_format "HP"] \
> -		&& ![test_debug_format "DWARF 2"] } then {
> +		&& ![test_debug_format "DWARF \[0-9\]"] } then {
>  	    setup_xfail "*-*-*" 
>  	}
>      }
> diff --git a/gdb/testsuite/gdb.base/included.exp b/gdb/testsuite/gdb.base/included.exp
> index 85b39a653ebb..0c04362dcff2 100644
> --- a/gdb/testsuite/gdb.base/included.exp
> +++ b/gdb/testsuite/gdb.base/included.exp
> @@ -22,7 +22,7 @@ gdb_test_no_output "set listsize 1"
>  
>  gdb_test "list -q main" ".*"
>  get_debug_format
> -set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
> +set non_dwarf [expr ! [test_debug_format "DWARF \[0-9\]"]]
>  
>  # We should be able to find the source file containing the definition,
>  # even though it was an included header.
> diff --git a/gdb/testsuite/gdb.base/structs.exp b/gdb/testsuite/gdb.base/structs.exp
> index ae847f85a501..0e4a7ec2cb1a 100644
> --- a/gdb/testsuite/gdb.base/structs.exp
> +++ b/gdb/testsuite/gdb.base/structs.exp
> @@ -232,8 +232,8 @@ proc test_struct_calls { n } {
>      set tests "call $n ${testfile}"
>  
>      # Call fun${n}, checking the printed return-value.
> -    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
> -    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
> +    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
> +    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
>      gdb_test "p/c fun${n}()"  "[foo ${n}]" "p/c fun<n>(); ${tests}"
>  
>      # Check that GDB can always pass a structure to an inferior function.
> @@ -244,8 +244,8 @@ proc test_struct_calls { n } {
>      # examining that global to confirm that the value is as expected.
>  
>      gdb_test_no_output "call Fun${n}(foo${n})" "call Fun<n>(foo<n>); ${tests}"
> -    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
> -    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455
> +    setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
> +    setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF \[0-9\]" i*86-*-* gdb/1455
>      gdb_test "p/c L${n}" [foo ${n}] "p/c L<n>; ${tests}"
>  }
>  
> diff --git a/gdb/testsuite/gdb.base/volatile.exp b/gdb/testsuite/gdb.base/volatile.exp
> index ae701340aa90..212ceaf34d66 100644
> --- a/gdb/testsuite/gdb.base/volatile.exp
> +++ b/gdb/testsuite/gdb.base/volatile.exp
> @@ -60,7 +60,7 @@ get_debug_format
>  proc local_compiler_xfail_check { } {
>      if { [test_compiler_info gcc-2-*] } then {
>  	if { ![test_debug_format "HP"] \
> -		&& ![test_debug_format "DWARF 2"] } then {
> +		&& ![test_debug_format "DWARF \[0-9\]"] } then {
>  	    setup_xfail "*-*-*" 
>  	}
>      }
> diff --git a/gdb/testsuite/gdb.cp/class2.exp b/gdb/testsuite/gdb.cp/class2.exp
> index 9dae91777e58..92715ddd29a4 100644
> --- a/gdb/testsuite/gdb.cp/class2.exp
> +++ b/gdb/testsuite/gdb.cp/class2.exp
> @@ -67,7 +67,7 @@ gdb_test_multiple "print * aap" "print * aap at marker return 0" {
>  	pass "print * aap at marker return 0"
>      }
>      -re "= {.*a1 = .*}\r\n$gdb_prompt $" {
> -	if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF 2"] } {
> +	if { [test_compiler_info gcc-2-*] && [test_debug_format "DWARF \[0-9\]"] } {
>  	    # gcc 2.95.3 -gdwarf-2
>  	    setup_kfail "gdb/1465" "*-*-*"
>  	}
> diff --git a/gdb/testsuite/gdb.cp/m-static.exp b/gdb/testsuite/gdb.cp/m-static.exp
> index 159320384879..98df116e6ec7 100644
> --- a/gdb/testsuite/gdb.cp/m-static.exp
> +++ b/gdb/testsuite/gdb.cp/m-static.exp
> @@ -48,7 +48,7 @@ if ![runto_main] then {
>  }
>  
>  get_debug_format
> -set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
> +set non_dwarf [expr ! [test_debug_format "DWARF \[0-9\]"]]
>  
>  # First, run to after we've constructed all the objects:
>  
> diff --git a/gdb/testsuite/gdb.dwarf2/pr10770.exp b/gdb/testsuite/gdb.dwarf2/pr10770.exp
> index 89542ffbabc6..26644a57b440 100644
> --- a/gdb/testsuite/gdb.dwarf2/pr10770.exp
> +++ b/gdb/testsuite/gdb.dwarf2/pr10770.exp
> @@ -25,9 +25,9 @@ if {![runto_main]} {
>      return -1
>  }
>  
> -# This test also requires DWARF 2.
> +# This test also requires DWARF.
>  get_debug_format
> -if {![test_debug_format "DWARF 2"]} {
> +if {![test_debug_format "DWARF \[0-9\]"]} {
>      return -1
>  }
>  
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index b145fe8e2e83..70fa2b3a8013 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -3683,8 +3683,8 @@ gdb_caching_proc skip_ifunc_tests {
>  # backtraces.  Requires get_compiler_info and get_debug_format.
>  
>  proc skip_inline_frame_tests {} {
> -    # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
> -    if { ! [test_debug_format "DWARF 2"] } {
> +    # GDB only recognizes inlining information in DWARF.
> +    if { ! [test_debug_format "DWARF \[0-9\]"] } {
>  	return 1
>      }
>  
> @@ -3702,8 +3702,8 @@ proc skip_inline_frame_tests {} {
>  # inlined functions.  Requires get_compiler_info and get_debug_format.
>  
>  proc skip_inline_var_tests {} {
> -    # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
> -    if { ! [test_debug_format "DWARF 2"] } {
> +    # GDB only recognizes inlining information in DWARF.
> +    if { ! [test_debug_format "DWARF \[0-9\]"] } {
>  	return 1
>      }
>  
> 

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

* Re: [PATCH] gdb/testsuite: update tests looking for "DWARF 2" debug format
  2021-12-02 16:14             ` Tom de Vries
@ 2021-12-02 16:56               ` Simon Marchi
  0 siblings, 0 replies; 12+ messages in thread
From: Simon Marchi @ 2021-12-02 16:56 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches



On 2021-12-02 11:14, Tom de Vries wrote:
> On 12/2/21 5:09 PM, Simon Marchi via Gdb-patches wrote:
>> Commit ab557072b8ec ("gdb: use actual DWARF version in compunit's
>> debugformat field") change the debug format string in "info source" to
> 
> typo: change -> changes

Fixed.

>> show the actual DWARF version, rather than always show "DWARF 2".
>>
>> However, it failed to consider that some tests checked for the "DWARF 2"
>> string to see if the test program is compiled with DWARF debug
>> information.  Since everything is compiled with DWARF 4 or 5 nowadays,
>> that changed the behavior of those tests.  Notably, it prevent the
>> tests using skip_inline_var_tests to run.
>>
>> Grep through the testsuite for "DWARF 2" and change all occurrences I
>> could find to use "DWARF [0-9]" instead (that string is passed to TCL's
>> string match).
>>
> 
> LGTM.

Pushed, thanks!

Simon

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

end of thread, other threads:[~2021-12-02 16:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19  2:08 [PATCH] gdb: use actual DWARF version in compunit's debugformat field Simon Marchi
2021-11-19  2:10 ` Simon Marchi
2021-11-19 18:32 ` Pedro Alves
2021-11-19 20:41 ` Tom Tromey
2021-11-19 23:00   ` Simon Marchi
2021-11-20  1:10     ` [PATCH v2] " Simon Marchi
2021-11-23  1:57       ` [PATCH v3] " Simon Marchi
2021-12-02 15:09         ` Tom de Vries
2021-12-02 16:09           ` [PATCH] gdb/testsuite: update tests looking for "DWARF 2" debug format Simon Marchi
2021-12-02 16:14             ` Tom de Vries
2021-12-02 16:56               ` Simon Marchi
2021-11-22 19:32     ` [PATCH] gdb: use actual DWARF version in compunit's debugformat field Tom Tromey

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