summaryrefslogtreecommitdiffstats
path: root/libdwfl/find-debuginfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdwfl/find-debuginfo.c')
-rw-r--r--libdwfl/find-debuginfo.c106
1 files changed, 56 insertions, 50 deletions
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);