From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 9D4953857823 for ; Thu, 27 May 2021 11:31:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D4953857823 Received: by mail-qk1-x730.google.com with SMTP id j189so240147qkf.2 for ; Thu, 27 May 2021 04:31:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=uJcfXWnv/cOBU3Uwddqxkw+R0ODhBhoYvvk9wuWgpVw=; b=UoG0yhfhi4VrCaF+tLIftpnRihssnPfQbmm5JoC4wMzXsNo3H+32H1GDQnW6HW7/SS JGLScehIZ0c5GJjqyPViF7A7VDg/gEelzUUtmlJxOElDtIgP8rW7344OMBWilyu6YPqu TYJhC78WBXgkLSHvIKVRAKzV6/QTjwK856adAHkLUYYJYQY/Z+NpUwkcFZnWBqnVbbkJ h5d84IedqYtB4gVJFTGqL2ldoTuK9WaAfRTpo6eixmQOE4X4hKblHqn/3HU3NcT5TOt5 u31NVgc+wwgRH48VYOU4+pRf3acnMYMbx00JB1nZBmGjS65AWRAWiynpDsPdL3CjGBol lHjA== X-Gm-Message-State: AOAM533lTeQgPHa9Hlikp9vrSvgJ2fkGwFJHm/mky96d/Ci4yB2vaJRL bIsBc6Kf9MAXM/bzqqYb0ukt1OlZPw73OQ== X-Google-Smtp-Source: ABdhPJyE2QdeX6BDd7+C5IfvfSBlbTZMgS1odM6/+8PqloVfHciS2Ay2Q2kABMVgpYsoDbTiWthv8g== X-Received: by 2002:a37:2792:: with SMTP id n140mr2895122qkn.478.1622115115153; Thu, 27 May 2021 04:31:55 -0700 (PDT) Received: from ?IPv6:2804:7f0:4841:5c9d:8973:dfa9:5713:eb5c? ([2804:7f0:4841:5c9d:8973:dfa9:5713:eb5c]) by smtp.gmail.com with ESMTPSA id t191sm1177475qke.100.2021.05.27.04.31.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 May 2021 04:31:54 -0700 (PDT) Subject: [PING] [PATCH] Fix printing of non pointer types when memory tagging is enabled From: Luis Machado To: gdb-patches@sourceware.org References: <20210518202004.3492036-1-luis.machado@linaro.org> Message-ID: <44c6dcaf-d98b-80f5-2ba0-e0e6c5c68a25@linaro.org> Date: Thu, 27 May 2021 08:31:52 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210518202004.3492036-1-luis.machado@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 27 May 2021 11:31:57 -0000 On 5/18/21 5:20 PM, Luis Machado wrote: > When the architecture supports memory tagging, we handle pointer types > in a special way, so we can validate tags and show mismatches. > > I noticed some errors while printing composite types, floats, references, > member functions and other things that implicitly get dereferenced by GDB to > show the contents rather than the pointer. > > Vector registers: > > (gdb) p $v0 > Value can't be converted to integer. > > Non-existent internal variables: > > (gdb) p $foo > Value can't be converted to integer. > > The same happens for complex types and printing struct/union types. > > There are a couple problems. The first one is that we try to evaluate the > expression to print and eventually call value_as_address (...) before making > sure we have a suitable TYPE_CODE_PTR type. That may throw for some types. We > fix this by making sure we have a TYPE_CODE_PTR first, and then proceed to > check if we need to validate tags. > > The second problem is that the evaluation process may naturally throw an > error. One such case is when we have an optimized out variable. Thus we > guard the evaluation path with a try/catch. > > If the evaluation throws, we want to resume the default expression printing > path instead of erroring out and printing nothing useful. > > This isn't ideal, but GDB does some magic, internally, in order to provide an > improved user experience. This allows users to print the contents of some types > without having to use the dereference operator. > > With the patch, printing works correctly again: > > (gdb) p $v0 > $1 = {d = {f = {2.0546950501119882e-81, 2.0546950501119882e-81}, u = {3399988123389603631, 3399988123389603631}, s = { > 3399988123389603631, 3399988123389603631}}, s = {f = {1.59329203e-10, 1.59329203e-10, 1.59329203e-10, 1.59329203e-10}, u = { > 791621423, 791621423, 791621423, 791621423}, s = {791621423, 791621423, 791621423, 791621423}}, h = {bf = {1.592e-10, > 1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10, 1.592e-10}, f = {0.11224, 0.11224, 0.11224, 0.11224, 0.11224, > 0.11224, 0.11224, 0.11224}, u = {12079, 12079, 12079, 12079, 12079, 12079, 12079, 12079}, s = {12079, 12079, 12079, 12079, > 12079, 12079, 12079, 12079}}, b = {u = {47 }, s = {47 }}, q = {u = { > 62718710765820030520700417840365121327}, s = {62718710765820030520700417840365121327}}} > (gdb) p $foo > $2 = void > (gdb) p 2 + 2i > $3 = 2 + 2i > > gdb/ChangeLog > > YYYY-MM-DD Luis Machado > > * printcmd.c (should_validate_memtags): Make more robust against > exceptions. > --- > gdb/printcmd.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > diff --git a/gdb/printcmd.c b/gdb/printcmd.c > index a5c03c3a830..1194c18358d 100644 > --- a/gdb/printcmd.c > +++ b/gdb/printcmd.c > @@ -1266,18 +1266,22 @@ print_value (value *val, const value_print_options &opts) > static bool > should_validate_memtags (struct value *value) > { > - if (target_supports_memory_tagging () > - && gdbarch_tagged_address_p (target_gdbarch (), value)) > - { > - gdb_assert (value != nullptr && value_type (value) != nullptr); > + gdb_assert (value != nullptr && value_type (value) != nullptr); > > - enum type_code code = value_type (value)->code (); > + enum type_code code = value_type (value)->code (); > > - return (code == TYPE_CODE_PTR > - || code == TYPE_CODE_REF > - || code == TYPE_CODE_METHODPTR > - || code == TYPE_CODE_MEMBERPTR); > + try > + { > + if (code == TYPE_CODE_PTR > + && target_supports_memory_tagging () > + && gdbarch_tagged_address_p (target_gdbarch (), value)) > + return true; > } > + catch (gdb_exception_error &ex) > + { > + /* Ignore the error and don't validate tags. */ > + } > + > return false; > } > >