Hi,
This is my first patch, so apologies in advance for anything that I
haven't done quite right.
In console mode, if I add a 'hook-run' which executes (for example)
'show inferior-tty', the result is printed before the run, and if I add
a 'hookpost-run' with the same command, the result is printed after the
run. This behaviour matches the documentation (and my expectations).
In MI mode, 'show' commands in post-execution hooks seem to be ignored,
and the result of a 'show' in a pre-execution hook is printed AFTER the
hooked command has terminated, for example in an exec-async-output
record as follows:
*stopped,value="<result of show command>",reason="exited-normally"
The following patch modifies the behaviour of a 'show' command executed
in a hook function in MI mode, so that it will print the result using
the console-mode behaviour, wrapped up as an MI console-stream-output
record.
I hope this is reasonable -- please get in touch if it warrants discussion.
To reproduce:
echo "int main() { }" | gcc -x c -
echo -e "set inferior-tty /dev/null\ndefine hook-run\nshow \
inferior-tty\nend\nrun\nquit" > x
gdb -i=mi -x x ./a.out
Patch:
* cli/cli-setshow.c: Print the results of 'show' commands in hook
functions in MI mode using the console-mode behaviour.
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index a7d0728..1659fca 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -21,6 +21,7 @@
#include <ctype.h>
#include "arch-utils.h"
#include "observer.h"
+#include "top.h"
#include "ui-out.h"
@@ -649,7 +650,7 @@ do_show_command (const char *arg, int from_tty,
struct cmd_list_element *c)
code to print the value out. For the latter there should be
MI and CLI specific versions. */
- if (ui_out_is_mi_like_p (uiout))
+ if (ui_out_is_mi_like_p (uiout) && !in_user_command)
ui_out_field_stream (uiout, "value", stb);
else
{