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 AEA6C385840D for ; Thu, 16 Mar 2023 17:37:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AEA6C385840D 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=1678988236; 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=2Jq/dgceUVfir3sp9Vj6qGReDLvlVejYLCJe11Y+qj4=; b=KLmezNjSWIEbRLinwviFsHKpL8gJi6bq5k83OFKhhz/FHJMiI8R9eW/yMasTAex75iNy6r cN0Yrn+KFLcCcI1Yqsyzh3S405AZMrsIh2QrebSsawZM23wqLTIOrjotIxBcreQ9c+UZs1 KC5Isz1MFGJmG9emwMUFQEYHflnaxek= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-5zbPiqurOb6Fuw3rigy4wA-1; Thu, 16 Mar 2023 13:37:14 -0400 X-MC-Unique: 5zbPiqurOb6Fuw3rigy4wA-1 Received: by mail-ed1-f71.google.com with SMTP id w6-20020a05640234c600b004fc0e5b4433so4014072edc.18 for ; Thu, 16 Mar 2023 10:37:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678988233; 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=2Jq/dgceUVfir3sp9Vj6qGReDLvlVejYLCJe11Y+qj4=; b=lbxWQ7AghgCJvbrQEf8ZHy+YRzRvUtaO8Xp8RuwsjTAOoGzG+oLe8YR74NDWz/eoUR 1x16ADZGXdMwtIGXg/I78b9XtuGaxgwGkyt/ZHhb22Rm450F4TcqnOqvjgv/uQXAApKm EbsqNv8ggmYdVqkY9digyCo74uRYcOgKNpbuz5anvXWaenGc+p8UZQEwLqJdQWpx9W6r aOf0WPJkdvrSrIFZWu+E8j5cBlh/882/5/o8uX9e3yvQPBzSf66Y9vTfep/wAN9CwPuV i8DcJvfQFZNVOQS5qdQX5FjtVqoGe/2Wg6YpebYDWLm4RVmB0yIl8gP+VmJzXyXA7Zga 1r0g== X-Gm-Message-State: AO0yUKX0Fn+Vxo5yG06Y6mXV+heaJM9KzW93RY1/anYSH1Ih8Pahc9RK efFgzfHPGOksduxcAYIDxCI3eP3hoYhSeShRY6mCuUSZP09fTwVnHPL9wFNBItMzqV1mT/RlYUl gooi29Fy87cNTFZ8Ed3vDhadz4cUdhwcnFGcmOLS3N6scFEP9WkVLYQsdHRdsb+TfGpg1BKglso HK1F30Gg== X-Received: by 2002:aa7:c7d7:0:b0:4fd:9702:2959 with SMTP id o23-20020aa7c7d7000000b004fd97022959mr27853eds.10.1678988233568; Thu, 16 Mar 2023 10:37:13 -0700 (PDT) X-Google-Smtp-Source: AK7set9N3+06RPVhH94QJH+nSbfQWeddJ8xNpulz1NFN7law8DzWtheNvHlnPMUAanhtViqmf4DgVg== X-Received: by 2002:aa7:c7d7:0:b0:4fd:9702:2959 with SMTP id o23-20020aa7c7d7000000b004fd97022959mr27837eds.10.1678988233286; Thu, 16 Mar 2023 10:37:13 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id y70-20020a50bb4c000000b004fa380a14e7sm32741ede.77.2023.03.16.10.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 10:37:12 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv5 02/11] gdbserver: allows agent_mem_read to return an error code Date: Thu, 16 Mar 2023 17:36:57 +0000 Message-Id: <0f2439cbd7b806648124aa8f979ae6f8914b4ad2.1678987897.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-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: 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 3f60989e4c7..125a384ffb3 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 060d44d0033..1f40d7b5177 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