From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id l8VvADpsU2DIIQAAWB0awg (envelope-from ) for ; Thu, 18 Mar 2021 11:05:30 -0400 Received: by simark.ca (Postfix, from userid 112) id E90C01EF78; Thu, 18 Mar 2021 11:05:29 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 239D61E789 for ; Thu, 18 Mar 2021 11:05:29 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C0E363844041; Thu, 18 Mar 2021 15:05:28 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 4DAED385781F for ; Thu, 18 Mar 2021 15:05:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4DAED385781F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0451D5629D; Thu, 18 Mar 2021 11:05:26 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Kjo55UpTCPbg; Thu, 18 Mar 2021 11:05:25 -0400 (EDT) Received: from murgatroyd.Home (71-211-137-228.hlrn.qwest.net [71.211.137.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id B4918562A1; Thu, 18 Mar 2021 11:05:25 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH] Reimplement dwarf_unit_type_name Date: Thu, 18 Mar 2021 09:05:24 -0600 Message-Id: <20210318150524.3677886-1-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 * 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