diff options
author | Tom de Vries <tdevries@suse.de> | 2021-10-09 18:58:30 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2021-10-09 18:58:30 +0200 |
commit | 84a6adfd4c7bc9e99a270b8a111da7218a0e89a5 (patch) | |
tree | 2c9335466ee4a93d7d2b907a4e6f3f1a8fecd2af /gdb/gdbcmd.h | |
parent | fa9ce2c143ce7ee6bc4f22a0577fe5c0858beddd (diff) | |
download | fsf-binutils-gdb-84a6adfd4c7bc9e99a270b8a111da7218a0e89a5.zip fsf-binutils-gdb-84a6adfd4c7bc9e99a270b8a111da7218a0e89a5.tar.gz fsf-binutils-gdb-84a6adfd4c7bc9e99a270b8a111da7218a0e89a5.tar.bz2 |
[gdb] Make execute_command_to_string return string on throw
The pattern for using execute_command_to_string is:
...
std::string output;
output = execute_fn_to_string (fn, term_out);
...
This results in a problem when using it in a try/catch:
...
try
{
output = execute_fn_to_string (fn, term_out)
}
catch (const gdb_exception &e)
{
/* Use output. */
}
...
If an expection was thrown during execute_fn_to_string, then the output
remains unassigned, while it could be worthwhile to known what output was
generated by gdb before the expection was thrown.
Fix this by returning the string using a parameter instead:
...
execute_fn_to_string (output, fn, term_out)
...
Also add a variant without string parameter, to support places where the
function is used while ignoring the result:
...
execute_fn_to_string (fn, term_out)
...
Tested on x86_64-linux.
Diffstat (limited to 'gdb/gdbcmd.h')
-rw-r--r-- | gdb/gdbcmd.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h index 59afb0a..39f5ede 100644 --- a/gdb/gdbcmd.h +++ b/gdb/gdbcmd.h @@ -42,7 +42,8 @@ extern void execute_fn_to_ui_file (struct ui_file *file, std::function<void(void (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. */ @@ -51,8 +52,13 @@ extern void execute_command_to_ui_file (struct ui_file *file, /* 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 *); |