public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-ambiguous-linespec: put source file and line number into each bp_location this makes 'info break' say the right thing:
@ 2011-08-04 19:38 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2011-08-04 19:38 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-ambiguous-linespec has been updated
       via  60c525337d9ee2b4afd457415a8586e9796b5120 (commit)
       via  22dac4a03cab3f4ace05d57d908214b3921e67cd (commit)
       via  fac61da6f88569054dd02272ebf56a5487aca47c (commit)
      from  08c801ec3b550dc84aaf57798b327dbc84417509 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 60c525337d9ee2b4afd457415a8586e9796b5120
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Aug 4 13:31:28 2011 -0600

    put source file and line number into each bp_location
    this makes 'info break' say the right thing:
    
    Num     Type           Disp Enb Address            What
    1       breakpoint     keep y   <MULTIPLE>
    1.1                         y     0x000000000040048b in n at b/thefile.c:3
    1.2                         y     0x000000000040047b in m at a/thefile.c:3
    
    ... before this, both locations would show up in "b/thefile.c".

commit 22dac4a03cab3f4ace05d57d908214b3921e67cd
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Aug 4 10:37:45 2011 -0600

    remove maybe_use_global_symtab

commit fac61da6f88569054dd02272ebf56a5487aca47c
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Aug 4 10:34:04 2011 -0600

    convert linespec to OO style

-----------------------------------------------------------------------

Summary of changes:
 gdb/breakpoint.c        |   62 +++++------
 gdb/breakpoint.h        |   16 ++--
 gdb/linespec.c          |  299 +++++++++++++++++++++++++----------------------
 gdb/tui/tui-winsource.c |   47 ++++----
 4 files changed, 220 insertions(+), 204 deletions(-)

First 500 lines of diff:
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index b10c5c1..385258f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4490,7 +4490,7 @@ print_breakpoint_location (struct breakpoint *b,
 
   if (b->display_canonical)
     ui_out_field_string (uiout, "what", b->addr_string);
-  else if (b->source_file && loc)
+  else if (loc && loc->source_file)
     {
       struct symbol *sym 
 	= find_pc_sect_function (loc->address, loc->section);
@@ -4503,7 +4503,7 @@ print_breakpoint_location (struct breakpoint *b,
 	  ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
 	  ui_out_text (uiout, "at ");
 	}
-      ui_out_field_string (uiout, "file", b->source_file);
+      ui_out_field_string (uiout, "file", loc->source_file);
       ui_out_text (uiout, ":");
       
       if (ui_out_is_mi_like_p (uiout))
@@ -4515,7 +4515,7 @@ print_breakpoint_location (struct breakpoint *b,
 	    ui_out_field_string (uiout, "fullname", fullname);
 	}
       
-      ui_out_field_int (uiout, "line", b->line_number);
+      ui_out_field_int (uiout, "line", loc->line_number);
     }
   else if (loc)
     {
@@ -5745,12 +5745,10 @@ init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
      breakpoint resetting.  */
   b->pspace = sal.pspace;
 
-  if (sal.symtab == NULL)
-    b->source_file = NULL;
-  else
-    b->source_file = xstrdup (sal.symtab->filename);
+  if (sal.symtab != NULL)
+    b->loc->source_file = xstrdup (sal.symtab->filename);
   b->loc->section = sal.section;
-  b->line_number = sal.line;
+  b->loc->line_number = sal.line;
 
   set_breakpoint_location_function (b->loc,
 				    sal.explicit_pc || sal.explicit_line);
@@ -6957,12 +6955,10 @@ momentary_breakpoint_from_master (struct breakpoint *orig,
   copy->loc->section = orig->loc->section;
   copy->loc->pspace = orig->loc->pspace;
 
-  if (orig->source_file == NULL)
-    copy->source_file = NULL;
-  else
-    copy->source_file = xstrdup (orig->source_file);
+  if (orig->loc->source_file != NULL)
+    copy->loc->source_file = xstrdup (orig->loc->source_file);
 
-  copy->line_number = orig->line_number;
+  copy->loc->line_number = orig->loc->line_number;
   copy->frame_id = orig->frame_id;
   copy->thread = orig->thread;
   copy->pspace = orig->pspace;
@@ -7035,6 +7031,10 @@ add_location_to_breakpoint (struct breakpoint *b,
   gdb_assert (loc->pspace != NULL);
   loc->section = sal->section;
 
+  if (sal->symtab != NULL)
+    loc->source_file = xstrdup (sal->symtab->filename);
+  loc->line_number = sal->line;
+
   set_breakpoint_location_function (loc,
 				    sal->explicit_pc || sal->explicit_line);
   return loc;
@@ -10113,12 +10113,12 @@ clear_command (char *arg, int from_tty)
 		    && (!section_is_overlay (loc->section)
 			|| loc->section == sal.section);
 		  int line_match = ((default_match || (0 == sal.pc))
-				    && b->source_file != NULL
+				    && loc->source_file != NULL
 				    && sal.symtab != NULL
 				    && sal.pspace == loc->pspace
-				    && filename_cmp (b->source_file,
+				    && filename_cmp (loc->source_file,
 						     sal.symtab->filename) == 0
-				    && b->line_number == sal.line);
+				    && loc->line_number == sal.line);
 		  if (pc_match || line_match)
 		    {
 		      match = 1;
@@ -10637,15 +10637,16 @@ say_where (struct breakpoint *b)
     }
   else
     {
-      if (opts.addressprint || b->source_file == NULL)
+      if (opts.addressprint || b->loc->source_file == NULL)
 	{
 	  printf_filtered (" at ");
 	  fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
 			  gdb_stdout);
 	}
-      if (b->source_file)
+      /* FIXME */
+      if (b->loc->source_file)
 	printf_filtered (": file %s, line %d.",
-			 b->source_file, b->line_number);
+			 b->loc->source_file, b->loc->line_number);
 
       if (b->loc->next)
 	{
@@ -10665,6 +10666,7 @@ bp_location_dtor (struct bp_location *self)
 {
   xfree (self->cond);
   xfree (self->function_name);
+  xfree (self->source_file);
 }
 
 static const struct bp_location_ops bp_location_ops =
@@ -10682,7 +10684,6 @@ base_breakpoint_dtor (struct breakpoint *self)
   xfree (self->cond_string);
   xfree (self->addr_string);
   xfree (self->addr_string_range_end);
-  xfree (self->source_file);
 }
 
 static struct bp_location *
@@ -11512,17 +11513,18 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
 	  ui_out_field_int (uiout, "line", sal.line);
 	  ui_out_text (uiout, "\n");
 
-	  b->line_number = sal.line;
+	  b->loc->line_number = sal.line;
 
-	  xfree (b->source_file);
+	  xfree (b->loc->source_file);
 	  if (sym)
-	    b->source_file = xstrdup (sal.symtab->filename);
+	    b->loc->source_file = xstrdup (sal.symtab->filename);
 	  else
-	    b->source_file = NULL;
+	    b->loc->source_file = NULL;
 
 	  xfree (b->addr_string);
 	  b->addr_string = xstrprintf ("%s:%d",
-				       sal.symtab->filename, b->line_number);
+				       sal.symtab->filename,
+				       b->loc->line_number);
 
 	  /* Might be nice to check if function changed, and warn if
 	     so.  */
@@ -11613,16 +11615,6 @@ update_breakpoint_locations (struct breakpoint *b,
 	    }
 	}
 
-      if (b->source_file != NULL)
-	xfree (b->source_file);
-      if (sals.sals[i].symtab == NULL)
-	b->source_file = NULL;
-      else
-	b->source_file = xstrdup (sals.sals[i].symtab->filename);
-
-      if (b->line_number == 0)
-	b->line_number = sals.sals[i].line;
-
       if (sals_end.nelts)
 	{
 	  CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 9b79e3e..4977f27 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -401,6 +401,14 @@ struct bp_location
      This variable keeps a number of events still to go, when
      it becomes 0 this location is retired.  */
   int events_till_retirement;
+
+  /* Line number of this address.  */
+
+  int line_number;
+
+  /* Source file name of this address.  */
+
+  char *source_file;
 };
 
 /* This structure is a collection of function pointers that, if available,
@@ -548,14 +556,6 @@ struct breakpoint
     /* Location(s) associated with this high-level breakpoint.  */
     struct bp_location *loc;
 
-    /* Line number of this address.  */
-
-    int line_number;
-
-    /* Source file name of this address.  */
-
-    char *source_file;
-
     /* Non-zero means a silent breakpoint (don't print frame info
        if we stop here).  */
     unsigned char silent;
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 8e79eee..fc82ba4 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -47,6 +47,35 @@
 typedef struct symtab *symtab_p;
 DEF_VEC_P (symtab_p);
 
+/* An instance of this is used to keep all state while linespec
+   operates.  This instance is passed around as a 'this' pointer to
+   the various implementation methods.  */
+
+struct linespec_state
+{
+  /* The default symtab to use, if no other symtab is specified.  */
+  struct symtab *default_symtab;
+
+  /* The default line to use.  */
+  int default_line;
+
+  /* If the linespec started with "FILE:", this holds all the matching
+     symtabs.  Otherwise, it will hold a single NULL entry, meaning
+     that the default symtab should be used.  */
+  VEC (symtab_p) *file_symtabs;
+
+  /* If the linespec started with "FILE:", this holds an xmalloc'd
+     copy of "FILE".  */
+  char *user_filename;
+
+  /* The 'funfirstline' value that was passed in to decode_line_1 or
+     decode_line_full.  */
+  int funfirstline;
+
+  /* The 'canonical' value passed to decode_line_full, or NULL.  */
+  struct linespec_result *canonical;
+};
+
 /* Prototypes for local functions.  */
 
 static void initialize_defaults (struct symtab **default_symtab,
@@ -56,15 +85,11 @@ static struct symtabs_and_lines decode_indirect (char **argptr);
 
 static char *locate_first_half (char **argptr, int *is_quote_enclosed);
 
-static struct symtabs_and_lines decode_objc (char **argptr,
-					     int funfirstline,
-					     VEC (symtab_p) *file_symtabs,
-					     struct linespec_result *canonical);
+static struct symtabs_and_lines decode_objc (struct linespec_state *self,
+					     char **argptr);
 
-static struct symtabs_and_lines decode_compound (char **argptr,
-						 int funfirstline,
-						 struct linespec_result *canonical,
-						 VEC (symtab_p) *file_symtabs,
+static struct symtabs_and_lines decode_compound (struct linespec_state *self,
+						 char **argptr,
 						 char *saved_arg,
 						 char *p);
 
@@ -113,28 +138,19 @@ static VEC (symtab_p) *symtab_from_filename (char **argptr,
 static struct symbol *find_function_symbol (char **argptr, char *p,
 					    int is_quote_enclosed);
 
-static struct
-symtabs_and_lines decode_all_digits (char **argptr,
-				     int default_line,
-				     struct linespec_result *canonical,
-				     VEC (symtab_p) *file_symtabs,
-				     char *q,
-				     const char *user_filename);
-
-static struct symtabs_and_lines decode_dollar (char *copy,
-					       int funfirstline,
-					       struct linespec_result *canonical,
-					       VEC (symtab_p) *file_symtabs);
+static struct symtabs_and_lines decode_all_digits (struct linespec_state *self,
+						   char **argptr,
+						   char *q);
+
+static struct symtabs_and_lines decode_dollar (struct linespec_state *self,
+					       char *copy);
 
 static int decode_label (struct symbol *function_symbol,
 			 char *copy, struct linespec_result *canonical,
 			 struct symtabs_and_lines *result);
 
-static struct symtabs_and_lines decode_variable (char *copy,
-						 int funfirstline,
-						 struct linespec_result *canonical,
-						 VEC (symtab_p) *file_symtabs,
-						 const char *);
+static struct symtabs_and_lines decode_variable (struct linespec_state *self,
+						 char *copy);
 
 static int symbol_to_sal (struct symtab_and_line *result,
 			  int funfirstline, char *copy,
@@ -153,19 +169,6 @@ symtabs_and_lines minsym_found (int funfirstline,
 				struct minimal_symbol *msymbol);
 
 
-/* The global default symtab; this is assigned when entering linespec
-   and valid only for the duration of the call.  */
-
-static struct symtab *global_default_symtab;
-
-/* Fix up SYMTAB depending on whether it is the global default.  */
-
-static struct symtab *
-maybe_use_global_symtab (struct symtab *s)
-{
-  return s == NULL ? global_default_symtab : s;
-}
-
 /* Helper functions.  */
 
 static void
@@ -841,9 +844,7 @@ keep_name_info (char *p, int on_boundary)
    can use as appropriate instead of make_symbol_completion_list.  */
 
 struct symtabs_and_lines
-decode_line_internal (char **argptr, int funfirstline,
-		      struct symtab *default_symtab,
-		      int default_line, struct linespec_result *canonical)
+decode_line_internal (struct linespec_state *self, char **argptr)
 {
   char *p;
   char *q;
@@ -863,9 +864,6 @@ decode_line_internal (char **argptr, int funfirstline,
   /* The "first half" of the linespec.  */
   char *first_half;
 
-  /* For "file:line", the "file" part.  */
-  char *user_filename = NULL;
-
   /* If we are parsing `function:label', this holds the symbol for the
      function.  */
   struct symbol *function_symbol = NULL;
@@ -873,12 +871,9 @@ decode_line_internal (char **argptr, int funfirstline,
      was thrown when trying to parse a filename.  */
   volatile struct gdb_exception file_exception;
 
-  /* If a file name is specified, this is all matching symtabs.  */
-  struct VEC (symtab_p) *file_symtabs = NULL;
-
   /* Defaults have defaults.  */
 
-  initialize_defaults (&default_symtab, &default_line);
+  initialize_defaults (&self->default_symtab, &self->default_line);
   
   /* See if arg is *PC.  */
 
@@ -910,24 +905,18 @@ decode_line_internal (char **argptr, int funfirstline,
      symtab and strip the filename from ARGPTR.  */
   TRY_CATCH (file_exception, RETURN_MASK_ERROR)
     {
-      file_symtabs = symtab_from_filename (argptr, p, is_quote_enclosed,
-					   &user_filename);
+      self->file_symtabs = symtab_from_filename (argptr, p, is_quote_enclosed,
+						 &self->user_filename);
     }
 
-  global_default_symtab = default_symtab;
-  if (VEC_empty (symtab_p, file_symtabs))
+  if (VEC_empty (symtab_p, self->file_symtabs))
     {
       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
-      VEC_safe_push (symtab_p, file_symtabs, NULL);
+      VEC_safe_push (symtab_p, self->file_symtabs, NULL);
     }
-  make_cleanup (VEC_cleanup (symtab_p), &file_symtabs);
 
   if (file_exception.reason >= 0)
     {
-      gdb_assert (user_filename != NULL);
-
-      make_cleanup (xfree, user_filename);
-
       /* Check for single quotes on the non-filename part.  */
       is_quoted = (**argptr
 		   && strchr (get_gdb_completer_quote_characters (),
@@ -949,7 +938,7 @@ decode_line_internal (char **argptr, int funfirstline,
   {
     struct symtabs_and_lines values;
 
-    values = decode_objc (argptr, funfirstline, file_symtabs, canonical);
+    values = decode_objc (self, argptr);
     if (values.sals != NULL)
       return values;
   }
@@ -979,8 +968,7 @@ decode_line_internal (char **argptr, int funfirstline,
 
 	  TRY_CATCH (ex, RETURN_MASK_ERROR)
 	    {
-	      values = decode_compound (argptr, funfirstline, canonical,
-					file_symtabs, saved_arg, p);
+	      values = decode_compound (self, argptr, saved_arg, p);
 	    }
 	  if ((is_quoted || is_squote_enclosed) && **argptr == '\'')
 	    *argptr = *argptr + 1;
@@ -1019,7 +1007,7 @@ decode_line_internal (char **argptr, int funfirstline,
 	}
     }
 
-  /* file_symtabs holds the  specified file symtabs, or 0 if no file
+  /* self->file_symtabs holds the  specified file symtabs, or 0 if no file
      specified.
      If we are parsing `function:symbol', then FUNCTION_SYMBOL is the
      function before the `:'.
@@ -1047,8 +1035,7 @@ decode_line_internal (char **argptr, int funfirstline,
   if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ',')
       && function_symbol == NULL)
     /* We found a token consisting of all digits -- at least one digit.  */
-    return decode_all_digits (argptr, default_line, canonical, file_symtabs, q,
-			      user_filename);
+    return decode_all_digits (self, argptr, q);
 
   /* Arg token is not digits => try it as a variable name
      Find the next token (everything up to end or next whitespace).  */
@@ -1097,16 +1084,16 @@ decode_line_internal (char **argptr, int funfirstline,
      be history value, or it may be a convenience variable.  */
 
   if (*copy == '$' && function_symbol == NULL)
-    return decode_dollar (copy, funfirstline, canonical, file_symtabs);
+    return decode_dollar (self, copy);
 
   /* Try the token as a label, but only if no file was specified,
      because we can only really find labels in the current scope.  */
 
-  if (VEC_length (symtab_p, file_symtabs) == 1
-      && VEC_index (symtab_p, file_symtabs, 0) == NULL)
+  if (VEC_length (symtab_p, self->file_symtabs) == 1
+      && VEC_index (symtab_p, self->file_symtabs, 0) == NULL)
     {
       struct symtabs_and_lines label_result;
-      if (decode_label (function_symbol, copy, canonical, &label_result))
+      if (decode_label (function_symbol, copy, self->canonical, &label_result))
 	return label_result;
     }
 
@@ -1116,8 +1103,34 @@ decode_line_internal (char **argptr, int funfirstline,
   /* Look up that token as a variable.
      If file specified, use that file's per-file block to start with.  */
 
-  return decode_variable (copy, funfirstline, canonical, file_symtabs,
-			  user_filename);
+  return decode_variable (self, copy);
+}
+
+/* A constructor for linespec_state.  */
+
+static void
+linespec_state_constructor (struct linespec_state *self,
+			    int funfirstline,
+			    struct symtab *default_symtab,
+			    int default_line,
+			    struct linespec_result *canonical)
+{
+  memset (self, 0, sizeof (*self));
+  self->funfirstline = funfirstline;
+  self->default_symtab = default_symtab;
+  self->default_line = default_line;
+  self->canonical = canonical;
+}
+
+/* A destructor for linespec_state.  */
+
+static void
+linespec_state_destructor (void *arg)
+{
+  struct linespec_state *self = arg;
+
+  xfree (self->user_filename);
+  VEC_free (symtab_p, self->file_symtabs);
 }
 
 struct symtabs_and_lines
@@ -1126,12 +1139,15 @@ decode_line_full (char **argptr, int funfirstline,
 		  int default_line, struct linespec_result *canonical)
 {
   struct symtabs_and_lines result;
-  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
+  struct linespec_state state;
+  struct cleanup *cleanups;
+
+  linespec_state_constructor (&state, funfirstline, default_symtab,
+			      default_line, canonical);
+  cleanups = make_cleanup (linespec_state_destructor, &state);
 
   gdb_assert (canonical != NULL);
-  result = decode_line_internal (argptr, funfirstline,
-				 default_symtab, default_line,
-				 canonical);
+  result = decode_line_internal (&state, argptr);
   do_cleanups (cleanups);
   return result;
 }
@@ -1142,11 +1158,14 @@ decode_line_1 (char **argptr, int funfirstline,
 	       int default_line)


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-04 19:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-04 19:38 [SCM] archer-tromey-ambiguous-linespec: put source file and line number into each bp_location this makes 'info break' say the right thing: tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).