From 677052f2a5c67f1d9b2e6d1b2a2149b5f0c20cd0 Mon Sep 17 00:00:00 2001 From: Sergio Durigan Junior Date: Thu, 16 May 2019 16:23:24 -0400 Subject: [PATCH] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string 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 * 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 faee99916ee..2dc91980988 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-05-16 Sergio Durigan Junior + + * stap-probe.c (stap_parse_register_operand): Make "regname" an + "std::string", simplifying the algorithm. + 2019-05-16 Sergio Durigan Junior * stap-probe.c (handle_stap_probe): Fix complaint formatting. diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index 5261a1aaa45..e5a901b4bf6 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.30.2