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]

[RFC] robustify / align CIE parser with GCC's runtime unwinder


Hi all,

We have a compiler for one of our targets which generates slightly ill-formed CIE in the .eh_frame information. Although I believe it is a compiler bug, it makes GDB crash in a user-confusing way, and I propose a patch to align GDB's CIE parser with the one from GCC's runtime unwinder (which copes with the .eh_frame information generated by our compiler).


More details: when there is no LSDA info, our compiler generates correctly "zP" as augmentation string, but adds a final -1 byte to the augmentation data, and the augmentation data length field takes this into account.


When parsing this CIE info, GCC's unwinder (extract_cie_info in unwind-dw2.c in GCC-3.3.3), defines the pointer to the "initial instructions" as "augmentation data addr + length(augmentation data)", and is OK.

By contrast, GDB's decode_frame_entry_1 (dwarf2-frame.c) first uses this same definition when parsing the 'z' byte, but later overwrites it after parsing the augmentation string: cie->initial_instructions = buf, where buf points just after the last *read* byte from augmentation data. In our case, it points to the trailing -1 I mentioned above.

This remains unnoticed until the information is actually used:
internal-error: execute_cfa_program: Assertion `fs->initial.reg' failed.
A problem internal to GDB has been detected....


The small patch I propose here aligns GDB to GCC's behaviour.


(I have also fixed our compiler ;-)

Are you OK with this patch?

Regards,

Christophe.


2008-11-07  Christophe Lyon  <christophe.lyon@st.com>

	* dwarf2-frame.c (decode_frame_entry_1): Trust augmentation data
	length when computing cie->initial_instructions.

Index: dwarf2-frame.c
===================================================================
--- dwarf2-frame.c	(revision 260)
+++ dwarf2-frame.c	(working copy)
@@ -1888,7 +1888,20 @@ decode_frame_entry_1 (struct comp_unit *
 	    }
 	}
 
+      /* Some compilers keep room for LSDA even if none is used.
+         Augmentation data length reflects this, so trust the value of
+         initial_instructions already computed. Otherwise, it would
+         result in confusing GDB crashes much later because
+         initial_instructions points to an incorrect address.  */
+      if (cie->initial_instructions != NULL && cie->initial_instructions != buf)
+        {
+          complaint (&symfile_complaints, _("inconsistent eh_frame CIE in %s \
+(augmentation length does not match augmentation contents)"),
+               unit->abfd->filename);
+        }
+      else 
       cie->initial_instructions = buf;
+
       cie->end = end;
 
       add_cie (unit, cie);

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