summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-03-15 17:50:28 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-03-22 10:07:37 +0000
commit46fec6428ef7504be486ebd57e2509bde4382918 (patch)
tree1b5854ccb1d9b0b1ec03a0ad8c844d233b1e8e58
parent08dedd6631efefbcba63c4dbf60ef97fb615e022 (diff)
downloadbinutils-gdb-46fec6428ef7504be486ebd57e2509bde4382918.tar.gz
gdb/objc: make objc_demangle a member function of objc_language
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.
-rw-r--r--gdb/ChangeLog12
-rw-r--r--gdb/objc-lang.c139
-rw-r--r--gdb/objc-lang.h2
3 files changed, 80 insertions, 73 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8f7537e3766..f3e7f3f8c59 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,15 @@
+2021-03-22 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * 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.
+
2021-03-22 Martin Liska <mliska@suse.cz>
* arm-tdep.c (show_disassembly_style_sfunc): Replace usage of CONST_STRNEQ with startswith.
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 8e8cc053531..1d440128a3d 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 @@ public:
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 @@ public:
{ 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 != '\0' && *cp == '_')
+ 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,