From patchwork Fri Oct 21 08:43:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 59263 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D6A138650D0 for ; Fri, 21 Oct 2022 08:45:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D6A138650D0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666341919; bh=l4TLGPtbEh+Nvv3PzqHc1UUMdfwR1uzTBdzPVWNwq8M=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=WrawCTCJFiWQWl3LnEK+zI3PPOyOaAg3Qm2B+zTUyg8l8EMvt1UwuZG36tF0UQWwp 7LFhk8gveDjTL2rBraXUtVHPLGniyIVjc/STzsKYcUZqn6dTeVznEAUlEr1u1Qs3Z8 yNvF7CUvM4q9jn9spYUobW3kGTyjemU/hOBMgyn0= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 588D03856162 for ; Fri, 21 Oct 2022 08:44:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 588D03856162 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-498-oFWnvs4jPt6VQBBkq3aHhQ-1; Fri, 21 Oct 2022 04:43:58 -0400 X-MC-Unique: oFWnvs4jPt6VQBBkq3aHhQ-1 Received: by mail-wm1-f71.google.com with SMTP id i203-20020a1c3bd4000000b003c6d18a7ee5so1149910wma.6 for ; Fri, 21 Oct 2022 01:43:58 -0700 (PDT) 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=l4TLGPtbEh+Nvv3PzqHc1UUMdfwR1uzTBdzPVWNwq8M=; b=Jmw06MfV5ux5K1ngfmSt9cHRJjcDkCENlW6nxkA30mORH5X7Xgbxb9Gx+BvGVdEU6g YeuHkrzgC7p+DA4Rc2ASmm3a5YQ6Edd8MHO5HgngHcKeMxqRtL/4DyVyc/umjd7dmeSa rAigmOWmhNBfLAfMsG3Up+PrgcgG2lN0MPashiwullOdaj2FWqwvifd95xqWIk63A23R nNgltAKPf0X089QZzOijVv42mwmVd4BoWWpdpUvECRp0Ivcz4J+bmstU78Bsc6DnjNRX nKmtix9TQNWTmUfTJUUamZmNWqwSmyO/0wGPuRKzHl4D0YjxeVQ93B1DdzdyndBJZ8Nm UPkA== X-Gm-Message-State: ACrzQf0SI/eS172+S5TYqmireRGWMQ7l18wVFujG/JOOWrzdI1vElHKN QGVyPZvvUcOaSj27lwXm5Cml0arLzqNXyiNV2KAG18caUlDwVU/HCxPZLfl17R5V4FajDn4n4d4 wIeUGzChXTQC4Jr6c91qBEZMiTpEL+W3pRkJbXSu4W7JH9C9ePCrdkNuDpxarymJKp42w6NbETA == X-Received: by 2002:a5d:4a4d:0:b0:22d:c8cb:8687 with SMTP id v13-20020a5d4a4d000000b0022dc8cb8687mr11247789wrs.554.1666341837426; Fri, 21 Oct 2022 01:43:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62oXpLEJ0JltHd7ftld+bQ3P0PRU4Gr4GB7I+CXzuSHmvMB27leRR8UiQPMHOmlAzjmcxPxA== X-Received: by 2002:a5d:4a4d:0:b0:22d:c8cb:8687 with SMTP id v13-20020a5d4a4d000000b0022dc8cb8687mr11247778wrs.554.1666341837097; Fri, 21 Oct 2022 01:43:57 -0700 (PDT) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id q124-20020a1c4382000000b003c706e177c1sm2068383wma.14.2022.10.21.01.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 01:43:56 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 05/12] gdbserver: allows agent_mem_read to return an error code Date: Fri, 21 Oct 2022 09:43:41 +0100 Message-Id: <2b2e5450488c5dc9422894ef36d67a644fc6db02.1666341010.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 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently the gdbserver function agent_mem_read ignores any errors from calling read_inferior_memory. This means that if there is an attempt to access invalid memory then this will appear to succeed. In this I update agent_mem_read so that if read_inferior_memory fails, agent_mem_read will return an error code. However, non of the callers of agent_mem_read actually check the return value, so this commit will have no effect on anything. In the next commit I will update the users of agent_mem_read to check for the error code. I've also updated the header comments on agent_mem_read to better reflect what the function does, and its possible return values. --- gdbserver/tracepoint.cc | 11 ++++------- gdbserver/tracepoint.h | 9 +++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc index efcdfe12beb..74774759d3a 100644 --- a/gdbserver/tracepoint.cc +++ b/gdbserver/tracepoint.cc @@ -4923,8 +4923,7 @@ condition_true_at_tracepoint (struct tracepoint_hit_ctx *ctx, return (value ? 1 : 0); } -/* Do memory copies for bytecodes. */ -/* Do the recording of memory blocks for actions and bytecodes. */ +/* See tracepoint.h. */ int agent_mem_read (struct eval_agent_expr_context *ctx, @@ -4936,10 +4935,7 @@ agent_mem_read (struct eval_agent_expr_context *ctx, /* If a 'to' buffer is specified, use it. */ if (to != NULL) - { - read_inferior_memory (from, to, len); - return 0; - } + return read_inferior_memory (from, to, len); /* Otherwise, create a new memory block in the trace buffer. */ while (remaining > 0) @@ -4960,7 +4956,8 @@ agent_mem_read (struct eval_agent_expr_context *ctx, memcpy (mspace, &blocklen, sizeof (blocklen)); mspace += sizeof (blocklen); /* Record the memory block proper. */ - read_inferior_memory (from, mspace, blocklen); + if (read_inferior_memory (from, mspace, blocklen) != 0) + return 1; trace_debug ("%d bytes recorded", blocklen); remaining -= blocklen; from += blocklen; diff --git a/gdbserver/tracepoint.h b/gdbserver/tracepoint.h index bbffb6228f4..afab22b214d 100644 --- a/gdbserver/tracepoint.h +++ b/gdbserver/tracepoint.h @@ -161,8 +161,13 @@ void gdb_agent_about_to_close (int pid); struct traceframe; struct eval_agent_expr_context; -/* Do memory copies for bytecodes. */ -/* Do the recording of memory blocks for actions and bytecodes. */ +/* When TO is not NULL, do memory copies for bytecodes, read LEN bytes + starting at address FROM, and place the result in the buffer TO. + Return 0 on success, otherwise a non-zero error code. + + When TO is NULL, do the recording of memory blocks for actions and + bytecodes into a new traceframe block. Return 0 on success, otherwise, + return 1 if there is an error. */ int agent_mem_read (struct eval_agent_expr_context *ctx, unsigned char *to, CORE_ADDR from,