Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: David Carlton <carlton@math.stanford.edu>
To: gdb-patches@sources.redhat.com
Cc: Elena Zannoni <ezannoni@redhat.com>, Jim Blandy <jimb@redhat.com>,
	Fernando Nasser <fnasser@redhat.com>
Subject: [rfa] linespec.c, part 2
Date: Fri, 08 Nov 2002 11:52:00 -0000	[thread overview]
Message-ID: <ro1adkjalf6.fsf@jackfruit.Stanford.EDU> (raw)

Here's part 2 of the linespec patches.  This one's quite
straightforward; it just moves two chunks of code from the beginning
of decode_line_1 to separate functions initialize_defaults and
decode_indirect.  Also, it turns out that, later in decode_line_1,
defaults get re-initialized, so I turned that into a second call to
initialize_defaults.

David Carlton
carlton@math.stanford.edu

2002-11-07  David Carlton  <carlton@math.stanford.edu>

	* linespec.c (decode_line_1): Move chunks of code to separate
	functions.
	(initialize_defaults): New function.
	(decode_indirect): New function.

Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.26
diff -u -p -r1.26 linespec.c
--- linespec.c	8 Nov 2002 19:16:17 -0000	1.26
+++ linespec.c	8 Nov 2002 19:21:33 -0000
@@ -39,6 +39,11 @@ extern char *operator_chars (char *, cha
 
 /* Prototypes for local functions */
 
+static void initialize_defaults (struct symtab **default_symtab,
+				 int *default_line);
+
+static struct symtabs_and_lines decode_indirect (char **argptr);
+
 static void cplusplus_error (const char *name, const char *fmt, ...) ATTR_FORMAT (printf, 2, 3);
 
 static int total_number_of_methods (struct type *type);
@@ -533,7 +538,6 @@ decode_line_1 (char **argptr, int funfir
   /* The symtab that SYM was found in.  */
   struct symtab *sym_symtab;
 
-  register CORE_ADDR pc;
   register struct minimal_symbol *msymbol;
   char *copy;
   struct symbol *sym_class;
@@ -552,35 +556,12 @@ decode_line_1 (char **argptr, int funfir
 
   /* Defaults have defaults.  */
 
-  if (default_symtab == 0)
-    {
-      /* Use whatever we have for the default source line.  We don't use
-         get_current_or_default_symtab_and_line as it can recurse and call
-	 us back! */
-      struct symtab_and_line cursal = 
-      			get_current_source_symtab_and_line ();
-      
-      default_symtab = cursal.symtab;
-      default_line = cursal.line;
-    }
-
+  initialize_defaults (&default_symtab, &default_line);
+  
   /* See if arg is *PC */
 
   if (**argptr == '*')
-    {
-      (*argptr)++;
-      pc = parse_and_eval_address_1 (argptr);
-
-      values.sals = (struct symtab_and_line *)
-	xmalloc (sizeof (struct symtab_and_line));
-
-      values.nelts = 1;
-      values.sals[0] = find_pc_line (pc, 0);
-      values.sals[0].pc = pc;
-      values.sals[0].section = find_pc_overlay (pc);
-
-      return values;
-    }
+    return decode_indirect (argptr);
 
   /* 'has_if' is for the syntax:
    *     (gdb) break foo if (a==b)
@@ -1034,10 +1015,7 @@ decode_line_1 (char **argptr, int funfir
 
 	  /* Make sure we have at least a default source file. */
 	  set_default_source_symtab_and_line ();
-          cursal = get_current_source_symtab_and_line ();
-      
-          default_symtab = cursal.symtab;
-          default_line = cursal.line;
+	  initialize_defaults (&default_symtab, &default_line);
 	}
 
       if (**argptr == '+')
@@ -1211,6 +1189,58 @@ decode_line_1 (char **argptr, int funfir
   return values;		/* for lint */
 }
 
+\f
+
+/* Now, still more helper functions.  */
+
+/* NOTE: carlton/2002-11-07: Some of these have non-obvious side
+   effects.  In particular, if a function is passed ARGPTR as an
+   argument, it modifies what ARGPTR points to.  (Typically, it
+   advances *ARGPTR past whatever substring it has just looked
+   at.)  */
+
+/* First, some functions to initialize stuff at the beggining of the
+   function.  */
+
+static void
+initialize_defaults (struct symtab **default_symtab, int *default_line)
+{
+  if (*default_symtab == 0)
+    {
+      /* Use whatever we have for the default source line.  We don't use
+         get_current_or_default_symtab_and_line as it can recurse and call
+	 us back! */
+      struct symtab_and_line cursal = 
+	get_current_source_symtab_and_line ();
+      
+      *default_symtab = cursal.symtab;
+      *default_line = cursal.line;
+    }
+}
+
+\f
+
+/* Decode arg of the form *PC.  */
+
+static struct symtabs_and_lines
+decode_indirect (char **argptr)
+{
+  struct symtabs_and_lines values;
+  CORE_ADDR pc;
+  
+  (*argptr)++;
+  pc = parse_and_eval_address_1 (argptr);
+
+  values.sals = (struct symtab_and_line *)
+    xmalloc (sizeof (struct symtab_and_line));
+
+  values.nelts = 1;
+  values.sals[0] = find_pc_line (pc, 0);
+  values.sals[0].pc = pc;
+  values.sals[0].section = find_pc_overlay (pc);
+
+  return values;
+}
 
 \f
 


             reply	other threads:[~2002-11-08 19:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-08 11:52 David Carlton [this message]
2002-11-11  7:42 ` Elena Zannoni
2002-11-11 17:15   ` David Carlton

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=ro1adkjalf6.fsf@jackfruit.Stanford.EDU \
    --to=carlton@math.stanford.edu \
    --cc=ezannoni@redhat.com \
    --cc=fnasser@redhat.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