public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR27202, readelf -wL doesn't work on ".loc 0"
@ 2021-09-29  2:37 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2021-09-29  2:37 UTC (permalink / raw)
  To: binutils

For DWARF revision 4 and earlier, display_debug_lines_decoded
populates the file_table array with entries read from .debug_line
after the directory table.  file_table[0] contains the first entry.
DWARF rev 4 line number programs index this entry as file number one.
DWARF revision 5 changes .debug_line format quite extensively, and in
particular gives file number zero a meaning.

	PR 27202
	* dwarf.c (display_debug_lines_decoded): Correct indexing used
	for DWARF5 files.

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 213b5d17877..6e10281a6ed 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -5297,15 +5297,17 @@ display_debug_lines_decoded (struct dwarf_section *  section,
 		state_machine_regs.file = uladv;
 
 		{
-		  unsigned file = state_machine_regs.file - 1;
+		  unsigned file = state_machine_regs.file;
 		  unsigned dir;
 
+		  if (linfo.li_version < 5)
+		    --file;
 		  if (file_table == NULL || n_files == 0)
 		    printf (_("\n [Use file table entry %d]\n"), file);
 		  /* PR 20439 */
 		  else if (file >= n_files)
 		    {
-		      warn (_("file index %u > number of files %u\n"), file + 1, n_files);
+		      warn (_("file index %u > number of files %u\n"), file, n_files);
 		      printf (_("\n <over large file table index %u>"), file);
 		    }
 		  else if ((dir = file_table[file].directory_index) == 0)
@@ -5414,7 +5416,10 @@ display_debug_lines_decoded (struct dwarf_section *  section,
 
 	      if (file_table)
 		{
-		  unsigned indx = state_machine_regs.file - 1;
+		  unsigned indx = state_machine_regs.file;
+
+		  if (linfo.li_version < 5)
+		    --indx;
 		  /* PR 20439  */
 		  if (indx >= n_files)
 		    {

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-29  2:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29  2:37 PR27202, readelf -wL doesn't work on ".loc 0" Alan Modra

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).