From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6Hn8LewbyGPzlRkAWB0awg (envelope-from ) for ; Wed, 18 Jan 2023 11:18:52 -0500 Received: by simark.ca (Postfix, from userid 112) id B90721E15D; Wed, 18 Jan 2023 11:18:52 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ut3upjMf; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id F1D891E124 for ; Wed, 18 Jan 2023 11:18:51 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 93BD138582BC for ; Wed, 18 Jan 2023 16:18:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93BD138582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674058731; bh=OE1uL6yvVfCCxE656XTl3nXLX8KrynaygoS5NdDgQY4=; 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=ut3upjMfA6BbvxZnILLduLYXlNG9gc/DIdntMfCpg/3Izttw8WM7qsx2dbWn4H1Q0 3lpmWUwXn0QZ0lmZGT+bPrnOpmMZu8EWWDMG857JyvomHEWWlF4pkFvpvcq7NT0xAT stL2CKSqW7gWWItDguiO1ONF4rVTTR62F5AowkW4= 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 EABAC38582AC for ; Wed, 18 Jan 2023 16:18:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EABAC38582AC Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-437-gRF8GE0rNr-9AFJnckOc7A-1; Wed, 18 Jan 2023 11:18:24 -0500 X-MC-Unique: gRF8GE0rNr-9AFJnckOc7A-1 Received: by mail-yb1-f200.google.com with SMTP id y15-20020a2586cf000000b007d35ff419e6so13866502ybm.5 for ; Wed, 18 Jan 2023 08:18:24 -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=OE1uL6yvVfCCxE656XTl3nXLX8KrynaygoS5NdDgQY4=; b=DfVX5QF1SbPFpOtFr/LG39v1EvyCin1jyqljm7jlyPC57ryaCoUtt1+GFH2ae/0JPX 78MEN3Yq0fD/FPnjFlCMOsmCWe6Ev2YbOlw7BmSWrh/Ls39XZTOxFv0ejOAnwrTgCJhb EggMd+iZPc5cBteZdWIluy7+XDGGZ+HLCmBBA5AH4WGyrNre6A8W+TLo/u+cmiRbLkzT ebIMoEnyfDgI1TG1O/G8zuFTR7yfWJX3FTZqhE88fBQybj5mw9Ql67aRA31E2870c10+ 15rYcMx03FuBkVqekkAHekJiz4YkftHuRfRcVrtKb3Q4QKBJM7BBNG6Vd6+r/iUKxcUw SDcg== X-Gm-Message-State: AFqh2kp5yFbC2ya18z9PEIT0yzcnSj2kMx7it/JrFNmAVFCcDpTpf91y NU6z/VxCwnxZb+6ztVddEKlZpIN8fZXFJ6yWrZTzdyIxwz9h9l0zI992kfRUejCWfdJt4Vvin1j hx3C5ybxGDT5shtkdFYVtlbJl9d5sNbCjNEBk8GN3kFlIt8WF5e3x0plL99lOwMfoqN8C8tC3vQ == X-Received: by 2002:a25:b8c9:0:b0:7cb:40de:ba17 with SMTP id g9-20020a25b8c9000000b007cb40deba17mr6550181ybm.16.1674058703466; Wed, 18 Jan 2023 08:18:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXtJtgB60R+DpMMyClViFqRZOcFgXK8MkkvbekjefrMeYEQCSnm3o87mHUF8GMXNzWSK1YWbnA== X-Received: by 2002:a25:b8c9:0:b0:7cb:40de:ba17 with SMTP id g9-20020a25b8c9000000b007cb40deba17mr6550148ybm.16.1674058703062; Wed, 18 Jan 2023 08:18:23 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id f9-20020a05620a280900b006fcaa1eab0esm22823407qkp.123.2023.01.18.08.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 08:18:22 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 04/13] gdbserver: allows agent_mem_read to return an error code Date: Wed, 18 Jan 2023 16:18:00 +0000 Message-Id: <38df45adb7bfb18c47724d63f67bd35b5cd0923c.1674058360.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-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: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@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 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, -- 2.25.4