From: Lancelot SIX <lsix@lancelotsix.com>
To: Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/objc: make objc_demangle a member function of objc_language
Date: Tue, 16 Mar 2021 22:47:03 +0000 [thread overview]
Message-ID: <YFE1ZyVS0/UiAuNU@Plymouth> (raw)
In-Reply-To: <20210316190204.2710358-1-andrew.burgess@embecosm.com>
Le Tue, Mar 16, 2021 at 07:02:04PM +0000, Andrew Burgess a écrit :
> Makes the objc_demangle helper function a member function of
> objc_language (by renaming it to be the demangle_symbol member
> function).
>
> I also fixed some of the obvious coding standard violations in
> obj_demangle, so the '&&' operators are now at the start of the line,
> not the end. Comparison to nullptr are now made explicit, as are
> comparisons to the null character.
>
> There should be no user visible changes after this commit.
>
> gdb/ChangeLog:
>
> * objc-lang.c (objc_demangle): Renamed to
> objc_language::demangle_symbol, and moved later in the file.
> (objc_language::sniff_from_mangled_name): Call demangle_symbol
> member function.
> (objc_language::demangle_symbol): Defined outside of class
> declaration. The definition is the old objc_demangle with NULL
> changed to nullptr, and if conditions relating to nullptr pointers
> or null character checks made explicit.
> * objc-lang.h (objc_demangle): Delete declaration.
> ---
> gdb/ChangeLog | 12 +++++
> gdb/objc-lang.c | 139 +++++++++++++++++++++++-------------------------
> gdb/objc-lang.h | 2 -
> 3 files changed, 80 insertions(+), 73 deletions(-)
>
> diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
> index 8e8cc053531..7e53124e4be 100644
> --- a/gdb/objc-lang.c
> +++ b/gdb/objc-lang.c
> @@ -216,72 +216,6 @@ value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len)
> return nsstringValue;
> }
>
> -/* Objective-C name demangling. */
> -
> -char *
> -objc_demangle (const char *mangled, int options)
> -{
> - char *demangled, *cp;
> -
> - if (mangled[0] == '_' &&
> - (mangled[1] == 'i' || mangled[1] == 'c') &&
> - mangled[2] == '_')
> - {
> - cp = demangled = (char *) xmalloc (strlen (mangled) + 2);
> -
> - if (mangled[1] == 'i')
> - *cp++ = '-'; /* for instance method */
> - else
> - *cp++ = '+'; /* for class method */
> -
> - *cp++ = '['; /* opening left brace */
> - strcpy(cp, mangled+3); /* Tack on the rest of the mangled name. */
> -
> - while (*cp && *cp == '_')
> - cp++; /* Skip any initial underbars in class
> - name. */
> -
> - cp = strchr(cp, '_');
> - if (!cp) /* Find first non-initial underbar. */
> - {
> - xfree(demangled); /* not mangled name */
> - return NULL;
> - }
> - if (cp[1] == '_') /* Easy case: no category name. */
> - {
> - *cp++ = ' '; /* Replace two '_' with one ' '. */
> - strcpy(cp, mangled + (cp - demangled) + 2);
> - }
> - else
> - {
> - *cp++ = '('; /* Less easy case: category name. */
> - cp = strchr(cp, '_');
> - if (!cp)
> - {
> - xfree(demangled); /* not mangled name */
> - return NULL;
> - }
> - *cp++ = ')';
> - *cp++ = ' '; /* Overwriting 1st char of method name... */
> - strcpy(cp, mangled + (cp - demangled)); /* Get it back. */
> - }
> -
> - while (*cp && *cp == '_')
> - cp++; /* Skip any initial underbars in
> - method name. */
> -
> - for (; *cp; cp++)
> - if (*cp == '_')
> - *cp = ':'; /* Replace remaining '_' with ':'. */
> -
> - *cp++ = ']'; /* closing right brace */
> - *cp++ = 0; /* string terminator */
> - return demangled;
> - }
> - else
> - return NULL; /* Not an objc mangled name. */
> -}
> -
> /* Class representing the Objective-C language. */
>
> class objc_language : public language_defn
> @@ -320,16 +254,13 @@ class objc_language : public language_defn
> bool sniff_from_mangled_name (const char *mangled,
> char **demangled) const override
> {
> - *demangled = objc_demangle (mangled, 0);
> + *demangled = demangle_symbol (mangled, 0);
> return *demangled != NULL;
> }
>
> /* See language.h. */
>
> - char *demangle_symbol (const char *mangled, int options) const override
> - {
> - return objc_demangle (mangled, options);
> - }
> + char *demangle_symbol (const char *mangled, int options) const override;
>
> /* See language.h. */
>
> @@ -385,6 +316,72 @@ class objc_language : public language_defn
> { return macro_expansion_c; }
> };
>
> +/* See declaration of objc_language::demangle_symbol above. */
> +
> +char *
> +objc_language::demangle_symbol (const char *mangled, int options) const
> +{
> + char *demangled, *cp;
> +
> + if (mangled[0] == '_'
> + && (mangled[1] == 'i' || mangled[1] == 'c')
> + && mangled[2] == '_')
> + {
> + cp = demangled = (char *) xmalloc (strlen (mangled) + 2);
> +
> + if (mangled[1] == 'i')
> + *cp++ = '-'; /* for instance method */
> + else
> + *cp++ = '+'; /* for class method */
> +
> + *cp++ = '['; /* opening left brace */
> + strcpy(cp, mangled+3); /* Tack on the rest of the mangled name. */
> +
> + while (*cp && *cp == '_')
Hi,
You forgot one explicit comparison to null char here.
Lancelot.
> + cp++; /* Skip any initial underbars in class
> + name. */
> +
> + cp = strchr(cp, '_');
> + if (cp == nullptr) /* Find first non-initial underbar. */
> + {
> + xfree(demangled); /* not mangled name */
> + return nullptr;
> + }
> + if (cp[1] == '_') /* Easy case: no category name. */
> + {
> + *cp++ = ' '; /* Replace two '_' with one ' '. */
> + strcpy(cp, mangled + (cp - demangled) + 2);
> + }
> + else
> + {
> + *cp++ = '('; /* Less easy case: category name. */
> + cp = strchr(cp, '_');
> + if (cp == nullptr)
> + {
> + xfree(demangled); /* not mangled name */
> + return nullptr;
> + }
> + *cp++ = ')';
> + *cp++ = ' '; /* Overwriting 1st char of method name... */
> + strcpy(cp, mangled + (cp - demangled)); /* Get it back. */
> + }
> +
> + while (*cp != '\0' && *cp == '_')
> + cp++; /* Skip any initial underbars in
> + method name. */
> +
> + for (; *cp != '\0'; cp++)
> + if (*cp == '_')
> + *cp = ':'; /* Replace remaining '_' with ':'. */
> +
> + *cp++ = ']'; /* closing right brace */
> + *cp++ = 0; /* string terminator */
> + return demangled;
> + }
> + else
> + return nullptr; /* Not an objc mangled name. */
> +}
> +
> /* Single instance of the class representing the Objective-C language. */
>
> static objc_language objc_language_defn;
> diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
> index f58335e62cd..9d3e26d18a0 100644
> --- a/gdb/objc-lang.h
> +++ b/gdb/objc-lang.h
> @@ -31,8 +31,6 @@ extern CORE_ADDR lookup_objc_class (struct gdbarch *gdbarch,
> extern CORE_ADDR lookup_child_selector (struct gdbarch *gdbarch,
> const char *methodname);
>
> -extern char *objc_demangle (const char *mangled, int options);
> -
> extern int find_objc_msgcall (CORE_ADDR pc, CORE_ADDR *new_pc);
>
> extern const char *find_imps (const char *method,
> --
> 2.25.4
>
--
Lancelot SIX
next prev parent reply other threads:[~2021-03-16 22:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 19:02 Andrew Burgess
2021-03-16 22:47 ` Lancelot SIX [this message]
2021-03-22 11:36 ` Andrew Burgess
2021-03-19 17:57 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YFE1ZyVS0/UiAuNU@Plymouth \
--to=lsix@lancelotsix.com \
--cc=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).