From patchwork Fri Jul 12 11:37:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 33685 Received: (qmail 124111 invoked by alias); 12 Jul 2019 11:37:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 124023 invoked by uid 89); 12 Jul 2019 11:37:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=discovering X-HELO: mail-wm1-f43.google.com Received: from mail-wm1-f43.google.com (HELO mail-wm1-f43.google.com) (209.85.128.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Jul 2019 11:37:16 +0000 Received: by mail-wm1-f43.google.com with SMTP id f17so8636088wme.2 for ; Fri, 12 Jul 2019 04:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=oVJBjU4nvIhPj7+DwFmqxKnTTGr6uEKDJazgNPH5O4Q=; b=KvwxfTmlwBpnoT6uEjLC4BKTn/9RkTgeQVvlAxwXNC+jV49PJlQ4TIrbTS3Z0ztq2i SJyb/hXf+ljRlo74M6P1HAGJy0BaWEtyElUvYIWQcjOInGl9LlOMFnHdy65PXMq7WnI4 g1bW4DNCq5ZZPthSguWP+V8heyS49GxIH5kyLdf6tSmiKyZAboz6TAKyGmjcNKtGbYHO MpSE7L9dtO+h7h+g3xTszR1mKhfO+1RnSYNDMRKcmfaji1aixIcCj4DO8F2tUHYq7w8P ZmLFXP5Vm7ROrf8VQjIHhlRvDAKPHC+rwYPsfk28W/s7+NfaNHtWMNf7//tmOF9agGvL uguw== Return-Path: Received: from localhost (host86-128-12-99.range86-128.btcentralplus.com. [86.128.12.99]) by smtp.gmail.com with ESMTPSA id o4sm6857726wmh.35.2019.07.12.04.37.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Jul 2019 04:37:14 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdb: Show type summary for anonymous structures from c_print_typedef Date: Fri, 12 Jul 2019 12:37:06 +0100 Message-Id: <4b4c8db945d3fbd3334b303b7acfa6d2c71b6bf6.1562931337.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Currently each language has a la_print_typedef method, this is only used for the "info types" command. The documentation for "info types" says: Print a brief description of all types whose names match the regular expression @var{regexp} (or all types in your program, if you supply no argument). However, if we consider this C code: typedef struct { int a; } my_type; Then currently with "info types" this will be printed like this: 3: typedef struct { int a; } my_type; I see two problems with this, first the indentation is clearly broken, second, if the struct contained more fields then the it feels like the actual type names could easily get lost in the noise. Given that "info types" is about discovering type names, I think there is an argument to be made that we should focus on giving _only_ the briefest summary for "info types", and if the user wants to know more they can take the type name and plug it into "ptype". As such, I propose that a better output would be: 3: typedef struct {...} my_type; The user understands that there is a type called `my_type`, and that it's an alias for an anonymous structure type. The change to achieve this turns out to be pretty simple, but only effects languages that make use of c_print_typedef, which are C, C++, asm, minimal, d, go, objc, and opencl. Other languages will for now do whatever they used to do. I did look at ada, as this is the only language to actually have some tests for "info types", however, as I understand it ada doesn't really support typedefs, however, by forcing the language we can see what ada would print. So, if we 'set language ada', then originally we printed this: 3: record a: int; end record Again the indentation is clearly broken, but we also have no mention of the type name at all, which is odd, but understandable given the lack of typedefs. If I make a similar change as I'm proposing for C, then we now get this output: 3: record ... end record Which is even less informative I think. However, the original output _is_ tested for in gdb.ada/info_auto_lang.exp, and its not clear to me if the change is a good one or not, so for now I have left this out. gdb/ChangeLog: * c-typeprint.c (c_print_typedef): Pass -1 instead of 0 to type_print. gdb/testsuite/ChangeLog: * gdb.ada/info_auto_lang.exp: Update expected results. * gdb.base/info-types.c: Add anonymous struct typedef. * gdb.base/info-types.exp: Update expected results. --- gdb/ChangeLog | 5 +++++ gdb/c-typeprint.c | 2 +- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.ada/info_auto_lang.exp | 5 +---- gdb/testsuite/gdb.base/info-types.c | 10 ++++++++++ gdb/testsuite/gdb.base/info-types.exp | 2 ++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 6690ca53bcd..43ad3b3e0e6 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -205,7 +205,7 @@ c_print_typedef (struct type *type, { type = check_typedef (type); fprintf_filtered (stream, "typedef "); - type_print (type, "", stream, 0); + type_print (type, "", stream, -1); if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0 || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))), SYMBOL_LINKAGE_NAME (new_symbol)) != 0 diff --git a/gdb/testsuite/gdb.ada/info_auto_lang.exp b/gdb/testsuite/gdb.ada/info_auto_lang.exp index be1deae99ef..68457827d2f 100644 --- a/gdb/testsuite/gdb.ada/info_auto_lang.exp +++ b/gdb/testsuite/gdb.ada/info_auto_lang.exp @@ -53,10 +53,7 @@ set func_in_c(ada_syntax) "${decimal}: procedure proc_in_c;" set func_in_ada(c_syntax) "${decimal}: void proc_in_ada\\\(void\\\);" set func_in_ada(ada_syntax) "${decimal}: procedure proc_in_ada;" -set type_in_c(c_syntax) [multi_line \ - "${decimal}: typedef struct {" \ - " int some_component_in_c;" \ - "} some_type_in_c;" ] +set type_in_c(c_syntax) "${decimal}: typedef struct {\\.\\.\\.} some_type_in_c;" set type_in_c(ada_syntax) [multi_line \ "${decimal}: record" \ " some_component_in_c: int;" \ diff --git a/gdb/testsuite/gdb.base/info-types.c b/gdb/testsuite/gdb.base/info-types.c index d07866544b6..94d1f6c9938 100644 --- a/gdb/testsuite/gdb.base/info-types.c +++ b/gdb/testsuite/gdb.base/info-types.c @@ -38,6 +38,14 @@ enum enum_t typedef enum enum_t my_enum_t; typedef my_enum_t nested_enum_t; +typedef struct +{ + double d; + float f; +} anon_struct_t; + +typedef anon_struct_t nested_anon_struct_t; + volatile int var_a; volatile float var_b; volatile my_int_t var_c; @@ -53,6 +61,8 @@ volatile baz_ptr var_l; volatile enum enum_t var_m; volatile my_enum_t var_n; volatile nested_enum_t var_o; +volatile anon_struct_t var_p; +volatile nested_anon_struct_t var_q; int main () diff --git a/gdb/testsuite/gdb.base/info-types.exp b/gdb/testsuite/gdb.base/info-types.exp index 2ebd76f0e94..781f8988f13 100644 --- a/gdb/testsuite/gdb.base/info-types.exp +++ b/gdb/testsuite/gdb.base/info-types.exp @@ -32,6 +32,7 @@ gdb_test "info types" \ "All defined types:" \ "" \ "File .*:" \ + "45:\[\t \]+typedef struct {\\.\\.\\.} anon_struct_t;" \ "28:\[\t \]+typedef struct baz_t baz;" \ "31:\[\t \]+typedef struct baz_t \\* baz_ptr;" \ "21:\[\t \]+struct baz_t;" \ @@ -42,6 +43,7 @@ gdb_test "info types" \ "38:\[\t \]+typedef enum enum_t my_enum_t;" \ "17:\[\t \]+typedef float my_float_t;" \ "16:\[\t \]+typedef int my_int_t;" \ + "47:\[\t \]+typedef struct {\\.\\.\\.} nested_anon_struct_t;" \ "30:\[\t \]+typedef struct baz_t nested_baz;" \ "29:\[\t \]+typedef struct baz_t nested_baz_t;" \ "39:\[\t \]+typedef enum enum_t nested_enum_t;" \