Reimplement dwarf_unit_type_name
authorTom Tromey <tromey@adacore.com>
Thu, 18 Mar 2021 15:01:10 +0000 (09:01 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 18 Mar 2021 18:08:41 +0000 (12:08 -0600)
I noticed that dwarf_unit_type_name is nearly identical to
get_DW_UT_name from libiberty; but rather than simply replacing it, it
seemed better to have it work like the other DWARF constant
stringification functions -- return a string showing unrecognized
numeric forms rather than nullptr.  (The previous code did include
numeric values for the recognized constants, but this seems to be not
that useful to me.)

2021-03-18  Tom Tromey  <tromey@adacore.com>

* dwarf2/stringify.c (dwarf_unit_type_name): New function.  Use
get_DW_UT_name.
* dwarf2/stringify.h (dwarf_unit_type_name): Declare.
* dwarf2/comp-unit.c (dwarf_unit_type_name): Remove.

gdb/ChangeLog
gdb/dwarf2/comp-unit.c
gdb/dwarf2/stringify.c
gdb/dwarf2/stringify.h

index 09cfe0f6723dc2b16c6c19cf06d22e37dc6e7a8b..11e9ea9c97c54b29d0e5d211d2b4e9c05e6c73c7 100644 (file)
@@ -1,3 +1,10 @@
+2021-03-18  Tom Tromey  <tromey@adacore.com>
+
+       * dwarf2/stringify.c (dwarf_unit_type_name): New function.  Use
+       get_DW_UT_name.
+       * dwarf2/stringify.h (dwarf_unit_type_name): Declare.
+       * dwarf2/comp-unit.c (dwarf_unit_type_name): Remove.
+
 2021-03-18  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * python/py-param.c (get_set_value): Update header comment.
index 72b4e80d808731b68b30eba6f47605dc5fa2c88e..ce3b55778f4bba141824eed121524d61af9a3679 100644 (file)
 #include "dwarf2/leb.h"
 #include "dwarf2/read.h"
 #include "dwarf2/section.h"
-
-/* Convert a unit type to corresponding DW_UT name.  */
-
-static const char *
-dwarf_unit_type_name (int unit_type)
-{
-  switch (unit_type)
-    {
-      case 0x01:
-       return "DW_UT_compile (0x01)";
-      case 0x02:
-       return "DW_UT_type (0x02)";
-      case 0x03:
-       return "DW_UT_partial (0x03)";
-      case 0x04:
-       return "DW_UT_skeleton (0x04)";
-      case 0x05:
-       return "DW_UT_split_compile (0x05)";
-      case 0x06:
-       return "DW_UT_split_type (0x06)";
-      case 0x80:
-       return "DW_UT_lo_user (0x80)";
-      case 0xff:
-       return "DW_UT_hi_user (0xff)";
-      default:
-       return nullptr;
-    }
-}
+#include "dwarf2/stringify.h"
 
 /* See comp-unit.h.  */
 
index 43e88f9043f4100d57f88233471b15bb20e203cc..b292f9fccc88c017f38b0f2835f0f5244a52ca1c 100644 (file)
@@ -112,3 +112,16 @@ dwarf_type_encoding_name (unsigned enc)
 
   return name;
 }
+
+/* See stringify.h.  */
+
+const char *
+dwarf_unit_type_name (int unit_type)
+{
+  const char *name = get_DW_UT_name (unit_type);
+
+  if (name == nullptr)
+    return dwarf_unknown ("UT", unit_type);
+
+  return name;
+}
index ada4c1e77e705ae22279f0abccab3c6cd98341c4..d2139d91db9a4d048c9cc19f9875b6ecc310c84c 100644 (file)
@@ -35,4 +35,7 @@ extern const char *dwarf_bool_name (unsigned mybool);
 /* Convert a DWARF type code into its string name.  */
 extern const char *dwarf_type_encoding_name (unsigned enc);
 
+/* Convert a DWARF unit type into is string name.  */
+extern const char *dwarf_unit_type_name (int unit_type);
+
 #endif /* GDB_DWARF2_STRINGIFY_H */