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 F05093857C71 for ; Thu, 16 Mar 2023 17:37:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F05093857C71 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=1678988237; 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=CruAqH9xi94Yzg7jHH3aUDp/0wu67CbzrGj9tpZdJuRaaxOzuWBOv5lfkeliUhnqRl2fv7 mvFcbUlxkOXRXXKnMEKiQQHaA7ndzgpA8VsGvwX+qaHB+tSHV+NaVxM4HKqnz9uoDS5yW8 ulEUcH431I5lAjezpLiGpGWsQhiciw8= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-zAxCTlQVOYmPh7fB0ItK7A-1; Thu, 16 Mar 2023 13:37:16 -0400 X-MC-Unique: zAxCTlQVOYmPh7fB0ItK7A-1 Received: by mail-ed1-f69.google.com with SMTP id en6-20020a056402528600b004fa01232e6aso4068734edb.16 for ; Thu, 16 Mar 2023 10:37:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678988235; 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=AHmsIiaXWfkdS4ykIraBvXSwPzj3CmbGDtX+/1v7C8OWujHv3v7t+TA1ZAfMnWyXx/ 2K0tpiBoPoh3hgtftpa7c73DlxHCm1XWeKHLyZZtyJqpggodOQKfuY2fMbdZbqmid47e iaESLtv0t5bwCqoXwclQcRGCE9gNoSYDEHFfGsuw3k20lZ/ORGUINcTa0sm4st/qFZlu cN3sF7QtCd52JRqFiN8Pk+vG5iMTv8uYCRxPbkcrDt8QTOHhV5dHjzI09KusEMZ3wkeN Kg1XmOxmfzQqFfvhKLlckPGw8x1282FkYp3QRfkkcBBhmEn291DDBYZdrZi386yYyQcw cCYA== X-Gm-Message-State: AO0yUKWL6qqTrVEmeIDnTYU9GLQMI+dhtJatTZZiiartU8fmqQ0f4sW2 GLnaiZgSE2cASJ+yZXF2BMXkNQLnx9G/RThAiJt9W5fYJaH+lIRJTYPRkOSuhKiJ5xJSANFqSeD 1TwvkAoiRQ3p13dW3UT/aQyC5XLduGJNv3ZdYaWRMHYk9Q9ksM3ovbZpzZeMBWk/3KxyKQxzuE3 dsGYwKQw== X-Received: by 2002:a17:906:3f87:b0:922:446b:105a with SMTP id b7-20020a1709063f8700b00922446b105amr200972ejj.19.1678988235305; Thu, 16 Mar 2023 10:37:15 -0700 (PDT) X-Google-Smtp-Source: AK7set+A5JAvsEuZM77o8XEyDg7sPPchiD3rShmjhWO34sjo9sQ3bcMzhbgdmDr2KBYDCgEX7DAU/A== X-Received: by 2002:a17:906:3f87:b0:922:446b:105a with SMTP id b7-20020a1709063f8700b00922446b105amr200960ejj.19.1678988235071; Thu, 16 Mar 2023 10:37:15 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id l1-20020a170906644100b0091f5e98abd5sm4083267ejn.133.2023.03.16.10.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 10:37:14 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv5 03/11] gdbserver: allow agent expressions to fail with invalid memory access Date: Thu, 16 Mar 2023 17:36:58 +0000 Message-Id: <0ef54ed920e1262a07f4a061ecc08bea8fcaee23.1678987897.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