This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb/gdb-8.3-branch] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string
- From: Tom de Vries <vries at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 11 Sep 2019 20:03:48 -0000
- Subject: [binutils-gdb/gdb-8.3-branch] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e9224f6d80ea35e90a61d44575f12b26742eaaf3
commit e9224f6d80ea35e90a61d44575f12b26742eaaf3
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date: Wed Sep 11 22:03:40 2019 +0200
Make stap-probe.c:stap_parse_register_operand's "regname" an std::string
[ Backport of master commit 677052f2a5. ]
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.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/stap-probe.c | 36 ++++++++++++------------------------
2 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c8ddcf6..8410819 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-28 Alan Hayward <alan.hayward@arm.com>
* event-top.c: Remove include comment.
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index a53c04d..64af4d2 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -684,12 +684,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;
@@ -751,37 +747,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);