Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Klee Dienes <klee@apple.com>
To: Jim Blandy <jimb@redhat.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA] Handle stack underflow in dbxread.c
Date: Mon, 18 Nov 2002 11:16:00 -0000	[thread overview]
Message-ID: <3908551A-FB2A-11D6-84AF-00039396EEB8@apple.com> (raw)
In-Reply-To: <vt2u1ielqs7.fsf@zenia.red-bean.com>

[-- Attachment #1: Type: text/plain, Size: 293 bytes --]

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:


[-- Attachment #2: check-context.txt --]
[-- Type: text/plain, Size: 3273 bytes --]

2002-11-18  Klee Dienes  <kdienes@apple.com>

        * 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
===================================================================
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 @@
 
   return new;
 }
+
+struct context_stack *
+pop_context (void)
+{
+  gdb_assert (context_stack_depth > 0);
+  return (&context_stack[--context_stack_depth]);
+}
+
 \f
 
 /* Compute a small integer hash code for the given name. */
Index: buildsym.h
===================================================================
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 @@
 
 EXTERN int context_stack_size;
 
-/* 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 == 0)
 
@@ -271,6 +265,8 @@
 extern void buildsym_init (void);
 
 extern struct context_stack *push_context (int desc, CORE_ADDR valu);
+
+extern struct context_stack *pop_context (void);
 
 extern void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
 
Index: dbxread.c
===================================================================
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 <= 0)
+ 	    {
+ 	      complain (&lbrac_mismatch_complaint, symnum);
+ 	      break;
+ 	    }
+
 	  record_line (current_subfile, 0, function_start_offset + valu);
 	  within_function = 0;
 	  new = 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 += last_source_start_addr;
+
+      if (context_stack_depth <= 0)
+	{
+	  complain (&lbrac_mismatch_complaint, symnum);
+	  break;
+	}
 
       new = pop_context ();
       if (desc != new->depth)

  reply	other threads:[~2002-11-18 19:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-15  1:02 Klee Dienes
2002-11-15 12:18 ` Jim Blandy
2002-11-15 13:19   ` Klee Dienes
2002-11-18  9:57     ` Jim Blandy
2002-11-18 11:16       ` Klee Dienes [this message]
2002-11-18 12:42         ` Andrew Cagney
2002-11-18 13:06           ` Klee Dienes
2002-11-18 13:18             ` Andrew Cagney
2002-11-18 13:43               ` Klee Dienes
2002-11-18 13:18         ` Jim Blandy
2002-11-18 13:53           ` Klee Dienes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3908551A-FB2A-11D6-84AF-00039396EEB8@apple.com \
    --to=klee@apple.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=jimb@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox