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 E96C13858436 for ; Tue, 31 Jan 2023 17:49:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E96C13858436 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=1675187346; 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=WpJb6Z6lSfjDWxWBRvLkeljxbLI1A+6tr1fbA9ZMIe4=; b=TVnR1Gc1qWHO3eq0C+a/6313leKSgZrVXZXsXvtGgRNKKm1MAARK6FbIaF1ULH+JRSEsAm iuSFndVkP4ntAzox5nhbPlH3VhljVPKtbyZBgWHcB1xeiSzBGBk04pqlCfTlRDT7BE9X9N xUofV49Xff9bPZUIu1KrsnRzt9PMuBE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-361-2gkvaswaNMSEevrF2Jtxxw-1; Tue, 31 Jan 2023 12:27:31 -0500 X-MC-Unique: 2gkvaswaNMSEevrF2Jtxxw-1 Received: by mail-qt1-f197.google.com with SMTP id m7-20020ac807c7000000b003b80b35c136so6809769qth.5 for ; Tue, 31 Jan 2023 09:27:31 -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=WpJb6Z6lSfjDWxWBRvLkeljxbLI1A+6tr1fbA9ZMIe4=; b=62j4XJ55MLn9lHSkd037gopB5YylN91Ck/AfyIZCdtcZ0HIdqtm8xuGeq4K8ajDl9T aIZ8ic1H8XMsHpt/PWlnS/iySlLxynDhUFrU9OeaBWdl0uGu9JOOYZrCxXsSbXaSCCCl pdY2BiJnhCyMPSccc7dTKgAGj8T82aNJ1heB1HwcNGnBQ0RnXOItVo8umxHNZSDRlCBV 4I05tfJ8nzDV5BQOU0IgDnuo1UOfk9WcXbotwxpiQ3tLt56MGy44nyJCvkuBPSjZ5oex Hkb6Ee/4iBf4VjjrnOyDacOzFa+DZYQPC014MoDBsXiqv4N0vOHdiYWZLd8/oy7jwiKV yU1g== X-Gm-Message-State: AO0yUKXIJYWMb3Pbr4TnO9YQ5OoPLf+tsmIszg616rLx5rcKdPLqkVgr mLoVJW5zFj4NExLuCLIz/istwS9vdArejqc2qMeNEGuDViUXVmJ8nYpEistw4IYUHXB6LFz02vY QC8zPGudeJN7zGKiC5NC6YmWeHzgH9TGGJpDrLzBP4gha/MFLH7Qq7f61OcxhB11miplM6X4P5g == X-Received: by 2002:ac8:7dc2:0:b0:3b8:68df:fc75 with SMTP id c2-20020ac87dc2000000b003b868dffc75mr15016385qte.31.1675186051173; Tue, 31 Jan 2023 09:27:31 -0800 (PST) X-Google-Smtp-Source: AK7set+CgFs2kyKO1RIw/pM7DzP6e/mqZNpsQUdjKAMrzTtkCopGR4HNhxiGsGrdRJicPooj8UtUsw== X-Received: by 2002:ac8:7dc2:0:b0:3b8:68df:fc75 with SMTP id c2-20020ac87dc2000000b003b868dffc75mr15016348qte.31.1675186050881; Tue, 31 Jan 2023 09:27:30 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id ea16-20020a05620a489000b007059c5929b8sm10394752qkb.21.2023.01.31.09.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:30 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 05/13] gdbserver: allow agent expressions to fail with invalid memory access Date: Tue, 31 Jan 2023 17:27:10 +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 it is 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 | 21 +++++++-------------- gdbserver/ax.cc | 12 ++++++++---- gdbserver/ax.h | 3 ++- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/gdb/testsuite/gdb.base/bp-cond-failure.exp b/gdb/testsuite/gdb.base/bp-cond-failure.exp index 9388b8cf582..d67c68c46a1 100644 --- a/gdb/testsuite/gdb.base/bp-cond-failure.exp +++ b/gdb/testsuite/gdb.base/bp-cond-failure.exp @@ -48,7 +48,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] } { @@ -61,7 +61,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" \ @@ -90,16 +90,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" - + lappend cond_eval_modes "host" set cond_eval_modes { "host" } pass $gdb_test_name } @@ -109,6 +100,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