do \
{ \
std::string output; \
- output = execute_fn_to_string ([]() { complaint (STR); }, false); \
+ execute_fn_to_string (output, []() { complaint (STR); }, false); \
std::string expected \
= _("During symbol reading: ") + std::string (STR "\n"); \
SELF_CHECK (output == expected); \
do \
{ \
std::string output; \
- output = execute_fn_to_string ([]() { complaint (STR); }, false); \
+ execute_fn_to_string (output, []() { complaint (STR); }, false); \
SELF_CHECK (output.empty ()); \
SELF_CHECK (counters[STR] == CNT); \
} while (0)
(e.g. with styling). When TERM_OUT is false raw output will be collected
(e.g. no styling). */
-extern std::string execute_fn_to_string (std::function<void(void)> fn, bool term_out);
+extern void execute_fn_to_string (std::string &res,
+ std::function<void(void)> fn, bool term_out);
/* As execute_fn_to_ui_file, but run execute_command for P and FROM_TTY. */
/* As execute_fn_to_string, but run execute_command for P and FROM_TTY. */
-extern std::string execute_command_to_string (const char *p, int from_tty,
- bool term_out);
+extern void execute_command_to_string (std::string &res, const char *p,
+ int from_tty, bool term_out);
+
+/* As execute_command_to_string, but ignore resulting string. */
+
+extern void execute_command_to_string (const char *p,
+ int from_tty, bool term_out);
extern void print_command_line (struct command_line *, unsigned int,
struct ui_file *);
scoped_restore preventer = prevent_dont_repeat ();
if (to_string)
- to_string_res = execute_command_to_string (command, from_tty, false);
+ execute_command_to_string (to_string_res, command, from_tty, false);
else
execute_command (command, from_tty);
static void
test_python ()
{
-#define CMD execute_command_to_string ("python print(5)", 0, true);
+#define CMD(S) execute_command_to_string (S, "python print(5)", 0, true)
std::string output;
- output = CMD;
+ CMD (output);
SELF_CHECK (output == "5\n");
output.clear ();
= make_scoped_restore (&gdb_python_initialized, 0);
try
{
- output = CMD;
+ CMD (output);
}
catch (const gdb_exception &e)
{
set to the selected frame. */
scoped_restore_current_thread restore_fi_current_frame;
- cmd_result = execute_command_to_string
- (cmd, from_tty, gdb_stdout->term_out ());
+ execute_command_to_string
+ (cmd_result, cmd, from_tty, gdb_stdout->term_out ());
}
fi = get_selected_frame (_("frame apply "
"unable to get selected frame."));
try
{
- std::string cmd_result = execute_command_to_string
- (cmd, from_tty, gdb_stdout->term_out ());
+ std::string cmd_result;
+ execute_command_to_string
+ (cmd_result, cmd, from_tty, gdb_stdout->term_out ());
if (!flags.silent || cmd_result.length () > 0)
{
if (!flags.quiet)
/* See gdbcmd.h. */
-std::string
-execute_fn_to_string (std::function<void(void)> fn, bool term_out)
+void
+execute_fn_to_string (std::string &res, std::function<void(void)> fn,
+ bool term_out)
{
string_file str_file (term_out);
- execute_fn_to_ui_file (&str_file, fn);
- return std::move (str_file.string ());
+ try
+ {
+ execute_fn_to_ui_file (&str_file, fn);
+ }
+ catch (...)
+ {
+ /* Finally. */
+ res = std::move (str_file.string ());
+ throw;
+ }
+
+ /* And finally. */
+ res = std::move (str_file.string ());
}
/* See gdbcmd.h. */
/* See gdbcmd.h. */
-std::string
+void
+execute_command_to_string (std::string &res, const char *p, int from_tty,
+ bool term_out)
+{
+ execute_fn_to_string (res, [=]() { execute_command (p, from_tty); },
+ term_out);
+}
+
+/* See gdbcmd.h. */
+
+void
execute_command_to_string (const char *p, int from_tty,
bool term_out)
{
- return
- execute_fn_to_string ([=]() { execute_command (p, from_tty); }, term_out);
+ std::string dummy;
+ execute_fn_to_string (dummy, [=]() { execute_command (p, from_tty); },
+ term_out);
}
\f
/* When nonzero, cause dont_repeat to do nothing. This should only be