public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix location list offset address dump under DW_AT_location (dwarf-5)
@ 2022-06-27  8:07 Alok Kumar Sharma
  0 siblings, 0 replies; only message in thread
From: Alok Kumar Sharma @ 2022-06-27  8:07 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2d1388e73c700f689b23d53b504e0991fe196596

commit 2d1388e73c700f689b23d53b504e0991fe196596
Author: Bhuvanendra Kumar N <Bhuvanendra.KumarN@amd.com>
Date:   Mon Jun 27 13:07:55 2022 +0530

    Fix location list offset address dump under DW_AT_location (dwarf-5)
    
    For clang compiled objects with dwarf-5, location list offset address dump
    under DW_AT_location is corrected, where DW_FORM_loclistx is used. While
    dumping the location list offset, the address dumped is wrong where it was
    refering to .debug_addr instead of .debug_loclists
    
          * dwarf.c (fetch_indexed_value): Add base_address as parameter and
          use it to access the section offset.
          (read_and_display_attr_value): Handle DW_FORM_loclistx form separately.
          Pass loclists_base to fetch_indexed_value().

Diff:
---
 binutils/dwarf.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index d9a3144023c..d9a1ee5a86b 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -838,7 +838,8 @@ fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
 
 static dwarf_vma
 fetch_indexed_value (dwarf_vma idx,
-		     enum dwarf_section_display_enum sec_enum)
+		     enum dwarf_section_display_enum sec_enum,
+		     dwarf_vma base_address)
 {
   struct dwarf_section *section = &debug_displays [sec_enum].section;
 
@@ -863,8 +864,12 @@ fetch_indexed_value (dwarf_vma idx,
  
   dwarf_vma offset = idx * pointer_size;
 
-  /* Offsets are biased by the size of the section header.  */
-  offset += bias;
+  /* Offsets are biased by the size of the section header
+     or base address.  */
+  if (sec_enum == loclists)
+    offset += base_address;
+  else
+    offset += bias;
 
   if (offset + pointer_size > section->size)
     {
@@ -2808,13 +2813,23 @@ read_and_display_attr_value (unsigned long           attribute,
 
 	  if (do_wide)
 	    /* We have already displayed the form name.  */
-	    printf (_("%c(index: 0x%s): %s"), delimiter,
-		    dwarf_vmatoa ("x", uvalue),
-		    dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
+	    if (form == DW_FORM_loclistx)
+	      printf (_("%c(index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", debug_info_p->loc_offsets [uvalue]));
+	    else
+	      printf (_("%c(index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
 	  else
-	    printf (_("%c(addr_index: 0x%s): %s"), delimiter,
-		    dwarf_vmatoa ("x", uvalue),
-		    dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
+	    if (form == DW_FORM_loclistx)
+	      printf (_("%c(addr_index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", debug_info_p->loc_offsets [uvalue]));
+	    else
+	      printf (_("%c(addr_index: 0x%s): %s"), delimiter,
+	              dwarf_vmatoa ("x", uvalue),
+	              dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
 	}
       break;
 
@@ -2898,9 +2913,8 @@ read_and_display_attr_value (unsigned long           attribute,
 			       lmax, sizeof (*debug_info_p->have_frame_base));
 		  debug_info_p->max_loc_offsets = lmax;
 		}
-
 	      if (form == DW_FORM_loclistx)
-		uvalue = fetch_indexed_value (uvalue, loclists);
+		uvalue = fetch_indexed_value (num, loclists, debug_info_p->loclists_base);
 	      else if (this_set != NULL)
 		uvalue += this_set->section_offsets [DW_SECT_LOC];
 
@@ -2969,7 +2983,7 @@ read_and_display_attr_value (unsigned long           attribute,
 		}
 
 	      if (form == DW_FORM_rnglistx)
-		uvalue = fetch_indexed_value (uvalue, rnglists);
+		uvalue = fetch_indexed_value (uvalue, rnglists, 0);
 
 	      debug_info_p->range_lists [num] = uvalue;
 	      debug_info_p->num_range_lists++;


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

only message in thread, other threads:[~2022-06-27  8:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27  8:07 [binutils-gdb] Fix location list offset address dump under DW_AT_location (dwarf-5) Alok Kumar Sharma

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