Commit Graph

39063 Commits

Author SHA1 Message Date
Tom Tromey 0092b74da6 Use ui_out_emit_tuple in more places in MI
This patch changes a few more spots in MI to use ui_out_emit_tuple.
These changes required the use of gdb::optional.

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

	* mi/mi-main.c (print_variable_or_computed): Use ui_out_emit_tuple.
	* mi/mi-cmd-var.c (varobj_update_one): Use ui_out_emit_tuple.
	* mi/mi-cmd-stack.c (list_arg_or_local): Use ui_out_emit_tuple.
2017-04-22 09:47:00 -06:00
Tom Tromey a14a62ddff Use ui_out_emit_tuple in tracepoint.c
This changes some code in tracepoint.c to use ui_out_emit_tuple.  One
of these involved removing an otherwise unrelated cleanup (changing
type to std::string) and the other involved introducing a new block.

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

	* tracepoint.c (tvariables_info_1)
	(print_one_static_tracepoint_marker): Use ui_out_emit_tuple.
2017-04-22 09:46:59 -06:00
Tom Tromey 46b9c12945 More uses of ui_out_emit_tuple
This patch adds a few more uses of ui_out_emit_tuple.  In these cases
a slightly more complicated change was needed.  This also adds
annotate_arg_emitter, for use in stack.c, to avoid having to introduce
a new scope and reindent the code for a single call.

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

	* stack.c (print_frame_arg): Use ui_out_emit_tuple,
	annotate_arg_emitter.
	* breakpoint.c (print_mention_watchpoint)
	(print_mention_masked_watchpoint): Use ui_out_emit_tuple.
	* annotate.h (struct annotate_arg_emitter): New.
2017-04-22 09:46:59 -06:00
Tom Tromey 2e78302469 Use ui_out_emit_tuple
This patch changes various places to use ui_out_emit_tuple,
eliminating a number of cleanups.  This patch only tackles "easy"
cases, which are ones where the cleanups in question were
block-structured and did not involve any changes other than the
obvious replacement.

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

	* record-btrace.c (record_btrace_insn_history)
	(record_btrace_insn_history_range, record_btrace_call_history)
	(record_btrace_call_history_range): Use ui_out_emit_tuple.
	* thread.c (do_captured_list_thread_ids, print_thread_info_1): Use
	ui_out_emit_tuple.
	* stack.c (print_frame_info): Use ui_out_emit_tuple.
	* solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple.
	* skip.c (skip_info): Use ui_out_emit_tuple.
	* remote.c (show_remote_cmd): Use ui_out_emit_tuple.
	* progspace.c (print_program_space): Use ui_out_emit_tuple.
	* probe.c (info_probes_for_ops): Use ui_out_emit_tuple.
	* osdata.c (info_osdata): Use ui_out_emit_tuple.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use
	ui_out_emit_tuple.
	* mi/mi-main.c (print_one_inferior, list_available_thread_groups)
	(output_register, mi_cmd_data_read_memory)
	(mi_cmd_data_read_memory_bytes, mi_load_progress)
	(mi_cmd_trace_frame_collected): Use ui_out_emit_tuple.
	* mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one):
	Use ui_out_emit_tuple.
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use
	ui_out_emit_tuple.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions)
	(mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple.
	* linux-thread-db.c (info_auto_load_libthread_db): Use
	ui_out_emit_tuple.
	* inferior.c (print_inferior): Use ui_out_emit_tuple.
	* gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple.
	* disasm.c (do_mixed_source_and_assembly_deprecated)
	(do_mixed_source_and_assembly): Use ui_out_emit_tuple.
	* cp-abi.c (list_cp_abis): Use ui_out_emit_tuple.
	* cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple.
	* breakpoint.c (print_one_breakpoint_location)
	(print_one_breakpoint): Use ui_out_emit_tuple.
	* auto-load.c (print_script, info_auto_load_cmd): Use
	ui_out_emit_tuple.
	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.
2017-04-22 09:46:58 -06:00
Simon Marchi ebe553db6c doc: Improve documentation about MI thread output
I noticed that the documentation on how the info about threads is output
in MI is duplicated and not up to date.  The duplication is between the
"GDB/MI Thread Information" page and the -thread-info result
description.

I improved the "GDB/MI Thread Information" page a bit and referred to it
in the -thread-info doc.  This way, the -thread-info doc is more precise
(it did not mention the "threads" and "current-thread-id" attributes)
and concise.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Thread Information): Add missing
	fields, re-word some things.
	(GDB/MI Thread Commands): Describe fields found in the output of
	-thread-info, remove description of fields in the
	thread output tuple, replace with a cross-reference to "GDB/MI
	Thread Information".
2017-04-21 21:50:22 -04:00
Simon Marchi 9be21bb4d4 Remove dead code and "current" field from MI thread output doc
The MI documentation says that -thread-info output contains a "current"
field in the current thread tuple, with the value "*".  Current GDB
master does not do this, and I couldn't find any GDB version that did.
I suspect that it was never the case.

The code that would correspond to this in print_thread_info_1 is
essentially dead code.  The calls to uiout->text end up in
mi_out::do_text, which is empty.

This patch removes the documentation bit and the dead code.  This
"current" field is not necessary, since -thread-info outputs a
"current-thread-id" field.

gdb/ChangeLog:

	* thread.c (print_thread_info_1): Remove dead code.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Thread Commands): Remove "current" field
	from -thread-info output.
2017-04-21 21:45:15 -04:00
Jan Kratochvil 0d4c07afb1 release branch: Fix: --enable-werror
gdb-8.0-branch
./configure --enable-werror --enable-targets=all
aarch64-tdep.c:3045:13: error: ‘void selftests::aarch64_process_record_test()’ declared ‘static’ but never defined [-Werror=unused-function]
arm-tdep.c:9601:13: error: ‘void selftests::arm_record_test()’ declared ‘static’ but never defined [-Werror=unused-function]

gdb/ChangeLog
2017-04-21  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* aarch64-tdep.c (selftests::aarch64_process_record_test): Make it #if
	GDB_SELF_TEST.
	* arm-tdep.c (selftests::arm_record_test): Likewise.
2017-04-21 16:14:37 +02:00
Yao Qi 4daf993d4d Simplify regcache_restore
This patches removes the 2nd argument of regcache_restore, because it
is only called by regcache_cpy.  In regcache_cpy, if regcache_restore
is called, dst is not readonly, but src is readonly.  So this patch
adds an assert that src is readonly in regcache_restore.
regcache_cook_read read everything from a readonly regcache cache
(src)'s register_buffer, and register status is from ->register_status.

gdb:

2017-04-21  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache_restore): Remove argument 2.  Replace
	argument 3 with regcache.  Get register status from
	src->register_status and get register contents from
	register_buffer (src, regnum).
	(regcache_cpy): Update.
2017-04-21 14:59:27 +01:00
Pedro Alves a6c21d4a55 gdbthread.h: Fix comment typo
gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (thread): Add missing closing parenthesis in
	comment.
2017-04-19 13:16:05 +01:00
Pedro Alves 3a3fd0fd2c Fix removing inferiors from within "thread apply" commands
This patch fixes an internal error exposed by a test that does
something like:

  define kill-and-remove
    kill inferiors 2
    remove-inferiors 2
  end

  # Start one inferior.
  start

  # Start another inferior.
  add-inferior 2
  inferior 2
  start

  # Kill and remove inferior 1 while inferior 2 is selected.
  thread apply 1.1 kill-and-remove

The internal error looks like this:

 Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)):
 [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)]
 [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))]
 #0  main () at src/gdb/testsuite/gdb.threads/threadapply.c:38
 38          for (i = 0; i < NUM; i++)
 src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error)

There are several problems around this area of the code.  One is that
in do_restore_current_thread_cleanup, we do a look up of inferior by
ptid, which can find the wrong inferior if the previously selected
inferior exited and some other inferior was started with a reused pid
(rare, but still...).

The other problem is that the "remove-inferiors" command rejects
attempts to remove the current inferior, but when we get to
"remove-inferiors" in a "thread apply THR remove-inferiors 2" command,
the current inferior is the inferior of thread THR, not the previously
selected inferior, so if the previously selected inferior was inferior
2, that command still manages to wipe it, and then gdb restores the
old selected inferior, which is now a dangling pointer...

So the fix here is:

- Make make_cleanup_restore_current_thread store a pointer to the
  previously selected inferior directly, and use it directly instead
  of doing ptid look ups.

- Add a refcount to inferiors, very similar to thread_info's refcount,
  that is incremented/decremented by
  make_cleanup_restore_current_thread, and checked before deleting an
  inferior.  To avoid duplication, a new refcounted_object type is
  added, that both thread_info and inferior inherit from.

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

	* common/refcounted-object.h: New file.
	* gdbthread.h: Include "common/refcounted-object.h".
	(thread_info): Inherit from refcounted_object and add comments.
	(thread_info::incref, thread_info::decref)
	(thread_info::m_refcount): Delete.
	(thread_info::deletable): Use the refcounted_object::refcount()
	method.
	* inferior.c (current_inferior_): Add comment.
	(set_current_inferior): Increment/decrement refcounts.
	(prune_inferiors, remove_inferior_command): Skip inferiors marked
	not-deletable instead of comparing with the current inferior.
	(initialize_inferiors): Increment the initial inferior's refcount.
	* inferior.h (struct inferior): Forward declare.
	Include "common/refcounted-object.h".
	(current_inferior, set_current_inferior): Move declaration to
	before struct inferior's definition, and fix comment.
	(inferior): Inherit from refcounted_object.  Add comments.
	* thread.c (switch_to_thread_no_regs): Reference the thread's
	inferior pointer directly instead of doing a ptid lookup.
	(switch_to_no_thread): New function.
	(switch_to_thread(thread_info *)): New function, factored out
	from ...
	(switch_to_thread(ptid_t)): ... this.
	(restore_current_thread): Delete.
	(current_thread_cleanup): Remove 'inf_id' and 'was_removable'
	fields, and add 'inf' field.
	(do_restore_current_thread_cleanup): Check whether old->inf is
	alive instead of looking up an inferior by ptid.  Use
	switch_to_thread and switch_to_no_thread.
	(restore_current_thread_cleanup_dtor): Use old->inf directly
	instead of lookup up an inferior by id.  Decref the inferior.
	Don't restore 'removable'.
	(make_cleanup_restore_current_thread): Same the inferior pointer
	in old, instead of the inferior number.  Incref the inferior.
	Don't save/clear 'removable'.

gdb/testsuite/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

	* gdb.threads/threadapply.exp (kill_and_remove_inferior): New
	procedure.
	(top level): Call it.
	* lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 13:12:23 +01:00
Pedro Alves 9bcb1f1630 Make inferior::detaching a bool, and introduce scoped_restore::release()
I left making inferior::detaching a bool to a separate patch, because
doing that makes a make_cleanup_restore_integer call in
infrun.c:prepare_for_detach no longer compile (passing a 'bool *' when
an 'int *' is expected).  Since we want to get rid of cleanups anyway,
I looked at converting that to a scoped_restore.  However,
prepare_for_detach wants to discard the cleanup on success, and
scoped_restore doesn't have an equivalent for that.  So I added one --
I called it "release()" because it seems like a natural fit in the way
standard components call similarly-spirited methods, and, it's also
what the proposal for a generic scope guard calls it too, AFAICS:

  http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189.pdf

I've added some scoped_guard unit tests, while at it.

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/scoped_restore-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add scoped_restore-selftests.o.
	* common/scoped_restore.h (scoped_restore_base): Make "class".
	(scoped_restore_base::release): New public method.
	(scoped_restore_base::scoped_restore_base): New protected ctor.
	(scoped_restore_base::m_saved_var): New protected field.
	(scoped_restore_tmpl::scoped_restore_tmpl(T*)): Initialize the
	scoped_restore_base base class instead of m_saved_var directly.
	(scoped_restore_tmpl::scoped_restore_tmpl(T*, T2)): Likewise.
	(scoped_restore_tmpl::scoped_restore_tmpl(const
	scoped_restore_tmpl<T>&)): Likewise.
	(scoped_restore_tmpl::~scoped_restore_tmpl): Use the saved_var
	method.
	(scoped_restore_tmpl::saved_var): New method.
	(scoped_restore_tmpl::m_saved_var): Delete.
	* inferior.h (inferior::detaching): Now a bool.
	* infrun.c (prepare_for_detach): Use a scoped_restore instead of a
	cleanup.
	* unittests/scoped_restore-selftests.c: New file.
2017-04-19 13:12:23 +01:00
Pedro Alves 26fcd539dd gdb/Makefile.in: Re-sort SUBDIR_UNITTESTS_SRCS/SUBDIR_UNITTESTS_OBS
Note to self: 'o' before 'p'.

gdb/ChangeLog:
2017-04-19  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS, SUBDIR_UNITTESTS_OBS):
	Re-sort in alphabetic order.
2017-04-19 13:06:20 +01:00
Pedro Alves fdd243b001 Eliminate obstack_printf
Not used anywhere.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

	* xml-support.c (obstack_xml_printf): Delete.
	* xml-support.h (obstack_xml_printf): Delete.
2017-04-18 23:52:05 +01:00
Pedro Alves 4895cde297 gdb_xml_parser: make data fields private and make more functions methods
This patch makes the data fields of gdb_xml_parser private, and makes
more functions be gdb_xml_parser methods.  This is mostly for better
encapsulation.

Some free functions have their parsing-related guts converted to
methods, while the free functions remain, as they're used as expat
callbacks.  Now their only job is to be small shims that restore back
the gdb_xml_parser type, defer work to the corresponding method, and
make sure C++ exceptions don't cross expat.

More C++-fycation of the XML parsers built on top of gdb_xml_parser
could follow, but this was my stopping point.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

	* xml-support.c (gdb_xml_parser) <use_dtd, dtd_name, parse,
	vdebug, verror, body_text, start_element, end_element, name,
	user_data, set_is_xinclude, set_error, expat_parser>: New methods.
	<name, user_data, expat_parser, scopes, error, last_line, dtd_name,
	is_xinclude>: Make private and add m_ prefix.
	(gdb_xml_parser::body_text): New method, based on ...
	(gdb_xml_body_text): ... this.  Adjust.
	(gdb_xml_parser::vdebug): New method, based on ...
	(gdb_xml_debug): ... this.  Adjust.
	(gdb_xml_parser::verror): New method, based on ...
	(gdb_xml_error): ... this.  Adjust.
	(gdb_xml_parser::start_element): New method, based on ...
	(gdb_xml_start_element): ... this.  Adjust.
	(gdb_xml_start_element_wrapper): Defer to
	gdb_xml_parser::start_element and gdb_xml_parser::set_error.
	(gdb_xml_parser::end_element): New method, based on ...
	(gdb_xml_end_element_wrapper): ... this.  Adjust.
	(gdb_xml_parser::~gdb_xml_parser): Adjust.
	(gdb_xml_parser::gdb_xml_parser): Adjust to field renames.
	(gdb_xml_parser::use_dtd): New method, based on ...
	(gdb_xml_use_dtd): ... this.  Adjust.
	(gdb_xml_parser::parse): New method, based on ...
	(gdb_xml_parse): ... this.  Adjust.
	(gdb_xml_parse_quick): Adjust to call the parser's parse method.
	(xinclude_start_include): Adjust to call the parser's name method.
	(xml_xinclude_default, xml_xinclude_start_doctype)
	(xml_xinclude_end_doctype): Adjust to call the parser's user_data
	method.
	(xml_process_xincludes): Adjust to call parser methods.
	* xml-support.h (gdb_xml_use_dtd, gdb_xml_parse): Delete
	declarations.
2017-04-18 23:51:33 +01:00
Pedro Alves bd8a901f9e xml-support.c: Use std::string for growing string buffer
This main idea behind this patch is this change to xml-support.c:scope_level

  -  /* Body text accumulation.  This is an owning pointer.  */
  -  struct obstack *body;
  +  /* Body text accumulation.  */
  +  std::string body;

... which allows simplifying other parts of the code.

In target_fetch_description_xml, we want to distinguish between
returning "success + empty std::string" and "no success", and
gdb::optional is a natural fit for that.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

	* tracefile-tfile.c (tfile_write_tdesc): Adjust to use
	gdb::optional<std::string>.
	* xml-support.c: Include <string>.
	(scope_level::scope_level(scope_level &&))
	(scope_level::~scope_level): Delete.
	(scope_level::body): Now a std::string.
	(gdb_xml_body_text, gdb_xml_end_element): Adjust.
	(xinclude_parsing_data::xinclude_parsing_data): Add 'output'
	parameter.
	(xinclude_parsing_data::~xinclude_parsing_data): Delete.
	(xinclude_parsing_data::output): Now a std::string reference.
	(xinclude_start_include): Adjust.
	(xml_xinclude_default): Adjust.
	(xml_process_xincludes): Add 'output' parameter, and return bool.
	* xml-support.h (xml_process_xincludes): Add 'output' parameter,
	and return bool.
	* xml-tdesc.c: Include <unordered_map> and <string>.
	(tdesc_xml_cache): Delete.
	(tdesc_xml_cache_s): Delete.
	(xml_cache): Now an std::unordered_map.
	(tdesc_parse_xml): Adjust to use std::string and unordered_map.
	(target_fetch_description_xml): Change return type to
	gdb::optional<std::string>, and adjust.
	* xml-tdesc.h: Include "common/gdb_optional.h" and <string>.
	(target_fetch_description_xml): Change return type to
	gdb::optional<std::string>.
2017-04-18 23:50:55 +01:00
Pedro Alves d35d19584c gdb::optional unit tests
I thought I'd add some unit tests to make sure gdb::optional behaved
correctly, and started writing some, but then thought/realized that
libstdc++ already has extensive testing for C++17 std::optional, which
gdb::optional is a subset of, and thought why bother writing something
from scratch.  So I tried copying over a subset of libstdc++'s tests
(that ones that cover the subset supported by gdb::optional), and was
positively surprised that they mostly work OOTB.  This did help shake
out a few bugs from what I was implementing in the previous patch to
gdb::optional.  Still, it's a good chunk of code being copied over, so
if people dislike this copying/duplication, I can drop this patch.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/optional-selftests.c.
	(SUBDIR_UNITTESTS_OBS): Add optional-selftests.o.
	* unittests/optional-selftests.c: New file.
	* unittests/optional/assignment/1.cc: New file.
	* unittests/optional/assignment/2.cc: New file.
	* unittests/optional/assignment/3.cc: New file.
	* unittests/optional/assignment/4.cc: New file.
	* unittests/optional/assignment/5.cc: New file.
	* unittests/optional/assignment/6.cc: New file.
	* unittests/optional/assignment/7.cc: New file.
	* unittests/optional/cons/copy.cc: New file.
	* unittests/optional/cons/default.cc: New file.
	* unittests/optional/cons/move.cc: New file.
	* unittests/optional/cons/value.cc: New file.
	* unittests/optional/in_place.cc: New file.
	* unittests/optional/observers/1.cc: New file.
	* unittests/optional/observers/2.cc: New file.
2017-04-18 23:49:33 +01:00
Pedro Alves 22796e972f More gdb::optional features
Currently we can't use gdb::optional<T> as function return type,
because gdb::optional's copy ctor is deleted.  For example, with:

  gdb::optional<int> function ()
  {
    gdb::optional<int> opt;
    ....
    return opt;

we get:

  src/gdb/foo.c: In function ‘gdb::optional<int> foo()’:
  src/gdb/foo.c:75:10: error: use of deleted function ‘gdb::optional<T>::optional(const gdb::optional<T>&) [with T = int]’
     return opt;
	    ^
  In file included from src/gdb/foo.c:68:0:
  src/gdb/common/gdb_optional.h:53:3: note: declared here
     optional (const optional &other) = delete;
     ^

I started by fixing that, and then ran into another missing feature,
also fixed by this patch.

The next feature I'm missing most from gdb::optional<T> compared to
std::optional<T> is construction/move/assignment from a T, instead of
having to default construct an gdb::optional and then use
optional::emplace(....).

For example:
  gdb::optional<std::string> function ()
  {
    gdb::optional<std::string> opt;
    std::string str;
    ...
    opt.emplace (std::move (str));
    return opt;
vs
  gdb::optional<std::string> function ()
  {
    std::string str;
    ...
    return str;

The copy/move ctor/assign methods weren't initialy implemented because
std::optional supports construction from a type U if U is convertible
to T too, and has rules to decide whether the ctors are
explicit/implicit based on that, and rules for whether the ctor should
be trivial or not, etc., which leads to a much more complicated
implementation.

If we stick to supporting copy/move construction/assignment of/to an
optional<T> from exactly only optional<T> and T, then all that
conversion-related complication disappears, and we still gain
convenience in most use cases.

The patch also makes emplace return a reference to the constructor
object, per C++17 std::optional, and adds a reset method, againt
because std::optional has one and it's trivial to support it.  These
two changes are a requirement of the gdb::optional unit testing patch
that will follow.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

	* common/gdb_optional.h: Include common/traits.h.
	(in_place_t): New type.
	(in_place): New constexpr variable.
	(optional::optional): Remove member initialization of
	m_instantiated.
	(optional::optional(in_place_t...)): New constructor.
	(optional::~optional): Use reset.
	(optional::optional(const optional&)): New.
	(optional::optional(const optional&&)): New.
	(optional::optional(T &)): New.
	(optional::optional(T &&)): New.
	(operator::operator=(const optional &)): New.
	(operator::operator=(optional &&)): New.
	(operator::operator= (const T &))
	(operator::operator= (T &&))
	(operator::emplace (Args &&... args)): Return a T&.  Use reset.
	(operator::reset): New.
	(operator::m_instantiated):: Add in-class initializer.
	* common/traits.h: Include <type_traits>.
	(struct And): New types.
2017-04-18 23:48:41 +01:00
Pedro Alves a7fc9b6193 xml-support.c: Use std::vector
scope_level::scope_level needed both a move ctor and a dtor explicitly
coded, but those will be eliminated in a following patch.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

	* xml-support.c: Include <vector>.
	(scope_level::scope_level(const gdb_xml_element *))
	(scope_level::scope_level(scope_level&&)): New.
	(scope_level::~scope_level): New.
	(scope_level_s): Delete.
	(gdb_xml_parser::scopes): Now a std::vector.
	(gdb_xml_body_text, gdb_xml_start_element, gdb_xml_end_element):
	Use std::vector.
	(gdb_xml_parser::~gdb_xml_parser): Remove now unnecessary
	scope cleanup code.
	(gdb_xml_parser::gdb_xml_parser): Remove explicit initialization
	of the scopes member.  Use std::vector::emplace_back.
2017-04-18 23:48:15 +01:00
Pedro Alves 010151c914 C++-ify gdb/xml-support.c a bit to eliminate cleanups
Basically convert cleanups to destructors in gdb_xml_parser and
xinclude_parsing_data, and then allocate objects of those types on the
stack.

More C++-ification is possible / will follow, but this removes a few
make_cleanup calls already.

gdb/ChangeLog:
2017-04-18  Pedro Alves  <palves@redhat.com>

	* xml-support.c (gdb_xml_parser): Add ctor/dtor.  Make is_xinclude
	a bool.
	(gdb_xml_end_element): Change type of first parameter.
	(gdb_xml_cleanup): Rename to ...
	(gdb_xml_parser::~gdb_xml_parser): ... this.
	(gdb_xml_create_parser_and_cleanup): Delete with ...
	(gdb_xml_parser::gdb_xml_parser): ... creation parts factored out
	to this new ctor.
	(gdb_xml_parse_quick): Create a local gdb_xml_parser instead of
	using gdb_xml_create_parser_and_cleanup.
	(xinclude_parsing_data): Add ctor/dtor.
	(xml_xinclude_cleanup): Delete.
	(xml_process_xincludes): Create a local xinclude_parsing_data
	instead of heap-allocating one.  Create a local gdb_xml_parser
	instead of heap-allocating one with
	gdb_xml_create_parser_and_cleanup.
2017-04-18 21:39:24 +01:00
John Baldwin d56060f08a PR threads/20743: Don't attempt to suspend or resume exited threads.
When resuming a native FreeBSD process, ignore exited threads when
suspending/resuming individual threads prior to continuing the process.

gdb/ChangeLog:

	PR threads/20743
	* fbsd-nat.c (resume_one_thread_cb): Remove.
	(resume_all_threads_cb): Remove.
	(fbsd_resume): Use ALL_NON_EXITED_THREADS instead of
	iterate_over_threads.
2017-04-18 09:45:37 -07:00
Joel Brobecker 305d16a9be Update NEWS post GDB 8.0 branch creation.
gdb/ChangeLog:

	* NEWS: Create a new section for the next release branch.
	Rename the section of the current branch, now that it has
	been cut.
2017-04-17 07:30:29 -07:00
Joel Brobecker 8bb5723165 Bump version to 8.0.50.DATE-git
Now that the GDB 8.0 branch has been created, we should bump
the GDB version accordingly.

gdb/ChangeLog:

	GDB 8.0 branch created (725bf5cf12):
	* version.in: Bump version to 7.99.90.DATE-git.
2017-04-17 07:20:49 -07:00
Sergio Durigan Junior 096c92ddb3 Fix build breakage on Cygwin (PR gdb/21385)
On gdb/windows-nat.c:windows_create_inferior, ALLARGS needs to be
declared independently of the host that we're building for.  This
fixes a build breakage on Cygwin.

2017-04-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21385
	* windows-nat.c (windows_create_inferior): Declare 'allargs'
	independently of the host, and fix build breakage on Cygwin.
2017-04-13 21:01:53 -04:00
Pedro Alves 0550c95595 Make inferior a class with cdtors, and use new/delete
struct inferior became a non-POD when enum_flags was made a non-POD,
so we should be allocating/destroying inferiors with new/delete, etc.
That's what this commit does.

Note: this commit makes all boolean fields of inferior be "bool",
except the "detaching" field.  That'll require more work, so I split
it to a separate patch.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* inferior.c (free_inferior): Convert to ...
	(inferior::~inferior): ... this dtor.
	(inferior::inferior): New ctor, factored out from ...
	(add_inferior_silent): ... here.  Allocate the inferior with a new
	expression.
	(delete_inferior): Call delete instead of free_inferior.
	* inferior.h (gdb_environ, continuation): Forward declare.
	(inferior): Now a class.  Add in-class initialization to all
	members.  Make boolean fields bool, except 'detaching'.
	(inferior::inferior): New explicit ctor.
	(inferior::~inferior): New.
2017-04-13 16:18:16 +01:00
Pedro Alves e3d60dfc00 GC inferior.c:init_inferior_list
Not used anywhere.  This was actually never used.  It came in because
I originally created inferior.c by copying thread.c, and doing
s/thread/inferior/g, and missed that nothing needs this.  :-)

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* inferior.c (init_inferior_list): Delete.
	* inferior.h (init_inferior_list): Delete.
2017-04-13 16:18:16 +01:00
Pedro Alves 5fd69d0ab2 Improve coverage of the PR threads/13217 regression test
- Make sure we end up with no thread selected after the detach.

- Test both "thread apply all" and "thread apply $some_threads", for
  completeness.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	PR threads/13217
	* gdb.threads/threadapply.exp (thr_apply_detach): New procedure.
	(top level): Call it twice, with different thread sets.
2017-04-13 16:18:16 +01:00
Pedro Alves c6609450b3 C++fy thread_apply_all_command
This eliminates a couple cleanups.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* thread.c: Include <algorithm>.
	(thread_array_cleanup): Delete.
	(scoped_inc_dec_ref): New class.
	(live_threads_count): New function.
	(set_thread_refcount): Delete.
	(tp_array_compar_ascending): Now a bool.
	(tp_array_compar): Convert to a std::sort comparison function.
	(thread_apply_all_command): Use std::vector and scoped_inc_dec_ref
	and live_threads_count.
2017-04-13 16:18:16 +01:00
Pedro Alves 2a00d7ce26 Fix follow-fork latent bug
A later patch in the series adds an assertion to switch_to_thread that
the resulting inferior_ptid always matches the "current_inferior()"
inferior.  This exposed a latent bug in the follow-fork code, where
we're building the fork child inferior.  We're switching
inferior_ptid, but not the current inferior object...

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* infrun.c (follow_fork_inferior): Also switch the current
	inferior.
2017-04-13 16:18:16 +01:00
Pedro Alves 441d7c9378 watch_command_1: Fix dangling frame access
While working on some changes to switch_to_thread, I inadvertently
make switch_to_thread call reinit_frame_cache more frequently, even
when the thread didn't change.  This exposed a latent bug in
watch_command_1, where we're referencing a frame after
creating/inserting breakpoints, which potentially calls
reinit_frame_cache if it needs to install breakpoints with a different
thread selected.

Handle this similarly to how it's already handled in other similar
cases.  I.e., save any frame-related information we might need before
creating a breakpoint.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (watch_command_1): Save watchpoint-frame info
	before calling create_internal_breakpoint.
2017-04-13 16:15:34 +01:00
Pedro Alves 808480f667 fork-child.c: Avoid unnecessary heap-allocation / string copying
The previous change to fork-child.c converted the argv building from
an alloca-allocated array of non-owning arg pointers, to a std::vector
of owning pointers, which results in N string dups, with N being the
number of arguments in the vector, and then requires manually
releasing the pointers owned by the vector.

This patch makes the vector hold non-owning pointers, and avoids the
string dups, by doing one single string copy of the arguments upfront,
and replacing separators with NULL terminators in place, like we used
to.  All the logic to do that is encapsulated in a new class.

With this, there's no need to remember to manually release the argv
elements with free_vector_argv either.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* fork-child.c (execv_argv): New class.
	(breakup_args): Refactored as ...
	(execv_argv::init_for_no_shell): .. this method of execv_argv.
	Copy arguments to storage and replace separators with NULL
	terminators in place.
	(escape_bang_in_quoted_argument): Adjust to return bool.
	(execv_argv::execv_argv): New ctor.
	(execv_argv::init_for_shell): New method, factored out from
	fork_inferior.  Don't strdup strings into the vector.
	(fork_inferior): Eliminate "shell" local and use execv_argv.  Use
	Remove free_vector_argv call.
2017-04-13 11:46:07 +01:00
Iain Buclaw b1b45502bd Add ChangeLog entries
ChangeLog entries were left unstaged in my previous commit on March 30th.
2017-04-13 10:39:13 +02:00
Yao Qi ad3d022a77 Fix a typo in rx_fpsw_type
gdb:

2017-04-13  Yao Qi  <yao.qi@linaro.org>

	* rx-tdep.c (rx_fpsw_type): Check tdep->rx_fpsw_type instead of
	tdep->rx_psw_type.
2017-04-13 08:29:44 +01:00
Yao Qi e6ddc3bfed XCNEW gdbarch_tdep in rl78 and rx
"struct gdbarch_tdep" is XNEW'ed in rl78 and rx, so the memory is not
cleared.  As the result, tdep->rl78_psw_type is never initialized
properly.

  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  if (tdep->rl78_psw_type == NULL)
    {
      tdep->rl78_psw_type = arch_flags_type (gdbarch,
					     "builtin_type_rl78_psw", 1);

The bug is found by my unit test in the following patch.

gdb:

2017-04-13  Yao Qi  <yao.qi@linaro.org>

	* rl78-tdep.c (rl78_gdbarch_init): Use XCNEW instead of XNEW.
	* rx-tdep.c (rx_gdbarch_init): Likewise.
2017-04-13 08:29:43 +01:00
Pedro Alves bfb8cf9091 struct breakpoint: Fix indentation
I'm going to need to touch all these fields to add in-class
initialization anyway, might as well take the opportunity to finally
fix this...

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* breakpoint.h (struct breakpoint): Reindent.
2017-04-13 03:07:21 +01:00
Pedro Alves f5336ca55c breakpoint.c: bp_location (the array) shadows bp_location (the type)
The bp_location array has the same name as the "struct bp_location",
type preventing refering to the structure without the "struct" inside
breakpoint.c.  I.e., we must write:

 "new struct bp_location;"

instead of:

 "new bp_location"

Rename the array and the associated variables/functions to avoid the
shadowing.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (bp_location): Rename to ...
	(bp_locations): ... this.  All references updated.
	(bp_location_count): Rename to ...
	(bp_locations_count): ... this.  All references updated.
	(bp_location_placed_address_before_address_max): Rename to ...
	(bp_locations_placed_address_before_address_max): ... this.  All
	references updated.
	(bp_location_shadow_len_after_address_max): Rename to ...
	(bp_locations_shadow_len_after_address_max): ... this.  All
	references updated.
	(bp_location_compare_addrs): Rename to ...
	(bp_locations_compare_addrs): ... this.  All references updated.
	(bp_location_compare):Rename to ...
	(bp_locations_compare): ... this.  All references updated.
	(bp_location_target_extensions_update): Rename to ...
	(bp_locations_target_extensions_update): ... this.  All references
	updated.
2017-04-13 02:12:53 +01:00
Sergio Durigan Junior be628ab814 Create gdb_termios.h (and cleanup gdb/{,gdbserver/}terminal.h)
As requested, I'm sending this as a separate patch because it is ready
to be included as-is.

The idea here is that both gdb/terminal.h and gdb/gdbserver/terminal.h
share the same code, which is responsible for setting a bunch of
defines on based on the presence of termios.h and a few other headers.
This simple patch just moves this common code to common/gdb_termios.h
and makes the necessary adjustments on both GDB and gdbserver so that
they can use this new header.  It also implements the some header
checks on common/common.m4.

As a bonus, gdb/gdbserver/terminal.h can be removed because it's now
empty.

Built on x86_64, no regressions found.

gdb/ChangeLog:
2017-04-12  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add "common/gdb_termios.h".
	* common/common.m4: Check headers 'termios.h', 'termio.h' and
	'sgtty.h'.
	* common/gdb_termios.h: New file, with parts of "terminal.h".
	* inflow.c: Include "gdb_termios.h".
	* ser-unix.c: Include "gdb_termios.h".
	* terminal.h: Move terminal-related defines to
	"common/gdb_termios.h".

gdb/gdbserver/ChangeLog:
2017-04-12  Sergio Durigan Junior  <sergiodj@redhat.com>

	* remote-utils.c: Include "gdb_termios.h" instead of
	"terminal.h".
	* terminal.h: Delete file.
2017-04-12 17:59:45 -04:00
Tom Tromey 8e9e35b180 Change linespec_result::location to be an event_location_up
This is a follow-up to another patch.  It changes
linespec_result::location to be an event_location_up.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* probe.c (parse_probes): Update.
	* location.h (delete_event_location): Don't declare.
	(event_location_deleter::operator()): Update.
	* location.c (event_location_deleter::operator()): Rename from
	delete_event_location.
	* linespec.h (linespec_result) <location>: Change type to
	event_location_up.
	* linespec.c (canonicalize_linespec, event_location_to_sals)
	(decode_objc): Update.
	(linespec_result): Don't call delete_event_location.
	* breakpoint.c (create_breakpoints_sal)
	(bkpt_probe_create_sals_from_location)
	(strace_marker_create_sals_from_location): Update.
2017-04-12 11:16:19 -06:00
Tom Tromey 16e802b9c0 Add a constructor and destructor to linespec_result
linespec_result is only ever allocated on the stack, so it's
relatively easy to convert to having a constructor and a destructor.
This patch makes this change.  This removes some cleanups.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* linespec.h (struct linespec_result): Add constructor and
	destructor.
	(init_linespec_result, destroy_linespec_result)
	(make_cleanup_destroy_linespec_result): Don't declare.
	* linespec.c (init_linespec_result): Remove.
	(linespec_result::~linespec_result): Rename from
	destroy_linespec_result.  Update.
	(cleanup_linespec_result, make_cleanup_destroy_linespec_result):
	Remove.
	* breakpoint.c (create_breakpoint, break_range_command)
	(decode_location_default): Update.
	* ax-gdb.c (agent_command_1): Update.
2017-04-12 11:16:19 -06:00
Tom Tromey d28cd78ad8 Change breakpoint event locations to event_location_up
This is a follow-up to an earlier patch.  It changes breakpoint's
location and location_range_end members to be of type
event_location_up, then fixes up the users.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_download_tracepoint): Update.
	* python/py-breakpoint.c (bppy_get_location): Update.
	* guile/scm-breakpoint.c (bpscm_print_breakpoint_smob)
	(gdbscm_breakpoint_location): Update.
	* elfread.c (elf_gnu_ifunc_resolver_return_stop): Update.
	* breakpoint.h (struct breakpoint) <location, location_range_end>:
	Change type to event_location_up.
	* breakpoint.c (create_overlay_event_breakpoint)
	(create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint)
	(breakpoint_event_location_empty_p, print_breakpoint_location)
	(print_one_breakpoint_location, create_thread_event_breakpoint)
	(init_breakpoint_sal, create_breakpoint)
	(print_recreate_ranged_breakpoint, break_range_command)
	(init_ada_exception_breakpoint, say_where): Update.
	(base_breakpoint_dtor): Don't call delete_event_location.
	(bkpt_print_recreate, tracepoint_print_recreate)
	(dprintf_print_recreate, update_static_tracepoint)
	(breakpoint_re_set_default): Update.
2017-04-12 11:16:19 -06:00
Tom Tromey 711799d513 Use std::vector in compile-loc2c.c
This changes compile-loc2c.c to use std::vector in place of a VEC,
allowing the removal of a cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* compile/compile-loc2c.c (compute_stack_depth_worker): Change
	type of "to_do".  Update.
	(compute_stack_depth): Use std::vector.
2017-04-12 11:16:19 -06:00
Tom Tromey 52d214d3e1 Use std::vector in find_instruction_backward
This changes find_instruction_backward to use std::vector, removing a
cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* printcmd.c (find_instruction_backward): Use std::vector.
2017-04-12 11:16:19 -06:00
Tom Tromey 4c404b8be6 Use std::vector in reread_symbols
This changes reread_symbols to use std::vector, removing a cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* symfile.c (objfilep): Remove typedef.
	(reread_symbols): Use a std::vector.
2017-04-12 11:16:19 -06:00
Tom Tromey 156d9eab86 Use scoped_restore in more places
This changes a few more places to use scoped_restore, allowing some
cleanup removals.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* mi/mi-main.c (exec_direction_forward): Remove.
	(exec_reverse_continue, mi_execute_command): Use scoped_restore.
	* guile/scm-ports.c (ioscm_with_output_to_port_worker): Use
	scoped_restore.
	* guile/guile.c (guile_repl_command, guile_command)
	(gdbscm_execute_gdb_command): Use scoped_restore.
	* go-exp.y (go_parse): Use scoped_restore.
	* d-exp.y (d_parse): Use scoped_restore.
	* cli/cli-decode.c (cmd_func): Use scoped_restore.
	* c-exp.y (c_parse): Use scoped_restore.
2017-04-12 11:16:19 -06:00
Tom Tromey 4d89769a7b C++ify mi_parse
This changes mi_parse to return a unique_ptr, and to use "new"; then
fixes up the users.  This allows removing one cleanup.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* mi/mi-parse.h (struct mi_parse): Add constructor, destructor.
	(mi_parse): Update return type.
	(mi_parse_free): Remove.
	* mi/mi-parse.c (mi_parse::mi_parse): New constructor.
	(mi_parse::~mi_parse): Rename from mi_parse_free.
	(mi_parse_cleanup): Remove.
	(mi_parse): Return a unique_ptr.  Use new.
	* mi/mi-main.c (mi_execute_command): Update.
2017-04-12 11:16:18 -06:00
Tom Tromey 4b217cc72b Remove some cleanups from location.c
This removes some more cleanups from location.c by using
unique_xmalloc_ptr.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* location.c (explicit_location_lex_one): Return a
	unique_xmalloc_ptr.
	(string_to_explicit_location): Update.  Remove cleanups.
2017-04-12 11:16:18 -06:00
Tom Tromey 59d3651be7 Remove some cleanups from gnu-v3-abi.c
This removes some cleanups from gnu-v3-abi.c, by using std::vector
rather than VEC.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* gnu-v3-abi.c (value_and_voffset_p): Remove typedef.
	(compare_value_and_voffset): Change type.  Update.
	(compute_vtable_size): Change type of "offset_vec".
	(gnuv3_print_vtable): Use std::vector.  Remove cleanups.
	(gnuv3_get_typeid): Remove extraneous declaration.
2017-04-12 11:16:18 -06:00
Tom Tromey b24b0d6c3b Fix up wchar_iterator comment
This fixes up a comment in charset.h that has been obsolete for a
while.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* charset.h (wchar_iterator): Fix comment.
2017-04-12 11:16:18 -06:00
Tom Tromey 80a3b8c578 Remove cleanup_iconv
This introduces a new "iconv_wrapper" class, to be used in
convert_between_encodings.  This allows the removal of cleanup_iconv.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* charset.c (iconv_wrapper): New class.
	(cleanup_iconv): Remove.
	(convert_between_encodings): Use it.
2017-04-12 11:16:18 -06:00
Tom Tromey c83dd86726 Change increment_reading_symtab to return a scoped_restore
This changes increment_reading_symtab to return a scoped_restore, then
fixes up the users.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* symfile.h (increment_reading_symtab): Update type.
	* symfile.c (decrement_reading_symtab): Remove.
	(increment_reading_symtab): Return a scoped_restore_tmpl<int>.
	* psymtab.c (psymtab_to_symtab): Update.
	* dwarf2read.c (dw2_instantiate_symtab): Update.
2017-04-12 11:16:17 -06:00
Tom Tromey 0e8621a0be Introduce gdb_dlhandle_up
This introduces gdb_dlhandle_up, a unique_ptr that can close a
dlopen'd library.  All the functions working with dlopen handles are
updated to use this new type.

I did not try to build this on Windows.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* jit.c (struct jit_reader): Declare separately.  Add constructor
	and destructor.  Change type of "handle".
	(loaded_jit_reader): Define separately.
	(jit_reader_load): Update.  New "new".
	(jit_reader_unload_command): Use "delete".
	* gdb-dlfcn.h (struct dlclose_deleter): New.
	(gdb_dlhandle_up): New typedef.
	(gdb_dlopen, gdb_dlsym): Update types.
	(gdb_dlclose): Remove.
	* gdb-dlfcn.c (gdb_dlopen): Return a gdb_dlhandle_up.
	(gdb_dlsym): Change type of "handle".
	(make_cleanup_dlclose): Remove.
	(dlclose_deleter::operator()): Rename from gdb_dlclose.
	* compile/compile-c-support.c (load_libcc): Update.
2017-04-12 11:16:17 -06:00