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 4/9] Explicit locations v2 - Add address locations


Hi,

Hi,

Currently address locations ("*EXPR") are handled by the linespec parser.

This patch adds a new address location type to the API introduced in previous patches and moves the handling of this form from the linespec parser into the location API function string_to_event_location.

From the command-writer's POV, nothing is required to support this. Once again, this is a elaboration of the location API to support existing features.

This patch also converts any hard-coded linespecs of the form "*EXPR" into proper address locations.

Keith

ChangeLog
2014-05-08  Keith Seitz  <keiths@redhat.com>

	* breakpoint.c (create_thread_event_breakpoint): Convert
	linespec to address location.
	(init_breakpoint_sal): Likewise.
	* linespec.c (canonicalize_linespec): Canonicalize expressions
	into address locations.
	(convert_address_location_to_sals): New function; contents moved
	from ...
	(convert_linespc_to_sals): ... here.
	(parse_linespec): Remove handling of address locations.
	(event_location_to_sals): Handle EVENT_LOCATION_ADDRESS.
	(linespec_expression_to_pc): Export.
	* linespec.h (linespec_expression_to_pc): Add declaration.
	* location.c (copy_event_location): Handle address locations.
	(delete_event_location): Likewise.
	(event_location_to_string): Likewise.
	(string_to_event_location): Likewise.
	(event_location_empty_p): Likewise.
	* location.h (enum event_location_type): Add EVENT_LOCATION_ADDRESS.
	(struct event_location.u) <address>: New member.
	(EVENT_LOCATION_ADDRESS): Define accessor macro.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Remove local
	variable `finish_pc'.
	Convert linespec to address location.
	* spu-tdep.c (spu_catch_start): Convert linespec to address
	location.
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index de0f65a..f509d7a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7544,9 +7544,8 @@ create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
 
   b->enable_state = bp_enabled;
   /* location has to be used or breakpoint_re_set will delete me.  */
-  b->location = new_event_location (EVENT_LOCATION_LINESPEC);
-  EVENT_LOCATION_LINESPEC (b->location)
-    = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
+  b->location = new_event_location (EVENT_LOCATION_ADDRESS);
+  EVENT_LOCATION_ADDRESS (b->location) = b->loc->address;
 
   update_global_location_list_nothrow (1);
 
@@ -9430,11 +9429,10 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
     b->location = location;
   else
     {
-      b->location = new_event_location (EVENT_LOCATION_LINESPEC);
-      EVENT_LOCATION_LINESPEC (b->location)
-	= xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
-      EVENT_LOCATION_SAVE_SPEC (b->location)
-	= xstrdup (EVENT_LOCATION_LINESPEC (b->location));
+      b->location = new_event_location (EVENT_LOCATION_ADDRESS);
+      EVENT_LOCATION_ADDRESS (b->location) = b->loc->address;
+      EVENT_LOCATION_SAVE_SPEC (b->location) =
+	xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
    }
   b->filter = filter;
 }
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 717ea68..07a84b5 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -317,7 +317,7 @@ static void iterate_over_file_blocks (struct symtab *symtab,
 static void initialize_defaults (struct symtab **default_symtab,
 				 int *default_line);
 
-static CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
+CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
 
 static struct symtabs_and_lines decode_objc (struct linespec_state *self,
 					     linespec_p ls,
@@ -1774,9 +1774,8 @@ canonicalize_linespec (struct linespec_state *state, linespec_p ls)
   if (ls->expression != NULL)
     {
       state->canonical->location
-	= new_event_location (EVENT_LOCATION_LINESPEC);
-      EVENT_LOCATION_LINESPEC (state->canonical->location)
-	= xstrdup (ls->expression);
+	= new_event_location (EVENT_LOCATION_ADDRESS);
+      EVENT_LOCATION_ADDRESS (state->canonical->location) = ls->expr_pc;
       EVENT_LOCATION_SAVE_SPEC (state->canonical->location)
 	= xstrdup (ls->expression);
     }
@@ -1997,6 +1996,30 @@ create_sals_line_offset (struct linespec_state *self,
   return values;
 }
 
+/* Convert the given ADDRESS into SaLs.  */
+
+static struct symtabs_and_lines
+convert_address_location_to_sals (struct linespec_state *self,
+				  CORE_ADDR address)
+{
+  struct symtab_and_line sal;
+  struct symtabs_and_lines sals = {NULL, 0};
+
+  sal = find_pc_line (address, 0);
+  sal.pc = address;
+  sal.section = find_pc_overlay (address);
+  sal.explicit_pc = 1;
+  add_sal_to_sals (self, &sals, &sal, core_addr_to_string (address), 1);
+
+  if (self->canonical != NULL)
+    {
+      self->canonical->location = new_event_location (EVENT_LOCATION_ADDRESS);
+      EVENT_LOCATION_ADDRESS (self->canonical->location) = address;
+    }
+
+  return sals;
+}
+
 /* Create and return SALs from the linespec LS.  */
 
 static struct symtabs_and_lines
@@ -2006,14 +2029,8 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
 
   if (ls->expression != NULL)
     {
-      struct symtab_and_line sal;
-
       /* We have an expression.  No other attribute is allowed.  */
-      sal = find_pc_line (ls->expr_pc, 0);
-      sal.pc = ls->expr_pc;
-      sal.section = find_pc_overlay (ls->expr_pc);
-      sal.explicit_pc = 1;
-      add_sal_to_sals (state, &sals, &sal, ls->expression, 1);
+      sals = convert_address_location_to_sals (state, ls->expr_pc);
     }
   else if (ls->labels.label_symbols != NULL)
     {
@@ -2212,33 +2229,7 @@ parse_linespec (linespec_parser *parser, const char **argptr)
   token = linespec_lexer_lex_one (parser);
 
   /* It must be either LSTOKEN_STRING or LSTOKEN_NUMBER.  */
-  if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '*')
-    {
-      char *expr;
-      const char *copy;
-
-      /* User specified an expression, *EXPR.  */
-      copy = expr = copy_token_string (token);
-      cleanup = make_cleanup (xfree, expr);
-      PARSER_RESULT (parser)->expr_pc = linespec_expression_to_pc (&copy);
-      discard_cleanups (cleanup);
-      PARSER_RESULT (parser)->expression = expr;
-
-      /* This is a little hacky/tricky.  If linespec_expression_to_pc
-	 did not evaluate the entire token, then we must find the
-	 string COPY inside the original token buffer.  */
-      if (*copy != '\0')
-	{
-	  PARSER_STREAM (parser) = strstr (parser->lexer.saved_arg, copy);
-	  gdb_assert (PARSER_STREAM (parser) != NULL);
-	}
-
-      /* Consume the token.  */
-      linespec_lexer_consume_token (parser);
-
-      goto convert_to_sals;
-    }
-  else if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '$')
+  if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '$')
     {
       char *var;
 
@@ -2460,6 +2451,12 @@ event_location_to_sals (linespec_parser *parser,
       }
       break;
 
+    case EVENT_LOCATION_ADDRESS:
+      result
+	= convert_address_location_to_sals (PARSER_STATE (parser),
+					    EVENT_LOCATION_ADDRESS (location));
+      break;
+
     default:
       gdb_assert_not_reached ("unhandled event location type");
     }
@@ -2669,7 +2666,7 @@ initialize_defaults (struct symtab **default_symtab, int *default_line)
 /* Evaluate the expression pointed to by EXP_PTR into a CORE_ADDR,
    advancing EXP_PTR past any parsed text.  */
 
-static CORE_ADDR
+CORE_ADDR
 linespec_expression_to_pc (const char **exp_ptr)
 {
   if (current_program_space->executing_startup)
diff --git a/gdb/linespec.h b/gdb/linespec.h
index 658f2a1..df5820a 100644
--- a/gdb/linespec.h
+++ b/gdb/linespec.h
@@ -152,4 +152,8 @@ extern struct symtabs_and_lines decode_line_with_current_source (char *, int);
 
 extern struct symtabs_and_lines decode_line_with_last_displayed (char *, int);
 
+/* Evaluate the expression pointed to by EXP_PTR into a CORE_ADDR,
+   advancing EXP_PTR past any parsed text.  */
+
+extern CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
 #endif /* defined (LINESPEC_H) */
diff --git a/gdb/location.c b/gdb/location.c
index 3f50bed..22e7496 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -68,6 +68,10 @@ copy_event_location (const struct event_location *src)
       EVENT_LOCATION_LINESPEC (dst) = xstrdup (EVENT_LOCATION_LINESPEC (src));
       break;
 
+    case EVENT_LOCATION_ADDRESS:
+      EVENT_LOCATION_ADDRESS (dst) = EVENT_LOCATION_ADDRESS (src);
+      break;
+
     default:
       gdb_assert_not_reached ("unknown event location type");
     }
@@ -93,6 +97,10 @@ delete_event_location (void *data)
 	  xfree (EVENT_LOCATION_LINESPEC (location));
 	  break;
 
+	case EVENT_LOCATION_ADDRESS:
+	  /* Nothing to do.  */
+	  break;
+
 	default:
 	  gdb_assert_not_reached ("unknown event location type");
 	}
@@ -116,6 +124,10 @@ event_location_to_string (const struct event_location *location)
       result = EVENT_LOCATION_LINESPEC (location);
       break;
 
+    case EVENT_LOCATION_ADDRESS:
+      result = EVENT_LOCATION_SAVE_SPEC (location);
+      break;
+
     default:
       gdb_assert_not_reached ("unknown event location type");
     }
@@ -133,11 +145,26 @@ string_to_event_location (char **stringp,
 {
   struct event_location *location;
 
-  location = new_event_location (EVENT_LOCATION_LINESPEC);
-  if (*stringp != NULL)
+  /* First, check if the string is an address location.  */
+  if (*stringp != NULL && **stringp == '*')
     {
-      EVENT_LOCATION_LINESPEC (location) = xstrdup (*stringp);
-      *stringp += strlen (*stringp);
+      const char *arg, *orig;
+
+      orig = arg = *stringp;
+      location = new_event_location (EVENT_LOCATION_ADDRESS);
+      EVENT_LOCATION_SAVE_SPEC (location) = xstrdup (arg);
+      EVENT_LOCATION_ADDRESS (location) = linespec_expression_to_pc (&arg);
+      *stringp += arg - orig;
+    }
+  else
+    {
+      /* Everything else is a linespec.  */
+      location = new_event_location (EVENT_LOCATION_LINESPEC);
+      if (*stringp != NULL)
+	{
+	  EVENT_LOCATION_LINESPEC (location) = xstrdup (*stringp);
+	  *stringp += strlen (*stringp);
+	}
     }
 
   return location;
@@ -153,6 +180,9 @@ event_location_empty_p (const struct event_location *location)
     case EVENT_LOCATION_LINESPEC:
       return EVENT_LOCATION_LINESPEC (location) == NULL;
 
+    case EVENT_LOCATION_ADDRESS:
+      return 0;
+
     default:
       gdb_assert_not_reached ("unknown event location type");
     }
diff --git a/gdb/location.h b/gdb/location.h
index 83fc3a4..8575daf 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -27,7 +27,10 @@ struct language_defn;
 enum event_location_type
 {
   /* A traditional linespec.  */
-  EVENT_LOCATION_LINESPEC
+  EVENT_LOCATION_LINESPEC,
+
+  /* An address in the inferior.  */
+  EVENT_LOCATION_ADDRESS
 };
 
 /* An event location used to set a stop event in the inferior.
@@ -47,6 +50,10 @@ struct event_location
        probes.  */
     char *addr_string;
 #define EVENT_LOCATION_LINESPEC(S) ((S)->u.addr_string)
+
+    /* An address in the inferior.  */
+    CORE_ADDR address;
+#define EVENT_LOCATION_ADDRESS(S) ((S)->u.address)
   } u;
 
   /* A string representation of how this location may be
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index b4db5ec..864b043 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -167,9 +167,8 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   struct frame_id frame_id;
   PyObject *internal = NULL;
   int internal_bp = 0;
-  CORE_ADDR finish_pc, pc;
+  CORE_ADDR pc;
   volatile struct gdb_exception except;
-  char small_buf[100];
   struct symbol *function;
 
   if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
@@ -291,10 +290,8 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
       struct event_location location;
 
       /* Set a breakpoint on the return address.  */
-      initialize_event_location (&location, EVENT_LOCATION_LINESPEC);
-      finish_pc = get_frame_pc (prev_frame);
-      xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (finish_pc));
-      EVENT_LOCATION_LINESPEC (&location) = small_buf;
+      initialize_event_location (&location, EVENT_LOCATION_ADDRESS);
+      EVENT_LOCATION_ADDRESS (&location) = get_frame_pc (prev_frame);
       create_breakpoint (python_gdbarch,
                          &location, NULL, thread, NULL,
                          0,
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index 43b4fec..2ced594 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -2001,8 +2001,8 @@ spu_catch_start (struct objfile *objfile)
 
   /* Use a numerical address for the set_breakpoint command to avoid having
      the breakpoint re-set incorrectly.  */
-  initialize_event_location (&location, EVENT_LOCATION_LINESPEC);
-  EVENT_LOCATION_LINESPEC (&location) = xstrdup (core_addr_to_string (pc));
+  initialize_event_location (&location, EVENT_LOCATION_ADDRESS);
+  EVENT_LOCATION_ADDRESS (&location) = pc;
   create_breakpoint (get_objfile_arch (objfile), &location,
 		     NULL /* cond_string */, -1 /* thread */,
 		     NULL /* extra_string */,

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