From patchwork Wed Jan 4 16:44:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62708 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9BBC3858C62 for ; Wed, 4 Jan 2023 16:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9BBC3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672850758; bh=10yBgbXJzA3G4HYxwyfbVkvQscN8N7uv30MtdoTfQlg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=BFVwOjPK964ggLPMWR+sJ7YsOwrpZQPbtUxvibVBiaglJCdYO4zIeJojrd789K9lX ggajLjqkIJ+MCF5ODiWbRTuOrtdrVh7HYZk5BzUGtqEeyVs3c1MO4yagnD1ZQ+C3ea ZXF/zUwVs29wPwmkqXsKDEVKA4bzCQNRTcI/pRik= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 791B83858D39 for ; Wed, 4 Jan 2023 16:45:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 791B83858D39 Received: by mail-io1-xd2a.google.com with SMTP id p66so18297604iof.1 for ; Wed, 04 Jan 2023 08:45:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=10yBgbXJzA3G4HYxwyfbVkvQscN8N7uv30MtdoTfQlg=; b=GT2797Wn8t1RPJjsDVUNQxnD5WbDv3K6mqmqhITUO+vCoXHTBgXwnjLPYOk+PSyp5+ LfAiy1G2+dKXL+6N9dj8pX6WWK9un/+Oq/S7O1Ncr/gAJC1j6CFXQONYIV6f6xZzk6Md kKLdRDliziaQmprrhdGAq7Rwn1V0W5x6RGx+a5p3oMegbigqH/MoRMkZo4w018KMan1M 7Q6ObzRx1CWs9nO+IvMIblpAuGMbld48flV1d0kK9W4MljjvCwrJjKviso9YrrvM6gyi Vvzr5DVhvvHV4MLq08RQhJdi0nM/1JRENpjsE6IsBob8y0RENBGxAkoCw1lfOjsDUs1h hfzg== X-Gm-Message-State: AFqh2kqjlGdVrkptpw1V4sxI48E7Vw/qUi4gz++wHzcAtUI6vEzWwQgU RKPSrmsx7G6Zcc3YpxPvv8pZ8dzDg9BAliId X-Google-Smtp-Source: AMrXdXujUX2a2t5IkVWkOsVQ1A/2FyAjFX9INaErBpFiwGCEVVr+dclEEKBaxD5325UGAgBnwYyGKA== X-Received: by 2002:a5e:970c:0:b0:6df:f777:ba81 with SMTP id w12-20020a5e970c000000b006dff777ba81mr30362316ioj.3.1672850702678; Wed, 04 Jan 2023 08:45:02 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id h145-20020a6bb797000000b006e02c489089sm12700680iof.32.2023.01.04.08.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 08:45:02 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] Implement some agent expressions for Ada Date: Wed, 4 Jan 2023 09:44:51 -0700 Message-Id: <20230104164452.1154744-2-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104164452.1154744-1-tromey@adacore.com> References: <20230104164452.1154744-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Ada historically has not implemented agent expressions, and some Ada constructs probably cannot reasonably be converted to agent expressions. However, a subset of simple operations can be, and this patch represents a first step in that direction. On one internal AdaCore test case, this improves the performance of a conditional breakpoint from 5 minutes to 5 seconds. The main tricky part in this patch is ensuring the converted expressions detect the cases that will not work. This is done by examining the code in the corresponding evaluation methods. --- gdb/ada-exp.h | 26 +++++++++- gdb/ada-lang.c | 69 ++++++++++++++++++++++++--- gdb/testsuite/gdb.ada/ax-ada.exp | 31 ++++++++++++ gdb/testsuite/gdb.ada/ax-ada/prog.adb | 20 ++++++++ 4 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/ax-ada.exp create mode 100644 gdb/testsuite/gdb.ada/ax-ada/prog.adb diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index 36ac3aaddb7..409cac4668f 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -130,6 +130,14 @@ class ada_wrapped_operation enum exp_opcode opcode () const override { return std::get<0> (m_storage)->opcode (); } + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override; }; /* An Ada string constant. */ @@ -255,6 +263,18 @@ class ada_binop_equal_operation arg1, arg2); } + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override + { + gen_expr_binop (exp, opcode (), + std::get<1> (this->m_storage).get (), + std::get<2> (this->m_storage).get (), + ax, value); + } + enum exp_opcode opcode () const override { return std::get<0> (m_storage); } }; @@ -380,7 +400,11 @@ class ada_var_value_operation protected: - using operation::do_generate_ax; + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override; }; /* Variant of var_msym_value_operation for Ada. */ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 40f85914a56..ce5faef40a4 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -60,6 +60,7 @@ #include #include "ada-exp.h" #include "charset.h" +#include "ax-gdb.h" /* Define whether or not the C operator '/' truncates towards zero for differently signed operands (truncation direction is undefined in C). @@ -9207,6 +9208,23 @@ ada_enum_name (const char *name) } } +/* If TYPE is a dynamic type, return the base type. Otherwise, if + there is no parallel type, return nullptr. */ + +static struct type * +find_base_type (struct type *type) +{ + struct type *raw_real_type + = ada_check_typedef (ada_get_base_type (type)); + + /* No parallel XVS or XVE type. */ + if (type == raw_real_type + && ada_find_parallel_type (type, "___XVE") == nullptr) + return nullptr; + + return raw_real_type; +} + /* If VAL is wrapped in an aligner or subtype wrapper, return the value it wraps. */ @@ -9227,13 +9245,8 @@ unwrap_value (struct value *val) } else { - struct type *raw_real_type = - ada_check_typedef (ada_get_base_type (type)); - - /* If there is no parallel XVS or XVE type, then the value is - already unwrapped. Return it without further modification. */ - if ((type == raw_real_type) - && ada_find_parallel_type (type, "___XVE") == NULL) + struct type *raw_real_type = find_base_type (type); + if (raw_real_type == nullptr) return val; return @@ -10659,6 +10672,21 @@ ada_wrapped_operation::evaluate (struct type *expect_type, return result; } +void +ada_wrapped_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + std::get<0> (m_storage)->generate_ax (exp, ax, value, cast_type); + + struct type *type = value->type; + if (ada_is_aligner_type (type)) + error (_("Aligner types cannot be handled in agent expressions")); + else if (find_base_type (type) != nullptr) + error (_("Dynamic types cannot be handled in agent expressions")); +} + value * ada_string_operation::evaluate (struct type *expect_type, struct expression *exp, @@ -11009,6 +11037,33 @@ ada_var_value_operation::resolve (struct expression *exp, return false; } +void +ada_var_value_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + symbol *sym = std::get<0> (m_storage).symbol; + + if (sym->domain () == UNDEF_DOMAIN) + error (_("Unexpected unresolved symbol, %s, during evaluation"), + sym->print_name ()); + + struct type *type = static_unwrap_type (sym->type ()); + if (ada_is_tagged_type (type, 0) + || (type->code () == TYPE_CODE_REF + && ada_is_tagged_type (type->target_type (), 0))) + error (_("Tagged types cannot be handled in agent expressions")); + + if ((type->code () == TYPE_CODE_STRUCT + && dynamic_template_type (type) != NULL) + || (type->code () == TYPE_CODE_UNION + && ada_find_parallel_type (type, "___XVU") != NULL)) + error (_("Dynamic types cannot be handled in agent expressions")); + + var_value_operation::do_generate_ax (exp, ax, value, cast_type); +} + value * ada_atr_val_operation::evaluate (struct type *expect_type, struct expression *exp, diff --git a/gdb/testsuite/gdb.ada/ax-ada.exp b/gdb/testsuite/gdb.ada/ax-ada.exp new file mode 100644 index 00000000000..b08f7c4362c --- /dev/null +++ b/gdb/testsuite/gdb.ada/ax-ada.exp @@ -0,0 +1,31 @@ +# Copyright 2019-2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile prog + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/prog.adb] +runto "prog.adb:$bp_location" + +gdb_test "maint agent-eval variable = 23" ".*end" diff --git a/gdb/testsuite/gdb.ada/ax-ada/prog.adb b/gdb/testsuite/gdb.ada/ax-ada/prog.adb new file mode 100644 index 00000000000..3852711e88c --- /dev/null +++ b/gdb/testsuite/gdb.ada/ax-ada/prog.adb @@ -0,0 +1,20 @@ +-- Copyright 2023 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +procedure Prog is + Variable : Integer := 23; +begin + null; -- START +end Prog; From patchwork Wed Jan 4 16:44:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62707 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1641D385842E for ; Wed, 4 Jan 2023 16:45:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1641D385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672850730; bh=GJzF/GXK5YkAvfNJ6gHhWWwVXzdtX51/JXHeXvgBMxY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pTujq0kOrdvjhtZQdY7AHYALJ6o7XwSb+820JgnQv/KId2pgpB8zd+uDI5F7bI5+a K/5QGilxXXbKjACUJZDhASHN167hjQ26UmBUwx44ZOauKubHqUd32yoaiqj34lbnMU oeQ6n6M763gAiKO0XwzQSNO3qqRaodTR5VPmOzZM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 24D2D3858C50 for ; Wed, 4 Jan 2023 16:45:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24D2D3858C50 Received: by mail-io1-xd2a.google.com with SMTP id r72so18279818iod.5 for ; Wed, 04 Jan 2023 08:45:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GJzF/GXK5YkAvfNJ6gHhWWwVXzdtX51/JXHeXvgBMxY=; b=3Ag1NfS9UXwn+pJzes475XQ1lfveY3W+oywYUlYgw2FDuyyVokU+XkN2Z+pOtZlXQv 60NoBY2WXxO2gJl33BiBM2OxjSAIt3pVh+e9GyYAJ97EgFOHcl/RtF7kidsI/7yXWuMD i3s5nT6vOF98gmY8fh4Nwk4hpjArRac+SJbkQdYusSw9o4r2GvD+FZg68uQDCy+bLWw1 EBzyN8djlrGDsrb02EXNvS9KZSMJKeBb4zt4cY9jZnE1bGrTt++jMcDzEx/11O88pW8t JlS4g6jmXy4CS1DM08/cHxbHuUpxcnxexPAjcIQ2+eQpa2pcS2N5ZtuFfu3/n4e2Wzbr f5uA== X-Gm-Message-State: AFqh2krp9qJaX+2VWIRMvGieXoD86B/37QGVL3DZlexO2l71ndOGZ4FU Mv/V5u0ivSd4Zj49f6QqY94uvFwvBhC8Look X-Google-Smtp-Source: AMrXdXvqRNESy4uLSp6/xYkkKzQQC87F1MRba29zLaW562R5l9pcmprUC3jJu8+/FJSLpQIj94mm5g== X-Received: by 2002:a6b:d919:0:b0:6e9:9776:a6c8 with SMTP id r25-20020a6bd919000000b006e99776a6c8mr39710253ioc.2.1672850703371; Wed, 04 Jan 2023 08:45:03 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id h145-20020a6bb797000000b006e02c489089sm12700680iof.32.2023.01.04.08.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 08:45:02 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Handle range types in ax-gdb.c Date: Wed, 4 Jan 2023 09:44:52 -0700 Message-Id: <20230104164452.1154744-3-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104164452.1154744-1-tromey@adacore.com> References: <20230104164452.1154744-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" A range type can usually be treated the same as its underlying integer type, at least for the purposes of agent expressions. This patch arranges for range types to be handled this way in ax-gdb.c, letting a somewhat larger subset of Ada expressions be compiled. --- gdb/ax-gdb.c | 60 +++++++++++++++++---------- gdb/testsuite/gdb.ada/ax-ada.exp | 1 + gdb/testsuite/gdb.ada/ax-ada/prog.adb | 3 ++ 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index fc214e7dfe1..dc2c25410fe 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -353,6 +353,16 @@ gen_extend (struct agent_expr *ax, struct type *type) ((type->is_unsigned () ? ax_zero_ext : ax_ext) (ax, bits)); } +/* A helper that returns the target type if TYPE is a range type, or + otherwise just returns TYPE. */ + +static struct type * +strip_range_type (struct type *type) +{ + if (type->code () == TYPE_CODE_RANGE) + return type->target_type (); + return type; +} /* Assume that the top of the stack contains a value of type "pointer to TYPE"; generate code to fetch its value. Note that TYPE is the @@ -366,8 +376,7 @@ gen_fetch (struct agent_expr *ax, struct type *type) ax_trace_quick (ax, type->length ()); } - if (type->code () == TYPE_CODE_RANGE) - type = type->target_type (); + type = strip_range_type (type); switch (type->code ()) { @@ -832,9 +841,12 @@ static void gen_usual_arithmetic (struct agent_expr *ax, struct axs_value *value1, struct axs_value *value2) { + struct type *type1 = strip_range_type (value1->type); + struct type *type2 = strip_range_type (value2->type); + /* Do the usual binary conversions. */ - if (value1->type->code () == TYPE_CODE_INT - && value2->type->code () == TYPE_CODE_INT) + if (type1->code () == TYPE_CODE_INT + && type2->code () == TYPE_CODE_INT) { /* The ANSI integral promotions seem to work this way: Order the integer types by size, and then by signedness: an n-bit @@ -842,18 +854,18 @@ gen_usual_arithmetic (struct agent_expr *ax, struct axs_value *value1, type. Promote to the "wider" of the two types, and always promote at least to int. */ struct type *target = max_type (builtin_type (ax->gdbarch)->builtin_int, - max_type (value1->type, value2->type)); + max_type (type1, type2)); /* Deal with value2, on the top of the stack. */ - gen_conversion (ax, value2->type, target); + gen_conversion (ax, type2, target); /* Deal with value1, not on the top of the stack. Don't generate the `swap' instructions if we're not actually going to do anything. */ - if (is_nontrivial_conversion (value1->type, target)) + if (is_nontrivial_conversion (type1, target)) { ax_simple (ax, aop_swap); - gen_conversion (ax, value1->type, target); + gen_conversion (ax, type1, target); ax_simple (ax, aop_swap); } @@ -892,6 +904,7 @@ gen_cast (struct agent_expr *ax, struct axs_value *value, struct type *type) require_rvalue (ax, value); /* Dereference typedefs. */ type = check_typedef (type); + type = strip_range_type (type); switch (type->code ()) { @@ -960,7 +973,7 @@ gen_ptradd (struct agent_expr *ax, struct axs_value *value, struct axs_value *value1, struct axs_value *value2) { gdb_assert (value1->type->is_pointer_or_reference ()); - gdb_assert (value2->type->code () == TYPE_CODE_INT); + gdb_assert (strip_range_type (value2->type)->code () == TYPE_CODE_INT); gen_scale (ax, aop_mul, value1->type); ax_simple (ax, aop_add); @@ -976,7 +989,7 @@ gen_ptrsub (struct agent_expr *ax, struct axs_value *value, struct axs_value *value1, struct axs_value *value2) { gdb_assert (value1->type->is_pointer_or_reference ()); - gdb_assert (value2->type->code () == TYPE_CODE_INT); + gdb_assert (strip_range_type (value2->type)->code () == TYPE_CODE_INT); gen_scale (ax, aop_mul, value1->type); ax_simple (ax, aop_sub); @@ -1048,14 +1061,15 @@ gen_binop (struct agent_expr *ax, struct axs_value *value, int may_carry, const char *name) { /* We only handle INT op INT. */ - if ((value1->type->code () != TYPE_CODE_INT) - || (value2->type->code () != TYPE_CODE_INT)) + struct type *type1 = strip_range_type (value1->type); + if ((type1->code () != TYPE_CODE_INT) + || (strip_range_type (value2->type)->code () != TYPE_CODE_INT)) error (_("Invalid combination of types in %s."), name); - ax_simple (ax, value1->type->is_unsigned () ? op_unsigned : op); + ax_simple (ax, type1->is_unsigned () ? op_unsigned : op); if (may_carry) - gen_extend (ax, value1->type); /* catch overflow */ - value->type = value1->type; + gen_extend (ax, type1); /* catch overflow */ + value->type = type1; value->kind = axs_rvalue; } @@ -1064,8 +1078,9 @@ static void gen_logical_not (struct agent_expr *ax, struct axs_value *value, struct type *result_type) { - if (value->type->code () != TYPE_CODE_INT - && value->type->code () != TYPE_CODE_PTR) + struct type *type = strip_range_type (value->type); + if (type->code () != TYPE_CODE_INT + && type->code () != TYPE_CODE_PTR) error (_("Invalid type of operand to `!'.")); ax_simple (ax, aop_log_not); @@ -1076,11 +1091,12 @@ gen_logical_not (struct agent_expr *ax, struct axs_value *value, static void gen_complement (struct agent_expr *ax, struct axs_value *value) { - if (value->type->code () != TYPE_CODE_INT) + struct type *type = strip_range_type (value->type); + if (type->code () != TYPE_CODE_INT) error (_("Invalid type of operand to `~'.")); ax_simple (ax, aop_bit_not); - gen_extend (ax, value->type); + gen_extend (ax, type); } @@ -2078,7 +2094,7 @@ gen_expr_binop_rest (struct expression *exp, switch (op) { case BINOP_ADD: - if (value1->type->code () == TYPE_CODE_INT + if (strip_range_type (value1->type)->code () == TYPE_CODE_INT && value2->type->is_pointer_or_reference ()) { /* Swap the values and proceed normally. */ @@ -2086,7 +2102,7 @@ gen_expr_binop_rest (struct expression *exp, gen_ptradd (ax, value, value2, value1); } else if (value1->type->is_pointer_or_reference () - && value2->type->code () == TYPE_CODE_INT) + && strip_range_type (value2->type)->code () == TYPE_CODE_INT) gen_ptradd (ax, value, value1, value2); else gen_binop (ax, value, value1, value2, @@ -2094,7 +2110,7 @@ gen_expr_binop_rest (struct expression *exp, break; case BINOP_SUB: if (value1->type->is_pointer_or_reference () - && value2->type->code () == TYPE_CODE_INT) + && strip_range_type (value2->type)->code () == TYPE_CODE_INT) gen_ptrsub (ax,value, value1, value2); else if (value1->type->is_pointer_or_reference () && value2->type->is_pointer_or_reference ()) diff --git a/gdb/testsuite/gdb.ada/ax-ada.exp b/gdb/testsuite/gdb.ada/ax-ada.exp index b08f7c4362c..d0464b7a5b8 100644 --- a/gdb/testsuite/gdb.ada/ax-ada.exp +++ b/gdb/testsuite/gdb.ada/ax-ada.exp @@ -29,3 +29,4 @@ set bp_location [gdb_get_line_number "START" ${testdir}/prog.adb] runto "prog.adb:$bp_location" gdb_test "maint agent-eval variable = 23" ".*end" +gdb_test "maint agent-eval range_variable = 23" ".*end" diff --git a/gdb/testsuite/gdb.ada/ax-ada/prog.adb b/gdb/testsuite/gdb.ada/ax-ada/prog.adb index 3852711e88c..85148d0c9c5 100644 --- a/gdb/testsuite/gdb.ada/ax-ada/prog.adb +++ b/gdb/testsuite/gdb.ada/ax-ada/prog.adb @@ -14,7 +14,10 @@ -- along with this program. If not, see . procedure Prog is + type Range_Type is range -15 .. 73; + Variable : Integer := 23; + Range_Variable : Range_Type := 23; begin null; -- START end Prog;