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]

[patch] Improve Executable displayed path (as PR 15415 regression)


On Wed, 04 Sep 2013 12:48:41 +0200, Pedro Alves wrote:
> It seems this patch introduces some output inconsistency
> (only tried mainline):
> 
>  $ ./gdb
>  ...
>  (gdb) file ./gdb
>  Reading symbols from /home/pedro/gdb/mygit/build/gdb/gdb...done.
>  Setting up the environment for debugging gdb.
>  (top-gdb) info inferiors
>    Num  Description       Executable
>  * 1    <null>            /home/pedro/gdb/mygit/build/gdb/./gdb
>  (top-gdb)
> 
> Note "gdb/gdb" vs "gdb/./gdb".
> 
>  (top-gdb) file gdbserver/../gdb
>  Load new symbol table from "/home/pedro/gdb/mygit/build/gdb/gdb"? (y or n) y
>  Reading symbols from /home/pedro/gdb/mygit/build/gdb/gdb...done.
>  (top-gdb) info inferiors
>    Num  Description       Executable
>  * 1    <null>            /home/pedro/gdb/mygit/build/gdb/gdbserver/../gdb
>  (top-gdb)
> 
> Note ".../gdb/gdb" vs ".../gdb/gdbserver/../gdb".

After the patch
	[patchv2] Support .dwp with the name of symlinked binary file
	https://sourceware.org/ml/gdb-patches/2013-09/msg00167.html
plus this patch:

bfd->filename and objfile->name always contain canonical path, therefore:

>  Load new symbol table from "/home/pedro/gdb/mygit/build/gdb/gdb"? (y or n) y

exec_filename (get_exec_file()) contains path normalized by xfullpath,
therefore:

#  * 1    <null>            /home/pedro/gdb/mygit/build/gdb/gdb
or
#  * 1    <null>            /home/pedro/gdb/mygit/build/gdb/symlink-to-gdb
and neither
>  * 1    <null>            /home/pedro/gdb/mygit/build/gdb/./gdb
nor
>  * 1    <null>            /home/pedro/gdb/mygit/build/gdb/gdbserver/../gdb

The patch reintroduces xfullpath although IMO under a better name
gdb_realpath_keepfile, to match it is very similar to gdb_realpath.
xfullpath was removed by:
	commit bfacf227ec8ee6b1c73311e323bd93c1eddd9ca6
	Author: Jan Kratochvil <jan.kratochvil@redhat.com>
	Date:   Sun Feb 3 15:54:14 2013 +0000
		Replace xfullpath calls by gdb_realpath calls.

Contrary to GDBs <=7.5 gdb_realpath_keepfile is used only for exec_filename
where it matters.  GDBs <=7.5 used it for everything (as it was used by
openp()), therefore even for source filenames, which made all the symtab
matching functions complicated, having to compare both xfullpath names and
gdb_realpath names.  Currently symtabs / source files still use only
gdb_realpath as keep the name of symbolic link does not matter for source
files.

I had to file for new KFAIL
	Keep directories for argv[0]
	https://sourceware.org/bugzilla/show_bug.cgi?id=15934
as this patch no longer keeps argv[0] (its directories) intact.
I do not think it matters, though, more details in this filed PR.
The testcase part about keeping the directory name did not come from any real
user request.


Jan


gdb/
2013-09-05  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Canonicalize directories for EXEC_FILENAME.
	* exec.c (exec_file_attach): Use gdb_realpath_keepfile for
	exec_filename.
	* utils.c (gdb_realpath_keepfile): New function.
	* utils.h (gdb_realpath_keepfile): New declaration.

gdb/testsuite/
2013-09-05  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/argv0-symlink.exp (print argv[0]): Setup kfail.

diff --git a/gdb/exec.c b/gdb/exec.c
index c7370e3..758cdc1 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -224,7 +224,7 @@ exec_file_attach (char *filename, int from_tty)
 	}
 
       gdb_assert (exec_filename == NULL);
-      exec_filename = xstrdup (scratch_pathname);
+      exec_filename = gdb_realpath_keepfile (scratch_pathname);
 
       if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
 	{
diff --git a/gdb/testsuite/gdb.base/argv0-symlink.exp b/gdb/testsuite/gdb.base/argv0-symlink.exp
index dc11f74..529d2b3 100644
--- a/gdb/testsuite/gdb.base/argv0-symlink.exp
+++ b/gdb/testsuite/gdb.base/argv0-symlink.exp
@@ -59,4 +59,8 @@ if ![runto_main] {
     return -1
 }
 
+# gdbserver does not have this issue.
+if ![is_remote target] {
+    setup_kfail "*-*-*" gdb/15934
+}
 gdb_test {print argv[0]} "/$dirlink/$filelink\"" $test
diff --git a/gdb/utils.c b/gdb/utils.c
index 0652197..b6914ff 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3204,6 +3204,52 @@ gdb_realpath (const char *filename)
   return xstrdup (filename);
 }
 
+/* Return a copy of FILENAME, with its directory prefix canonicalized
+   by gdb_realpath.  */
+
+char *
+gdb_realpath_keepfile (const char *filename)
+{
+  const char *base_name = lbasename (filename);
+  char *dir_name;
+  char *real_path;
+  char *result;
+
+  /* Extract the basename of filename, and return immediately 
+     a copy of filename if it does not contain any directory prefix.  */
+  if (base_name == filename)
+    return xstrdup (filename);
+
+  dir_name = alloca ((size_t) (base_name - filename + 2));
+  /* Allocate enough space to store the dir_name + plus one extra
+     character sometimes needed under Windows (see below), and
+     then the closing \000 character.  */
+  strncpy (dir_name, filename, base_name - filename);
+  dir_name[base_name - filename] = '\000';
+
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  /* We need to be careful when filename is of the form 'd:foo', which
+     is equivalent of d:./foo, which is totally different from d:/foo.  */
+  if (strlen (dir_name) == 2 && isalpha (dir_name[0]) && dir_name[1] == ':')
+    {
+      dir_name[2] = '.';
+      dir_name[3] = '\000';
+    }
+#endif
+
+  /* Canonicalize the directory prefix, and build the resulting
+     filename.  If the dirname realpath already contains an ending
+     directory separator, avoid doubling it.  */
+  real_path = gdb_realpath (dir_name);
+  if (IS_DIR_SEPARATOR (real_path[strlen (real_path) - 1]))
+    result = concat (real_path, base_name, (char *) NULL);
+  else
+    result = concat (real_path, SLASH_STRING, base_name, (char *) NULL);
+
+  xfree (real_path);
+  return result;
+}
+
 ULONGEST
 align_up (ULONGEST v, int n)
 {
diff --git a/gdb/utils.h b/gdb/utils.h
index 143cd6b..e917dae 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -128,6 +128,8 @@ extern struct cleanup *make_bpstat_clear_actions_cleanup (void);
 
 extern char *gdb_realpath (const char *);
 
+extern char *gdb_realpath_keepfile (const char *);
+
 extern int gdb_filename_fnmatch (const char *pattern, const char *string,
 				 int flags);
 


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