[3/3] gdb/breakpoint: refactor 'set_breakpoint_condition'

Message ID 453f3c95a7e485dd900541defcc98f0c9cf1dd62.1593438119.git.tankut.baris.aktemur@intel.com
State New
Headers show
Series
  • Prevent bad conditions from putting breakpoints into broken state
Related show

Commit Message

Jose E. Marchesi via Gdb-patches June 29, 2020, 1:48 p.m.
Apply minor refactoring to 'set_breakpoint_condition'.

gdb/ChangeLog:
2020-06-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* breakpoint.c (set_breakpoint_condition): Do minor refactoring.
---
 gdb/breakpoint.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

-- 
2.17.1

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index abda470fe21..aebc123f86f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -840,16 +840,10 @@  set_breakpoint_condition (struct breakpoint *b, const char *exp,
       b->cond_string = nullptr;
 
       if (is_watchpoint (b))
-	{
-	  struct watchpoint *w = (struct watchpoint *) b;
-
-	  w->cond_exp.reset ();
-	}
+	static_cast<watchpoint *> (b)->cond_exp.reset ();
       else
 	{
-	  struct bp_location *loc;
-
-	  for (loc = b->loc; loc; loc = loc->next)
+	  for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next)
 	    {
 	      loc->cond.reset ();
 
@@ -864,31 +858,26 @@  set_breakpoint_condition (struct breakpoint *b, const char *exp,
     }
   else
     {
-      const char *arg = exp;
-
       if (is_watchpoint (b))
 	{
-	  struct watchpoint *w = (struct watchpoint *) b;
-
 	  innermost_block_tracker tracker;
-	  arg = exp;
+	  const char *arg = exp;
 	  expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker);
-	  if (*arg)
+	  if (*arg != 0)
 	    error (_("Junk at end of expression"));
+	  watchpoint *w = static_cast<watchpoint *> (b);
 	  w->cond_exp = std::move (new_exp);
 	  w->cond_exp_valid_block = tracker.block ();
 	}
       else
 	{
-	  struct bp_location *loc;
-
-	  for (loc = b->loc; loc; loc = loc->next)
+	  for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next)
 	    {
-	      arg = exp;
+	      const char *arg = exp;
 	      expression_up new_exp
 		= parse_exp_1 (&arg, loc->address,
 			       block_for_pc (loc->address), 0);
-	      if (*arg)
+	      if (*arg != 0)
 		error (_("Junk at end of expression"));
 	      loc->cond = std::move (new_exp);
 	    }