This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Breakpoint commands in MI mode and "backtrace"


On 2017-10-08 06:08 AM, Eli Zaretskii wrote:
> There seems to be a problem with execution of "bt" as part of
> breakpoint commands in MI mode: the output of "bt" is not shown.
> 
> What I did was invoke GDB as "gdb -i=mi PROGRAM", then set a
> breakpoint or a watchpoint in that program, and defined the following
> as its breakpoint commands:
> 
>   bt
>   end
> 
> When the breakpoint triggers, I don't see the backtrace.
> 
> I tried other commands, like "up" and "print SOME-VARIABLE", and they
> do seem to be executed and the output shown.  So why doesn't that
> happen with "backtrace"?  Is it a bug or am I missing something?
> 
> (FWIW, I also tried using -break-commands, with a similar result: the
> backtrace is not shown when the breakpoint triggers.)
> 
> This problem prevents "bt" from being useful in breakpoint commands
> when running with the Emacs GDB front-end, which uses MI.
> 
> Thanks in advance for any pointers.
> 

It is most certainly a bug, I don't see why a command that produces some output
should work and not another one.

It seems like even though we are executing CLI commands, the current interpreter
and uiout are the MI ones.  I'm always confused by all these data structures, but
I managed to hack it to work with this:

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 0a93e8b54f..bc8e1047c5 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -482,7 +482,10 @@ execute_control_command (struct command_line *cmd)
       {
 	/* A simple command, execute it and return.  */
 	std::string new_line = insert_user_defined_cmd_args (cmd->line);
-	execute_command (&new_line[0], 0);
+
+	scoped_restore_interp restorer (INTERP_CONSOLE);
+	current_interpreter ()->exec (&new_line[0]);
+
 	ret = cmd->control_type;
 	break;
       }

Does that work for you?  It might not be the right solution, but it's a start.

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]