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 353363858C36 for ; Mon, 3 Apr 2023 13:50:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 353363858C36 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=1680529840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Tr4N+S1j+FQhzeXATzeFCv5Z8TQtLbEgyOXh2NCp8B8=; b=DMp99PSZ+a+pEDULgvRH8JQ3jElFozJQAQlFrUmsyZ+Y1q1aGUni39Q6c+PuIRvtr5JQI/ zgX8wivGOazbn1g8xFJ6jD6WldvA4+Bp0B5TW7nIrUgrVfGLlSr5bJzZ0X3fBSzRAc+00t 0wEDz8H/l+O74p5CYOPgZFHsX/Pk6Dw= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-214-TrxLjkAaN0uVvZNhfIngxw-1; Mon, 03 Apr 2023 09:50:39 -0400 X-MC-Unique: TrxLjkAaN0uVvZNhfIngxw-1 Received: by mail-qv1-f69.google.com with SMTP id h7-20020a0cd807000000b005dd254e7babso13021565qvj.14 for ; Mon, 03 Apr 2023 06:50:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680529839; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tr4N+S1j+FQhzeXATzeFCv5Z8TQtLbEgyOXh2NCp8B8=; b=cjQfqDsN8sI3Cg2odxh9gAl0d5eTvl/JVFcIdt1BdQuMk+NlZcppaUb13URNqmcNY9 tSF8UJ0VsCSDMqGqaqCKAfH/gVkDbY1dFxJ5EI0pKwo9RiI3BHr5uMJIYNCsp+R7umxa UBFveqvKzEIZn52BQqLqwtzB6QtQU1QmRq1qoFeSS0Mv9m+s7+OiO+Mo5iZaXOHBkpE1 ogzk022ZLvn8thE78kTJ24VSCAhhIah723MjzKraefDA0x6ZnP5AI6ifp+VLWd3Bb2Ey 2eZfEjG/VhDBE5lSO1NnMJRqPv6VqrdCqtV3uxgOy1s8rv8mm+/7HuW7wKLr75EFU4ig HbDA== X-Gm-Message-State: AAQBX9e5UpIdNLprC8xypShjI7JeckqA56nDKQoszfdQHFIlXVxv7IC9 FDxlkHWI2JPYcsfV1tc2Utwu0jSS48ZTmGeY+jWfSQJN8543VfJe/BK7OXC9ZLlscvzwVAsBJWx R0p0vwp5qHc6RHIXbUM6z1HyiB8nz5RyV+G45n8eKSNiPHEUHFomoTvV3LhF2zQCR+65GaRCR/t I60QqIKw== X-Received: by 2002:ac8:5910:0:b0:3e6:4efe:deb2 with SMTP id 16-20020ac85910000000b003e64efedeb2mr8418192qty.12.1680529839004; Mon, 03 Apr 2023 06:50:39 -0700 (PDT) X-Google-Smtp-Source: AKy350a19sc6vs/og62HQ33Kz8uJOJfD9h4mqCFIarR9c06OCJB7qxKQUXngOg42B7QBj4Wybq1ZMg== X-Received: by 2002:ac8:5910:0:b0:3e6:4efe:deb2 with SMTP id 16-20020ac85910000000b003e64efedeb2mr8418155qty.12.1680529838637; Mon, 03 Apr 2023 06:50:38 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id jt11-20020a05622aa00b00b003e4ec377dc4sm2532314qtb.49.2023.04.03.06.50.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 06:50:38 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: Re: [PATCHv5 02/11] gdbserver: allows agent_mem_read to return an error code In-Reply-To: <0f2439cbd7b806648124aa8f979ae6f8914b4ad2.1678987897.git.aburgess@redhat.com> References: <0f2439cbd7b806648124aa8f979ae6f8914b4ad2.1678987897.git.aburgess@redhat.com> Date: Mon, 03 Apr 2023 14:50:37 +0100 Message-ID: <87o7o5cbwy.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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: Andrew Burgess writes: > 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. I went ahead and pushed this commit. If there are any problems, please let me know, I'm happy to address any issues. Thanks, Andrew > --- > 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