diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2013-10-13 16:11:08 +0000 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2013-10-13 16:11:08 +0000 |
commit | 4856b6bc835e25ab0f48462104152701c864858c (patch) | |
tree | a9cdb2e19fc8c02072765dbf3ac49043ddbcb4ac /gdb/utils.c | |
parent | 690f47bf982493bf41a09238d38e9a934411f214 (diff) | |
download | gdb-4856b6bc835e25ab0f48462104152701c864858c.zip gdb-4856b6bc835e25ab0f48462104152701c864858c.tar.gz gdb-4856b6bc835e25ab0f48462104152701c864858c.tar.bz2 |
Improve Executable displayed path (PR 15415 regression kind #2)
gdb/
2013-10-13 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-10-13 Jan Kratochvil <jan.kratochvil@redhat.com>
Canonicalize directories for EXEC_FILENAME.
* gdb.base/argv0-symlink.exp
(kept file symbolic link name for info inferiors): New.
(kept directory symbolic link name): Setup kfail.
(kept directory symbolic link name for info inferiors): New.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 89c248c..47f9dfe 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3233,6 +3233,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) { |