From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id A5A433858D32 for ; Sun, 14 Jan 2024 18:25:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5A433858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A5A433858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705256708; cv=none; b=wokDQibE3QA6bsBUIVTqR82F4fc8uMc2daNCjkJqzoqJMjKT2c+UohS1WWkRFVpbPLQj58xBj5+kF0wBFgQ0BUyO5w+SucfFOOUk861xo2Rp+2JcksSeTuHldLfTwbr5rba5wyFakacOcL6BKkTlDi0yE05DVatKTH6qCi0JmQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705256708; c=relaxed/simple; bh=gv4r4ljH3F122NxOZeQgLvmBkdaQ8aUv1N/2eS1gzi0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=KAyvsNusW7dLQLGo6xUmFiGdvvpu7zCZjuypBdaOLvODCfQymQwFOL/vZ0fmhvvO0sN3qUubjT8PxdZu0bczhfDMJbQTxuURtpktc3vNiK/JDurMlQFfPxx6uL5lVUgNIqW68vdcZcQcY46ecPoaaDBxSYW3NXNhJmkKNbhe9cU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1d50d0c98c3so57685345ad.1 for ; Sun, 14 Jan 2024 10:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705256704; x=1705861504; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=1l1Wl+dM7IxtDTuMoa0INI8Zgdmt68FN8HKIcnQB2QA=; b=mErw9+BwuuXMWRaWjL21kam2D1KhGdXBLHkZLju++fT1d9pEkbrRv/R6Swc2ZlX/kp sJ6XMzZ1ZMHnWlkewqqMdW2h/D10ojRpai0/rdHokbRJJO/VB1ZFuwCIq+QoeBCdDBDy VuNpqOnkAJMC0fksrvmkiJ4H0Q1/dUFQz9MWaHWa/5HAzlZjuZsDBdmnNRqWUK24kv0S qzbDIhB9VeHd0Wn5vhPl5Ds8k9kQjM4jCqHEMyi1bY0SVR6QLwEVFBfpV6pWjfwf88u3 TNDrb8wKOK61PE6TSkSmUVeg4OXtiO9SJcWJSepVjqa8p0JC2gGj//lII294yFn0FnPN 5wRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705256704; x=1705861504; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1l1Wl+dM7IxtDTuMoa0INI8Zgdmt68FN8HKIcnQB2QA=; b=DfTS9+sI4YpzfUXHIo5+nZ997FRevDplgJN4MZPdoO1VlRXHDe3rrJb2WsYunF9WPI +135RjW58I94DJwDcWkQZyfB4VCKxFSzWRq0DiS2t3f2SVJwWHwsPdWDHnqljaPi6bpA e691vyrws4xtfZXsCD/VReHhxafPjl6znbCZ+CQKT0PiXlntXywq6Qi8Ku3Ly5F1Py6B GSz69InSk02/uuMn5dGCD2Q+eHxTCruXaFmPgQgRCj4cYnI9rqjXqdEYL/PxTpH4MJqj 81ISgWbJENyvjSqyp0uk3L3IbBiLRlWlXI1Oy6iwTR0S2f3Y8fId6T4+T74ksGRCSFnr o2oA== X-Gm-Message-State: AOJu0Yw4/UMnw4Z+7kHKFsPItgw/XVnXVbVDeQgmc68Vb25w3BDjRnqz 1meiPw4R5uDdFzjS5ZMERdkG0X2hiHNCWdXL2POY2J4zbSUStg== X-Google-Smtp-Source: AGHT+IGR1Cuws7hzS9hpxr5JHzuYeX4CzJXGWBCNUA5NU2My2hJr65laMg62v2jw6yFJYpS/jDCW7P/bePUZ9n3bhno= X-Received: by 2002:a17:90a:7449:b0:28d:b6c6:646c with SMTP id o9-20020a17090a744900b0028db6c6646cmr7647903pjk.46.1705256704250; Sun, 14 Jan 2024 10:25:04 -0800 (PST) MIME-Version: 1.0 From: Andrew Strauss Date: Sun, 14 Jan 2024 13:24:38 -0500 Message-ID: Subject: [PATCH] debugedit: Add support for converting dos paths to unix paths To: debugedit@sourceware.org Content-Type: multipart/alternative; boundary="0000000000001b9797060eec04f9" X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000001b9797060eec04f9 Content-Type: text/plain; charset="UTF-8" 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 --- 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 --0000000000001b9797060eec04f9--