From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 87976 invoked by alias); 15 Feb 2019 11:13:41 -0000 Mailing-List: contact dwz-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: dwz-owner@sourceware.org Received: (qmail 87961 invoked by uid 89); 15 Feb 2019 11:13:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:4200 X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mx1.suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Date: Tue, 01 Jan 2019 00:00:00 -0000 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com Subject: [PATCH 2/2] Add --save-temps/-s Message-ID: <20190215111409.GA30084@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2019-q1/txt/msg00025.txt.bz2 Hi, The temporary files used in multifile mode are of interest when debugging multifile issues, but they are removed after dwz has run. Add a developer-only (that is, not added to usage or manual) option --save-temps/-s to keep these files available: ... $ dwz --save-temps -m 3 1 2 $ ls -1 dwz.* dwz.debug_abbrev.IklrhP dwz.debug_info.CWGFOC dwz.debug_line.Dx6cK1 dwz.debug_macro.Yjq9Fq dwz.debug_str.uZ1Yce ... These files can then be added to a dummy elf file, which can be inspected using readelf or some such: ... $ echo 'int a;' | gcc -xc - -c -o mf.o $ for f in dwz.debug_*; do section=$(echo $f \ | sed 's/^dwz\.//;s/\..*//') objcopy \ --add-section .$section=$f \ mf.o done $ readelf -w mf.o > READELF ... OK for trunk? Thanks, - Tom Add --save-temps/-s 2019-02-15 Tom de Vries * dwz.c (save_temps): New variable. (dwz_options): Add -save-temps entry. (TMPDIR): Define. (make_temp_file): Handle save_temps. (main): Set save_temps. --- dwz.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/dwz.c b/dwz.c index c8ada61..426bebc 100644 --- a/dwz.c +++ b/dwz.c @@ -485,6 +485,8 @@ static int multi_info_fd = -1, multi_abbrev_fd = -1; static int multi_line_fd = -1, multi_str_fd = -1; static int multi_macro_fd = -1; +bool save_temps = false; + /* Copy of one of the input file's ehdr. */ static GElf_Ehdr multi_ehdr; @@ -11762,6 +11764,7 @@ static struct option dwz_options[] = { "multifile", required_argument, 0, 'm' }, { "quiet", no_argument, 0, 'q' }, { "hardlink", no_argument, 0, 'h' }, + { "save-temps", no_argument, 0, 's' }, { "low-mem-die-limit", required_argument, 0, 'l' }, { "max-die-limit", required_argument, 0, 'L' }, { "multifile-name", required_argument, 0, 'M' }, @@ -11794,26 +11797,37 @@ version (void) exit (0); } +#define TMPDIR "/tmp/" + /* Create a temporary file using TEMPLATE. Return the corresponding file descriptor if successful, otherwise return -1. */ static int make_temp_file (const char *template) { - char buf[sizeof "/tmp/dwz.debug_abbrev.XXXXXX"]; + char buf[sizeof TMPDIR "dwz.debug_abbrev.XXXXXX"]; + char *s = buf; int fd; - size_t template_len; + size_t template_len, tmpdir_len; + tmpdir_len = strlen (TMPDIR); template_len = strlen (template); - assert (template_len + 1 <= sizeof buf); - strncpy (buf, template, sizeof buf); + assert (tmpdir_len + template_len + 1 <= sizeof buf); + + if (!save_temps) + { + strncpy (s, TMPDIR, sizeof buf); + s += tmpdir_len; + } + strncpy (s, template, sizeof buf - tmpdir_len); fd = mkstemp (buf); if (fd == -1) return fd; - /* Unlink the filename, such that the file is disposed of once the file - descriptor is closed. */ - unlink (buf); + if (!save_temps) + /* Unlink the filename, such that the file is disposed of once the file + descriptor is closed. */ + unlink (buf); return fd; } @@ -11835,7 +11849,8 @@ main (int argc, char *argv[]) while (1) { int option_index; - int c = getopt_long (argc, argv, "m:o:qhl:L:M:r?v", dwz_options, &option_index); + int c = getopt_long (argc, argv, "m:o:qhl:L:M:r?vs", dwz_options, + &option_index); if (c == -1) break; switch (c) @@ -11861,6 +11876,10 @@ main (int argc, char *argv[]) hardlink = true; break; + case 's': + save_temps = true; + break; + case 'M': multifile_name = optarg; break; @@ -11921,11 +11940,11 @@ main (int argc, char *argv[]) error (1, 0, "-o option not allowed for multiple files"); if (multifile) { - multi_info_fd = make_temp_file ("/tmp/dwz.debug_info.XXXXXX"); - multi_abbrev_fd = make_temp_file ("/tmp/dwz.debug_abbrev.XXXXXX"); - multi_line_fd = make_temp_file ("/tmp/dwz.debug_line.XXXXXX"); - multi_str_fd = make_temp_file ("/tmp/dwz.debug_str.XXXXXX"); - multi_macro_fd = make_temp_file ("/tmp/dwz.debug_macro.XXXXXX"); + multi_info_fd = make_temp_file ("dwz.debug_info.XXXXXX"); + multi_abbrev_fd = make_temp_file ("dwz.debug_abbrev.XXXXXX"); + multi_line_fd = make_temp_file ("dwz.debug_line.XXXXXX"); + multi_str_fd = make_temp_file ("dwz.debug_str.XXXXXX"); + multi_macro_fd = make_temp_file ("dwz.debug_macro.XXXXXX"); if (multi_info_fd == -1 || multi_abbrev_fd == -1 || multi_line_fd == -1