This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Relative source file search


On Thu, 2005-10-06 at 20:25 -0400, Bob Rossi wrote:
> Craig, you should be able to put your patch into 
> source.c:find_and_open_source in the part where it checks for 
>   if (dirname != NULL)
>     {
>       ...
>     }
> 
> instead of appending to the source_path, simply change the filename and
> leave the source_path alone. Run this through the testsuite, are there
> any errors?

Attached is a new patch with the change in find_and_open_source.  I
haven't had any luck with the testsuite though, I kept getting a build
error, then I did a cvs update to make sure I had the latest, now the
whole thing won't build.  Does the cvs head build today?  I'm getting

make[4]: Entering directory `/staff/cjeffree/gdb/gdb-cvs/src/opcodes/po'
make[4]: *** No rule to make target `ga.po', needed by `ga.gmo'.  Stop.


Cheers,
Craig.


Index: gdb/source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.70
diff -u -r1.70 source.c
--- gdb/source.c	29 Aug 2005 12:57:49 -0000	1.70
+++ gdb/source.c	10 Oct 2005 03:53:53 -0000
@@ -831,6 +831,7 @@
 		      char **fullname)
 {
   char *path = source_path;
+  char *file = filename;
   const char *p;
   int result;
 
@@ -847,31 +848,45 @@
 
   if (dirname != NULL)
     {
-      /* Replace a path entry of  $cdir  with the compilation directory name */
+      if (IS_ABSOLUTE_PATH(dirname))
+        {
+          /* Replace a path entry of  $cdir  with the compilation directory name */
 #define	cdir_len	5
-      /* We cast strstr's result in case an ANSIhole has made it const,
-         which produces a "required warning" when assigned to a nonconst. */
-      p = (char *) strstr (source_path, "$cdir");
-      if (p && (p == path || p[-1] == DIRNAME_SEPARATOR)
-	  && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0'))
-	{
-	  int len;
-
-	  path = (char *)
-	    alloca (strlen (source_path) + 1 + strlen (dirname) + 1);
-	  len = p - source_path;
-	  strncpy (path, source_path, len);	/* Before $cdir */
-	  strcpy (path + len, dirname);	/* new stuff */
-	  strcat (path + len, source_path + len + cdir_len);	/* After $cdir */
-	}
+          /* We cast strstr's result in case an ANSIhole has made it const,
+             which produces a "required warning" when assigned to a nonconst. */
+          p = (char *) strstr (source_path, "$cdir");
+          if (p && (p == path || p[-1] == DIRNAME_SEPARATOR)
+              && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0'))
+            {
+              int len;
+
+              path = (char *)
+                alloca (strlen (source_path) + 1 + strlen (dirname) + 1);
+              len = p - source_path;
+              strncpy (path, source_path, len);	/* Before $cdir */
+              strcpy (path + len, dirname);	/* new stuff */
+              strcat (path + len, source_path + len + cdir_len);	/* After $cdir */
+            }
+        }
+      else
+        {
+          /* Use the concatenation of dirname and filename if dirname isn't absolute */
+          file = (char *) 
+            alloca (strlen (dirname) + strlen (SLASH_STRING) + 
+                    strlen (filename) + 1);
+
+          strcpy(file, dirname);
+          strcat(file, SLASH_STRING);
+          strcat(file, filename);
+        }      
     }
 
-  result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, 0, fullname);
+  result = openp (path, OPF_SEARCH_IN_PATH, file, OPEN_MODE, 0, fullname);
   if (result < 0)
     {
       /* Didn't work.  Try using just the basename. */
-      p = lbasename (filename);
-      if (p != filename)
+      p = lbasename (file);
+      if (p != file)
 	result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0, fullname);
     }
 

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