Commit Graph

803 Commits

Author SHA1 Message Date
Tom Tromey 0a9db5ad8a Change objfile_to_objfile_object to return a new reference
This changes objfile_to_objfile_object to return a new references and
fixes up all the uses.

gdb/ChangeLog
2018-09-16  Tom Tromey  <tom@tromey.com>

	* python/py-progspace.c (pspy_get_objfiles): Update.
	* python/python-internal.h (objfile_to_objfile_object): Change
	return type.
	* python/py-newobjfileevent.c (create_new_objfile_event_object):
	Update.
	* python/py-xmethods.c (gdbpy_get_matching_xmethod_workers):
	Update.
	* python/python.c (gdbpy_get_current_objfile): Update.
	(gdbpy_objfiles): Update.
	* python/py-objfile.c (objfpy_get_owner, gdbpy_lookup_objfile):
	Update.
	(objfile_to_objfile_object): Return a new reference.
	* python/py-symtab.c (stpy_get_objfile): Update.
	* python/py-prettyprint.c (find_pretty_printer_from_objfiles):
	Update.
2018-09-16 07:25:56 -06:00
Tom Tromey 3c7aa30778 Change pspace_to_pspace_object to return a new reference
This changes pspace_to_pspace_object to return a new reference and
fixes up all the callers.

gdb/ChangeLog
2018-09-16  Tom Tromey  <tom@tromey.com>

	* python/py-inferior.c (infpy_get_progspace): Update.
	* python/python-internal.h (pspace_to_pspace_object): Change
	return type.
	* python/py-newobjfileevent.c
	(create_clear_objfiles_event_object): Update.
	* python/py-xmethods.c (gdbpy_get_matching_xmethod_workers):
	Update.
	* python/python.c (gdbpy_get_current_progspace): Update.
	(gdbpy_progspaces): Update.
	* python/py-progspace.c (pspace_to_pspace_object): Return a new
	reference.
	* python/py-objfile.c (objfpy_get_progspace): Update.
	* python/py-prettyprint.c (find_pretty_printer_from_progspace):
	Update.
2018-09-16 07:25:56 -06:00
Tom Tromey 8743a9cdd2 Add more methods to gdb.Progspace
There are a number of global functions in the gdb Python module which
really should be methods on Progspace.  This patch adds new methods to
Progspace and then redefines these globals in terms of these new
methods.

This version has been rebased on the related changes that Simon
recently put in.

Built and regtested on x86-64 Fedora 28.

gdb/ChangeLog
2018-09-16  Tom Tromey  <tom@tromey.com>

	* python/lib/gdb/__init__.py (current_progspace, objfiles)
	(solib_name, block_for_pc, find_pc_line): New functions.
	(execute_unwinders): Update.
	* python/py-block.c (gdbpy_block_for_pc): Remove.
	* python/py-inferior.c (infpy_get_progspace): New function.
	(inferior_object_getset) <progspace>: Add.
	* python/py-progspace.c (pspy_objfiles): Rewrite.
	(pspy_solib_name, pspy_block_for_pc)
	(pspy_find_pc_line, pspy_is_valid): New functions.
	(progspace_object_methods): Add entries for solib_name,
	block_for_pc, find_pc_line, is_valid.
	* python/python-internal.h (gdbpy_block_for_pc)
	(build_objfiles_list): Don't declare.
	* python/python.c: Don't include solib.h.
	(gdbpy_solib_name, gdbpy_find_pc_line)
	(gdbpy_get_current_progspace, build_objfiles_list)
	(gdbpy_objfiles): Remove.
	(GdbMethods) <current_progspace, objfiles, block_for_pc,
	solib_name, find_pc_line>: Remove entries.

gdb/doc/ChangeLog
2018-09-16  Tom Tromey  <tom@tromey.com>

	* python.texi (Basic Python): Update docs for find_pc_line,
	solib_name.
	(Progspaces In Python): Update docs for current_progspace.
	Document block_for_pc, find_pc_line, is_valid, nsolib_name.
	Move method documentation before example.
2018-09-16 06:52:37 -06:00
Tom Tromey a3a6aef409 Fix possible exception leak in python.c
In the Python code, gdb exceptions may not leak into the Python core.
execute_gdb_command was calling bpstat_do_actions outside of a
TRY/CATCH; which seemed risky.  I don't have a test case for this, but
if bpstat_do_actions could ever throw, it could crash gdb.

This patch introduces a new scope in order to preserve the current
semantics, so it is looks a bit bigger than it really is.

Tested on x86-64 Fedora 28.

gdb/ChangeLog
2018-09-07  Tom Tromey  <tom@tromey.com>

	* python/python.c (execute_gdb_command): Call bpstat_do_actions
	inside the TRY.
2018-09-14 21:56:41 -06:00
Tom Tromey 7d2215128b Make infpy_thread_from_thread_handle static
I noticed that infpy_thread_from_thread_handle is not static, but
should be.  This patch changes it.

gdb/ChangeLog
2018-09-13  Tom Tromey  <tom@tromey.com>

	* python/py-inferior.c (infpy_thread_from_thread_handle): Now
	static.
2018-09-13 16:23:52 -06:00
Simon Marchi 0ae1a3211a python: Add Progspace.objfiles method
This patch adds an objfiles method to the Progspace object, which
returns a sequence of the objfiles associated to that program space.  I
chose a method rather than a property for symmetry with gdb.objfiles().

gdb/ChangeLog:

	* python/py-progspace.c (PSPY_REQUIRE_VALID): New macro.
	(pspy_get_objfiles): New function.
	(progspace_object_methods): New.
	(pspace_object_type): Add tp_methods callback.
	* python/python-internal.h (build_objfiles_list): New
	declaration.
	* python/python.c (build_objfiles_list): New function.
	(gdbpy_objfiles): Implement using build_objfiles_list.
	* NEWS: Mention the Progspace.objfiles method.

gdb/doc/ChangeLog:

	* python.texi (Program Spaces In Python): Document the
	Progspace.objfiles method.
	(Objfiles In Python): Mention that gdb.objfiles() is identical
	to gdb.selected_inferior().progspace.objfiles().

gdb/testsuite/ChangeLog:

	* gdb.python/py-progspace.exp: Test the Progspace.objfiles
	method.
2018-09-13 15:42:12 -04:00
Simon Marchi a40bf0c2e9 python: Add Inferior.progspace property
This patch adds a progspace property to the gdb.Inferior type, which
allows getting the gdb.Progspace object associated to that inferior.
In conjunction with the following patch, this will allow scripts iterate
on objfiles associated with a particular inferior.

gdb/ChangeLog:

	* python/py-inferior.c (infpy_get_progspace): New function.
	(inferior_object_getset): Add progspace property.
	* NEWS: Mention the new property.

gdb/doc/ChangeLog:

	* python.texi (Inferiors In Python): Document
	Inferior.progspace.
	(Program Spaces In Python): Document that
	gdb.current_progspace() is the same as
	gdb.selected_inferior().progspace.

gdb/testsuite/ChangeLog:

	* gdb.python/py-inferior.exp: Add tests for Inferior.progspace
	and a few other Inferior properties when the Inferior is no
	longer valid.
2018-09-13 15:42:12 -04:00
Simon Marchi 1256af7d1a python: Provide textual representation for Inferior and Objfile
Printing a GDB Python object is notoriously not helpful:

>>> print(gdb.selected_inferior())
<gdb.Inferior object at 0x7fea59aed198>
>>> print(gdb.objfiles())
[<gdb.Objfile object at 0x7fea59b57c90>]

This makes printing debug traces more difficult than it should be.  This
patch provides some repr() implementation for these two types (more to
come if people agree with the idea, but I want to test the water first).
Here's the same example as above, but with this patch:

>>> print(gdb.selected_inferior())
<gdb.Inferior num=1>
>>> print(gdb.objfiles())
[<gdb.Objfile filename=/home/emaisin/build/binutils-gdb-gcc-git/gdb/test>]

I implemented repr rather than str, because when printing a list (or
another container I suppose), Python calls the repr method of the
elements.  This is useful when printing a list of inferiors or objfiles.
The print(gdb.objfiles()) above would not have worked if I had
implemented str.

I found this post useful to understand the difference between repr and
str:

  https://stackoverflow.com/questions/1436703/difference-between-str-and-repr

gdb/ChangeLog:

	* python/py-inferior.c (infpy_repr): New.
	(inferior_object_type): Register infpy_repr.
	* python/py-objfile.c (objfpy_repr): New.
	(objfile_object_type): Register objfpy_repr.

gdb/testsuite/ChangeLog:

	* gdb.python/py-inferior.exp: Test repr() of gdb.Inferior.
	* gdb.python/py-objfile.exp: Test repr() of gdb.Objfile.
	* gdb.python/py-symtab.exp: Update test printing an objfile.

gdb/doc/ChangeLog:

	* python.texi (Basic Python): Mention the string representation
	of GDB Python objects.
2018-09-13 11:54:38 -04:00
Tom Tromey a154931ef1 Fix help text for "python" command
PR python/18380 points out that the example in the "help python" text
will only work in Python 2.  This changes the example to be valid
syntax for both Python 2 and Python 3.

gdb/ChangeLog
2018-09-10  Tom Tromey  <tom@tromey.com>

	PR python/18380:
	* python/python.c (_initialize_python): Make example in "python"
	help work in Python 3.
2018-09-10 07:44:24 -06:00
Simon Marchi a5c5eda7e4 python: Make two functions return gdbpy_ref<>
I noticed that we release a gdbpy_ref in pretty_print_one_value only to
create it again later.  This patch fills the gap by returning a
gdbpy_ref all the way.

gdb/ChangeLog:

	* python/py-prettyprint.c (pretty_print_one_value): Return
	gdbpy_ref<>.
	(print_string_repr): Adjust.
	(apply_varobj_pretty_printer): Return gdbpy_ref<>.
	* python/python-internal.h (apply_varobj_pretty_printer): Return
	gdbpy_ref<>.
	* varobj.c (varobj_value_get_print_value): Adjust.
2018-09-09 08:13:17 +01:00
Tom Tromey 332cf4c925 Allow a pretty-printer without a to_string method
PR python/16047 points out that, while the documentation says that the
to_string method is optional for a pretty-printer, the code disagrees
and throws an exception.  This patch fixes the problem.  varobj is
already ok here.

Tested on x86-64 Fedora 26.

gdb/ChangeLog
2018-09-08  Tom Tromey  <tom@tromey.com>

	PR python/16047:
	* python/py-prettyprint.c (pretty_print_one_value): Check for
	to_string method.

gdb/testsuite/ChangeLog
2018-09-08  Tom Tromey  <tom@tromey.com>

	PR python/16047:
	* gdb.python/py-prettyprint.py (pp_int_typedef3): New class.
	(register_pretty_printers): Register new printer.
	* gdb.python/py-prettyprint.exp (run_lang_tests): Add int_type3
	test.
	* gdb.python/py-prettyprint.c (int_type3): New typedef.
	(an_int_type3): New global.
2018-09-08 20:49:15 -06:00
Jan Vrany 3bf9c013e4 MI: Fix printing of frame architecture with Python frame filters enabled
Commit 6d52907e22 (MI: Print frame architecture when printing frames
on an MI channel) added frame's architecture to MI frame output. However
the frame architecture was not correctly printed in the output of
"-stack-list-frames" with frame filters enabled (via "-enable-frame-filters").
This was because with frame filters enabled, the actual frame printing is
done in "py_print_frame" rather than "print_frame". This issue is now fixed.

gdb/Changelog:
2018-08-27  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* python/py-framefilter.c (py_print_frame): Print frame architecture
	when printing on an MI output.

gdb/testsuite/Changelog:
2018-08-27  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.python/py-framefilter-mi.exp: Update regexp to
	check for "arch" field in frame output.
2018-08-27 17:12:41 -04:00
Simon Marchi bbbbbceebc Initialize variable in py_get_event_thread
The pythread variable could be used without being initialized, fix it by
initializing it to nullptr.

gdb/ChangeLog:

	* python/py-threadevent.c (py_get_event_thread): Initialize
	pythread.
2018-08-25 11:52:24 -04:00
Pedro Alves d98fc15be2 gdb/python: Use copy-initialization more when possible
gdb/ChangeLog:
2018-08-24  Pedro Alves  <palves@redhat.com>

	* python/py-bpevent.c (create_breakpoint_event_object): Use
	copy-initialization.
	* python/py-continueevent.c (emit_continue_event): Use
	copy-initialization.
	* python/py-exitedevent.c (create_exited_event_object): Return a
	gdbpy_ref<>.
	(emit_exited_event): Use copy-initialization.
	* python/py-inferior.c (python_new_inferior)
	(python_inferior_deleted, add_thread_object): Use
	copy-initialization.
	* python/py-infevents.c (create_inferior_call_event_object)
	(create_register_changed_event_object)
	(create_memory_changed_event_object): Return a gdbpy_ref<>.
	(emit_inferior_call_event, emit_memory_changed_event)
	(emit_register_changed_event): Use copy-initialization.
	* python/py-newobjfileevent.c (create_new_objfile_event_object):
	Return a gdbpy_ref<>.
	(emit_new_objfile_event): Use copy-initialization.
	(create_clear_objfiles_event_object): Return a gdbpy_ref<>.
	(emit_clear_objfiles_event): Use copy-initialization.
	* python/py-signalevent.c (create_signal_event_object): Use
	copy-initialization.
	* python/py-threadevent.c (create_thread_event_object): Use
	copy-initialization.
2018-08-24 22:57:16 +01:00
Pedro Alves da3c873831 Fix 8.2 regression in gdb.python/py-evthreads.exp w/ gdbserver (PR gdb/23379)
This commit fixes a 8.1->8.2 regression exposed by
gdb.python/py-evthreads.exp when testing with
--target_board=native-gdbserver.

gdb.log shows:

  src/gdb/thread.c:93: internal-error: thread_info* inferior_thread(): Assertion `tp' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) FAIL: gdb.python/py-evthreads.exp: run to breakpoint 1 (GDB internal error)

A backtrace shows (frames #2 and #10 highlighted) that the assertion
fails when GDB is setting up the connection to the remote target, in
non-stop mode:

  #0  0x0000000000622ff0 in internal_error(char const*, int, char const*, ...) (file=0xc1ad98 "src/gdb/thread.c", line=93, fmt=0xc1ad20 "%s: Assertion `%s' failed.") at src/gdb/common/errors.c:54
  #1  0x000000000089567e in inferior_thread() () at src/gdb/thread.c:93
= #2  0x00000000004da91d in get_event_thread() () at src/gdb/python/py-threadevent.c:38
  #3  0x00000000004da9b7 in create_thread_event_object(_typeobject*, _object*) (py_type=0x11574c0 <continue_event_object_type>, thread=0x0)
      at src/gdb/python/py-threadevent.c:60
  #4  0x00000000004bf6fe in create_continue_event_object() () at src/gdb/python/py-continueevent.c:27
  #5  0x00000000004bf738 in emit_continue_event(ptid_t) (ptid=...) at src/gdb/python/py-continueevent.c:40
  #6  0x00000000004c7d47 in python_on_resume(ptid_t) (ptid=...) at src/gdb/python/py-inferior.c:108
  #7  0x0000000000485bfb in std::_Function_handler<void (ptid_t), void (*)(ptid_t)>::_M_invoke(std::_Any_data const&, ptid_t&&) (__functor=..., __args#0=...) at /usr/include/c++/7/bits/std_function.h:316
  #8  0x000000000089b416 in std::function<void (ptid_t)>::operator()(ptid_t) const (this=0x12aa600, __args#0=...)
      at /usr/include/c++/7/bits/std_function.h:706
  #9  0x000000000089aa0e in gdb::observers::observable<ptid_t>::notify(ptid_t) const (this=0x118a7a0 <gdb::observers::target_resumed>, args#0=...)
      at src/gdb/common/observable.h:106
= #10 0x0000000000896fbe in set_running(ptid_t, int) (ptid=..., running=1) at src/gdb/thread.c:880
  #11 0x00000000007f750f in remote_target::remote_add_thread(ptid_t, bool, bool) (this=0x12c5440, ptid=..., running=true, executing=true) at src/gdb/remote.c:2434
  #12 0x00000000007f779d in remote_target::remote_notice_new_inferior(ptid_t, int) (this=0x12c5440, currthread=..., executing=1)
      at src/gdb/remote.c:2515
  #13 0x00000000007f9c44 in remote_target::update_thread_list() (this=0x12c5440) at src/gdb/remote.c:3831
  #14 0x00000000007fb922 in remote_target::start_remote(int, int) (this=0x12c5440, from_tty=0, extended_p=0)
      at src/gdb/remote.c:4655
  #15 0x00000000007fd102 in remote_target::open_1(char const*, int, int) (name=0x1a4f45e "localhost:2346", from_tty=0, extended_p=0)
      at src/gdb/remote.c:5638
  #16 0x00000000007fbec1 in remote_target::open(char const*, int) (name=0x1a4f45e "localhost:2346", from_tty=0)
      at src/gdb/remote.c:4862

So on frame #10, we're marking a newly-discovered thread as running,
and that causes the Python API to emit a gdb.ContinueEvent.
gdb.ContinueEvent is a gdb.ThreadEvent, and as such includes the event
thread as the "inferior_thread" attribute.  The problem is that when
we get to frame #3/#4, we lost all references to the thread that is
being marked as running.  create_continue_event_object assumes that it
is the current thread, which is not true in this case.

Fix this by passing down the right thread in
create_continue_event_object.  Also remove
create_thread_event_object's default argument and have the only other
caller left pass down the right thread explicitly too.

gdb/ChangeLog:
2018-08-24  Pedro Alves  <palves@redhat.com>
	    Simon Marchi  <simon.marchi@ericsson.com>

	PR gdb/23379
	* python/py-continueevent.c: Include "gdbthread.h".
	(create_continue_event_object): Add intro comment.  Add 'ptid'
	parameter.  Use it to find thread to pass to
	create_thread_event_object.
	(emit_continue_event): Pass PTID down to
	create_continue_event_object.
	* python/py-event.h (py_get_event_thread): Declare.
	(create_thread_event_object): Remove default from 'thread'
	parameter.
	* python/py-stopevent.c (create_stop_event_object): Use
	py_get_event_thread.
	* python/py-threadevent.c (get_event_thread): Rename to ...
	(py_get_event_thread): ... this, make extern, add 'ptid' parameter
	and use it to find the thread.
	(create_thread_event_object): Assert that THREAD isn't null.
	Don't find the event thread here.
2018-08-24 22:13:30 +01:00
Tom Tromey 89fbedf3ab Remove "repeat" argument from command_line_input
After the previous patch, all callers pass 0 as the repeat argument to
command_line_input.  So, this patch removes it.

gdb/ChangeLog
2018-08-16  Tom Tromey  <tom@tromey.com>

	* top.c (read_command_file): Update.
	(command_line_input): Remove "repeat" argument.
	* ada-lang.c (get_selections): Update.
	* linespec.c (decode_line_2): Update.
	* defs.h (command_line_input): Remove argument.
	* cli/cli-script.c (read_next_line): Update.
	* python/py-gdb-readline.c: Update.
2018-08-17 16:39:06 -06:00
Tom Tromey c51f6a54c2 Call value_fetch_lazy when needed in pretty-printers
This removes some unused variables, and replaces the calls to
value_contents_for_printing with a call to value_fetch_lazy, when
needed.

gdb/ChangeLog
2018-07-22  Tom Tromey  <tom@tromey.com>

	* python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Remove
	unused variable.  Call value_fetch_lazy when needed.
	* guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer):
	Remove unused variable.  Call value_fetch_lazy when needed.
2018-07-22 13:20:04 -06:00
Tom Tromey 8d49165d83 Simple unused variable removals
This patch holds all the straightforward unused variable deletions.

gdb/ChangeLog
2018-07-22  Tom Tromey  <tom@tromey.com>

	* guile/scm-value.c (gdbscm_value_call): Remove unused variables.
	* guile/scm-math.c (vlscm_unop_gdbthrow, vlscm_binop_gdbthrow)
	(vlscm_convert_typed_value_from_scheme): Remove unused variable.
	* buildsym-legacy.c (get_macro_table): Remove unused variable.
	* stack.c (frame_apply_level_command): Remove unused variable.
	* tic6x-tdep.c (tic6x_push_dummy_call): Remove unused variable.
	* sparc64-tdep.c (adi_examine_command): Remove unused variable.
	* rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Remove
	unused variable.
	* nios2-tdep.c (nios2_push_dummy_call): Remove unused variable.
	* mep-tdep.c (mep_push_dummy_call): Remove unused variable.
	* ada-lang.c (ada_lookup_symbol_list_worker): Remove unused
	variable.
	* amd64-tdep.c (amd64_supply_xsave): Remove unused variable.
	* arm-tdep.c (arm_record_data_proc_misc_ld_str): Remove unused
	variable.
	* breakpoint.c (check_no_tracepoint_commands, update_watchpoint):
	Remove unused variable.
	* cli/cli-script.c (recurse_read_control_structure): Remove unused
	variable.
	* common/tdesc.c (print_xml_feature::visit): Remove unused
	variable.
	* compile/compile-object-load.c (store_regs): Remove unused
	variables.
	* complaints.c (clear_complaints): Remove unused variable.
	* corelow.c (core_target_open): Remove unused variable.
	* fbsd-tdep.c (fbsd_core_info_proc_status): Remove unused
	variable.
	* guile/scm-frame.c (gdbscm_frame_read_var): Remove unused
	variable.
	* guile/scm-symtab.c (stscm_print_sal_smob): Remove unused
	variable.
	* guile/scm-type.c (gdbscm_field_baseclass_p): Remove unused
	variable.
	* guile/scm-utils.c (gdbscm_parse_function_args): Remove unused
	variable.
	* hppa-tdep.c (hppa_stub_frame_unwind_cache): Remove unused
	variable.
	* ia64-tdep.c (examine_prologue): Remove unused variable.
	* infcall.c (run_inferior_call): Remove unused variable.
	* inferior.c (exit_inferior): Remove unused variable.
	* infrun.c (infrun_thread_ptid_changed): Remove unused variable.
	* linespec.c (decode_line_2): Remove unused variable.
	* linux-nat.c (super_close): Remove.
	* linux-tdep.c (linux_info_proc): Remove unused variable.
	* mi/mi-main.c (mi_execute_command): Remove unused variable.
	* microblaze-linux-tdep.c (microblaze_linux_sigtramp_cache):
	Remove unused variable.
	* parse.c (find_minsym_type_and_address): Remove unused variable.
	* printcmd.c (info_symbol_command, printf_floating): Remove unused
	variable.
	* python/py-breakpoint.c (bppy_set_commands): Remove unused
	variable.
	* python/py-unwind.c (unwind_infopy_dealloc): Remove unused
	variables.
	* record-btrace.c (record_btrace_target::store_registers): Remove
	unused variable.
	(cmd_show_record_btrace_cpu): Remove unused variable.
	* riscv-tdep.c (riscv_register_reggroup_p)
	(riscv_push_dummy_call, riscv_return_value): Remove unused
	variable.
	* rust-exp.y (literal): Remove unused variable.
	* rust-lang.c (rust_evaluate_subexp) <OP_RUST_ARARAY>: Remove
	unused variable.
	<STRUCTOP_ANONYMOUS>: Likewise.
	* s390-linux-tdep.c (s390_linux_init_abi_31)
	(s390_linux_init_abi_64): Remove unused variable.
	* ser-ming2.c (ser_windows_read_prim, pipe_select_thread)
	(file_select_thread, net_windows_open, _initialize_ser_windows):
	Remove unused variables.
	* symtab.c (find_pc_sect_line): Remove unused variable.
	* target-memory.c (compute_garbled_blocks): Remove unused
	variable.
	(target_write_memory_blocks): Remove unused variable.
	* target.c (target_stack::unpush): Remove unused variables.
	* tracepoint.c (start_tracing, all_tracepoint_actions)
	(merge_uploaded_trace_state_variables)
	(print_one_static_tracepoint_marker): Remove unused variable.
	* unittests/basic_string_view/element_access/char/1.cc (test01):
	Remove unused variable.
	* windows-nat.c (windows_continue, windows_add_all_dlls)
	(do_initial_windows_stuff, windows_nat_target::create_inferior):
	Remove unused variables.
2018-07-22 13:20:01 -06:00
Tom Tromey cc6bcb548d Remove ptid_get_tid
This removes ptid_get_tid in favor of calling the ptid_t::tid method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_tid): Remove.
	* common/ptid.h (ptid_get_tid): Don't declare.
	* ada-tasks.c: Update.
	* aix-thread.c: Update.
	* bsd-uthread.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* i386-darwin-nat.c: Update.
	* infrun.c: Update.
	* linux-tdep.c: Update.
	* nto-procfs.c: Update.
	* ppc-ravenscar-thread.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* sol-thread.c: Update.
	* sparc-ravenscar-thread.c: Update.
	* windows-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* target.c: Update.
2018-07-03 11:36:44 -06:00
Tom Tromey e38504b392 Remove ptid_get_lwp
This removes ptid_get_lwp in favor of calling the ptid_t::lwp method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_lwp): Remove.
	* common/ptid.h (ptid_get_lwp): Don't declare.
	* aarch64-linux-nat.c: Update.
	* ada-tasks.c: Update.
	* aix-thread.c: Update.
	* amd64-linux-nat.c: Update.
	* arm-linux-nat.c: Update.
	* corelow.c: Update.
	* fbsd-nat.c: Update.
	* fbsd-tdep.c: Update.
	* gnu-nat.c: Update.
	* i386-cygwin-tdep.c: Update.
	* i386-gnu-nat.c: Update.
	* i386-linux-nat.c: Update.
	* ia64-linux-nat.c: Update.
	* inf-ptrace.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-tdep.c: Update.
	* linux-thread-db.c: Update.
	* mips-linux-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/aarch64-linux.c: Update.
	* nat/linux-btrace.c: Update.
	* nat/linux-osdata.c: Update.
	* nat/linux-procfs.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* obsd-nat.c: Update.
	* ppc-fbsd-nat.c: Update.
	* ppc-linux-nat.c: Update.
	* procfs.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* remote.c: Update.
	* s390-linux-nat.c: Update.
	* sol-thread.c: Update.
	* sol2-tdep.c: Update.
	* spu-linux-nat.c: Update.
	* x86-linux-nat.c: Update.
	* xtensa-linux-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-mips-low.c: Update.
	* lynx-low.c: Update.
	* nto-low.c: Update.
	* remote-utils.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* target.c: Update.
	* thread-db.c: Update.
2018-07-03 11:36:43 -06:00
Tom Tromey e99b03dcf4 Remove ptid_get_pid
This removes ptid_get_pid in favor of calling the ptid_t::pid method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_pid): Remove.
	* common/ptid.h (ptid_get_pid): Don't declare.
	* aarch64-linux-nat.c: Update.
	* ada-lang.c: Update.
	* aix-thread.c: Update.
	* alpha-bsd-nat.c: Update.
	* amd64-fbsd-nat.c: Update.
	* amd64-linux-nat.c: Update.
	* arm-linux-nat.c: Update.
	* arm-nbsd-nat.c: Update.
	* auxv.c: Update.
	* break-catch-syscall.c: Update.
	* breakpoint.c: Update.
	* bsd-uthread.c: Update.
	* corelow.c: Update.
	* ctf.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* fbsd-tdep.c: Update.
	* gcore.c: Update.
	* gnu-nat.c: Update.
	* hppa-nbsd-nat.c: Update.
	* hppa-obsd-nat.c: Update.
	* i386-fbsd-nat.c: Update.
	* ia64-linux-nat.c: Update.
	* inf-ptrace.c: Update.
	* infcmd.c: Update.
	* inferior.c: Update.
	* inferior.h: Update.
	* inflow.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-tdep.c: Update.
	* linux-thread-db.c: Update.
	* m68k-bsd-nat.c: Update.
	* mi/mi-interp.c: Update.
	* mi/mi-main.c: Update.
	* mips-linux-nat.c: Update.
	* mips-nbsd-nat.c: Update.
	* mips64-obsd-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/aarch64-linux.c: Update.
	* nat/linux-btrace.c: Update.
	* nat/linux-osdata.c: Update.
	* nat/linux-procfs.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* nto-procfs.c: Update.
	* obsd-nat.c: Update.
	* ppc-linux-nat.c: Update.
	* ppc-nbsd-nat.c: Update.
	* ppc-obsd-nat.c: Update.
	* proc-service.c: Update.
	* procfs.c: Update.
	* python/py-inferior.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* record.c: Update.
	* remote-sim.c: Update.
	* remote.c: Update.
	* rs6000-nat.c: Update.
	* s390-linux-nat.c: Update.
	* sh-nbsd-nat.c: Update.
	* sol-thread.c: Update.
	* sparc-nat.c: Update.
	* sparc64-tdep.c: Update.
	* spu-linux-nat.c: Update.
	* spu-tdep.c: Update.
	* target-debug.h: Update.
	* target.c: Update.
	* thread.c: Update.
	* tid-parse.c: Update.
	* tracefile-tfile.c: Update.
	* vax-bsd-nat.c: Update.
	* windows-nat.c: Update.
	* x86-linux-nat.c: Update.
	* x86-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-mips-low.c: Update.
	* lynx-low.c: Update.
	* mem-break.c: Update.
	* nto-low.c: Update.
	* remote-utils.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* target.c: Update.
	* tracepoint.c: Update.
2018-07-03 11:36:42 -06:00
Tom Tromey 0c6aef226e Remove a VEC from py-unwind.c
This removes a use of VEC from py-unwind.c, replacing it wit
std::vector.  It also changes saved_regs to hold a gdbpy_ref<>,
simplifying the memory management.

Tested against gdb.python on x86-64 Fedora 26.

gdb/ChangeLog
2018-06-27  Tom Tromey  <tom@tromey.com>

	* python/py-unwind.c (unwind_info_object) <saved_regs>: Now a
	std::vector.
	(unwind_infopy_str, pyuw_create_unwind_info)
	(unwind_infopy_add_saved_register, pyuw_sniffer)
	(unwind_infopy_dealloc, unwind_infopy_add_saved_register):
	Update.
	(struct saved_reg): Add constructor.
	<value>: Now a gdbpy_ref<>.
2018-06-27 14:50:10 -06:00
Pedro Alves 00431a78b2 Use thread_info and inferior pointers more throughout
This is more preparation bits for multi-target support.

In a multi-target scenario, we need to address the case of different
processes/threads running on different targets that happen to have the
same PID/PTID.  E.g., we can have both process 123 in target 1, and
process 123 in target 2, while they're in reality different processes
running on different machines.  Or maybe we've loaded multiple
instances of the same core file.  Etc.

To address this, in my WIP multi-target branch, threads and processes
are uniquely identified by the (process_stratum target_ops *, ptid_t)
and (process_stratum target_ops *, pid) tuples respectively.  I.e.,
each process_stratum instance has its own thread/process number space.

As you can imagine, that requires passing around target_ops * pointers
in a number of functions where we're currently passing only a ptid_t
or an int.  E.g., when we look up a thread_info object by ptid_t in
find_thread_ptid, the ptid_t alone isn't sufficient.

In many cases though, we already have the thread_info or inferior
pointer handy, but we "lose" it somewhere along the call stack, only
to look it up again by ptid_t/pid.  Since thread_info or inferior
objects know their parent target, if we pass around thread_info or
inferior pointers when possible, we avoid having to add extra
target_ops parameters to many functions, and also, we eliminate a
number of by ptid_t/int lookups.

So that's what this patch does.  In a bit more detail:

- Changes a number of functions and methods to take a thread_info or
  inferior pointer instead of a ptid_t or int parameter.

- Changes a number of structure fields from ptid_t/int to inferior or
  thread_info pointers.

- Uses the inferior_thread() function whenever possible instead of
  inferior_ptid.

- Uses thread_info pointers directly when possible instead of the
  is_running/is_stopped etc. routines that require a lookup.

- A number of functions are eliminated along the way, such as:

  int valid_gdb_inferior_id (int num);
  int pid_to_gdb_inferior_id (int pid);
  int gdb_inferior_id_to_pid (int num);
  int in_inferior_list (int pid);

- A few structures and places hold a thread_info pointer across
  inferior execution, so now they take a strong reference to the
  (refcounted) thread_info object to avoid the thread_info pointer
  getting stale.  This is done in enable_thread_stack_temporaries and
  in the infcall.c code.

- Related, there's a spot in infcall.c where using a RAII object to
  handle the refcount would be handy, so a gdb::ref_ptr specialization
  for thread_info is added (thread_info_ref, in gdbthread.h), along
  with a gdb_ref_ptr policy that works for all refcounted_object types
  (in common/refcounted-object.h).

gdb/ChangeLog:
2018-06-21  Pedro Alves  <palves@redhat.com>

	* ada-lang.h (ada_get_task_number): Take a thread_info pointer
	instead of a ptid_t.  All callers adjusted.
	* ada-tasks.c (ada_get_task_number): Likewise.  All callers
	adjusted.
	(print_ada_task_info, display_current_task_id, task_command_1):
	Adjust.
	* breakpoint.c (watchpoint_in_thread_scope): Adjust to use
	inferior_thread.
	(breakpoint_kind): Adjust.
	(remove_breakpoints_pid): Rename to ...
	(remove_breakpoints_inf): ... this.  Adjust to take an inferior
	pointer.  All callers adjusted.
	(bpstat_clear_actions): Use inferior_thread.
	(get_bpstat_thread): New.
	(bpstat_do_actions): Use it.
	(bpstat_check_breakpoint_conditions, bpstat_stop_status): Adjust
	to take a thread_info pointer.  All callers adjusted.
	(set_longjmp_breakpoint_for_call_dummy, set_momentary_breakpoint)
	(breakpoint_re_set_thread): Use inferior_thread.
	* breakpoint.h (struct inferior): Forward declare.
	(bpstat_stop_status): Update.
	(remove_breakpoints_pid): Delete.
	(remove_breakpoints_inf): New.
	* bsd-uthread.c (bsd_uthread_target::wait)
	(bsd_uthread_target::update_thread_list): Use find_thread_ptid.
	* btrace.c (btrace_add_pc, btrace_enable, btrace_fetch)
	(maint_btrace_packet_history_cmd)
	(maint_btrace_clear_packet_history_cmd): Adjust.
	(maint_btrace_clear_cmd, maint_info_btrace_cmd): Adjust to use
	inferior_thread.
	* cli/cli-interp.c: Include "inferior.h".
	* common/refcounted-object.h (struct
	refcounted_object_ref_policy): New.
	* compile/compile-object-load.c: Include gdbthread.h.
	(store_regs): Use inferior_thread.
	* corelow.c (core_target::close): Use current_inferior.
	(core_target_open): Adjust to use first_thread_of_inferior and use
	the current inferior.
	* ctf.c (ctf_target::close): Adjust to use current_inferior.
	* dummy-frame.c (dummy_frame_id) <ptid>: Delete, replaced by ...
	<thread>: ... this new field.  All references adjusted.
	(dummy_frame_pop, dummy_frame_discard, register_dummy_frame_dtor):
	Take a thread_info pointer instead of a ptid_t.
	* dummy-frame.h (dummy_frame_push, dummy_frame_pop)
	(dummy_frame_discard, register_dummy_frame_dtor): Take a
	thread_info pointer instead of a ptid_t.
	* elfread.c: Include "inferior.h".
	(elf_gnu_ifunc_resolver_stop, elf_gnu_ifunc_resolver_return_stop):
	Use inferior_thread.
	* eval.c (evaluate_subexp): Likewise.
	* frame.c (frame_pop, has_stack_frames, find_frame_sal): Use
	inferior_thread.
	* gdb_proc_service.h (struct thread_info): Forward declare.
	(struct ps_prochandle) <ptid>: Delete, replaced by ...
	<thread>: ... this new field.  All references adjusted.
	* gdbarch.h, gdbarch.c: Regenerate.
	* gdbarch.sh (get_syscall_number): Replace 'ptid' parameter with a
	'thread' parameter.  All implementations and callers adjusted.
	* gdbthread.h (thread_info) <set_running>: New method.
	(delete_thread, delete_thread_silent): Take a thread_info pointer
	instead of a ptid.
	(global_thread_id_to_ptid, ptid_to_global_thread_id): Delete.
	(first_thread_of_process): Delete, replaced by ...
	(first_thread_of_inferior): ... this new function.  All callers
	adjusted.
	(any_live_thread_of_process): Delete, replaced by ...
	(any_live_thread_of_inferior): ... this new function.  All callers
	adjusted.
	(switch_to_thread, switch_to_no_thread): Declare.
	(is_executing): Delete.
	(enable_thread_stack_temporaries): Update comment.
	<enable_thread_stack_temporaries>: Take a thread_info pointer
	instead of a ptid_t.  Incref the thread.
	<~enable_thread_stack_temporaries>: Decref the thread.
	<m_ptid>: Delete
	<m_thr>: New.
	(thread_stack_temporaries_enabled_p, push_thread_stack_temporary)
	(get_last_thread_stack_temporary)
	(value_in_thread_stack_temporaries, can_access_registers_thread):
	Take a thread_info pointer instead of a ptid_t.  All callers
	adjusted.
	* infcall.c (get_call_return_value): Use inferior_thread.
	(run_inferior_call): Work with thread pointers instead of ptid_t.
	(call_function_by_hand_dummy): Work with thread pointers instead
	of ptid_t.  Use thread_info_ref.
	* infcmd.c (proceed_thread_callback): Access thread's state
	directly.
	(ensure_valid_thread, ensure_not_running): Use inferior_thread,
	access thread's state directly.
	(continue_command): Use inferior_thread.
	(info_program_command): Use find_thread_ptid and access thread
	state directly.
	(proceed_after_attach_callback): Use thread state directly.
	(notice_new_inferior): Take a thread_info pointer instead of a
	ptid_t.  All callers adjusted.
	(exit_inferior): Take an inferior pointer instead of a pid.  All
	callers adjusted.
	(exit_inferior_silent): New.
	(detach_inferior): Delete.
	(valid_gdb_inferior_id, pid_to_gdb_inferior_id)
	(gdb_inferior_id_to_pid, in_inferior_list): Delete.
	(detach_inferior_command, kill_inferior_command): Use
	find_inferior_id instead of valid_gdb_inferior_id and
	gdb_inferior_id_to_pid.
	(inferior_command): Use inferior and thread pointers.
	* inferior.h (struct thread_info): Forward declare.
	(notice_new_inferior): Take a thread_info pointer instead of a
	ptid_t.  All callers adjusted.
	(detach_inferior): Delete declaration.
	(exit_inferior, exit_inferior_silent): Take an inferior pointer
	instead of a pid.  All callers adjusted.
	(gdb_inferior_id_to_pid, pid_to_gdb_inferior_id, in_inferior_list)
	(valid_gdb_inferior_id): Delete.
	* infrun.c (follow_fork_inferior, proceed_after_vfork_done)
	(handle_vfork_child_exec_or_exit, follow_exec): Adjust.
	(struct displaced_step_inferior_state) <pid>: Delete, replaced by
	...
	<inf>: ... this new field.
	<step_ptid>: Delete, replaced by ...
	<step_thread>: ... this new field.
	(get_displaced_stepping_state): Take an inferior pointer instead
	of a pid.  All callers adjusted.
	(displaced_step_in_progress_any_inferior): Adjust.
	(displaced_step_in_progress_thread): Take a thread pointer instead
	of a ptid_t.  All callers adjusted.
	(displaced_step_in_progress, add_displaced_stepping_state): Take
	an inferior pointer instead of a pid.  All callers adjusted.
	(get_displaced_step_closure_by_addr): Adjust.
	(remove_displaced_stepping_state): Take an inferior pointer
	instead of a pid.  All callers adjusted.
	(displaced_step_prepare_throw, displaced_step_prepare)
	(displaced_step_fixup): Take a thread pointer instead of a ptid_t.
	All callers adjusted.
	(start_step_over): Adjust.
	(infrun_thread_ptid_changed): Remove bit updating ptids in the
	displaced step queue.
	(do_target_resume): Adjust.
	(fetch_inferior_event): Use inferior_thread.
	(context_switch, get_inferior_stop_soon): Take an
	execution_control_state pointer instead of a ptid_t.  All callers
	adjusted.
	(switch_to_thread_cleanup): Delete.
	(stop_all_threads): Use scoped_restore_current_thread.
	* inline-frame.c: Include "gdbthread.h".
	(inline_state) <inline_state>: Take a thread pointer instead of a
	ptid_t.  All callers adjusted.
	<ptid>: Delete, replaced by ...
	<thread>: ... this new field.
	(find_inline_frame_state): Take a thread pointer instead of a
	ptid_t.  All callers adjusted.
	(skip_inline_frames, step_into_inline_frame)
	(inline_skipped_frames, inline_skipped_symbol): Take a thread
	pointer instead of a ptid_t.  All callers adjusted.
	* inline-frame.h (skip_inline_frames, step_into_inline_frame)
	(inline_skipped_frames, inline_skipped_symbol): Likewise.
	* linux-fork.c (delete_checkpoint_command): Adjust to use thread
	pointers directly.
	* linux-nat.c (get_detach_signal): Likewise.
	* linux-thread-db.c (thread_from_lwp): New 'stopped' parameter.
	(thread_db_notice_clone): Adjust.
	(thread_db_find_new_threads_silently)
	(thread_db_find_new_threads_2, thread_db_find_new_threads_1): Take
	a thread pointer instead of a ptid_t.  All callers adjusted.
	* mi/mi-cmd-var.c: Include "inferior.h".
	(mi_cmd_var_update_iter): Update to use thread pointers.
	* mi/mi-interp.c (mi_new_thread): Update to use the thread's
	inferior directly.
	(mi_output_running_pid, mi_inferior_count): Delete, bits factored
	out to ...
	(mi_output_running): ... this new function.
	(mi_on_resume_1): Adjust to use it.
	(mi_user_selected_context_changed): Adjust to use inferior_thread.
	* mi/mi-main.c (proceed_thread): Adjust to use thread pointers
	directly.
	(interrupt_thread_callback): : Adjust to use thread and inferior
	pointers.
	* proc-service.c: Include "gdbthread.h".
	(ps_pglobal_lookup): Adjust to use the thread's inferior directly.
	* progspace-and-thread.c: Include "inferior.h".
	* progspace.c: Include "inferior.h".
	* python/py-exitedevent.c (create_exited_event_object): Adjust to
	hold a reference to an inferior_object.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Adjust to use
	inferior_thread.
	* python/py-inferior.c (struct inferior_object): Give the type a
	tag name instead of a typedef.
	(python_on_normal_stop): No need to check if the current thread is
	listed.
	(inferior_to_inferior_object): Change return type to
	inferior_object.  All callers adjusted.
	(find_thread_object): Delete, bits factored out to ...
	(thread_to_thread_object): ... this new function.
	* python/py-infthread.c (create_thread_object): Use
	inferior_to_inferior_object.
	(thpy_is_stopped): Use thread pointer directly.
	(gdbpy_selected_thread): Use inferior_thread.
	* python/py-record-btrace.c (btpy_list_object) <ptid>: Delete
	field, replaced with ...
	<thread>: ... this new field.  All users adjusted.
	(btpy_insn_or_gap_new): Drop const.
	(btpy_list_new): Take a thread pointer instead of a ptid_t.  All
	callers adjusted.
	* python/py-record.c: Include "gdbthread.h".
	(recpy_insn_new, recpy_func_new): Take a thread pointer instead of
	a ptid_t.  All callers adjusted.
	(gdbpy_current_recording): Use inferior_thread.
	* python/py-record.h (recpy_record_object) <ptid>: Delete
	field, replaced with ...
	<thread>: ... this new field.  All users adjusted.
	(recpy_element_object) <ptid>: Delete
	field, replaced with ...
	<thread>: ... this new field.  All users adjusted.
	(recpy_insn_new, recpy_func_new): Take a thread pointer instead of
	a ptid_t.  All callers adjusted.
	* python/py-threadevent.c: Include "gdbthread.h".
	(get_event_thread): Use thread_to_thread_object.
	* python/python-internal.h (struct inferior_object): Forward
	declare.
	(find_thread_object, find_inferior_object): Delete declarations.
	(thread_to_thread_object, inferior_to_inferior_object): New
	declarations.
	* record-btrace.c: Include "inferior.h".
	(require_btrace_thread): Use inferior_thread.
	(record_btrace_frame_sniffer)
	(record_btrace_tailcall_frame_sniffer): Use inferior_thread.
	(get_thread_current_frame): Use scoped_restore_current_thread and
	switch_to_thread.
	(get_thread_current_frame): Use thread pointer directly.
	(record_btrace_replay_at_breakpoint): Use thread's inferior
	pointer directly.
	* record-full.c: Include "inferior.h".
	* regcache.c: Include "gdbthread.h".
	(get_thread_arch_regcache): Use the inferior's address space
	directly.
	(get_thread_regcache, registers_changed_thread): New.
	* regcache.h (get_thread_regcache(thread_info *thread)): New
	overload.
	(registers_changed_thread): New.
	(remote_target) <remote_detach_1>: Swap order of parameters.
	(remote_add_thread): <remote_add_thread>: Return the new thread.
	(get_remote_thread_info(ptid_t)): New overload.
	(remote_target::remote_notice_new_inferior): Use thread pointers
	directly.
	(remote_target::process_initial_stop_replies): Use
	thread_info::set_running.
	(remote_target::remote_detach_1, remote_target::detach)
	(extended_remote_target::detach): Adjust.
	* stack.c (frame_show_address): Use inferior_thread.
	* target-debug.h (target_debug_print_thread_info_pp): New.
	* target-delegates.c: Regenerate.
	* target.c (default_thread_address_space): Delete.
	(memory_xfer_partial_1): Use current_inferior.
	(target_detach): Use current_inferior.
	(target_thread_address_space): Delete.
	(generic_mourn_inferior): Use current_inferior.
	* target.h (struct target_ops) <thread_address_space>: Delete.
	(target_thread_address_space): Delete.
	* thread.c (init_thread_list): Use ALL_THREADS_SAFE.  Use thread
	pointers directly.
	(delete_thread_1, delete_thread, delete_thread_silent): Take a
	thread pointer instead of a ptid_t.  Adjust all callers.
	(ptid_to_global_thread_id, global_thread_id_to_ptid): Delete.
	(first_thread_of_process): Delete, replaced by ...
	(first_thread_of_inferior): ... this new function.  All callers
	adjusted.
	(any_thread_of_process): Rename to ...
	(any_thread_of_inferior): ... this, and take an inferior pointer.
	(any_live_thread_of_process): Rename to ...
	(any_live_thread_of_inferior): ... this, and take an inferior
	pointer.
	(thread_stack_temporaries_enabled_p, push_thread_stack_temporary)
	(value_in_thread_stack_temporaries)
	(get_last_thread_stack_temporary): Take a thread pointer instead
	of a ptid_t.  Adjust all callers.
	(thread_info::set_running): New.
	(validate_registers_access): Use inferior_thread.
	(can_access_registers_ptid): Rename to ...
	(can_access_registers_thread): ... this, and take a thread
	pointer.
	(print_thread_info_1): Adjust to compare thread pointers instead
	of ptids.
	(switch_to_no_thread, switch_to_thread): Make extern.
	(scoped_restore_current_thread::~scoped_restore_current_thread):
	Use m_thread pointer directly.
	(scoped_restore_current_thread::scoped_restore_current_thread):
	Use inferior_thread.
	(thread_command): Use thread pointer directly.
	(thread_num_make_value_helper): Use inferior_thread.
	* top.c (execute_command): Use inferior_thread.
	* tui/tui-interp.c: Include "inferior.h".
	* varobj.c (varobj_create): Use inferior_thread.
	(value_of_root_1): Use find_thread_global_id instead of
	global_thread_id_to_ptid.
2018-06-21 17:09:31 +01:00
Tom Tromey 0d0b0ea29a Fix a memory leak in py-param.c
Mark Wielaard pointed out this memory leak to me:

    ==17633== 775 bytes in 1 blocks are definitely lost in loss record 13,346 of 13,967
    ==17633==    at 0x4C2DB6B: malloc (vg_replace_malloc.c:299)
    ==17633==    by 0x6652B7: xmalloc (common-utils.c:45)
    ==17633==    by 0xC4C889: xstrdup (xstrdup.c:34)
    ==17633==    by 0x5A71FD: unicode_to_encoded_string(_object*, char const*) (py-utils.c:81)
    ==17633==    by 0x5A73EB: python_string_to_host_string(_object*) (py-utils.c:158)
    ==17633==    by 0x59CC6C: get_doc_string(_object*, _object*) (py-param.c:334)
    ==17633==    by 0x59D2AA: parmpy_init(_object*, _object*, _object*) (py-param.c:728)

The bug here is that parmpy_init is written as though
add_setshow_generic takes ownership of its doc-string arguments.
However, it does not.  This patch fixes the bug in a straightforward
way and also applies some missing constification to make the problem
more apparent.

Tested on x86-64 Fedora 26.

gdb/ChangeLog
2018-06-20  Tom Tromey  <tom@tromey.com>

	* python/py-param.c (add_setshow_generic): Make parameters const.
	(parmpy_init): Update.
2018-06-20 21:10:10 -06:00
Tom Tromey b4be9fadea Use unique_xmalloc_ptr for read_string
This changes read_string's "buffer" out-parameter to be a
unique_xmalloc_ptr, then updates the users.  This allows for the
removal of some cleanups.

I chose unique_xmalloc_ptr rather than byte_vector here due to the way
Guile unwinding seems to work.

Tested by the buildbot.

gdb/ChangeLog
2018-06-18  Tom Tromey  <tom@tromey.com>

	* valprint.h (read_string): Update.
	* valprint.c (read_string): Change type of "buffer".
	(val_print_string): Update.
	* python/py-value.c (valpy_string): Update.
	* language.h (struct language_defn) <la_get_string>: Change
	type of "buffer".
	(default_get_string, c_get_string): Update.
	* language.c (default_get_string): Change type of "buffer".
	* guile/scm-value.c (gdbscm_value_to_string): Update.
	* c-lang.c (c_get_string): Change type of "buffer".
2018-06-18 12:51:02 -06:00
Paul Koning aeab512851 Fix build issue with Python 3.7
Originally reported in
https://bugzilla.redhat.com/show_bug.cgi?id=1577396 -- gdb build fails
with Python 3.7 due to references to a Python internal function whose
declaration changed in 3.7.

gdb/ChangeLog
2018-06-08  Paul Koning  <paul_koning@dell.com>

	    PR gdb/23252

	    * python/python.c (do_start_initialization):
	    Avoid call to internal Python API.
	    (init__gdb_module): New function.
2018-06-08 13:32:03 -04:00
Tom Tromey 3513a6bb20 Remove a static buffer from cp-name-parser.y
This removes a static buffer from cp-name-parser.y by replacing the
fixed-sized buffer with a std::string out parameter.

gdb/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* python/py-type.c (typy_legacy_template_argument): Update.
	* cp-support.h (cp_demangled_name_to_comp): Update.
	* cp-name-parser.y (cp_demangled_name_to_comp): Change errmsg
	parameter to be a "std::string *".
	(main): Update.
2018-06-01 10:46:47 -06:00
Tom Tromey e86ca25fd6 Remove TYPE_TAG_NAME
TYPE_TAG_NAME has been an occasional source of confusion and bugs.  It
seems to me that it is only useful for C and C++ -- but even there,
not so much, because at least with DWARF there doesn't seem to be any
way to wind up with a type where the name and the tag name are both
non-NULL and different.

So, this patch removes TYPE_TAG_NAME entirely.  This should save a
little memory, but more importantly, it simplifies this part of gdb.

A few minor test suite adjustments were needed.  In some situations
the new code does not yield identical output to the old code.

gdb/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* valops.c (enum_constant_from_type, value_namespace_elt)
	(value_maybe_namespace_elt): Update.
	* valarith.c (find_size_for_pointer_math): Update.
	* target-descriptions.c (make_gdb_type): Update.
	* symmisc.c (print_symbol): Update.
	* stabsread.c (define_symbol, read_type)
	(complain_about_struct_wipeout, add_undefined_type)
	(cleanup_undefined_types_1): Update.
	* rust-lang.c (rust_tuple_type_p, rust_slice_type_p)
	(rust_range_type_p, val_print_struct, rust_print_struct_def)
	(rust_internal_print_type, rust_composite_type)
	(rust_evaluate_funcall, rust_evaluate_subexp)
	(rust_inclusive_range_type_p): Update.
	* python/py-type.c (typy_get_tag): Update.
	* p-typeprint.c (pascal_type_print_base): Update.
	* mdebugread.c (parse_symbol, parse_type): Update.
	* m2-typeprint.c (m2_long_set, m2_record_fields, m2_enum):
	Update.
	* guile/scm-type.c (gdbscm_type_tag): Update.
	* go-lang.c (sixg_string_p): Update.
	* gnu-v3-abi.c (build_gdb_vtable_type, build_std_type_info_type):
	Update.
	* gdbtypes.h (struct main_type) <tag_name>: Remove.
	(TYPE_TAG_NAME): Remove.
	* gdbtypes.c (type_name_no_tag): Simplify.
	(check_typedef, check_types_equal, recursive_dump_type)
	(copy_type_recursive, arch_composite_type): Update.
	* f-typeprint.c (f_type_print_base): Update.  Print "Type" prefix
	in summary mode when needed.
	* eval.c (evaluate_funcall): Update.
	* dwarf2read.c (fixup_go_packaging, read_structure_type)
	(process_structure_scope, read_enumeration_type)
	(read_namespace_type, read_module_type, determine_prefix): Update.
	* cp-support.c (inspect_type): Update.
	* coffread.c (process_coff_symbol, decode_base_type): Update.
	* c-varobj.c (c_is_path_expr_parent): Update.
	* c-typeprint.c (c_type_print_base_struct_union): Update.
	(c_type_print_base_1): Update.  Print struct/class/union/enum in
	summary when using C language.
	* ax-gdb.c (gen_struct_ref, gen_namespace_elt)
	(gen_maybe_namespace_elt): Update.
	* ada-lang.c (ada_type_name): Simplify.
	(empty_record, ada_template_to_fixed_record_type_1)
	(template_to_static_fixed_type)
	(to_record_with_fixed_variant_part, ada_check_typedef): Update.

gdb/testsuite/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* gdb.xml/tdesc-regs.exp (load_description): Update expected
	results.
	* gdb.dwarf2/method-ptr.exp: Set language to C++.
	* gdb.dwarf2/member-ptr-forwardref.exp: Set language to C++.
	* gdb.cp/typeid.exp (do_typeid_tests): Update type_re.
	* gdb.base/maint.exp (maint_pass_if): Update.
2018-06-01 10:19:55 -06:00
Tom Tromey 984ee559a2 Fix "set" handling of Python parameters
It's long bothered me that setting a Python parameter from the CLI
will print the "set" help text by default.  I think usually "set"
commands should be silent.  And, while you can modify this behavior a
bit by providing a "get_set_string" method, if this method returns an
empty string, a blank line will be printed.

This patch removes the "help" behavior and changes the get_set_string
behavior to avoid printing a blank line.  The code has a comment about
preserving API behavior, but I don't think this is truly important;
and in any case the workaround -- implementing get_set_string -- is
trivial.

Regression tested on x86-64 Fedora 26.

2018-04-26  Tom Tromey  <tom@tromey.com>

	* NEWS: Mention new "set" behavior.
	* python/py-param.c (get_set_value): Don't print an empty string.
	Don't call get_doc_string.

gdb/doc/ChangeLog
2018-04-26  Tom Tromey  <tom@tromey.com>

	* python.texi (Parameters In Python): Update get_set_string
	documentation.
2018-05-31 15:02:01 -06:00
Tom Tromey 7729052b53 Add basic Python API for convenience variables
This adds a basic Python API for accessing convenience variables.
With this, convenience variables can be read and set from Python.
Although gdb supports convenience variables whose value changes at
each call, this is not exposed to Python; it could be, but I think
it's just as good to write a convenience function in this situation.

This is PR python/23080.

Tested on x86-64 Fedora 26.

2018-04-22  Tom Tromey  <tom@tromey.com>

	PR python/23080:
	* NEWS: Update for new functions.
	* python/py-value.c (gdbpy_set_convenience_variable)
	(gdbpy_convenience_variable): New functions.
	* python/python-internal.h (gdbpy_convenience_variable)
	(gdbpy_set_convenience_variable): Declare.
	* python/python.c (python_GdbMethods): Add convenience_variable,
	set_convenience_variable.

doc/ChangeLog
2018-04-22  Tom Tromey  <tom@tromey.com>

	PR python/23080:
	* python.texi (Basic Python): Document gdb.convenience_variable,
	gdb.set_convenience_variable.

testsuite/ChangeLog
2018-04-22  Tom Tromey  <tom@tromey.com>

	PR python/23080:
	* gdb.python/python.exp: Add convenience variable tests.
2018-05-31 15:00:40 -06:00
Tom Tromey 894882e344 Remove a VEC from type.c
This removes a VEC from type.c, by using std::vector.

While doing this I also took the opportunity to change
types_deeply_equal to return bool.  This caught some weird code in
typy_richcompare, now fixed.

And, since I was changing types_deeply_equal, it seemed like a good
idea to also change types_equal, so this patch includes that as well.

Tested by the buildbot.

ChangeLog
2018-05-29  Tom Tromey  <tom@tromey.com>

	* python/py-type.c (typy_richcompare): Update.
	* guile/scm-type.c (tyscm_equal_p_type_smob): Update.
	* gdbtypes.h (types_deeply_equal): Return bool.
	(types_equal): Likewise.
	* gdbtypes.c (type_equality_entry_d): Remove typedef.  Don't
	declare VEC.
	(check_types_equal): Change worklist to std::vector.  Return
	bool.
	(struct type_equality_entry): Add constructor.
	(compare_maybe_null_strings): Return bool.
	(check_types_worklist): Return bool.  Change worklist to
	std::vector.
	(types_deeply_equal): Use std::vector.
	(types_equal): Return bool.
	(compare_maybe_null_strings): Simplify.
2018-05-29 11:44:12 -06:00
Tom Tromey 29f9434081 Remove interp_ui_out
The function interp_ui_out simply calls the interp_ui_out method.
However, if it is passed a NULL interpreter, it first finds the
current interpreter.  I believe, though, that NULL is never passed
here, and I think it's simpler to just remove this function and
require callers to be more explicit.

ChangeLog
2018-05-25  Tom Tromey	<tom@tromey.com>

	* utils.c (fputs_maybe_filtered): Update.
	* linespec.c (decode_line_full): Update.
	* mi/mi-interp.c (mi_on_normal_stop_1, mi_tsv_modified)
	(mi_print_breakpoint_for_event, mi_solib_loaded)
	(mi_solib_unloaded, mi_command_param_changed, mi_memory_changed)
	(mi_user_selected_context_changed): Update.
	* mi/mi-main.c (mi_execute_command): Update.
	* cli/cli-script.c (execute_control_command): Update.
	* python/python.c (execute_gdb_command): Update.
	* solib.c (info_sharedlibrary_command): Update.
	* interps.c (interp_ui_out): Remove.
	* interps.h (interp_ui_out): Remove.
2018-05-25 12:41:01 -06:00
Tom Tromey 56bcdbea2b Let gdb.execute handle multi-line commands
This changes the Python API so that gdb.execute can now handle
multi-line commands, like "commands" or "define".

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22730:
	* NEWS: Mention gdb.execute change.
	* gdbcmd.h (execute_control_command): Don't declare.
	* python/python.c (execute_gdb_command): Use read_command_lines_1,
	execute_control_commands, execute_control_commands_to_string.
	* cli/cli-script.h (execute_control_commands)
	(execute_control_commands_to_string): Declare.
	(execute_control_command): Add from_tty parameter.
	* cli/cli-script.c (execute_control_commands)
	(execute_control_commands_to_string): New functions.
	(execute_user_command): Use execute_control_commands.
	(execute_control_command_1): Add "from_tty" parameter.  Update.
	(execute_control_command): Likewise.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22730:
	* gdb.python/python.exp: Test multi-line execute.
2018-05-04 15:58:09 -06:00
Tom Tromey a913fffbde Allow breakpoint commands to be set from Python
This changes the Python API so that breakpoint commands can be set by
writing to the "commands" attribute.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* NEWS: Mention that breakpoint commands are writable.
	* python/py-breakpoint.c (bppy_set_commands): New function.
	(breakpoint_object_getset) <"commands">: Use it.

doc/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* python.texi (Breakpoints In Python): Mention that "commands" is
	writable.

testsuite/ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	PR python/22731:
	* gdb.python/py-breakpoint.exp: Test setting breakpoint commands.
2018-05-04 15:58:09 -06:00
Tom Tromey 12973681f5 Use counted_command_line everywhere
Currently command lines are reference counted using shared_ptr only
when attached to breakpoints.  This patch changes gdb to use
shared_ptr in commands as well.  This allows for the removal of
copy_command_lines.

Note that the change to execute_user_command explicitly makes a new
reference to the command line.  This will be used in a later patch.

This simplifies struct command_line based on the observation that a
given command can have at most two child bodies: an "if" can have both
"then" and "else" parts.  Perhaps the names I've chosen for the
replacements here are not very good -- your input requested.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (all_tracepoint_actions): Rename from
	all_tracepoint_actions_and_cleanup.  Change return type.
	(actions_command, encode_actions_1, encode_actions)
	(trace_dump_actions, tdump_command): Update.
	* remote.c (remote_download_command_source): Update.
	* python/python.c (gdbpy_eval_from_control_command)
	(python_command, python_interactive_command): Update.
	* mi/mi-cmd-break.c (mi_cmd_break_commands): Update.
	* guile/guile.c (guile_command)
	(gdbscm_eval_from_control_command, guile_command): Update.
	* compile/compile.c (compile_code_command)
	(compile_print_command, compile_to_object): Update.
	* cli/cli-script.h (struct command_lines_deleter): New.
	(counted_command_line): New typedef.
	(struct command_line): Add constructor, destructor.
	<body_list>: Remove.
	<body_list_0, body_list_1>: New members.
	(command_line_up): Remove typedef.
	(read_command_lines, read_command_lines_1, get_command_line):
	Update.
	(copy_command_lines): Don't declare.
	* cli/cli-script.c (build_command_line): Use "new".
	(get_command_line): Return counted_command_line.
	(print_command_lines, execute_user_command)
	(execute_control_command_1, while_command, if_command): Update.
	(realloc_body_list): Remove.
	(process_next_line, recurse_read_control_structure): Update.
	(read_command_lines, read_command_lines_1): Return counted_command_line.
	(free_command_lines): Use "delete".
	(copy_command_lines): Remove.
	(define_command, document_command, show_user_1): Update.
	* cli/cli-decode.h (struct cmd_list_element) <user_commands>: Now
	a counted_command_line.
	* breakpoint.h (counted_command_line): Remove typedef.
	(breakpoint_set_commands): Update.
	* breakpoint.c (check_no_tracepoint_commands)
	(validate_commands_for_breakpoint): Update.
	(breakpoint_set_commands): Change commands to be a
	counted_command_line.
	(commands_command_1, update_dprintf_command_list)
	(create_tracepoint_from_upload): Update.
2018-05-04 15:58:06 -06:00
Paul Pluzhnikov bf27f0e2c7 configure uses incorrect link order when testing libpython
References:

https://stackoverflow.com/a/49868387
https://sourceware.org/bugzilla/show_bug.cgi?id=11420

Configure uses "gcc -o conftest -g ... conftest.c -ldl -lncurses -lm -ldl
... -lpthread ... -lpython2.7" when deciding whether give libpython is
usable.

That of course is the wrong link order, and only works for shared libraries
(mostly by accident), and only on some systems.

gdb/ChangeLog:

	PR gdb/11420
	* configure.ac: Prepend libpython.
	* python/python-config.py: Likewise.
	* configure: Regenerate.
2018-05-04 10:08:09 -04:00
Tom Tromey 0489430a0e Handle var_zuinteger and var_zuinteger_unlimited from Python
PR python/20084 points out that the Python API doesn't handle the
var_zuinteger and var_zuinteger_unlimited parameter types.

This patch adds support for these types.

Regression tested on x86-64 Fedora 26.

ChangeLog
2018-05-02  Tom Tromey  <tom@tromey.com>

	PR python/20084:
	* python/python.c (gdbpy_parameter_value): Handle var_zuinteger
	and var_zuinteger_unlimited.
	* python/py-param.c (struct parm_constant): Add PARAM_ZUINTEGER
	and PARAM_ZUINTEGER_UNLIMITED.
	(set_parameter_value): Handle var_zuinteger and
	var_zuinteger_unlimited.
	(add_setshow_generic): Likewise.
	(parmpy_init): Likewise.

doc/ChangeLog
2018-05-02  Tom Tromey  <tom@tromey.com>

	PR python/20084:
	* python.texi (Parameters In Python): Document PARAM_ZUINTEGER and
	PARAM_ZUINTEGER_UNLIMITED.

testsuite/ChangeLog
2018-05-02  Tom Tromey  <tom@tromey.com>

	PR python/20084:
	* gdb.python/py-parameter.exp: Add PARAM_ZUINTEGER and
	PARAM_ZUINTEGER_UNLIMITED tests.
2018-05-02 10:31:55 -06:00
Tom Tromey 2038b7fdf3 Remove some uses of is_mi_like_p from py-framefilter.c
Some uses of is_mi_like_p in py-framefilter.c were not needed.  In
general a call to ui_out::text, ui_out::message, or ui_out::spaces
does not need to be guarded -- these are already ignored by MI.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (py_print_single_arg)
	(enumerate_locals, py_print_args, py_print_frame): Remove some
	uses of is_mi_like_p.
2018-04-30 12:59:04 -06:00
Tom Tromey 7c66fffc1f Change Python code to use new_reference
This changes a few spots in the Python code to use new_reference
rather than the manual incref+constructor that was previously being
done.

ChangeLog
2018-04-30  Tom Tromey  <tom@tromey.com>

	* varobj.c (varobj_set_visualizer): Use new_reference.
	* python/python.c (gdbpy_decode_line): Use new_reference.
	* python/py-cmd.c (cmdpy_function, cmdpy_completer_helper): Use
	new_reference.
2018-04-30 11:33:12 -06:00
Tom Tromey 6d7bb8246b Expose type alignment on gdb.Type
This adds an "alignof" attribute to gdb.Type in the Python API.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* NEWS: Mention Type.align.
	* python/py-type.c (typy_get_alignof): New function.
	(type_object_getset): Add "alignof".

2018-04-30  Tom Tromey  <tom@tromey.com>

	* python.texi (Types In Python): Document Type.align.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* gdb.python/py-type.exp: Check align attribute.
	* gdb.python/py-type.c: New "aligncheck" global.
2018-04-30 11:25:31 -06:00
Markus Metzger 4a4495d62d btrace: set/show record btrace cpu
Add new set/show commands to set the processor that is used for enabling
errata workarounds when decoding branch trace.

The general format is "<vendor>:<identifier>" but we also allow two
special values "auto" and "none".

The default is "auto", which is the current behaviour of having GDB
determine the processor on which the trace was recorded.

If that cpu is not known to the trace decoder, e.g. when using an old
decoder on a new system, decode may fail with "unknown cpu".  In most
cases it should suffice to 'downgrade' decode to assume an older cpu.
Unfortunately, we can't do this automatically.

The other special value, "none", disables errata workarounds.

gdb/
	* NEWS (New options): announce set/show record btrace cpu.
	* btrace.c: Include record-btrace.h.
	(btrace_compute_ftrace_pt): Skip enabling errata workarounds if
	the vendor is unknown.
	(btrace_compute_ftrace_1): Add cpu parameter.  Update callers.
	Maybe overwrite the btrace configuration's cpu.
	(btrace_compute_ftrace): Add cpu parameter.  Update callers.
	(btrace_fetch): Add cpu parameter.  Update callers.
	(btrace_maint_update_pt_packets): Call record_btrace_get_cpu.
	Maybe overwrite the btrace configuration's cpu.  Skip enabling
	errata workarounds if the vendor is unknown.
	* python/py-record-btrace.c: Include record-btrace.h.
	(recpy_bt_begin, recpy_bt_end, recpy_bt_instruction_history)
	(recpy_bt_function_call_history): Call record_btrace_get_cpu.
	* record-btrace.c (record_btrace_cpu_state_kind): New.
	(record_btrace_cpu): New.
	(set_record_btrace_cpu_cmdlist): New.
	(record_btrace_get_cpu): New.
	(require_btrace_thread, record_btrace_info)
	(record_btrace_resume_thread): Call record_btrace_get_cpu.
	(cmd_set_record_btrace_cpu_none): New.
	(cmd_set_record_btrace_cpu_auto): New.
	(cmd_set_record_btrace_cpu): New.
	(cmd_show_record_btrace_cpu): New.
	(_initialize_record_btrace): Initialize set/show record btrace cpu
	commands.
	* record-btrace.h (record_btrace_get_cpu): New.

testsuite/
	* gdb.btrace/cpu.exp: New.

doc/
	* gdb.texinfo: Document set/show record btrace cpu.
2018-04-13 11:35:55 +02:00
Tom Tromey 22bc8444e6 Introduce a gdb_ref_ptr specialization for struct value
struct value is internally reference counted and so, while it also has
some ownership rules unique to it, it makes sense to use a gdb_ref_ptr
when managing it automatically.

This patch removes the existing unique_ptr specialization in favor of
a reference-counted pointer.  It also introduces two other
clarifications:

1. Rename value_free to value_decref, which I think is more in line
   with what the function actually does; and

2. Change release_value to return a gdb_ref_ptr.  This change allows
   us to remove the confusing release_value_or_incref function,
   primarily by making it much simpler to reason about the result of
   release_value.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

	* varobj.c (varobj_clear_saved_item)
	(update_dynamic_varobj_children, install_new_value, ~varobj):
	Update.
	* value.h (value_incref): Move declaration earlier.
	(value_decref): Rename from value_free.
	(struct value_ref_policy): New.
	(value_ref_ptr): New typedef.
	(struct value_deleter): Remove.
	(gdb_value_up): Remove typedef.
	(release_value): Change return type.
	(release_value_or_incref): Remove.
	* value.c (set_value_parent): Update.
	(value_incref): Change return type.
	(value_decref): Rename from value_free.
	(value_free_to_mark, free_all_values, free_value_chain): Update.
	(release_value): Return value_ref_ptr.
	(release_value_or_incref): Remove.
	(record_latest_value, set_internalvar, clear_internalvar):
	Update.
	* stack.c (info_frame_command): Don't call value_free.
	* python/py-value.c (valpy_dealloc, valpy_new)
	(value_to_value_object): Update.
	* printcmd.c (do_examine): Update.
	* opencl-lang.c (lval_func_free_closure): Update.
	* mi/mi-main.c (register_changed_p): Don't call value_free.
	* mep-tdep.c (mep_frame_prev_register): Don't call value_free.
	* m88k-tdep.c (m88k_frame_prev_register): Don't call value_free.
	* m68hc11-tdep.c (m68hc11_frame_prev_register): Don't call
	value_free.
	* guile/scm-value.c (vlscm_free_value_smob)
	(vlscm_scm_from_value): Update.
	* frame.c (frame_register_unwind, frame_unwind_register_signed)
	(frame_unwind_register_unsigned, get_frame_register_bytes)
	(put_frame_register_bytes): Don't call value_free.
	* findvar.c (address_from_register): Don't call value_free.
	* dwarf2read.c (dwarf2_compute_name): Don't call value_free.
	* dwarf2loc.c (entry_data_value_free_closure)
	(value_of_dwarf_reg_entry, free_pieced_value_closure)
	(dwarf2_evaluate_loc_desc_full): Update.
	* breakpoint.c (update_watchpoint, breakpoint_init_inferior)
	(~bpstats, bpstats, bpstat_clear_actions, watchpoint_check)
	(~watchpoint, watch_command_1)
	(invalidate_bp_value_on_memory_change): Update.
	* alpha-tdep.c (alpha_register_to_value): Don't call value_free.
2018-04-06 15:44:46 -06:00
Tom Tromey 76c939acfd Simplify exception handling in py-framefilter.c
This patch changes py-framefilter.c as suggested by Pedro in:
https://sourceware.org/ml/gdb-patches/2017-06/msg00748.html

In particular, gdb exceptions are now caught at the outermost layer,
rather than in each particular function.  This simplifies much of the
code.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (py_print_type): Don't catch
	exceptions.  Return void.
	(py_print_value): Likewise.
	(py_print_single_arg): Likewise.
	(enumerate_args): Don't catch exceptions.
	(py_print_args): Likewise.
	(py_print_frame): Likewise.
	(gdbpy_apply_frame_filter): Catch exceptions here.
2018-03-26 21:57:14 -06:00
Tom Tromey eb68e48764 Call wrap_hint in one more spot in py-framefilter.c
PR python/16486 notes that "bt" output is still wrapped differently
when a frame filter is in use.  This patch brings it a bit closer by
adding one more wrap_hint call, in a place where stack.c does this as
well.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	PR python/16486:
	* python/py-framefilter.c (py_print_args): Call wrap_hint.
2018-03-26 21:57:14 -06:00
Tom Tromey 1f111921a0 Return EXT_LANG_BT_ERROR in one more spot in py-framefilter.c
While reading py-framefilter.c, I found one spot where an exception
could be caught but then not be turned into EXT_LANG_BT_ERROR.  This
patch fixes this spot.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (py_print_single_arg): Return
	EXT_LANG_BT_ERROR from catch.
2018-03-26 21:57:13 -06:00
Tom Tromey 4ca59a9f36 Throw a "quit" on a KeyboardException in py-framefilter.c
If a C-c comes while the Python code for a frame filter is running, it
will be turned into a Python KeyboardException.  It seems good for
this to be treated like a GDB quit, so this patch changes
py-framefilter.c to notice this situation and call throw_quit in this
case.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (throw_quit_or_print_exception): New
	function.
	(gdbpy_apply_frame_filter): Use it.

gdb/testsuite/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	* gdb.python/py-framefilter.exp: Add test for KeyboardInterrupt.
	* gdb.python/py-framefilter.py (name_error): New global.
	(ErrorInName.function): Use name_error.
2018-03-26 21:57:12 -06:00
Tom Tromey 92256134f3 Allow C-c to work in backtrace in more cases
PR cli/17716 notes that it is difficult to C-c (or "q" at a pagination
prompt) while backtracing using a frame filter.  One reason for this
is that many places in py-framefilter.c use RETURN_MASK_ALL in a
try/catch.

This patch changes these spots to use RETURN_MASK_ERROR instead.  This
is safe to do because this entire file is exception safe now.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	PR cli/17716:
	* python/py-framefilter.c (py_print_type, py_print_value)
	(enumerate_args, py_print_args, gdbpy_apply_frame_filter): Use
	RETURN_MASK_ERROR.
2018-03-26 21:57:12 -06:00
Tom Tromey 7a630bc2f9 Avoid manual resource management in py-framefilter.c
This patch removes the last bit of manual resource management from
py-framefilter.c.  This will be useful in the next patch.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (enumerate_args): Use
	gdb::unique_xmalloc_ptr.
2018-03-26 21:57:11 -06:00
Tom Tromey 63283d4a29 Remove EXT_LANG_BT_COMPLETED
While looking at the frame filter code, I noticed that
EXT_LANG_BT_COMPLETED is not really needed.  Semantically there is no
difference between the "completed" and "ok" results.  So, this patch
removes this constant.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (py_print_frame): Return
	EXT_LANG_BT_OK.
	(gdbpy_apply_frame_filter): Update comment.
	* extension.h (enum ext_lang_bt_status) <EXT_LANG_BT_COMPLETED>:
	Remove.
	<EXT_LANG_BT_NO_FILTERS>: Change value.
2018-03-26 21:57:11 -06:00
Tom Tromey 978d6c756f Allow hiding of some filtered frames
When a frame filter elides some frames, they are still printed by
"bt", indented a few spaces.  PR backtrace/15582 notes that it would
be nice for users if elided frames could simply be dropped.  This
patch adds this capability.

gdb/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	PR backtrace/15582:
	* stack.c (backtrace_command): Parse "hide" argument.
	* python/py-framefilter.c (py_print_frame): Handle PRINT_HIDE.
	* extension.h (enum frame_filter_flags) <PRINT_HIDE>: New
	constant.

gdb/doc/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	PR backtrace/15582:
	* gdb.texinfo (Backtrace): Mention "hide" argument.

gdb/testsuite/ChangeLog
2018-03-26  Tom Tromey  <tom@tromey.com>

	PR backtrace/15582:
	* gdb.python/py-framefilter.exp: Add "bt hide" test.
2018-03-26 21:57:11 -06:00