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 BB7923858439 for ; Wed, 18 Jan 2023 16:18:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB7923858439 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=1674058707; 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=LCjfycesF3lyIvgRhuxOZll32Bd6KAbeEnf9R8JAoF8=; b=Cu0t9R4eSa67bXapWoH9/m/pCHZ/dQDgiUHml48rV2MMpywmUmVZ/wbf0+V6Uxlsd4IpYz sStaboAiatHsa2lQPQ+4trCPutCZ34F9oi9NceLT+BjG1J9kmvNfXdOQqQNacDuSw0/kPD vm1X8KnndotDBLcM/kD5Hde8RVSH4V0= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-225-u2DLPI5OPqmnp6jLvyGKcQ-1; Wed, 18 Jan 2023 11:18:26 -0500 X-MC-Unique: u2DLPI5OPqmnp6jLvyGKcQ-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-4d5097a95f5so230084607b3.1 for ; Wed, 18 Jan 2023 08:18:26 -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=LCjfycesF3lyIvgRhuxOZll32Bd6KAbeEnf9R8JAoF8=; b=mY3EspDtsobCL+5pjQlLA+xeEz9E2xi238b86jnWmugS4vF19CsSpwCwfrTsrFRe0D 1zw+TwIRH+7M3jHdr/mStb15sFyrc/13AK7193NbugVPiQI5b9IpcFJJoO2OJfQuYN2S yUy647krXGl6kKvfePOHxogYmP8aPh58kogR9yvPQD87JTSI26Bt+mJ14s6rjYzzStF4 2Bl7bE/n9skazjJD6l779TS4OE1qb6lmHaT8+bhWQ2PpOwgsbGb/T5SQY5NafFuejaOn ynepn8SGnPODs3l0EBiz/0cfl8FqAvVYhCfkVkui8jNINJ3ROfeA+hJMU1J2SAs29Tko XWGw== X-Gm-Message-State: AFqh2kq9WYyI3M4I/c2YGXvgDFpsktrmn5O2Kw1v05jjc5R7Nz4gf71A MEgO1N5PMS2fabPqwJtVa3e/vzxhaEpzwcgrE5wcImous+q4+CpsVMl8CBLVR0F22QZLMiENAMc nY5RGLFzSIxZKuuPbQ27LAkfb5aKaOxJUsxRUnN/kQICZMfahAv6336ZlIy9+8mqG58ao1xOS6w == X-Received: by 2002:a81:430d:0:b0:477:f2c8:6def with SMTP id q13-20020a81430d000000b00477f2c86defmr22864553ywa.49.1674058705401; Wed, 18 Jan 2023 08:18:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsKDEZkyaitZtpVi/OfL8MOND7DdSf/G78vAtR4pRELOWSGyrXUpF4N4Z2Jc3QE0RH4DhWNyg== X-Received: by 2002:a81:430d:0:b0:477:f2c8:6def with SMTP id q13-20020a81430d000000b00477f2c86defmr22864528ywa.49.1674058705059; Wed, 18 Jan 2023 08:18:25 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id w26-20020a05620a0e9a00b006fa22f0494bsm2916236qkm.117.2023.01.18.08.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 08:18:24 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 05/13] gdbserver: allow agent expressions to fail with invalid memory access Date: Wed, 18 Jan 2023 16:18:01 +0000 Message-Id: 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 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 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 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