From 84a6adfd4c7bc9e99a270b8a111da7218a0e89a5 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Sat, 9 Oct 2021 18:58:30 +0200 Subject: [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. --- gdb/guile/guile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gdb/guile/guile.c') diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c index a28dee3..8ba840c 100644 --- a/gdb/guile/guile.c +++ b/gdb/guile/guile.c @@ -302,7 +302,7 @@ gdbscm_execute_gdb_command (SCM command_scm, SCM rest) 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); -- cgit v1.1