public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Reimplement dwarf_unit_type_name
@ 2021-03-18 15:05 Tom Tromey
  2021-03-18 15:48 ` Andrew Burgess
  2021-03-19 20:19 ` Pedro Alves
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2021-03-18 15:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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

gdb/ChangeLog
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          |  7 +++++++
 gdb/dwarf2/comp-unit.c | 29 +----------------------------
 gdb/dwarf2/stringify.c | 13 +++++++++++++
 gdb/dwarf2/stringify.h |  3 +++
 4 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/gdb/dwarf2/comp-unit.c b/gdb/dwarf2/comp-unit.c
index 72b4e80d808..ce3b55778f4 100644
--- a/gdb/dwarf2/comp-unit.c
+++ b/gdb/dwarf2/comp-unit.c
@@ -29,34 +29,7 @@
 #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.  */
 
diff --git a/gdb/dwarf2/stringify.c b/gdb/dwarf2/stringify.c
index 43e88f9043f..b292f9fccc8 100644
--- a/gdb/dwarf2/stringify.c
+++ b/gdb/dwarf2/stringify.c
@@ -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;
+}
diff --git a/gdb/dwarf2/stringify.h b/gdb/dwarf2/stringify.h
index ada4c1e77e7..d2139d91db9 100644
--- a/gdb/dwarf2/stringify.h
+++ b/gdb/dwarf2/stringify.h
@@ -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 */
-- 
2.26.2


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

* Re: [PATCH] Reimplement dwarf_unit_type_name
  2021-03-18 15:05 [PATCH] Reimplement dwarf_unit_type_name Tom Tromey
@ 2021-03-18 15:48 ` Andrew Burgess
  2021-03-19 20:19 ` Pedro Alves
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Burgess @ 2021-03-18 15:48 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tromey@adacore.com> [2021-03-18 09:05:24 -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.)
> 
> gdb/ChangeLog
> 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.

LGTM.

Thanks,
Andrew

> ---
>  gdb/ChangeLog          |  7 +++++++
>  gdb/dwarf2/comp-unit.c | 29 +----------------------------
>  gdb/dwarf2/stringify.c | 13 +++++++++++++
>  gdb/dwarf2/stringify.h |  3 +++
>  4 files changed, 24 insertions(+), 28 deletions(-)
> 
> diff --git a/gdb/dwarf2/comp-unit.c b/gdb/dwarf2/comp-unit.c
> index 72b4e80d808..ce3b55778f4 100644
> --- a/gdb/dwarf2/comp-unit.c
> +++ b/gdb/dwarf2/comp-unit.c
> @@ -29,34 +29,7 @@
>  #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.  */
>  
> diff --git a/gdb/dwarf2/stringify.c b/gdb/dwarf2/stringify.c
> index 43e88f9043f..b292f9fccc8 100644
> --- a/gdb/dwarf2/stringify.c
> +++ b/gdb/dwarf2/stringify.c
> @@ -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;
> +}
> diff --git a/gdb/dwarf2/stringify.h b/gdb/dwarf2/stringify.h
> index ada4c1e77e7..d2139d91db9 100644
> --- a/gdb/dwarf2/stringify.h
> +++ b/gdb/dwarf2/stringify.h
> @@ -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 */
> -- 
> 2.26.2
> 

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

* Re: [PATCH] Reimplement dwarf_unit_type_name
  2021-03-18 15:05 [PATCH] Reimplement dwarf_unit_type_name Tom Tromey
  2021-03-18 15:48 ` Andrew Burgess
@ 2021-03-19 20:19 ` Pedro Alves
  2021-03-31 15:48   ` Tom Tromey
  1 sibling, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2021-03-19 20:19 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 18/03/21 15:05, Tom Tromey wrote:
> +/* Convert a DWARF unit type into is string name.  */
> +extern const char *dwarf_unit_type_name (int unit_type);

Typo "is" -> "its".

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

* Re: [PATCH] Reimplement dwarf_unit_type_name
  2021-03-19 20:19 ` Pedro Alves
@ 2021-03-31 15:48   ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2021-03-31 15:48 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> On 18/03/21 15:05, Tom Tromey wrote:
>> +/* Convert a DWARF unit type into is string name.  */
>> +extern const char *dwarf_unit_type_name (int unit_type);

Pedro> Typo "is" -> "its".

I'll fix this momentarily.  Thanks.

Tom

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

end of thread, other threads:[~2021-03-31 15:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 15:05 [PATCH] Reimplement dwarf_unit_type_name Tom Tromey
2021-03-18 15:48 ` Andrew Burgess
2021-03-19 20:19 ` Pedro Alves
2021-03-31 15:48   ` 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).