From patchwork Mon Mar 2 18:21:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 38375 Received: (qmail 98213 invoked by alias); 2 Mar 2020 18:21:59 -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 97403 invoked by uid 89); 2 Mar 2020 18:21:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wr1-f44.google.com Received: from mail-wr1-f44.google.com (HELO mail-wr1-f44.google.com) (209.85.221.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Mar 2020 18:21:56 +0000 Received: by mail-wr1-f44.google.com with SMTP id j7so917821wrp.13 for ; Mon, 02 Mar 2020 10:21:56 -0800 (PST) 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; bh=dUs0r7lHYfxu5YqEKzXz9wj/JiFwEXR/Z0auVRx5TFs=; b=Z4rcJj0mV1OYeB49Q9B+DfWtFoz8hou9RcFHeA8Ks6F6EhSgxXP8palYd2CCrWBYfb JgAFfp6Y7mMgviGwQMO8Ix0kTK5n2ku4rvkORRNkMOvhWM7c167UP0UTN+K4vzn48bPb 5igovn1KMeFe1udo2yVsAq0e0JnAYh1X8nZ0mb81H4v45N3o47Sh8lCGVuiUxs8aVgmS DL5E31IP/9dTqg4o/eL5RecwhF/9AYwzcdnAYc08Yk+9Bm8s0nAhaWG3kCxBcrOB5iB3 sQRb9iXOnfJIPnuIhcS96WJjkOv9wyenWMTmly1BD75757zDLqJlcA+OUw9DIwg71Ehd SW6w== Return-Path: Received: from localhost ([212.69.42.53]) by smtp.gmail.com with ESMTPSA id f6sm345225wmc.9.2020.03.02.10.21.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Mar 2020 10:21:53 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: AlokKumar.Sharma@amd.com, Andrew Burgess Subject: [PATCHv2] gdb/fortran: Fix printing of logical true values for Flang Date: Mon, 2 Mar 2020 18:21:52 +0000 Message-Id: <20200302182152.12819-1-andrew.burgess@embecosm.com> In-Reply-To: References: X-IsSubscribed: yes Alok, Thanks for looking into this. I think that the best solution right now will be to handle TYPE_CODE_BOOL in f_val_print rather than modifying generic_val_print_bool. The other possibility would be, I think, to add a new field to 'struct language_defn' and use this in generic_val_print_bool instead of comparing the value of current_lanuage directly, however, this isn't the common approach, so I'd prefer to handle this case just like other TYPE_CODE_* are handled for now. I know that in places within GDB we do compare the value of current_lanuage to the know language structures, but I'd like to move us away from doing this. I've gone ahead and added some tests too. Let me know what you think of this. If you're happy then I'll go ahead and push this. Thanks Andrew --- GDB is not able to print logical true values for Flang compiler. Actual result: (gdb) p l $1 = 4294967295 Expected result: (gdb) p l $1 = .TRUE. This is due to GDB expecting representation of true value being 1. The Fortran standard doesnt specify how LOGICAL types are represented. Different compilers use different non-zero values to represent logical true. The gfortran compiler uses 1 to represent logical true and the flang compiler uses -1. GDB should accept all the non-zero values as true. This is achieved by handling TYPE_CODE_BOOL in f_val_print and printing any non-zero value as true. gdb/ChangeLog: * f-valprint.c (f_val_print): Handle TYPE_CODE_BOOL, any non-zero value should be printed as true. gdb/testsuite/ChangeLog: * gdb.fortran/logical.exp: Add tests that any non-zero value is printed as true. --- gdb/ChangeLog | 6 ++++++ gdb/f-valprint.c | 25 ++++++++++++++++++++++++- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.fortran/logical.exp | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index a25e6147322..0393ddfa8ab 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -357,6 +357,30 @@ f_val_print (struct type *type, int embedded_offset, fprintf_filtered (stream, " )"); break; + case TYPE_CODE_BOOL: + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + val_print_scalar_formatted (type, embedded_offset, + original_value, &opts, 0, stream); + } + else + { + int unit_size = gdbarch_addressable_memory_unit_size (gdbarch); + LONGEST val + = unpack_long (type, valaddr + embedded_offset * unit_size); + /* The Fortran standard doesn't specify how logical types are + represented. Different compilers use different non zero + values to represent logical true. */ + if (val == 0) + fputs_filtered (f_decorations.false_name, stream); + else + fputs_filtered (f_decorations.true_name, stream); + } + break; + case TYPE_CODE_REF: case TYPE_CODE_FUNC: case TYPE_CODE_FLAGS: @@ -366,7 +390,6 @@ f_val_print (struct type *type, int embedded_offset, case TYPE_CODE_RANGE: case TYPE_CODE_UNDEF: case TYPE_CODE_COMPLEX: - case TYPE_CODE_BOOL: case TYPE_CODE_CHAR: default: generic_val_print (type, embedded_offset, address, diff --git a/gdb/testsuite/gdb.fortran/logical.exp b/gdb/testsuite/gdb.fortran/logical.exp index f0028159e59..96e6f8f9559 100644 --- a/gdb/testsuite/gdb.fortran/logical.exp +++ b/gdb/testsuite/gdb.fortran/logical.exp @@ -33,3 +33,21 @@ gdb_test "p l1" " = \\.TRUE\\." gdb_test "p l2" " = \\.TRUE\\." gdb_test "p l4" " = \\.TRUE\\." gdb_test "p l8" " = \\.TRUE\\." + +# Different Fortran compilers use different values for logical true. +# Check how GDB handles this by modifying the underlying value for our +# logical variables and check they still print as true. +foreach_with_prefix var { l l1 l2 l4 l8 } { + set len [get_integer_valueof "sizeof (${var})" "get sizeof ${var}"] + set addr [get_hexadecimal_valueof "&l" "get address of ${var}"] + + for { set i 0 } { $i < $len } { incr i } { + with_test_prefix "byte $i" { + gdb_test_no_output "set *((uint8_t *) ${addr}) = 0xff" \ + "set contents of byte at offset $i" + gdb_test "p l" " = \\.TRUE\\." + incr addr + set addr [format "0x%x" $addr] + } + } +}