From patchwork Thu May 16 20:35:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 32732 Received: (qmail 52681 invoked by alias); 16 May 2019 20:44:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 52132 invoked by uid 89); 16 May 2019 20:44:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 May 2019 20:44:06 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8DEF550BB for ; Thu, 16 May 2019 20:35:13 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B2A25C70A; Thu, 16 May 2019 20:35:13 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Sergio Durigan Junior Subject: [FYI 5/5] Make stap-probe.c:stap_parse_register_operand's "regname" an std::string Date: Thu, 16 May 2019 16:35:01 -0400 Message-Id: <20190516203501.25992-6-sergiodj@redhat.com> In-Reply-To: <20190516203501.25992-1-sergiodj@redhat.com> References: <20190516203501.25992-1-sergiodj@redhat.com> X-IsSubscribed: yes 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 faee99916e..2dc9198098 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 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);