public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [FYI 0/5] Some improvements on stap code
@ 2019-05-16 20:35 Sergio Durigan Junior
  2019-05-16 20:35 ` [FYI 2/5] Update some comments on stap-probe.c Sergio Durigan Junior
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2019-05-16 20:35 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

Hi,

I had to work on an stap problem recently, and that made me realize
that there were a few simple improvements that could be done on
stap-probe.c, so I went ahead and did them.  They've been pushed under
the obvious rule, but I'm also the maintainer of this part of the
code, and I ran tests to make sure everything was working correctly.

Thanks.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FYI 2/5] Update some comments on stap-probe.c
  2019-05-16 20:35 [FYI 0/5] Some improvements on stap code Sergio Durigan Junior
@ 2019-05-16 20:35 ` Sergio Durigan Junior
  2019-05-16 20:35 ` [FYI 1/5] Bool-ify stap-probe.c and stap-related code on i386-tdep.c Sergio Durigan Junior
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2019-05-16 20:35 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

Some functions's comments were not entirely correct on stap-probe.c,
so this patch updates them.

Pushed as obvious.

gdb/ChangeLog:
2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* stap-probe.c (stap_get_opcode): Update comment.
	(stap_get_expected_argument_type): Likewise.
	(handle_stap_probe): Likewise.
---
 gdb/ChangeLog    |  6 ++++++
 gdb/stap-probe.c | 13 ++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8d40fc95ea..3389167adb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* stap-probe.c (stap_get_opcode): Update comment.
+	(stap_get_expected_argument_type): Likewise.
+	(handle_stap_probe): Likewise.
+
 2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	* i386-tdep.c (i386_stap_parse_special_token_triplet): Change
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 89cd780747..bc2f9fc85b 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -316,8 +316,9 @@ stap_get_operator_prec (enum exp_opcode op)
     }
 }
 
-/* Given S, read the operator in it and fills the OP pointer with its code.
-   Return 1 on success, zero if the operator was not recognized.  */
+/* Given S, read the operator in it.  Return the EXP_OPCODE which
+   represents the operator detected, or throw an error if no operator
+   was found.  */
 
 static enum exp_opcode
 stap_get_opcode (const char **s)
@@ -422,7 +423,8 @@ stap_get_opcode (const char **s)
 }
 
 /* Given the bitness of the argument, represented by B, return the
-   corresponding `struct type *'.  */
+   corresponding `struct type *', or throw an error if B is
+   unknown.  */
 
 static struct type *
 stap_get_expected_argument_type (struct gdbarch *gdbarch,
@@ -1491,10 +1493,7 @@ stap_probe::gen_info_probes_table_values () const
      probe doesn't have an associated semaphore;
    - Probe's provider name;
    - Probe's name;
-   - Probe's argument format
-   
-   This function returns 1 if the handling was successful, and zero
-   otherwise.  */
+   - Probe's argument format.  */
 
 static void
 handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
-- 
2.17.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FYI 1/5] Bool-ify stap-probe.c and stap-related code on i386-tdep.c
  2019-05-16 20:35 [FYI 0/5] Some improvements on stap code Sergio Durigan Junior
  2019-05-16 20:35 ` [FYI 2/5] Update some comments on stap-probe.c Sergio Durigan Junior
@ 2019-05-16 20:35 ` Sergio Durigan Junior
  2019-05-16 20:35 ` [FYI 3/5] Slightly improve logic of some operations on stap-probe.c Sergio Durigan Junior
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2019-05-16 20:35 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This simple patch converts a bunch of "int"s to "bool" on stap-probe.c
and on the stap-related code present on i386-tdep.c.

Pushed as obvious (+ I'm the maintainer of this code).

gdb/ChangeLog:
2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* i386-tdep.c (i386_stap_parse_special_token_triplet): Change
	return type to 'bool'.  Adjust comment.  Use 'bool' when
	appropriate.
	(i386_stap_parse_special_token_three_arg_disp): Likewise.
	* stap-probe.c (stap_parse_argument_1): Likewise.
	(stap_is_operator): Likewise.
	(stap_is_generic_prefix): Likewise.
	(stap_is_register_prefix): Likewise.
	(stap_is_register_indirection_prefix): Likewise.
	(stap_is_integer_prefix): Likewise.
	(stap_generic_check_suffix): Likewise.
	(stap_check_integer_suffix): Likewise.
	(stap_check_register_suffix): Likewise.
	(stap_check_register_indirection_suffix): Likewise.
	(stap_parse_register_operand): Likewise.
	(stap_parse_single_operand): Likewise.
	(stap_parse_argument_1): Likewise.
	(stap_probe::get_argument_count): Likewise.
	(stap_is_operator): Likewise.
---
 gdb/ChangeLog    | 22 +++++++++++
 gdb/i386-tdep.c  | 62 +++++++++++++++---------------
 gdb/stap-probe.c | 99 ++++++++++++++++++++++++------------------------
 3 files changed, 103 insertions(+), 80 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cd71dc3192..8d40fc95ea 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,25 @@
+2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* i386-tdep.c (i386_stap_parse_special_token_triplet): Change
+	return type to 'bool'.  Adjust comment.  Use 'bool' when
+	appropriate.
+	(i386_stap_parse_special_token_three_arg_disp): Likewise.
+	* stap-probe.c (stap_parse_argument_1): Likewise.
+	(stap_is_operator): Likewise.
+	(stap_is_generic_prefix): Likewise.
+	(stap_is_register_prefix): Likewise.
+	(stap_is_register_indirection_prefix): Likewise.
+	(stap_is_integer_prefix): Likewise.
+	(stap_generic_check_suffix): Likewise.
+	(stap_check_integer_suffix): Likewise.
+	(stap_check_register_suffix): Likewise.
+	(stap_check_register_indirection_suffix): Likewise.
+	(stap_parse_register_operand): Likewise.
+	(stap_parse_single_operand): Likewise.
+	(stap_parse_argument_1): Likewise.
+	(stap_probe::get_argument_count): Likewise.
+	(stap_is_operator): Likewise.
+
 2019-05-16  Tom Tromey  <tromey@adacore.com>
 
 	* darwin-nat.c (thread_info_from_private_thread_info): Add struct
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 54d9dd873b..8990583d87 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -4033,10 +4033,10 @@ i386_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
    This function parses operands of the form `-8+3+1(%rbp)', which
    must be interpreted as `*(-8 + 3 - 1 + (void *) $eax)'.
 
-   Return 1 if the operand was parsed successfully, zero
+   Return true if the operand was parsed successfully, false
    otherwise.  */
 
-static int
+static bool
 i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
 				       struct stap_parse_info *p)
 {
@@ -4044,7 +4044,7 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
 
   if (isdigit (*s) || *s == '-' || *s == '+')
     {
-      int got_minus[3];
+      bool got_minus[3];
       int i;
       long displacements[3];
       const char *start;
@@ -4053,17 +4053,17 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
       struct stoken str;
       char *endp;
 
-      got_minus[0] = 0;
+      got_minus[0] = false;
       if (*s == '+')
 	++s;
       else if (*s == '-')
 	{
 	  ++s;
-	  got_minus[0] = 1;
+	  got_minus[0] = true;
 	}
 
       if (!isdigit ((unsigned char) *s))
-	return 0;
+	return false;
 
       displacements[0] = strtol (s, &endp, 10);
       s = endp;
@@ -4071,20 +4071,20 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
       if (*s != '+' && *s != '-')
 	{
 	  /* We are not dealing with a triplet.  */
-	  return 0;
+	  return false;
 	}
 
-      got_minus[1] = 0;
+      got_minus[1] = false;
       if (*s == '+')
 	++s;
       else
 	{
 	  ++s;
-	  got_minus[1] = 1;
+	  got_minus[1] = true;
 	}
 
       if (!isdigit ((unsigned char) *s))
-	return 0;
+	return false;
 
       displacements[1] = strtol (s, &endp, 10);
       s = endp;
@@ -4092,26 +4092,26 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
       if (*s != '+' && *s != '-')
 	{
 	  /* We are not dealing with a triplet.  */
-	  return 0;
+	  return false;
 	}
 
-      got_minus[2] = 0;
+      got_minus[2] = false;
       if (*s == '+')
 	++s;
       else
 	{
 	  ++s;
-	  got_minus[2] = 1;
+	  got_minus[2] = true;
 	}
 
       if (!isdigit ((unsigned char) *s))
-	return 0;
+	return false;
 
       displacements[2] = strtol (s, &endp, 10);
       s = endp;
 
       if (*s != '(' || s[1] != '%')
-	return 0;
+	return false;
 
       s += 2;
       start = s;
@@ -4120,7 +4120,7 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
 	++s;
 
       if (*s++ != ')')
-	return 0;
+	return false;
 
       len = s - start - 1;
       regname = (char *) alloca (len + 1);
@@ -4167,10 +4167,10 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
 
       p->arg = s;
 
-      return 1;
+      return true;
     }
 
-  return 0;
+  return false;
 }
 
 /* Helper function for i386_stap_parse_special_token.
@@ -4179,10 +4179,10 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
    (register index * size) + offset', as represented in
    `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
 
-   Return 1 if the operand was parsed successfully, zero
+   Return true if the operand was parsed successfully, false
    otherwise.  */
 
-static int
+static bool
 i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
 					      struct stap_parse_info *p)
 {
@@ -4190,9 +4190,9 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
 
   if (isdigit (*s) || *s == '(' || *s == '-' || *s == '+')
     {
-      int offset_minus = 0;
+      bool offset_minus = false;
       long offset = 0;
-      int size_minus = 0;
+      bool size_minus = false;
       long size = 0;
       const char *start;
       char *base;
@@ -4206,11 +4206,11 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
       else if (*s == '-')
 	{
 	  ++s;
-	  offset_minus = 1;
+	  offset_minus = true;
 	}
 
       if (offset_minus && !isdigit (*s))
-	return 0;
+	return false;
 
       if (isdigit (*s))
 	{
@@ -4221,7 +4221,7 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
 	}
 
       if (*s != '(' || s[1] != '%')
-	return 0;
+	return false;
 
       s += 2;
       start = s;
@@ -4230,7 +4230,7 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
 	++s;
 
       if (*s != ',' || s[1] != '%')
-	return 0;
+	return false;
 
       len_base = s - start;
       base = (char *) alloca (len_base + 1);
@@ -4257,7 +4257,7 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
 	       index, p->saved_arg);
 
       if (*s != ',' && *s != ')')
-	return 0;
+	return false;
 
       if (*s == ',')
 	{
@@ -4269,14 +4269,14 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
 	  else if (*s == '-')
 	    {
 	      ++s;
-	      size_minus = 1;
+	      size_minus = true;
 	    }
 
 	  size = strtol (s, &endp, 10);
 	  s = endp;
 
 	  if (*s != ')')
-	    return 0;
+	    return false;
 	}
 
       ++s;
@@ -4330,10 +4330,10 @@ i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
 
       p->arg = s;
 
-      return 1;
+      return true;
     }
 
-  return 0;
+  return false;
 }
 
 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index e70940c487..89cd780747 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -257,14 +257,14 @@ enum stap_operand_prec
   STAP_OPERAND_PREC_MUL
 };
 
-static void stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
+static void stap_parse_argument_1 (struct stap_parse_info *p, bool has_lhs,
 				   enum stap_operand_prec prec);
 
 static void stap_parse_argument_conditionally (struct stap_parse_info *p);
 
-/* Returns 1 if *S is an operator, zero otherwise.  */
+/* Returns true if *S is an operator, false otherwise.  */
 
-static int stap_is_operator (const char *op);
+static bool stap_is_operator (const char *op);
 
 static void
 show_stapexpressiondebug (struct ui_file *file, int from_tty,
@@ -474,9 +474,9 @@ stap_get_expected_argument_type (struct gdbarch *gdbarch,
 
    This function does a case-insensitive match.
 
-   Return 1 if any prefix has been found, zero otherwise.  */
+   Return true if any prefix has been found, false otherwise.  */
 
-static int
+static bool
 stap_is_generic_prefix (struct gdbarch *gdbarch, const char *s,
 			const char **r, const char *const *prefixes)
 {
@@ -487,7 +487,7 @@ stap_is_generic_prefix (struct gdbarch *gdbarch, const char *s,
       if (r != NULL)
 	*r = "";
 
-      return 1;
+      return true;
     }
 
   for (p = prefixes; *p != NULL; ++p)
@@ -496,16 +496,16 @@ stap_is_generic_prefix (struct gdbarch *gdbarch, const char *s,
 	if (r != NULL)
 	  *r = *p;
 
-	return 1;
+	return true;
       }
 
-  return 0;
+  return false;
 }
 
-/* Return 1 if S points to a register prefix, zero otherwise.  For a
-   description of the arguments, look at stap_is_generic_prefix.  */
+/* Return true if S points to a register prefix, false otherwise.  For
+   a description of the arguments, look at stap_is_generic_prefix.  */
 
-static int
+static bool
 stap_is_register_prefix (struct gdbarch *gdbarch, const char *s,
 			 const char **r)
 {
@@ -514,11 +514,11 @@ stap_is_register_prefix (struct gdbarch *gdbarch, const char *s,
   return stap_is_generic_prefix (gdbarch, s, r, t);
 }
 
-/* Return 1 if S points to a register indirection prefix, zero
+/* Return true if S points to a register indirection prefix, false
    otherwise.  For a description of the arguments, look at
    stap_is_generic_prefix.  */
 
-static int
+static bool
 stap_is_register_indirection_prefix (struct gdbarch *gdbarch, const char *s,
 				     const char **r)
 {
@@ -527,15 +527,15 @@ stap_is_register_indirection_prefix (struct gdbarch *gdbarch, const char *s,
   return stap_is_generic_prefix (gdbarch, s, r, t);
 }
 
-/* Return 1 if S points to an integer prefix, zero otherwise.  For a
-   description of the arguments, look at stap_is_generic_prefix.
+/* Return true if S points to an integer prefix, false otherwise.  For
+   a description of the arguments, look at stap_is_generic_prefix.
 
    This function takes care of analyzing whether we are dealing with
    an expected integer prefix, or, if there is no integer prefix to be
    expected, whether we are dealing with a digit.  It does a
    case-insensitive match.  */
 
-static int
+static bool
 stap_is_integer_prefix (struct gdbarch *gdbarch, const char *s,
 			const char **r)
 {
@@ -549,7 +549,7 @@ stap_is_integer_prefix (struct gdbarch *gdbarch, const char *s,
       if (r != NULL)
 	*r = "";
 
-      return isdigit (*s);
+      return isdigit (*s) > 0;
     }
 
   for (p = t; *p != NULL; ++p)
@@ -567,35 +567,35 @@ stap_is_integer_prefix (struct gdbarch *gdbarch, const char *s,
 	  if (r != NULL)
 	    *r = *p;
 
-	  return 1;
+	  return true;
 	}
     }
 
-  return 0;
+  return false;
 }
 
 /* Helper function to check for a generic list of suffixes.  If we are
    not expecting any suffixes, then it just returns 1.  If we are
-   expecting at least one suffix, then it returns 1 if a suffix has
-   been found, zero otherwise.  GDBARCH is the current gdbarch being
+   expecting at least one suffix, then it returns true if a suffix has
+   been found, false otherwise.  GDBARCH is the current gdbarch being
    used.  S is the expression being analyzed.  If R is not NULL, it
    will be used to return the found suffix.  SUFFIXES is the list of
    expected suffixes.  This function does a case-insensitive
    match.  */
 
-static int
+static bool
 stap_generic_check_suffix (struct gdbarch *gdbarch, const char *s,
 			   const char **r, const char *const *suffixes)
 {
   const char *const *p;
-  int found = 0;
+  bool found = false;
 
   if (suffixes == NULL)
     {
       if (r != NULL)
 	*r = "";
 
-      return 1;
+      return true;
     }
 
   for (p = suffixes; *p != NULL; ++p)
@@ -604,18 +604,18 @@ stap_generic_check_suffix (struct gdbarch *gdbarch, const char *s,
 	if (r != NULL)
 	  *r = *p;
 
-	found = 1;
+	found = true;
 	break;
       }
 
   return found;
 }
 
-/* Return 1 if S points to an integer suffix, zero otherwise.  For a
-   description of the arguments, look at
+/* Return true if S points to an integer suffix, false otherwise.  For
+   a description of the arguments, look at
    stap_generic_check_suffix.  */
 
-static int
+static bool
 stap_check_integer_suffix (struct gdbarch *gdbarch, const char *s,
 			   const char **r)
 {
@@ -624,11 +624,11 @@ stap_check_integer_suffix (struct gdbarch *gdbarch, const char *s,
   return stap_generic_check_suffix (gdbarch, s, r, p);
 }
 
-/* Return 1 if S points to a register suffix, zero otherwise.  For a
-   description of the arguments, look at
+/* Return true if S points to a register suffix, false otherwise.  For
+   a description of the arguments, look at
    stap_generic_check_suffix.  */
 
-static int
+static bool
 stap_check_register_suffix (struct gdbarch *gdbarch, const char *s,
 			    const char **r)
 {
@@ -637,11 +637,11 @@ stap_check_register_suffix (struct gdbarch *gdbarch, const char *s,
   return stap_generic_check_suffix (gdbarch, s, r, p);
 }
 
-/* Return 1 if S points to a register indirection suffix, zero
+/* Return true if S points to a register indirection suffix, false
    otherwise.  For a description of the arguments, look at
    stap_generic_check_suffix.  */
 
-static int
+static bool
 stap_check_register_indirection_suffix (struct gdbarch *gdbarch, const char *s,
 					const char **r)
 {
@@ -674,10 +674,11 @@ stap_parse_register_operand (struct stap_parse_info *p)
 {
   /* Simple flag to indicate whether we have seen a minus signal before
      certain number.  */
-  int got_minus = 0;
+  bool got_minus = false;
   /* Flags to indicate whether this register access is being displaced and/or
      indirected.  */
-  int disp_p = 0, indirect_p = 0;
+  bool disp_p = false;
+  bool indirect_p = false;
   struct gdbarch *gdbarch = p->gdbarch;
   /* Needed to generate the register name as a part of an expression.  */
   struct stoken str;
@@ -705,7 +706,7 @@ stap_parse_register_operand (struct stap_parse_info *p)
 
   if (*p->arg == '-')
     {
-      got_minus = 1;
+      got_minus = true;
       ++p->arg;
     }
 
@@ -715,7 +716,7 @@ stap_parse_register_operand (struct stap_parse_info *p)
       long displacement;
       char *endp;
 
-      disp_p = 1;
+      disp_p = true;
       displacement = strtol (p->arg, &endp, 10);
       p->arg = endp;
 
@@ -731,7 +732,7 @@ stap_parse_register_operand (struct stap_parse_info *p)
   /* Getting rid of register indirection prefix.  */
   if (stap_is_register_indirection_prefix (gdbarch, p->arg, &reg_ind_prefix))
     {
-      indirect_p = 1;
+      indirect_p = true;
       p->arg += strlen (reg_ind_prefix);
     }
 
@@ -854,7 +855,7 @@ stap_parse_single_operand (struct stap_parse_info *p)
       char c = *p->arg;
       /* We use this variable to do a lookahead.  */
       const char *tmp = p->arg;
-      int has_digit = 0;
+      bool has_digit = false;
 
       /* Skipping signal.  */
       ++tmp;
@@ -879,7 +880,7 @@ stap_parse_single_operand (struct stap_parse_info *p)
 	     called below ('stap_parse_argument_conditionally' or
 	     'stap_parse_register_operand').  */
 	  ++tmp;
-	  has_digit = 1;
+	  has_digit = true;
 	}
 
       if (has_digit && stap_is_register_indirection_prefix (gdbarch, tmp,
@@ -1023,7 +1024,7 @@ stap_parse_argument_conditionally (struct stap_parse_info *p)
    better understand what this function does.  */
 
 static void
-stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
+stap_parse_argument_1 (struct stap_parse_info *p, bool has_lhs,
 		       enum stap_operand_prec prec)
 {
   /* This is an operator-precedence parser.
@@ -1295,7 +1296,7 @@ stap_probe::get_argument_count (struct frame_info *frame)
 	this->parse_arguments (gdbarch);
       else
 	{
-	  static int have_warned_stap_incomplete = 0;
+	  static bool have_warned_stap_incomplete = false;
 
 	  if (!have_warned_stap_incomplete)
 	    {
@@ -1303,7 +1304,7 @@ stap_probe::get_argument_count (struct frame_info *frame)
 "The SystemTap SDT probe support is not fully implemented on this target;\n"
 "you will not be able to inspect the arguments of the probes.\n"
 "Please report a bug against GDB requesting a port to this target."));
-	      have_warned_stap_incomplete = 1;
+	      have_warned_stap_incomplete = true;
 	    }
 
 	  /* Marking the arguments as "already parsed".  */
@@ -1315,13 +1316,13 @@ stap_probe::get_argument_count (struct frame_info *frame)
   return m_parsed_args.size ();
 }
 
-/* Return 1 if OP is a valid operator inside a probe argument, or zero
-   otherwise.  */
+/* Return true if OP is a valid operator inside a probe argument, or
+   false otherwise.  */
 
-static int
+static bool
 stap_is_operator (const char *op)
 {
-  int ret = 1;
+  bool ret = true;
 
   switch (*op)
     {
@@ -1340,12 +1341,12 @@ stap_is_operator (const char *op)
 
     case '=':
       if (op[1] != '=')
-	ret = 0;
+	ret = false;
       break;
 
     default:
       /* We didn't find any operator.  */
-      ret = 0;
+      ret = false;
     }
 
   return ret;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FYI 3/5] Slightly improve logic of some operations on stap-probe.c
  2019-05-16 20:35 [FYI 0/5] Some improvements on stap code Sergio Durigan Junior
  2019-05-16 20:35 ` [FYI 2/5] Update some comments on stap-probe.c Sergio Durigan Junior
  2019-05-16 20:35 ` [FYI 1/5] Bool-ify stap-probe.c and stap-related code on i386-tdep.c Sergio Durigan Junior
@ 2019-05-16 20:35 ` Sergio Durigan Junior
  2019-05-16 20:41 ` [FYI 4/5] Fix complaint string formatting " Sergio Durigan Junior
  2019-05-16 20:44 ` [FYI 5/5] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string Sergio Durigan Junior
  4 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2019-05-16 20:35 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This patch contains three very small improvement on the logic of some
operations we do on stap-probe.c.  They don't change what the code
does.

Pushed as obvious.

gdb/ChangeLog:
2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* stap-probe.c (stap_parse_register_operand): Make "if (*p->arg ==
	'-')" and "else if".
	(stap_parse_single_operand): Join checks for
	"gdbarch_stap_parse_special_token_p" and
	"gdbarch_stap_parse_special_token" in the same "if" statement.
	Invert check when verifying for operation on register
	displacement.
---
 gdb/ChangeLog    | 10 ++++++++++
 gdb/stap-probe.c | 21 ++++++++++-----------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3389167adb..c89b7039e8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* stap-probe.c (stap_parse_register_operand): Make "if (*p->arg ==
+	'-')" and "else if".
+	(stap_parse_single_operand): Join checks for
+	"gdbarch_stap_parse_special_token_p" and
+	"gdbarch_stap_parse_special_token" in the same "if" statement.
+	Invert check when verifying for operation on register
+	displacement.
+
 2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	* stap-probe.c (stap_get_opcode): Update comment.
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index bc2f9fc85b..db9231558f 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -705,8 +705,7 @@ stap_parse_register_operand (struct stap_parse_info *p)
 	 pointer.  */
       ++p->arg;
     }
-
-  if (*p->arg == '-')
+  else if (*p->arg == '-')
     {
       got_minus = true;
       ++p->arg;
@@ -842,15 +841,15 @@ stap_parse_single_operand (struct stap_parse_info *p)
   const char *int_prefix = NULL;
 
   /* We first try to parse this token as a "special token".  */
-  if (gdbarch_stap_parse_special_token_p (gdbarch))
-    if (gdbarch_stap_parse_special_token (gdbarch, p) != 0)
-      {
-	/* If the return value of the above function is not zero,
-	   it means it successfully parsed the special token.
+  if (gdbarch_stap_parse_special_token_p (gdbarch)
+      && (gdbarch_stap_parse_special_token (gdbarch, p) != 0))
+    {
+      /* If the return value of the above function is not zero,
+	 it means it successfully parsed the special token.
 
-	   If it is NULL, we try to parse it using our method.  */
-	return;
-      }
+	 If it is NULL, we try to parse it using our method.  */
+      return;
+    }
 
   if (*p->arg == '-' || *p->arg == '~' || *p->arg == '+')
     {
@@ -890,7 +889,7 @@ stap_parse_single_operand (struct stap_parse_info *p)
 	{
 	  /* If we are here, it means it is a displacement.  The only
 	     operations allowed here are `-' and `+'.  */
-	  if (c == '~')
+	  if (c != '-' && c != '+')
 	    error (_("Invalid operator `%c' for register displacement "
 		     "on expression `%s'."), c, p->saved_arg);
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FYI 4/5] Fix complaint string formatting on stap-probe.c
  2019-05-16 20:35 [FYI 0/5] Some improvements on stap code Sergio Durigan Junior
                   ` (2 preceding siblings ...)
  2019-05-16 20:35 ` [FYI 3/5] Slightly improve logic of some operations on stap-probe.c Sergio Durigan Junior
@ 2019-05-16 20:41 ` Sergio Durigan Junior
  2019-05-16 20:44 ` [FYI 5/5] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string Sergio Durigan Junior
  4 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2019-05-16 20:41 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

I think the string formatting for complaints was messed up by Tom's
patch to simplify the complaint mechanism.  This small and trivial
patch fixes them.

Pushed as obvious.

gdb/ChangeLog:
2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* stap-probe.c (handle_stap_probe): Fix complaint formatting.
	(stap_static_probe_ops::get_probes): Likewise.
---
 gdb/ChangeLog    |  5 +++++
 gdb/stap-probe.c | 13 +++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c89b7039e8..faee99916e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* stap-probe.c (handle_stap_probe): Fix complaint formatting.
+	(stap_static_probe_ops::get_probes): Likewise.
+
 2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	* stap-probe.c (stap_parse_register_operand): Make "if (*p->arg ==
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index db9231558f..5261a1aaa4 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -1512,12 +1512,11 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
   /* Making sure there is a name.  */
   if (name == NULL)
     {
-      complaint (_("corrupt probe name when "
-					"reading `%s'"),
+      complaint (_("corrupt probe name when reading `%s'"),
 		 objfile_name (objfile));
 
       /* There is no way to use a probe without a name or a provider, so
-	 returning zero here makes sense.  */
+	 returning here makes sense.  */
       return;
     }
   else
@@ -1549,11 +1548,10 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
       || (memchr (probe_args, '\0', (char *) el->data + el->size - name)
 	  != el->data + el->size - 1))
     {
-      complaint (_("corrupt probe argument when "
-					"reading `%s'"),
+      complaint (_("corrupt probe argument when reading `%s'"),
 		 objfile_name (objfile));
       /* If the argument string is NULL, it means some problem happened with
-	 it.  So we return 0.  */
+	 it.  So we return.  */
       return;
     }
 
@@ -1661,8 +1659,7 @@ stap_static_probe_ops::get_probes
     {
       /* If we are here, it means we have failed to parse every known
 	 probe.  */
-      complaint (_("could not parse SystemTap probe(s) "
-					"from inferior"));
+      complaint (_("could not parse SystemTap probe(s) from inferior"));
       return;
     }
 }
-- 
2.17.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FYI 5/5] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string
  2019-05-16 20:35 [FYI 0/5] Some improvements on stap code Sergio Durigan Junior
                   ` (3 preceding siblings ...)
  2019-05-16 20:41 ` [FYI 4/5] Fix complaint string formatting " Sergio Durigan Junior
@ 2019-05-16 20:44 ` Sergio Durigan Junior
  4 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2019-05-16 20:44 UTC (permalink / raw)
  To: GDB Patches; +Cc: Sergio Durigan Junior

This patch simplifies the code of
stap-probe.c:stap_parse_register_operand by making "regname" an
std::string.  No functionality change.

I'm this code's maintainer, so I'm pushing this as it's a fairly
trivial patch.

gdb/ChangeLog:
2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* stap-probe.c (stap_parse_register_operand): Make "regname" an
	"std::string", simplifying the algorithm.
---
 gdb/ChangeLog    |  5 +++++
 gdb/stap-probe.c | 36 ++++++++++++------------------------
 2 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index faee99916e..2dc9198098 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* stap-probe.c (stap_parse_register_operand): Make "regname" an
+	"std::string", simplifying the algorithm.
+
 2019-05-16  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	* stap-probe.c (handle_stap_probe): Fix complaint formatting.
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 5261a1aaa4..e5a901b4bf 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -687,12 +687,8 @@ stap_parse_register_operand (struct stap_parse_info *p)
   /* Variables used to extract the register name from the probe's
      argument.  */
   const char *start;
-  char *regname;
-  int len;
   const char *gdb_reg_prefix = gdbarch_stap_gdb_register_prefix (gdbarch);
-  int gdb_reg_prefix_len = gdb_reg_prefix ? strlen (gdb_reg_prefix) : 0;
   const char *gdb_reg_suffix = gdbarch_stap_gdb_register_suffix (gdbarch);
-  int gdb_reg_suffix_len = gdb_reg_suffix ? strlen (gdb_reg_suffix) : 0;
   const char *reg_prefix;
   const char *reg_ind_prefix;
   const char *reg_suffix;
@@ -753,37 +749,29 @@ stap_parse_register_operand (struct stap_parse_info *p)
   while (isalnum (*p->arg))
     ++p->arg;
 
-  len = p->arg - start;
-
-  regname = (char *) alloca (len + gdb_reg_prefix_len + gdb_reg_suffix_len + 1);
-  regname[0] = '\0';
+  std::string regname (start, p->arg - start);
 
   /* We only add the GDB's register prefix/suffix if we are dealing with
      a numeric register.  */
-  if (gdb_reg_prefix && isdigit (*start))
+  if (isdigit (*start))
     {
-      strncpy (regname, gdb_reg_prefix, gdb_reg_prefix_len);
-      strncpy (regname + gdb_reg_prefix_len, start, len);
-
-      if (gdb_reg_suffix)
-	strncpy (regname + gdb_reg_prefix_len + len,
-		 gdb_reg_suffix, gdb_reg_suffix_len);
+      if (gdb_reg_prefix != NULL)
+	regname = gdb_reg_prefix + regname;
 
-      len += gdb_reg_prefix_len + gdb_reg_suffix_len;
+      if (gdb_reg_suffix != NULL)
+	regname += gdb_reg_suffix;
     }
-  else
-    strncpy (regname, start, len);
-
-  regname[len] = '\0';
 
   /* Is this a valid register name?  */
-  if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
+  if (user_reg_map_name_to_regnum (gdbarch,
+				   regname.c_str (),
+				   regname.size ()) == -1)
     error (_("Invalid register name `%s' on expression `%s'."),
-	   regname, p->saved_arg);
+	   regname.c_str (), p->saved_arg);
 
   write_exp_elt_opcode (&p->pstate, OP_REGISTER);
-  str.ptr = regname;
-  str.length = len;
+  str.ptr = regname.c_str ();
+  str.length = regname.size ();
   write_exp_string (&p->pstate, str);
   write_exp_elt_opcode (&p->pstate, OP_REGISTER);
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-05-16 20:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-16 20:35 [FYI 0/5] Some improvements on stap code Sergio Durigan Junior
2019-05-16 20:35 ` [FYI 2/5] Update some comments on stap-probe.c Sergio Durigan Junior
2019-05-16 20:35 ` [FYI 1/5] Bool-ify stap-probe.c and stap-related code on i386-tdep.c Sergio Durigan Junior
2019-05-16 20:35 ` [FYI 3/5] Slightly improve logic of some operations on stap-probe.c Sergio Durigan Junior
2019-05-16 20:41 ` [FYI 4/5] Fix complaint string formatting " Sergio Durigan Junior
2019-05-16 20:44 ` [FYI 5/5] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string Sergio Durigan Junior

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).