* [PATCH 2/2] Add --save-temps/-s
@ 2019-01-01 0:00 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2019-01-01 0:00 UTC (permalink / raw)
To: dwz, jakub
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 <tdevries@suse.de>
* 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-02-15 11:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01 0:00 [PATCH 2/2] Add --save-temps/-s Tom de Vries
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).