From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10101 invoked by alias); 18 Nov 2002 19:16:30 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 10083 invoked from network); 18 Nov 2002 19:16:24 -0000 Received: from unknown (HELO dc-mx02.cluster1.charter.net) (209.225.8.12) by sources.redhat.com with SMTP; 18 Nov 2002 19:16:24 -0000 Received: from [66.189.46.2] (HELO platinum.local.) by dc-mx02.cluster1.charter.net (CommuniGate Pro SMTP 3.5.9) with ESMTP id 6574831; Mon, 18 Nov 2002 14:16:23 -0500 Date: Mon, 18 Nov 2002 11:16:00 -0000 Subject: Re: [RFA] Handle stack underflow in dbxread.c Content-Type: multipart/mixed; boundary=Apple-Mail-4--789760309 Mime-Version: 1.0 (Apple Message framework v543) Cc: gdb-patches@sources.redhat.com To: Jim Blandy From: Klee Dienes In-Reply-To: Message-Id: <3908551A-FB2A-11D6-84AF-00039396EEB8@apple.com> X-SW-Source: 2002-11/txt/msg00464.txt.bz2 --Apple-Mail-4--789760309 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 293 On Monday, November 18, 2002, at 12:40 PM, Jim Blandy wrote: > > Okay, that looks like a good change to me --- please commit it. > > But rather than making pop_context a hairy macro, could you make it a > function in buildsym.c, right after push_context? Gladly. Committed the following: --Apple-Mail-4--789760309 Content-Disposition: attachment; filename=check-context.txt Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; x-unix-mode=0644; name="check-context.txt" Content-length: 3620 2002-11-18 Klee Dienes * buildsym.h (pop_context): Convert to function, defined in buildsym.c. * buildsym.c: Include gdb_assert.h. (pop_context): Implement as C function. Add check for stack underflow. * dbxread.c (process_one_symbol): Complain and stop processing that symbol if we are already at the top of the context stack for a function-end N_FUN (this would imply an umatched RBRAC). Ditto when processing N_RBRAC. Index: buildsym.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/buildsym.c,v retrieving revision 1.21 diff -u -r1.21 buildsym.c --- buildsym.c 25 Oct 2002 22:25:55 -0000 1.21 +++ buildsym.c 18 Nov 2002 19:13:17 -0000 @@ -33,6 +33,7 @@ #include "symfile.h" #include "objfiles.h" #include "gdbtypes.h" +#include "gdb_assert.h" #include "complaints.h" #include "gdb_string.h" #include "expression.h" /* For "enum exp_opcode" used by... */ @@ -1100,6 +1101,14 @@ =20 return new; } + +struct context_stack * +pop_context (void) +{ + gdb_assert (context_stack_depth > 0); + return (&context_stack[--context_stack_depth]); +} + =0C =20 /* Compute a small integer hash code for the given name. */ Index: buildsym.h =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/buildsym.h,v retrieving revision 1.6 diff -u -r1.6 buildsym.h --- buildsym.h 8 Nov 2002 20:05:10 -0000 1.6 +++ buildsym.h 18 Nov 2002 19:13:17 -0000 @@ -173,12 +173,6 @@ =20 EXTERN int context_stack_size; =20 -/* Macro "function" for popping contexts from the stack. Pushing is - done by a real function, push_context. This returns a pointer to a - struct context_stack. */ - -#define pop_context() (&context_stack[--context_stack_depth]); - /* Non-zero if the context stack is empty. */ #define outermost_context_p() (context_stack_depth =3D=3D 0) =20 @@ -271,6 +265,8 @@ extern void buildsym_init (void); =20 extern struct context_stack *push_context (int desc, CORE_ADDR valu); + +extern struct context_stack *pop_context (void); =20 extern void record_line (struct subfile *subfile, int line, CORE_ADDR pc); =20 Index: dbxread.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/dbxread.c,v retrieving revision 1.36 diff -u -r1.36 dbxread.c --- dbxread.c 25 Oct 2002 22:25:55 -0000 1.36 +++ dbxread.c 18 Nov 2002 19:13:18 -0000 @@ -2774,6 +2774,13 @@ { /* This N_FUN marks the end of a function. This closes off the current block. */ + + if (context_stack_depth <=3D 0) + { + complain (&lbrac_mismatch_complaint, symnum); + break; + } + record_line (current_subfile, 0, function_start_offset + valu); within_function =3D 0; new =3D pop_context (); @@ -2842,6 +2849,12 @@ /* On most machines, the block addresses are relative to the N_SO, the linker did not relocate them (sigh). */ valu +=3D last_source_start_addr; + + if (context_stack_depth <=3D 0) + { + complain (&lbrac_mismatch_complaint, symnum); + break; + } =20 new =3D pop_context (); if (desc !=3D new->depth) --Apple-Mail-4--789760309--