From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 486B6386F837 for ; Mon, 15 Jun 2020 12:38:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 486B6386F837 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-44-N_pYY_udO0a0e5OekRXlOA-1; Mon, 15 Jun 2020 08:37:57 -0400 X-MC-Unique: N_pYY_udO0a0e5OekRXlOA-1 Received: by mail-wm1-f71.google.com with SMTP id b63so6003771wme.1 for ; Mon, 15 Jun 2020 05:37:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kxegk/LueFcP3Bqg0EPNnp05TidtO3psPhuztBhnemU=; b=J3rsAzxzQyG84lBcDgBJd4PIFqQAVqVcC9CypdJiDxRYBJkjDrK+H3EWxOrSUcSjYj ygP6bC9hCF5Q+IVqyaJslhm5HImJfd6hBkJ5U1EwhmbMq9mpMQD1lIy1HNDrGTFKiGik YgRYuEs4i23LTEwbyIV3wr/dTSNXEw7lqsEHKwnK7iLCMHUtnIdYDyxLoPdX8KQB452a DAZ2Ai3/pXU1B7RyF+2yRHwB1aVN9gV2Rqv0P3LLsQ6hoTMLyzQqOcOoQRxckmVqpJKx s5VI8N9C/fan996j/E2gZv3OTRUwr5DlFdEgwHet8ynvN5b3PQPVoGBr8R9uSOBbwWCw /GWg== X-Gm-Message-State: AOAM533We9CPYTKGwttMbj6U11x4JYGlFjZHpm1yxRtnM+zQhN9YRwpr AQrNm4ZD0SWD2x8caOm9WIRDgrNuEJy5OSDWkI+tnUZ6034KhjsvEyRm1NNBCv3ZQa+RlB2yKg0 uG00ty9tolVUwKX2QkjWb1w== X-Received: by 2002:a5d:4ec3:: with SMTP id s3mr30635865wrv.103.1592224676148; Mon, 15 Jun 2020 05:37:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzW9qcCWD2JIJuqsEYy0yLz+3pXd1cdIJvi4+Sb14VKDadINv2P1/856RnEDsYrAik45cG7QQ== X-Received: by 2002:a5d:4ec3:: with SMTP id s3mr30635839wrv.103.1592224675833; Mon, 15 Jun 2020 05:37:55 -0700 (PDT) Received: from ?IPv6:2001:8a0:f922:c400:56ee:75ff:fe8d:232b? ([2001:8a0:f922:c400:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id g19sm21656116wmh.29.2020.06.15.05.37.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jun 2020 05:37:54 -0700 (PDT) Subject: Re: [PATCH 1/4] Remove read_memory_string To: Tom Tromey , gdb-patches@sourceware.org References: <20200612215356.22145-1-tromey@adacore.com> <20200612215356.22145-2-tromey@adacore.com> From: Pedro Alves Message-ID: <59ad6b57-770d-3c58-9084-d08accce306f@redhat.com> Date: Mon, 15 Jun 2020 13:37:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20200612215356.22145-2-tromey@adacore.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.6 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Mon, 15 Jun 2020 12:38:01 -0000 On 6/12/20 10:53 PM, Tom Tromey wrote: > read_memory_string is redundant and only called in a couple of spots. > This patch removes it in favor of target_read_string. > There's a difference of behavior that is getting lost here -- read_memory_string throws an error on memory read failure, while target_read_string does not. Similarly to how we have read_memory throwing, vs target_read_memory not throwing. It would make sense to me to reimplement read_memory_string on top of target_read_string and throw on error, for instance. Did you go over the call paths, to check whether the behavior change is desirable? Thanks, Pedro Alves > gdb/ChangeLog > 2020-06-02 Tom Tromey > > * corefile.c (read_memory_string): Remove. > * ada-valprint.c (ada_value_print_ptr): Update. > * ada-lang.h (ada_tag_name): Change return type. > * ada-lang.c (type_from_tag): Update. > (ada_tag_name_from_tsd): Change return type. Use > target_read_string. > (ada_tag_name): Likewise. > * gdbcore.h (read_memory_string): Don't declare. > --- > gdb/ChangeLog | 11 +++++++++++ > gdb/ada-lang.c | 34 ++++++++++++++++++++-------------- > gdb/ada-lang.h | 2 +- > gdb/ada-valprint.c | 4 ++-- > gdb/corefile.c | 27 --------------------------- > gdb/gdbcore.h | 6 ------ > 6 files changed, 34 insertions(+), 50 deletions(-) > > diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c > index f7b973f36ee..3245758a1bd 100644 > --- a/gdb/ada-lang.c > +++ b/gdb/ada-lang.c > @@ -6567,10 +6567,10 @@ value_tag_from_contents_and_address (struct type *type, > static struct type * > type_from_tag (struct value *tag) > { > - const char *type_name = ada_tag_name (tag); > + gdb::unique_xmalloc_ptr type_name = ada_tag_name (tag); > > if (type_name != NULL) > - return ada_find_any_type (ada_encode (type_name)); > + return ada_find_any_type (ada_encode (type_name.get ())); > return NULL; > } > > @@ -6721,34 +6721,38 @@ ada_get_tsd_from_tag (struct value *tag) > The returned value is good until the next call. May return NULL > if we are unable to determine the tag name. */ > > -static char * > +static gdb::unique_xmalloc_ptr > ada_tag_name_from_tsd (struct value *tsd) > { > - static char name[1024]; > char *p; > struct value *val; > > val = ada_value_struct_elt (tsd, "expanded_name", 1); > if (val == NULL) > return NULL; > - read_memory_string (value_as_address (val), name, sizeof (name) - 1); > - for (p = name; *p != '\0'; p += 1) > + gdb::unique_xmalloc_ptr buffer; > + int err; > + if (target_read_string (value_as_address (val), &buffer, INT_MAX, &err) == 0 > + || err != 0) > + return nullptr; > + > + for (p = (char *) buffer.get (); *p != '\0'; p += 1) > if (isalpha (*p)) > *p = tolower (*p); > - return name; > + > + return buffer; > } > > /* The type name of the dynamic type denoted by the 'tag value TAG, as > a C string. > > Return NULL if the TAG is not an Ada tag, or if we were unable to > - determine the name of that tag. The result is good until the next > - call. */ > + determine the name of that tag. */ > > -const char * > +gdb::unique_xmalloc_ptr > ada_tag_name (struct value *tag) > { > - char *name = NULL; > + gdb::unique_xmalloc_ptr name; > > if (!ada_is_tag_type (value_type (tag))) > return NULL; > @@ -12104,9 +12108,11 @@ ada_exception_message_1 (void) > if (e_msg_len <= 0) > return NULL; > > - gdb::unique_xmalloc_ptr e_msg ((char *) xmalloc (e_msg_len + 1)); > - read_memory_string (value_address (e_msg_val), e_msg.get (), e_msg_len + 1); > - e_msg.get ()[e_msg_len] = '\0'; > + gdb::unique_xmalloc_ptr e_msg; > + int err; > + if (target_read_string (value_address (e_msg_val), &e_msg, INT_MAX, &err) == 0 > + || err != 0) > + return nullptr; > > return e_msg; > } > diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h > index 5ba00518e6d..9be597942fd 100644 > --- a/gdb/ada-lang.h > +++ b/gdb/ada-lang.h > @@ -260,7 +260,7 @@ extern int ada_is_tagged_type (struct type *, int); > > extern int ada_is_tag_type (struct type *); > > -extern const char *ada_tag_name (struct value *); > +extern gdb::unique_xmalloc_ptr ada_tag_name (struct value *); > > extern struct value *ada_tag_value_at_base_address (struct value *obj); > > diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c > index a36e7ca793a..61893d5cad3 100644 > --- a/gdb/ada-valprint.c > +++ b/gdb/ada-valprint.c > @@ -754,10 +754,10 @@ ada_value_print_ptr (struct value *val, > struct type *type = ada_check_typedef (value_type (val)); > if (ada_is_tag_type (type)) > { > - const char *name = ada_tag_name (val); > + gdb::unique_xmalloc_ptr name = ada_tag_name (val); > > if (name != NULL) > - fprintf_filtered (stream, " (%s)", name); > + fprintf_filtered (stream, " (%s)", name.get ()); > } > } > > diff --git a/gdb/corefile.c b/gdb/corefile.c > index 996e5301b27..fed0e4fe8ad 100644 > --- a/gdb/corefile.c > +++ b/gdb/corefile.c > @@ -328,33 +328,6 @@ read_code_unsigned_integer (CORE_ADDR memaddr, int len, > return extract_unsigned_integer (buf, len, byte_order); > } > > -void > -read_memory_string (CORE_ADDR memaddr, char *buffer, int max_len) > -{ > - char *cp; > - int i; > - int cnt; > - > - cp = buffer; > - while (1) > - { > - if (cp - buffer >= max_len) > - { > - buffer[max_len - 1] = '\0'; > - break; > - } > - cnt = max_len - (cp - buffer); > - if (cnt > 8) > - cnt = 8; > - read_memory (memaddr + (int) (cp - buffer), (gdb_byte *) cp, cnt); > - for (i = 0; i < cnt && *cp; i++, cp++) > - ; /* null body */ > - > - if (i < cnt && !*cp) > - break; > - } > -} > - > CORE_ADDR > read_memory_typed_address (CORE_ADDR addr, struct type *type) > { > diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h > index 24db21e462c..58566d58785 100644 > --- a/gdb/gdbcore.h > +++ b/gdb/gdbcore.h > @@ -87,12 +87,6 @@ extern ULONGEST read_code_unsigned_integer (CORE_ADDR memaddr, > int len, > enum bfd_endian byte_order); > > -/* Read a null-terminated string from the debuggee's memory, given > - address, a buffer into which to place the string, and the maximum > - available space. */ > - > -extern void read_memory_string (CORE_ADDR, char *, int); > - > /* Read the pointer of type TYPE at ADDR, and return the address it > represents. */ > >