This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix DW_CFA_restore_extended parsing


Hi folks,

There appears to be a flaw during the execution of this instruction
(DW_CFA_restore_extended). Most of the time the registers are implicitly
defined to use an "unspecified" rule due to the lack of information (or
due to space optimization strategies) in the CIE's initial instructions.

Different from DW_CFA_restore, DW_CFA_restore_extended doesn't check if
the register rule in the current dwarf frame set's list of initialized
registers is valid prior to assigning the rule to it, so it might just
grab junk and fail eventually.

This is hard to reproduce as the extended restore instruction doesn't
show up very often, and you have to be lucky to grab the "wrong" kind of
junk for the rule, leading GDB to an internal error.

This simple patch fixes the issue. Any thoughts? Ok to commit?

Best regards,
-- 
Luis Machado
Software Engineer 
IBM Linux Technology Center
2007-12-20  Luis Machado  <luisgpm@br.ibm.com>

    * dwarf2-frame.c (execute_cfa_program): Check if a register's rule
    is explicitly defined in the CIE before assignment, else force the
    default rule.

Index: gdb/dwarf2-frame.c
===================================================================
--- gdb.orig/dwarf2-frame.c	2007-10-21 12:33:37.000000000 -0700
+++ gdb/dwarf2-frame.c	2007-12-20 11:19:56.000000000 -0800
@@ -382,7 +382,14 @@
 	      insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
 	      reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
 	      dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
-	      fs->regs.reg[reg] = fs->initial.reg[reg];
+
+              /* Check if this register was explicitly initialized in the
+	      CIE initial instructions.  If not, default the rule to
+	      UNSPECIFIED.  */
+	      if (reg < fs->initial.num_regs)
+	        fs->regs.reg[reg] = fs->initial.reg[reg];
+	      else
+		fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNSPECIFIED;
 	      break;
 
 	    case DW_CFA_undefined:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]