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 763A63858408 for ; Mon, 3 Apr 2023 13:50:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 763A63858408 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=1680529850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=U4/Bv3TDXKKyklCKtALhgmESf8Inc5FYWttTyARg9TI=; b=SU3F9VqmMmMfg2L4jggY1KZgehukajlWO7TrDteOC8zyOgbxbv7Ib3LSp3TsnAUDWWIlvE YJJ5tnoqQtRXkln58xoxHGfnmhpNCHu2BiIYlllDStN8r1oiX1xJGxY6/gTDSPG1NeU0Bx Tky07g/xa7GQuhxCVgebjDSxUWRMRXs= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-283-bBXbGTelMcOH3j6IqETYuw-1; Mon, 03 Apr 2023 09:50:48 -0400 X-MC-Unique: bBXbGTelMcOH3j6IqETYuw-1 Received: by mail-qv1-f70.google.com with SMTP id y19-20020ad445b3000000b005a5123cb627so13035447qvu.20 for ; Mon, 03 Apr 2023 06:50:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680529848; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U4/Bv3TDXKKyklCKtALhgmESf8Inc5FYWttTyARg9TI=; b=n3bLvneMQmqTA+RGW4QSh/N+rtM3aR2/NCRrBkuiiP6xmHtexQfmW6kVc2Njd1obs0 QgY85ZelSJZ9T6j7Q7Hjpu9zGazdlgwL4VIPPLWP6xqJhQlrEQq+wIqBb5qWa/8jF1O6 1y7SDOh8J1otrU8bAUtg3WUOitYuYPZ9cJfTy1aM7rnJm7U8zO1NLicx51zRYKVbVjR4 t7YrAaSR5VsUHfP3gyq3JHEzQU13SDHkBzGd9u3z33JjER/Q5yHHf3BaHgTp6iVOC4Xn n6b93LYS8uTBb22j37002sk/mUJoJgT9WNYCZ3lhK16Fcv+c1riHxUsAozVw45l12XHH yN3w== X-Gm-Message-State: AO0yUKWfLnlO4weItgGDlkHbwYB3pyYOjc96wQGngVNQf2N3lbrqxWKg ZuI4aSGmYeoyJQQZGcL7P6e4gUUDni3XWJF2vaPDnT8flIcxRYG3qO40l3UHLcnj7VaU6vH3G2n kCFYgAI/5mCAB3YfoyCbStcMl3J4OMUHktEOV6dUSXsD8f409hHntNszlWbFzTdXZMLWHNHOvKa /tIG8mSA== X-Received: by 2002:ac8:5982:0:b0:3e3:c889:ed06 with SMTP id e2-20020ac85982000000b003e3c889ed06mr58201894qte.21.1680529848150; Mon, 03 Apr 2023 06:50:48 -0700 (PDT) X-Google-Smtp-Source: AK7set9190mMoM9aY9A07LN1uhGdGKi7/9EVPx8KRdLSRcdWZ5n1jaQPyijijsci6vibqvK0ypI/Cw== X-Received: by 2002:ac8:5982:0:b0:3e3:c889:ed06 with SMTP id e2-20020ac85982000000b003e3c889ed06mr58201868qte.21.1680529847824; Mon, 03 Apr 2023 06:50:47 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id o19-20020a05620a2a1300b007461e8efacbsm2754538qkp.69.2023.04.03.06.50.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 06:50:47 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: Re: [PATCHv5 03/11] gdbserver: allow agent expressions to fail with invalid memory access In-Reply-To: <0ef54ed920e1262a07f4a061ecc08bea8fcaee23.1678987897.git.aburgess@redhat.com> References: <0ef54ed920e1262a07f4a061ecc08bea8fcaee23.1678987897.git.aburgess@redhat.com> Date: Mon, 03 Apr 2023 14:50:46 +0100 Message-ID: <87lej9cbwp.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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: Andrew Burgess writes: > 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. I went ahead and pushed this commit. If there are any problems, please let me know, I'm happy to address any issues. Thanks, Andrew > --- > 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