Blame SOURCES/0001-gdb-Fix-an-assertion-failure-in-the-gdb-s-copy_type.patch

dbaa30
From d941266da5fb9c386128a180f39281ec9d4aa242 Mon Sep 17 00:00:00 2001
dbaa30
From: Lianbo Jiang <lijiang@redhat.com>
dbaa30
Date: Mon, 20 Feb 2023 15:57:04 +0800
dbaa30
Subject: [PATCH] gdb: Fix an assertion failure in the gdb's copy_type()
dbaa30
dbaa30
This is a backported patch from gdb. Without the patch, the following
dbaa30
crash command may abort due to an assertion failure in the gdb's
dbaa30
copy_type():
dbaa30
dbaa30
  crash> px __per_cpu_start:0
dbaa30
  gdbtypes.c:5505: internal-error: type* copy_type(const type*): Assertion `TYPE_OBJFILE_OWNED (type)' failed.
dbaa30
  A problem internal to GDB has been detected,
dbaa30
  further debugging may prove unreliable.
dbaa30
  Quit this debugging session? (y or n)
dbaa30
dbaa30
The gdb commit 8e2da1651879 ("Fix assertion failure in copy_type")
dbaa30
solved the current issue.
dbaa30
dbaa30
Reported-by: Buland Kumar Singh <bsingh@redhat.com>
dbaa30
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
dbaa30
---
dbaa30
 gdb-10.2.patch | 40 ++++++++++++++++++++++++++++++++++++++++
dbaa30
 1 file changed, 40 insertions(+)
dbaa30
dbaa30
diff --git a/gdb-10.2.patch b/gdb-10.2.patch
dbaa30
index 91edfb338445..8c3b5a7fdf77 100644
dbaa30
--- a/gdb-10.2.patch
dbaa30
+++ b/gdb-10.2.patch
dbaa30
@@ -1737,3 +1737,43 @@ exit 0
dbaa30
          struct field *nextfield;
dbaa30
          short nfields;
dbaa30
          struct type *typedef_type, *target_type;
dbaa30
+--- gdb-10.2/gdb/gdbtypes.c.orig
dbaa30
++++ gdb-10.2/gdb/gdbtypes.c
dbaa30
+@@ -5492,27 +5492,25 @@ copy_type_recursive (struct objfile *objfile,
dbaa30
+ }
dbaa30
+ 
dbaa30
+ /* Make a copy of the given TYPE, except that the pointer & reference
dbaa30
+-   types are not preserved.
dbaa30
+-   
dbaa30
+-   This function assumes that the given type has an associated objfile.
dbaa30
+-   This objfile is used to allocate the new type.  */
dbaa30
++   types are not preserved. */
dbaa30
+ 
dbaa30
+ struct type *
dbaa30
+ copy_type (const struct type *type)
dbaa30
+ {
dbaa30
+-  struct type *new_type;
dbaa30
+-
dbaa30
+-  gdb_assert (TYPE_OBJFILE_OWNED (type));
dbaa30
++  struct type *new_type = alloc_type_copy (type);
dbaa30
+ 
dbaa30
+-  new_type = alloc_type_copy (type);
dbaa30
+   TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
dbaa30
+   TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
dbaa30
+   memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
dbaa30
+ 	  sizeof (struct main_type));
dbaa30
+   if (type->main_type->dyn_prop_list != NULL)
dbaa30
+-    new_type->main_type->dyn_prop_list
dbaa30
+-      = copy_dynamic_prop_list (&TYPE_OBJFILE (type) -> objfile_obstack,
dbaa30
+-				type->main_type->dyn_prop_list);
dbaa30
++    {
dbaa30
++      struct obstack *storage = (TYPE_OBJFILE_OWNED (type)
dbaa30
++                                ? &TYPE_OBJFILE (type)->objfile_obstack
dbaa30
++                                : gdbarch_obstack (TYPE_OWNER (type).gdbarch));
dbaa30
++      new_type->main_type->dyn_prop_list
dbaa30
++       = copy_dynamic_prop_list (storage, type->main_type->dyn_prop_list);
dbaa30
++    }
dbaa30
+ 
dbaa30
+   return new_type;
dbaa30
+ }
dbaa30
+
dbaa30
-- 
dbaa30
2.37.1
dbaa30