This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] decode_line_spec_* cleanup, V2


Here's another way to do this.
ref: http://sourceware.org/ml/gdb-patches/2012-06/msg00861.html

Ok to check this version in?
[regression tests still running, I'll update if they fail]

2012-06-28  Doug Evans  <dje@google.com>

	* breakpoint.c (decode_line_spec_1): Delete, functionality folded
	into decode_line_spec.  All callers updated.
	* linespec.c: #include "stack.h".
	(decode_line_spec): Moved here from symtab.c.  New arg "default_kind".
	All callers updated.
	* linespec.h (enum decode_line_default_kind): New enum.
	(decode_line_spec): Declaration moved here from symtab.h.
	* symtab.h (decode_line_spec_1): Delete.
	* macrocmd.c: #include "linespec.h".
	* symtab.c: Remove #include "linespec.h".

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.685
diff -u -p -r1.685 breakpoint.c
--- breakpoint.c	27 Jun 2012 18:08:39 -0000	1.685
+++ breakpoint.c	28 Jun 2012 20:32:56 -0000
@@ -11532,8 +11532,10 @@ clear_command (char *arg, int from_tty)
 
   if (arg)
     {
-      sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
-				     | DECODE_LINE_LIST_MODE));
+      sals = decode_line_spec (arg,
+			       (DECODE_LINE_FUNFIRSTLINE
+				| DECODE_LINE_LIST_MODE),
+			       DECODE_LINE_DEFAULT_CURRENT_SOURCE);
       default_match = 0;
     }
   else
@@ -14494,27 +14496,6 @@ invalidate_bp_value_on_memory_change (CO
       }
 }
 
-/* Use the last displayed codepoint's values, or nothing
-   if they aren't valid.  */
-
-struct symtabs_and_lines
-decode_line_spec_1 (char *string, int flags)
-{
-  struct symtabs_and_lines sals;
-
-  if (string == 0)
-    error (_("Empty line specification."));
-  if (last_displayed_sal_is_valid ())
-    sals = decode_line_1 (&string, flags,
-			  get_last_displayed_symtab (),
-			  get_last_displayed_line ());
-  else
-    sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
-  if (*string)
-    error (_("Junk at end of line specification: %s"), string);
-  return sals;
-}
-
 /* Create and insert a raw software breakpoint at PC.  Return an
    identifier, which should be used to remove the breakpoint later.
    In general, places which call this should be using something on the
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.305
diff -u -p -r1.305 infcmd.c
--- infcmd.c	12 Jun 2012 16:36:42 -0000	1.305
+++ infcmd.c	28 Jun 2012 20:32:56 -0000
@@ -1140,7 +1140,8 @@ jump_command (char *arg, int from_tty)
   if (!arg)
     error_no_arg (_("starting address"));
 
-  sals = decode_line_spec_1 (arg, DECODE_LINE_FUNFIRSTLINE);
+  sals = decode_line_spec (arg, DECODE_LINE_FUNFIRSTLINE,
+			   DECODE_LINE_DEFAULT_LAST_DISPLAYED);
   if (sals.nelts != 1)
     {
       error (_("Unreasonable jump request"));
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.158
diff -u -p -r1.158 linespec.c
--- linespec.c	4 Jun 2012 02:57:28 -0000	1.158
+++ linespec.c	28 Jun 2012 20:32:56 -0000
@@ -43,6 +43,7 @@
 #include "cli/cli-utils.h"
 #include "filenames.h"
 #include "ada-lang.h"
+#include "stack.h"
 
 typedef struct symtab *symtab_p;
 DEF_VEC_P (symtab_p);
@@ -2325,6 +2326,8 @@ decode_line_full (char **argptr, int fla
   do_cleanups (cleanups);
 }
 
+/* See linespec.h.  */
+
 struct symtabs_and_lines
 decode_line_1 (char **argptr, int flags,
 	       struct symtab *default_symtab,
@@ -2345,6 +2348,44 @@ decode_line_1 (char **argptr, int flags,
   return result;
 }
 
+/* See linespec.h.  */
+
+struct symtabs_and_lines
+decode_line_spec (char *string, int flags,
+		  enum decode_line_default_kind default_kind)
+{
+  struct symtabs_and_lines sals;
+  struct symtab_and_line cursal;
+
+  if (string == 0)
+    error (_("Empty line specification."));
+
+  switch (default_kind)
+    {
+    case DECODE_LINE_DEFAULT_CURRENT_SOURCE:
+      /* We use whatever is set as the current source line.  We do not try
+	 and get a default  or it will recursively call us!  */
+      cursal = get_current_source_symtab_and_line ();
+      sals = decode_line_1 (&string, flags,
+			    cursal.symtab, cursal.line);
+      break;
+    case DECODE_LINE_DEFAULT_LAST_DISPLAYED:
+      if (last_displayed_sal_is_valid ())
+	sals = decode_line_1 (&string, flags,
+			      get_last_displayed_symtab (),
+			      get_last_displayed_line ());
+      else
+	sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
+      break;
+    default:
+      gdb_assert_not_reached ("unexpected decode_line_spec default kind");
+    }
+
+  if (*string)
+    error (_("Junk at end of line specification: %s"), string);
+  return sals;
+}
+
 
 
 /* First, some functions to initialize stuff at the beggining of the
Index: linespec.h
===================================================================
RCS file: /cvs/src/src/gdb/linespec.h,v
retrieving revision 1.16
diff -u -p -r1.16 linespec.h
--- linespec.h	4 Jan 2012 08:17:05 -0000	1.16
+++ linespec.h	28 Jun 2012 20:32:56 -0000
@@ -35,6 +35,14 @@ enum decode_line_flags
     DECODE_LINE_LIST_MODE = 2
   };
 
+/* The value to pass to decode_line_spec to specify the default to use.  */
+
+enum decode_line_default_kind
+  {
+    DECODE_LINE_DEFAULT_CURRENT_SOURCE,
+    DECODE_LINE_DEFAULT_LAST_DISPLAYED
+  };
+
 /* decode_line_full returns a vector of these.  */
 
 struct linespec_sals
@@ -93,10 +101,21 @@ extern void destroy_linespec_result (str
 extern struct cleanup *
         make_cleanup_destroy_linespec_result (struct linespec_result *);
 
+/* Decode a linespec using the provided default symtab and line.  */
+
 extern struct symtabs_and_lines
 	decode_line_1 (char **argptr, int flags,
 		       struct symtab *default_symtab, int default_line);
 
+/* Utility wrapper around decode_line_1 to use the specified default.
+   If STRING is empty or contains junk at the end of the linespec
+   an error is raised.
+   FLAGS is passed as is to decode_line_1.  */
+
+extern struct symtabs_and_lines
+	decode_line_spec (char *string, int flags,
+			  enum decode_line_default_kind);
+
 /* Parse *ARGPTR as a linespec and return results.  This is the "full"
    interface to this module, which handles multiple results
    properly.
Index: macrocmd.c
===================================================================
RCS file: /cvs/src/src/gdb/macrocmd.c,v
retrieving revision 1.28
diff -u -p -r1.28 macrocmd.c
--- macrocmd.c	4 Jan 2012 08:17:06 -0000	1.28
+++ macrocmd.c	28 Jun 2012 20:32:56 -0000
@@ -26,6 +26,7 @@
 #include "command.h"
 #include "gdbcmd.h"
 #include "gdb_string.h"
+#include "linespec.h"
 
 
 /* The `macro' prefix command.  */
@@ -282,7 +283,8 @@ info_macros_command (char *args, int fro
     ms = default_macro_scope ();
   else
     {
-      struct symtabs_and_lines sals = decode_line_spec (args, 0);
+      struct symtabs_and_lines sals =
+	decode_line_spec (args, 0, DECODE_LINE_DEFAULT_CURRENT_SOURCE);
 
       if (sals.nelts)
         ms = sal_macro_scope (sals.sals[0]);
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.135
diff -u -p -r1.135 source.c
--- source.c	30 May 2012 03:42:21 -0000	1.135
+++ source.c	28 Jun 2012 20:32:56 -0000
@@ -243,7 +243,8 @@ select_source_symtab (struct symtab *s)
      if one exists.  */
   if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0))
     {
-      sals = decode_line_spec (main_name (), DECODE_LINE_FUNFIRSTLINE);
+      sals = decode_line_spec (main_name (), DECODE_LINE_FUNFIRSTLINE,
+			       DECODE_LINE_DEFAULT_CURRENT_SOURCE);
       sal = sals.sals[0];
       xfree (sals.sals);
       current_source_pspace = sal.pspace;
@@ -1405,8 +1406,8 @@ line_info (char *arg, int from_tty)
     }
   else
     {
-      sals = decode_line_spec_1 (arg, DECODE_LINE_LIST_MODE);
-
+      sals = decode_line_spec (arg, DECODE_LINE_LIST_MODE,
+			       DECODE_LINE_DEFAULT_LAST_DISPLAYED);
       dont_repeat ();
     }
 
Index: stack.c
===================================================================
RCS file: /cvs/src/src/gdb/stack.c,v
retrieving revision 1.253
diff -u -p -r1.253 stack.c
--- stack.c	18 May 2012 21:02:50 -0000	1.253
+++ stack.c	28 Jun 2012 20:32:56 -0000
@@ -2373,7 +2373,8 @@ func_command (char *arg, int from_tty)
     return;
 
   frame = parse_frame_specification ("0");
-  sals = decode_line_spec (arg, DECODE_LINE_FUNFIRSTLINE);
+  sals = decode_line_spec (arg, DECODE_LINE_FUNFIRSTLINE,
+			   DECODE_LINE_DEFAULT_CURRENT_SOURCE);
   cleanups = make_cleanup (xfree, sals.sals);
   func_bounds = (struct function_bounds *) xmalloc (
 			      sizeof (struct function_bounds) * sals.nelts);
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.315
diff -u -p -r1.315 symtab.c
--- symtab.c	28 Jun 2012 18:56:52 -0000	1.315
+++ symtab.c	28 Jun 2012 20:32:56 -0000
@@ -33,7 +33,6 @@
 #include "language.h"
 #include "demangle.h"
 #include "inferior.h"
-#include "linespec.h"
 #include "source.h"
 #include "filenames.h"		/* for FILENAME_CMP */
 #include "objc-lang.h"
@@ -4821,27 +4820,6 @@ skip_prologue_using_sal (struct gdbarch 
     return prologue_sal.pc;
 }
 
-struct symtabs_and_lines
-decode_line_spec (char *string, int flags)
-{
-  struct symtabs_and_lines sals;
-  struct symtab_and_line cursal;
-
-  if (string == 0)
-    error (_("Empty line specification."));
-
-  /* We use whatever is set as the current source line.  We do not try
-     and get a default  or it will recursively call us!  */
-  cursal = get_current_source_symtab_and_line ();
-
-  sals = decode_line_1 (&string, flags,
-			cursal.symtab, cursal.line);
-
-  if (*string)
-    error (_("Junk at end of line specification: %s"), string);
-  return sals;
-}
-
 /* Track MAIN */
 static char *name_of_main;
 enum language language_of_main = language_unknown;
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.209
diff -u -p -r1.209 symtab.h
--- symtab.h	26 Jun 2012 20:14:02 -0000	1.209
+++ symtab.h	28 Jun 2012 20:32:56 -0000
@@ -1113,13 +1113,6 @@ extern int find_line_pc_range (struct sy
 
 extern void resolve_sal_pc (struct symtab_and_line *);
 
-/* Given a string, return the line specified by it.  For commands like "list"
-   and "breakpoint".  */
-
-extern struct symtabs_and_lines decode_line_spec (char *, int);
-
-extern struct symtabs_and_lines decode_line_spec_1 (char *, int);
-
 /* Symmisc.c */
 
 void maintenance_print_symbols (char *, int);
Index: tracepoint.c
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.c,v
retrieving revision 1.259
diff -u -p -r1.259 tracepoint.c
--- tracepoint.c	27 Jun 2012 18:08:40 -0000	1.259
+++ tracepoint.c	28 Jun 2012 20:32:56 -0000
@@ -2494,7 +2494,8 @@ trace_find_line_command (char *args, int
     }
   else
     {
-      sals = decode_line_spec (args, DECODE_LINE_FUNFIRSTLINE);
+      sals = decode_line_spec (args, DECODE_LINE_FUNFIRSTLINE,
+			       DECODE_LINE_DEFAULT_CURRENT_SOURCE);
       sal = sals.sals[0];
     }
   
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.218
diff -u -p -r1.218 mi-main.c
--- mi/mi-main.c	24 May 2012 16:51:38 -0000	1.218
+++ mi/mi-main.c	28 Jun 2012 20:32:56 -0000
@@ -2436,7 +2436,8 @@ mi_cmd_trace_find (char *command, char *
       if (argc != 2)
 	error (_("Line is required"));
 
-      sals = decode_line_spec (argv[1], DECODE_LINE_FUNFIRSTLINE);
+      sals = decode_line_spec (argv[1], DECODE_LINE_FUNFIRSTLINE,
+			       DECODE_LINE_DEFAULT_CURRENT_SOURCE);
       back_to = make_cleanup (xfree, sals.sals);
 
       sal = sals.sals[0];


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]