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]

[PATCH/v4 2/3] fix Bug 15180 Agent style dprintf does not respect conditions (gdbserver)


This patch doesn't has big chanage with previous version. Just update follow git upstream.

Update gdbserver add commands and condition in right order like how it
received because maybe we have a 0 size conditions in the end without
commands.
And update function gdb_condition_true_at_breakpoint let it can execute
commands if need.

2014-01-27  Hui Zhu  <hui@codesourcery.com>

	PR gdb/15180
	* linux-low.c (linux_wait_1): Update arguments of function
	gdb_condition_true_at_breakpoint.
	Remove function run_breakpoint_commands.
	(need_step_over_p): Update arguments of function
	gdb_condition_true_at_breakpoint.
	* mem-break.c (add_condition_to_breakpoint): Add new condition
	to tail.
	(gdb_condition_true_at_breakpoint): Execute commands.
	(add_commands_to_breakpoint): Add new commands to tail.
	* mem-break.h (gdb_condition_true_at_breakpoint): Update arguments.

--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -2595,10 +2595,8 @@ retry:
 		   || (!step_over_finished && !in_step_range
 		       && !bp_explains_trap && !trace_event)
 		   || (gdb_breakpoint_here (event_child->stop_pc)
-		       && gdb_condition_true_at_breakpoint (event_child->stop_pc)
-		       && gdb_no_commands_at_breakpoint (event_child->stop_pc)));
-
-  run_breakpoint_commands (event_child->stop_pc);
+		       && gdb_condition_true_at_breakpoint (event_child->stop_pc,
+							    1)));

   /* We found no reason GDB would want us to stop.  We either hit one
      of our own breakpoints, or finished an internal step GDB
@@ -3505,8 +3503,7 @@ need_step_over_p (struct inferior_list_e
 	 though.  If the condition is being evaluated on the target's side
 	 and it evaluate to false, step over this breakpoint as well.  */
       if (gdb_breakpoint_here (pc)
-	  && gdb_condition_true_at_breakpoint (pc)
-	  && gdb_no_commands_at_breakpoint (pc))
+	  && gdb_condition_true_at_breakpoint (pc, 0))
 	{
 	  if (debug_threads)
 	    debug_printf ("Need step over [LWP %ld]? yes, but found"
--- a/gdb/gdbserver/mem-break.c
+++ b/gdb/gdbserver/mem-break.c
@@ -779,15 +779,21 @@ void
 add_condition_to_breakpoint (struct breakpoint *bp,
 			     struct agent_expr *condition)
 {
-  struct point_cond_list *new_cond;
+  struct point_cond_list *new_cond, *tail;

   /* Create new condition.  */
-  new_cond = xcalloc (1, sizeof (*new_cond));
+  new_cond = xzalloc (sizeof (*new_cond));
   new_cond->cond = condition;

-  /* Add condition to the list.  */
-  new_cond->next = bp->cond_list;
-  bp->cond_list = new_cond;
+  /* Add condition to the tail of list.  */
+  if (bp->cond_list)
+    {
+      for (tail = bp->cond_list; tail->next; tail = tail->next)
+	;
+      tail->next = new_cond;
+    }
+  else
+    bp->cond_list = new_cond;
 }

 /* Add a target-side condition CONDITION to the breakpoint at ADDR.  */
@@ -821,41 +827,101 @@ add_breakpoint_condition (CORE_ADDR addr
   return 0;
 }

-/* Evaluate condition (if any) at breakpoint BP.  Return 1 if
-   true and 0 otherwise.  */
+/* Evaluate condition (if any) at breakpoint BP.
+   If EXEC_CMDS is true, execute the commands in this BP.
+   Return 1 if true and 0 otherwise.  */

 int
-gdb_condition_true_at_breakpoint (CORE_ADDR where)
+gdb_condition_true_at_breakpoint (CORE_ADDR where, int exec_cmds)
 {
   /* Fetch registers for the current inferior.  */
   struct breakpoint *bp = find_gdb_breakpoint_at (where);
   ULONGEST value = 0;
   struct point_cond_list *cl;
+  struct point_command_list *cmdsl;
   int err = 0;
   struct eval_agent_expr_context ctx;

   if (bp == NULL)
     return 0;

-  /* Check if the breakpoint is unconditional.  If it is,
-     the condition always evaluates to TRUE.  */
-  if (bp->cond_list == NULL)
+  if (bp->cond_list == NULL && bp->command_list == NULL)
     return 1;

   ctx.regcache = get_thread_regcache (current_inferior, 1);
   ctx.tframe = NULL;
   ctx.tpoint = NULL;

+  /* Handle the breakpoints that do not have condition.  */
+  if (bp->cond_list == NULL)
+    {
+      value = 0;
+      for (cmdsl = bp->command_list; cmdsl; cmdsl = cmdsl->next)
+        {
+	  if (cmdsl->cmd->length != 0)
+	    {
+	      /* For the breakpoint that have commands, inferior's
+	         execution should not stop by it.  */
+	      if (exec_cmds)
+		{
+		  err = gdb_eval_agent_expr (&ctx, cmdsl->cmd, NULL);
+		  if (err)
+		    break;
+		}
+	    }
+	  else
+	    {
+	      /* For the breakpoints that have NULL commands, inferior's
+	         execution should stop.  */
+	      value = 1;
+	    }
+	}
+
+      if (err)
+	return 1;
+
+      return value;
+    }
+
   /* Evaluate each condition in the breakpoint's list of conditions.
      Return true if any of the conditions evaluates to TRUE.

      If we failed to evaluate the expression, TRUE is returned.  This
      forces GDB to reevaluate the conditions.  */
-  for (cl = bp->cond_list;
-       cl && !value && !err; cl = cl->next)
+  cmdsl = bp->command_list;
+  for (cl = bp->cond_list; cl; cl = cl->next)
     {
+      ULONGEST current_value = 0;
+
       /* Evaluate the condition.  */
-      err = gdb_eval_agent_expr (&ctx, cl->cond, &value);
+      if (cl->cond->length != 0)
+	{
+	  err = gdb_eval_agent_expr (&ctx, cl->cond, &current_value);
+	  if (err)
+	    break;
+	}
+      else
+	current_value = 1;
+
+      if (cmdsl && cmdsl->cmd->length != 0)
+        {
+	  if (exec_cmds && current_value != 0)
+	    {
+	      /* Current condition is true, execute the current commands.
+	         But not set current_value to value because the breakpoints
+	         that have commands should not stop inferior's execution.  */
+	      err = gdb_eval_agent_expr (&ctx, cmdsl->cmd, NULL);
+	      if (err)
+	        break;
+	    }
+	  cmdsl = cmdsl->next;
+	}
+      else
+        {
+          value = current_value;
+	  if (value)
+            break;
+	}
     }

   if (err)
@@ -870,16 +936,22 @@ void
 add_commands_to_breakpoint (struct breakpoint *bp,
 			    struct agent_expr *commands, int persist)
 {
-  struct point_command_list *new_cmd;
+  struct point_command_list *new_cmd, *tail;

   /* Create new command.  */
-  new_cmd = xcalloc (1, sizeof (*new_cmd));
+  new_cmd = xzalloc (sizeof (*new_cmd));
   new_cmd->cmd = commands;
   new_cmd->persistence = persist;

-  /* Add commands to the list.  */
-  new_cmd->next = bp->command_list;
-  bp->command_list = new_cmd;
+  /* Add commands to the tail of list.  */
+  if (bp->command_list)
+    {
+      for (tail = bp->command_list; tail->next; tail = tail->next)
+	;
+      tail->next = new_cmd;
+    }
+  else
+    bp->command_list = new_cmd;
 }

 /* Add a target-side command COMMAND to the breakpoint at ADDR.  */
--- a/gdb/gdbserver/mem-break.h
+++ b/gdb/gdbserver/mem-break.h
@@ -56,10 +56,7 @@ int add_breakpoint_commands (CORE_ADDR a

 int any_persistent_commands (void);

-/* Evaluation condition (if any) at breakpoint BP.  Return 1 if
-   true and 0 otherwise.  */
-
-int gdb_condition_true_at_breakpoint (CORE_ADDR where);
+int gdb_condition_true_at_breakpoint (CORE_ADDR where, int exec_cmds);

 int gdb_no_commands_at_breakpoint (CORE_ADDR where);



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