Blame SOURCES/valgrind-3.11.0-is_stmt.patch

0ab3a1
commit 434c7524413a8a47ae40e4b141f5821eabc506b7
0ab3a1
Author: iraisr <iraisr@a5019735-40e9-0310-863c-91ae7b9d1cf9>
0ab3a1
Date:   Fri Dec 4 13:14:10 2015 +0000
0ab3a1
0ab3a1
    Dwarf line info reader now correctly interprets 'is_stmt' register
0ab3a1
    
0ab3a1
    Line numbers should correctly reflect all instructions belonging to a source line,
0ab3a1
    regardless of is_stmt value. Previously only instructions covered by
0ab3a1
    'is_stmt = 1' were attributed to a source line.
0ab3a1
    
0ab3a1
    Fixes BZ#356044
0ab3a1
    
0ab3a1
    
0ab3a1
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15741 a5019735-40e9-0310-863c-91ae7b9d1cf9
0ab3a1
0ab3a1
diff --git a/coregrind/m_debuginfo/readdwarf.c b/coregrind/m_debuginfo/readdwarf.c
0ab3a1
index 88d49e9..a95bb3d 100644
0ab3a1
--- a/coregrind/m_debuginfo/readdwarf.c
0ab3a1
+++ b/coregrind/m_debuginfo/readdwarf.c
0ab3a1
@@ -91,7 +91,6 @@ typedef struct
0ab3a1
   ULong  li_header_length;
0ab3a1
   UChar  li_min_insn_length;
0ab3a1
   UChar  li_max_ops_per_insn;
0ab3a1
-  UChar  li_default_is_stmt;
0ab3a1
   Int    li_line_base;
0ab3a1
   UChar  li_line_range;
0ab3a1
   UChar  li_opcode_base;
0ab3a1
@@ -150,7 +149,6 @@ typedef struct
0ab3a1
   UInt  file;
0ab3a1
   UInt  line;
0ab3a1
   UInt  column;
0ab3a1
-  Int   is_stmt;
0ab3a1
   Int   basic_block;
0ab3a1
   UChar end_sequence;
0ab3a1
 } LineSMR;
0ab3a1
@@ -230,7 +228,7 @@ ULong read_initial_length_field ( DiCursor p_img, /*OUT*/Bool* is64 )
0ab3a1
 static LineSMR state_machine_regs;
0ab3a1
 
0ab3a1
 static 
0ab3a1
-void reset_state_machine ( Int is_stmt )
0ab3a1
+void reset_state_machine ( void )
0ab3a1
 {
0ab3a1
    if (0) VG_(printf)("smr.a := %p (reset)\n", NULL );
0ab3a1
    state_machine_regs.last_address = 0;
0ab3a1
@@ -240,7 +238,6 @@ void reset_state_machine ( Int is_stmt )
0ab3a1
    state_machine_regs.file = 1;
0ab3a1
    state_machine_regs.line = 1;
0ab3a1
    state_machine_regs.column = 0;
0ab3a1
-   state_machine_regs.is_stmt = is_stmt;
0ab3a1
    state_machine_regs.basic_block = 0;
0ab3a1
    state_machine_regs.end_sequence = 0;
0ab3a1
 }
0ab3a1
@@ -253,7 +250,7 @@ void reset_state_machine ( Int is_stmt )
0ab3a1
 static 
0ab3a1
 void process_extended_line_op( struct _DebugInfo* di,
0ab3a1
                                XArray* fndn_ix_xa,
0ab3a1
-                               DiCursor* data, Int is_stmt)
0ab3a1
+                               DiCursor* data )
0ab3a1
 {
0ab3a1
    UInt len = step_leb128U(data);
0ab3a1
    if (len == 0) {
0ab3a1
@@ -275,19 +272,17 @@ void process_extended_line_op( struct _DebugInfo* di,
0ab3a1
             reset_state_machine below */
0ab3a1
          state_machine_regs.end_sequence = 1; 
0ab3a1
 
0ab3a1
-         if (state_machine_regs.is_stmt) {
0ab3a1
-            if (state_machine_regs.last_address) {
0ab3a1
-               ML_(addLineInfo) (
0ab3a1
-                  di,
0ab3a1
-                  safe_fndn_ix (fndn_ix_xa,
0ab3a1
-                                state_machine_regs.last_file),
0ab3a1
-                  di->text_debug_bias + state_machine_regs.last_address, 
0ab3a1
-                  di->text_debug_bias + state_machine_regs.address, 
0ab3a1
-                  state_machine_regs.last_line, 0
0ab3a1
-               );
0ab3a1
-            }
0ab3a1
+         if (state_machine_regs.last_address) {
0ab3a1
+            ML_(addLineInfo)(
0ab3a1
+               di,
0ab3a1
+               safe_fndn_ix(fndn_ix_xa,
0ab3a1
+                            state_machine_regs.last_file),
0ab3a1
+               di->text_debug_bias + state_machine_regs.last_address, 
0ab3a1
+               di->text_debug_bias + state_machine_regs.address, 
0ab3a1
+               state_machine_regs.last_line, 0
0ab3a1
+            );
0ab3a1
          }
0ab3a1
-         reset_state_machine (is_stmt);
0ab3a1
+         reset_state_machine();
0ab3a1
          if (di->ddump_line)
0ab3a1
             VG_(printf)("  Extended opcode %d: End of Sequence\n\n", 
0ab3a1
                         (Int)op_code);
0ab3a1
@@ -446,29 +441,9 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
0ab3a1
       info.li_max_ops_per_insn = 1;
0ab3a1
    }
0ab3a1
 
0ab3a1
-   info.li_default_is_stmt = ML_(cur_step_UChar)(&external);
0ab3a1
-   if (di->ddump_line)
0ab3a1
-      VG_(printf)("  Initial value of 'is_stmt':  %d\n", 
0ab3a1
-                  (Int)info.li_default_is_stmt);
0ab3a1
-
0ab3a1
-   /* Josef Weidendorfer (20021021) writes:
0ab3a1
-
0ab3a1
-      It seems to me that the Intel Fortran compiler generates bad
0ab3a1
-      DWARF2 line info code: It sets "is_stmt" of the state machine in
0ab3a1
-      the line info reader to be always false. Thus, there is never
0ab3a1
-      a statement boundary generated and therefore never an instruction
0ab3a1
-      range/line number mapping generated for valgrind.
0ab3a1
-
0ab3a1
-      Please have a look at the DWARF2 specification, Ch. 6.2
0ab3a1
-      (x86.ddj.com/ftp/manuals/tools/dwarf.pdf).  Perhaps I understand
0ab3a1
-      this wrong, but I don't think so.
0ab3a1
-
0ab3a1
-      I just had a look at the GDB DWARF2 reader...  They completely
0ab3a1
-      ignore "is_stmt" when recording line info ;-) That's the reason
0ab3a1
-      "objdump -S" works on files from the intel fortran compiler.
0ab3a1
-
0ab3a1
-      Therefore: */
0ab3a1
-   info.li_default_is_stmt = True; 
0ab3a1
+   /* Register is_stmt is not tracked as we are interested only
0ab3a1
+      in pc -> line info mapping and not other debugger features. */
0ab3a1
+   /* default_is_stmt = */ ML_(cur_step_UChar)(&external);
0ab3a1
 
0ab3a1
    /* JRS: changed (UInt*) to (UChar*) */
0ab3a1
    info.li_line_base = ML_(cur_step_UChar)(&external);
0ab3a1
@@ -495,7 +470,7 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
0ab3a1
    DiCursor end_of_sequence
0ab3a1
      = ML_(cur_plus)(data, info.li_length + (is64 ? 12 : 4));
0ab3a1
 
0ab3a1
-   reset_state_machine (info.li_default_is_stmt);
0ab3a1
+   reset_state_machine();
0ab3a1
 
0ab3a1
    /* Read the contents of the Opcodes table.  */
0ab3a1
    DiCursor standard_opcodes = external;
0ab3a1
@@ -632,55 +607,49 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
0ab3a1
                         (Int)op_code, advAddr, state_machine_regs.address,
0ab3a1
                         (Int)adv, (Int)state_machine_regs.line );
0ab3a1
 
0ab3a1
-         if (state_machine_regs.is_stmt) {
0ab3a1
-            /* only add a statement if there was a previous boundary */
0ab3a1
-            if (state_machine_regs.last_address) {
0ab3a1
-               ML_(addLineInfo)(
0ab3a1
-                  di,
0ab3a1
-                  safe_fndn_ix (fndn_ix_xa,
0ab3a1
-                                state_machine_regs.last_file),
0ab3a1
-                  di->text_debug_bias + state_machine_regs.last_address, 
0ab3a1
-                  di->text_debug_bias + state_machine_regs.address, 
0ab3a1
-                  state_machine_regs.last_line, 
0ab3a1
-                  0
0ab3a1
-               );
0ab3a1
-            }
0ab3a1
-            state_machine_regs.last_address = state_machine_regs.address;
0ab3a1
-            state_machine_regs.last_file = state_machine_regs.file;
0ab3a1
-            state_machine_regs.last_line = state_machine_regs.line;
0ab3a1
+         /* only add a statement if there was a previous boundary */
0ab3a1
+         if (state_machine_regs.last_address) {
0ab3a1
+            ML_(addLineInfo)(
0ab3a1
+               di,
0ab3a1
+               safe_fndn_ix(fndn_ix_xa,
0ab3a1
+                            state_machine_regs.last_file),
0ab3a1
+               di->text_debug_bias + state_machine_regs.last_address, 
0ab3a1
+               di->text_debug_bias + state_machine_regs.address, 
0ab3a1
+               state_machine_regs.last_line, 
0ab3a1
+               0
0ab3a1
+            );
0ab3a1
          }
0ab3a1
+         state_machine_regs.last_address = state_machine_regs.address;
0ab3a1
+         state_machine_regs.last_file = state_machine_regs.file;
0ab3a1
+         state_machine_regs.last_line = state_machine_regs.line;
0ab3a1
       }
0ab3a1
 
0ab3a1
       else { /* ! (op_code >= info.li_opcode_base) */
0ab3a1
 
0ab3a1
       switch (op_code) {
0ab3a1
          case DW_LNS_extended_op:
0ab3a1
-            process_extended_line_op (
0ab3a1
-                       di, fndn_ix_xa,
0ab3a1
-                       &data, info.li_default_is_stmt);
0ab3a1
+            process_extended_line_op(di, fndn_ix_xa, &data);
0ab3a1
             break;
0ab3a1
 
0ab3a1
          case DW_LNS_copy:
0ab3a1
             if (0) VG_(printf)("1002: di->o %#lx, smr.a %#lx\n",
0ab3a1
                                (UWord)di->text_debug_bias,
0ab3a1
                                state_machine_regs.address );
0ab3a1
-            if (state_machine_regs.is_stmt) {
0ab3a1
-               /* only add a statement if there was a previous boundary */
0ab3a1
-               if (state_machine_regs.last_address) {
0ab3a1
-                  ML_(addLineInfo)(
0ab3a1
-                     di,
0ab3a1
-                     safe_fndn_ix (fndn_ix_xa,
0ab3a1
-                                   state_machine_regs.last_file), 
0ab3a1
-                     di->text_debug_bias + state_machine_regs.last_address, 
0ab3a1
-                     di->text_debug_bias + state_machine_regs.address,
0ab3a1
-                     state_machine_regs.last_line, 
0ab3a1
-                     0
0ab3a1
-                  );
0ab3a1
-               }
0ab3a1
-               state_machine_regs.last_address = state_machine_regs.address;
0ab3a1
-               state_machine_regs.last_file = state_machine_regs.file;
0ab3a1
-               state_machine_regs.last_line = state_machine_regs.line;
0ab3a1
+            /* only add a statement if there was a previous boundary */
0ab3a1
+            if (state_machine_regs.last_address) {
0ab3a1
+               ML_(addLineInfo)(
0ab3a1
+                  di,
0ab3a1
+                  safe_fndn_ix(fndn_ix_xa,
0ab3a1
+                               state_machine_regs.last_file), 
0ab3a1
+                  di->text_debug_bias + state_machine_regs.last_address, 
0ab3a1
+                  di->text_debug_bias + state_machine_regs.address,
0ab3a1
+                  state_machine_regs.last_line, 
0ab3a1
+                  0
0ab3a1
+               );
0ab3a1
             }
0ab3a1
+            state_machine_regs.last_address = state_machine_regs.address;
0ab3a1
+            state_machine_regs.last_file = state_machine_regs.file;
0ab3a1
+            state_machine_regs.last_line = state_machine_regs.line;
0ab3a1
             state_machine_regs.basic_block = 0; /* JRS added */
0ab3a1
             if (di->ddump_line)
0ab3a1
                VG_(printf)("  Copy\n");
0ab3a1
@@ -719,9 +688,6 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di,
0ab3a1
             break;
0ab3a1
          }
0ab3a1
          case DW_LNS_negate_stmt: {
0ab3a1
-            Int adv = state_machine_regs.is_stmt;
0ab3a1
-            adv = ! adv;
0ab3a1
-            state_machine_regs.is_stmt = adv;
0ab3a1
             if (di->ddump_line)
0ab3a1
                VG_(printf)("  DWARF2-line: negate_stmt\n");
0ab3a1
             break;
0ab3a1
diff --git a/coregrind/m_debuginfo/storage.c b/coregrind/m_debuginfo/storage.c
0ab3a1
index 7b2e26a..e6a9856 100644
0ab3a1
--- a/coregrind/m_debuginfo/storage.c
0ab3a1
+++ b/coregrind/m_debuginfo/storage.c
0ab3a1
@@ -419,6 +419,21 @@ static void addLoc ( struct _DebugInfo* di, DiLoc* loc, UInt fndn_ix )
0ab3a1
    /* Zero-sized locs should have been ignored earlier */
0ab3a1
    vg_assert(loc->size > 0);
0ab3a1
 
0ab3a1
+   /* Check if the last entry has adjacent range for the same line. */
0ab3a1
+   if (di->loctab_used > 0) {
0ab3a1
+      DiLoc *previous = &di->loctab[di->loctab_used - 1];
0ab3a1
+      if ((previous->lineno == loc->lineno)
0ab3a1
+          && (previous->addr + previous->size == loc->addr)) {
0ab3a1
+         if (0)
0ab3a1
+            VG_(printf)("Merging previous: addr %#lx, size %d, line %d, "
0ab3a1
+                        "with current: addr %#lx, size %d, line %d.\n",
0ab3a1
+                        previous->addr, previous->size, previous->lineno,
0ab3a1
+                        loc->addr, loc->size, loc->lineno);
0ab3a1
+         previous->size += loc->size;
0ab3a1
+         return;
0ab3a1
+      }
0ab3a1
+   }
0ab3a1
+
0ab3a1
    if (di->loctab_used == di->loctab_size) {
0ab3a1
       UInt   new_sz;
0ab3a1
       DiLoc* new_loctab;