From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24752 invoked by alias); 4 Jul 2011 18:12:23 -0000 Received: (qmail 24743 invoked by uid 22791); 4 Jul 2011 18:12:22 -0000 X-SWARE-Spam-Status: No, hits=-1.5 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-sa01.nokia.com) (147.243.1.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Jul 2011 18:12:06 +0000 Received: from nokia.com (localhost [127.0.0.1]) by mgw-sa01.nokia.com (Switch-3.4.4/Switch-3.4.3) with ESMTP id p64IAoo7014771; Mon, 4 Jul 2011 21:11:50 +0300 Received: from bettdhcp167180.europe.nokia.com ([bettdhcp167180.europe.nokia.com [172.25.167.180]]) by mgw-sa01.nokia.com with RELAY id p64IBVN8015456 ; Mon, 4 Jul 2011 21:11:33 +0300 From: Fawzi Mohamed Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: [PATCH,gdb]: ensures that cie ptr of an fda is a cie Date: Mon, 04 Jul 2011 18:19:00 -0000 Message-Id: Cc: ext Tristan Gingold , =?iso-8859-1?Q?Andr=E9_P=F6nitz?= To: gdb-patches@sourceware.org Mime-Version: 1.0 (Apple Message framework v1084) 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/msg00104.txt.bz2 Here is a patch that ensures that cie pointer of a fda really points to a c= ie. This avoids infinite loops if a fda cie pointer points to itself, as was th= e case on mac when the mmaped read section was broken for fat binaries and returned=20 invalid info (see http://sourceware.org/bugzilla/show_bug.cgi?id=3D11488 ). This increases the robustness of gdb, so I think it is worthwhile to add. Fawzi 2011-07-04 Fawzi Mohamed * dwarf2-frame.c (decode_frame_entry, decode_frame_entry_1): ensure that cie pointer really points to a cie=20 Index: gdb/dwarf2-frame.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v retrieving revision 1.125 diff -d -u -r1.125 dwarf2-frame.c --- gdb/dwarf2-frame.c 4 Jul 2011 16:30:09 -0000 1.125 +++ gdb/dwarf2-frame.c 4 Jul 2011 17:39:29 -0000 @@ -1801,17 +1801,25 @@ #define DW64_CIE_ID ~0 #endif =20 +enum eh_frame_type { + eh_cie_type_id =3D 1, + eh_fde_type_id =3D 2, + eh_cie_or_fde_type_id =3D 3 +}; + 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); =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 +1870,8 @@ char *augmentation; unsigned int cie_version; =20 + gdb_assert ((entry_type & eh_cie_type_id)!=3D0); + /* Record the offset into the .debug_frame section of this CIE. */ cie_pointer =3D start - unit->dwarf_frame_buffer; =20 @@ -2027,6 +2037,8 @@ /* This is a FDE. */ struct dwarf2_fde *fde; =20 + gdb_assert ((entry_type & eh_fde_type_id)!=3D0); + /* 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 +2060,8 @@ 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 @@ -2093,7 +2106,8 @@ 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 +2116,8 @@ while (1) { ret =3D decode_frame_entry_1 (unit, start, eh_frame_p, - cie_table, fde_table); + cie_table, fde_table,entry_type, + entry_type); if (ret !=3D NULL) break; =20 @@ -2256,7 +2271,8 @@ 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); + &cie_table, &fde_table, + eh_cie_or_fde_type_id); =20 if (cie_table.num_entries !=3D 0) {