2003-02-06 05:30:17 +00:00
|
|
|
/* Manages interpreters for GDB, the GNU debugger.
|
|
|
|
|
2015-01-01 09:32:14 +00:00
|
|
|
Copyright (C) 2000-2015 Free Software Foundation, Inc.
|
2003-02-06 05:30:17 +00:00
|
|
|
|
|
|
|
Written by Jim Ingham <jingham@apple.com> of Apple Computer, Inc.
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-23 18:08:50 +00:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2003-02-06 05:30:17 +00:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-01-09 03:08:57 +00:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2003-02-06 05:30:17 +00:00
|
|
|
|
|
|
|
#ifndef INTERPS_H
|
|
|
|
#define INTERPS_H
|
|
|
|
|
|
|
|
struct ui_out;
|
|
|
|
struct interp;
|
|
|
|
|
|
|
|
extern int interp_resume (struct interp *interp);
|
|
|
|
extern int interp_suspend (struct interp *interp);
|
2005-04-26 05:03:41 +00:00
|
|
|
extern struct gdb_exception interp_exec (struct interp *interp,
|
|
|
|
const char *command);
|
2003-02-06 05:30:17 +00:00
|
|
|
extern int interp_quiet_p (struct interp *interp);
|
|
|
|
|
2011-09-12 21:25:22 +00:00
|
|
|
typedef void *(interp_init_ftype) (struct interp *self, int top_level);
|
2003-02-06 05:30:17 +00:00
|
|
|
typedef int (interp_resume_ftype) (void *data);
|
|
|
|
typedef int (interp_suspend_ftype) (void *data);
|
2005-04-26 05:03:41 +00:00
|
|
|
typedef struct gdb_exception (interp_exec_ftype) (void *data,
|
|
|
|
const char *command);
|
2003-02-12 15:23:20 +00:00
|
|
|
typedef void (interp_command_loop_ftype) (void *data);
|
2011-09-12 21:25:22 +00:00
|
|
|
typedef struct ui_out *(interp_ui_out_ftype) (struct interp *self);
|
2003-02-06 05:30:17 +00:00
|
|
|
|
2012-06-28 22:11:23 +00:00
|
|
|
typedef int (interp_set_logging_ftype) (struct interp *self, int start_log,
|
|
|
|
struct ui_file *out,
|
|
|
|
struct ui_file *logfile);
|
|
|
|
|
2003-02-06 05:30:17 +00:00
|
|
|
struct interp_procs
|
|
|
|
{
|
|
|
|
interp_init_ftype *init_proc;
|
|
|
|
interp_resume_ftype *resume_proc;
|
|
|
|
interp_suspend_ftype *suspend_proc;
|
|
|
|
interp_exec_ftype *exec_proc;
|
2011-09-12 21:25:22 +00:00
|
|
|
|
|
|
|
/* Returns the ui_out currently used to collect results for this
|
|
|
|
interpreter. It can be a formatter for stdout, as is the case
|
|
|
|
for the console & mi outputs, or it might be a result
|
|
|
|
formatter. */
|
|
|
|
interp_ui_out_ftype *ui_out_proc;
|
|
|
|
|
2012-06-28 22:11:23 +00:00
|
|
|
/* Provides a hook for interpreters to do any additional
|
|
|
|
setup/cleanup that they might need when logging is enabled or
|
|
|
|
disabled. */
|
|
|
|
interp_set_logging_ftype *set_logging_proc;
|
|
|
|
|
2003-02-06 05:30:17 +00:00
|
|
|
interp_command_loop_ftype *command_loop_proc;
|
|
|
|
};
|
|
|
|
|
2011-09-12 21:25:22 +00:00
|
|
|
extern struct interp *interp_new (const char *name, const struct interp_procs *procs);
|
2003-02-06 05:30:17 +00:00
|
|
|
extern void interp_add (struct interp *interp);
|
2008-03-14 17:21:08 +00:00
|
|
|
extern int interp_set (struct interp *interp, int top_level);
|
2003-02-06 05:30:17 +00:00
|
|
|
extern struct interp *interp_lookup (const char *name);
|
|
|
|
extern struct ui_out *interp_ui_out (struct interp *interp);
|
2011-09-12 21:25:22 +00:00
|
|
|
extern void *interp_data (struct interp *interp);
|
|
|
|
extern const char *interp_name (struct interp *interp);
|
2012-05-08 18:49:42 +00:00
|
|
|
extern struct interp *interp_set_temp (const char *name);
|
2003-02-06 05:30:17 +00:00
|
|
|
|
|
|
|
extern int current_interp_named_p (const char *name);
|
Make display_gdb_prompt CLI-only.
Enabling target-async by default will require implementing sync
execution on top of an async target, much like foreground command are
implemented on the CLI in async mode.
In order to do that, we will need better control of when to print the
MI prompt. Currently the interp->display_prompt_p hook is all we
have, and MI just always returns false, meaning, make
display_gdb_prompt a no-op. We'll need to be able to know to print
the MI prompt in some of the conditions that display_gdb_prompt is
called from the core, but not all.
This is all a litte twisted currently. As we can see,
display_gdb_prompt is really CLI specific, so make the console
interpreters (console/tui) themselves call it. To be able to do that,
and add a few different observers that the interpreters can use to
distinguish when or why the the prompt is being printed:
#1 - one called whenever a command is cancelled due to an error.
#2 - another for when a foreground command just finished.
In both cases, CLI wants to print the prompt, while MI doesn't.
MI will want to print the prompt in the second case when in a special
MI mode.
The display_gdb_prompt call in interp_set made me pause. The comment
there reads:
/* Finally, put up the new prompt to show that we are indeed here.
Also, display_gdb_prompt for the console does some readline magic
which is needed for the console interpreter, at least... */
But, that looks very much like a no-op to me currently:
- the MI interpreter always return false in the prompt hook, meaning
actually display no prompt.
- the interpreter used at that point is still quiet. And the
console/tui interpreters return false in the prompt hook if they're
quiet, meaning actually display no prompt.
The only remaining possible use would then be the readline magic. But
whatever that might have been, it's not reacheable today either,
because display_gdb_prompt returns early, before touching readline if
the interpreter returns false in the display_prompt_p hook.
Tested on x86_64 Fedora 20, sync and async modes.
gdb/
2014-05-29 Pedro Alves <palves@redhat.com>
* cli/cli-interp.c (cli_interpreter_display_prompt_p): Delete.
(_initialize_cli_interp): Adjust.
* event-loop.c: Include "observer.h".
(start_event_loop): Notify 'command_error' observers instead of
calling display_gdb_prompt. Remove FIXME comment.
* event-top.c (display_gdb_prompt): Remove call into the
interpreters.
* inf-loop.c: Include "observer.h".
(inferior_event_handler): Notify 'command_error' observers instead
of calling display_gdb_prompt.
* infrun.c (fetch_inferior_event): Notify 'sync_execution_done'
observers instead of calling display_gdb_prompt.
* interps.c (interp_set): Don't call display_gdb_prompt.
(current_interp_display_prompt_p): Delete.
* interps.h (interp_prompt_p): Delete declaration.
(interp_prompt_p_ftype): Delete.
(struct interp_procs) <prompt_proc_p>: Delete field.
(current_interp_display_prompt_p): Delete declaration.
* mi-interp.c (mi_interpreter_prompt_p): Delete.
(_initialize_mi_interp): Adjust.
* tui-interp.c (tui_init): Install 'sync_execution_done' and
'command_error' observers.
(tui_on_sync_execution_done, tui_on_command_error): New
functions.
(tui_display_prompt_p): Delete.
(_initialize_tui_interp): Adjust.
gdb/doc/
2014-05-29 Pedro Alves <palves@redhat.com>
* observer.texi (sync_execution_done, command_error): New
subjects.
2014-05-23 10:37:12 +00:00
|
|
|
|
2003-02-06 05:30:17 +00:00
|
|
|
extern void current_interp_command_loop (void);
|
2012-06-28 22:11:23 +00:00
|
|
|
|
|
|
|
/* Call this function to give the current interpreter an opportunity
|
|
|
|
to do any special handling of streams when logging is enabled or
|
|
|
|
disabled. START_LOG is 1 when logging is starting, 0 when it ends,
|
|
|
|
and OUT is the stream for the log file; it will be NULL when
|
|
|
|
logging is ending. LOGFILE is non-NULL if the output streams
|
|
|
|
are to be tees, with the log file as one of the outputs. */
|
|
|
|
|
|
|
|
extern int current_interp_set_logging (int start_log, struct ui_file *out,
|
|
|
|
struct ui_file *logfile);
|
|
|
|
|
2008-03-14 17:21:08 +00:00
|
|
|
/* Returns opaque data associated with the top-level interpreter. */
|
|
|
|
extern void *top_level_interpreter_data (void);
|
2008-04-19 06:09:15 +00:00
|
|
|
extern struct interp *top_level_interpreter (void);
|
2003-02-06 05:30:17 +00:00
|
|
|
|
PR gdb/13860: don't lose '-interpreter-exec console EXECUTION_COMMAND''s output in async mode.
The other part of PR gdb/13860 is about console execution commands in
MI getting their output half lost. E.g., take the finish command,
executed on a frontend's GDB console:
sync:
finish
&"finish\n"
~"Run till exit from #0 usleep (useconds=10) at ../sysdeps/unix/sysv/linux/usleep.c:27\n"
^running
*running,thread-id="1"
(gdb)
~"0x00000000004004d7 in foo () at stepinf.c:6\n"
~"6\t usleep (10);\n"
~"Value returned is $1 = 0\n"
*stopped,reason="function-finished",frame={addr="0x00000000004004d7",func="foo",args=[],file="stepinf.c",fullname="/home/pedro/gdb/tests/stepinf.c",line="6"},thread-id="1",stopped-threads="all",core="1"
async:
finish
&"finish\n"
~"Run till exit from #0 usleep (useconds=10) at ../sysdeps/unix/sysv/linux/usleep.c:27\n"
^running
*running,thread-id="1"
(gdb)
*stopped,reason="function-finished",frame={addr="0x00000000004004d7",func="foo",args=[],file="stepinf.c",fullname="/home/pedro/gdb/tests/stepinf.c",line="6"},gdb-result-var="$1",return-value="0",thread-id="1",stopped-threads="all",core="0"
Note how all the "Value returned" etc. output is missing in async mode.
The same happens with e.g., catchpoints:
=breakpoint-modified,bkpt={number="1",type="catchpoint",disp="keep",enabled="y",what="22016",times="1"}
~"\nCatchpoint "
~"1 (forked process 22016), 0x0000003791cbd8a6 in __libc_fork () at ../nptl/sysdeps/unix/sysv/linux/fork.c:131\n"
~"131\t pid = ARCH_FORK ();\n"
*stopped,reason="fork",disp="keep",bkptno="1",newpid="22016",frame={addr="0x0000003791cbd8a6",func="__libc_fork",args=[],file="../nptl/sysdeps/unix/sysv/linux/fork.c",fullname="/usr/src/debug/glibc-2.14-394-g8f3b1ff/nptl/sysdeps/unix/sysv/linux/fork.c",line="131"},thread-id="1",stopped-threads="all",core="0"
where all those ~ lines are missing in async mode, or just the "step"
current line indication:
s
&"s\n"
^running
*running,thread-id="all"
(gdb)
~"13\t foo ();\n"
*stopped,frame={addr="0x00000000004004ef",func="main",args=[{name="argc",value="1"},{name="argv",value="0x7fffffffdd78"}],file="stepinf.c",fullname="/home/pedro/gdb/tests/stepinf.c",line="13"},thread-id="1",stopped-threads="all",core="3"
(gdb)
Or in the case of the PRs example, the "Stopped due to shared library
event" note:
start
&"start\n"
~"Temporary breakpoint 1 at 0x400608: file ../../../src/gdb/testsuite/gdb.mi/solib-main.c, line 21.\n"
=breakpoint-created,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0x0000000000400608",func="main",file="../../../src/gdb/testsuite/gdb.mi/solib-main.c",fullname="/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.mi/solib-main.c",line="21",times="0",original-location="main"}
~"Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/solib-main \n"
=thread-group-started,id="i1",pid="21990"
=thread-created,id="1",group-id="i1"
^running
*running,thread-id="all"
(gdb)
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
~"Stopped due to shared library event (no libraries added or removed)\n"
*stopped,reason="solib-event",thread-id="1",stopped-threads="all",core="3"
(gdb)
IMO, if you're typing execution commands in a frontend's console, you
expect to see their output. Indeed it's what you get in sync mode. I
think async mode should do the same. Deciding what to mirror to the
console wrt to breakpoints and random stops gets messy real fast.
E.g., say "s" trips on a breakpoint. We'd clearly want to mirror the
event to the console in this case. But what about more complicated
cases like "s&; thread n; s&", and one of those steps spawning a new
thread, and that thread hitting a breakpoint? It's impossible in
general to track whether the thread had any relation to the commands
that had been executed. So I think we should just simplify and always
mirror breakpoints and random events to the console.
Notes:
- mi->out is the same as gdb_stdout when MI is the current
interpreter. I think that referring to that directly is cleaner.
An earlier revision of this patch made the changes that are now
done in mi_on_normal_stop directly in infrun.c:normal_stop, and so
not having an obvious place to put the new uiout by then, and not
wanting to abuse CLI's uiout, I made a temporary uiout when
necessary.
- Hopefuly the rest of the patch is more or less obvious given the
comments added.
Tested on x86_64 Fedora 20, no regressions.
2014-05-21 Pedro Alves <palves@redhat.com>
PR gdb/13860
* gdbthread.h (struct thread_control_state): New field
`command_interp'.
* infrun.c (follow_fork): Copy the new thread control field to the
child fork thread.
(clear_proceed_status_thread): Clear the new thread control field.
(proceed): Set the new thread control field.
* interps.h (command_interp): Declare.
* interps.c (command_interpreter): New global.
(command_interp): New function.
(interp_exec): Set `command_interpreter' while here.
* cli-out.c (cli_uiout_dtor): New function.
(cli_ui_out_impl): Install it.
* mi/mi-interp.c: Include cli-out.h.
(mi_cmd_interpreter_exec): Add comment.
(restore_current_uiout_cleanup): New function.
(ui_out_free_cleanup): New function.
(mi_on_normal_stop): If finishing an execution command started by
a CLI command, or any kind of breakpoint-like event triggered,
print the stop event to the output (CLI) stream.
* mi/mi-out.c (mi_ui_out_impl): Install NULL `dtor' handler.
2014-05-21 Pedro Alves <palves@redhat.com>
PR gdb/13860
* gdb.mi/mi-cli.exp (line_callee4_next_step): New global.
(top level): Test that output related to execution commands is
sent to the console with CLI commands, but not with MI commands.
Test that breakpoint events are always mirrored to the console.
Also expect the new source line to be output after a "next" in
async mode too. Make it a pass/fail test.
* gdb.mi/mi-solib.exp: Test that the CLI solib event note is
output.
* lib/mi-support.exp (mi_gdb_expect_cli_output): New procedure.
2014-03-11 20:31:36 +00:00
|
|
|
extern struct interp *command_interp (void);
|
|
|
|
|
2011-09-02 16:56:30 +00:00
|
|
|
/* True if the current interpreter is in async mode, false if in sync
|
|
|
|
mode. If in sync mode, running a synchronous execution command
|
|
|
|
(with execute_command, e.g, "next") will not return until the
|
|
|
|
command is finished. If in async mode, then running a synchronous
|
|
|
|
command returns right after resuming the target. Waiting for the
|
|
|
|
command's completion is later done on the top event loop (using
|
|
|
|
continuations). */
|
|
|
|
extern int interpreter_async;
|
|
|
|
|
2003-06-08 Andrew Cagney <cagney@redhat.com>
* acinclude.m4 (gcc_AC_CHECK_DECL, (gcc_AC_CHECK_DECL): Stolen
from GCC's acinclude.m4.
* configure.in: Check for getopt's delcaration.
* aclocal.m4, config.in, configure: Re-generate.
* main.c (error_init): Delete declaration.
* defs.h (error_init): Declare.
* rs6000-tdep.c (rs6000_fetch_pointer_argument): Make static.
(rs6000_convert_from_func_ptr_addr): Make static.
(_initialize_rs6000_tdep): Add declaration.
* cli/cli-cmds.c (dont_repeat): Delete declaration.
(show_commands, set_verbose, show_history): Delete declaration.
* top.h (set_verbose): Add declaration.
(show_history, set_history, show_commands): Add declaration.
(do_restore_instream_cleanup): Add declaration.
* objc-lang.c (specialcmp): Make static.
(print_object_command): Make static.
(find_objc_msgsend): Make static.
(find_objc_msgcall_submethod_helper): Make static.
(find_objc_msgcall_submethod): Make static.
(_initialize_objc_language): Add declaration.
(find_implementation_from_class): Make static.
(find_implementation): Make static.
* objc-exp.y (yylex): Delete lookup_struct_typedef declaration.
* objc-lang.h (lookup_struct_typedef): Add declaration.
* cli/cli-interp.c (_initialize_cli_interp): Add declaration.
* cli/cli-script.c (clear_hook_in_cleanup): Make static.
(do_restore_user_call_depth): Make static.
(do_restore_instream_cleanup): Delete declaration.
(dont_repeat): Delete declaration.
* cli/cli-decode.c (add_abbrev_cmd): Delete function.
* cli/cli-dump.c (_initialize_cli_dump): Add declaration.
* reggroups.c (_initialize_reggroup): Add declaration.
* cp-support.c (_initialize_cp_support): Add declaration.
* cp-abi.c (_initialize_cp_abi): Add declaration.
* hpacc-abi.c (_initialize_hpacc_abi): Add declaration.
* gnu-v3-abi.c (gnuv3_baseclass_offset): Make static.
(_initialize_gnu_v3_abi): Add declaration.
* gnu-v2-abi.c (gnuv2_value_rtti_type): Make static.
(_initialize_gnu_v2_abi): Add declaration.
* frame-base.c (_initialize_frame_base): Add declaration.
* doublest.c (floatformat_from_length): Make static.
* frame-unwind.c (_initialize_frame_unwind): Add declaration.
* frame.c (create_sentinel_frame): Make static.
(_initialize_frame): Add declaration.
* top.c (do_catch_errors): Make static.
(gdb_rl_operate_and_get_next_completion): Make static.
* typeprint.c: Include "typeprint.h".
* sentinel-frame.c (sentinel_frame_prev_register): Make static.
(sentinel_frame_this_id): Make static.
* p-valprint.c (_initialize_pascal_valprint): Add declaration.
* ui-out.c (make_cleanup_ui_out_begin_end): Delete function.
* dwarf2-frame.c (dwarf2_frame_cache): Make static.
* p-exp.y (push_current_type, pop_current_type): ISO C declaration.
* dwarf2expr.h (dwarf_expr_context): ISO C declaration.
* maint.c (maintenance_print_architecture): Make static.
* signals/signals.c (_initialize_signals): Add declaration.
* std-regs.c (_initialize_frame_reg): Add declaration.
* jv-exp.y (push_variable): ISO C definition.
(push_qualified_expression_name): Ditto.
* memattr.c (_initialize_mem): Add declaration.
* remote.c (remote_check_watch_resources): Make static.
(remote_stopped_by_watchpoint): Make static.
(remote_stopped_data_address): Make static.
* d10v-tdep.c (nr_dmap_regs): Make static.
(a0_regnum): Make static.
(d10v_frame_unwind_cache): Make static.
(d10v_frame_p): Make static.
* osabi.c (show_osabi): Make static.
(_initialize_gdb_osabi): Add extern declaration.
* gdbtypes.c (make_qualified_type): Make static.
(safe_parse_type): Make static.
* macrocmd.c (_initialize_macrocmd): Add extern declaration.
* macrotab.c (macro_bcache_free): Make static.
* interps.c (interp_set_quiet): Make static.
(interpreter_exec_cmd): Make static.
* stack.h (select_frame_command): New file.
* stack.c: Include "stack.h".
(select_frame_command_wrapper): Delete function.
(select_frame_command): Make global.
* infcall.c: Include "infcall.h".
* linespec.c: Include "linespec.h".
* symfile.c (sections_overlap): Make static.
* cp-support.h (cp_initialize_namespace): ISO C declaration.
* charset.c (_initialize_charset): Add missing prototype.
* regcache.c (init_legacy_regcache_descr): Make static.
(do_regcache_xfree): Make static.
(regcache_xfer_part): Make static.
(_initialize_regcache): Add missing prototype.
* breakpoint.c (parse_breakpoint_sals): Make static.
(breakpoint_sals_to_pc): Make static.
* interps.h (clear_interpreter_hooks): ISO C declaration.
* Makefile.in (stack_h): Define.
(stack.o, typeprint.o, mi-main.o): Update dependencies.
(mi-cmd-stack.o, infcall.o, linespec.o): Update dependencies.
Index: mi/ChangeLog
2003-06-08 Andrew Cagney <cagney@redhat.com>
* mi-parse.c (_initialize_mi_parse): Delete function.
* mi-main.c: Include "mi-main.h".
* mi-interp.c (_initialize_mi_interp): Add declaration.
* mi-cmd-stack.c: Include "stack.h".
(select_frame_command_wrapper): Delete extern declaration.
(mi_cmd_stack_select_frame): Replace select_frame_command_wrapper
with select_frame_command.
2003-06-08 18:27:14 +00:00
|
|
|
extern void clear_interpreter_hooks (void);
|
2003-02-06 05:30:17 +00:00
|
|
|
|
|
|
|
/* well-known interpreters */
|
|
|
|
#define INTERP_CONSOLE "console"
|
|
|
|
#define INTERP_MI1 "mi1"
|
Index: ChangeLog
2003-08-07 Andrew Cagney <cagney@redhat.com>
* interps.h (INTERP_MI2, INTERP_MI3): Define.
Index: doc/ChangeLog
2003-08-07 Andrew Cagney <cagney@redhat.com>
* gdb.texinfo (Mode Options): Mention that "mi2" was included in
GDB 6.0.
Index: mi/ChangeLog
2003-08-07 Andrew Cagney <cagney@redhat.com>
* mi-interp.c (_initialize_mi_interp): Register "mi2" and "mi3".
Make "mi" select "mi2".
Index: testsuite/gdb.mi/ChangeLog
2003-08-07 Andrew Cagney <cagney@redhat.com>
* mi2-basics.exp: Copy base MI .exp file, set MIFLAGS to -i=mi2.
* mi2-break.exp, mi2-cli.exp, mi2-console.exp: Ditto.
* mi2-disassemble.exp, mi2-eval.exp, mi2-file.exp: Ditto.
* mi2-hack-cli.exp, mi2-pthreads.exp, mi2-read-memory.exp: Ditto.
* mi2-regs.exp, mi2-return.exp, mi2-simplerun.exp: Ditto.
* mi2-stack.exp, mi2-stepi.exp, mi2-syn-frame.exp: Ditto.
* mi2-until.exp, mi2-var-block.exp, mi2-var-child.exp: Ditto.
* mi2-var-cmd.exp, mi2-var-display.exp, mi2-watch.exp: Ditto.
2003-08-07 17:47:42 +00:00
|
|
|
#define INTERP_MI2 "mi2"
|
|
|
|
#define INTERP_MI3 "mi3"
|
2003-02-06 05:30:17 +00:00
|
|
|
#define INTERP_MI "mi"
|
2004-02-18 19:01:36 +00:00
|
|
|
#define INTERP_TUI "tui"
|
2005-11-07 12:46:38 +00:00
|
|
|
#define INTERP_INSIGHT "insight"
|
2003-02-06 05:30:17 +00:00
|
|
|
|
|
|
|
#endif
|