Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 3/8] Use std::string in utils.c
Date: Sun, 01 Oct 2017 04:07:00 -0000	[thread overview]
Message-ID: <20171001040643.25162-4-tom@tromey.com> (raw)
In-Reply-To: <20171001040643.25162-1-tom@tromey.com>

This converts internal_vproblem and defaulted_query to use
std::string.

2017-09-30  Tom Tromey  <tom@tromey.com>

	* 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  <tom@tromey.com>
 
+	* utils.c (internal_vproblem): Use std::string.
+	(defaulted_query): Likewise.
+
+2017-09-30  Tom Tromey  <tom@tromey.com>
+
 	* 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;
 }
 \f
-- 
2.9.5


  parent reply	other threads:[~2017-10-01  4:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-01  4:06 [RFA 0/8] more cleanup removal Tom Tromey
2017-10-01  4:06 ` [RFA 4/8] Remove unused declarations Tom Tromey
2017-10-01  4:06 ` [RFA 8/8] Use std::string in info_symbol_command Tom Tromey
2017-10-01  4:06 ` [RFA 6/8] Remove make_delete_ui_cleanup Tom Tromey
2017-10-01  4:07 ` [RFA 7/8] Use std::string in gdb_safe_append_history Tom Tromey
2017-10-01  4:07 ` [RFA 1/8] Change record_full_gdb_operation_disable_set not to return a cleanup Tom Tromey
2017-10-01  4:07 ` Tom Tromey [this message]
2017-10-03 10:50   ` [RFA 3/8] Use std::string in utils.c Pedro Alves
2017-10-03 11:26     ` Tom Tromey
2017-10-01  4:07 ` [RFA 5/8] Use gdb::byte_vector in load_progress Tom Tromey
2017-10-01  4:07 ` [RFA 2/8] Remove set_batch_flag_and_make_cleanup_restore_page_info Tom Tromey
2017-10-03 10:55 ` [RFA 0/8] more cleanup removal Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171001040643.25162-4-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox