From: Andrew Strauss <astrauss11@gmail.com>
To: debugedit@sourceware.org
Subject: [PATCH] debugedit: Add support for converting dos paths to unix paths
Date: Sun, 14 Jan 2024 13:24:38 -0500 [thread overview]
Message-ID: <CAP=E3Jjgd8cchXEmvyG92LrhT1R+vuVUMCVoCAogAiM3enGWpw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 5023 bytes --]
When replacing paths using the --base-dir and --dest-dir debugedit currently
cannot handle paths that use '\' as the directory separator. This patch adds
the --fix-dos-paths (-p) option to replace all `\`'s with a '/'. The normal
-b and -d flags can then be used to transform the result into a valid path.
Signed-off-by: Andrew Strauss <astrauss11@gmail.com>
---
tools/debugedit.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/tools/debugedit.c b/tools/debugedit.c
index 7802f9f..24b7d19 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -92,6 +92,7 @@ char *list_file = NULL;
int list_file_fd = -1;
int do_build_id = 0;
int no_recompute_build_id = 0;
+int fix_dos_paths = 0;
char *build_id_seed = NULL;
int show_version = 0;
@@ -984,6 +985,17 @@ canonicalize_path (const char *s, char *d)
return rv;
}
+/* Replaces \ directory separators with / */
+void
+fix_dir_separator (char *s)
+{
+ for (char *c = s; *c; c++) {
+ if (*c == '\\') {
+ *c = '/';
+ }
+ }
+}
+
/* Returns the rest of PATH if it starts with DIR_PREFIX, skipping any
/ path separators, or NULL if PATH doesn't start with
DIR_PREFIX. Might return the empty string if PATH equals DIR_PREFIX
@@ -1153,6 +1165,8 @@ record_file_string_entry_idx (bool line_strp, DSO
*dso, size_t old_idx)
Strent *strent;
const char *old_str = (char *)sec->data + old_idx;
+ if (fix_dos_paths)
+ fix_dir_separator ((char *)old_str);
const char *file = skip_dir_prefix (old_str, base_dir);
if (file == NULL)
{
@@ -1514,6 +1528,8 @@ edit_dwarf2_line (DSO *dso)
const char *file_path = NULL;
if (t->replace_dirs)
{
+ if (fix_dos_paths)
+ fix_dir_separator ((char *)dir);
file_path = skip_dir_prefix (dir, base_dir);
if (file_path != NULL)
{
@@ -1551,6 +1567,8 @@ edit_dwarf2_line (DSO *dso)
const char *file_path = NULL;
if (t->replace_files)
{
+ if (fix_dos_paths)
+ fix_dir_separator ((char *)file);
file_path = skip_dir_prefix (file, base_dir);
if (file_path != NULL)
{
@@ -1753,6 +1771,8 @@ read_dwarf4_line (DSO *dso, unsigned char *ptr, char
*comp_dir,
if (base_dir && dest_dir)
{
/* Do we need to replace any of the dirs? Calculate new size. */
+ if (fix_dos_paths)
+ fix_dir_separator ((char *)ptr);
const char *file_path = skip_dir_prefix ((const char *)ptr,
base_dir);
if (file_path != NULL)
@@ -1802,6 +1822,8 @@ read_dwarf4_line (DSO *dso, unsigned char *ptr, char
*comp_dir,
if (base_dir && dest_dir)
{
/* Do we need to replace any of the files? Calculate new size. */
+ if (fix_dos_paths)
+ fix_dir_separator ((char *)dir);
const char *file_path = skip_dir_prefix (file, base_dir);
if (file_path != NULL)
{
@@ -2277,6 +2299,8 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct
abbrev_tag *t, int phase)
if (form == DW_FORM_string)
{
free (comp_dir);
+ if (fix_dos_paths)
+ fix_dir_separator ((char *)ptr);
comp_dir = strdup ((char *)ptr);
if (dest_dir)
@@ -3203,13 +3227,14 @@ static struct option optionsTable[] =
{ "build-id", no_argument, 0, 'i' },
{ "build-id-seed", required_argument, 0, 's' },
{ "no-recompute-build-id", no_argument, 0, 'n' },
+ { "fix-dos-paths", no_argument, 0, 'p' },
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, '?' },
{ "usage", no_argument, 0, 'u' },
{ NULL, 0, 0, 0 }
};
-static const char *optionsChars = "b:d:l:is:nV?u";
+static const char *optionsChars = "b:d:l:is:npV?u";
static const char *helpText =
"Usage: %s [OPTION...] FILE\n"
@@ -3223,6 +3248,8 @@ static const char *helpText =
" this string as hash seed\n"
" -n, --no-recompute-build-id do not recompute build ID note even\n"
" when -i or -s are given\n"
+ " -p, --fix-dos-paths convert dos directory separators (\\)
to\n"
+ " unix (/)\n"
"\n"
"Help options:\n"
" -?, --help Show this help message\n"
@@ -3233,8 +3260,9 @@ static const char *usageText =
"Usage: %s [-in?] [-b|--base-dir STRING] [-d|--dest-dir STRING]\n"
" [-l|--list-file STRING] [-i|--build-id] \n"
" [-s|--build-id-seed STRING]\n"
- " [-n|--no-recompute-build-id] [-?|--help] [-u|--usage]\n"
- " [-V|--version] FILE\n";
+ " [-n|--no-recompute-build-id]\n"
+ " [-p|--fix-dos-paths]\n"
+ " [-?|--help] [-u|--usage] [-V|--version] FILE\n";
static void
help (const char *progname, bool error)
@@ -3536,6 +3564,10 @@ main (int argc, char *argv[])
no_recompute_build_id = 1;
break;
+ case 'p':
+ fix_dos_paths = 1;
+ break;
+
case 'V':
show_version = 1;
break;
--
2.43.0
next reply other threads:[~2024-01-14 18:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-14 18:24 Andrew Strauss [this message]
2024-04-08 14:11 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAP=E3Jjgd8cchXEmvyG92LrhT1R+vuVUMCVoCAogAiM3enGWpw@mail.gmail.com' \
--to=astrauss11@gmail.com \
--cc=debugedit@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).