From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21961 invoked by alias); 7 Jul 2011 16:16:49 -0000 Received: (qmail 21950 invoked by uid 22791); 7 Jul 2011 16:16:47 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,TVD_RCVD_SPACE_BRACKET,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp.nokia.com (HELO mgw-da02.nokia.com) (147.243.128.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Jul 2011 16:16:32 +0000 Received: from nokia.com (localhost [127.0.0.1]) by mgw-da02.nokia.com (Switch-3.4.4/Switch-3.4.3) with ESMTP id p67GG6Ir019330; Thu, 7 Jul 2011 19:16:06 +0300 Received: from bettdhcp167105.europe.nokia.com ([bettdhcp167105.europe.nokia.com [172.25.167.105]]) by mgw-da02.nokia.com with RELAY id p67GG22d019276 ; Thu, 7 Jul 2011 19:16:05 +0300 Subject: Re: [PATCH,gdb,Update4]: ensures that cie ptr of an fda is a cie Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Fawzi Mohamed In-Reply-To: <20110706170323.GA28535@host1.jankratochvil.net> Date: Thu, 07 Jul 2011 17:17:00 -0000 Cc: , ext Tristan Gingold , =?iso-8859-1?Q?Andr=E9_P=F6nitz?= Content-Transfer-Encoding: quoted-printable Message-Id: <4A77D598-9262-4A47-813D-0CD977E9DA68@nokia.com> References: <0FC98010-6811-4715-BD3B-AE8B9221C7BF@nokia.com> <20110706170323.GA28535@host1.jankratochvil.net> To: ext Jan Kratochvil X-Nokia-AV: Clean Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00241.txt.bz2 On Jul 6, 2011, at 7:03 PM, ext Jan Kratochvil wrote: > On Wed, 06 Jul 2011 16:40:14 +0200, Fawzi Mohamed wrote: >> +/* Defines the type of eh_frames that are expected to be decoded: CIE, = FDE >> + or any of them. */ > ^^^ Two spaces at the end of line. done >> + >> +enum eh_frame_type >> +{ >> + EH_CIE_TYPE_ID =3D 1 << 0, >> + EH_FDE_TYPE_ID =3D 1 << 1, >> + EH_CIE_OR_FDE_TYPE_ID =3D EH_CIE_TYPE_ID + EH_FDE_TYPE_ID >=20 > A nitpick but the intended operation is | , not + . well for non overlapping masks + is the same, and as it was what had been p= roposed I used it, but I also find | better. In the previous version I had switched to error from gdb_assert, but had no= t yet controlled to which handler it went. The handler is in solib_read_symbols, and it is silent if one uses it insid= e an IDE (no tty). That skips the whole so lib, so I have added handlers to= dwarf2_build_frame_info that prints a warning and skip only the corrupted = eh_fame section. Here is updated patch: 2011-07-07 Fawzi Mohamed * dwarf2-frame.c (decode_frame_entry, decode_frame_entry_1): Ensure that CIE pointer of an FDE really points to a CIE . diff --git a/fsfGdb.config b/fsfGdb.config index e69de29..8cec188 100644 --- a/fsfGdb.config +++ b/fsfGdb.config @@ -0,0 +1 @@ +// ADD PREDEFINED MACROS HERE! diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index b68a773..a3c19ee 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -1801,17 +1801,30 @@ add_fde (struct dwarf2_fde_table *fde_table, struct= dwarf2_fde *fde) #define DW64_CIE_ID ~0 #endif =20 +/* 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 =3D 1 << 0, + EH_FDE_TYPE_ID =3D 1 << 1, + EH_CIE_OR_FDE_TYPE_ID =3D EH_CIE_TYPE_ID | EH_FDE_TYPE_ID +}; + static gdb_byte *decode_frame_entry (struct comp_unit *unit, gdb_byte *sta= rt, 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. = */ =20 -/* 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_fram= e_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 =3D get_objfile_arch (unit->objfile); gdb_byte *buf, *end; @@ -1862,6 +1875,10 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_by= te *start, int eh_frame_p, char *augmentation; unsigned int cie_version; =20 + /* Check that a CIE was expected. */ + if ((entry_type & EH_CIE_TYPE_ID) =3D=3D 0) + error (_("Found a CIE when not expecting it, broken eh_info")); + /* Record the offset into the .debug_frame section of this CIE. */ cie_pointer =3D start - unit->dwarf_frame_buffer; =20 @@ -2027,6 +2044,10 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_by= te *start, int eh_frame_p, /* This is a FDE. */ struct dwarf2_fde *fde; =20 + /* Check that an FDE was expected. */ + if ((entry_type & EH_FDE_TYPE_ID) =3D=3D 0) + error (_("Found an FDE when not expecting it, broken eh_info.")); + /* 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 @@ -2048,7 +2069,8 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_byt= e *start, int eh_frame_p, if (fde->cie =3D=3D 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 =3D find_cie (cie_table, cie_pointer); } =20 @@ -2089,11 +2111,14 @@ decode_frame_entry_1 (struct comp_unit *unit, gdb_b= yte *start, int eh_frame_p, return end; } =20 -/* Read a CIE or FDE in BUF and decode it. */ +/* Read a CIE or FDE in BUF and decode it. Entry_type specifies if we expe= ct + 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 =3D NONE; gdb_byte *ret; @@ -2102,7 +2127,7 @@ decode_frame_entry (struct comp_unit *unit, gdb_byte = *start, int eh_frame_p, while (1) { ret =3D decode_frame_entry_1 (unit, start, eh_frame_p, - cie_table, fde_table); + cie_table, fde_table, entry_type); if (ret !=3D NULL) break; =20 @@ -2212,6 +2237,7 @@ dwarf2_build_frame_info (struct objfile *objfile) struct dwarf2_cie_table cie_table; struct dwarf2_fde_table fde_table; struct dwarf2_fde_table *fde_table2; + volatile struct gdb_exception e; =20 cie_table.num_entries =3D 0; cie_table.entries =3D NULL; @@ -2253,10 +2279,27 @@ dwarf2_build_frame_info (struct objfile *objfile) if (txt) unit->tbase =3D txt->vma; =20 - frame_ptr =3D unit->dwarf_frame_buffer; - while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_= size) - frame_ptr =3D decode_frame_entry (unit, frame_ptr, 1, - &cie_table, &fde_table); + TRY_CATCH (e, RETURN_MASK_ERROR) + { + frame_ptr =3D unit->dwarf_frame_buffer; + while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_siz= e) + frame_ptr =3D 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.me= ssage); + + if (fde_table.num_entries !=3D 0) + { + xfree(fde_table.entries); + fde_table.entries =3D NULL; + fde_table.num_entries =3D 0; + } + /* cie_table is discarded by the next if. */ + } =20 if (cie_table.num_entries !=3D 0) { @@ -2274,10 +2317,37 @@ dwarf2_build_frame_info (struct objfile *objfile) &unit->dwarf_frame_size); if (unit->dwarf_frame_size) { - frame_ptr =3D unit->dwarf_frame_buffer; - while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size) - frame_ptr =3D decode_frame_entry (unit, frame_ptr, 0, - &cie_table, &fde_table); + int num_old_fde_entries =3D fde_table.num_entries; + + TRY_CATCH (e, RETURN_MASK_ERROR) + { + frame_ptr =3D unit->dwarf_frame_buffer; + while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size) + frame_ptr =3D 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.mes= sage); + + if (fde_table.num_entries !=3D 0) + { + fde_table.num_entries =3D num_old_fde_entries; + if (num_old_fde_entries =3D=3D 0) + { + xfree(fde_table.entries); + fde_table.entries =3D NULL; + } + else + { + xrealloc (fde_table.entries, + fde_table.num_entries * sizeof (fde_table.entries[0])); + } + } + fde_table.num_entries =3D num_old_fde_entries; + /* cie_table is discarded by the next if */ + } } =20 /* Discard the cie_table, it is no longer needed. */