mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
[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.
This commit is contained in:
@@ -1924,11 +1924,11 @@ namespace selftests {
|
||||
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 ();
|
||||
|
||||
@@ -1937,7 +1937,7 @@ test_python ()
|
||||
= make_scoped_restore (&gdb_python_initialized, 0);
|
||||
try
|
||||
{
|
||||
output = CMD;
|
||||
CMD (output);
|
||||
}
|
||||
catch (const gdb_exception &e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user