public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] DWARFv5: Handle location list for split dwarf.
@ 2020-04-07 15:56 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2020-04-07 15:56 UTC (permalink / raw)
  To: gdb-cvs

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

commit 9fc3eaae69b2a60c5688d6bfe334829a3964b17f
Author: nitachra <Nitika.Achra@amd.com>
Date:   Tue Apr 7 18:35:59 2020 +0530

    DWARFv5: Handle location list for split dwarf.
    
    GDB throws the error '<error reading variable: dwarf2_find_location_
    expression: Corrupted DWARF expression.>' while printing the variable
    value with executable file compiled with -gdwarf-5 and -gdwarf-split
    flags. This is because DW_LLE_start* or DW_LLE_offset_pair with
    DW_LLE_base_addressx are being emitted in DWARFv5 location list instead of
    DW_LLE_GNU*. This patch fixes this error.
    
    Tested by running the testsuite before and after the patch and there is no
    increase in the number of test cases that fails. Tested with both -gdwarf-4
    and -gdwarf-5 flags. Also tested -gslit-dwarf along with -gdwarf-4 as well as
    -gdwarf-5 flags. Used clang version 10.0.0. This is the test case used-
    
    void bar(int arr[], int l, int m, int r) {
        int i, j, k, n1= m - l + 1, n2= r - m, L[n1], R[n2];
        for (i = 0; i < n1; i++)
            L[i] = arr[l + i];
        for (j = 0; j < n2; j++)
            R[j] = arr[m + 1+ j];
    }
    
    int main()
    {
        int arr[] = {12, 11};
        bar(arr,0,1,2);
        return 0;
    }
    
    clang -gdwarf-5 -gsplit-dwarf test.c -o test.out
    
    gdb test.out
    gdb> start
    gdb> step
    gdb> step
    gdb> step
    gdb> step
    gdb> p L[0]
    dwarf2_find_location_expression: Corrupted DWARF expression.
    
    gdb/ChangeLog:
    2020-04-07  Nitika Achra  <Nitika.Achra@amd.com>
    
            * dwarf2/loc.c (enum debug_loc_kind): Add a new kind DEBUG_LOC_OFFSET_PAIR.
            (dwarf2_find_location_expression): Call the function decode_debug_loclists_
            addresses if DWARF version is 5 or more. DW_LLE_start* or DW_LLE_offset_pair
            with DW_LLE_base_addressx are being emitted in DWARFv5 instead of DW_LLE_GNU*.
            Add applicable base address if the entry is DW_LLE_offset_pair from DWO.
            (decode_debug_loclists_addresses): Return DEBUG_LOC_OFFSET_PAIR instead of
            DEBUG_LOC_START_END in case of DW_LLE_offset_pair.

Diff:
---
 gdb/ChangeLog    | 11 +++++++++++
 gdb/dwarf2/loc.c | 18 +++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a9e955304f6..4d3c70bf9e6 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2020-04-07  Nitika Achra  <Nitika.Achra@amd.com>
+
+	* dwarf2/loc.c (enum debug_loc_kind): Add a new kind DEBUG_LOC_OFFSET_PAIR.
+	(dwarf2_find_location_expression): Call the function decode_debug_loclists_
+	addresses if DWARF version is 5 or more. DW_LLE_start* or DW_LLE_offset_pair
+	with DW_LLE_base_addressx are being emitted in DWARFv5 instead of DW_LLE_GNU*.
+	Add applicable base address if the entry is DW_LLE_offset_pair from DWO.
+	(decode_debug_loclists_addresses): Return DEBUG_LOC_OFFSET_PAIR instead of
+	DEBUG_LOC_START_END in case of DW_LLE_offset_pair.
+
+
 2020-04-07  Nitika Achra  <Nitika.Achra@amd.com>
 
 	* dwarf2/read.c (cu_debug_loc_section): Added the declaration for the function.
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index fc54e16ffdd..ecd83ec4b9c 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -92,6 +92,11 @@ enum debug_loc_kind
      as in .debug_loc.  */
   DEBUG_LOC_START_LENGTH = 3,
 
+  /* This is followed by two unsigned LEB128 operands. The values of these
+     operands are the starting and ending offsets, respectively, relative to
+     the applicable base address.  */
+  DEBUG_LOC_OFFSET_PAIR = 4,
+
   /* An internal value indicating there is insufficient data.  */
   DEBUG_LOC_BUFFER_OVERFLOW = -1,
 
@@ -232,7 +237,7 @@ decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu,
 	return DEBUG_LOC_BUFFER_OVERFLOW;
       *high = u64;
       *new_ptr = loc_ptr;
-      return DEBUG_LOC_START_END;
+      return DEBUG_LOC_OFFSET_PAIR;
     /* Following cases are not supported yet.  */
     case DW_LLE_startx_endx:
     case DW_LLE_start_end:
@@ -332,7 +337,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
       enum debug_loc_kind kind;
       const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */
 
-      if (baton->from_dwo)
+      if (baton->per_cu->version () < 5 && baton->from_dwo)
 	kind = decode_debug_loc_dwo_addresses (baton->per_cu,
 					       loc_ptr, buf_end, &new_ptr,
 					       &low, &high, byte_order);
@@ -358,6 +363,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 	  continue;
 	case DEBUG_LOC_START_END:
 	case DEBUG_LOC_START_LENGTH:
+	case DEBUG_LOC_OFFSET_PAIR:
 	  break;
 	case DEBUG_LOC_BUFFER_OVERFLOW:
 	case DEBUG_LOC_INVALID_ENTRY:
@@ -369,9 +375,11 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 
       /* Otherwise, a location expression entry.
 	 If the entry is from a DWO, don't add base address: the entry is from
-	 .debug_addr which already has the DWARF "base address".  We still add
-	 base_offset in case we're debugging a PIE executable.  */
-      if (baton->from_dwo)
+	 .debug_addr which already has the DWARF "base address". We still add
+	 base_offset in case we're debugging a PIE executable. However, if the
+	 entry is DW_LLE_offset_pair from a DWO, add the base address as the
+	 operands are offsets relative to the applicable base address.  */
+      if (baton->from_dwo && kind != DEBUG_LOC_OFFSET_PAIR)
 	{
 	  low += base_offset;
 	  high += base_offset;


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

only message in thread, other threads:[~2020-04-07 15:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07 15:56 [binutils-gdb] DWARFv5: Handle location list for split dwarf Tom Tromey

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