* [PATCH] debugedit: Add support for converting dos paths to unix paths
@ 2024-01-14 18:24 Andrew Strauss
2024-04-08 14:11 ` Mark Wielaard
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Strauss @ 2024-01-14 18:24 UTC (permalink / raw)
To: debugedit
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] debugedit: Add support for converting dos paths to unix paths
2024-01-14 18:24 [PATCH] debugedit: Add support for converting dos paths to unix paths Andrew Strauss
@ 2024-04-08 14:11 ` Mark Wielaard
0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2024-04-08 14:11 UTC (permalink / raw)
To: Andrew Strauss, debugedit
Hi Andrew,
On Sun, 2024-01-14 at 13:24 -0500, Andrew Strauss wrote:
> 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.
Sorry I missed this earlier.
I think the patch looks OK in principle. But we have to double check we
can simply cast away the const everywhere. And the indentation looks
odd in a few places (tab vs space?).
But when/how do you get DOS paths in your DWARF?
And shouldn't all paths be converted back the DOS after replacement?
Thanks,
Mark
> 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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-08 14:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-14 18:24 [PATCH] debugedit: Add support for converting dos paths to unix paths Andrew Strauss
2024-04-08 14:11 ` Mark Wielaard
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).