public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/symtab] Make per_cu->set_lang more strict
@ 2022-07-13 10:20 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2022-07-13 10:20 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=52c0a455466aa437e4b8d6967e44767c8f3fa260

commit 52c0a455466aa437e4b8d6967e44767c8f3fa260
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Jul 13 12:20:53 2022 +0200

    [gdb/symtab] Make per_cu->set_lang more strict
    
    We have in per_cu->set_lang this comment:
    ...
      void set_lang (enum language lang)
      {
        /* We'd like to be more strict here, similar to what is done in
           set_unit_type,  but currently a partial unit can go from unknown to
           minimal to ada to c.  */
    ...
    
    Fix this by not setting m_lang for partial units.
    
    This requires us to move the m_unit_type initialization to ensure that
    m_unit_type is initialized before per_cu->m_lang.
    
    Tested on x86_64-linux, with native and target board cc-with-dwz-m.

Diff:
---
 gdb/dwarf2/read.c                               | 38 ++++++++++++-------------
 gdb/dwarf2/read.h                               | 11 ++++---
 gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp |  4 +--
 3 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2aac9912ef1..5ca787cc095 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6777,24 +6777,6 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu,
   if (reader.comp_unit_die == nullptr)
     return;
 
-  switch (reader.comp_unit_die->tag)
-    {
-    case DW_TAG_compile_unit:
-      this_cu->set_unit_type (DW_UT_compile);
-      break;
-    case DW_TAG_partial_unit:
-      this_cu->set_unit_type (DW_UT_partial);
-      break;
-    case DW_TAG_type_unit:
-      this_cu->set_unit_type (DW_UT_type);
-      break;
-    default:
-      error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
-	     dwarf_tag_name (reader.comp_unit_die->tag),
-	     sect_offset_str (reader.cu->per_cu->sect_off),
-	     objfile_name (per_objfile->objfile));
-    }
-
   if (reader.dummy_p)
     {
       /* Nothing.  */
@@ -23587,8 +23569,26 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
   else
     lang = pretend_language;
 
-  cu->per_cu->set_lang (lang);
   cu->language_defn = language_def (lang);
+
+  switch (comp_unit_die->tag)
+    {
+    case DW_TAG_compile_unit:
+      cu->per_cu->set_unit_type (DW_UT_compile);
+      break;
+    case DW_TAG_partial_unit:
+      cu->per_cu->set_unit_type (DW_UT_partial);
+      break;
+    case DW_TAG_type_unit:
+      cu->per_cu->set_unit_type (DW_UT_type);
+      break;
+    default:
+      error (_("Dwarf Error: unexpected tag '%s' at offset %s"),
+	     dwarf_tag_name (comp_unit_die->tag),
+	     sect_offset_str (cu->per_cu->sect_off));
+    }
+
+  cu->per_cu->set_lang (lang);
 }
 
 /* See read.h.  */
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 707dca9ee57..fcf0cd70530 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -353,11 +353,14 @@ public:
 
   void set_lang (enum language lang)
   {
-    /* We'd like to be more strict here, similar to what is done in
-       set_unit_type,  but currently a partial unit can go from unknown to
-       minimal to ada to c.  */
-    if (m_lang != lang)
+    if (unit_type () == DW_UT_partial)
+      return;
+    if (m_lang == language_unknown)
+      /* Set if not set already.  */
       m_lang = lang;
+    else
+      /* If already set, verify that it's the same value.  */
+      gdb_assert (m_lang == lang);
   }
 
   /* Free any cached file names.  */
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp b/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp
index 3ac94c31689..3d2890a56b2 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-missing-cu-tag.exp
@@ -54,7 +54,7 @@ clean_restart
 set pattern1 \
     [multi_line \
 	 "Reading symbols from \[^\r\n\]+" \
-	 "Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex \\\[\[^\r\n\]+\\\]"]
+	 "Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex"]
 
 # This pattern is hit when GDB does use -readnow (e.g. running with
 # --target_board=readnow).
@@ -62,7 +62,7 @@ set pattern2 \
     [multi_line \
 	 "Reading symbols from \[^\r\n\]+" \
 	 "Expanding full symbols from \[^\r\n\]+" \
-	 "Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex \\\[\[^\r\n\]+\\\]"]
+	 "Dwarf Error: unexpected tag 'DW_TAG_subprogram' at offset $hex"]
 
 # Load the executable, we expect an error from the DWARF parser.
 gdb_test_multiple "file $binfile" "file $testfile" {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-13 10:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 10:20 [binutils-gdb] [gdb/symtab] Make per_cu->set_lang more strict 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).