This converts observers from using a special source-generating script
to be plain C++. This version of the patch takes advantage of C++11
by using std::function and variadic templates; incorporates Pedro's
patches; and renames the header file to "observable.h" (this change
eliminates the need for a clean rebuild).
Note that Pedro's patches used a template lambda in tui-hooks.c, but
this failed to compile on some buildbot instances (presumably due to
differing C++ versions); I replaced this with an ordinary template
function.
Regression tested on the buildbot.
gdb/ChangeLog
2018-03-19 Pedro Alves <palves@redhat.com>
Tom Tromey <tom@tromey.com>
* unittests/observable-selftests.c: New file.
* common/observable.h: New file.
* observable.h: New file.
* ada-lang.c, ada-tasks.c, agent.c, aix-thread.c, annotate.c,
arm-tdep.c, auto-load.c, auxv.c, break-catch-syscall.c,
breakpoint.c, bsd-uthread.c, cli/cli-interp.c, cli/cli-setshow.c,
corefile.c, dummy-frame.c, event-loop.c, event-top.c, exec.c,
extension.c, frame.c, gdbarch.c, guile/scm-breakpoint.c,
infcall.c, infcmd.c, inferior.c, inflow.c, infrun.c, jit.c,
linux-tdep.c, linux-thread-db.c, m68klinux-tdep.c,
mi/mi-cmd-break.c, mi/mi-interp.c, mi/mi-main.c, objfiles.c,
ppc-linux-nat.c, ppc-linux-tdep.c, printcmd.c, procfs.c,
python/py-breakpoint.c, python/py-finishbreakpoint.c,
python/py-inferior.c, python/py-unwind.c, ravenscar-thread.c,
record-btrace.c, record-full.c, record.c, regcache.c, remote.c,
riscv-tdep.c, sol-thread.c, solib-aix.c, solib-spu.c, solib.c,
spu-multiarch.c, spu-tdep.c, stack.c, symfile-mem.c, symfile.c,
symtab.c, thread.c, top.c, tracepoint.c, tui/tui-hooks.c,
tui/tui-interp.c, valops.c: Update all users.
* tui/tui-hooks.c (tui_bp_created_observer)
(tui_bp_deleted_observer, tui_bp_modified_observer)
(tui_inferior_exit_observer, tui_before_prompt_observer)
(tui_normal_stop_observer, tui_register_changed_observer):
Remove.
(tui_observers_token): New global.
(attach_or_detach, tui_attach_detach_observers): New functions.
(tui_install_hooks, tui_remove_hooks): Use
tui_attach_detach_observers.
* record-btrace.c (record_btrace_thread_observer): Remove.
(record_btrace_thread_observer_token): New global.
* observer.sh: Remove.
* observer.c: Rename to observable.c.
* observable.c (namespace gdb_observers): Define new objects.
(observer_debug): Move into gdb_observers namespace.
(struct observer, struct observer_list, xalloc_observer_list_node)
(xfree_observer_list_node, generic_observer_attach)
(generic_observer_detach, generic_observer_notify): Remove.
(_initialize_observer): Update.
Don't include observer.inc.
* Makefile.in (generated_files): Remove observer.h, observer.inc.
(clean mostlyclean): Likewise.
(observer.h, observer.inc): Remove targets.
(SUBDIR_UNITTESTS_SRCS): Add observable-selftests.c.
(COMMON_SFILES): Use observable.c, not observer.c.
* .gitignore: Remove observer.h.
gdb/doc/ChangeLog
2018-03-19 Tom Tromey <tom@tromey.com>
* observer.texi: Remove.
gdb/testsuite/ChangeLog
2018-03-19 Tom Tromey <tom@tromey.com>
* gdb.gdb/observer.exp: Remove.
This patch replaces an instance of VEC (const_char_ptr) with
std::vector<const char *>. Tested by running gdb.tui/completion.exp,
which exercises this function.
gdb/ChangeLog:
* tui/tui-win.c (window_name_completer): Replace VEC with
std::vector.
This removes the last cleanups from the TUI, by using std::string
rather than manual memory management.
Regression tested against gdb.tui/*.exp on Fedora 26 x86-64.
gdb/ChangeLog
2017-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-win.c (tui_set_win_height, parse_scrolling_args): Use
std::string.
* tui/tui-layout.c (enum tui_status): Use std::string.
GCC commit a94975e57 ("C++ warning on vexing parse") introduces new
warnings "unnecessary parentheses in the declaration of ...". These
cause the build of binutils and gdb to fail. This patch removes those
parentheses for a successful build.
gdb/ChangeLog:
2017-10-11 Egeyar Bagcioglu <egeyar.bagcioglu@oracle.com>
* macrotab.h (macro_lookup_inclusion): Remove unnecessary
parentheses in the declaration.
(macro_lookup_inclusion): Likewise.
(macro_lookup_definition): Likewise.
* p-lang.h (pascal_builtin_types): Likewise.
* tui/tui-data.c (tui_win_list): Likewise.
* tui/tui-data.h (tui_win_list): Likewise.
* utils.h (make_cleanup_free_section_addr_info): Likewise.
Instead, make symtab_and_line initialize its members itself. Many
symtab_and_line declarations are moved to where the object is
initialized at the same time both for clarity and to avoid double
initialization. A few functions, like e.g., find_frame_sal are
adjusted to return the sal using normal function return instead of an
output parameter likewise to avoid having to default-construct a sal
and then immediately have the object overwritten.
gdb/ChangeLog:
2017-09-04 Pedro Alves <palves@redhat.com>
* ada-lang.c (is_known_support_routine): Move sal declaration to
where it is initialized.
* breakpoint.c (create_internal_breakpoint, init_catchpoint)
(parse_breakpoint_sals, decode_static_tracepoint_spec)
(clear_command, update_static_tracepoint): Remove init_sal
references. Move declarations closer to initializations.
* cli/cli-cmds.c (list_command): Move sal declarations closer to
initializations.
* elfread.c (elf_gnu_ifunc_resolver_stop): Remove init_sal
references. Move sal declarations closer to initializations.
* frame.c (find_frame_sal): Return a symtab_and_line via function
return instead of output parameter. Remove init_sal references.
* frame.h (find_frame_sal): Return a symtab_and_line via function
return instead of output parameter.
* guile/scm-frame.c (gdbscm_frame_sal): Adjust.
* guile/scm-symtab.c (stscm_make_sal_smob): Use in-place new
instead of memset.
(gdbscm_find_pc_line): Remove init_sal reference.
* infcall.c (call_function_by_hand_dummy): Remove init_sal
references. Move declarations closer to initializations.
* infcmd.c (set_step_frame): Update. Move declarations closer to
initializations.
(finish_backward): Remove init_sal references. Move declarations
closer to initializations.
* infrun.c (process_event_stop_test, handle_step_into_function)
(insert_hp_step_resume_breakpoint_at_frame)
(insert_step_resume_breakpoint_at_caller): Likewise.
* linespec.c (create_sals_line_offset, decode_digits_ordinary)
(symbol_to_sal): Likewise.
* probe.c (parse_probes_in_pspace): Remove init_sal reference.
* python/py-frame.c (frapy_find_sal): Move sal declaration closer
to its initialization.
* reverse.c (save_bookmark_command): Use new/delete. Remove
init_sal references. Move declarations closer to initializations.
* source.c (get_current_source_symtab_and_line): Remove brace
initialization.
(set_current_source_symtab_and_line): Now takes the sal by const
reference. Remove brace initialization.
(line_info): Remove init_sal reference.
* source.h (set_current_source_symtab_and_line): Now takes a
symtab_and_line via const reference.
* stack.c (set_current_sal_from_frame): Adjust.
(print_frame_info): Adjust.
(get_last_displayed_sal): Return the sal via function return
instead of via output parameter. Simplify.
(frame_info): Adjust.
* stack.h (get_last_displayed_sal): Return the sal via function
return instead of via output parameter.
* symtab.c (init_sal): Delete.
(find_pc_sect_line): Remove init_sal references. Move
declarations closer to initializations.
(find_function_start_sal): Remove init_sal references. Move
declarations closer to initializations.
* symtab.h (struct symtab_and_line): In-class initialize all
fields.
* tracepoint.c (set_traceframe_context)
(print_one_static_tracepoint_marker): Remove init_sal references.
Move declarations closer to initializations.
* tui/tui-disasm.c (tui_show_disassem_and_update_source): Adjust.
* tui/tui-stack.c (tui_show_frame_info): Adjust. Move
declarations closer to initializations.
* tui/tui-winsource.c (tui_update_source_window_as_is): Remove
init_sal references. Adjust.
Currently, "layout asm" is not so useful as "layout src" with Single-Key mode:
you have to use multi-key commands like "ni" and "si" to do single-stepping.
This patch adds, in addition to "next" and "step" commands, corresponding
assembly-level ones - "nexti" and "stepi" - to Single-Key mode, with the
shortcuts of "o" (from "step Over") and "i" (from "Step Into") respectively.
gdb/ChangeLog:
* tui/tui.c (tui_commands): Add "nexti" and "stepi" to the Single-Key
mode command list.
gdb/doc/ChangeLog:
* gdb.texinfo (TUI Single Key Mode): Document the new shortcuts in
Single-Key mode.
This patch replaces tui_restore_gdbout (a cleaup function) with a use
of scoped_restore. This one is broken out into its own patch because
it might slightly change the behavior of gdb: it saves and restores
pagination_enabled, whereas the tui_restore_gdbout unconditionally set
pagination_enabled to 1; and I think this warrants closer review.
ChangeLog
2017-08-03 Tom Tromey <tom@tromey.com>
* tui/tui-regs.c (tui_restore_gdbout): Remove.
(tui_register_format): Use scoped_restore.
This patch reworks the whole completion machinery, and prepares it
for later enhancements.
Adds a new "completion_tracker" class that is meant to hold everything
about the state of the current completion operation.
This class now has the responsibility of tracking the list of
completion matches, and checking whether the max completions limit has
been reached. You can look at this as this patch starting out by
C++fying the existing "completion_tracker" in symtab.c (it's just an
htab_t typedef currently), moving it to completer.h/c, and then making
it a class/generalizing/enhancing it.
Unlike with the current tracking, completion_tracker now checks
whether the limit has been reached on each completion match list
insertion. This both simplifies the max-completions handling code
(maybe_add_completion_enum is gone, for example), and is a
prerequisite for follow up patches.
The current completion_tracker is only used for symbol completions,
and the symbol code gets at the current instance via globals. This
patch cleans that up by adding a completion_tracker reference to the
signature of the completion functions, and passing the tracker around
everywhere necessary.
Then, the patch changes how the completion match list is handed over
to readline. Currently, we're using the rl_completion_entry_function
readline entry point, and the patch switches to
rl_attempted_completion_function. A following patch will want to let
GDB itself decide the common completion prefix between all matches
(what readline calls the "lowest common denominator"), instead of
having readline compute it, and that's not possible with the
rl_completion_entry_function entry point. Also,
rl_attempted_completion_function lets GDB hand over the match list to
readline as an array in one go instead of passing down matches one by
one, so from that angle it's a nicer entry point anyway.
Lastly, the patch catches exceptions around the readline entry points,
because we can't let C++ exceptions cross readline. We handle that in
the readline input entry point, but the completion entry point isn't
guarded, so GDB can abort if completion throws. E.g., in current
master:
(gdb) b -function "fun<tab>
terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
Aborted (core dumped)
This patch fixes that. This will be exercised in the new tests added
later on in the series.
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* ada-lang.c (symbol_completion_match): Adjust comments.
(symbol_completion_add): Replace vector parameter with
completion_tracker parameter. Use it.
(ada_make_symbol_completion_list): Rename to...
(ada_collect_symbol_completion_matches): ... this. Add
completion_tracker parameter and use it.
(ada_language_defn): Adjust.
* break-catch-syscall.c (catch_syscall_completer): Adjust
prototype and work with completion_tracker instead of VEC.
* breakpoint.c (condition_completer): Adjust prototype and work
with completion_tracker instead of VEC.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Adjust to renames.
* cli/cli-cmds.c (complete_command): Rework using
completion_tracker. Catch exceptions when completing.
* cli/cli-decode.c (integer_unlimited_completer)
(complete_on_cmdlist, complete_on_enum): Adjust prototype and work
with completion_tracker instead of VEC.
* command.h (struct completion_tracker): Forward declare.
(completer_ftype, completer_handle_brkchars_ftype): Change
types.
(complete_on_cmdlist, complete_on_enum): Adjust.
* completer.c: Include <algorithm>.
(struct gdb_completer_state): New.
(current_completion): New global.
(readline_line_completion_function): Delete.
(noop_completer, filename_completer)
(filename_completer_handle_brkchars, complete_files_symbols)
(linespec_location_completer): Adjust to work with a
completion_tracker instead of a VEC.
(string_or_empty): New.
(collect_explicit_location_matches): Adjust to work with a
completion_tracker instead of a VEC.
(explicit_location_completer): Rename to ...
(complete_explicit_location): ... this and adjust to work with a
completion_tracker instead of a VEC.
(location_completer): Adjust to work with a completion_tracker
instead of a VEC.
(add_struct_fields): Adjust to work with a completion_list instead
of VEC.
(expression_completer): Rename to ...
(complete_expression): ... this and adjust to work with a
completion_tracker instead of a VEC. Use complete_files_symbols.
(expression_completer): Reimplement on top of complete_expression.
(symbol_completer): Adjust to work with a completion_tracker
instead of a VEC.
(enum complete_line_internal_reason): Add describing comments.
(complete_line_internal_normal_command): Adjust to work with a
completion_tracker instead of a VEC.
(complete_line_internal): Rename to ...
(complete_line_internal_1): ... this and adjust to work with a
completion_tracker instead of a VEC. Assert TEXT is NULL in the
handle_brkchars phase.
(new_completion_tracker): Delete.
(complete_line_internal): Reimplement as TRY/CATCH wrapper around
complete_line_internal_1.
(free_completion_tracker): Delete.
(INITIAL_COMPLETION_HTAB_SIZE): New.
(completion_tracker::completion_tracker)
(completion_tracker::~completion_tracker): New.
(maybe_add_completion): Delete.
(completion_tracker::maybe_add_completion)
(completion_tracker::add_completion)
(completion_tracker::add_completions): New.
(throw_max_completions_reached_error): Delete.
(complete_line): Adjust to work with a completion_tracker instead
of a VEC. Don't create a completion_tracker_t or check for max
completions here.
(command_completer, command_completer_handle_brkchars)
(signal_completer, reg_or_group_completer_1)
(reg_or_group_completer, default_completer_handle_brkchars):
Adjust to work with a completion_tracker.
(gdb_completion_word_break_characters_throw): New.
(gdb_completion_word_break_characters): Reimplement.
(line_completion_function): Delete.
(completion_tracker::recompute_lowest_common_denominator)
(expand_preserving_ws)
(completion_tracker::build_completion_result)
(completion_result::completion_result)
(completion_result::completion_result)
(completion_result::~completion_result)
(completion_result::completion_result)
(completion_result::release_match_list, compare_cstrings)
(completion_result::sort_match_list)
(completion_result::reset_match_list)
(gdb_rl_attempted_completion_function_throw)
(gdb_rl_attempted_completion_function): New.
* completer.h (completion_list, struct completion_result)
(class completion_tracker): New.
(complete_line): Add completion_tracker parameter.
(readline_line_completion_function): Delete.
(gdb_rl_attempted_completion_function): New.
(noop_completer, filename_completer, expression_completer)
(location_completer, symbol_completer, command_completer)
(signal_completer, reg_or_group_completer): Update prototypes.
(completion_tracker_t, new_completion_tracker)
(make_cleanup_free_completion_tracker): Delete.
(enum maybe_add_completion_enum): Delete.
(maybe_add_completion): Delete.
(throw_max_completions_reached_error): Delete.
* corefile.c (complete_set_gnutarget): Adjust to work with a
completion_tracker instead of a VEC.
* cp-abi.c (cp_abi_completer): Adjust to work with a
completion_tracker instead of a VEC.
* d-lang.c (d_language_defn): Adjust.
* disasm.c (disassembler_options_completer): Adjust to work with a
completion_tracker instead of a VEC.
* f-lang.c (f_make_symbol_completion_list): Rename to ...
(f_collect_symbol_completion_matches): ... this. Adjust to work
with a completion_tracker instead of a VEC.
(f_language_defn): Adjust.
* go-lang.c (go_language_defn): Adjust.
* guile/scm-cmd.c (cmdscm_add_completion, cmdscm_completer):
Adjust to work with a completion_tracker instead of a VEC.
* infrun.c (handle_completer): Likewise.
* interps.c (interpreter_completer): Likewise.
* interps.h (interpreter_completer): Likewise.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Adjust.
* language.h (language_defn::la_make_symbol_completion_list):
Rename to ...
(language_defn::la_collect_symbol_completion_matches): ... this
and adjust to work with a completion_tracker instead of a VEC.
* m2-lang.c (m2_language_defn): Adjust.
* objc-lang.c (objc_language_defn): Adjust.
* opencl-lang.c (opencl_language_defn): Adjust.
* p-lang.c (pascal_language_defn): Adjust.
* python/py-cmd.c (cmdpy_completer_helper): Handle NULL word.
(cmdpy_completer_handle_brkchars, cmdpy_completer): Adjust to work
with a completion_tracker.
* rust-lang.c (rust_language_defn): Adjust.
* symtab.c (free_completion_list, do_free_completion_list)
(return_val, completion_tracker): Delete.
(completion_list_add_name, completion_list_add_symbol)
(completion_list_add_msymbol, completion_list_objc_symbol)
(completion_list_add_fields, add_symtab_completions): Add
completion_tracker parameter and use it.
(default_make_symbol_completion_list_break_on_1): Rename to...
(default_collect_symbol_completion_matches_break_on): ... this.
Add completion_tracker parameter and use it instead of allocating
a completion tracker here.
(default_make_symbol_completion_list_break_on): Delete old
implementation.
(default_make_symbol_completion_list): Delete.
(default_collect_symbol_completion_matches): New.
(make_symbol_completion_list): Delete.
(collect_symbol_completion_matches): New.
(make_symbol_completion_type): Rename to ...
(collect_symbol_completion_matches_type): ... this. Add
completion_tracker parameter and use it instead of VEC.
(make_file_symbol_completion_list_1): Rename to...
(collect_file_symbol_completion_matches): ... this. Add
completion_tracker parameter and use it instead of VEC.
(make_file_symbol_completion_list): Delete.
(add_filename_to_list): Use completion_list instead of a VEC.
(add_partial_filename_data::list): Now a completion_list.
(make_source_files_completion_list): Work with a completion_list
instead of a VEC.
* symtab.h: Include "completer.h".
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_type, make_file_symbol_completion_list)
(make_source_files_completion_list): Delete.
(default_collect_symbol_completion_matches_break_on)
(default_collect_symbol_completion_matches)
(collect_symbol_completion_matches)
(collect_symbol_completion_matches_type)
(collect_file_symbol_completion_matches)
(make_source_files_completion_list): New.
* top.c (init_main): Don't install a rl_completion_entry_function
hook. Install a rl_attempted_completion_function hook instead.
* tui/tui-layout.c (layout_completer): Adjust to work with a
completion_tracker.
* tui/tui-regs.c (tui_reggroup_completer):
* tui/tui-win.c (window_name_completer, focus_completer)
(winheight_completer): Adjust to work with a completion_tracker.
* value.c: Include "completer.h".
(complete_internalvar): Adjust to work with a completion_tracker.
* value.h (complete_internalvar): Likewise.
On both mainline and the 8.0 branch, gdb compilation fails on Solaris 10
with the native libcurses in gdb/tui for several instances of the same problem:
/vol/src/gnu/gdb/gdb-8.0-branch/local/gdb/tui/tui-winsource.c: In function `void tui_erase_source_content(tui_win_info*, int)':
/vol/src/gnu/gdb/gdb-8.0-branch/local/gdb/tui/tui-winsource.c:257:18: error: invalid conversion from `const char*' to `char*' [-fpermissive]
no_src_str);
^
In file included from /vol/src/gnu/gdb/gdb-8.0-branch/local/gdb/gdb_curses.h:42:0,
from /vol/src/gnu/gdb/gdb-8.0-branch/local/gdb/tui/tui-data.h:26,
from /vol/src/gnu/gdb/gdb-8.0-branch/local/gdb/tui/tui-winsource.c:33:
/vol/gcc-7/lib/gcc/sparc-sun-solaris2.10/7.1.0/include-fixed/curses.h:699:12: note: initializing argument 4 of `int mvwaddstr(WINDOW*, int, int, char*)'
extern int mvwaddstr(WINDOW *, int, int, char *);
^~~~~~~~~
make[2]: *** [Makefile:1927: tui-winsource.o] Error 1
Unlike ncurses, <curses.h> declares
extern int mvwaddstr(WINDOW *, int, int, char *);
i.e. the last arg is char *, not const char *.
The patch fixes this by casting the last arg to mvwaddstr to char *,
as was recently done on mainline in a newterm() call (the only
difference between 8.0 and mainline gdb/tui).
* tui/tui-windata.c (tui_erase_data_content): Cast last mvwaddstr
arg to char *.
* tui/tui-wingeneral.c (box_win): Likewise.
* tui/tui-winsource.c (tui_erase_source_content): Likewise.
(tui_show_source_line): Likewise.
(tui_show_exec_info_content): Likewise.
Commit d7e747318f ("Eliminate make_cleanup_ui_file_delete / make
ui_file a class hierarchy") regressed the TUI's command window.
Newlines miss doing a "carriage return", resulting in output like:
~~~~~~~~~~~~~~~~~~
(gdb) helpList of classes of commands:
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Before the commit mentioned above, the default ui_file->to_write
implementation had a hack that would defer into the ui_file->to_fputs
method. The TUI's ui_file did not implement the to_write method, so
all writes would end up going to the ncurses window via tui_file_fputs
-> tui_puts.
After the commit above, the hack is gone, but the TUI's ui_file still
does not implement the ui_file::write method. Since tui_file inherits
from stdio_file, writing to a tui_file ends up doing fwrite on the
FILE stream the TUI is "associated" with, via stdio_file::write,
instead of writing to the ncurses window.
The fix is to have tui_file override the "write" method.
New test included.
gdb/ChangeLog:
2017-03-08 Pedro Alves <palves@redhat.com>
PR tui/21216
* tui/tui-file.c (tui_file::write): New.
* tui/tui-file.h (tui_file): Override "write".
* tui/tui-io.c (do_tui_putc, update_start_line): New functions,
factored out from ...
(tui_puts): ... here.
(tui_putc): Use them.
(tui_write): New function.
* tui/tui-io.h (tui_write): Declare.
gdb/testsuite/ChangeLog:
2017-03-08 Pedro Alves <palves@redhat.com>
PR tui/21216
* gdb.tui/tui-nl-filtered-output.exp: New file.
Commit d7e747318f ("Eliminate make_cleanup_ui_file_delete / make
ui_file a class hierarchy") introduced a problem when using "layout
regs", that leads gdb to crash when issuing:
./gdb ./a.out -ex 'layout regs' -ex start
From the backtrace, it's caused by this 'delete' on tui_restore_gdbout():
(gdb) bt
#0 0x00007ffff6b962b2 in free () from /lib64/libc.so.6
#1 0x000000000059fa47 in tui_restore_gdbout (ui=0x22997b0) at ../../gdb/tui/tui-regs.c:714
#2 0x0000000000619996 in do_my_cleanups (pmy_chain=pmy_chain@entry=0x1e08320 <cleanup_chain>, old_chain=old_chain@entry=0x235b4b0) at ../../gdb/common/cleanups.c:154
#3 0x0000000000619b1d in do_cleanups (old_chain=old_chain@entry=0x235b4b0) at ../../gdb/common/cleanups.c:176
#4 0x000000000059fb0d in tui_register_format (frame=frame@entry=0x22564e0, regnum=regnum@entry=0) at ../../gdb/tui/tui-regs.c:747
#5 0x000000000059ffeb in tui_get_register (data=0x2434d18, changedp=0x0, regnum=0, frame=0x22564e0) at ../../gdb/tui/tui-regs.c:768
#6 tui_show_register_group (refresh_values_only=<optimized out>, frame=0x22564e0, group=0x1e09250 <general_group>) at ../../gdb/tui/tui-regs.c:287
#7 tui_show_registers (group=0x1e09250 <general_group>) at ../../gdb/tui/tui-regs.c:156
#8 0x00000000005a07cf in tui_check_register_values (frame=frame@entry=0x22564e0) at ../../gdb/tui/tui-regs.c:496
#9 0x00000000005a3e65 in tui_check_data_values (frame=frame@entry=0x22564e0) at ../../gdb/tui/tui-windata.c:232
#10 0x000000000059cf65 in tui_refresh_frame_and_register_information (registers_too_p=1) at ../../gdb/tui/tui-hooks.c:156
#11 0x00000000006d5c05 in generic_observer_notify (args=0x7fffffffdbe0, subject=<optimized out>) at ../../gdb/observer.c:167
#12 observer_notify_normal_stop (bs=<optimized out>, print_frame=print_frame@entry=1) at ./observer.inc:61
#13 0x00000000006a6409 in normal_stop () at ../../gdb/infrun.c:8364
#14 0x00000000006af8f5 in fetch_inferior_event (client_data=<optimized out>) at ../../gdb/infrun.c:3990
#15 0x000000000066f0fd in gdb_wait_for_event (block=block@entry=0) at ../../gdb/event-loop.c:859
#16 0x000000000066f237 in gdb_do_one_event () at ../../gdb/event-loop.c:322
#17 0x000000000066f386 in gdb_do_one_event () at ../../gdb/event-loop.c:353
#18 0x00000000007411bc in wait_sync_command_done () at ../../gdb/top.c:570
#19 0x0000000000741426 in maybe_wait_sync_command_done (was_sync=0) at ../../gdb/top.c:587
#20 execute_command (p=<optimized out>, p@entry=0x7fffffffe43a "start", from_tty=from_tty@entry=1) at ../../gdb/top.c:676
#21 0x00000000006c2048 in catch_command_errors (command=0x741200 <execute_command(char*, int)>, arg=0x7fffffffe43a "start", from_tty=1) at ../../gdb/main.c:376
#22 0x00000000006c2b60 in captured_main_1 (context=0x7fffffffde70) at ../../gdb/main.c:1119
#23 captured_main (data=0x7fffffffde70) at ../../gdb/main.c:1140
#24 gdb_main (args=args@entry=0x7fffffffdf90) at ../../gdb/main.c:1158
#25 0x0000000000408cf5 in main (argc=<optimized out>, argv=<optimized out>) at ../../gdb/gdb.c:32
(gdb) f 1
#1 0x000000000059fa47 in tui_restore_gdbout (ui=0x22997b0) at ../../gdb/tui/tui-regs.c:714
714 delete gdb_stdout;
The problem is simply that the commit mentioned above made the ui_file
that gdb_stdout is temporarily set to be a stack-allocated
string_file, while before it used to be a heap-allocated ui_file. The
fix is simply to remove the now-incorrect delete.
New test included, which exercises enabling all TUI layouts, with and
without execution. (This particular crash only triggers with
execution.)
gdb/ChangeLog:
2017-03-07 Pedro Alves <palves@redhat.com>
* tui/tui-regs.c (tui_restore_gdbout): Don't delete gdb_stdout.
gdb/testsuite/ChangeLog:
2017-03-07 Pedro Alves <palves@redhat.com>
* gdb.base/tui-layout.c: New file.
* gdb.base/tui-layout.exp: New file.
- The interp->data field disappears, since we can put data in the
interpreter directly now. The "init" method remains in place, but
it now returns void.
- A few places check if the interpreter method is NULL before calling
it, and also check whether the method returns true/false. For some
of those methods, all current implementations always return true.
In those cases, this commit makes the C++-fied method return void
instead and cleans up the callers.
Tested on x86_64 Fedora 23.
gdb/ChangeLog:
2017-02-03 Pedro Alves <palves@redhat.com>
* cli/cli-interp.c (cli_interp_base::cli_interp_base)
(cli_interp_base::~cli_interp_base): New.
(cli_interp): New struct.
(as_cli_interp): Cast the interp itself to cli_interp.
(cli_interpreter_pre_command_loop): Rename to ...
(cli_interp_base::pre_command_loop): ... this. Remove 'self'
parameter.
(cli_interpreter_init): Rename to ...
(cli_interp::init): ... this. Remove 'self' parameter. Use
boolean. Make extern.
(cli_interpreter_resume): Rename to ...
(cli_interp::resume): ... this. Remove 'data' parameter. Make
extern.
(cli_interpreter_suspend): Rename to ...
(cli_interp::suspend): ... this. Remove 'data' parameter. Make
extern.
(cli_interpreter_exec): Rename to ...
(cli_interp::exec): ... this. Remove 'data' parameter. Make
extern.
(cli_interpreter_supports_command_editing): Rename to ...
(cli_interp_base::supports_command_editing): ... this. Remove
'interp' parameter. Make extern.
(cli_ui_out): Rename to ...
(cli_interp::interp_ui_out): ... this. Remove 'interp' parameter.
Make extern.
(cli_set_logging): Rename to ...
(cli_interp_base::set_logging): ... this. Remove 'interp'
parameter. Make extern.
(cli_interp_procs): Delete.
(cli_interp_factory): Adjust to use "new".
* cli/cli-interp.h: Include "interps.h".
(struct cli_interp_base): New struct.
* interps.c (struct interp): Delete. Fields moved to interps.h.
(interp_new): Delete.
(interp::interp, interp::~interp): New.
(interp_set): Use bool, and return void. Assume the interpreter
has suspend, init and resume methods, and that the all return
void.
(set_top_level_interpreter): interp_set returns void.
(interp_ui_out): Adapt.
(current_interp_set_logging): Adapt.
(interp_data): Delete.
(interp_pre_command_loop, interp_supports_command_editing): Adapt.
(interp_exec): Adapt.
(top_level_interpreter_data): Delete.
* interps.h (interp_init_ftype, interp_resume_ftype)
(interp_suspend_ftype, interp_exec_ftype)
(interp_pre_command_loop_ftype, interp_ui_out_ftype): Delete.
(class interp): New.
(interp_new): Delete.
(interp_set): Now returns void. Use bool.
(interp_data, top_level_interpreter_data): Delete.
* mi/mi-common.h: Include interps.h.
(class mi_interp): Inherit from interp. Define a ctor. Declare
init, resume, suspect, exec, interp_ui_out, set_logging and
pre_command_loop methods.
* mi/mi-interp.c (as_mi_interp): Cast the interp itself.
(mi_interpreter_init): Rename to ...
(mi_interp::init): ... this. Remove the 'interp' parameter, use
bool, return void and make extern. Adjust.
(mi_interpreter_resume): ... Rename to ...
(mi_interp::resume): ... this. Remove the 'data' parameter,
return void and make extern. Adjust.
(mi_interpreter_suspend): ... Rename to ...
(mi_interp::suspend): ... this. Remove the 'data' parameter,
return void and make extern. Adjust.
(mi_interpreter_exec): ... Rename to ...
(mi_interp::exec): ... this. Remove the 'data' parameter and make
extern. Adjust.
(mi_interpreter_pre_command_loop): ... Rename to ...
(mi_interp::pre_command_loop): ... this. Remove the 'self'
parameter and make extern.
(mi_on_normal_stop_1): Adjust.
(mi_ui_out): Rename to ...
(mi_interp::interp_ui_out): ... this. Remove the 'interp'
parameter and make extern. Adjust.
(mi_set_logging): Rename to ...
(mi_interp::set_logging): ... this. Remove the 'interp'
parameter and make extern. Adjust.
(mi_interp_procs): Delete.
(mi_interp_factory): Adjust to use 'new'.
* mi/mi-main.c (mi_cmd_gdb_exit, captured_mi_execute_command)
(mi_print_exception, mi_execute_command, mi_load_progress):
Adjust.
* tui/tui-interp.c (tui_interp): New class.
(as_tui_interp): Return a tui_interp pointer.
(tui_on_normal_stop, tui_on_signal_received)
(tui_on_end_stepping_range, tui_on_signal_exited, tui_on_exited)
(tui_on_no_history, tui_on_user_selected_context_changed): Adjust
to use interp::interp_ui_out.
(tui_init): Rename to ...
(tui_interp::init): ... this. Remove the 'self' parameter, use
bool, return void and make extern. Adjust.
(tui_resume): Rename to ...
(tui_interp::resume): ... this. Remove the 'data' parameter,
return void and make extern. Adjust.
(tui_suspend): Rename to ...
(tui_interp::suspend): ... this. Remove the 'data' parameter,
return void and make extern. Adjust.
(tui_ui_out): Rename to ...
(tui_interp::interp_ui_out): ... this. Remove the 'self'
parameter, and make extern. Adjust.
(tui_exec): Rename to ...
(tui_interp::exec): ... this. Remove the 'data' parameter and
make extern.
(tui_interp_procs): Delete.
(tui_interp_factory): Use "new".
This patch gets rid of this hack in mi_set_logging:
/* The tee created already is based on gdb_stdout, which for MI
is a console and so we end up in an infinite loop of console
writing to ui_file writing to console etc. So discard the
existing tee (it hasn't been used yet, and MI won't ever use
it), and create one based on raw_stdout instead. */
By pushing down responsibility for the tee creation to the
interpreter. I.e., pushing the CLI bits out of handle_redirections
down to the CLI interpreter's set_logging_proc method.
This fixes a few leaks that I spotted, and then confirmed with
"valgrind --leak-check=full":
[...]
==21429== 56 (32 direct, 24 indirect) bytes in 1 blocks are definitely lost in loss record 30,243 of 34,980
==21429== at 0x4C29216: operator new(unsigned long) (vg_replace_malloc.c:334)
==21429== by 0x62D9A9: mi_set_logging(interp*, int, ui_file*, ui_file*) (mi-interp.c:1395)
==21429== by 0x810B8A: current_interp_set_logging(int, ui_file*, ui_file*) (interps.c:360)
==21429== by 0x61C537: handle_redirections(int) (cli-logging.c:162)
==21429== by 0x61C6EC: set_logging_on(char*, int) (cli-logging.c:190)
==21429== by 0x6163BE: do_cfunc(cmd_list_element*, char*, int) (cli-decode.c:105)
==21429== by 0x6193C1: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1913)
==21429== by 0x8DB790: execute_command(char*, int) (top.c:674)
==21429== by 0x632AE6: mi_execute_cli_command(char const*, int, char const*) (mi-main.c:2343)
==21429== by 0x6329BA: mi_cmd_execute(mi_parse*) (mi-main.c:2306)
==21429== by 0x631E19: captured_mi_execute_command(ui_out*, mi_parse*) (mi-main.c:1998)
==21429== by 0x632389: mi_execute_command(char const*, int) (mi-main.c:2163)
==21429==
[...]
==26635== 24 bytes in 1 blocks are definitely lost in loss record 20,740 of 34,995
==26635== at 0x4C29216: operator new(unsigned long) (vg_replace_malloc.c:334)
==26635== by 0x61C355: handle_redirections(int) (cli-logging.c:131)
==26635== by 0x61C6EC: set_logging_on(char*, int) (cli-logging.c:190)
==26635== by 0x6163BE: do_cfunc(cmd_list_element*, char*, int) (cli-decode.c:105)
==26635== by 0x6193C1: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1913)
==26635== by 0x8DB7BC: execute_command(char*, int) (top.c:674)
==26635== by 0x7B9132: command_handler(char*) (event-top.c:590)
==26635== by 0x7B94F7: command_line_handler(char*) (event-top.c:780)
==26635== by 0x7B8ABB: gdb_rl_callback_handler(char*) (event-top.c:213)
==26635== by 0x933CE9: rl_callback_read_char (callback.c:220)
==26635== by 0x7B89ED: gdb_rl_callback_read_char_wrapper_noexcept() (event-top.c:175)
==26635== by 0x7B8A49: gdb_rl_callback_read_char_wrapper(void*) (event-top.c:192)
One is fixed by transfering ownership of the log file to the tee. In
pseudo-patch, since the code was moved at the same time:
- out = new tee_file (curr_output, false, logfile.get (), false);
+ out = new tee_file (curr_output, false, logfile.get (), true);
The other is this bit in mi_set_logging:
else
{
+ delete mi->raw_stdout;
I tried to split the leak fixes to a smaller preparatory patch, but
that was difficult exactly because of the tee hack in
handle_redirections -> mi_set_logging.
gdb/ChangeLog:
2017-02-02 Pedro Alves <palves@redhat.com>
* cli/cli-interp.c (struct saved_output_files, saved_output):
Moved from cli/cli-logging.c.
(cli_set_logging): New function.
(cli_interp_procs): Install cli_set_logging.
* cli/cli-interp.h (make_logging_output, cli_set_logging):
Declare.
* cli/cli-logging.c (struct saved_output_files, saved_output):
Moved to cli/cli-interp.c.
(pop_output_files): Don't save outputs here.
(make_logging_output): New function.
(handle_redirections): Don't build tee nor save previous outputs
here.
* interps.c (current_interp_set_logging): Change prototype.
Assume there's always a set_logging_proc method installed.
* interps.h (interp_set_logging_ftype): Change prototype.
(current_interp_set_logging): Change prototype and adjust comment.
* mi/mi-interp.c (mi_set_logging): Change protototype. Adjust to
use make_logging_output.
* tui/tui-interp.c (tui_interp_procs): Install cli_set_logging.
This patch starts from the desire to eliminate
make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file &
friends a real C++ class hierarchy, and switches temporary
ui_file-like objects to stack-based allocation.
- mem_fileopen -> string_file
mem_fileopen is replaced with a new string_file class that is treated
as a value class created on the stack. This alone eliminates most
make_cleanup_ui_file_delete calls, and, simplifies code a whole lot
(diffstat shows around 1k loc dropped.)
string_file's internal buffer is a std::string, thus the "string" in
the name. This simplifies the implementation much, compared to
mem_fileopen, which managed growing its internal buffer manually.
- ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone
The new string_file class has a string() method that provides direct
writable access to the internal std::string buffer. This replaced
ui_file_as_string, which forced a copy of the same data the stream had
inside. With direct access via a writable reference, we can instead
move the string out of the string_stream, avoiding deep string
copying.
Related, ui_file_xstrdup calls are replaced with xstrdup'ping the
stream's string, and ui_file_obsavestring is replaced by
obstack_copy0.
With all those out of the way, getting rid of the weird ui_file_put
mechanism was possible.
- New ui_file::printf, ui_file::puts, etc. methods
These simplify / clarify client code. I considered splitting
client-code changes, like these, e.g.:
- stb = mem_fileopen ();
- fprintf_unfiltered (stb, "%s%s%s",
- _("The valid values are:\n"),
- regdesc,
- _("The default is \"std\"."));
+ string_file stb;
+ stb.printf ("%s%s%s",
+ _("The valid values are:\n"),
+ regdesc,
+ _("The default is \"std\"."));
In two steps, with the first step leaving fprintf_unfiltered (etc.)
calls in place, and only afterwards do a pass to change all those to
call stb.printf etc.. I didn't do that split, because (when I tried),
it turned out to be pointless make-work: the first pass would have to
touch the fprintf_unfiltered line anyway, to replace "stb" with
"&stb".
- gdb_fopen replaced with stack-based objects
This avoids the need for cleanups or unique_ptr's. I.e., this:
struct ui_file *file = gdb_fopen (filename, "w");
if (filename == NULL)
perror_with_name (filename);
cleanups = make_cleanup_ui_file_delete (file);
// use file.
do_cleanups (cleanups);
is replaced with this:
stdio_file file;
if (!file.open (filename, "w"))
perror_with_name (filename);
// use file.
- odd contorsions in null_file_write / null_file_fputs around when to
call to_fputs / to_write eliminated.
- Global null_stream object
A few places that were allocating a ui_file in order to print to
"nowhere" are adjusted to instead refer to a new 'null_stream' global
stream.
- TUI's tui_sfileopen eliminated. TUI's ui_file much simplified
The TUI's ui_file was serving a dual purpose. It supported being used
as string buffer, and supported being backed by a stdio FILE. The
string buffer part is gone, replaced by using of string_file. The
'FILE *' support is now much simplified, by making the TUI's ui_file
inherit from stdio_file.
gdb/ChangeLog:
2017-02-02 Pedro Alves <palves@redhat.com>
* ada-lang.c (type_as_string): Use string_file.
* ada-valprint.c (ada_print_floating): Use string_file.
* ada-varobj.c (ada_varobj_scalar_image)
(ada_varobj_get_value_image): Use string_file.
* aix-thread.c (aix_thread_extra_thread_info): Use string_file.
* arm-tdep.c (_initialize_arm_tdep): Use string_printf.
* breakpoint.c (update_inserted_breakpoint_locations)
(insert_breakpoint_locations, reattach_breakpoints)
(print_breakpoint_location, print_one_detail_ranged_breakpoint)
(print_it_watchpoint): Use string_file.
(save_breakpoints): Use stdio_file.
* c-exp.y (oper): Use string_file.
* cli/cli-logging.c (set_logging_redirect): Use ui_file_up and
tee_file.
(pop_output_files): Use delete.
(handle_redirections): Use stdio_file and tee_file.
* cli/cli-setshow.c (do_show_command): Use string_file.
* compile/compile-c-support.c (c_compute_program): Use
string_file.
* compile/compile-c-symbols.c (generate_vla_size): Take a
'string_file &' instead of a 'ui_file *'.
(generate_c_for_for_one_variable): Take a 'string_file &' instead
of a 'ui_file *'. Use string_file.
(generate_c_for_variable_locations): Take a 'string_file &'
instead of a 'ui_file *'.
* compile/compile-internal.h (generate_c_for_for_one_variable):
Take a 'string_file &' instead of a 'ui_file *'.
* compile/compile-loc2c.c (push, pushf, unary, binary)
(print_label, pushf_register_address, pushf_register)
(do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a
'ui_file *'. Adjust.
* compile/compile.c (compile_to_object): Use string_file.
* compile/compile.h (compile_dwarf_expr_to_c)
(compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a
'ui_file *'.
* cp-support.c (inspect_type): Use string_file and obstack_copy0.
(replace_typedefs_qualified_name): Use string_file and
obstack_copy0.
* disasm.c (gdb_pretty_print_insn): Use string_file.
(gdb_disassembly): Adjust reference the null_stream global.
(do_ui_file_delete): Delete.
(gdb_insn_length): Use null_stream.
* dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file.
* dwarf2loc.c (dwarf2_compile_property_to_c)
(locexpr_generate_c_location, loclist_generate_c_location): Take a
'string_file &' instead of a 'ui_file *'.
* dwarf2loc.h (dwarf2_compile_property_to_c): Likewise.
* dwarf2read.c (do_ui_file_peek_last): Delete.
(dwarf2_compute_name): Use string_file.
* event-top.c (gdb_setup_readline): Use stdio_file.
* gdbarch.sh (verify_gdbarch): Use string_file.
* gdbtypes.c (safe_parse_type): Use null_stream.
* guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use
string_file.
* guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a
'string_file *' instead of a 'ui_file *'.
(gdbscm_arch_disassemble): Use string_file.
* guile/scm-frame.c (frscm_print_frame_smob): Use string_file.
* guile/scm-ports.c (class ioscm_file_port): Now a class that
inherits from ui_file.
(ioscm_file_port_delete, ioscm_file_port_rewind)
(ioscm_file_port_put): Delete.
(ioscm_file_port_write): Rename to ...
(ioscm_file_port::write): ... this. Remove file_port_magic
checks.
(ioscm_file_port_new): Delete.
(ioscm_with_output_to_port_worker): Use ioscm_file_port and
ui_file_up.
* guile/scm-type.c (tyscm_type_name): Use string_file.
* guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print):
Use string_file.
* infcmd.c (print_return_value_1): Use string_file.
* infrun.c (print_target_wait_results): Use string_file.
* language.c (add_language): Use string_file.
* location.c (explicit_to_string_internal): Use string_file.
* main.c (captured_main_1): Use null_file.
* maint.c (maintenance_print_architecture): Use stdio_file.
* mi/mi-cmd-stack.c (list_arg_or_local): Use string_file.
* mi/mi-common.h (struct mi_interp) <out, err, log, targ,
event_channel>: Change type to mi_console_file pointer.
* mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush)
(mi_console_file_delete): Delete.
(struct mi_console_file): Delete.
(mi_console_file_magic): Delete.
(mi_console_file_new): Delete.
(mi_console_file::mi_console_file): New.
(mi_console_file_delete): Delete.
(mi_console_file_fputs): Delete.
(mi_console_file::write): New.
(mi_console_raw_packet): Delete.
(mi_console_file::flush): New.
(mi_console_file_flush): Delete.
(mi_console_set_raw): Rename to ...
(mi_console_file::set_raw): ... this.
* mi/mi-console.h (class mi_console_file): New class.
(mi_console_file_new, mi_console_set_raw): Delete.
* mi/mi-interp.c (mi_interpreter_init): Use mi_console_file.
(mi_set_logging): Use delete and tee_file. Adjust.
* mi/mi-main.c (output_register): Use string_file.
(mi_cmd_data_evaluate_expression): Use string_file.
(mi_cmd_data_read_memory): Use string_file.
(mi_cmd_execute, print_variable_or_computed): Use string_file.
* mi/mi-out.c (mi_ui_out::main_stream): New.
(mi_ui_out::rewind): Use main_stream and
string_file.
(mi_ui_out::put): Use main_stream and string_file.
(mi_ui_out::mi_ui_out): Remove 'stream' parameter.
Allocate a 'string_file' instead.
(mi_out_new): Don't allocate a mem_fileopen stream here.
* mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter.
(mi_ui_out::main_stream): Declare method.
* printcmd.c (eval_command): Use string_file.
* psymtab.c (maintenance_print_psymbols): Use stdio_file.
* python/py-arch.c (archpy_disassemble): Use string_file.
* python/py-breakpoint.c (bppy_get_commands): Use string_file.
* python/py-frame.c (frapy_str): Use string_file.
* python/py-framefilter.c (py_print_type, py_print_single_arg):
Use string_file.
* python/py-type.c (typy_str): Use string_file.
* python/py-unwind.c (unwind_infopy_str): Use string_file.
* python/py-value.c (valpy_str): Use string_file.
* record-btrace.c (btrace_insn_history): Use string_file.
* regcache.c (regcache_print): Use stdio_file.
* reggroups.c (maintenance_print_reggroups): Use stdio_file.
* remote.c (escape_buffer): Use string_file.
* rust-lang.c (rust_get_disr_info): Use string_file.
* serial.c (serial_open_ops_1): Use stdio_file.
(do_serial_close): Use delete.
* stack.c (print_frame_arg): Use string_file.
(print_frame_args): Remove local mem_fileopen stream, not used.
(print_frame): Use string_file.
* symmisc.c (maintenance_print_symbols): Use stdio_file.
* symtab.h (struct symbol_computed_ops) <generate_c_location>:
Take a 'string_file *' instead of a 'ui_file *'.
* top.c (new_ui): Use stdio_file and stderr_file.
(free_ui): Use delete.
(execute_command_to_string): Use string_file.
(quit_confirm): Use string_file.
* tracepoint.c (collection_list::append_exp): Use string_file.
* tui/tui-disasm.c (tui_disassemble): Use string_file.
* tui/tui-file.c: Don't include "ui-file.h".
(enum streamtype, struct tui_stream): Delete.
(tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen)
(tui_file_isatty, tui_file_rewind, tui_file_put): Delete.
(tui_file::tui_file): New method.
(tui_file_fputs): Delete.
(tui_file_get_strbuf): Delete.
(tui_file::puts): New method.
(tui_file_adjust_strbuf): Delete.
(tui_file_flush): Delete.
(tui_file::flush): New method.
* tui/tui-file.h: Tweak intro comment.
Include ui-file.h.
(tui_fileopen, tui_sfileopen, tui_file_get_strbuf)
(tui_file_adjust_strbuf): Delete declarations.
(class tui_file): New class.
* tui/tui-io.c (tui_initialize_io): Use tui_file.
* tui/tui-regs.c (tui_restore_gdbout): Use delete.
(tui_register_format): Use string_stream.
* tui/tui-stack.c (tui_make_status_line): Use string_file.
(tui_get_function_from_frame): Use string_file.
* typeprint.c (type_to_string): Use string_file.
* ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete.
(null_stream): New global.
(ui_file_delete): Delete.
(ui_file::ui_file): New.
(null_file_isatty): Delete.
(ui_file::~ui_file): New.
(null_file_rewind): Delete.
(ui_file::printf): New.
(null_file_put): Delete.
(null_file_flush): Delete.
(ui_file::putstr): New.
(null_file_write): Delete.
(ui_file::putstrn): New.
(null_file_read): Delete.
(ui_file::putc): New.
(null_file_fputs): Delete.
(null_file_write_async_safe): Delete.
(ui_file::vprintf): New.
(null_file_delete): Delete.
(null_file::write): New.
(null_file_fseek): Delete.
(null_file::puts): New.
(ui_file_data): Delete.
(null_file::write_async_safe): New.
(gdb_flush, ui_file_isatty): Adjust.
(ui_file_put, ui_file_rewind): Delete.
(ui_file_write): Adjust.
(ui_file_write_for_put): Delete.
(ui_file_write_async_safe, ui_file_read): Adjust.
(ui_file_fseek): Delete.
(fputs_unfiltered): Adjust.
(set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind)
(set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe)
(set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek)
(set_ui_file_data): Delete.
(string_file::~string_file, string_file::write)
(struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup)
(do_ui_file_as_string, ui_file_as_string): Delete.
(do_ui_file_obsavestring, ui_file_obsavestring): Delete.
(struct mem_file): Delete.
(mem_file_new): Delete.
(stdio_file::stdio_file): New.
(mem_file_delete): Delete.
(stdio_file::stdio_file): New.
(mem_fileopen): Delete.
(stdio_file::~stdio_file): New.
(mem_file_rewind): Delete.
(stdio_file::set_stream): New.
(mem_file_put): Delete.
(stdio_file::open): New.
(mem_file_write): Delete.
(stdio_file_magic, struct stdio_file): Delete.
(stdio_file_new, stdio_file_delete, stdio_file_flush): Delete.
(stdio_file::flush): New.
(stdio_file_read): Rename to ...
(stdio_file::read): ... this. Adjust.
(stdio_file_write): Rename to ...
(stdio_file::write): ... this. Adjust.
(stdio_file_write_async_safe): Rename to ...
(stdio_file::write_async_safe) ... this. Adjust.
(stdio_file_fputs): Rename to ...
(stdio_file::puts) ... this. Adjust.
(stdio_file_isatty): Delete.
(stdio_file_fseek): Delete.
(stdio_file::isatty): New.
(stderr_file_write): Rename to ...
(stderr_file::write) ... this. Adjust.
(stderr_file_fputs): Rename to ...
(stderr_file::puts) ... this. Adjust.
(stderr_fileopen, stdio_fileopen, gdb_fopen): Delete.
(stderr_file::stderr_file): New.
(tee_file_magic): Delete.
(struct tee_file): Delete.
(tee_file::tee_file): New.
(tee_file_new): Delete.
(tee_file::~tee_file): New.
(tee_file_delete): Delete.
(tee_file_flush): Rename to ...
(tee_file::flush): ... this. Adjust.
(tee_file_write): Rename to ...
(tee_file::write): ... this. Adjust.
(tee_file::write_async_safe): New.
(tee_file_fputs): Rename to ...
(tee_file::puts): ... this. Adjust.
(tee_file_isatty): Rename to ...
(tee_file::isatty): ... this. Adjust.
* ui-file.h (struct obstack, struct ui_file): Don't
forward-declare.
(ui_file_new, ui_file_flush_ftype, set_ui_file_flush)
(ui_file_write_ftype)
(set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs)
(ui_file_write_async_safe_ftype, set_ui_file_write_async_safe)
(ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype)
(set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind)
(ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put)
(ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype)
(set_ui_file_fseek): Delete.
(ui_file_data, ui_file_delete, ui_file_rewind)
(struct ui_file): New.
(ui_file_up): New.
(class null_file): New.
(null_stream): Declare.
(ui_file_write_for_put, ui_file_put): Delete.
(ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring):
Delete.
(ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen)
(gdb_fopen, tee_file_new): Delete.
(struct string_file): New.
(struct stdio_file): New.
(stdio_file_up): New.
(struct stderr_file): New.
(class tee_file): New.
* ui-out.c (ui_out::field_stream): Take a 'string_file &' instead
of a 'ui_file *'. Adjust.
* ui-out.h (class ui_out) <field_stream>: Likewise.
* utils.c (do_ui_file_delete, make_cleanup_ui_file_delete)
(null_stream): Delete.
(error_stream): Take a 'string_file &' instead of a 'ui_file *'.
Adjust.
* utils.h (struct ui_file): Delete forward declaration..
(make_cleanup_ui_file_delete, null_stream): Delete declarations.
(error_stream): Take a 'string_file &' instead of a
'ui_file *'.
* varobj.c (varobj_value_get_print_value): Use string_file.
* xtensa-tdep.c (xtensa_verify_config): Use string_file.
* gdbarch.c: Regenerate.
This applies the second part of GDB's End of Year Procedure, which
updates the copyright year range in all of GDB's files.
gdb/ChangeLog:
Update copyright year range in all GDB files.
The following patches introduce C++ vectors and strings as fields of the
various ui_out structures. We therefore need to use new/delete so that
their contructor/destructor is called. I find it simpler to change all
the allocations in a separate preliminary patch, rather than in each
individual patch.
gdb/ChangeLog:
* cli-out.c (cli_uiout_dtor): Use delete instead of xfree.
(cli_out_new): Use new instead of XNEW.
* mi/mi-out.c (mi_out_data_dtor): Use delete instead of xfree.
(mi_out_new): Use new instead of XNEW.
* tui/tui-out.c (tui_out_new): Likewise.
* ui-out.c (push_level): Likewise.
(pop_level): Use delete instead of xfree.
(clear_header_list): Use delete instead of xfree.
(append_header_to_list): Use new instead of XNEW.
(ui_out_new): Likewise.
This removes dead code in tui_alloc_source_buffer for handling a NULL
return value from xmalloc.
gdb/ChangeLog:
* tui/tui-winsource.c (tui_alloc_source_buffer): Remove
failed-xmalloc handling.
The logic for allocating a TUI source window's content buffer allocates
two more lines than needed, because it does not reduce the window height
by the highlight box's overhead. However, it does reduce the line width
accordingly. This patch makes the height and width calculation
consistent and improves the comment.
gdb/ChangeLog:
* tui/tui-winsource.c (tui_alloc_source_buffer): Subtract
highlight box's overhead when calculating the content height.
The code that fills the TUI disassembly window content first calculates
the maximum full length of a displayed disassembly line. This
calculation typically yields the wrong result. The result is too large,
so the bug does not cause any run-time failures, but unnecessary
confusion for the reader. This patch fixes the calculation.
gdb/ChangeLog:
* tui/tui-disasm.c (tui_set_disassem_content): Fix calculation of
the longest disassembly line's length.
A user reported a GDB crash with TUI when trying to debug a function
with a long demangled C++ method name. It turned out that the logic for
displaying the TUI disassembly window has a bug that can cause a buffer
overrun, possibly overwriting GDB-internal data structures. In
particular, the logic performs an unguarded strcpy.
Another (harmless) bug in tui_alloc_source_buffer causes the buffer to
be two lines longer than needed. This may have made the crash appear
less frequently.
gdb/ChangeLog:
* tui/tui-disasm.c (tui_set_disassem_content): Fix line buffer
overrun due to unchecked strcpy.
gdb/testsuite/ChangeLog:
* gdb.base/tui-layout.c: New file.
* gdb.base/tui-layout.exp: Use tui-layout.c, to ensure that the
disassembly window contains very long lines.
This removes make_cleanup_restore_current_ui by converting the last
use. The last use was in a few functions used to iterate over all
UIs. This patch replaces these functions with a class, and arranges
for the class destructor to do the needed cleanup.
2016-10-21 Tom Tromey <tom@tromey.com>
* tui/tui-interp.c (tui_on_normal_stop, tui_on_signal_received)
(tui_on_end_stepping_range, tui_on_signal_exited, tui_on_exited)
(tui_on_no_history, tui_on_user_selected_context_changed):
Update.
* top.h (switch_thru_all_uis): New class.
(SWITCH_THRU_ALL_UIS): Rewrite.
(make_cleanup_restore_current_ui, switch_thru_all_uis_init)
(switch_thru_all_uis_cond, switch_thru_all_uis_next): Don't
declare.
* mi/mi-interp.c (mi_new_thread, mi_thread_exit)
(mi_record_changed, mi_inferior_added, mi_inferior_appeared)
(mi_inferior_exit, mi_inferior_removed, mi_on_signal_received)
(mi_on_end_stepping_range, mi_on_signal_exited, mi_on_exited)
(mi_on_no_history, mi_on_normal_stop, mi_traceframe_changed)
(mi_tsv_created, mi_tsv_deleted, mi_tsv_modified)
(mi_breakpoint_created, mi_breakpoint_deleted)
(mi_breakpoint_modified, mi_output_running_pid, mi_on_resume)
(mi_solib_loaded, mi_solib_unloaded, mi_command_param_changed)
(mi_memory_changed, mi_user_selected_context_changed): Update.
* infrun.c (all_uis_check_sync_execution_done)
(all_uis_on_sync_execution_starting, normal_stop): Update.
* event-top.c (restore_ui_cleanup)
(make_cleanup_restore_current_ui, switch_thru_all_uis_init)
(switch_thru_all_uis_cond, switch_thru_all_uis_next): Remove.
* cli/cli-interp.c (cli_on_normal_stop, cli_on_signal_received)
(cli_on_end_stepping_range, cli_on_signal_exited, cli_on_exited)
(cli_on_no_history, cli_on_user_selected_context_changed):
Update.
* breakpoint.c (watchpoint_check): Update.
With this patch, when an inferior, thread or frame is explicitly
selected by the user, notifications will appear on all CLI and MI UIs.
When a GDB console is integrated in a front-end, this allows the
front-end to follow a selection made by the user ont he CLI, and it
informs the user about selection changes made behind the scenes by the
front-end.
This patch addresses PR gdb/20487.
In order to communicate frame changes to the front-end, this patch adds
a new field to the =thread-selected event for the selected frame. The
idea is that since inferior/thread/frame can be seen as a composition,
it makes sense to send them together in the same event. The vision
would be to eventually send the inferior information as well, if we find
that it's needed, although the "=thread-selected" event would be
ill-named for that job.
Front-ends need to handle this new field if they want to follow the
frame selection changes that originate from the console. The format of
the frame attribute is the same as what is found in the *stopped events.
Here's a detailed example for each command and the events they generate:
thread
------
1. CLI command:
thread 1.3
MI event:
=thread-selected,id="3",frame={...}
2. MI command:
-thread-select 3
CLI event:
[Switching to thread 1.3 ...]
3. MI command (CLI-in-MI):
thread 1.3
MI event/reply:
&"thread 1.3\n"
~"#0 child_sub_function () ...
=thread-selected,id="3",frame={level="0",...}
^done
frame
-----
1. CLI command:
frame 1
MI event:
=thread-selected,id="3",frame={level="1",...}
2. MI command:
-stack-select-frame 1
CLI event:
#1 0x00000000004007f0 in child_function...
3. MI command (CLI-in-MI):
frame 1
MI event/reply:
&"frame 1\n"
~"#1 0x00000000004007f9 in ..."
=thread-selected,id="3",frame={level="1"...}
^done
inferior
--------
Inferior selection events only go from the console to MI, since there's
no way to select the inferior in pure MI.
1. CLI command:
inferior 2
MI event:
=thread-selected,id="3"
Note that if the user selects an inferior that is not started or exited,
the MI doesn't receive a notification. Since there is no threads to
select, the =thread-selected event does not apply...
2. MI command (CLI-in-MI):
inferior 2
MI event/reply:
&"inferior 2\n"
~"[Switching to inferior 2 ...]"
=thread-selected,id="4",frame={level="0"...}
^done
Internal implementation detail: this patch makes it possible to suppress
notifications caused by a CLI command, like what is done in mi-interp.c.
This means that it's now possible to use the
add_com_suppress_notification function to register a command with some
event suppressed. It is used to implement the select-frame command in
this patch.
The function command_notifies_uscc_observer was added to extract
the rather complicated logical expression from the if statement. It is
also now clearer what that logic does: if the command used by the user
already notifies the user_selected_context_changed observer, there is
not need to notify it again. It therefore protects again emitting the
event twice.
No regressions, tested on ubuntu 14.04 x86 with target boards unix and
native-extended-gdbserver.
gdb/ChangeLog:
YYYY-MM-DD Antoine Tremblay <antoine.tremblay@ericsson.com>
YYYY-MM-DD Simon Marchi <simon.marchi@ericsson.com>
PR gdb/20487
* NEWS: Mention new frame field of =thread-selected event.
* cli/cli-decode.c (add_cmd): Initialize c->suppress_notification.
(add_com_suppress_notification): New function definition.
(cmd_func): Set and restore the suppress_notification flag.
* cli/cli-deicode.h (struct cmd_list_element)
<suppress_notification>: New field.
* cli/cli-interp.c (cli_suppress_notification): New global variable.
(cli_on_user_selected_context_changed): New function.
(_initialize_cli_interp): Attach to user_selected_context_changed
observer.
* command.h (struct cli_suppress_notification): New structure.
(cli_suppress_notification): New global variable declaration.
(add_com_suppress_notification): New function declaration.
* defs.h (enum user_selected_what_flag): New enum.
(user_selected_what): New enum flag type.
* frame.h (print_stack_frame_to_uiout): New function declaration.
* gdbthread.h (print_selected_thread_frame): New function declaration.
* inferior.c (print_selected_inferior): New function definition.
(inferior_command): Remove printing of inferior/thread/frame switch
notifications, notify user_selected_context_changed observer.
* inferior.h (print_selected_inferior): New function declaration.
* mi/mi-cmds.c (struct mi_cmd): Add user_selected_context
suppression to stack-select-frame and thread-select commands.
* mi/mi-interp.c (struct mi_suppress_notification)
<user_selected_context>: Initialize.
(mi_user_selected_context_changed): New function definition.
(_initialize_mi_interp): Attach to user_selected_context_changed.
* mi/mi-main.c (mi_cmd_thread_select): Print thread selection reply.
(mi_execute_command): Handle notification suppression. Notify
user_selected_context_changed observer on thread change instead of printing
event directly. Don't send it if command already sends the notification.
(command_notifies_uscc_observer): New function.
(mi_cmd_execute): Don't handle notification suppression.
* mi/mi-main.h (struct mi_suppress_notification)
<user_selected_context>: New field.
* stack.c (print_stack_frame_to_uiout): New function definition.
(select_frame_command): Notify user_selected_context_changed
observer.
(frame_command): Call print_selected_thread_frame if there's no frame
change or notify user_selected_context_changed observer if there is.
(up_command): Notify user_selected_context_changed observer.
(down_command): Likewise.
(_initialize_stack): Suppress user_selected_context notification for
command select-frame.
* thread.c (thread_command): Notify
user_selected_context_changed if the thread has changed, print
thread info directly if it hasn't.
(do_captured_thread_select): Do not print thread switch event.
(print_selected_thread_frame): New function definition.
* tui/tui-interp.c (tui_on_user_selected_context_changed):
New function definition.
(_initialize_tui_interp): Attach to user_selected_context_changed
observer.
gdb/doc/ChangeLog:
PR gdb/20487
* gdb.texinfo (Context management): Update mention of frame
change notifications.
(gdb/mi Async Records): Document frame field in
=thread-select event.
* observer.texi (GDB Observers): New user_selected_context_changed
observer.
gdb/testsuite/ChangeLog:
PR gdb/20487
* gdb.mi/mi-pthreads.exp (check_mi_thread_command_set): Adapt
=thread-select-event check.
As suggested by Pedro, this changes a few spots to use getcurx, rather
than getyx. This avoids some unused variable warnings.
2016-07-14 Tom Tromey <tom@tromey.com>
* tui/tui-winsource.c (tui_show_source_line): Use getcurx.
* tui/tui-io.c (tui_puts): Use getcurx.
(tui_redisplay_readline): Likewise.
Currently when a "step", "next", etc. finishes, the current source
line is printed on all console UIs.
This patch makes the CLI and TUI interpreters reuse MI's logic to only
emit console output related to a synchronous command on the
console-like interpreter that started the command in the first place.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
* cli/cli-interp.c (cli_on_normal_stop): Bail out early if there's
nothing to print. Use should_print_stop_to_console.
* tui/tui-interp.c (tui_on_normal_stop): Likewise.
All interpreter types (CLI/TUI/MI) print the prompt, and then call
start_event_loop.
Because we'll need an interpreter hook to display the
interpreter-specific prompt before going back to the event loop,
without actually starting an event loop, this patch moves the
start_event_loop call to common code, and replaces the command_loop
hook with a pre_command_look hook, that now just prints the prompt.
Turns out to be a cleanup on its own right anyway.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
* cli/cli-interp.c (cli_interpreter_pre_command_loop): New
function.
(cli_interp_procs): Install it instead of cli_command_loop.
* cli/cli-interp.h (cli_interpreter_pre_command_loop): Declare.
* event-top.c (cli_command_loop): Delete.
* interps.c (interp_new): Remove reference to command_loop_proc.
(current_interp_command_loop): Delete.
(interp_pre_command_loop): New function.
(interp_command_loop_ftype): Delete.
* interps.h (interp_pre_command_loop_ftype): New typedef.
(struct interp_procs) <command_loop_proc>: Delele field.
<pre_command_loop_proc>: New field.
(current_interp_command_loop): Delete declaration.
(interp_pre_command_loop): New declaration.
* main.c (captured_command_loop): Call interp_pre_command_loop
instead of current_interp_command_loop and start an event loop.
* mi/mi-interp.c (mi_command_loop): Delete.
(mi_interpreter_pre_command_loop): New.
(mi_interp_procs): Update.
* tui/tui-interp.c (tui_interp_procs): Install
cli_interpreter_pre_command_loop instead of cli_command_loop.
Due to the way that readline's API works (based on globals), we can
only have one instance of readline in a process. So the goal of this
patch is to only allow editing in the main UI, and make sure that only
one UI calls into readline. Some MI paths touch readline variables
currently, which is bad as that is changing variables that matter for
the main console UI. This patch fixes those.
This actually fixes a nasty bug -- starting gdb in MI mode ("gdb
-i=mi"), and then doing "set editing on" crashes GDB, because MI is
not prepared to use readline:
set editing on
&"set editing on\n"
=cmd-param-changed,param="editing",value="on"
^done
(gdb)
p 1
readline: readline_callback_read_char() called with no handler!
Aborted (core dumped)
The fix for that was to add an interp_proc method to query the
interpreter whether it actually supports editing. New test included.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
PR mi/20034
* cli/cli-interp.c: Include cli-interp.h and event-top.h.
(cli_interpreter_resume): Pass 1 to gdb_setup_readline. Set the
UI's input_handler here.
(cli_interpreter_supports_command_editing): New function.
(cli_interp_procs): Install it.
* cli/cli-interp.h: New file.
* event-top.c (async_command_editing_p): Rename to ...
(set_editing_cmd_var): ... this.
(change_line_handler): Add parameter 'editing', and use it. Bail
early if the interpreter doesn't support editing. Don't touch
readline state if editing is off.
(gdb_rl_callback_handler_remove, gdb_rl_callback_handler_install)
(gdb_rl_callback_handler_reinstall): Assert the current UI is the
main UI.
(display_gdb_prompt): Don't call gdb_rl_callback_handler_remove if
not using readline. Check whether the current UI is using command
editing instead of checking the async_command_editing_p global.
(set_async_editing_command): Delete.
(gdb_setup_readline): Add 'editing' parameter. Only allow editing
on the main UI. Don't touch readline state if editing is off.
(gdb_disable_readline): Don't touch readline state if editing is
off.
* event-top.h (gdb_setup_readline): Add 'int' parameter.
(set_async_editing_command): Delete declaration.
(change_line_handler, command_line_handler): Declare.
(async_command_editing_p): Rename to ...
(set_editing_cmd_var): ... this.
* infrun.c (reinstall_readline_callback_handler_cleanup): Check
whether the current UI has editing enabled rather than checking
the async_command_editing_p global.
* interps.c (interp_supports_command_editing): New function.
* interps.h (interp_supports_command_editing_ftype): New typedef.
(struct interp_procs) <supports_command_editing_proc>: New field.
(interp_supports_command_editing): Declare.
* mi/mi-interp.c (mi_interpreter_resume): Pass 0 to
gdb_setup_readline. Don't clear the async_command_editing_p
global. Update comments.
* top.c (gdb_readline_wrapper_line, gdb_readline_wrapper): Check
whether the current UI has editing enabled rather than checking
the async_command_editing_p global. Don't touch readline state if
editing is off.
(undo_terminal_modifications_before_exit): Switch to the main UI.
Unconditionally call gdb_disable_readline.
(set_editing): New function.
(show_async_command_editing_p): Rename to ...
(show_editing): ... this. Show the state of the current UI.
(_initialize_top): Adjust.
* top.h (struct ui) <command_editing>: New field.
* tui/tui-interp.c: Include cli/cli-interp.h.
(tui_resume): Pass 1 to gdb_setup_readline. Set the UI's
input_handler.
(tui_interp_procs): Install
cli_interpreter_supports_command_editing.
* tui/tui-io.c (tui_getc): Check whether the current UI has
editing enabled rather than checking the async_command_editing_p
global.
gdb/testsuite/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
PR mi/20034
* gdb.mi/mi-editing.exp: New file.
When we have multiple consoles, MI channels, etc., then we need to
broadcast breakpoint hits, etc. to all UIs. In the past, I've
adjusted most of the run control to communicate events to the
interpreters through observer notifications, so events would be
properly sent to console and MI streams, in sync and async modes.
This patch does the next logical step -- have each interpreter's
observers output interpreter-specific info to _all_ UIs.
Note that when we have multiple instances of active cli/tui
interpreters, then the cli_interp and tui_interp globals no longer
work. This is addressed by this patch.
Also, the interpreters currently register some observers when resumed
and remove them when suspended. If we have multiple instances of the
interpreters, and they can be suspended/resumed at different,
independent times, that no longer works. What we instead do is always
install the observers, and then have the observers themselves know
when to do nothing.
An earlier prototype of this series did the looping over struct UIs in
common code, and then dispatched events to the interpreters through a
matching interp_on_foo method for each observer. That turned out a
lot more complicated than the present solution, as we'd end up with
having to create a new interp method every time some interpreter
wanted to listen to some observer notification, resulting in a lot of
duplicated make-work and more coupling than desirable.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
* cli/cli-interp.c (cli_interp): Delete.
(as_cli_interp): New function.
(cli_on_normal_stop, cli_on_signal_received)
(cli_on_end_stepping_range, cli_on_signal_exited, cli_on_exited)
(cli_on_no_history): Send output to all CLI UIs.
(cli_on_sync_execution_done, cli_on_command_error): Skip output if
the top level interpreter is not a CLI.
(cli_interpreter_init): Don't set cli_interp or install observers
here.
(_initialize_cli_interp): Install observers here.
* event-top.c (main_ui_, ui_list): New globals.
(current_ui): Point to main_ui_.
(restore_ui_cleanup, switch_thru_all_uis_init)
(switch_thru_all_uis_cond, switch_thru_all_uis_next): New
functions.
* mi/mi-interp.c (as_mi_interp): New function.
(mi_interpreter_init): Don't install observers here.
(mi_on_sync_execution_done): Skip output if the top level
interpreter is not a MI.
(mi_new_thread, mi_thread_exit, mi_record_changed)
(mi_inferior_added, mi_inferior_appeared, mi_inferior_exit)
(mi_inferior_removed): Send output to all MI UIs.
(find_mi_interpreter, mi_interp_data): Delete.
(find_mi_interp): New function.
(mi_on_signal_received, mi_on_end_stepping_range)
(mi_on_signal_exited, mi_on_exited, mi_on_no_history): Send output
to all MI UIs.
(mi_on_normal_stop): Rename to ...
(mi_on_normal_stop_1): ... this.
(mi_on_normal_stop): Reimplement, sending output to all MI UIs.
(mi_traceframe_changed, mi_tsv_created, mi_tsv_deleted)
(mi_tsv_modified, mi_breakpoint_created, mi_breakpoint_deleted)
(mi_breakpoint_modified, mi_output_running_pid): Send output to
all MI UIs.
(mi_on_resume): Rename to ...
(mi_on_resume_1): ... this. Don't handle infcalls here.
(mi_on_resume): Reimplement, sending output to all MI UIs.
(mi_solib_loaded, mi_solib_unloaded, mi_command_param_changed)
(mi_memory_changed): Send output to all MI UIs.
(report_initial_inferior): Install observers here.
* top.h (struct ui) <next>: New field.
(ui_list): Declare.
(struct switch_thru_all_uis): New.
(switch_thru_all_uis_init, switch_thru_all_uis_cond)
(switch_thru_all_uis_next): Declare.
(SWITCH_THRU_ALL_UIS): New macro.
* tui/tui-interp.c (tui_interp): Delete global.
(as_tui_interp): New function.
(tui_on_normal_stop, tui_on_signal_received)
(tui_on_end_stepping_range, tui_on_signal_exited, tui_on_exited)
(tui_on_no_history): Send output to all TUI UIs.
(tui_on_sync_execution_done, tui_on_command_error): Skip output if
the top level interpreter is not a TUI.
(tui_init): Don't set tui_interp or install observers here.
(_initialize_tui_interp): Install observers here.
If every UI instance has its own set of interpreters, then the current
scheme of creating the interpreters at GDB initialization time no
longer works. We need to create them whenever a new UI instance is
created.
The scheme implemented here has each interpreter register a factory
callback that when called creates a new instance of a specific
interpreter type. Then, when some code in gdb looks up an interpreter
(always by name), if there's none yet, the factory method is called to
construct one.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
* cli/cli-interp.c (cli_uiout): Delete, moved into ...
(struct cli_interp): ... this new structure.
(cli_on_normal_stop, cli_on_signal_received)
(cli_on_end_stepping_range, cli_on_signal_exited, cli_on_exited)
(cli_on_no_history): Use interp_ui_out.
(cli_interpreter_init): If top level, set the cli_interp global.
(cli_interpreter_init): Return the interp's data instead of NULL.
(cli_interpreter_resume, cli_interpreter_exec, cli_ui_out): Adjust
to cli_uiout being in the interpreter's data.
(cli_interp_procs): New, factored out from _initialize_cli_interp.
(cli_interp_factory): New function.
(_initialize_cli_interp): Call interp_factory_register.
* interps.c (get_interp_info): New, factored out from ...
(get_current_interp_info): ... this.
(interp_new): Add parameter 'data'. Store it.
(struct interp_factory): New function.
(interp_factory_p): New typedef. Define a VEC_P.
(interpreter_factories): New global.
(interp_factory_register): New function.
(interp_add): Add 'ui' parameter. Use get_interp_info and
interp_lookup_existing.
(interp_lookup): Rename to ...
(interp_lookup_existing): ... this. Add 'ui' parameter. Don't
check for NULL or empty name here.
(interp_lookup): Add 'ui' parameter and reimplement.
(interp_set_temp, interpreter_exec_cmd): Adjust.
(interpreter_completer): Complete on registered interpreter
factories instead of interpreters.
* interps.h (interp_factory_func): New typedef.
(interp_factory_register): Declare.
(interp_new, interp_add): Adjust.
(interp_lookup): Declare.
* main.c (captured_main): Adjust.
* mi/mi-interp.c (mi_cmd_interpreter_exec): Adjust.
(mi_interp_procs): New, factored out from
_initialize_mi_interp.
(mi_interp_factory): New function.
* python/python.c (execute_gdb_command): Adjust.
* tui/tui-interp.c (tui_init): If top level, set the tui_interp
global.
(tui_interp_procs): New.
(tui_interp_factory): New function.
(_initialize_tui_interp): Call interp_factory_register.
As can be seen in the tui_redisplay_readline comment:
"The command could call prompt_for_continue and we must not restore
SingleKey so that the prompt and normal keymap are used."
immediate_quit is being used as proxy for "secondary prompt".
We have a better predicate nowadays, so use it.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* tui/tui-io.c (tui_redisplay_readline): Check
gdb_in_secondary_prompt_p instead of immediate_quit.
* tui/tui.c: Include top.h.
(tui_rl_startup_hook): Check gdb_in_secondary_prompt_p instead of
immediate_quit.
I stumbled upon this while doing some cxx-conversion work. Since the
x-family alloc functions throw on failure, it is useless to test their
result for failure. The else branch of != NULL is basically dead code.
I changed the type of element_block_ptr to struct tui_win_element, which
seems obvious (this is actually what raised the flag, casting the result
of xmalloc to struct tui_win_element* wouldn't work).
gdb/ChangeLog:
* tui/tui-data.c (tui_alloc_content): Don't check xmalloc
result. Change type of element_block_ptr. Change allocation to
use XNEWVEC.
The (void *) casts make the build fail in C++ mode and are unnecessary.
gdb/ChangeLog:
* tui/tui-data.c (tui_add_to_source_windows): Remove void *
cast.
(tui_add_content_elements): Likewise.