public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Record and write files in read_dwarf5_line_entries.
@ 2021-07-05 16:35 Mark Wielaard
  2021-07-12 20:31 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2021-07-05 16:35 UTC (permalink / raw)
  To: debugedit; +Cc: Mark Wielaard

Without giving -d /foo/build/bar debugedit wouldn't actually output
any file from the line number table for DWARF5.

	* tools/debugedit.c (read_dwarf5_line_entries): Don't make
	collecting_dirs and writing_files depend on dest_dir. Always
	read idx for strp or line_strp on phase 0. comp_dir_len is
	zero when comp_dir is NULL.
	* tests/debugedit.at: Add source list mode tests for DWARF4
	and DWARF5.

https://bugzilla.redhat.com/show_bug.cgi?id=1966987

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tests/debugedit.at | 24 ++++++++++++++++++++++++
 tools/debugedit.c  | 22 +++++++++++++---------
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/tests/debugedit.at b/tests/debugedit.at
index 01b1f2f..608b1d0 100644
--- a/tests/debugedit.at
+++ b/tests/debugedit.at
@@ -666,3 +666,27 @@ readelf --debug-dump=macro ./foobarbaz.exe \
 ]],[0],[expout])
 
 AT_CLEANUP
+
+# ===
+# source list mode dwarf-4
+# ===
+AT_SETUP([debugedit --list-file DWARF4])
+AT_KEYWORDS([debuginfo] [debugedit])
+echo "int main () { }" > main.c
+$CC $CFLAGS -gdwarf-4 -o main main.c
+AT_CHECK([[debugedit -l sources.list main]])
+AT_CHECK([[grep -q main.c sources.list]])
+cat sources.list
+AT_CLEANUP
+
+# ===
+# source list mode dwarf-5
+# ===
+AT_SETUP([debugedit --list-file DWARF5])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+echo "int main () { }" > main.c
+$CC $CFLAGS -gdwarf-5 -o main main.c
+AT_CHECK([[debugedit -l sources.list main]])
+AT_CHECK([[grep -q main.c sources.list]])
+AT_CLEANUP
diff --git a/tools/debugedit.c b/tools/debugedit.c
index c4e6c4c..668777a 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -1831,8 +1831,8 @@ read_dwarf5_line_entries (DSO *dso, unsigned char **ptrp,
   /* file_names_count */
   unsigned entry_count = read_uleb128 (*ptrp);
 
-  bool collecting_dirs = dest_dir && phase == 0 && *dirs == NULL;
-  bool writing_files = dest_dir && phase == 0 && *dirs != NULL;
+  bool collecting_dirs = phase == 0 && *dirs == NULL;
+  bool writing_files = phase == 0 && *dirs != NULL;
   if (collecting_dirs)
     {
       *ndir = entry_count;
@@ -1862,15 +1862,19 @@ read_dwarf5_line_entries (DSO *dso, unsigned char **ptrp,
 		{
 		case DW_FORM_strp:
 		case DW_FORM_line_strp:
-		  if (dest_dir && phase == 0)
+		  if (phase == 0)
 		    {
 		      size_t idx = do_read_32_relocated (*ptrp);
-		      if (record_file_string_entry_idx (line_strp, dso, idx))
+		      if (dest_dir)
 			{
-			  if (line_strp)
-			    need_line_strp_update = true;
-			  else
-			    need_strp_update = true;
+			  if (record_file_string_entry_idx (line_strp, dso,
+							    idx))
+			    {
+			      if (line_strp)
+				need_line_strp_update = true;
+			      else
+				need_strp_update = true;
+			    }
 			}
 		      handled_strp = true;
 		      if (collecting_dirs || writing_files)
@@ -1956,7 +1960,7 @@ read_dwarf5_line_entries (DSO *dso, unsigned char **ptrp,
       if (writing_files)
 	{
 	  char *comp_dir = (*dirs)[0];
-	  size_t comp_dir_len = strlen(comp_dir);
+	  size_t comp_dir_len = !comp_dir ? 0 : strlen(comp_dir);
 	  size_t file_len = strlen (file);
 	  size_t dir_len = strlen (dir);
 
-- 
2.18.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Record and write files in read_dwarf5_line_entries.
  2021-07-05 16:35 [PATCH] Record and write files in read_dwarf5_line_entries Mark Wielaard
@ 2021-07-12 20:31 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2021-07-12 20:31 UTC (permalink / raw)
  To: debugedit; +Cc: fche

Hi,

On Mon, Jul 05, 2021 at 06:35:04PM +0200, Mark Wielaard wrote:
> Without giving -d /foo/build/bar debugedit wouldn't actually output
> any file from the line number table for DWARF5.
> 
> 	* tools/debugedit.c (read_dwarf5_line_entries): Don't make
> 	collecting_dirs and writing_files depend on dest_dir. Always
> 	read idx for strp or line_strp on phase 0. comp_dir_len is
> 	zero when comp_dir is NULL.
> 	* tests/debugedit.at: Add source list mode tests for DWARF4
> 	and DWARF5.

Pushed.

> https://bugzilla.redhat.com/show_bug.cgi?id=1966987

Although I added test cases to show this patch fixes a real bug I am
not 100% sure it also fixes the bug reported in the above bug report.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-12 20:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-05 16:35 [PATCH] Record and write files in read_dwarf5_line_entries Mark Wielaard
2021-07-12 20:31 ` 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).