From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19495 invoked by alias); 5 Jul 2011 09:20:37 -0000 Received: (qmail 19485 invoked by uid 22791); 5 Jul 2011 09:20:36 -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-da02.nokia.com) (147.243.128.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Jul 2011 09:20:20 +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 p659JuDs004213; Tue, 5 Jul 2011 12:19:56 +0300 Received: from bettdhcp167109.europe.nokia.com ([bettdhcp167109.europe.nokia.com [172.25.167.109]]) by mgw-da02.nokia.com with RELAY id p659Jhde004049 ; Tue, 5 Jul 2011 12:19:47 +0300 Subject: Re: [PATCH,gdb, Update1]: 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: <20110704184111.GP2407@adacore.com> Date: Tue, 05 Jul 2011 10:44:00 -0000 Cc: , ext Tristan Gingold , Andr? P?nitz Content-Transfer-Encoding: quoted-printable Message-Id: <29C73230-F22F-4551-B99F-B21E6B61CCAF@nokia.com> References: <20110704184111.GP2407@adacore.com> To: ext Joel Brobecker 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/msg00144.txt.bz2 On Jul 4, 2011, at 8:41 PM, ext Joel Brobecker wrote: >> This increases the robustness of gdb, so I think it is worthwhile to add. >=20 > Indeed. > [...] Thanks for the comments Joel, here is a revised patch that hopefully addres= ses your issues Fawzi 2011-07-04 Fawzi Mohamed * dwarf2-frame.c (decode_frame_entry, decode_frame_entry_1): ensure that CIE pointer of an FDE 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 -p -d -u -r1.125 dwarf2-frame.c --- gdb/dwarf2-frame.c 4 Jul 2011 16:30:09 -0000 1.125 +++ gdb/dwarf2-frame.c 5 Jul 2011 09:07:59 -0000 @@ -1801,17 +1801,28 @@ add_fde (struct dwarf2_fde_table *fde_ta #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); =20 -/* Decode the next CIE or FDE. Return NULL if invalid input, otherwise - the next byte to be processed. */ +/* Decode the next CIE or FDE, entry type specifies the expected type. + 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 +1873,9 @@ decode_frame_entry_1 (struct comp_unit * char *augmentation; unsigned int cie_version; =20 + /* checks that we expected a CIE */ + gdb_assert ((entry_type & eh_cie_type_id) !=3D 0); + /* Record the offset into the .debug_frame section of this CIE. */ cie_pointer =3D start - unit->dwarf_frame_buffer; =20 @@ -2027,6 +2041,9 @@ decode_frame_entry_1 (struct comp_unit * /* This is a FDE. */ struct dwarf2_fde *fde; =20 + /* checks that we expected a FDE */ + gdb_assert ((entry_type & eh_fde_type_id) !=3D 0); + /* 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 +2065,8 @@ decode_frame_entry_1 (struct comp_unit * 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 +2107,12 @@ decode_frame_entry_1 (struct comp_unit * 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 +2121,8 @@ decode_frame_entry (struct comp_unit *un 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 +2276,8 @@ dwarf2_build_frame_info (struct objfile=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); + &cie_table, &fde_table, + eh_cie_or_fde_type_id); =20 if (cie_table.num_entries !=3D 0) {