From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102637 invoked by alias); 1 Oct 2017 04:07:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 102475 invoked by uid 89); 1 Oct 2017 04:07:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=4668, sk:filter X-HELO: outbound-ss-1812.hostmonster.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO outbound-ss-1812.hostmonster.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Oct 2017 04:07:22 +0000 Received: from CMOut01 (cmgw2 [10.0.90.82]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 003B1175B53 for ; Sat, 30 Sep 2017 22:07:20 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id G47H1w01P2f2jeq0147L6j; Sat, 30 Sep 2017 22:07:20 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=8Cpd6-EWiztLyEBEaxQA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-0-208.hlrn.qwest.net ([75.166.0.208]:43148 helo=pokyo.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dyVWg-002l9R-O8; Sat, 30 Sep 2017 22:06:46 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/8] Use std::string in utils.c Date: Sun, 01 Oct 2017 04:07:00 -0000 Message-Id: <20171001040643.25162-4-tom@tromey.com> In-Reply-To: <20171001040643.25162-1-tom@tromey.com> References: <20171001040643.25162-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dyVWg-002l9R-O8 X-Source-Sender: 75-166-0-208.hlrn.qwest.net (pokyo.Home) [75.166.0.208]:43148 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes X-SW-Source: 2017-10/txt/msg00005.txt.bz2 This converts internal_vproblem and defaulted_query to use std::string. 2017-09-30 Tom Tromey * utils.c (internal_vproblem): Use std::string. (defaulted_query): Likewise. --- gdb/ChangeLog | 5 +++++ gdb/utils.c | 45 ++++++++++++++++++++------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a17a83c..6744ac0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-09-30 Tom Tromey + * utils.c (internal_vproblem): Use std::string. + (defaulted_query): Likewise. + +2017-09-30 Tom Tromey + * guile/scm-ports.c (ioscm_with_output_to_port_worker): Update. * top.c (execute_command_to_string): Update. * utils.c (make_cleanup_restore_page_info): Remove. diff --git a/gdb/utils.c b/gdb/utils.c index 0c59b4e..7595c21 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -392,8 +392,7 @@ internal_vproblem (struct internal_problem *problem, static int dejavu; int quit_p; int dump_core_p; - char *reason; - struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); + std::string reason; /* Don't allow infinite error/warning recursion. */ { @@ -429,18 +428,17 @@ internal_vproblem (struct internal_problem *problem, char *msg; msg = xstrvprintf (fmt, ap); - reason = xstrprintf ("%s:%d: %s: %s\n" - "A problem internal to GDB has been detected,\n" - "further debugging may prove unreliable.", - file, line, problem->name, msg); + reason = string_printf ("%s:%d: %s: %s\n" + "A problem internal to GDB has been detected,\n" + "further debugging may prove unreliable.", + file, line, problem->name, msg); xfree (msg); - make_cleanup (xfree, reason); } /* Fall back to abort_with_message if gdb_stderr is not set up. */ if (current_ui == NULL) { - fputs (reason, stderr); + fputs (reason.c_str (), stderr); abort_with_message ("\n"); } @@ -458,7 +456,7 @@ internal_vproblem (struct internal_problem *problem, if (problem->should_quit != internal_problem_ask || !confirm || !filtered_printing_initialized ()) - fprintf_unfiltered (gdb_stderr, "%s\n", reason); + fprintf_unfiltered (gdb_stderr, "%s\n", reason.c_str ()); if (problem->should_quit == internal_problem_ask) { @@ -468,7 +466,8 @@ internal_vproblem (struct internal_problem *problem, if (!confirm || !filtered_printing_initialized ()) quit_p = 1; else - quit_p = query (_("%s\nQuit this debugging session? "), reason); + quit_p = query (_("%s\nQuit this debugging session? "), + reason.c_str ()); } else if (problem->should_quit == internal_problem_yes) quit_p = 1; @@ -485,7 +484,7 @@ internal_vproblem (struct internal_problem *problem, if (problem->should_dump_core == internal_problem_ask) { - if (!can_dump_core_warn (LIMIT_MAX, reason)) + if (!can_dump_core_warn (LIMIT_MAX, reason.c_str ())) dump_core_p = 0; else if (!filtered_printing_initialized ()) dump_core_p = 1; @@ -494,11 +493,12 @@ internal_vproblem (struct internal_problem *problem, /* Default (yes/batch case) is to dump core. This leaves a GDB `dropping' so that it is easier to see that something went wrong in GDB. */ - dump_core_p = query (_("%s\nCreate a core file of GDB? "), reason); + dump_core_p = query (_("%s\nCreate a core file of GDB? "), + reason.c_str ()); } } else if (problem->should_dump_core == internal_problem_yes) - dump_core_p = can_dump_core_warn (LIMIT_MAX, reason); + dump_core_p = can_dump_core_warn (LIMIT_MAX, reason.c_str ()); else if (problem->should_dump_core == internal_problem_no) dump_core_p = 0; else @@ -523,7 +523,6 @@ internal_vproblem (struct internal_problem *problem, } dejavu = 0; - do_cleanups (cleanup); } static struct internal_problem internal_error_problem = { @@ -915,8 +914,6 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) int def_value; char def_answer, not_def_answer; const char *y_string, *n_string; - char *question, *prompt; - struct cleanup *old_chain; /* Set up according to which answer is the default. */ if (defchar == '\0') @@ -978,13 +975,12 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) } /* Format the question outside of the loop, to avoid reusing args. */ - question = xstrvprintf (ctlstr, args); - old_chain = make_cleanup (xfree, question); - prompt = xstrprintf (_("%s%s(%s or %s) %s"), - annotation_level > 1 ? "\n\032\032pre-query\n" : "", - question, y_string, n_string, - annotation_level > 1 ? "\n\032\032query\n" : ""); - make_cleanup (xfree, prompt); + std::string question = string_vprintf (ctlstr, args); + std::string prompt + = string_printf (_("%s%s(%s or %s) %s"), + annotation_level > 1 ? "\n\032\032pre-query\n" : "", + question.c_str (), y_string, n_string, + annotation_level > 1 ? "\n\032\032query\n" : ""); /* Used to add duration we waited for user to respond to prompt_for_continue_wait_time. */ @@ -998,7 +994,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) char *response, answer; gdb_flush (gdb_stdout); - response = gdb_readline_wrapper (prompt); + response = gdb_readline_wrapper (prompt.c_str ()); if (response == NULL) /* C-d */ { @@ -1038,7 +1034,6 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) if (annotation_level > 1) printf_filtered (("\n\032\032post-query\n")); - do_cleanups (old_chain); return retval; } -- 2.9.5