From patchwork Fri Apr 19 22:45:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 32347 Received: (qmail 24015 invoked by alias); 19 Apr 2019 22:45:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 23951 invoked by uid 89); 19 Apr 2019 22:45:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:2259, HX-Gm-Message-State:APjAAAVZ X-HELO: mail-wm1-f66.google.com Received: from mail-wm1-f66.google.com (HELO mail-wm1-f66.google.com) (209.85.128.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Apr 2019 22:45:18 +0000 Received: by mail-wm1-f66.google.com with SMTP id o25so7526993wmf.5 for ; Fri, 19 Apr 2019 15:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+3nnMGOaPyNCPT9RiNCS8hWB0j5TkEYz7JNMW4qBa1U=; b=Lx7cI14t6MHr8EIanjE+Qd6lxIjDvzZ+bR2sGjkRCXn0WSqBduCh7ANzMT2OvxQgmY 1NwM5a7TPfMI7naOHEdAZashIGASms5yAUE6H4SDPpPoaeY94Fd+CKyLc2Qs3JztfNvu n4z6/BUObgFgAtyWwpdI5JXb4sGC2CRsSRbuNoJcrXfDNZoXZewXdUcuD79DrfGmasnd hrrIu/b5s340aRJUl6TNRNujMJUKIqpSfn6TXLc38SSOARmo1nfKujYlgvqhrZd1UrLC 2aevzORqQ27nO5avZdIFzA6wWt2Z/wCpeDHiQeN18IjCiTjbk3b74qHh3Re62+IzMt77 Q8AQ== Return-Path: Received: from localhost (host109-148-134-137.range109-148.btcentralplus.com. [109.148.134.137]) by smtp.gmail.com with ESMTPSA id x12sm3796969wrl.34.2019.04.19.15.45.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2019 15:45:15 -0700 (PDT) Date: Fri, 19 Apr 2019 23:45:14 +0100 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCHv2 4/5] gdb: Introduce new language field la_is_string_type_p Message-ID: <20190419224514.GX2737@embecosm.com> References: <878sw6dpg0.fsf@tromey.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <878sw6dpg0.fsf@tromey.com> X-Fortune: Torque is cheap. X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes * Tom Tromey [2019-04-19 08:45:03 -0600]: > >>>>> "Andrew" == Andrew Burgess writes: > > Andrew> Some languages already have a "is this a string" predicate that I was > Andrew> able to reuse, while for other languages I've had to add a new > Andrew> predicate. In this case I took inspiration from the value printing > Andrew> code for that language - what different conditions would result in > Andrew> printing something as a string. > > This looks essentially fine, but I had some questions. > > Andrew> +bool > Andrew> +c_is_string_type_p (struct type *type) > Andrew> +{ > Andrew> + type = check_typedef (type); > Andrew> + while (TYPE_CODE (type) == TYPE_CODE_REF) > Andrew> + { > Andrew> + type = TYPE_TARGET_TYPE (type); > Andrew> + type = check_typedef (type); > Andrew> + } > Andrew> + > Andrew> + switch (TYPE_CODE (type)) > Andrew> + { > Andrew> + case TYPE_CODE_ARRAY: > Andrew> + { > Andrew> + /* See if target type looks like a string. */ > Andrew> + struct type *array_target_type = TYPE_TARGET_TYPE (type); > Andrew> + return (TYPE_LENGTH (type) > 0 > Andrew> + && TYPE_LENGTH (array_target_type) > 0 > Andrew> + && c_textual_element_type (array_target_type, 0)); > Andrew> + } > Andrew> + case TYPE_CODE_STRING: > Andrew> + return true; > > It seems to me that a "char *" should be considered a string in C; > and probably a "wchar_t *" as well. Maybe see c-lang.c:classify_type. Do you think that this applied on top of the previous would catch all of the pointer cases? I don't think we need to call classify_type as that seems to assume that by the time it's called we know we have a character type of some description, so I think calling c_textual_element_type is enough... Let me know if you think I've missed something, thanks, Andrew diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 4d5284e2e80..aeffefad55e 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -739,6 +739,11 @@ c_is_string_type_p (struct type *type) } case TYPE_CODE_STRING: return true; + case TYPE_CODE_PTR: + { + struct type *element_type = TYPE_TARGET_TYPE (type); + return c_textual_element_type (element_type, 0); + } default: break; }