From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 618AD385617E for ; Fri, 21 Oct 2022 08:44:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 618AD385617E Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-443-HM19IpQlOU-PEzrk4uebbw-1; Fri, 21 Oct 2022 04:43:59 -0400 X-MC-Unique: HM19IpQlOU-PEzrk4uebbw-1 Received: by mail-wr1-f69.google.com with SMTP id i26-20020adfaada000000b0022e2f38ffccso581953wrc.14 for ; Fri, 21 Oct 2022 01:43:59 -0700 (PDT) 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=kjG1QlRCscnb3YYTOFPvqaxv7698dyfFOSLXzBJQre0=; b=BM13CVcpepnkQrQkQQ2oRnhaedwBs0wImF1L2kVJ+y2UVXKD2+tt8hzfEKPR2K/bDf OYfRrpXdlQ8UzGVgmB53PK4QdUY2x7IE/h4aQJnfuflYqbJfVzvrDYEQ3gPNb5yzPZ+3 h0OYF0rEGdJHjGwJtQUKrQ/Us64bFcBhCDW/CYRXZQCou2LvJabFnp/g1gGa9mA/pTq0 3njeTkj/YhbSfdDQcy3hnZu50KdkeUOQ5SoT8gDu0wfctj2lnRjewQUwmpyVLDQbGy7y asO4P8Tq1J4cUDh8WVjKnJfFE8SGK2lA1p5z4Tun/2W9ONw1pEzFbz5qP7VQa2aUTK45 rU9g== X-Gm-Message-State: ACrzQf2iNY1mqOk8GfMnKiVx8lxXVNjBKxfT5MrPmI3sgjh0recqSOaV a3QiHx44O/CnMrq5fJzSUgxaVIZbEWpt5A5GewMlo9QwRhVaHYChfPwJ0t2cgVGRZE2+U8gO41K 0MQe6viklwxe0wfSG3L6V13rhQPyrf29gYBEnDpuIjytCAgshwy+Ehb/DM6vTFLgZ5uMpIDRHCQ == X-Received: by 2002:a05:600c:1906:b0:3c6:f154:d4b5 with SMTP id j6-20020a05600c190600b003c6f154d4b5mr12121997wmq.94.1666341838555; Fri, 21 Oct 2022 01:43:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5A9cn3qMMenq8UUTISrwbnTDl/BmBqicZa7TNq160y8M+QIEXTEnSMdyAc1eEtPo3hInFwIw== X-Received: by 2002:a05:600c:1906:b0:3c6:f154:d4b5 with SMTP id j6-20020a05600c190600b003c6f154d4b5mr12121983wmq.94.1666341838348; Fri, 21 Oct 2022 01:43:58 -0700 (PDT) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id k5-20020a5d6d45000000b0022e57e66824sm21598578wri.99.2022.10.21.01.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 01:43:58 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 06/12] gdbserver: allow agent expressions to fail with invalid memory access Date: Fri, 21 Oct 2022 09:43:42 +0100 Message-Id: <225a59db6143d8793f131f9489fa66f3166e788a.1666341010.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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-List-Received-Date: Fri, 21 Oct 2022 08:44:35 -0000 This commit extends gdbserver to take account of a failed memory access from agent_mem_read, and to return a new eval_result_type expr_eval_invalid_memory_access. I have only updated the agent_mem_read calls related directly to reading memory, I have not updated any of the calls related to tracepoint data collection. This is just because I'm not familiar with that area of gdb/gdbserver, and I don't want to break anything, so leaving the existing behaviour as is seems like the safest approach. I've then update gdb.base/bp-cond-failure.exp to test evaluating the breakpoints on the target, and have also extended the test so that it checks for different sizes of memory access. --- gdb/testsuite/gdb.base/bp-cond-failure.exp | 16 +++++++--------- gdbserver/ax.cc | 12 ++++++++---- gdbserver/ax.h | 3 ++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp index 6f89771d187..aa39b638592 100644 --- a/gdb/testsuite/gdb.base/bp-cond-failure.exp +++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp @@ -39,7 +39,7 @@ if { [is_address_zero_readable] } { # Where the breakpoint will be placed. set bp_line [gdb_get_line_number "Breakpoint here"] -proc run_test { cond_eval } { +proc run_test { cond_eval access_type } { clean_restart ${::binfile} if {![runto_main]} { @@ -52,7 +52,7 @@ proc run_test { cond_eval } { } # Setup the conditional breakpoint and record its number. - gdb_breakpoint "${::srcfile}:${::bp_line} if (*(int *) 0) == 0" + gdb_breakpoint "${::srcfile}:${::bp_line} if (*(${access_type} *) 0) == 0" set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*"] gdb_test "continue" \ @@ -68,16 +68,14 @@ proc run_test { cond_eval } { # If we're using a remote target then conditions could be evaulated # locally on the host, or on the remote target. Otherwise, conditions # are always evaluated locally (which is what auto will select). -# -# NOTE: 'target' is not included here for remote targets as a -# gdbserver bug prevents the test from passing. This will be fixed in -# the next commit, and this test updated. if { [gdb_is_remote_or_extended_remote_target] } { - set cond_eval_modes { "host" } + set cond_eval_modes { "host" "target" } } else { set cond_eval_modes { "auto" } } -foreach_with_prefix cond_eval $cond_eval_modes { - run_test $cond_eval +foreach_with_prefix access_type { "char" "short" "int" "long long" } { + foreach_with_prefix cond_eval $cond_eval_modes { + run_test $cond_eval $access_type + } } diff --git a/gdbserver/ax.cc b/gdbserver/ax.cc index 365bd2195b2..377ac9682a6 100644 --- a/gdbserver/ax.cc +++ b/gdbserver/ax.cc @@ -1112,22 +1112,26 @@ gdb_eval_agent_expr (struct eval_agent_expr_context *ctx, break; case gdb_agent_op_ref8: - agent_mem_read (ctx, cnv.u8.bytes, (CORE_ADDR) top, 1); + if (agent_mem_read (ctx, cnv.u8.bytes, (CORE_ADDR) top, 1) != 0) + return expr_eval_invalid_memory_access; top = cnv.u8.val; break; case gdb_agent_op_ref16: - agent_mem_read (ctx, cnv.u16.bytes, (CORE_ADDR) top, 2); + if (agent_mem_read (ctx, cnv.u16.bytes, (CORE_ADDR) top, 2) != 0) + return expr_eval_invalid_memory_access; top = cnv.u16.val; break; case gdb_agent_op_ref32: - agent_mem_read (ctx, cnv.u32.bytes, (CORE_ADDR) top, 4); + if (agent_mem_read (ctx, cnv.u32.bytes, (CORE_ADDR) top, 4) != 0) + return expr_eval_invalid_memory_access; top = cnv.u32.val; break; case gdb_agent_op_ref64: - agent_mem_read (ctx, cnv.u64.bytes, (CORE_ADDR) top, 8); + if (agent_mem_read (ctx, cnv.u64.bytes, (CORE_ADDR) top, 8) != 0) + return expr_eval_invalid_memory_access; top = cnv.u64.val; break; diff --git a/gdbserver/ax.h b/gdbserver/ax.h index b4062bf24a8..aad9e11078d 100644 --- a/gdbserver/ax.h +++ b/gdbserver/ax.h @@ -41,7 +41,8 @@ enum eval_result_type expr_eval_unhandled_opcode, expr_eval_unrecognized_opcode, expr_eval_divide_by_zero, - expr_eval_invalid_goto + expr_eval_invalid_goto, + expr_eval_invalid_memory_access }; struct agent_expr -- 2.25.4