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.133.124]) by sourceware.org (Postfix) with ESMTPS id 13F6C3858C5E for ; Tue, 28 Feb 2023 16:42:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13F6C3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677602548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pl4VCI6VN8m5Xp5WOf37xaIXVDNh8d6O9nFwZJMUvyI=; b=UP9nySBKkxjKy5lguaaZuhuPPB1JU97vTrUCT4kM6kdxg1s1gukwJutP5DGYcwczDan7Mc Cm76DZ6+PzTMp2DaHBqu5OTG/tYdGbD3/I9HiXrljzRYm8xO9hBOqmAHEN72nOvBUFBDi2 S5p0jvsUIDcjdDBav1aPUOxrfWgjRr8= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-138-8a2QFkfaOdK5Sw00fDIVSA-1; Tue, 28 Feb 2023 11:42:27 -0500 X-MC-Unique: 8a2QFkfaOdK5Sw00fDIVSA-1 Received: by mail-ed1-f72.google.com with SMTP id ck7-20020a0564021c0700b004a25d8d7593so14781904edb.0 for ; Tue, 28 Feb 2023 08:42:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677602546; 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=pl4VCI6VN8m5Xp5WOf37xaIXVDNh8d6O9nFwZJMUvyI=; b=Qk5X1I9bqG+Qliv6J9usDUSAN2XKQVVhpc6Zx54uBjqmw4Ey4zytRpZaQchVPKirsC xYOeBk/BiNmK6Wxrdao1bAudoG3f7aR7Q8JmmngvSvi/R5i+T+jhlF7E92a5iFUDCrfE xnSH4nwWeVTaqNObo61B/IJej+8K2IJiu72QVkOYd545O2YGPRkE01sFPMFtTfAM9SGg zk+7V3ua511kYnko+m03iths9mjGx/82ATvd3kIwE2lxntNetNrgPXegMfYKfT3cnpV2 OFauqOWIe3mzw1Vou0eDMl9DuWvfDWcxMnjkQ5HDDrLtjebs+pJ6d+j5p4iuf+kt2Hln ykbg== X-Gm-Message-State: AO0yUKX1C0s910nht6TU/BGhIis/l+pWUA8TlXUPvIoGzp2sFAUxiMpi J+oAVzJ4aoiPuBn9U9sXEyIvw9ZkeJW5MX9FjVsSi3IGoFuOPEZRCuYQzulO/9PKSzQWETtyHqQ 536YmNNxENgvx8ZkZE2uPHDCUEjgoeHLYCBNEtpUmVxUhNUpfnwitwqoIlyT7ZsaP/yUqgAboMg Y13eY= X-Received: by 2002:a17:906:49ca:b0:87b:dac1:bbe6 with SMTP id w10-20020a17090649ca00b0087bdac1bbe6mr3134813ejv.36.1677602546216; Tue, 28 Feb 2023 08:42:26 -0800 (PST) X-Google-Smtp-Source: AK7set+wmPOgvcj6e5eWUcuQZ19fLJa+lVobepD1cm+r9OQmZItNy2MdN0kxZGcQ9m/8XB7fQ7xmnA== X-Received: by 2002:a17:906:49ca:b0:87b:dac1:bbe6 with SMTP id w10-20020a17090649ca00b0087bdac1bbe6mr3134793ejv.36.1677602545874; Tue, 28 Feb 2023 08:42:25 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id t7-20020a1709063e4700b008da6a37de1bsm4772970eji.10.2023.02.28.08.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 08:42:25 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 04/12] gdbserver: allow agent expressions to fail with invalid memory access Date: Tue, 28 Feb 2023 16:42:09 +0000 Message-Id: <339e567a7bfde214c410df9ce3eb0c6c4bec1080.1677602051.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.7 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 List-Id: 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 untouched seems like the safest approach. I've then updated 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 | 22 +++++++--------------- gdbserver/ax.cc | 12 ++++++++---- gdbserver/ax.h | 3 ++- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp index b528ccce4ad..cb572203772 100644 --- a/gdb/testsuite/gdb.base/bp-cond-failure.exp +++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp @@ -47,7 +47,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] } { @@ -59,7 +59,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" \ @@ -88,17 +88,7 @@ set cond_eval_modes { "auto" } gdb_test_multiple "show breakpoint condition-evaluation" "" { -re -wrap "Breakpoint condition evaluation mode is auto \\(currently target\\)\\." { - - ## NOTE: Instead of testing with "auto" and "host" in this - ## case we only test with "host". This is because a GDB bug - ## prevents the "auto" (a.k.a. target) mode from working. - ## - ## Don't worry, this will be fixed in a later commit, and this - ## comment will be removed at that time. - ## - ## lappend cond_eval_modes "host" - - set cond_eval_modes { "host" } + lappend cond_eval_modes "host" pass $gdb_test_name } @@ -107,6 +97,8 @@ gdb_test_multiple "show breakpoint condition-evaluation" "" { } } -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 38ebfbbd750..fba5b4ad0fc 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 8e64a7a593e..c98e36a83c6 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