From patchwork Sun Dec 3 01:52:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 24696 Received: (qmail 89617 invoked by alias); 3 Dec 2017 01:52:09 -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 86320 invoked by uid 89); 3 Dec 2017 01:52:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=Hx-languages-length:2219 X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 03 Dec 2017 01:52:05 +0000 X-ASG-Debug-ID: 1512265923-0c856e65d53e33590001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id tSBVXJcw2MY0SmhY (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 02 Dec 2017 20:52:03 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) by smtp.ebox.ca (Postfix) with ESMTP id BCDED441D64; Sat, 2 Dec 2017 20:52:03 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-251-162.qc.cable.ebox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] Make parse_debug_format_options return an std::string Date: Sat, 2 Dec 2017 20:52:01 -0500 X-ASG-Orig-Subj: [PATCH] Make parse_debug_format_options return an std::string Message-Id: <20171203015201.31012-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1512265923 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 2445 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.45461 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes This avoid having to manually free the return value. gdb/gdbserver/ChangeLog: * server.c (parse_debug_format_options): Return std::string. (handle_monitor_command, captured_main): Adjust. --- gdb/gdbserver/server.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index e2b75376ee..94532e9d7d 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -1295,7 +1295,7 @@ handle_detach (char *own_buf) to gdb's "set debug foo on|off" because we also use this function to parse "--debug-format=foo,bar". */ -static char * +static std::string parse_debug_format_options (const char *arg, int is_monitor) { VEC (char_ptr) *options; @@ -1338,8 +1338,8 @@ parse_debug_format_options (const char *arg, int is_monitor) } else { - char *msg = xstrprintf ("Unknown debug-format argument: \"%s\"\n", - option); + std::string msg + = string_printf ("Unknown debug-format argument: \"%s\"\n", option); free_char_ptr_vec (options); return msg; @@ -1347,7 +1347,7 @@ parse_debug_format_options (const char *arg, int is_monitor) } free_char_ptr_vec (options); - return NULL; + return std::string (); } /* Handle monitor commands not handled by target-specific handlers. */ @@ -1387,16 +1387,15 @@ handle_monitor_command (char *mon, char *own_buf) } else if (startswith (mon, "set debug-format ")) { - char *error_msg + std::string error_msg = parse_debug_format_options (mon + sizeof ("set debug-format ") - 1, 1); - if (error_msg != NULL) + if (!error_msg.empty ()) { - monitor_output (error_msg); + monitor_output (error_msg.c_str ()); monitor_show_help (); write_enn (own_buf); - xfree (error_msg); } } else if (strcmp (mon, "help") == 0) @@ -3611,13 +3610,13 @@ captured_main (int argc, char *argv[]) debug_threads = 1; else if (startswith (*next_arg, "--debug-format=")) { - char *error_msg + std::string error_msg = parse_debug_format_options ((*next_arg) + sizeof ("--debug-format=") - 1, 0); - if (error_msg != NULL) + if (!error_msg.empty ()) { - fprintf (stderr, "%s", error_msg); + fprintf (stderr, "%s", error_msg.c_str ()); exit (1); } }