2002-05-10 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 98c3250529c04f96a8fd806bc4cdbce3627f7911..3a4286720e1cf42508149700c08d712813372095 100644 (file)
@@ -144,11 +144,17 @@ lookup_symtab (const char *name)
   register struct partial_symtab *ps;
   register struct objfile *objfile;
   char *real_path = NULL;
+  char *full_path = NULL;
 
   /* Here we are interested in canonicalizing an absolute path, not
      absolutizing a relative path.  */
   if (IS_ABSOLUTE_PATH (name))
-    real_path = gdb_realpath (name);
+    {
+      full_path = xfullpath (name);
+      make_cleanup (xfree, full_path);
+      real_path = gdb_realpath (name);
+      make_cleanup (xfree, real_path);
+    }
 
 got_symtab:
 
@@ -158,24 +164,32 @@ got_symtab:
   {
     if (FILENAME_CMP (name, s->filename) == 0)
       {
-       xfree (real_path);
        return s;
       }
+      
     /* If the user gave us an absolute path, try to find the file in
        this symtab and use its absolute path.  */
+    
+    if (full_path != NULL)
+      {
+       const char *fp = symtab_to_filename (s);
+       if (FILENAME_CMP (full_path, fp) == 0)
+         {
+           return s;
+         }
+      }
+
     if (real_path != NULL)
       {
-       char *rp = symtab_to_filename (s);
+       char *rp = gdb_realpath (symtab_to_filename (s));
+        make_cleanup (xfree, rp);
        if (FILENAME_CMP (real_path, rp) == 0)
          {
-           xfree (real_path);
            return s;
          }
       }
   }
 
-  xfree (real_path);
-
   /* Now, search for a matching tail (only if name doesn't have any dirs) */
 
   if (lbasename (name) == name)
@@ -221,36 +235,55 @@ lookup_partial_symtab (const char *name)
 {
   register struct partial_symtab *pst;
   register struct objfile *objfile;
+  char *full_path = NULL;
   char *real_path = NULL;
 
   /* Here we are interested in canonicalizing an absolute path, not
      absolutizing a relative path.  */
   if (IS_ABSOLUTE_PATH (name))
-    real_path = gdb_realpath (name);
+    {
+      full_path = xfullpath (name);
+      make_cleanup (xfree, full_path);
+      real_path = gdb_realpath (name);
+      make_cleanup (xfree, real_path);
+    }
 
   ALL_PSYMTABS (objfile, pst)
   {
     if (FILENAME_CMP (name, pst->filename) == 0)
       {
-       xfree (real_path);
        return (pst);
       }
+
     /* If the user gave us an absolute path, try to find the file in
        this symtab and use its absolute path.  */
-    if (real_path != NULL)
+    if (full_path != NULL)
       {
        if (pst->fullname == NULL)
          source_full_path_of (pst->filename, &pst->fullname);
        if (pst->fullname != NULL
-           && FILENAME_CMP (real_path, pst->fullname) == 0)
+           && FILENAME_CMP (full_path, pst->fullname) == 0)
          {
-           xfree (real_path);
            return pst;
          }
       }
-  }
 
-  xfree (real_path);
+    if (real_path != NULL)
+      {
+        char *rp = NULL;
+       if (pst->fullname == NULL)
+         source_full_path_of (pst->filename, &pst->fullname);
+        if (pst->fullname != NULL)
+          {
+            rp = gdb_realpath (pst->fullname);
+            make_cleanup (xfree, rp);
+          }
+       if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
+         {
+           return pst;
+         }
+      }
+  }
 
   /* Now, search for a matching tail (only if name doesn't have any dirs) */
 
@@ -349,6 +382,83 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
   strcat (mangled_name, physname);
   return (mangled_name);
 }
+
+\f
+/* Initialize a symbol's mangled name.  */
+
+/* Try to initialize the demangled name for a symbol, based on the
+   language of that symbol.  If the language is set to language_auto,
+   it will attempt to find any demangling algorithm that works and
+   then set the language appropriately.  If no demangling of any kind
+   is found, the language is set back to language_unknown, so we can
+   avoid doing this work again the next time we encounter the symbol.
+   Any required space to store the name is obtained from the specified
+   obstack. */
+
+void
+symbol_init_demangled_name (struct general_symbol_info *gsymbol,
+                            struct obstack *obstack)
+{
+  char *mangled = gsymbol->name;
+  char *demangled = NULL;
+
+  if (gsymbol->language == language_unknown)
+    gsymbol->language = language_auto;
+  if (gsymbol->language == language_cplus
+      || gsymbol->language == language_auto)
+    {
+      demangled =
+        cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
+      if (demangled != NULL)
+        {
+          gsymbol->language = language_cplus;
+          gsymbol->language_specific.cplus_specific.demangled_name =
+            obsavestring (demangled, strlen (demangled), obstack);
+          xfree (demangled);
+        }
+      else
+        {
+          gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+        }
+    }
+  if (gsymbol->language == language_java)
+    {
+      demangled =
+        cplus_demangle (gsymbol->name,
+                        DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
+      if (demangled != NULL)
+        {
+          gsymbol->language = language_java;
+          gsymbol->language_specific.cplus_specific.demangled_name =
+            obsavestring (demangled, strlen (demangled), obstack);
+          xfree (demangled);
+        }
+      else
+        {
+          gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+        }
+    }
+  if (demangled == NULL
+      && (gsymbol->language == language_chill
+          || gsymbol->language == language_auto))
+    {
+      demangled =
+        chill_demangle (gsymbol->name);
+      if (demangled != NULL)
+        {
+          gsymbol->language = language_chill;
+          gsymbol->language_specific.chill_specific.demangled_name =
+            obsavestring (demangled, strlen (demangled), obstack);
+          xfree (demangled);
+        }
+      else
+        {
+          gsymbol->language_specific.chill_specific.demangled_name = NULL;
+        }
+    }
+}
+
+
 \f
 
 
@@ -3202,7 +3312,7 @@ make_symbol_completion_list (char *text, char *word)
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
 
-  for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
+  for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
     {
       if (!BLOCK_SUPERBLOCK (b))
        {
@@ -3735,7 +3845,7 @@ make_symbol_overload_list (struct symbol *fsym)
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
 
-  for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
+  for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
     {
       if (!BLOCK_SUPERBLOCK (b))
        {
This page took 0.029792 seconds and 4 git commands to generate.