summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-04-06 15:14:09 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-05-08 09:45:39 +0000
commite5cde7378c246a32d7dbc3bff8db15befad8b1a9 (patch)
tree7586f1b4901236f1dbe28e022d6a4c9b84bef74e /libdwfl
parent037d971fa81644af1d3be30db409309155fda721 (diff)
Use OS-specific paths
In general we need to use ';' as path separator and '\' and directory separator on windows. The shell will automatically translate paths to some extent, but we have to call "pwd -W" rather than plain "pwd" to get something useful. Change-Id: I1a117d219a2aa00c1f77ae7d3a1d92b9bae526db Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog8
-rw-r--r--libdwfl/dwfl_build_id_find_elf.c5
-rw-r--r--libdwfl/find-debuginfo.c106
-rw-r--r--libdwfl/libdwflP.h4
-rw-r--r--libdwfl/linux-kernel-modules.c3
-rw-r--r--libdwfl/linux-proc-maps.c4
6 files changed, 75 insertions, 55 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 6f3a5611..ee550d02 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,13 @@
2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+ * dwfl_build_id_find_elf.c: Don't assume unix file system conventions.
+ * find-debuginfo.c: Likewise.
+ * linux-kernel-modules.c: Likewise.
+ * linux-proc-maps.c: Likewise.
+ * libdwflP.h: Add a windows-compatible default debuginfo path.
+
+2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+
* argp-std.c: Open files in O_BINARY.
* dwfl_build_id_find_elf.c: Likewise.
* dwfl_build_id_find_elf.c: Likewise.
diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c
index 6ce2c1cc..cf2a0f15 100644
--- a/libdwfl/dwfl_build_id_find_elf.c
+++ b/libdwfl/dwfl_build_id_find_elf.c
@@ -79,13 +79,14 @@ __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug, char **file_name,
int fd = -1;
char *dir;
char *paths = path;
- while (fd < 0 && (dir = strsep (&paths, ":")) != NULL)
+ char pathsep[] = { PATHSEP, '\0' };
+ while (fd < 0 && (dir = strsep (&paths, pathsep)) != NULL)
{
if (dir[0] == '+' || dir[0] == '-')
++dir;
/* Only absolute directory names are useful to us. */
- if (dir[0] != '/')
+ if (IS_ABSOLUTE_PATH(dir))
continue;
size_t dirlen = strlen (dir);
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 7f7e1081..ac568d08 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -52,9 +52,10 @@ try_open (const struct stat *main_stat,
if (unlikely (fname == NULL))
return -1;
}
- else if ((subdir == NULL ? asprintf (&fname, "%s/%s", dir, debuglink)
- : dir == NULL ? asprintf (&fname, "%s/%s", subdir, debuglink)
- : asprintf (&fname, "%s/%s/%s", dir, subdir, debuglink)) < 0)
+ else if ((subdir == NULL ? asprintf (&fname, "%s%c%s", dir, DIRSEP, debuglink)
+ : dir == NULL ? asprintf (&fname, "%s%c%s", subdir, DIRSEP, debuglink)
+ : asprintf (&fname, "%s%c%s%c%s", dir, DIRSEP, subdir, DIRSEP,
+ debuglink)) < 0)
return -1;
struct stat st;
@@ -231,7 +232,8 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name,
return -1;
}
char *p;
- while ((p = strsep (&path, ":")) != NULL)
+ const char pathsep[] = { PATHSEP, '\0' };
+ while ((p = strsep (&path, pathsep)) != NULL)
{
/* A leading - or + says whether to check file CRCs for this element. */
bool check = defcheck;
@@ -244,53 +246,57 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name,
bool try_file_basename;
const char *dir, *subdir, *file;
- switch (p[0])
- {
- case '\0':
- /* An empty entry says to try the main file's directory. */
- dir = file_dirname;
- subdir = NULL;
- file = debuglink_file;
- try_file_basename = false;
- break;
- case '/':
- /* An absolute path says to look there for a subdirectory
- named by the main file's absolute directory. This cannot
- be applied to a relative file name. For alt debug files
- it means to look for the basename file in that dir or the
- .dwz subdir (see below). */
- if (mod->dw == NULL
- && (file_dirname == NULL || file_dirname[0] != '/'))
- continue;
- dir = p;
- if (mod->dw == NULL)
- {
- subdir = file_dirname;
- /* We want to explore all sub-subdirs. Chop off one slash
- at a time. */
- explore_dir:
- subdir = strchr (subdir, '/');
- if (subdir != NULL)
- subdir = subdir + 1;
- if (subdir && *subdir == 0)
- continue;
- file = debuglink_file;
- }
- else
- {
+ if (IS_ABSOLUTE_PATH(p))
+ {
+ /* An absolute path says to look there for a subdirectory
+ named by the main file's absolute directory. This cannot
+ be applied to a relative file name. For alt debug files
+ it means to look for the basename file in that dir or the
+ .dwz subdir (see below). */
+ if (mod->dw == NULL
+ && (file_dirname == NULL || !IS_ABSOLUTE_PATH(file_dirname)))
+ continue;
+ dir = p;
+ if (mod->dw == NULL) {
+ subdir = file_dirname;
+ /* We want to explore all sub-subdirs. Chop off one slash
+ at a time. */
+ explore_dir:
+ while (subdir && *subdir && !ISDIRSEP(*subdir))
+ ++subdir;
+ if (subdir != NULL && *subdir != 0)
+ subdir = subdir + 1;
+ if (subdir && *subdir == 0)
+ continue;
+ file = debuglink_file;
+ }
+ else
+ {
+ subdir = NULL;
+ file = basename (debuglink_file);
+ }
+ try_file_basename = debuglink_null;
+ }
+ else
+ {
+ switch (p[0])
+ {
+ case '\0':
+ /* An empty entry says to try the main file's directory. */
+ dir = file_dirname;
subdir = NULL;
- file = basename (debuglink_file);
+ file = debuglink_file;
+ try_file_basename = false;
+ break;
+ default:
+ /* A relative path says to try a subdirectory of that name
+ in the main file's directory. */
+ dir = file_dirname;
+ subdir = p;
+ file = debuglink_file;
+ try_file_basename = debuglink_null;
+ break;
}
- try_file_basename = debuglink_null;
- break;
- default:
- /* A relative path says to try a subdirectory of that name
- in the main file's directory. */
- dir = file_dirname;
- subdir = p;
- file = debuglink_file;
- try_file_basename = debuglink_null;
- break;
}
char *fname = NULL;
@@ -304,7 +310,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name,
case ENOTDIR:
/* If we are looking for the alt file also try the .dwz subdir.
But only if this is the empty or absolute path. */
- if (mod->dw != NULL && (p[0] == '\0' || p[0] == '/'))
+ if (mod->dw != NULL && (p[0] == '\0' || IS_ABSOLUTE_PATH(p)))
{
fd = try_open (&main_stat, dir, ".dwz",
basename (file), &fname);
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 7d5f795c..fbd1a647 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -766,7 +766,11 @@ INTDECL (dwfl_frame_pc)
/* The default used by dwfl_standard_find_debuginfo. */
+#if (defined _WIN32 || defined __WIN32__)
+#define DEFAULT_DEBUGINFO_PATH ";.debug"
+#else
#define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug"
+#endif
#endif /* libdwflP.h */
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 139a4774..bd963d32 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -48,6 +48,7 @@
#include <sys/utsname.h>
#include <fcntl.h>
#include <unistd.h>
+#include <system.h>
/* If fts.h is included before config.h, its indirect inclusions may not
give us the right LFS aliases of these functions, so map them manually. */
@@ -96,7 +97,7 @@ try_kernel_name (Dwfl *dwfl, char **fname, bool try_debug)
tried because we give its own basename as DEBUGLINK_FILE. */
int fd = ((((dwfl->callbacks->debuginfo_path
? *dwfl->callbacks->debuginfo_path : NULL)
- ?: DEFAULT_DEBUGINFO_PATH)[0] == ':') ? -1
+ ?: DEFAULT_DEBUGINFO_PATH)[0] == PATHSEP) ? -1
: TEMP_FAILURE_RETRY (open (*fname, O_RDONLY | O_BINARY)));
if (fd < 0)
diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c
index 78f472a8..8eb9a5cb 100644
--- a/libdwfl/linux-proc-maps.c
+++ b/libdwfl/linux-proc-maps.c
@@ -245,7 +245,7 @@ proc_maps_report (Dwfl *dwfl, FILE *f, GElf_Addr sysinfo_ehdr, pid_t pid)
}
char *file = line + nread + strspn (line + nread, " \t");
- if (file[0] != '/' || (ino == 0 && dmajor == 0 && dminor == 0))
+ if (!IS_ABSOLUTE_PATH(file) || (ino == 0 && dmajor == 0 && dminor == 0))
/* This line doesn't indicate a file mapping. */
continue;
@@ -362,7 +362,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)),
char **file_name, Elf **elfp)
{
int pid = -1;
- if (module_name[0] == '/')
+ if (IS_ABSOLUTE_PATH (module_name))
{
/* When this callback is used together with dwfl_linux_proc_report
then we might see mappings of special character devices. Make