From 365f58fa9f9075c932cbb4fabaff29a7075dcbb3 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Wed, 8 Feb 2017 11:54:55 -0800 Subject: [PATCH] Cleanups from precursor patch submissions. --- gdb/compile/compile-cplus-symbols.c | 1 - gdb/cp-support.c | 102 ++-------------------------- gdb/dwarf2read.c | 6 +- gdb/linespec.c | 95 -------------------------- gdb/linespec.h | 19 ------ gdb/utils.c | 92 +++++++++++++++++++++++++ gdb/utils.h | 18 +++++ 7 files changed, 117 insertions(+), 216 deletions(-) diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c index 61d672515d7..cbd4cdaa14e 100644 --- a/gdb/compile/compile-cplus-symbols.c +++ b/gdb/compile/compile-cplus-symbols.c @@ -111,7 +111,6 @@ convert_one_symbol (compile_cplus_instance *instance, addr = gnu_ifunc_resolve_addr (target_gdbarch (), addr); special_name = NULL; - //cp_find_method_field (sym.symbol, 1); func_name = maybe_canonicalize_special_function (SYMBOL_LINKAGE_NAME (sym.symbol), NULL, SYMBOL_TYPE (sym.symbol), &special_name, &ignore); diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 926308ecde2..cbd3c550688 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -36,7 +36,6 @@ #include #include "gdb_setjmp.h" #include "safe-ctype.h" -#include "linespec.h" /* for find_toplevel_char_r */ /* Functions related to demangled name parsing. */ @@ -831,99 +830,9 @@ cp_func_name (const char *full_name) char * cp_strip_template_parameters (const char *linkage_or_phys_name) { - /* This is by far the best way to do this, but there is one really big - problem... The code below resets the the top-level node to below the - (first) DEMANGLE_COMPONENT_TEMPLATE node in the tree. - - Normally that works, however, there is a special case (of course!) - where this fails: conversion operators. Those *require* the template - parameter to deduce the name of the operator. As a result, the code - below will not work on conversion operators at all (and maybe others). */ -#if 0 - struct demangle_component *ret_comp; - struct demangle_parse_info *info; - void *storage = NULL; - char *ret, *str = NULL, *demangled_name = NULL; - - info = cp_mangled_name_to_comp (linkage_or_phys_name, DMGL_ANSI, - &storage, &demangled_name); - - if (info == NULL) - { - info = cp_demangled_name_to_comp (linkage_or_phys_name, NULL); - if (info == NULL) - { - char *p; - - /* Special case: cp_demangled_name_to_comp doesn't like - template specializations, templatename<>. Adjust for that - here until libiberty is fixed. */ - str = xstrdup (linkage_or_phys_name); - p = strstr (str, "<>"); - if (p == NULL) - return NULL; - - *p = '\0'; - info = cp_demangled_name_to_comp (str, NULL); - if (info == NULL) - { - xfree (str); - return NULL; - } - } - } - - ret_comp = info->tree; - ret = NULL; - if (ret_comp != NULL) - { - int done = 0; - - while (!done) - { - switch (ret_comp->type) - { - case DEMANGLE_COMPONENT_QUAL_NAME: - case DEMANGLE_COMPONENT_LOCAL_NAME: - ret_comp = d_right (ret_comp); - break; - case DEMANGLE_COMPONENT_TYPED_NAME: - case DEMANGLE_COMPONENT_CONST: - case DEMANGLE_COMPONENT_RESTRICT: - case DEMANGLE_COMPONENT_VOLATILE: - case DEMANGLE_COMPONENT_CONST_THIS: - case DEMANGLE_COMPONENT_RESTRICT_THIS: - case DEMANGLE_COMPONENT_VOLATILE_THIS: - case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: - ret_comp = d_left (ret_comp); - break; - case DEMANGLE_COMPONENT_TEMPLATE: - ret_comp = d_left (ret_comp); - if (ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME - && d_right (ret_comp)->type == DEMANGLE_COMPONENT_CONVERSION) - { - /* Remove the template parameter, replacing this - node with a NAME node. */ - /* !!keiths: Can't be done without modifications to - libiberty *or* reimplementing the entire libiberty - printer (d_print_comp_inner). */ - /* !!keiths: Is there any other option??? */ - } - /* fall through */ - default: - done = 1; - break; - } - } - } - - ret = cp_comp_to_string (ret_comp, 10); - cp_demangled_name_parse_free (info); - xfree (storage); - xfree (demangled_name); - xfree (str); - return ret; -#else + /* We do not turn the linkage name into demangle components since we cannot + walk the tree in any usable way when dealing with conversion operators. + Instead we use a heuristic approach that works for all cases. */ char *stripped = NULL; const char *name; @@ -934,8 +843,7 @@ cp_strip_template_parameters (const char *linkage_or_phys_name) name = linkage_or_phys_name; /* Only attempt to strip this if it looks like a template. */ - if (strchr (name, '<') != NULL - && strchr (name, '>') != NULL) + if (strchr (name, '<') != NULL && strchr (name, '>') != NULL) { const char *p; size_t len = strlen (name) - 1; @@ -957,9 +865,7 @@ cp_strip_template_parameters (const char *linkage_or_phys_name) } xfree (demangled_name); - //printf ("stripped = \"%s\"\n", stripped); return stripped; -#endif } /* DEMANGLED_NAME is the name of a function, including parameters and diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a3b75c3a345..9f8ef405ec0 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -11704,8 +11704,6 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) /* Attach template arguments to function. */ if (! VEC_empty (symbolp, template_args)) { - const char *linkage_name; - gdb_assert (templ_func != NULL); templ_func->template_arguments @@ -11737,7 +11735,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) /* Determine whether the template's return and argument types were specified using template parameters. */ - linkage_name = dw2_linkage_name (die, cu); + const char *linkage_name = dw2_linkage_name (die, cu); templ_func->linkage_name = linkage_name; if (linkage_name != NULL) { @@ -12938,9 +12936,11 @@ dwarf2_add_type_defn (struct field_info *fip, struct die_info *die, accessibility = dwarf2_default_access_attribute (die, cu); switch (accessibility) { +#if 1 case DW_ACCESS_public: fp->is_public = 1; break; +#endif case DW_ACCESS_private: fp->is_private = 1; break; diff --git a/gdb/linespec.c b/gdb/linespec.c index ef6dc5a6c38..5031c6a63f0 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1132,101 +1132,6 @@ find_methods (struct type *t, const char *name, VEC_safe_push (typep, *superclasses, TYPE_BASECLASS (t, ibase)); } -/* Find an instance of the character C in the string S that is outside - of all parenthesis pairs, single-quoted strings, and double-quoted - strings. Also, ignore the char within a template name, like a ',' - within foo. */ - -const char * -find_toplevel_char (const char *s, char c) -{ - int quoted = 0; /* zero if we're not in quotes; - '"' if we're in a double-quoted string; - '\'' if we're in a single-quoted string. */ - int depth = 0; /* Number of unclosed parens we've seen. */ - const char *scan; - - for (scan = s; *scan; scan++) - { - if (quoted) - { - if (*scan == quoted) - quoted = 0; - else if (*scan == '\\' && *(scan + 1)) - scan++; - } - else if (*scan == c && ! quoted && depth == 0) - return scan; - else if (*scan == '"' || *scan == '\'') - quoted = *scan; - else if (*scan == '(' || *scan == '<') - depth++; - else if ((*scan == ')' || *scan == '>') && depth > 0) - depth--; - } - - return 0; -} - -/* See description in linespec.h. */ - -const char * -find_toplevel_char_r (const char *s, size_t len, char c) -{ - int quoted = 0; - int depth = 0; - const char *scan; - - for (scan = s + len; scan >= s; --scan) - { - if (quoted) - { - if (*scan == quoted) - quoted = 0; - } - else if (*scan == ')' || *scan == '>') - ++depth; - else if ((*scan == '(' || *scan == '<') && depth > 0) - --depth; - - if (*scan == c && !quoted && depth == 0) - return scan; - else if ((*scan == '"' || *scan == '\'') - && scan > s && *(scan - 1) != '\\') - quoted = *scan; - } - - return NULL; -} - -/* See linespec.h. */ - -const char * -find_toplevel_string (const char *haystack, const char *needle) -{ - const char *s = haystack; - - do - { - s = find_toplevel_char (s, *needle); - - if (s != NULL) - { - /* Found first char in HAYSTACK; check rest of string. */ - if (startswith (s, needle)) - return s; - - /* Didn't find it; loop over HAYSTACK, looking for the next - instance of the first character of NEEDLE. */ - ++s; - } - } - while (s != NULL && *s != '\0'); - - /* NEEDLE was not found in HAYSTACK. */ - return NULL; -} - /* Convert CANONICAL to its string representation using symtab_to_fullname for SYMTAB. The caller must xfree the result. */ diff --git a/gdb/linespec.h b/gdb/linespec.h index 4c58356c4fa..f4923a752e3 100644 --- a/gdb/linespec.h +++ b/gdb/linespec.h @@ -175,25 +175,6 @@ extern const char *get_gdb_linespec_parser_quote_characters (void); extern int is_ada_operator (const char *string); -/* Find an instance of the character C in the string S that is outside - of all parenthesis pairs, single-quoted strings, and double-quoted - strings. Also, ignore the char within a template name, like a ',' - within foo. */ - -extern const char *find_toplevel_char (const char *s, char c); - -/* Like find_toplevel_char but searches S backwards, starting LEN characters - into S. */ - -extern const char *find_toplevel_char_r (const char *s, size_t len, char c); - -/* The string equivalent of find_toplevel_char. Returns a pointer - to the location of NEEDLE in HAYSTACK, ignoring any occurrences - inside "()" and "<>". Returns NULL if NEEDLE was not found. */ - -const char *find_toplevel_string (const char *haystack, - const char *needle); - /* Find the end of the (first) linespec pointed to by *STRINGP. STRINGP will be advanced to this point. */ diff --git a/gdb/utils.c b/gdb/utils.c index ab87143c755..8f4ca63a9f2 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3422,6 +3422,98 @@ strip_leading_path_elements (const char *path, int n) return p; } +/* See description in utils.h. */ + +const char * +find_toplevel_char (const char *s, char c) +{ + int quoted = 0; /* zero if we're not in quotes; + '"' if we're in a double-quoted string; + '\'' if we're in a single-quoted string. */ + int depth = 0; /* Number of unclosed parens we've seen. */ + const char *scan; + + for (scan = s; *scan; scan++) + { + if (quoted) + { + if (*scan == quoted) + quoted = 0; + else if (*scan == '\\' && *(scan + 1)) + scan++; + } + else if (*scan == c && ! quoted && depth == 0) + return scan; + else if (*scan == '"' || *scan == '\'') + quoted = *scan; + else if (*scan == '(' || *scan == '<') + depth++; + else if ((*scan == ')' || *scan == '>') && depth > 0) + depth--; + } + + return 0; +} + +/* See description in utils.h. */ + +const char * +find_toplevel_char_r (const char *s, size_t len, char c) +{ + int quoted = 0; + int depth = 0; + const char *scan; + + for (scan = s + len; scan >= s; --scan) + { + if (quoted) + { + if (*scan == quoted) + quoted = 0; + } + else if (*scan == ')' || *scan == '>') + ++depth; + else if ((*scan == '(' || *scan == '<') && depth > 0) + --depth; + + if (*scan == c && !quoted && depth == 0) + return scan; + else if ((*scan == '"' || *scan == '\'') + && scan > s && *(scan - 1) != '\\') + quoted = *scan; + } + + return NULL; +} + +/* See description in utils.h. */ + +const char * +find_toplevel_string (const char *haystack, const char *needle) +{ + const char *s = haystack; + + do + { + s = find_toplevel_char (s, *needle); + + if (s != NULL) + { + /* Found first char in HAYSTACK; check rest of string. */ + if (startswith (s, needle)) + return s; + + /* Didn't find it; loop over HAYSTACK, looking for the next + instance of the first character of NEEDLE. */ + ++s; + } + } + while (s != NULL && *s != '\0'); + + /* NEEDLE was not found in HAYSTACK. */ + return NULL; +} + /* Provide a prototype to silence -Wmissing-prototypes. */ extern initialize_file_ftype _initialize_utils; diff --git a/gdb/utils.h b/gdb/utils.h index 9e71cc2792c..d5875056111 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -393,4 +393,22 @@ extern void dump_core (void); extern char *make_hex_string (const gdb_byte *data, size_t length); +/* Find an instance of the character C in the string S that is outside + of all parenthesis pairs, single-quoted strings, and double-quoted + strings. Also, ignore the char within a template name, like a ',' + within foo. */ + +extern const char *find_toplevel_char (const char *s, char c); + +/* Like find_toplevel_char but searches S backwards, starting LEN characters + into S. */ + +extern const char *find_toplevel_char_r (const char *s, size_t len, char c); + +/* The string equivalent of find_toplevel_char. Returns a pointer + to the location of NEEDLE in HAYSTACK, ignoring any occurrences + inside "()" and "<>". Returns NULL if NEEDLE was not found. */ + +const char *find_toplevel_string (const char *haystack, const char *needle); + #endif /* UTILS_H */ -- 2.47.2