Make a bunch of functions static
[deliverable/binutils-gdb.git] / gdb / cp-support.c
index 07265ef88db9f2a8291ca0055dd71bb4649e8635..90a8d2ece04f2581dedc995a1a37416458ca75d7 100644 (file)
@@ -34,9 +34,9 @@
 #include "cp-abi.h"
 #include "namespace.h"
 #include <signal.h>
-#include "common/gdb_setjmp.h"
+#include "gdbsupport/gdb_setjmp.h"
 #include "safe-ctype.h"
-#include "common/selftest.h"
+#include "gdbsupport/selftest.h"
 
 #define d_left(dc) (dc)->u.s_binary.left
 #define d_right(dc) (dc)->u.s_binary.right
@@ -155,7 +155,7 @@ inspect_type (struct demangle_parse_info *info,
     {
       sym = lookup_symbol (name, 0, VAR_DOMAIN, 0).symbol;
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &except)
+  catch (const gdb_exception &except)
     {
       return 0;
     }
@@ -190,10 +190,20 @@ inspect_type (struct demangle_parse_info *info,
          /* Get the real type of the typedef.  */
          type = check_typedef (otype);
 
-         /* If the symbol is a namespace and its type name is no different
+         /* If the symbol name is the same as the original type name,
+            don't substitute.  That would cause infinite recursion in
+            symbol lookups, as the typedef symbol is often the first
+            found symbol in the symbol table.
+
+            However, this can happen in a number of situations, such as:
+
+            If the symbol is a namespace and its type name is no different
             than the name we looked up, this symbol is not a namespace
-            alias and does not need to be substituted.  */
-         if (TYPE_CODE (otype) == TYPE_CODE_NAMESPACE
+            alias and does not need to be substituted.
+
+            If the symbol is typedef and its type name is the same
+            as the symbol's name, e.g., "typedef struct foo foo;".  */
+         if (TYPE_NAME (type) != nullptr
              && strcmp (TYPE_NAME (type), name) == 0)
            return 0;
 
@@ -228,13 +238,13 @@ inspect_type (struct demangle_parse_info *info,
            }
          /* If type_print threw an exception, there is little point
             in continuing, so just bow out gracefully.  */
-         catch (const gdb_exception_RETURN_MASK_ERROR &except)
+         catch (const gdb_exception_error &except)
            {
              return 0;
            }
 
          len = buf.size ();
-         name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
+         name = obstack_strdup (&info->obstack, buf.string ());
 
          /* Turn the result into a new tree.  Note that this
             tree will contain pointers into NAME, so NAME cannot
@@ -305,9 +315,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
 
          buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len);
          newobj.type = DEMANGLE_COMPONENT_NAME;
-         newobj.u.s_name.s
-           = (char *) obstack_copy0 (&info->obstack,
-                                     buf.c_str (), buf.size ());
+         newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.string ());
          newobj.u.s_name.len = buf.size ();
          if (inspect_type (info, &newobj, finder, data))
            {
@@ -369,9 +377,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info,
         with a DEMANGLE_COMPONENT_NAME node containing the whole
         name.  */
       ret_comp->type = DEMANGLE_COMPONENT_NAME;
-      ret_comp->u.s_name.s
-       = (char *) obstack_copy0 (&info->obstack,
-                                 buf.c_str (), buf.size ());
+      ret_comp->u.s_name.s = obstack_strdup (&info->obstack, buf.string ());
       ret_comp->u.s_name.len = buf.size ();
       inspect_type (info, ret_comp, finder, data);
     }
@@ -427,7 +433,7 @@ replace_typedefs (struct demangle_parse_info *info,
                  sym = lookup_symbol (local_name.get (), 0,
                                       VAR_DOMAIN, 0).symbol;
                }
-             catch (const gdb_exception_RETURN_MASK_ALL &except)
+             catch (const gdb_exception &except)
                {
                }
 
@@ -898,7 +904,7 @@ cp_remove_params_if_any (const char *demangled_name, bool completion_mode)
      we're completing / matching everything, avoid returning NULL
      which would make callers interpret the result as an error.  */
   if (demangled_name[0] == '\0' && completion_mode)
-    return gdb::unique_xmalloc_ptr<char> (xstrdup (""));
+    return make_unique_xstrdup ("");
 
   gdb::unique_xmalloc_ptr<char> without_params
     = cp_remove_params_1 (demangled_name, false);
@@ -979,7 +985,7 @@ cp_find_first_component_aux (const char *name, int permissive)
   /* Operator names can show up in unexpected places.  Since these can
      contain parentheses or angle brackets, they can screw up the
      recursion.  But not every string 'operator' is part of an
-     operater name: e.g. you could have a variable 'cooperator'.  So
+     operator name: e.g. you could have a variable 'cooperator'.  So
      this variable tells us whether or not we should treat the string
      'operator' as starting an operator.  */
   int operator_possible = 1;
@@ -1148,13 +1154,12 @@ overload_list_add_symbol (struct symbol *sym,
 
   /* skip any symbols that we've already considered.  */
   for (symbol *listed_sym : *overload_list)
-    if (strcmp (SYMBOL_LINKAGE_NAME (sym),
-               SYMBOL_LINKAGE_NAME (listed_sym)) == 0)
+    if (strcmp (sym->linkage_name (), listed_sym->linkage_name ()) == 0)
       return;
 
   /* Get the demangled name without parameters */
   gdb::unique_xmalloc_ptr<char> sym_name
-    = cp_remove_params (SYMBOL_NATURAL_NAME (sym));
+    = cp_remove_params (sym->natural_name ());
   if (!sym_name)
     return;
 
@@ -1463,10 +1468,10 @@ cp_lookup_rtti_type (const char *name, const struct block *block)
 
 #ifdef HAVE_WORKING_FORK
 
-/* If nonzero, attempt to catch crashes in the demangler and print
+/* If true, attempt to catch crashes in the demangler and print
    useful debugging information.  */
 
-static int catch_demangler_crashes = 1;
+static bool catch_demangler_crashes = true;
 
 /* Stack context and environment for demangler crash recovery.  */
 
@@ -1533,7 +1538,16 @@ gdb_demangle (const char *name, int options)
       ofunc = signal (SIGSEGV, gdb_demangle_signal_handler);
 #endif
 
-      crash_signal = SIGSETJMP (gdb_demangle_jmp_buf);
+      /* The signal handler may keep the signal blocked when we longjmp out
+         of it.  If we have sigprocmask, we can use it to unblock the signal
+        afterwards and we can avoid the performance overhead of saving the
+        signal mask just in case the signal gets triggered.  Otherwise, just
+        tell sigsetjmp to save the mask.  */
+#ifdef HAVE_SIGPROCMASK
+      crash_signal = SIGSETJMP (gdb_demangle_jmp_buf, 0);
+#else
+      crash_signal = SIGSETJMP (gdb_demangle_jmp_buf, 1);
+#endif
     }
 #endif
 
@@ -1553,6 +1567,14 @@ gdb_demangle (const char *name, int options)
        {
          static int error_reported = 0;
 
+#ifdef HAVE_SIGPROCMASK
+         /* If we got the signal, SIGSEGV may still be blocked; restore it.  */
+         sigset_t segv_sig_set;
+         sigemptyset (&segv_sig_set);
+         sigaddset (&segv_sig_set, SIGSEGV);
+         sigprocmask (SIG_UNBLOCK, &segv_sig_set, NULL);
+#endif
+
          if (!error_reported)
            {
              std::string short_msg
@@ -1788,7 +1810,7 @@ cp_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 namespace selftests {
 
-void
+static void
 test_cp_symbol_name_matches ()
 {
 #define CHECK_MATCH(SYMBOL, INPUT)                                     \
This page took 0.030834 seconds and 4 git commands to generate.