#define DW64_CIE_ID ~0
#endif
+/* Defines the type of eh_frames that are expected to be decoded: CIE, FDE
+ or any of them. */
+
+enum eh_frame_type
+{
+ EH_CIE_TYPE_ID = 1 << 0,
+ EH_FDE_TYPE_ID = 1 << 1,
+ EH_CIE_OR_FDE_TYPE_ID = EH_CIE_TYPE_ID | EH_FDE_TYPE_ID
+};
+
static gdb_byte *decode_frame_entry (struct comp_unit *unit, gdb_byte *start,
int eh_frame_p,
struct dwarf2_cie_table *cie_table,
- struct dwarf2_fde_table *fde_table);
+ struct dwarf2_fde_table *fde_table,
+ enum eh_frame_type entry_type);
+
+/* Decode the next CIE or FDE, entry_type specifies the expected type.
+ Return NULL if invalid input, otherwise the next byte to be processed. */
-/* Decode the next CIE or FDE. Return NULL if invalid input, otherwise
- the next byte to be processed. */
static gdb_byte *
decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
struct dwarf2_cie_table *cie_table,
- struct dwarf2_fde_table *fde_table)
+ struct dwarf2_fde_table *fde_table,
+ enum eh_frame_type entry_type)
{
struct gdbarch *gdbarch = get_objfile_arch (unit->objfile);
gdb_byte *buf, *end;
char *augmentation;
unsigned int cie_version;
+ /* Check that a CIE was expected. */
+ if ((entry_type & EH_CIE_TYPE_ID) == 0)
+ error (_("Found a CIE when not expecting it."));
+
/* Record the offset into the .debug_frame section of this CIE. */
cie_pointer = start - unit->dwarf_frame_buffer;
/* This is a FDE. */
struct dwarf2_fde *fde;
+ /* Check that an FDE was expected. */
+ if ((entry_type & EH_FDE_TYPE_ID) == 0)
+ error (_("Found an FDE when not expecting it."));
+
/* In an .eh_frame section, the CIE pointer is the delta between the
address within the FDE where the CIE pointer is stored and the
address of the CIE. Convert it to an offset into the .eh_frame
if (fde->cie == NULL)
{
decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer,
- eh_frame_p, cie_table, fde_table);
+ eh_frame_p, cie_table, fde_table,
+ EH_CIE_TYPE_ID);
fde->cie = find_cie (cie_table, cie_pointer);
}
return end;
}
-/* Read a CIE or FDE in BUF and decode it. */
+/* Read a CIE or FDE in BUF and decode it. Entry_type specifies whether we
+ expect an FDE or a CIE. */
+
static gdb_byte *
decode_frame_entry (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
struct dwarf2_cie_table *cie_table,
- struct dwarf2_fde_table *fde_table)
+ struct dwarf2_fde_table *fde_table,
+ enum eh_frame_type entry_type)
{
enum { NONE, ALIGN4, ALIGN8, FAIL } workaround = NONE;
gdb_byte *ret;
while (1)
{
ret = decode_frame_entry_1 (unit, start, eh_frame_p,
- cie_table, fde_table);
+ cie_table, fde_table, entry_type);
if (ret != NULL)
break;
struct dwarf2_cie_table cie_table;
struct dwarf2_fde_table fde_table;
struct dwarf2_fde_table *fde_table2;
+ volatile struct gdb_exception e;
cie_table.num_entries = 0;
cie_table.entries = NULL;
if (txt)
unit->tbase = txt->vma;
- frame_ptr = unit->dwarf_frame_buffer;
- while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
- frame_ptr = decode_frame_entry (unit, frame_ptr, 1,
- &cie_table, &fde_table);
+ TRY_CATCH (e, RETURN_MASK_ERROR)
+ {
+ frame_ptr = unit->dwarf_frame_buffer;
+ while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
+ frame_ptr = decode_frame_entry (unit, frame_ptr, 1,
+ &cie_table, &fde_table,
+ EH_CIE_OR_FDE_TYPE_ID);
+ }
+
+ if (e.reason < 0)
+ {
+ warning (_("skipping .eh_frame info of %s: %s"),
+ objfile->name, e.message);
+
+ if (fde_table.num_entries != 0)
+ {
+ xfree (fde_table.entries);
+ fde_table.entries = NULL;
+ fde_table.num_entries = 0;
+ }
+ /* The cie_table is discarded by the next if. */
+ }
if (cie_table.num_entries != 0)
{
&unit->dwarf_frame_size);
if (unit->dwarf_frame_size)
{
- frame_ptr = unit->dwarf_frame_buffer;
- while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
- frame_ptr = decode_frame_entry (unit, frame_ptr, 0,
- &cie_table, &fde_table);
+ int num_old_fde_entries = fde_table.num_entries;
+
+ TRY_CATCH (e, RETURN_MASK_ERROR)
+ {
+ frame_ptr = unit->dwarf_frame_buffer;
+ while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
+ frame_ptr = decode_frame_entry (unit, frame_ptr, 0,
+ &cie_table, &fde_table,
+ EH_CIE_OR_FDE_TYPE_ID);
+ }
+ if (e.reason < 0)
+ {
+ warning (_("skipping .debug_frame info of %s: %s"),
+ objfile->name, e.message);
+
+ if (fde_table.num_entries != 0)
+ {
+ fde_table.num_entries = num_old_fde_entries;
+ if (num_old_fde_entries == 0)
+ {
+ xfree (fde_table.entries);
+ fde_table.entries = NULL;
+ }
+ else
+ {
+ fde_table.entries = xrealloc (fde_table.entries,
+ fde_table.num_entries *
+ sizeof (fde_table.entries[0]));
+ }
+ }
+ fde_table.num_entries = num_old_fde_entries;
+ /* The cie_table is discarded by the next if. */
+ }
}
/* Discard the cie_table, it is no longer needed. */