From patchwork Tue Jan 31 17:27:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64028 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 320A93858C27 for ; Tue, 31 Jan 2023 17:49:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 320A93858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187370; bh=MlpcCbiH7uPAPCNQh01Jxe8GcmBHloptTG/lScdXxXs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=O5PHK97pksNCpZbPHwmoQumRX8Cuw1N90Hwj4YGbcDO8Wr4HcrQ09YvhSGhjlCDn3 z7yifIw7s91Dnipj1FEKAzjMkY8sH9Kb/sF9FAlDTlGlZVQfOl0K5JkNrqLZN7Mh7A VA+XRMV6d2c6LcBViV4lZntgdE4vyei4I1rHPFgs= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 22F5E3858D28 for ; Tue, 31 Jan 2023 17:49:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22F5E3858D28 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-464-UD-sSsI_Njm30OC4ACvQ9Q-1; Tue, 31 Jan 2023 12:27:30 -0500 X-MC-Unique: UD-sSsI_Njm30OC4ACvQ9Q-1 Received: by mail-qv1-f71.google.com with SMTP id ob12-20020a0562142f8c00b004c6c72bf1d0so8552127qvb.9 for ; Tue, 31 Jan 2023 09:27:29 -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=MlpcCbiH7uPAPCNQh01Jxe8GcmBHloptTG/lScdXxXs=; b=FIMwmyKwtFoBB9Fcih1rJMgOXl/LOUCKktgb3AbSkDFbyoaXRLRkfAFQB25TyrHu+C e221rJlm3bWeq/LbPKed5kGc2olTqkBjQjnBsvTqgn+507qHgPMu91fsZ4e+V+7XyLt4 SxomF2D87J81H9QkRefsHJyMirPDcx34PrcP79IGW2lLWXBlfP4DfyA3ydR6rTZtbZui tBias6RyS7GF6N1ijXThGAZEYaVWQLzSoFeN5N9IB8gjGfurL7pJB625lSrHJMfm3po7 ZSwMbLzRMutc+n8MG8SU4OZNc9W9MV4143txCDRZXwTfB5Z2z1UKywrr/8rwF6uMHv9X m/iQ== X-Gm-Message-State: AO0yUKU4fqMonaGMgCEYkdBxX9TaJOEQhBxKHUIzCIqUGA+qxtAki9Hy 00seJ/iOHrV3HaDjp3ShdNYTIa0rowfxhYj5mgr/YRYKrGFFWLALwuy3PwcATZXrxNNiWz9FeYo 9oDzm/+Qos9qDGeh7ZzAdwuPfT5WQQgPloPL6G1NT1fu0WwZ08bDNDfbLPhLA3fayHWOi27XCqw == X-Received: by 2002:a05:622a:1181:b0:3b8:293c:24eb with SMTP id m1-20020a05622a118100b003b8293c24ebmr20665757qtk.30.1675186049260; Tue, 31 Jan 2023 09:27:29 -0800 (PST) X-Google-Smtp-Source: AK7set+BvNCnvabOvTu1qSSug6viBuHNsWoPgBH8h/OFQtb4g3hVqmSHC2rRS4GZ2Ms5I7DUYO9cWQ== X-Received: by 2002:a05:622a:1181:b0:3b8:293c:24eb with SMTP id m1-20020a05622a118100b003b8293c24ebmr20665721qtk.30.1675186048917; Tue, 31 Jan 2023 09:27:28 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id x20-20020a05620a01f400b0071d2cd07560sm5614817qkn.124.2023.01.31.09.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:28 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 04/13] gdbserver: allows agent_mem_read to return an error code Date: Tue, 31 Jan 2023 17:27:09 +0000 Message-Id: <880c3b43698c198daa8dd9dc128421b4874454b2.1675185990.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 patch I update agent_mem_read so that if read_inferior_memory fails, agent_mem_read will return an error code. However, none 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 37a9a8c5b7c..60918fc0678 100644 --- a/gdbserver/tracepoint.cc +++ b/gdbserver/tracepoint.cc @@ -4914,8 +4914,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, @@ -4927,10 +4926,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) @@ -4951,7 +4947,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 a30f540d130..e424dc9dfb8 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,