public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast
@ 2023-01-31 15:57 Simon Marchi
  2023-01-31 15:57 ` [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump Simon Marchi
  2023-01-31 17:35 ` [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Marchi @ 2023-01-31 15:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Both static_cast and dynamic_cast handle nullptr (they return nullptr),
so I think checked_static_cast should too.  This will allow doing a null
check after a checked_static_cast:

  cooked_index_vector *table
    = (gdb::checked_static_cast<cooked_index_vector *>
       (per_bfd->index_table.get ()));
  if (table != nullptr)
    return;

Change-Id: If5c3134e63696f8e417c87b5f3901240c9f7ea97
---
 gdbsupport/gdb-checked-static-cast.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdbsupport/gdb-checked-static-cast.h b/gdbsupport/gdb-checked-static-cast.h
index cc298733fadb..bc75244bddd0 100644
--- a/gdbsupport/gdb-checked-static-cast.h
+++ b/gdbsupport/gdb-checked-static-cast.h
@@ -54,6 +54,9 @@ checked_static_cast (V *v)
 		 "types must be related");
 
 #ifdef DEVELOPMENT
+  if (v == nullptr)
+    return nullptr;
+
   T result = dynamic_cast<T> (v);
   gdb_assert (result != nullptr);
 #else
-- 
2.39.1


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

* [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump
  2023-01-31 15:57 [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast Simon Marchi
@ 2023-01-31 15:57 ` Simon Marchi
  2023-01-31 17:35   ` Tom Tromey
  2023-01-31 17:35 ` [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast Tom Tromey
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2023-01-31 15:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Since commit 7d82b08e9e0a ("gdb/dwarf: dump cooked index contents in
cooked_index_functions::dump"), we see:

    maint print objfiles /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error^M
    ^M
    Object file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error:  Objfile at 0x614000005040, bfd at 0x6120000e08c0, 15 minsyms^M
    ^M
    Cooked index in use:^M
    ^M
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static-cast.h:58: internal-error: checked_static_cast: Assertion `result != nullptr' failed.^M
    A problem internal to GDB has been detected,^M
    further debugging may prove unreliable.^M
    ----- Backtrace -----^M
    FAIL: gdb.dwarf2/dw2-error.exp: maint print objfiles /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error (GDB internal error)

The problem is that when cooked_index_functions fails to build an index,
per_objfile->index_table is nullptr.  Therefore, add a nullptr check,
like other methods of cooked_index_functions already do.

Print the "Cooked index in use" message after the nullptr check, such
that if the cooked index failed to build, that message is not printed.

Change-Id: Id67aef592e76c41b1e3bde9838a4e36cef873253
---
 gdb/dwarf2/read.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e8a3e359adaa..6cee22a3faa6 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18589,14 +18589,15 @@ struct cooked_index_functions : public dwarf2_base_index_functions
 
   void dump (struct objfile *objfile) override
   {
-    gdb_printf ("Cooked index in use:\n");
-    gdb_printf ("\n");
-
     dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
     cooked_index_vector *index
       = (gdb::checked_static_cast<cooked_index_vector *>
-         (per_objfile->per_bfd->index_table.get ()));
+	  (per_objfile->per_bfd->index_table.get ()));
+    if (index == nullptr)
+      return;
 
+    gdb_printf ("Cooked index in use:\n");
+    gdb_printf ("\n");
     index->dump (objfile->arch ());
   }
 
-- 
2.39.1


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

* Re: [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast
  2023-01-31 15:57 [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast Simon Marchi
  2023-01-31 15:57 ` [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump Simon Marchi
@ 2023-01-31 17:35 ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2023-01-31 17:35 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

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

Simon> Both static_cast and dynamic_cast handle nullptr (they return nullptr),
Simon> so I think checked_static_cast should too.  This will allow doing a null
Simon> check after a checked_static_cast:

Thanks, I think this is a good idea.

Tom

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

* Re: [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump
  2023-01-31 15:57 ` [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump Simon Marchi
@ 2023-01-31 17:35   ` Tom Tromey
  2023-01-31 18:22     ` Simon Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2023-01-31 17:35 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

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

Simon> Print the "Cooked index in use" message after the nullptr check, such
Simon> that if the cooked index failed to build, that message is not printed.

Thank you.  This looks good to me.

Tom

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

* Re: [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump
  2023-01-31 17:35   ` Tom Tromey
@ 2023-01-31 18:22     ` Simon Marchi
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Marchi @ 2023-01-31 18:22 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi

On 1/31/23 12:35, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Print the "Cooked index in use" message after the nullptr check, such
> Simon> that if the cooked index failed to build, that message is not printed.
> 
> Thank you.  This looks good to me.
> 
> Tom

Thanks, pushed both patches.

Simon

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

end of thread, other threads:[~2023-01-31 18:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 15:57 [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast Simon Marchi
2023-01-31 15:57 ` [PATCH 2/2] gdb: add nullptr check to cooked_index_functions::dump Simon Marchi
2023-01-31 17:35   ` Tom Tromey
2023-01-31 18:22     ` Simon Marchi
2023-01-31 17:35 ` [PATCH 1/2] gdbsupport: allow passing nullptr to checked_static_cast 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).