This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch: search `directory' path for `break' files


>>>>> "Elena" == Elena Zannoni <ezannoni@cygnus.com> writes:

Elena> No, no need to do the psymtabs now. I would like to get rid of
Elena> code duplication with gdbtk, if possible, first, though.

Sorry for the long delay on this.  I rarely have any time to work on
my gdb patches.

I looked at the full_lookup_symtab function.  I think with my patch it
is redundant.  However, it is hard to be 100% sure.  Simple tests of
Insight on my machine work, but since I'm running Linux, which has
realpath(), this may not be the best test.

I've appended the full patch.  I'd appreciate any comments from
Insight hackers.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* configure, config.in: Rebuilt.
	* configure.in: Check for realpath.
	* defs.h (gdb_realpath): Declare.
	* symtab.h (partial_symtab): Added fullname field.
	* source.c (openp): Use gdb_realpath.
	(forget_cached_source_info): Clear full name of each partial
	symtab.
	* utils.c (gdb_realpath): New function.
	* symtab.c (lookup_symtab): Removed.
	(lookup_symtab_1): Renamed to lookup_symtab.
	(lookup_symtab): Look for real path.
	(lookup_partial_symtab): Likewise.

Index: config.in
===================================================================
RCS file: /cvs/src/src/gdb/config.in,v
retrieving revision 1.30
diff -u -r1.30 config.in
--- config.in 2001/08/27 22:39:55 1.30
+++ config.in 2001/11/07 04:53:26
@@ -220,6 +220,9 @@
 /* Define if you have the putenv function.  */
 #undef HAVE_PUTENV
 
+/* Define if you have the realpath function.  */
+#undef HAVE_REALPATH
+
 /* Define if you have the sbrk function.  */
 #undef HAVE_SBRK
 
Index: configure
===================================================================
RCS file: /cvs/src/src/gdb/configure,v
retrieving revision 1.72
diff -u -r1.72 configure
--- configure 2001/11/05 23:54:49 1.72
+++ configure 2001/11/07 04:53:31
@@ -3582,7 +3582,7 @@
 fi
 
 
-for ac_func in bcopy btowc bzero isascii poll sbrk setpgid setpgrp \
+for ac_func in bcopy btowc bzero isascii poll realpath sbrk setpgid setpgrp \
 	sigaction sigprocmask sigsetmask
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/configure.in,v
retrieving revision 1.74
diff -u -r1.74 configure.in
--- configure.in 2001/11/05 23:54:49 1.74
+++ configure.in 2001/11/07 04:53:32
@@ -131,7 +131,7 @@
 
 AC_C_CONST
 
-AC_CHECK_FUNCS(bcopy btowc bzero isascii poll sbrk setpgid setpgrp \
+AC_CHECK_FUNCS(bcopy btowc bzero isascii poll realpath sbrk setpgid setpgrp \
 	sigaction sigprocmask sigsetmask)
 AC_FUNC_ALLOCA
 AC_FUNC_VFORK
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.64
diff -u -r1.64 defs.h
--- defs.h 2001/10/17 20:35:31 1.64
+++ defs.h 2001/11/07 04:53:33
@@ -579,6 +579,8 @@
 extern CORE_ADDR host_pointer_to_address (void *ptr);
 extern void *address_to_host_pointer (CORE_ADDR addr);
 
+extern char *gdb_realpath (const char *);
+
 /* From demangle.c */
 
 extern void set_demangling_style (char *);
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.20
diff -u -r1.20 source.c
--- source.c 2001/07/17 06:41:47 1.20
+++ source.c 2001/11/07 04:53:35
@@ -234,6 +234,7 @@
 {
   register struct symtab *s;
   register struct objfile *objfile;
+  struct partial_symtab *pst;
 
   for (objfile = object_files; objfile != NULL; objfile = objfile->next)
     {
@@ -250,6 +251,15 @@
 	      s->fullname = NULL;
 	    }
 	}
+
+      ALL_OBJFILE_PSYMTABS (objfile, pst)
+      {
+	if (pst->fullname != NULL)
+	  {
+	    xfree (pst->fullname);
+	    pst->fullname = NULL;
+	  }
+      }
     }
 }
 
@@ -603,15 +613,17 @@
       if (fd < 0)
 	*filename_opened = NULL;
       else if (IS_ABSOLUTE_PATH (filename))
-	*filename_opened = savestring (filename, strlen (filename));
+	*filename_opened = gdb_realpath (filename);
       else
 	{
 	  /* Beware the // my son, the Emacs barfs, the botch that catch... */
 
-	  *filename_opened = concat (current_directory,
+	  char *f = concat (current_directory,
            IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
 				     ? "" : SLASH_STRING,
 				     filename, NULL);
+	  *filename_opened = gdb_realpath (f);
+	  xfree (f);
 	}
     }
   /* OBSOLETE #ifdef MPW  */
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.47
diff -u -r1.47 symtab.c
--- symtab.c 2001/11/05 23:27:31 1.47
+++ symtab.c 2001/11/07 04:53:38
@@ -141,14 +141,36 @@
   register struct symtab *s;
   register struct partial_symtab *ps;
   register struct objfile *objfile;
+  char *real_path = NULL;
 
+  if (IS_ABSOLUTE_PATH (name))
+    real_path = gdb_realpath (name);
+
 got_symtab:
 
   /* First, search for an exact match */
 
   ALL_SYMTABS (objfile, s)
+  {
     if (FILENAME_CMP (name, s->filename) == 0)
-      return s;
+      {
+	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 (real_path != NULL)
+      {
+	char *rp = symtab_to_filename (s);
+	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) */
 
@@ -195,14 +217,34 @@
 {
   register struct partial_symtab *pst;
   register struct objfile *objfile;
+  char *real_path = NULL;
+
+  if (IS_ABSOLUTE_PATH (name))
+    real_path = gdb_realpath (name);
 
   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 (pst->fullname == NULL)
+	  source_full_path_of (pst->filename, &pst->fullname);
+	if (pst->fullname != NULL
+	    && FILENAME_CMP (real_path, pst->fullname) == 0)
+	  {
+	    xfree (real_path);
+	    return pst;
+	  }
+      }
   }
+
+  xfree (real_path);
 
   /* Now, search for a matching tail (only if name doesn't have any dirs) */
 
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.25
diff -u -r1.25 symtab.h
--- symtab.h 2001/10/12 23:51:29 1.25
+++ symtab.h 2001/11/07 04:53:39
@@ -967,6 +967,10 @@
 
     char *filename;
 
+    /* Full path of the source file.  NULL if not known.  */
+
+    char *fullname;
+
     /* Information about the object file from which symbols should be read.  */
 
     struct objfile *objfile;
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.49
diff -u -r1.49 utils.c
--- utils.c 2001/11/02 21:46:52 1.49
+++ utils.c 2001/11/07 04:53:41
@@ -2534,3 +2534,15 @@
     }
   return addr;
 }
+
+char *
+gdb_realpath (const char *filename)
+{
+#ifdef HAVE_REALPATH
+  char buf[PATH_MAX];
+  char *rp = realpath (filename, buf);
+  return xstrdup (rp ? rp : filename);
+#else
+  return xstrdup (filename);
+#endif
+}
Index: gdbtk/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* generic/gdbtk-cmds.h (full_lookup_symtab): Don't declare.
	* generic/gdbtk-cmds.c (gdb_find_file_command): Use
	lookup_symtab.
	(gdb_listfuncs): Likewise.
	(gdb_loadfile): Likewise.
	(full_lookup_symtab): Removed.
	* generic/gdbtk-bp.c (gdb_find_bp_at_line): Use lookup_symtab.
	(gdb_set_bp): Likewise.

Index: gdbtk/generic/gdbtk-bp.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-bp.c,v
retrieving revision 1.13
diff -u -r1.13 gdbtk-bp.c
--- gdbtk/generic/gdbtk-bp.c 2001/11/05 19:42:48 1.13
+++ gdbtk/generic/gdbtk-bp.c 2001/11/07 04:53:44
@@ -252,7 +252,7 @@
       return TCL_ERROR;
     }
 
-  s = full_lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL));
+  s = lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL));
   if (s == NULL)
     return TCL_ERROR;
 
@@ -493,7 +493,7 @@
       return TCL_ERROR;
     }
 
-  sal.symtab = full_lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL));
+  sal.symtab = lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL));
   if (sal.symtab == NULL)
     return TCL_ERROR;
 
Index: gdbtk/generic/gdbtk-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v
retrieving revision 1.43
diff -u -r1.43 gdbtk-cmds.c
--- gdbtk/generic/gdbtk-cmds.c 2001/11/05 19:42:48 1.43
+++ gdbtk/generic/gdbtk-cmds.c 2001/11/07 04:53:46
@@ -1102,7 +1102,7 @@
     }
 
   filename = Tcl_GetStringFromObj (objv[1], NULL);
-  st = full_lookup_symtab (filename);
+  st = lookup_symtab (filename);
 
   /* We should always get a symtab. */
   if (!st)
@@ -1470,7 +1470,7 @@
       return TCL_ERROR;
     }
 
-  symtab = full_lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL));
+  symtab = lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL));
   if (!symtab)
     {
       gdbtk_set_result (interp, "No such file (%s)", 
@@ -2769,7 +2769,7 @@
   file  = Tcl_GetStringFromObj (objv[2], NULL);
   Tcl_GetBooleanFromObj (interp, objv[3], &linenumbers);
 
-  symtab = full_lookup_symtab (file);
+  symtab = lookup_symtab (file);
   if (!symtab)
     {
       gdbtk_set_result (interp, "File not found in symtab");
@@ -2995,68 +2995,6 @@
 {
   perror_with_name (args);
   return 1;
-}
-
-/* The lookup_symtab() in symtab.c doesn't work correctly */
-/* It will not work will full pathnames and if multiple */
-/* source files have the same basename, it will return */
-/* the first one instead of the correct one. */
-/* symtab->fullname will be NULL if the file is not available. */
-
-struct symtab *
-full_lookup_symtab (file)
-     char *file;
-{
-  struct symtab *st;
-  struct objfile *objfile;
-  char *bfile, *fullname;
-  struct partial_symtab *pt;
-
-  if (!file)
-    return NULL;
-
-  /* first try a direct lookup */
-  st = lookup_symtab (file);
-  if (st)
-    {
-      if (!st->fullname)
-	symtab_to_filename (st);
-      return st;
-    }
-
-  /* if the direct approach failed, try */
-  /* looking up the basename and checking */
-  /* all matches with the fullname */
-  bfile = basename (file);
-  ALL_SYMTABS (objfile, st)
-  {
-    if (!strcmp (bfile, basename (st->filename)))
-      {
-	if (!st->fullname)
-	  fullname = symtab_to_filename (st);
-	else
-	  fullname = st->fullname;
-
-	if (!strcmp (file, fullname))
-	  return st;
-      }
-  }
-
-  /* still no luck?  look at psymtabs */
-  ALL_PSYMTABS (objfile, pt)
-  {
-    if (!strcmp (bfile, basename (pt->filename)))
-      {
-	st = PSYMTAB_TO_SYMTAB (pt);
-	if (st)
-	  {
-	    fullname = symtab_to_filename (st);
-	    if (!strcmp (file, fullname))
-	      return st;
-	  }
-      }
-  }
-  return NULL;
 }
 
 /* Look for the function that contains PC and return the source
Index: gdbtk/generic/gdbtk-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.h,v
retrieving revision 1.2
diff -u -r1.2 gdbtk-cmds.h
--- gdbtk/generic/gdbtk-cmds.h 2001/11/05 19:42:48 1.2
+++ gdbtk/generic/gdbtk-cmds.h 2001/11/07 04:53:46
@@ -38,10 +38,6 @@
    tcl. ALL tcl commands should be wrapped in this call. */
 extern int gdbtk_call_wrapper (ClientData, Tcl_Interp *, int, Tcl_Obj * CONST[]);
 
-/* Like lookup_symtab but this deals with full pathnames and multiple
-   source files with the same basename. FIXME: why doesn't gdb use this? */
-extern struct symtab *full_lookup_symtab (char *file);
-
 /* Returns the source (demangled) name for a function at PC. Returns empty string
    if not found. Memory is owned by gdb. Do not free it. */
 extern char *pc_function_name (CORE_ADDR pc);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]