Commit Graph

42074 Commits

Author SHA1 Message Date
Simon Marchi ed2df75c51 Fix spurious semicolon in sparc-linux-nat.c
Remove a semicolon that should not be there, as reported in PR 23917:

  CXX    sparc-linux-nat.o
/home/emaisin/src/binutils-gdb/gdb/sparc-linux-nat.c:39:3: error: expected unqualified-id before ‘{’ token
   { sparc_store_inferior_registers (regcache, regnum); }
   ^

Tested by rebuilding the file manually (make sparc-linux-nat.o) in a
sparc64-linux-gnu build.

gdb/ChangeLog:

	PR gdb/23917
	* sparc-linux-nat.c (sparc_linux_nat_target): Remove extraneous
	semicolon.
2018-11-26 14:35:11 -05:00
Pedro Alves 24bce9bbe5 Fix Solaris build
The recent commit 0803633106 ("Per-inferior thread list, thread
ranges/iterators, down with ALL_THREADS, etc.") removed the
definitions of is_running/is_stopped/is_exited but missed updating a
couple uses of is_exited in Solaris-specific code.

Tested by Rainer Orth on amd64-pc-solaris2.11.

gdb/ChangeLog:
2018-11-26  Pedro Alves  <palves@redhat.com>

	* procfs.c (procfs_notice_thread): Replace uses of
	in_thread_list/is_exited with find_thread_ptid/THREAD_EXITED.
	* sol-thread.c (sol_thread_target::wait)
	(sol_update_thread_list_callback): Likewise.
2018-11-26 13:16:26 +00:00
Sergio Durigan Junior f63c03b470 Implement timestamp'ed output on "make check"
It is unfortunately not uncommon to have tests hanging on some of the
BuildBot workers.  For example, the ppc64be/ppc64le+gdbserver builders
are especially in a bad state when it comes to testing GDB/gdbserver,
and we can have builds that take an absurd amount of time to
finish (almost 1 week for one single build, for example).

It may be hard to diagnose these failures, because sometimes we don't
have access to the faulty systems, and other times we're just too busy
to wait and check which test is actually hanging.  During one of our
conversations about the topic, someone proposed that it would be a
good idea to have a timestamp put together with stdout output, so that
we can come back later and examine which tests are taking too long to
complete.

Here's my proposal to do this.  The very first thing I tried to do was
to use "ts(1)" to achieve this feature, and it obviously worked, but
the problem is that I'm afraid "ts(1)" may not be widely available on
every system we support.  Therefore, I decided to implement a *very*
simple version of "ts(1)", in Python 3, which basically does the same
thing: iterate over the stdin lines, and prepend a timestamp onto
them.

As for testsuite/Makefile.in, the user can now specify two new
variables to enable timestamp'ed output: TS (which enables the
output), and TS_FORMAT (optional, used to specify another timestamp
format according to "strftime").

Here's an example of how the output looks like:

  ...
  [Nov 22 17:07:19] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/call-strs.exp ...
  [Nov 22 17:07:19] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/step-over-no-symbols.exp ...
  [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/all-architectures-6.exp ...
  [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/hashline3.exp ...
  [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/max-value-size.exp ...
  [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/quit-live.exp ...
  [Nov 22 17:07:46] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/paginate-bg-execution.exp ...
  [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/gcore-buffer-overflow.exp ...
  [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/gcore-relro.exp ...
  [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/watchpoint-delete.exp ...
  [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/breakpoint-in-ro-region.exp ...
  [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/vla-sideeffect.exp ...
  [Nov 22 17:07:57] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/unload.exp ...
  ...

(What, gdb.base/quit-live.exp is taking 26 seconds to complete?!)

Output to stderr is not timestamp'ed, but I don't think that will be a
problem for us.  If it is, we can revisit the solution and extend it.

gdb/testsuite/ChangeLog:
2018-11-25  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (TIMESTAMP): New variable.
	(check-single): Add $(TIMESTAMP) to the end of $(DO_RUNTEST)
	command.
	(check-single-racy): Likewise.
	(check/%.exp): Likewise.
	(check-racy/%.exp): Likewise.
	(workers/%.worker): Likewise.
	(build-perf): Likewise.
	(check-perf): Likewise.
	* README: Describe new "TS" and "TS_FORMAT" variables.
	* print-ts.py: New file.
2018-11-25 18:21:26 -05:00
Tom Tromey b5b12e1dbe Remove obsolete comments from field_fmt
This removes some comments that I believe were made obsolete by the
recent change to cli_ui_out::do_field_fmt.  The comment in mi_ui_out
probably was just copy/paste, because I think aligning never made
sense in an MI context.

gdb/ChangeLog
2018-11-25  Tom Tromey  <tom@tromey.com>

	* ui-out.c (ui_out::field_fmt): Remove comment.
	* tui/tui-out.c (tui_ui_out::do_field_fmt): Remove comment.
	* mi/mi-out.c (mi_ui_out::do_field_fmt): Remove comment.
2018-11-25 15:29:35 -07:00
Philippe Waroquiers 5446094655 Re-fix leak in source.c (open_source_file).
Leak fixed in '8e6a5953e1d Fix 4K leak in open_source_file' has been partially
undone by '2179fbc36d23 Return scoped_fd from open_source_file'. Re-add the
transfer of current s->fullname to the unique_xmalloc_ptr fullname given to
find_and_open_source.
2018-11-24 12:42:24 +01:00
Alan Hayward 5013824590 gdbserver: AArch64: Remove cannot_fetch/store_register
The cannot store/fetch register functions are only used for checking
if a register can be accessed using PEEKUSER/POKEUSER.
The AArch64 port doesn't support this method of access, so remove the
unused functions.

gdb/gdbserver:
	* linux-aarch64-low.c (aarch64_cannot_store_register): Remove.
	(aarch64_cannot_fetch_register): Likewise.
	(struct linux_target_ops): Update references.
2018-11-23 14:12:46 +00:00
Pedro Alves 6af05e645a Remove declarations of is_running/is_stopped/is_exited
The recent commit 0803633106 ("Per-inferior thread list, thread
ranges/iterators, down with ALL_THREADS, etc.") removed the
definitions of is_running/is_stopped/is_exited but missed removing the
declarations.

gdb/ChangeLog:
2018-11-23  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (enum thread_state): Move comments here.
	(is_running, is_stopped, is_exited): Remove declarations.
2018-11-23 13:36:59 +00:00
Pedro Alves 0803633106 Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc.
As preparation for multi-target, this patch makes each inferior have
its own thread list.

This isn't absolutely necessary for multi-target, but simplifies
things.  It originally stemmed from the desire to eliminate the
init_thread_list calls sprinkled around, plus it makes it more
efficient to iterate over threads of a given inferior (no need to
always iterate over threads of all inferiors).

We still need to iterate over threads of all inferiors in a number of
places, which means we'd need adjust the ALL_THREADS /
ALL_NON_EXITED_THREADS macros.  However, naively tweaking those macros
to have an extra for loop, like:

     #define ALL_THREADS (thr, inf) \
       for (inf = inferior_list; inf; inf = inf->next) \
	 for (thr = inf->thread_list; thr; thr = thr->next)

causes problems with code that does "break" or "continue" within the
ALL_THREADS loop body.  Plus, we need to declare the extra "inf" local
variable in order to pass it as temporary variable to ALL_THREADS
(etc.)

It gets even trickier when we consider extending the macros to filter
out threads matching a ptid_t and a target.  The macros become tricker
to read/write.  Been there.

An alternative (which was my next attempt), is to replace the
ALL_THREADS etc. iteration style with for_each_all_threads,
for_each_non_exited_threads, etc. functions which would take a
callback as parameter, which would usually be passed a lambda.
However, I did not find that satisfactory at all, because the
resulting code ends up a little less natural / more noisy to read,
write and debug/step-through (due to use of lambdas), and in many
places where we use "continue;" to skip to the next thread now need to
use "return;".  (I ran into hard to debug bugs caused by a
continue/return confusion.)

I.e., before:

    ALL_NON_EXITED_THREADS (tp)
      {
	if (tp->not_what_I_want)
	  continue;
	// do something
      }

would turn into:

    for_each_non_exited_thread ([&] (thread_info *tp)
      {
	if (tp->not_what_I_want)
	  return;
	// do something
      });

Lastly, the solution I settled with was to replace the ALL_THREADS /
ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges
and iterators, such that you can instead naturaly iterate over
threads/inferiors using range-for, like e.g,.:

   // all threads, including THREAD_EXITED threads.
   for (thread_info *tp : all_threads ())
     { .... }

   // all non-exited threads.
   for (thread_info *tp : all_non_exited_threads ())
     { .... }

   // all non-exited threads of INF inferior.
   for (thread_info *tp : inf->non_exited_threads ())
     { .... }

The all_non_exited_threads() function takes an optional filter ptid_t as
parameter, which is quite convenient when we need to iterate over
threads matching that filter.  See e.g., how the
set_executing/set_stop_requested/finish_thread_state etc. functions in
thread.c end up being simplified.

Most of the patch thus is about adding the infrustructure for allowing
the above.  Later on when we get to actual multi-target, these
functions/ranges/iterators will gain a "target_ops *" parameter so
that e.g., we can iterate over all threads of a given target that
match a given filter ptid_t.

The only entry points users needs to be aware of are the
all_threads/all_non_exited_threads etc. functions seen above.  Thus,
those functions are declared in gdbthread.h/inferior.h.  The actual
iterators/ranges are mainly "internals" and thus are put out of view
in the new thread-iter.h/thread-iter.c/inferior-iter.h files.  That
keeps the gdbthread.h/inferior.h headers quite a bit more readable.

A common/safe-iterator.h header is added which adds a template that
can be used to build "safe" iterators, which are forward iterators
that can be used to replace the ALL_THREADS_SAFE macro and other
instances of the same idiom in future.

There's a little bit of shuffling of code between
gdbthread.h/thread.c/inferior.h in the patch.  That is necessary in
order to avoid circular dependencies between the
gdbthread.h/inferior.h headers.

As for the init_thread_list calls sprinkled around, they're all
eliminated by this patch, and a new, central call is added to
inferior_appeared.  Note how also related to that, there's a call to
init_wait_for_inferior in remote.c that is eliminated.
init_wait_for_inferior is currently responsible for discarding skipped
inline frames, which had to be moved elsewhere.  Given that nowadays
we always have a thread even for single-threaded processes, the
natural place is to delete a frame's inline frame info when we delete
the thread.  I.e., from clear_thread_inferior_resources.

gdb/ChangeLog:
2018-11-22  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMMON_SFILES): Add thread-iter.c.
	* breakpoint.c (breakpoints_should_be_inserted_now): Replace
	ALL_NON_EXITED_THREADS with all_non_exited_threads.
	(print_one_breakpoint_location): Replace ALL_INFERIORS with
	all_inferiors.
	* bsd-kvm.c: Include inferior.h.
	* btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS
	with all_non_exited_threads.
	* common/filtered-iterator.h: New.
	* common/safe-iterator.h: New.
	* corelow.c (core_target_open): Don't call init_thread_list here.
	* darwin-nat.c (thread_info_from_private_thread_info): Replace
	ALL_THREADS with all_threads.
	* fbsd-nat.c (fbsd_nat_target::resume): Replace
	ALL_NON_EXITED_THREADS with inf->non_exited_threads.
	* fbsd-tdep.c (fbsd_make_corefile_notes): Replace
	ALL_NON_EXITED_THREADS with inf->non_exited_threads.
	* fork-child.c (postfork_hook): Don't call init_thread_list here.
	* gdbarch-selftests.c (register_to_value_test): Adjust.
	* gdbthread.h: Don't include "inferior.h" here.
	(struct inferior): Forward declare.
	(enum step_over_calls_kind): Moved here from inferior.h.
	(thread_info::deletable): Definition moved to thread.c.
	(find_thread_ptid (inferior *, ptid_t)): Declare.
	(ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete.
	Include "thread-iter.h".
	(all_threads, all_non_exited_threads, all_threads_safe): New.
	(any_thread_p): Declare.
	(thread_list): Delete.
	* infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with
	all_non_exited_threads.
	(proceed_after_attach_callback): Delete.
	(proceed_after_attach): Take an inferior pointer instead of an
	integer PID.  Adjust to use range-for.
	(attach_post_wait): Pass down inferior pointer instead of pid.
	Use range-for instead of ALL_NON_EXITED_THREADS.
	(detach_command): Remove init_thread_list call.
	* inferior-iter.h: New.
	* inferior.c (struct delete_thread_of_inferior_arg): Delete.
	(delete_thread_of_inferior): Delete.
	(delete_inferior, exit_inferior_1): Use range-for with
	inf->threads_safe() instead of iterate_over_threads.
	(inferior_appeared): Call init_thread_list here.
	(discard_all_inferiors): Use all_non_exited_inferiors.
	(find_inferior_id, find_inferior_pid): Use all_inferiors.
	(iterate_over_inferiors): Use all_inferiors_safe.
	(have_inferiors, number_of_live_inferiors): Use
	all_non_exited_inferiors.
	(number_of_inferiors): Use all_inferiors and std::distance.
	(print_inferior): Use all_inferiors.
	* inferior.h: Include gdbthread.h.
	(enum step_over_calls_kind): Moved to gdbthread.h.
	(struct inferior) <thread_list>: New field.
	<threads, non_exited_threads, threads_safe>: New methods.
	(ALL_INFERIORS): Delete.
	Include "inferior-iter.h".
	(ALL_NON_EXITED_INFERIORS): Delete.
	(all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New
	functions.
	* inflow.c (child_interrupt, child_pass_ctrlc): Replace
	ALL_NON_EXITED_THREADS with all_non_exited_threads.
	* infrun.c (follow_exec): Use all_threads_safe.
	(clear_proceed_status, proceed): Use all_non_exited_threads.
	(init_wait_for_inferior): Don't clear inline frame state here.
	(infrun_thread_stop_requested, for_each_just_stopped_thread): Use
	all_threads instead of ALL_NON_EXITED_THREADS.
	(random_pending_event_thread): Use all_non_exited_threads instead
	of ALL_NON_EXITED_THREADS.  Use a lambda for repeated code.
	(clean_up_just_stopped_threads_fsms): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	(handle_no_resumed): Use all_non_exited_threads instead of
	ALL_NON_EXITED_THREADS.  Use all_inferiors instead of
	ALL_INFERIORS.
	(restart_threads, switch_back_to_stepped_thread): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with
	all_inferiors.
	(kill_unfollowed_fork_children): Use inf->non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	* linux-tdep.c (linux_make_corefile_notes): Use
	inf->non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* linux-thread-db.c (thread_db_target::update_thread_list):
	Replace ALL_INFERIORS with all_inferiors.
	(thread_db_target::thread_handle_to_thread_info): Use
	inf->non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* mi/mi-interp.c (multiple_inferiors_p): New.
	(mi_on_resume_1): Simplify using all_non_exited_threads and
	multiple_inferiors_p.
	* mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	* nto-procfs.c (nto_procfs_target::open): Don't call
	init_thread_list here.
	* record-btrace.c (record_btrace_target_open)
	(record_btrace_target::stop_recording)
	(record_btrace_target::close)
	(record_btrace_target::record_is_replaying)
	(record_btrace_target::resume, record_btrace_target::wait)
	(record_btrace_target::record_stop_replaying): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* record-full.c (record_full_wait_1): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	* regcache.c (cooked_read_test): Remove reference to global
	thread_list.
	* remote-sim.c (gdbsim_target::create_inferior): Don't call
	init_thread_list here.
	* remote.c (remote_target::update_thread_list): Use
	all_threads_safe instead of ALL_NON_EXITED_THREADS.
	(remote_target::process_initial_stop_replies): Replace
	ALL_INFERIORS with all_non_exited_inferiors and use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	(remote_target::open_1): Don't call init_thread_list here.
	(remote_target::append_pending_thread_resumptions)
	(remote_target::remote_resume_with_hc): Use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	(remote_target::commit_resume)
	(remote_target::remove_new_fork_children): Replace ALL_INFERIORS
	with all_non_exited_inferiors and use all_non_exited_threads
	instead of ALL_NON_EXITED_THREADS.
	(remote_target::kill_new_fork_children): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.  Remove
	init_thread_list and init_wait_for_inferior calls.
	(remote_target::remote_btrace_maybe_reopen)
	(remote_target::thread_handle_to_thread_info): Use
	all_non_exited_threads instead of ALL_NON_EXITED_THREADS.
	* target.c (target_terminal::restore_inferior)
	(target_terminal_is_ours_kind): Replace ALL_INFERIORS with
	all_non_exited_inferiors.
	* thread-iter.c: New file.
	* thread-iter.h: New file.
	* thread.c: Include "inline-frame.h".
	(thread_list): Delete.
	(clear_thread_inferior_resources): Call clear_inline_frame_state.
	(init_thread_list): Use all_threads_safe instead of
	ALL_THREADS_SAFE.  Adjust to per-inferior thread lists.
	(new_thread): Adjust to per-inferior thread lists.
	(add_thread_silent): Pass inferior to find_thread_ptid.
	(thread_info::deletable): New, moved from the header.
	(delete_thread_1): Adjust to per-inferior thread lists.
	(find_thread_global_id): Use inf->threads().
	(find_thread_ptid): Use find_inferior_ptid and pass inferior to
	find_thread_ptid.
	(find_thread_ptid(inferior*, ptid_t)): New overload.
	(iterate_over_threads): Use all_threads_safe.
	(any_thread_p): New.
	(thread_count): Use all_threads and std::distance.
	(live_threads_count): Use all_non_exited_threads and
	std::distance.
	(valid_global_thread_id): Use all_threads.
	(in_thread_list): Use find_thread_ptid.
	(first_thread_of_inferior): Adjust to per-inferior thread lists.
	(any_thread_of_inferior, any_live_thread_of_inferior): Use
	inf->non_exited_threads().
	(prune_threads, delete_exited_threads): Use all_threads_safe.
	(thread_change_ptid): Pass inferior pointer to find_thread_ptid.
	(set_resumed, set_running): Use all_non_exited_threads.
	(is_thread_state, is_stopped, is_exited, is_running)
	(is_executing): Delete.
	(set_executing, set_stop_requested, finish_thread_state): Use
	all_non_exited_threads.
	(print_thread_info_1): Use all_inferiors and all_threads.
	(thread_apply_all_command): Use all_non_exited_threads.
	(thread_find_command): Use all_threads.
	(update_threads_executing): Use all_non_exited_threads.
	* tid-parse.c (parse_thread_id): Use inf->threads.
	* x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 16:13:23 +00:00
Pedro Alves c4c17fb0f5 Fix follow_exec latent problem
A following commit to make each inferior have its own thread list
exposes a problem with bf93d7ba99 ("Add thread after updating gdbarch
when exec'ing"), which is that we can't defer adding the thread
because that breaks try_open_exec_file which deep inside ends up
calling inferior_thread():

 #5  0x0000000000637c78 in internal_error(char const*, int, char const*, ...) (file=0xc151f8 "src/gdb/thread.c", line=165, fmt=0xc15180 "%s: Assertion `%s' failed.") at src/gdb/common/errors.c:55
 #6  0x00000000008a3d80 in inferior_thread() () at src/gdb/thread.c:165
 #7  0x0000000000456f91 in try_thread_db_load_1(thread_db_info*) (info=0x277eb00) at src/gdb/linux-thread-db.c:830
 #8  0x0000000000457554 in try_thread_db_load(char const*, int) (library=0xb01a4f "libthread_db.so.1", check_auto_load_safe=0)
     at src/gdb/linux-thread-db.c:1002
 #9  0x0000000000457861 in try_thread_db_load_from_sdir() () at src/gdb/linux-thread-db.c:1079
 #10 0x0000000000457b72 in thread_db_load_search() () at src/gdb/linux-thread-db.c:1134
 #11 0x0000000000457d29 in thread_db_load() () at src/gdb/linux-thread-db.c:1192
 #12 0x0000000000457e51 in check_for_thread_db() () at src/gdb/linux-thread-db.c:1244
 #13 0x0000000000457ed2 in thread_db_new_objfile(objfile*) (objfile=0x270ff60) at src/gdb/linux-thread-db.c:1273
 #14 0x000000000045a92e in std::_Function_handler<void (objfile*), void (*)(objfile*)>::_M_invoke(std::_Any_data const&, objfile*&&) (__functor=..., __args#0=@0x7ffef3efe140: 0x270ff60) at /usr/include/c++/7/bits/std_function.h:316
 #15 0x00000000007bbebf in std::function<void (objfile*)>::operator()(objfile*) const (this=0x24e1d18, __args#0=0x270ff60)
     at /usr/include/c++/7/bits/std_function.h:706
 #16 0x00000000007bba86 in gdb::observers::observable<objfile*>::notify(objfile*) const (this=0x117ce80 <gdb::observers::new_objfile>, args#0=0x270ff60) at src/gdb/common/observable.h:106
 #17 0x0000000000856000 in symbol_file_add_with_addrs(bfd*, char const*, symfile_add_flags, section_addr_info*, objfile_flags, objfile*) (abfd=0x1d7dae0, name=0x254bfc0 "/ho

The problem is latent currently because inferior_thread() at that
point manages to return a thread, even though it's the wrong one (of
the old inferior).

The problem originally fixed by bf93d7ba99 was:

    (...) we should avoid doing register reads
    after a process does an exec and before we've updated that inferior's
    gdbarch.  Otherwise, we may interpret the registers using the wrong
    architecture.

    (...) The call to "add_thread" done just after adding the inferior is
    problematic, because it ends up reading the registers (because the ptid
    is re-used, we end up doing a switch_to_thread to it, which tries to
    update stop_pc). (...)

The register-reading issue is no longer a problem nowadays, ever since
switch_to_thread stopped reading the stop_pc in git commit
f2ffa92bbc ("gdb: Eliminate the 'stop_pc' global").

So this commit basically reverts bf93d7ba99.

gdb/ChangeLog:
2018-11-22  Pedro Alves  <palves@redhat.com>

	* infrun.c (follow_exec) <set follow-exec new>: Add thread and
	switch to it before calling into try_open_exec_file.
2018-11-22 16:12:54 +00:00
Pedro Alves 151bb4a505 Avoid find_thread_ptid with null_ptid
With a following patch, find_thread_ptid will first find the inferior
for the passed-in ptid, using find_inferior_pid, and then look for the
thread in that inferior's thread list.  If we pass down null_ptid to
find_thread_ptid then that means we'll end up passing 0 to
find_inferior_pid, which hits this assertion:

>   struct inferior *
>   find_inferior_pid (int pid)
>   {
>     struct inferior *inf;
>
>     /* Looking for inferior pid == 0 is always wrong, and indicative of
>	a bug somewhere else.  There may be more than one with pid == 0,
>	for instance.  */
>     gdb_assert (pid != 0);

This patch prepares for the change, by avoiding passing down null_ptid
to find_thread_ptid or to functions that naturally use it, such as the
target_pid_to_str call in inferior.c:add_inferior.  In that latter
case, the patch changes GDB output,

from:
 (gdb) add-inferior
 [New inferior 2 (process 0)]

to:
 (gdb) add-inferior
 [New inferior 2]

which seems like a good change to me.  It might not even make sense to
talk about "process" for the current target, for example.

The python_on_normal_stop change ends up avoiding looking up the
same thread twice (inferior_thread also does a look up).

gdb/ChangeLog:
2018-11-22  Pedro Alves  <palves@redhat.com>

	* cli/cli-interp.c (cli_on_user_selected_context_changed): Use
	inferior_thread instead of find_thread_ptid, and only when
	inferior_ptid is not null_ptid.
	* inferior.c (add_inferior): Don't include target_pid_to_str
	output when the inferior is not started.
	* python/py-inferior.c (python_on_normal_stop): Don't use
	find_thread_ptid.
	(tui_on_user_selected_context_changed): Use inferior_thread
	instead of find_thread_ptid, and only when inferior_ptid is not
	null_ptid.
2018-11-22 16:09:12 +00:00
Benno Fünfstück 1c97054b87 Make command-repeat work after gdb.execute
Since commit

  56bcdbea2b ("Let gdb.execute handle multi-line commands")

command repetition after using the `gdb.execute` Python function
fails (the previous command is not repeated anymore). This happens
because read_command_lines_1 sets dont_repeat, but the call to
prevent_dont_repeat in execute_gdb_command is later.

The fix is to move the call to prevent_dont_repeat to the beginning of
the function.

Tested on my laptop (ArchLinux-x86_64).

gdb/ChangeLog:

	PR python/23714
	* gdb/python/python.c (execute_gdb_command): Call
	prevent_dont_repeat earlier to avoid affecting dont_repeat.

gdb/testuite/ChangeLog:

	PR python/23714
	* gdb.python/python.exp: Test command repetition after
	gdb.execute.
2018-11-21 17:06:05 +00:00
Andrew Burgess b5ffee3181 gdb/riscv: Add target description support
This commit adds target description support for riscv.

I've used the split feature approach for specifying the architectural
features, and the CSR feature is auto-generated from the riscv-opc.h
header file.

If the target doesn't provide a suitable target description then GDB
will build one by looking at the bfd headers.

This commit does not implement target description creation for the
Linux or FreeBSD native targets, both of these will need to add
read_description methods into their respective target classes, which
probe the target features, and then call
riscv_create_target_description to build a suitable target
description.  Until this is done Linux and FreeBSD will get the same
default target description based on the bfd that bare-metal targets
get.

I've only added feature descriptions for 32 and 64 bit registers, 128
bit registers (for RISC-V) are not supported in the reset of GDB yet.

This commit removes the special reading of the MISA register in order
to establish the target features, this was only used for figuring out
the f-register size, and even that wasn't done consistently.  We now
rely on the target to tell us what size of registers it has (or look
in the BFD as a last resort).  The result of this is that we should
now support RV64 targets with 32-bit float, though I have not
extensively tested this combination yet.

	* Makefile.in (ALL_TARGET_OBS): Add arch/riscv.o.
	(HFILES_NO_SRCDIR): Add arch/riscv.h.
	* arch/riscv.c: New file.
	* arch/riscv.h: New file.
	* configure.tgt: Add cpu_obs list of riscv, move riscv-tdep.o into
	this list, and add arch/riscv.o.
	* features/Makefile: Add riscv features.
	* features/riscv/32bit-cpu.c: New file.
	* features/riscv/32bit-cpu.xml: New file.
	* features/riscv/32bit-csr.c: New file.
	* features/riscv/32bit-csr.xml: New file.
	* features/riscv/32bit-fpu.c: New file.
	* features/riscv/32bit-fpu.xml: New file.
	* features/riscv/64bit-cpu.c: New file.
	* features/riscv/64bit-cpu.xml: New file.
	* features/riscv/64bit-csr.c: New file.
	* features/riscv/64bit-csr.xml: New file.
	* features/riscv/64bit-fpu.c: New file.
	* features/riscv/64bit-fpu.xml: New file.
	* features/riscv/rebuild-csr-xml.sh: New file.
	* riscv-tdep.c: Add 'arch/riscv.h' include.
	(riscv_gdb_reg_names): Delete.
	(csr_reggroup): New global.
	(struct riscv_register_alias): Delete.
	(struct riscv_register_feature): New structure.
	(riscv_register_aliases): Delete.
	(riscv_xreg_feature): New global.
	(riscv_freg_feature): New global.
	(riscv_virtual_feature): New global.
	(riscv_csr_feature): New global.
	(riscv_create_csr_aliases): New function.
	(riscv_read_misa_reg): Delete.
	(riscv_has_feature): Delete.
	(riscv_isa_xlen): Simplify, just return cached xlen.
	(riscv_isa_flen): Simplify, just return cached flen.
	(riscv_has_fp_abi): Update for changes in struct gdbarch_tdep.
	(riscv_register_name): Update to make use of tdesc_register_name.
	Look up xreg and freg names in the new globals riscv_xreg_feature
	and riscv_freg_feature.  Don't supply csr aliases here.
	(riscv_fpreg_q_type): Delete.
	(riscv_register_type): Use tdesc_register_type in almost all
	cases, override the returned type in a few specific cases only.
	(riscv_print_one_register_info): Handle errors reading registers.
	(riscv_register_reggroup_p): Use tdesc_register_in_reggroup_p for
	registers that are otherwise unknown to GDB.  Also check the
	csr_reggroup.
	(riscv_print_registers_info): Remove assert about upper register
	number, and use gdbarch_register_reggroup_p instead of
	short-cutting.
	(riscv_find_default_target_description): New function.
	(riscv_check_tdesc_feature): New function.
	(riscv_add_reggroups): New function.
	(riscv_setup_register_aliases): New function.
	(riscv_init_reggroups): New function.
	(_initialize_riscv_tdep): Add calls to setup CSR aliases, and
	setup register groups.  Register new riscv debug variable.
	* riscv-tdep.h: Add 'arch/riscv.h' include.
	(struct gdbarch_tdep): Remove abi union, and add
	riscv_gdbarch_features field.  Remove cached quad floating point
	type, and provide initialisation for double type field.
	* target-descriptions.c (maint_print_c_tdesc_cmd): Add riscv to
	the list of targets using the feature based target descriptions.
	* NEWS: Mention target description support.

gdb/doc/ChangeLog:

	* gdb.texinfo (Standard Target Features): Add RISC-V Features
	sub-section.
2018-11-21 13:09:50 +00:00
Pedro Alves 38139a9681 valops.c: Overload resolution code: Rename parameters/locals
While looking over this code, I thought the names of the parameters to
find_oload_champ and related functions and locals were a bit too
cryptic.  For example, FN_LIST holds methods, not free functions.
Free-functions are in OLOAD_SYMS.

This patch renames parameters/variables to the more obvious
methods/xmethods/functions instead.

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

	* valops.c (find_method_list, value_find_oload_method_list)
	(find_overload_match, find_oload_champ): Rename parameters and
	locals.
2018-11-21 12:27:29 +00:00
Pedro Alves 85cca2bcbc valops.c: Some more gdb::array_view
This commit replaces some more use of pointer+length pairs in the
overload resolution code with gdb::array_view.

find_oload_champ's interface is simplified/normalized: the xmethods
parameter is converted from std::vector to array pointer, and then the
num_fns parameter is always passed in, no matter the array which is
non-NULL.  I tweaked the formatting of callers a little bit here and
there so that the 3 optional parameters are all in the same line.  (I
tried making the 3 optional array parameters be array_views, but the
resulting code didn't look as nice.)

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

	* valops.c (find_method_list): Replace pointer and length
	parameters with an gdb::array_view.  Adjust.
	(value_find_oload_method_list): Likewise.
	(find_overload_match): Use gdb::array_view for methods list.
	Adjust to find_oload_champ interface change.
	(find_oload_champ): 'xm_worker_vec' parameter now a pointer/array.
	'num_fns' parameter now a size_t.  Eliminate 'fn_count' local.
2018-11-21 12:11:45 +00:00
Pedro Alves 82ceee5014 C++ify badness_vector, fix leaks
badness_vector is currently an open coded vector.  This reimplements
it as a std::vector.

This fixes a few leaks as well:

 - find_oload_champ is leaking every badness vector calculated bar the
   one returned.

 - bv->rank is always leaked, since callers of rank_function only
   xfree the badness_vector pointer, not bv->rank.

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

	* gdbtypes.c (compare_badness): Change type of parameters to const
	reference.  Adjust to badness_vector being a std::vector now.
	(rank_function): Adjust to badness_vector being a std::vector now.
	* gdbtypes.h (badness_vector): Now a typedef to std::vector.
	(LENGTH_MATCH): Delete.
	(compare_badness): Change type of parameters to const reference.
	(rank_function): Return a badness_vector by value now.
	(find_overload_match): Adjust to badness_vector being a
	std::vector now.  Remove cleanups.
	(find_oload_champ_namespace): 'oload_champ_bv' parameter now a
	badness_vector pointer.
	(find_oload_champ_namespace_loop): 'oload_champ_bv' parameter now
	a badness_vector pointer.  Adjust to badness_vector being a
	std::vector now.  Remove cleanups.
	(find_oload_champ): 'oload_champ_bv' parameter now
	a badness_vector pointer.  Adjust to badness_vector being a
	std::vector now.  Remove cleanups.
2018-11-21 12:06:51 +00:00
Pedro Alves 0891c3cc13 Eliminate make_symbol_overload_list-related globals & cleanup
This gets rid of a few globals and a cleanup.

make_symbol_overload_list & friends currently maintain a global
open-coded vector.  Reimplement that with a std::vector, trickled down
through the functions.  Rename a few functions from "make_" to "add_"
for clarity.

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

	* cp-support.c (sym_return_val_size, sym_return_val_index)
	(sym_return_val): Delete.
	(overload_list_add_symbol): Add std::vector parameter.  Adjust to
	add to the vector.
	(make_symbol_overload_list): Adjust to return a std::vector
	instead of maintaining a global open coded vector.
	(make_symbol_overload_list_block): Add std::vector parameter.
	(make_symbol_overload_list_block): Rename to ...
	(add_symbol_overload_list_block): ... this and add std::vector
	parameter.
	(make_symbol_overload_list_namespace): Rename to ...
	(add_symbol_overload_list_namespace): ... this and add std::vector
	parameter.
	(make_symbol_overload_list_adl_namespace): Rename to ...
	(add_symbol_overload_list_adl_namespace): ... this and add
	std::vector parameter.
	(make_symbol_overload_list_adl): Delete.
	(add_symbol_overload_list_adl): New.
	(make_symbol_overload_list_using): Rename to ...
	(add_symbol_overload_list_using): ... this and add std::vector
	parameter.
	(make_symbol_overload_list_qualified): Rename to ...
	(add_symbol_overload_list_qualified): ... this and add std::vector
	parameter.
	* cp-support.h: Include "common/array-view.h" and <vector>.
	(make_symbol_overload_list): Change return type to std::vector.
	(make_symbol_overload_list_adl): Delete declaration.
	(add_symbol_overload_list_adl): New declaration.
	* valops.c (find_overload_match): Local 'oload_syms' now a
	std::vector.
	(find_oload_champ_namespace): 'oload_syms' parameter now a
	std::vector pointer.
	(find_oload_champ_namespace_loop): 'oload_syms' parameter now a
	std::vector pointer.  Adjust to new make_symbol_overload_list
	interface.
2018-11-21 12:06:36 +00:00
Pedro Alves 6b1747cd13 invoke_xmethod & array_view
This replaces more pointer+length with gdb::array_view.  This time,
around invoke_xmethod, and then propagating the fallout around, which
inevitably leaks to the overload resolution code.

There are several places in the code that want to grab a slice of an
array, by advancing the array pointer, and decreasing the length
pointer.  This patch introduces a pair of new
gdb::array_view::slice(...) methods to make that convenient and clear.
Unit test included.

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

	* common/array-view.h (array_view::splice(size_type, size_t)): New.
	(array_view::splice(size_type)): New.
	* eval.c (eval_call, evaluate_funcall): Adjust to use array_view.
	* extension.c (xmethod_worker::get_arg_types): Adjust to return an
	std::vector.
	(xmethod_worker::get_result_type): Adjust to use gdb::array_view.
	* extension.h: Include "common/array-view.h".
	(xmethod_worker::invoke): Adjust to use gdb::array_view.
	(xmethod_worker::get_arg_types): Adjust to return an std::vector.
	(xmethod_worker::get_result_type): Adjust to use gdb::array_view.
	(xmethod_worker::do_get_arg_types): Adjust to use std::vector.
	(xmethod_worker::do_get_result_type): Adjust to use
	gdb::array_view.
	* gdbtypes.c (rank_function): Adjust to use gdb::array_view.
	* gdbtypes.h: Include "common/array-view.h".
	(rank_function): Adjust to use gdb::array_view.
	* python/py-xmethods.c (python_xmethod_worker::invoke)
	(python_xmethod_worker::do_get_arg_types)
	(python_xmethod_worker::do_get_result_type)
	(python_xmethod_worker::invoke): Adjust to new interfaces.
	* valarith.c (value_user_defined_cpp_op, value_user_defined_op)
	(value_x_binop, value_x_unop): Adjust to use gdb::array_view.
	* valops.c (find_overload_match, find_oload_champ_namespace)
	(find_oload_champ_namespace_loop, find_oload_champ): Adjust to use
	gdb:array_view and the new xmethod_worker interfaces.
	* value.c (result_type_of_xmethod, call_xmethod): Adjust to use
	gdb::array_view.
	* value.h (find_overload_match, result_type_of_xmethod)
	(call_xmethod): Adjust to use gdb::array_view.
	* unittests/array-view-selftests.c: Add slicing tests.
2018-11-21 12:06:20 +00:00
Pedro Alves e71585ffe2 Use gdb:array_view in call_function_by_hand & friends
This replaces a few uses of pointer+length with gdb::array_view, in
call_function_by_hand and related code.

Unfortunately, due to -Wnarrowing, there are places where we can't
brace-initialize an gdb::array_view without an ugly-ish cast.  To
avoid the cast, this patch introduces a gdb::make_array_view function.
Unit tests included.

This patch in isolation may not look so interesting, due to
gdb::make_array_view uses, but I think it's still worth it.  Some of
the gdb::make_array_view calls disappear down the series, and others
could be eliminated with more (non-trivial) gdb::array_view
detangling/conversion (e.g. code around eval_call).  See this as a "we
have to start somewhere" patch.

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

	* ada-lang.c (ada_evaluate_subexp): Adjust to pass an array_view.
	* common/array-view.h (make_array_view): New.
	* compile/compile-object-run.c (compile_object_run): Adjust to
	pass an array_view.
	* elfread.c (elf_gnu_ifunc_resolve_addr): Adjust.
	* eval.c (eval_call): Adjust to pass an array_view.
	(evaluate_subexp_standard): Adjust to pass an array_view.
	* gcore.c (call_target_sbrk): Adjust to pass an array_view.
	* guile/scm-value.c (gdbscm_value_call): Likewise.
	* infcall.c (push_dummy_code): Replace pointer + size parameters
	with an array_view parameter.
	(call_function_by_hand, call_function_by_hand_dummy): Likewise and
	adjust.
	* infcall.h: Include "common/array-view.h".
	(call_function_by_hand, call_function_by_hand_dummy): Replace
	pointer + size parameters with an array_view parameter.
	* linux-fork.c (inferior_call_waitpid): Adjust to use array_view.
	* linux-tdep.c (linux_infcall_mmap): Likewise.
	* objc-lang.c (lookup_objc_class, lookup_child_selector)
	(value_nsstring, print_object_command): Likewise.
	* python/py-value.c (valpy_call): Likewise.
	* rust-lang.c (rust_evaluate_funcall): Likewise.
	* spu-tdep.c (flush_ea_cache): Likewise.
	* valarith.c (value_x_binop, value_x_unop): Likewise.
	* valops.c (value_allocate_space_in_inferior): Likewise.
	* unittests/array-view-selftests.c (run_tests): Add
	gdb::make_array_view test.
2018-11-21 11:55:11 +00:00
Andrew Burgess d63095c426 gdb: Use string_printf to format int fields instead of a fixed size buffer
This patch removes a FIXME comment from cli-out.c, now instead of
formatting integers into a fixed size buffer we build a std::string
and extract the formatted integer from that.

The old code using a fixed size buffer was probably fine (the integer
was not going to overflow it) and probably slightly more efficient
(avoids building a std::string) however, given we already have utility
code in GDB that will allow the 'FIXME' comment to be removed, it
seems like an easy improvement.

gdb/ChangeLog:

	* cli-out.c (cli_ui_out::do_field_int): Use string_printf rather
	than a fixed size buffer.
2018-11-20 23:01:42 +00:00
Andrew Burgess 1871a62daf gdb: Respect field width and alignment for 'fmt' fields in CLI output
Currently the method 'cli_ui_out::do_field_fmt' has this comment:

  /* This is the only field function that does not align.  */

The reality is even slightly worse, the 'fmt' field type doesn't
respect either the field alignment or the field width.  In at least
one place in GDB we attempt to work around this lack of respect for
field width by adding additional padding manually.  But, as is often
the case, this is leading to knock on problems.

Conside the output for 'info breakpoints' when a breakpoint has
multiple locations.  This example is taken from the testsuite, from
test gdb.opt/inline-break.exp:

  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  1       breakpoint     keep y   <MULTIPLE>
  1.1                     y     0x00000000004004ae in func4b at /src/gdb/testsuite/gdb.opt/inline-break.c:64
  1.2                     y     0x0000000000400682 in func4b at /src/gdb/testsuite/gdb.opt/inline-break.c:64

The miss-alignment of the fields shown here is exactly as GDB
currently produces.

With this patch 'fmt' style fields are now first written into a
temporary buffer, and then written out as a 'string' field.  The
result is that the field width, and alignment should now be respected.
With this patch in place the output from GDB now looks like this:

  (gdb) info breakpoints
  Num     Type           Disp Enb Address            What
  1       breakpoint     keep y   <MULTIPLE>
  1.1                         y   0x00000000004004ae in func4b at /src/gdb/testsuite/gdb.opt/inline-break.c:64
  1.2                         y   0x0000000000400682 in func4b at /src/gdb/testsuite/gdb.opt/inline-break.c:64

This patch has been tested on x86-64/Linux with no regressions,
however, the testsuite doesn't always spot broken output formatting or
alignment.  I have also audited all uses of 'fmt' fields that I could
find, and I don't think there are any other places that specifically
try to work around the lack of width/alignment, however, I could have
missed something.

gdb/ChangeLog:

	* breakpoint.c (print_one_breakpoint_location): Reduce whitespace,
	and remove insertion of extra spaces in GDB's output.
	* cli-out.c (cli_ui_out::do_field_fmt): Update header comment.
	Layout field into a temporary buffer, and then output it as a
	string field.

gdb/testsuite/ChangeLog:

	* gdb.opt/inline-break.exp: Add test that info breakpoint output
	is correctly aligned.
2018-11-20 23:01:42 +00:00
Philippe Waroquiers 604c4ca9f3 NEWS: Document the language choice by 'info [types|functions|variables]|rbreak'.
gdb/ChangeLog
2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Document the language choice done by
	'info [types|functions|variables]|rbreak'.
2018-11-20 22:44:50 +01:00
Philippe Waroquiers 20813a0b7b Document language choice in 'info [functions|variables|types]|rbreak' commands
doc/ChangeLog
2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Examining the Symbol Table): Document language choice
	for 'info types|functions|variables' commands.
	(Setting Breakpoints): Document language choice to print
	the functions in which a breakpoint is set.
2018-11-20 22:44:02 +01:00
Philippe Waroquiers fb5e1ed910 Add a test to verify info [functions|variables|types]|rbreak respect language_mode.
2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.ada/info_auto_lang.exp: New testcase.
	* gdb.ada/info_auto_lang/global_pack.ads: New file.
	* gdb.ada/info_auto_lang/proc_in_ada.adb: New file.
	* gdb.ada/info_auto_lang/some_c.c: New file.
2018-11-20 22:42:31 +01:00
Philippe Waroquiers 43d397ca8f Use scoped_switch_to_sym_language_if_auto in symtab.c to switch language.
Use scoped_switch_to_sym_language_if_auto in treg_matches_sym_type_name to
replace the local logic that was doing the same as the new class
scoped_switch_to_sym_language_if_auto.

Use scoped_switch_to_sym_language_if_auto inside print_symbol_info, so
that symbol information is printed in the symbol language when
language mode is auto.
This modifies the behaviour of the test dw2-case-insensitive.exp,
as the function FUNC_lang is now printed with the Fortran syntax
(as declared in the .S file).

gdb/ChangeLog
2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* symtab.c (treg_matches_sym_type_name): Use
	scoped_switch_to_sym_language_if_auto instead of local logic.
	(print_symbol_info): Use scoped_switch_to_sym_language_if_auto
	to switch to SYM language when language mode is auto.

gdb/testsuite/ChangeLog
2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.dwarf2/dw2-case-insensitive.exp: Update due to auto switch to
	FUNC_lang language syntax.
2018-11-20 22:41:08 +01:00
Philippe Waroquiers 9e6a1ab665 Add class scoped_switch_to_sym_language_if_auto.
The class scoped_switch_to_sym_language_if_auto allows to switch in a scope
the current language to the language of a symbol when language mode is
set to auto.

2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* language.h (scoped_switch_to_sym_language_if_auto): New class.
2018-11-20 22:39:08 +01:00
Philippe Waroquiers beddd67132 Test case for 'info variables|functions' with minimal symbols.
2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/info_minsym.c: New file.
	* gdb.base/info_minsym.exp: New file.
2018-11-20 21:56:06 +01:00
Philippe Waroquiers a8462bbf0b Fix regression 'info variables' does not show minimal symbols.
12615cba84 Add [-q] [-t TYPEREGEXP] [NAMEREGEXP] args to info [args|functions|locals|variables]
introduced a regression that minimal symbols were not listed anymore, due to a wrong
condition checking the absence of a type regexp in the loop scanning the minimal symbols.

Instead, before entering the loop scanning the minimal symbols, check that we
do not have a type regexp, as we will never match a minimal symbol with
this type regexp.

With the fix in this patch, for this part of the code, we basically go back
to the GDB 8.2 logic, with just the addition of
  && !treg.has_value ())
to 'enter' in the minsym case.
This should ensure that at least there is no regression compared to 8.2,
when not using the new type matching argument, as there was no treg in 8.2.

2018-11-20  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* symtab.c (search_symbols): Properly check absence of type regexp
	before entering the loop scanning the minimal symbols.
2018-11-20 21:54:39 +01:00
Pedro Alves 4399bce99b Fix gdb/ChangeLog formatting and date 2018-11-20 19:04:14 +00:00
John Darrington c3247a98cd GDB: S12Z: new function s12z_extract_return_value
Make gdb aware of the return values of functions which
return in registers.

gdb/ChangeLog:
* s12z-tdep.c (s12z_extract_return_value): New function.
  (inv_reg_perm) New array.
  (s12z_return_value): Populate readbuf if non-null.
2018-11-20 18:55:02 +01:00
Eli Zaretskii 2fa1b3191e Fix previous change in filestuff.c
gdb/ChangeLog:

	* common/filestuff.c (O_NOINHERIT): Define if not defined.
2018-11-20 19:23:51 +02:00
Eli Zaretskii 970d89d8fd Avoid "Invalid parameter passed to C runtime function" warning
This warning was displayed by OutputDebugString on MinGW when
GDB was being debugged natively.

gdb/ChangeLog:

	* common/filestuff.c (gdb_fopen_cloexec): Disable use of "e" mode
	with 'fopen' also if O_CLOEXEC is equal to O_NOINHERIT, to cater
	to MinGW fixed by Gnulib.
2018-11-20 18:49:43 +02:00
John Darrington 7b5227d132 GDB: S12Z: Add assertion
gdb/ChangeLog:

	* s12z-tdep.c (s12z_frame_cache): Add an assertion.
2018-11-20 07:36:24 +01:00
Simon Marchi dbe4e6545e Remove displaced_step_inferior_state::next
Commit

  39a36629f6 ("Use std::forward_list for displaced_step_inferior_states")

missed removing the "next" field, while changing the hand-made linked
list in favor of std::forward_list.  This patch fixes that.

gdb/ChangeLog:

	* infrun.c (displaced_step_inferior_state) <next>: Remove.
2018-11-19 22:35:19 -05:00
Tom Tromey 0614ef69be Change get_filename_and_charpos to return void
The return value from get_filename_and_charpos is never used, so this
patch changes it to return void.

gdb/ChangeLog
2018-11-19  Tom Tromey  <tom@tromey.com>

	* source.c (get_filename_and_charpos): Return void.
2018-11-19 15:45:28 -07:00
Simon Marchi 261f6f7962 Fix inaccuracies in "info skip" help
"help info skip" uses "skip info" in its examples, which is not the same
(it ends up creating new skips).  Also, the Type column that is referred
to doesn't exist today.

gdb/ChangeLog:

	* skip.c (_initialize_step_skip): Fix "info skip" help.
2018-11-19 17:27:13 -05:00
Tom Tromey 73fc52c4cc Handle TYPE_CODE_PTR when printing Rust types
This changes the Rust type printers to handle TYPE_CODE_PTR.  The
current approach is not ideal, because currently the code can't
distinguish between mut and const, or between pointers and references.
(These are debuginfo deficiencies, for which there are rustc bugs on
file.)

Meanwhile, this at least clears up the case seen in PR rust/23625.

Tested on x86-64 Fedora 28.  The nightly compiler gives the best
results, but I regression-tested with stable and beta as well.

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

	PR rust/23625:
	* rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR.

gdb/testsuite/ChangeLog
2018-11-19  Tom Tromey  <tom@tromey.com>

	PR rust/23625:
	* gdb.rust/simple.exp: Add ptype test.  Update expected output.
	* gdb.rust/expr.exp: Update expected output.  Change one test.
2018-11-19 11:19:01 -07:00
Tom Tromey 994b876a51 Fix gdb.rust/simple.rs for more recent compilers
gdb.rust/simple.exp will fail when run with a recent version of rustc.
This patch fixes the test case so that it will continue to run.

Tested on x86-64 Fedora 28.

I also temporarily backed out the rust-lang.c from
commit 098b2108a2, and verified that
this updated test still would have provoked the original bug.

gdb/testsuite/ChangeLog
2018-11-19  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.rs: Don't initialize empty_enum_value.
2018-11-19 11:07:07 -07:00
Simon Marchi 39a36629f6 Use std::forward_list for displaced_step_inferior_states
Use std::forward_list instead of manually implemented list.  This
simplifies a bit the code, especially around removal.

Regtested on the buildbot.  There are some failures as always, but I
think they are unrelated.

gdb/ChangeLog:

	* infrun.c (displaced_step_inferior_states): Change type to
	std::forward_list.
	(get_displaced_stepping_state): Adjust.
	(displaced_step_in_progress_any_inferior): Adjust.
	(add_displaced_stepping_state): Adjust.
	(remove_displaced_stepping_state): Adjust.
2018-11-19 11:57:38 -05:00
John Darrington 32641fa925 GDB: Add ChangeLog entry inadvertently omitted from commit. 2018-11-19 17:36:42 +01:00
Pedro Alves 6769f2765d gdb.base/warning.exp tweaks
#1- Check that the warning is emitted.

#2- Avoid overriding INTERNAL_GDBFLAGS, as per documentated in
    gdb/testsuite/README:

 ~~~
 The testsuite does not override a value provided by the user.
 ~~~

We don't actually need to tweak INTERNAL_GDBFLAGS, we just need to
append out -data-directory to GDBFLAGS, because each passed
-data-directory option leads to a call to the warning:

 $ ./gdb -data-directory=foo -data-directory=bar
 Warning: foo: No such file or directory.
 Warning: bar: No such file or directory.
 [...]

gdb/ChangeLog
2018-11-19  Pedro Alves  <palves@redhat.com>

	* gdb.base/warning.exp: Don't override INTERNAL_FLAGS.  Use
	gdb_spawn_with_cmdline_opts instead of gdb_start.  Check that we
	see the expected warning.
2018-11-19 15:08:46 +00:00
Tom Tromey c2a6c5da37 Fix ia64-linux-nat.c
PR build/23814 points out that ia64-linux-nat.c will not compile any
more.  This patch fixes the problem.  Thanks to Andreas Schwab for
trying the patch.

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

	PR build/23814:
	* target-delegates.c: Rebuild.
	* ia64-linux-nat.c (class ia64_linux_nat_target)
	<have_steppable_watchpoint>: Use override.  Return true, not 1.
	(ia64_linux_nat_target::can_use_hw_breakpoint): Rename.  Remove
	"self" argument.
	(ia64_linux_nat_target::low_new_thread): Rename.
	(class ia64_linux_nat_target) <read_description>: Don't declare.
	* target.h (struct target_ops) <have_steppable_watchpoint>: Return
	bool.
2018-11-18 09:30:55 -07:00
Alan Hayward 38a72da0f1 Aarch64: Fix segfault when casting dummy calls
The following will segfault on aarch64 if foo is in another object,
was compiled as c++ and has no debug symbols:
(gdb) p (int)foo()

This is because aarch64_push_dummy_call determines the return type
of the function and then does not check for null pointer.

A null pointer for the return type means the call has no debug
information.  For the code to get here, then the call must have
been cast, otherwise we'd error out sooner.  In the case of a
no-debug-info call cast, the return type is the type the user
had cast the call to, but we do not have that information
available here.

However, aarch64_push_dummy_call only requires the return type in
order to calculate lang_struct_return. This information is available
in the return_method enum. The fix is to simply use this instead.

Adds testcase to check calls across objects, with all combinations
of c, c++, debug and no debug.

gdb/ChangeLog:

	PR gdb/22736:
	* aarch64-tdep.c (aarch64_push_dummy_call): Remove
	lang_struct_return code.

gdb/testsuite/ChangeLog:

	PR gdb/22736:
	* gdb.cp/infcall-nodebug-lib.c: New test.
	* gdb.cp/infcall-nodebug-main.c: New test.
	* gdb.cp/infcall-nodebug.exp: New file.
2018-11-16 13:45:38 +00:00
Alan Hayward cf84fa6bcf Pass return_method to _push_dummy_call
gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_push_dummy_call): Replace arg with
	return_method.
	* alpha-tdep.c (alpha_push_dummy_call): Likewise.
	* amd64-tdep.c (amd64_push_arguments): Likewise.
	(amd64_push_dummy_call): Likewise.
	* amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise.
	* arc-tdep.c (arc_push_dummy_call): Likewise.
	* arm-tdep.c (arm_push_dummy_call): Likewise.
	* avr-tdep.c (avr_push_dummy_call): Likewise.
	* bfin-tdep.c (bfin_push_dummy_call): Likewise.
	* cris-tdep.c (cris_push_dummy_call): Likewise.
	* csky-tdep.c (csky_push_dummy_call): Likewise.
	* frv-tdep.c (frv_push_dummy_call): Likewise.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbarch.sh (gdbarch_push_dummy_call): Replace arg with
	return_method.
	* h8300-tdep.c (h8300_push_dummy_call): Likewise.
	* hppa-tdep.c (hppa32_push_dummy_call): Likewise.
	(hppa64_push_dummy_call): Likewise.
	* i386-darwin-tdep.c (i386_darwin_push_dummy_call): Likewise.
	* i386-tdep.c (i386_push_dummy_call): Likewise.
	* ia64-tdep.c (ia64_push_dummy_call): Likewise.
	* infcall.c (call_function_by_hand_dummy): Likewise.
	* iq2000-tdep.c (iq2000_push_dummy_call): Likewise.
	* lm32-tdep.c (lm32_push_dummy_call): Likewise.
	* m32c-tdep.c (m32c_push_dummy_call): Likewise.
	* m32r-tdep.c (m32r_push_dummy_call): Likewise.
	* m68hc11-tdep.c (m68hc11_push_dummy_call): Likewise.
	* m68k-tdep.c (m68k_push_dummy_call): Likewise.
	* mep-tdep.c (mep_push_dummy_call): Likewise.
	* mips-tdep.c (mips_eabi_push_dummy_call): Likewise.
	(mips_n32n64_push_dummy_call): Likewise.
	(mips_o32_push_dummy_call): Likewise.
	(mips_o64_push_dummy_call): Likewise.
	* mn10300-tdep.c (mn10300_push_dummy_call): Likewise.
	* msp430-tdep.c (msp430_push_dummy_call): Likewise.
	* nds32-tdep.c (nds32_push_dummy_call): Likewise.
	* nios2-tdep.c (nios2_push_dummy_call): Likewise.
	* or1k-tdep.c (or1k_push_dummy_call): Likewise.
	* ppc-sysv-tdep.c (ppc_sysv_abi_push_dummy_call): Likewise.
	(ppc64_sysv_abi_push_dummy_call): Likewise.
	* ppc-tdep.h (ppc_sysv_abi_push_dummy_call): Likewise.
	(ppc64_sysv_abi_push_dummy_call): Likewise.
	* riscv-tdep.c (riscv_push_dummy_call): Likewise.
	* rl78-tdep.c (rl78_push_dummy_call): Likewise.
	* rs6000-aix-tdep.c (rs6000_push_dummy_call): Likewise.
	* rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Likewise.
	* rx-tdep.c (rx_push_dummy_call): Likewise.
	* s390-tdep.c (s390_push_dummy_call): Likewise.
	* score-tdep.c (score_push_dummy_call): Likewise.
	* sh-tdep.c (sh_push_dummy_call_fpu): Likewise.
	(sh_push_dummy_call_nofpu): Likewise.
	* sparc-tdep.c (sparc32_store_arguments): Likewise.
	(sparc32_push_dummy_call): Likewise.
	* sparc64-tdep.c (sparc64_store_arguments): Likewise.
	(sparc64_push_dummy_call): Likewise.
	* spu-tdep.c (spu_push_dummy_call): Likewise.
	* tic6x-tdep.c (tic6x_push_dummy_call): Likewise.
	* tilegx-tdep.c (tilegx_push_dummy_call): Likewise.
	* v850-tdep.c (v850_push_dummy_call): Likewise.
	* vax-tdep.c (vax_push_dummy_call): Likewise.
	* xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise.
	* xtensa-tdep.c (xtensa_push_dummy_call): Likewise.
2018-11-16 13:45:38 +00:00
Alan Hayward c5ac5cbb5b Use enum for return method for dummy calls
In call_function_by_hand_dummy, struct_return and hidden_first_param_p
are used to represent a single concept. Replace with an enum.

gdb/ChangeLog:

	* gdbarch.sh (enum function_call_return_method): Add enum.
	* gdbarch.h: Regenerate.
	* infcall.c (call_function_by_hand_dummy): Replace vars with enum.
2018-11-16 13:45:38 +00:00
Joel Brobecker f9db0c4c6c Move copy_bitwise unittests to own unittest file
Now that copy_bitwise has been made public, and considering that
its implementation could move to a different file again in the future,
this patch moves its unittest to its own file in gdb/unittests.

gdb/ChangeLog:

        * unittests/copy_bitwise-selftests.c: New file.
        * utils.c (selftests::bits_to_str, selftests::check_copy_bitwise)
        (selftests::copy_bitwise_tests): Delete, moving this code to
        unittests/copy_bitwise-selftests.c instead.
        (_initialize_utils): Do not register copy_bitwise tests.
        * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
        unittests/copy_bitwise-selftests.c.

Tested on x86_64-linux using the official testsuite, but also by
verifying that "maintenance selftests" still runs the copy_bitwise
tests.
2018-11-15 10:53:57 -05:00
Joel Brobecker a99bc3d23c delete ada-lang.c::move_bits, sharing and re-using copy_bitwise instead
This patch deletes ada-lang.c's move_bits function entirely, and
replaces all calls to it by calls to copy_bitwise instead. Because
the latter function was declared locally inside dwarf2loc.c, this
patch also move the function to a common area, and makes it non-static.

gdb/ChangeLog:

        * ada-lang.c (move_bits): Delete. Update all callers to use
        copy_bitwise instead.
        * dwarf2loc.c (copy_bitwise, bits_to_str::bits_to_str)
        (selftests::check_copy_bitwise, selftests::copy_bitwise_tests):
        Move from here to utils.c.
        (_initialize_dwarf2loc): Remove call to register copy_bitwise
        selftests.
        * utils.h (copy_bitwise): Add declaration.
        * utils.c (copy_bitwise, bits_to_str::bits_to_str)
        (selftests::check_copy_bitwise, selftests::copy_bitwise_tests):
        Moved here from dwarf2loc.c.
        (_initialize_utils): Register copy_bitwise selftests.

Tested on x86_64-linux, no regression. Also tested using AdaCore's
testsuite on a collection of small endian and big endian platforms.
2018-11-14 18:18:49 -05:00
Jim Wilson 8b2d40cbba RISC-V: Fix unnamed arg alignment in registers.
For riscv64-linux target, second half of fix for
FAIL: gdb.base/gnu_vector.exp: call add_various_floatvecs

Unnamed arguments with 2*XLEN alignment are passed in aligned register pairs.

	gdb/
	* riscv-tdep.c (struct riscv_arg_info): New field is_unnamed.
	(riscv_call_arg_scalar_int): If unnamed arg with twice xlen alignment,
	then increment next_regnum if odd.
	(riscv_arg_location): New arg is_unnamed.  Set ainfo->is_unnamed.
	(riscv_push_dummy_call): New local ftype.  Call check_typedef to set
	function type.  Pass new arg to riscv_arg_location based on function
	type.
	(riscv_return_value): Pass new arg to riscv_arg_location.
2018-11-14 14:54:10 -08:00
Jim Wilson ef2de9e7eb RISC-V: Handle vector type alignment.
For riscv64-linux target, first half of fix for
FAIL: gdb.base/gnu_vector.exp: call add_various_floatvecs

GCC gives vectors natural aligment based on total size, not element size,
bounded by the maximum supported type alignment.

	gdb/
	* riscv-tdep.c (BIGGEST_ALIGNMENT): New.
	(riscv_type_alignment) <TYPE_CODE_ARRAY>: If TYPE_VECTOR, return min
	of TYPE_LENGTH and BIGGEST_ALIGNMENT.
2018-11-14 14:52:34 -08:00
Jim Wilson 174f8ac8d4 RISC-V: Give stack slots same align as XLEN.
For riscv64-linux target, fixes
FAIL: gdb.base/gnu_vector.exp: call add_many_charvecs

Ensure that stack slots are always the same alignment as XLEN by rounding
up arg align to xlen.

	gdb/
	* riscv-tdep.c (riscv_call_arg_scalar_int): Use std::min when
	setting len.  New local align, set to max of arg align and xlen,
	and pass to first riscv_assign_stack_location call.
2018-11-14 14:51:40 -08:00
Simon Marchi 53a89d6e58 Add completer for skip numbers
Add completer to various commands that accept skip numbers:

  - skip enable
  - skip disable
  - skip delete
  - info skip

These commands also accept ranges, the completer works for that but is
not very smart.  It will suggest invalid ranges, for example when doing
"2-<TAB>" it will suggest "1", which would not result in a valid range.
Also, it will keep suggesting when doing "1-2-<TAB>", even though it's
an invalid syntax.

A future idea would be to make a re-usable and well-tested completer for
numbers and ranges.  I think it could at least be re-used for breakpoint
and thread numbers (for example with the "enable breakpoints" command).

gdb/ChangeLog:

	* skip.c (complete_skip_number): New function.
	(_initialize_step_skip): Add completers to some skip commands.

gdb/testsuite/ChangeLog:

	* gdb.base/skip.exp: Add standard_testfile.  Add "skip delete"
	completer tests.
2018-11-12 10:38:44 -05:00
Tom Tromey eefce37f62 Remove a VEC from remote.c
This removes the VEC from remote_g_packet_data, replacing it with a
std::vector.  This is a bit odd in that this object is never
destroyed, and is obstack-allocated.  I believe a gdbarch is never
destroyed, so this seemed ok.

Tested by the buildbot.

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

	* remote.c (remote_g_packet_guess_s): Remove typedef and DEF_VEC.
	(struct remote_g_packet_data): Derive from allocate_on_obstack.
	<guesses>: Now a std::vector.
	(remote_g_packet_data_init, register_remote_g_packet_guess):
	Update.
	(remote_read_description_p): Update.  Return bool.
	(remote_target::read_description): Update.
	(struct remote_g_packet_guess): Add constructor.
2018-11-09 16:04:03 -07:00
Tom Tromey 2179fbc36d Return scoped_fd from open_source_file and find_and_open_source
This changes open_source_file and find_and_open_source to return
scoped_fd, then updates the callers as appropriate, including using
scoped_fd::to_file.

Tested by the buildbot.

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

	* common/scoped_fd.h (class scoped_fd): Add move constructor and
	move assignment operator.
	* psymtab.c (psymtab_to_fullname): Update.
	* source.h (open_source_file): Return scoped_fd.
	(find_and_open_source): Likewise.
	* source.c (open_source_file): Return scoped_fd.
	(get_filename_and_charpos): Update.
	(print_source_lines_base): Update.  Use scoped_fd::to_file.
	(forward_search_command): Likewise.
	(reverse_search_command): Likewise.
	(find_and_open_source): Return scoped_fd.
	* tui/tui-source.c (tui_set_source_content): Update.  Use
	gdb_file_up.
2018-11-09 15:47:45 -07:00
John Baldwin 9c122c7f9c Fix unsigned overflow in minsyms reader.
Use a ssize_t helper variable for the number of bytes to shrink the
msymbols obstack rather than relying on unsigned overflow to shrink
the size of the obstack.

gdb/ChangeLog:

	* minsyms.c (minimal_symbol_reader::install): Fix unsigned
	overflow.
2018-11-09 11:44:20 -08:00
Pedro Franco de Carvalho 4b905ae1b4 [PowerPC] Document requirements for VSX feature
As suggested in
https://sourceware.org/ml/gdb-patches/2018-10/msg00510.html, this
patch changes the documentation for the VSX tdesc feature to make it
clear that the altivec and FPU features are requirements.

gdb/doc/ChangeLog:
2018-11-09  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.texinfo (PowerPC Features): Document the altivec and fpu
	requirements for the org.gnu.gdb.power.vsx feature.
2018-11-09 16:09:03 -02:00
Hafiz Abid Qadeer 5d762de01c Fix a typo in iconv.m4.
config/
2018-11-09  Hafiz Abid Qadeer  <abidh@codesourcery.com>

	* iconv.m4 (AM_ICONV_LINK): Don't overwrite CPPFLAGS.
	Append $INCICONV to it.

gdb/
2018-11-09  Hafiz Abid Qadeer  <abidh@codesourcery.com>

	* configure: Regenerate.

binutils/
2018-11-09  Hafiz Abid Qadeer  <abidh@codesourcery.com>

	* configure: Regenerate.

intl/
2018-11-09  Hafiz Abid Qadeer  <abidh@codesourcery.com>

	* configure: Regenerate.
2018-11-09 16:08:10 +00:00
Tom de Vries 9325300dc2 [gdb/symtab] Fix language of duplicate static minimal symbol
Consider a test-case with source files msym.c:
...
static int foo (void) { return 1; }
...
and msym_main.c:
...
static int foo (void) { return 2; }
int main (void) { return 0; }
..
compiled as c++ with minimal symbols:
...
$ g++ msym_main.c msym.c
...

With objdump -x we find the two foo symbols prefixed with their corresponding
files in the symbol table:
...
0000000000000000 l    df *ABS*  0000000000000000              msym_main.c
00000000004004c7 l     F .text  000000000000000b              _ZL3foov
0000000000000000 l    df *ABS*  0000000000000000              msym.c
00000000004004dd l     F .text  000000000000000b              _ZL3foov
...

However, when we use gdb to print info on foo, both foos are listed, but we
get one symbol mangled and one symbol demangled:
...
$ gdb ./a.out -batch -ex "info func foo"
All functions matching regular expression "foo":

Non-debugging symbols:
0x00000000004004c7  foo()
0x00000000004004dd  _ZL3foov
...

During minimal symbol reading symbol_set_names is called for each symbol.

First, it's called with foo from msym.c, an entry is created in
per_bfd->demangled_names_hash and symbol_find_demangled_name is called, which
has the side effect of setting the language of the symbol to language_cplus.

Then, it's called with foo from msym_main.c.  Since
per_bfd->demangled_names_hash already has an entry for that name,
symbol_find_demangled_name is not called, and the language of the symbol
remains language_auto.

Fix this by doing the symbol_find_demangled_name call unconditionally.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2018-11-09  Tom de Vries  <tdevries@suse.de>

	* symtab.c (symbol_set_names): Call symbol_find_demangled_name
	unconditionally, to set the language of the symbol.  Manage freeing
	returned pointer using gdb::unique_xmalloc_ptr.

gdb/testsuite/ChangeLog:

2018-11-09  Tom de Vries  <tdevries@suse.de>

	* gdb.base/msym-lang.c: New test.
	* gdb.base/msym-lang.exp: New file.
	* gdb.base/msym-lang-main.c: New test.
2018-11-09 11:54:04 +01:00
Tom Tromey 9c710e1157 Capitalize "<TAB>" in require_record_target error
This changes require_record_target to say "<TAB>" rather than "<tab>".
I think capitalizing here is a bit more GNU-ish, based on Emacs usage
and one other case in gdb.

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

	* record.c (require_record_target): Upper-case "<TAB>".
2018-11-08 16:17:01 -07:00
Tom Tromey 3c6618cd22 Fix output indentation for "info pretty-printers"
I noticed that "info pretty-printers" will indent the "objfile" line
like:

    (top-gdb) info pretty-printer
    global pretty-printers:
      builtin
	mpx_bound128
      objfile /home/tromey/gdb/build/gdb/gdb pretty-printers:
      type_lookup_function

I think the "objfile" line should be "out-dented", following the same
style as the "global" and "progspace" (not shown) lines.

This patch implements this.

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

	* python/lib/gdb/command/pretty_printers.py
	(InfoPrettyPrinter.invoke): Don't indent "objfile" heading.
2018-11-08 16:17:01 -07:00
Tom Tromey 20f0d60db4 Avoid crash when calling warning too early
I noticed that if you pass the name of an existing file (not a
directory) as the argument to --data-directory, gdb will crash:

    $ ./gdb -nx  --data-directory  ./gdb
    ../../binutils-gdb/gdb/target.c:590:56: runtime error: member call on null pointer of type 'struct target_ops'

This was later reported as PR gdb/23838.

This happens because warning ends up calling
target_supports_terminal_ours, which calls current_top_target, which
returns nullptr this early.

This fixes the problem by handling this case specially in
target_supports_terminal_ours.  I also changed
target_supports_terminal_ours to return bool.

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

	PR gdb/23555:
	PR gdb/23838:
	* target.h (target_supports_terminal_ours): Return bool.
	* target.c (target_supports_terminal_ours): Handle case where
	current_top_target returns nullptr.  Return bool.

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

	PR gdb/23555:
	PR gdb/23838:
	* gdb.base/warning.exp: New file.
2018-11-08 16:10:21 -07:00
Joel Brobecker d4718d5c9f (AArch64) wrong value returned by "finish" for HFA
Consider the gdb.ada/array_return.exp testcase, and in particular,
consider the following code...

   type Small_Float_Vector is array (1 .. 2) of Float;

   function Create_Small_Float_Vector return Small_Float_Vector is
   begin
      return (others => 4.25);
   end Create_Small_Float_Vector;

... which declares a type which is an array with 2 floats in it
(floats are 4 bytes on AArch64), trying to get GDB to print
the return value from that function does not work:

    (gdb) fin
    Run till exit from #0  pck.create_small_float_vector () at /[...]/pck.adb:15
    0x000000000000062c in p () at /[...]/p.adb:11
    11         Vector := Create_Small_Float_Vector;
    Value returned is $1 = (4.25, 0.0)
                                  ^^^
                                  |||

We expected the value shown to be:

    (gdb) fin
    Run till exit from #0  pck.create_small_float_vector () at /[...]/pck.adb:15
    0x000000000000062c in p () at /[...]/p.adb:11
    11         Vector := Create_Small_Float_Vector;
    Value returned is $1 = (4.25, 4.25)

Because the return type is an HFA, it is returned via the first two
SIMD registers. However, what happens is that the current implementation
fails to realize that this is an HFA, and therefore fetches the return
value from the wrong location. And the reason why it fails to realize
this is because it thinks that our array has 8 elements (HFAs have
a maximum of 4). Looking at aapcs_is_vfp_call_or_return_candidate_1,
where this is determined, we can easily see why (looks like a thinko):

        | case TYPE_CODE_ARRAY:
        | [...]
        |         struct type *target_type = TYPE_TARGET_TYPE (type);
        |         int count = aapcs_is_vfp_call_or_return_candidate_1
        |                       (target_type, fundamental_type);
        |
        |         if (count == -1)
        |           return count;
        |
  !! -> |         count *= TYPE_LENGTH (type);
        |           return count;

Here, we first determine the count for one element of our array,
and so we should then be multiplying that count by the number
of elements in our array (2 in our case). But instead, we multiply it
by the total size (8). As a result, we do not classify the return
type as an HFA, and thus pick the wrong location for fetching
the return value.

gdb/ChangeLog:

        * aarch64-tdep.c (aapcs_is_vfp_call_or_return_candidate_1):
        return the correct count for potential HFAs.

Tested on aarch64-linux, fixes:

    array_return.exp: value printed by finish of Create_Small_Float_Vector
2018-11-08 10:27:31 -05:00
Jan Beulich b5420128da x86-64: fix ZMM register state tracking
The three AVX512 state components are entirely independent - one being
in its "init state" has no implication whatsoever on either of the other
two. Fully separate X86_XSTATE_ZMM_H and X86_XSTATE_ZMM handling, to
prevent upper halves of the upper 16 ZMM registers to display as if they
were zero (when they aren't) after e.g. VZEROALL/VZEROUPPER.
2018-11-08 12:12:05 +01:00
Andrew Burgess cd115d615c gdb/riscv: Update test to support targets without FP hardware
Update gdb.arch/riscv-reg-aliases.exp test to support targets without
floating point registers.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-reg-aliases.exp: Handle targets without floating
	point hardware.
2018-11-08 09:34:19 +00:00
Andrew Burgess 17cf289784 gdb/riscv: Handle errors while setting the frame id
When we connect to a remote target one of the first things GDB does is
establish a frame id.  If an error is thrown while building this frame
id then GDB will disconnect from the target.

This can mean that, if the user is attempting to connect to a target
that doesn't yet have a program loaded, or the program the user is
going to load onto the target doesn't match what is already loaded, or
the target is just in some undefined state, then the very first
request for a frame id can fail (for example, by trying to load from
an invalid memory address), and GDB will disconnect.  It is then
impossible for the user to connect to the target and load a new
program at all.

An example of such a session might look like this:

    Reading symbols from ./gdb/testsuite/outputs/gdb.arch/riscv-reg-aliases/riscv-reg-aliases...
    (gdb) target remote :37191
    Remote debugging using :37191
    0x0000000000000100 in ?? ()
    Cannot access memory at address 0x0
    (gdb) load
    You can't do that when your target is `exec'
    (gdb) info frame
    /path/to/gdb/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)

The solution is to handle errors in riscv_frame_this_id, and leave the
this_id variable with its default value, which is the predefined
'outermost' frame.

With this fix in place, connecting to the same target now looks like
this:

    (gdb) target remote :37191
    Remote debugging using :37191
    0x0000000000000100 in ?? ()
    (gdb) info frame
    Stack level 0, frame at 0x0:
     pc = 0x100; saved pc = <not saved>
     Outermost frame: outermost
     Arglist at unknown address.
     Locals at unknown address, Previous frame's sp in sp

gdb/ChangeLog:

	* riscv-tdep.c (riscv_insn::decode): Update header comment.
	(riscv_frame_this_id): Catch errors thrown while building the
	frame cache, leave the frame id as the default, which is the outer
	frame id.
2018-11-08 09:34:19 +00:00
Joel Brobecker 76136aeda5 (Ada/tasking) fix array or string index out of range warning
A recent change in the compiler highlighted a small weakness in
the function reading the contents of the Ada Task Control Block
(ATCB -- the data that allows us to inspect Ada tasks). As a result,
anytime we read it, we started getting some warnings. For instance,
using the gdb.ada/tasks.exp testcase...

        $ gnatmake -g foo.adb
        $ gdb foo
        (gdb) b foo.adb:60
        Breakpoint 1 at 0x403e07: file foo.adb, line 60.
        (gdb) run
        [...]
        Thread 1 "foo" hit Breakpoint 1, foo () at foo.adb:60
        60         for J in Task_List'Range loop  -- STOP_HERE

... we can see that the "info tasks" command produces some warnings,
followed by the correct output.

        (gdb) info tasks
  !! ->  warning: array or string index out of range
  !! ->  warning: array or string index out of range
  !! ->  warning: array or string index out of range
  !! ->  warning: array or string index out of range
           ID       TID P-ID Pri State                  Name
        *   1    654050       48 Runnable               main_task
            2    654ef0    1  48 Accept or Select Term  task_list(1)
            3    658680    1  48 Accept or Select Term  task_list(2)
            4    65be10    1  48 Accept or Select Term  task_list(3)

The problem comes from the fact that read_atcb, the function responsible
for loading the contents of the ATCB, blindly tries to read some data
which is only relevant when a task is waiting for another task on
an entry call. A comment in that code's section gives a hint as to
how the information is meant to be decoded:

      /* Let My_ATCB be the Ada task control block of a task calling the
         entry of another task; then the Task_Id of the called task is
         in My_ATCB.Entry_Calls (My_ATCB.ATC_Nesting_Level).Called_Task.  */

What the comment shows is that, to get the Id of the task being called,
one has to go through the entry calls field, which is an array pointer.
Up to now, we were lucky that, for tasks that are _not_ waiting on an
entry call, its ATCB atc_nesting_level used to be set to 1, and so
we were able to silently read some irrelevant data. But a recent change
now causes this field to be zero instead, and this triggers the warning,
since we are now trying to read outside of the array's range (arrays
in Ada often start at index 1, as is the case here).

We avoid this issue by simply only reading that data when the data
is actually known to be relevant (state == Entry_Caller_Sleep).

This, in turn, allows us to simplify a bit the use of the task_info->state
field, where we no longer need to check task the task has a state equal
to Entry_Caller_Sleep before using this field. Indeed, with this new
approach, we now know that, unless task_info->state == Entry_Caller_Sleep,
the state is now guaranteed to be zero. In other words, we no longer set
task_info->called_task to some random value, forcing to check the task's
state first as a way to verify that the data is not random.

gdb/ChangeLog:

        * ada-lang.c (read_atcb): Only set task_info->called_task if
        task_info->state == Entry_Caller_Sleep.
        (print_ada_task_info): Do not check task_info->state before
        checking task_info->called_task.
        (info_task): Likewise.
2018-11-07 16:28:52 -05:00
Joel Brobecker 07deea26b5 ada-tasks.c::read_atcb: start from a cleared ada_task_info result
The purpose of this patch is not to fix a bug per se, but rather
to robustify this function to make sure it never returns a struct
ada_task_info where some of the fields are left uninitialized.
Reading the current implementation, it attempts to methodically
set them all one by one: but it's not excluded that a future
change might miss something. A memset is cheap and make sure that
this function returns repeatable results.

This in turns allows us to remove some assignments which have become
redundant.

gdb/ChangeLog:

        * ada-tasks.c (read_atcb): Clear task_info before computing
        the value of each of its fields.
2018-11-07 16:28:07 -05:00
Andrew Burgess 35ee2dc2e4 gdb: Guard against NULL dereference in dwarf2_init_integer_type
In this commit:

    commit eb77c9df9f
    Date:   Thu Oct 18 14:04:27 2018 +0100

        gdb: Handle ICC's unexpected void return type

A potential dereference of a NULL pointer was introduced if a
DW_TAG_base_type is missing a DW_AT_name attribute.

I have taken this opportunity to fix a slight confusion that existed
in the test also added in the above commit, the test had two C
variables, declared like this:

    int var_a = 5;

    void *var_ptr = &var_a;

However, the fake DWARF in the test script declared them like this:

    void var_a = 5;

    void *var_ptr = &var_a;

This wasn't a problem as the test never uses 'var_a' directly, this
only exists so 'var_ptr' can be initialised.  However, it seemed worth
fixing.

I've also added a test for a DW_TAG_base_type with a missing
DW_AT_name, as clearly there's not test currently that covers this
(the original patch tested cleanly).  I can confirm that the new test
causes GDB to crash before this patch, and passes with this patch.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_init_integer_type): Check for name being
	NULL before dereferencing it.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/void-type.exp: Rename types, and make var_a an 'int'.
	* gdb.dwarf2/missing-type-name.exp: New file.
2018-11-07 12:58:56 +00:00
Tom de Vries 31aceee863 [gdb] Fix gdb crash when reading core file
Consider the test-case from this patch, compiled with O0.

The executable segfaults, and generates a core dump:
...
$ ./a.out
Segmentation fault (core dumped)
...

When loading the core file, limiting stack size to 4MB, gdb crashes:
...
$ ulimit -s 4096
$ gdb -batch ./a.out core.saved
[New LWP 19379]
Segmentation fault (core dumped)
...

The crash originates here in linux_vsyscall_range_raw, where we call alloca
with phdrs_size == 4194112 (roughly 4MB):
...
      phdrs = (Elf_Internal_Phdr *) alloca (phdrs_size);
...

While for this test-case gdb runs fine with the system default stack limit of
8MB, there are cases reported of 12MB phdrs_size where gdb also crashes with
the system default stack limit.

Fix this by using xmalloc instead of alloca, which prevents the crash provided
the stack limit is at least 112kb.

Build and reg-tested on x86_64-linux.

2018-11-06  Tom de Vries  <tdevries@suse.de>

	* linux-tdep.c (linux_vsyscall_range_raw): Use xmalloc to allocate
	program headers.

	* gdb.base/many-headers.c: New test.
	* gdb.base/many-headers.exp: New file.
2018-11-06 23:15:41 +01:00
Jim Wilson 109be305bb RISC-V: Force variables to .data for code_elim.
RISC-V puts a global variable in .sdata by default, which causes the
add-symbol-file commands with -s .data to fail as there is no .data section.
This fixes 3 testsuite failures.

	gdb/testsuite/
	* gdb.base/code_elim.exp: For riscv, set additional_flags
	to include -msmall-data-limit=0.
2018-11-06 11:06:23 -08:00
Max Filippov f11acc5ec0 gdb: xtensa: use linux ABI code for uclinux
gdb/
2018-11-06  Max Filippov  <jcmvbkbc@gmail.com>

	* configure.tgt (xtensa*-*-linux*): Change to xtensa*-*-*linux*
	so that it applies to uclinux as well.
2018-11-06 10:25:11 -08:00
Marius Muench 9e237747bd ARM: Do not use FP reg when on AAPCS
GDB tries to dereference the frame pointer in arm_scan_prologue as a
last resort to create frame information.
However, the more recent AAPCS ABI does not make use of a frame pointer.

This patch checks whether the specified arm_abi is AAPCS before
dereferencing the "frame pointer". If so, just return as efforts to use
it for restoring frame information won't work.

gdb/ChangeLog
2018-11-06  Marius Muench  <marius.muench@eurecom.fr>

	* arm-tdep.c (arm_scan_prologue): Don't dereference FP reg
	when on AAPCS.
2018-11-06 10:54:08 -07:00
John Baldwin bcecc11da2 Note that PT_GETREGS supplies SSTATUS for FreeBSD/riscv.
This permits reading the value of the SSTATUS CSR returned by ptrace()
for live FreeBSD/riscv processes.

	* riscv-fbsd-nat.c (getregs_supplies): Return true for
	RISCV_CSR_SSTATUS_REGNUM.
2018-11-06 09:47:21 -08:00
Philippe Waroquiers bb20ccab70 ChangeLog for 'Fix 4K leak each time next/step changes of function.' 2018-11-05 23:09:44 +01:00
Philippe Waroquiers 8e6a5953e1 Fix 4K leak in open_source_file each time next/step changes of function.
When current function changes after a next/step, GDB shows a message such as:
  (gdb) s
  info_fun1 ()
      at /bd/home/philippe/gdb/git/build_smallthing/gdb/testsuite/../../../smallthing/gdb/testsuite/gdb.base/info_qt.c:41
  41	  info_qt_inc++;
  (gdb)

Valgrind reports a 4K definite leak for each such message (full stacktrace of
the leak below).

This patch fixes this leak, by transferring the current s->fullname to the
unique_xmalloc_ptr fullname given to find_and_open_source.

Note that I do not understand why find_and_open_source always tries to
re-execute the substitution rules on the provided fullname, as source.c
symtab_to_fullname just blindly returns a non NULL s->fullname, counting on
forget_cached_source_info to be called if search dir or substitution rules are
changed.  Similarly, psymtab_to_fullname also just returns a non NULL
ps->fullname.

==15309== VALGRIND_GDB_ERROR_BEGIN
==15309== 69,632 bytes in 17 blocks are definitely lost in loss record 3,158 of 3,186
==15309==    at 0x4C2BE2D: malloc (vg_replace_malloc.c:299)
==15309==    by 0x5BF0987: realpath@@GLIBC_2.3 (canonicalize.c:78)
==15309==    by 0x41F713: gdb_realpath(char const*) (pathstuff.c:72)
==15309==    by 0x608833: openp(char const*, enum_flags<openp_flag>, char const*, int, std::unique_ptr<char, gdb::xfree_deleter<char> >*) (source.c:861)
==15309==    by 0x608B89: find_and_open_source(char const*, char const*, std::unique_ptr<char, gdb::xfree_deleter<char> >*) (source.c:1049)
==15309==    by 0x608D0B: open_source_file(symtab*) (source.c:1074)
==15309==    by 0x609101: print_source_lines_base(symtab*, int, int, enum_flags<print_source_lines_flag>) (source.c:1291)
==15309==    by 0x614ADF: print_frame_info(frame_info*, int, print_what, int, int) (stack.c:911)
==15309==    by 0x614C45: print_stack_frame(frame_info*, int, print_what, int) (stack.c:181)
==15309==    by 0x511D5E: print_stop_location (infrun.c:8044)
==15309==    by 0x511D5E: print_stop_event(ui_out*) (infrun.c:8061)
==15309==    by 0x40DD6D: cli_on_normal_stop(bpstats*, int) (cli-interp.c:145)
==15309==    by 0x512409: operator() (functional:2127)
==15309==    by 0x512409: notify (observable.h:106)
==15309==    by 0x512409: normal_stop() (infrun.c:8334)
==15309==    by 0x5156D8: fetch_inferior_event(void*) (infrun.c:3955)
==15309==    by 0x4B3EEC: gdb_wait_for_event(int) (event-loop.c:859)
==15309==    by 0x4B3FF6: gdb_do_one_event() [clone .part.4] (event-loop.c:322)
==15309==    by 0x4B41B4: gdb_do_one_event (common-exceptions.h:219)
==15309==    by 0x4B41B4: start_event_loop() (event-loop.c:371)
==15309==    by 0x551217: captured_command_loop() (main.c:330)
==15309==    by 0x55220C: captured_main (main.c:1177)
==15309==    by 0x55220C: gdb_main(captured_main_args*) (main.c:1193)
==15309==    by 0x29B4F7: main (gdb.c:32)
==15309==
==15309== VALGRIND_GDB_ERROR_END

gdb/ChangeLog
2018-11-04  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* source.c (open_source_file): Fix leak by transferring the
	current s->fullname to the unique_xmalloc_ptr fullname given
	to find_and_open_source.
2018-11-05 21:26:03 +01:00
Tom Tromey a31abe80ea Return gdbpy_ref from gdbpy_get_varobj_pretty_printer
This changes gdbpy_get_varobj_pretty_printer to return a gdbpy_ref.

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

	* varobj.c (install_default_visualizer): Update.
	* python/python-internal.h (gdbpy_get_varobj_pretty_printer):
	Return gdbpy_ref.
	* python/py-prettyprint.c (search_pp_list): Return gdbpy_ref.
	(find_pretty_printer_from_progspace)
	(find_pretty_printer_from_gdb, find_pretty_printer)
	(gdbpy_get_varobj_pretty_printer): Return gdbpy_ref.
	(gdbpy_get_varobj_pretty_printer, gdbpy_default_visualizer):
	Update.
2018-11-04 08:01:01 -07:00
Tom Tromey 833d985d1c Return gdbpy_ref from some Python string functions
This changes python_string_to_unicode,
python_string_to_target_python_string, and
host_string_to_python_string to return gdbpy_ref.

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

	* python/python.c (gdbpy_parameter_value): Update.
	* python/python-internal.h (python_string_to_unicode)
	(python_string_to_target_python_string)
	(host_string_to_python_string): Return gdbpy_ref.
	* python/py-utils.c (python_string_to_unicode)
	(unicode_to_encoded_python_string)
	(unicode_to_target_python_string)
	(python_string_to_target_string)
	(python_string_to_target_python_string): Return gdbpy_ref.
	(python_string_to_host_string): Update.
	(host_string_to_python_string): Return gdbpy_ref.
	* python/py-symtab.c (stpy_get_filename, stpy_get_producer)
	(stpy_fullname): Update.
	* python/py-progspace.c (pspy_get_filename, pspy_solib_name):
	Update.
	* python/py-prettyprint.c (print_string_repr): Update.
	* python/py-objfile.c (objfpy_get_filename, objfpy_get_username)
	(objfpy_get_build_id): Update.
	* python/py-breakpoint.c (bppy_get_location)
	(bppy_get_expression, bppy_get_condition, bppy_get_commands):
	Update.
2018-11-04 08:01:01 -07:00
Tom Tromey 12dfa12a3c Return gdbpy_ref from gdb_py_object_from_*longest
This changes gdb_py_object_from_longest and
gdb_py_object_from_ulongest to return a gdbpy_ref rather than a
PyObject*.

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

	* python/python-internal.h (gdb_py_object_from_longest)
	(gdb_py_object_from_ulongest): Return gdbpy_ref.
	* python/py-value.c (valpy_int): Update.
	* python/py-utils.c (gdb_py_object_from_longest): Return
	gdbpy_ref.
	(gdb_py_object_from_ulongest): Likewise.
	* python/py-type.c (typy_get_alignof): Update.
	* python/py-linetable.c (ltpy_get_all_source_lines)
	(ltpy_entry_get_line, ltpy_entry_get_pc): Update.
	* python/py-block.c (blpy_get_start, blpy_get_end): Update.
2018-11-04 08:01:00 -07:00
Philippe Waroquiers 470678d7c9 OBVIOUS Fix a typo in ada-lang.c add_prefix_cmd for "set ada"
Correct typo in add_prefix_cmd doc arg for "set ada".
2018-11-03 21:33:42 +01:00
Philippe Waroquiers 814fa4f632 OBVIOUS Remove a useless const char *type and its initialization.
Valgrind detected a leak for the line:
  type = xstrdup ("auto");

as the compile probably dropped the type variable completely, as its
only usage was this initialization.

So, remove the useless variable.
2018-11-03 19:31:41 +01:00
Philippe Waroquiers 3c6dd3d1c7 OBVIOUS fix the month of the last gdb/ChangeLog entry to be 11 instead of 12. 2018-11-03 19:19:05 +01:00
Joel Brobecker e8bf1ce461 (Ada) Add ravenscar tasking support on AArch64
This patch adds support for debugging Ravenscar tasks, similar to what
is done for ppc and sparc.

gdb/ChangeLog:

        * aarch64-ravenscar-thread.h, aarch64-ravenscar-thread.c:
        New files.
        * aarch64-tdep.c: #include "aarch64-ravenscar-thread.h".
        (aarch64_gdbarch_init): Add call to register_aarch64_ravenscar_ops.
        * Makefile.in (ALL_64_TARGET_OBS): Add aarch64-ravenscar-thread.o.
        (HFILES_NO_SRCDIR): Add aarch64-ravenscar-thread.h.
        (ALLDEPFILES): Add aarch64-ravenscar-thread.c.
        * configure.tgt (cpu_obs) [aarch64*-*-*]: Add ravenscar-thread.o
        and aarch64-ravenscar-thread.o.
        * NEWS: Add entry documenting Ravenscar tasking support
        on AArch64 ELF.
2018-11-02 13:37:29 -04:00
Philippe Waroquiers d54cfd762b QUIET flag initialization missing in 2 places.
Fix by Matthew Malcomson  <matthew.malcomson@arm.com>

Pushed as obvious.
2018-11-02 14:20:59 +01:00
Jim Wilson 3ba2ee38a6 RISC-V: Don't allow unaligned breakpoints.
Some hardware doesn't support unaligned accesses, and a bare metal target
may not have an unaligned access trap handler.  So if the PC is 2-byte
aligned, then use a 2-byte breakpoint to avoid unaligned accesses.

Tested on native RV64GC Linux with gdb testsuite and cross on spike
simulator and openocd with riscv-tests/debug.

	gdb/
	* riscv-tdep.c (riscv_breakpoint_kind_from_pc): New local unaligned_p.
	Set if pcptr if unaligned.  Return 2 if unaligned_p true.  Update
	debugging messages.
2018-11-01 17:25:15 -07:00
Joel Brobecker e2b7af7242 (Ada) fix "error in expression" when using watch -location command
The "watch -l EXPR" command with the language set to Ada currently
fails with the following error:

     (gdb) watch -l global_var
     Error in expression, near ` 0x000000000062d2d8'.

The error occurs because GDB internally translate the request into
a watchpoint on a different expression: "* (TYPE *) ADDR" where
TYPE and ADDR are the type and the address of the object returned
by the expression's evaluation (resp.). So, in the example above,
global_var being an integer stored at 0x000000000062d2d8, GDB tries
to set a watchpoint on "* (integer *) 0x000000000062d2d8", which
fails, because we try to parse this expression with Ada, when
in fact it is not valid.

This patch fixes the issue by implementing the la_watch_location_expression
language method, using a syntax that the Ada parser recognizes
("{TYPE} ADDR").

gdb/ChangeLog:

	* ada-lang.c (ada_watch_location_expression): New function.
        (ada_language_defn): Set la_watch_location_expression to
        ada_watch_location_expression.

gdb/testsuite/ChangeLog:

        * gdb.ada/watch_minus_l: New testcase.
2018-11-01 15:15:41 -07:00
Joel Brobecker 8b578f9c76 remove trailing spaces in print-utils.c ("int_string" function)
gdb/ChangeLog:

        * print-utils.c (int_string): Remove unnecessary trailing spaces.
2018-11-01 15:08:57 -07:00
Joel Brobecker 87f7ab7b84 gdb.texinfo: Fix the output of the "info tasks 2" example
gdb/doc/ChangeLog:

        * gdb.texinfo (Ada Tasks): Update the "info task 2" example
        output to match the current implementation.
2018-11-01 15:05:40 -07:00
Joel Brobecker 1cc62f2e44 rs6000-tdep.c:skip_prologue avoid negative left shift
the rs6000-tdep.c::skip_prologue function has the following code:

          unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);

          /* Not a recognized prologue instruction.
             Handle optimizer code motions into the prologue by continuing
             the search if we have no valid frame yet or if the return
             address is not yet saved in the frame.  Also skip instructions
             if some of the GPRs expected to be saved are not yet saved.  */
          if (fdata->frameless == 0 && fdata->nosavedpc == 0
              && (fdata->gpr_mask & all_mask) == all_mask)
            break;

The problem is that fdata->saved_gpr is initialized to -1, and so,
if no instruction is found in the function's prologue that causes us
to set that field to a non-negative value, the sanitizer crashes
with the following message:

    rs6000-tdep.c:1965:34: runtime error: shift exponent -1 is negative

This patch fixes the issue the by only doing the shift if saved_gpr
is not negative. When saved_gpr is negative, we actually don't need
the shift.

gdb/ChangeLog:

        * rs6000-tdep.c (skip_prologue): Fix potential negative left
        shifting.

Tested on ppc-linux native.
Also tested on ppc-elf (baremetal) using AdaCore's testsuite.
2018-11-01 17:46:58 -04:00
Jerome Guitton e1c3a37375 arm-pikeos: software single step
On ARM, PikeOS does not support hardware single step, causing various
semi-random errors when trying to next/step over some user code. So
this patch changes this target to use software-single-step instead.

The challenge is that, up to now, the PikeOS target was in all respects
identical to a baremetal target as far as GDB was concerned, meaning
we were using the baremetal osabi for this target too. This is no longer
possible, and we need to introduce a new OSABI variant. Unfortunately,
there isn't anything in the object file that would allow us to
differentiate between the two platforms. So we have to rely on a
heuristic instead, where we look for some known symbols that are
required in a PikeOS application (these symbols are expected to be
defined by the default linker script, and correspond to routines used
to allocate the application stack).

For the long run, the hope is that the stub implementation provided
by PikeOS is enhanced so that it includes vContSupported+ to the
$qSupported query, and then that the reply to the "vCont?" query
only return support for "continue" operations (thus exclusing "step"
operations). We could then use that information to reliably determine
at connection time that the target does not support single-stepping
and therefore automatically turn software single-stepping automatically
based on it.

gdb/ChangeLog:

        * defs.h (enum gdb_osabi): Add GDB_OSABI_PIKEOS.
        * osabi.c (gdb_osabi_names): Add name for GDB_OSABI_PIKEOS.
        * arm-pikeos-tdep.c: New file.
        * configure.tgt: Add arm-pikeos-tdep.o to the case of ARM
        embedded system.
        * Makefile.in (ALL_TARGET_OBS): Add arm-pikeos-tdep.o.

Tested on arm-pikeos and arm-elf using AdaCore's testsuite.
We also evaluated it on armhf-linux as a cross platform.
2018-11-01 14:43:44 -07:00
Simon Marchi e8d8cce69b Import mkdtemp gnulib module, fix mingw build
Building with mingw currently fails:

  CXX    unittests/mkdir-recursive-selftests.o
/home/emaisin/src/binutils-gdb/gdb/unittests/mkdir-recursive-selftests.c: In function ‘void selftests::mkdir_recursive::test()’:
/home/emaisin/src/binutils-gdb/gdb/unittests/mkdir-recursive-selftests.c:49:20: error: ‘mkdtemp’ was not declared in this scope
   if (mkdtemp (base) == NULL)
                    ^
Commit

    e418a61a67 ("Move mkdir_recursive to common/filestuff.c")

moved this code, but also removed the HAVE_MKDTEMP guard which prevented
the mkdtemp call to be compiled on mingw.

We can either put back the HAVE_MKDTEMP ifdef, or import the gnulib
mkdtemp module, which provides the function for mingw.  Since the
mkdir_recursive is susceptible to be used on mingw at some point, I
think it would be nice to have it tested on mingw, so I did the latter.

Once built, I tested it on Windows (copied the resulting gdb.exe on a
Windows machine, ran it, and ran "maint selftest mkdir_recursive").  It
failed, because the temporary directory is hardcoded to "/tmp/...".  I
therefore added and used a new get_standard_temp_dir function, which
returns an appropriate temporary directory for the host platform.

gdb/ChangeLog:

	* common/pathstuff.c (get_standard_temp_dir): New.
	* common/pathstuff.h (get_standard_temp_dir): New.
	* config.in: Re-generate.
	* configure: Re-generate.
	* configure.ac: Don't check for mkdtemp.
	* gnulib/aclocal-m4-deps.mk: Re-generate.
	* gnulib/aclocal.m4: Re-generate.
	* gnulib/config.in: Re-generate.
	* gnulib/configure: Re-generate.
	* gnulib/import/Makefile.am: Re-generate.
	* gnulib/import/Makefile.in: Re-generate.
	* gnulib/import/m4/gnulib-cache.m4: Re-generate.
	* gnulib/import/m4/gnulib-comp.m4: Re-generate.
	* gnulib/import/m4/mkdtemp.m4: New file.
	* gnulib/import/mkdtemp.c: New file.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES):
	Add mkdtemp module.
	* unittests/mkdir-recursive-selftests.c (test): Use
	get_standard_temp_dir.
	(_initialize_mkdir_recursive_selftests): Remove HAVE_MKDTEMP
	ifdef.
	* compile/compile.c (get_compile_file_tempdir): Likewise.
2018-11-01 15:41:43 -04:00
Sangamesh Mallayya cdcda965ea Reading signal handler frame in AIX
In AIX if gdb is debugging an application which has a signal handler
and reaches the signal handler frame, then we need to read the back
chain address from sigcontext saved on the stack, similarly the LR.

As backchain at an offset 0 will be 0, because we will have a
sigconext saved after the minimum stack size. So the correct
backchain will be at an offset after minimum stack and the LR at
an offset 8 will be of the signal millicode address.
If the back chain pointer is NULL and the LR field is in the kernel
segment(ex. 0x00004a14) then we can probably assume we are in a
signal  handler.

sample output

(gdb) bt
0  sig_handle_aix (signo=11) at aix-sighandle.c:7
1  0x0000000000004a94 in ?? ()
(gdb)

expected output

(gdb) bt
0  sig_handle_aix (signo=11) at aix-sighandle.c:7
1  <signal handler called>
2  0x0000000100000748 in foo () at aix-sighandle.c:14
3  0x000000010000079c in main () at aix-sighandle.c:19

gdb/ChangeLog:

2018-11-01  Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>

	* rs6000-aix-tdep.c: Include "trad-frame.h" and "frame-unwind.h".
	(SIG_FRAME_LR_OFFSET64): New define.
	(SIG_FRAME_FP_OFFSET64): New define.
	(aix_sighandle_frame_cache): New Function.
	(aix_sighandle_frame_this_id): New Function.
	(aix_sighandle_frame_prev_register): New Function.
	(aix_sighandle_frame_sniffer): New Function.
	(aix_sighandle_frame_unwind): New global variable.
	(rs6000_aix_init_osabi): Install new frame unwinder.

gdb/testsuite/ChangeLog:

2018-11-01  Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>

	* gdb.arch/aix-sighandle.c: New file.
	* gdb.arch/aix-sighandle.exp: New file.
2018-11-01 06:23:59 -04:00
Sergio Durigan Junior 656efb5e26 Fix PR gdb/23835: Don't redefine _FORTIFY_SOURCE if it's already defined
Gentoo has a local GCC patch which always defines _FORTIFY_SOURCE=2.
This causes a build problem when building GDB there, because
"common/common-defs.h" also defines _FORTIFY_SOURCE=2:

    CXX    gdb.o
  In file included from ../../gdb/defs.h:28:0,
		   from ../../gdb/gdb.c:19:
  ../../gdb/common/common-defs.h:71:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
   #define _FORTIFY_SOURCE 2

  <built-in>: note: this is the location of the previous definition
  cc1plus: all warnings being treated as errors
  make[2]: *** [Makefile:1619: gdb.o] Error 1

Even though it is questionable whether Gentoo's approach is the
correct one:

  https://jira.mongodb.org/browse/SERVER-29982
  https://bugs.gentoo.org/621036

it is still possible for GDB to be a bit more robust here and make
sure it just defines _FORTIFY_SOURCE if it hasn't been defined
already.  This patch does that.

Tested by rebuilding and making sure the macro was defined.

gdb/ChangeLog:
2018-10-31  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/23835
	* common/common-defs.h: Don't redefine _FORTIFY_SOURCE if it's
	already defined.
2018-10-31 17:42:43 -04:00
Andrew Burgess 92dcebf3fa gdb/riscv: Fix failures on rv64 in gdb.arch/riscv-reg-aliases.exp test
The gdb.arch/riscv-reg-aliases.exp test didn't take into account that
on RV64 (and RV128) the floating point registers are represented as a
union.  This patch updates the test to handle this.

Tested against RV32 and RV64.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-reg-aliases.exp: Rewrite to take account of float
	registers being unions.
2018-10-31 18:03:01 +00:00
Tom de Vries 68b9ac18cf [gdb/testsuite] Factor out lib/valgrind.exp
Factor out common code related to vgdb setup and cleanup in valgrind-bt.exp,
valgrind-disp-step.exp and gdb.base/valgrind-infcall.exp.

Tested on x86_64-linux with and without --target_board=native-gdbserver.

2018-10-31  Tom de Vries  <tdevries@suse.de>

	* lib/valgrind.exp: New file.
	 (vgdb_start, vgdb_stop): New procs, factored out of ...
	* gdb.base/valgrind-bt.exp: ... here, ...
	* gdb.base/valgrind-disp-step.exp: ... here and ...
	* gdb.base/valgrind-infcall.exp: ... here.
2018-10-31 18:26:40 +01:00
Tom de Vries 1443936e96 [gdb/testsuite] get_valueof: Don't output value in test name
The get_valueof outputs the value it has read as part of the test name.  This
causes test names to vary from run to run, and adds some noise when diffing
test results.  e.g.:

-PASS: gdb.guile/scm-ports.exp: buffered: get valueof "$sp" (140737488343920)
+PASS: gdb.guile/scm-ports.exp: buffered: get valueof "$sp" (140737488343968)
-PASS: gdb.guile/scm-ports.exp: unbuffered: get valueof "$sp" (140737488343920)
+PASS: gdb.guile/scm-ports.exp: unbuffered: get valueof "$sp" (140737488343968)

This patch removes that, since it's probably not very useful.

Tested on x86_64-linux.

2018-10-31  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (get_valueof): Don't output read value in test name.
2018-10-31 17:45:38 +01:00
Pedro Franco de Carvalho 64f57f3d7d [PowerPC] Include nat/linux-ptrace.h in native targets
Patch "[PowerPC] Add support for PPR and DSCR" used
PTRACE_GETREGSET/SETREGSET without including the fallback definitions
from "nat/linux-ptrace.h".  Include this header to avoid breaking
builds in systems that don't define them.

gdb/ChangeLog:
2018-10-31  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* ppc-linux-nat.c: Include nat/linux-ptrace.h.

gdb/gdbserver/ChangeLog:
2018-10-31  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* linux-ppc-low.c: Include nat/linux-ptrace.h.
2018-10-31 10:59:26 -03:00
Andrew Burgess eb77c9df9f gdb: Handle ICC's unexpected void return type
I encountered a binary compiled with Intel's C Compiler (ICC) version
14.0.5.212, which seemed to contain some non-standard DWARF.

The DWARF spec (V5 3.3.2) says:

    Debugging information entries for C void functions should not have
    an attribute for the return type.

However, what I observed in the DWARF from this ICC compiled binary
was this:

    ...
    <0><857>: Abbrev Number: 1 (DW_TAG_compile_unit)
       <858>   DW_AT_comp_dir    : (indirect string, offset: 0x48d): /tmp/
       <85c>   DW_AT_language    : 1       (ANSI C)
       <85d>   DW_AT_name        : (indirect string, offset: 0x77c): filename.c
       <861>   DW_AT_producer    : (indirect string, offset: 0x520): Intel(R) C Intel(R) 64 Compiler ...
       <865>   DW_AT_low_pc      : 0x4378d0
       <86d>   DW_AT_high_pc     : 0x4378f0
       <875>   DW_AT_stmt_list   : 0xa37
    ...
    <1><7ea>: Abbrev Number: 2 (DW_TAG_base_type)
       <7eb>   DW_AT_byte_size   : 0
       <7ec>   DW_AT_encoding    : 5       (signed)
       <7ed>   DW_AT_name        : (indirect string, offset: 0x58f): void
    ...
    <1><7f1>: Abbrev Number: 3 (DW_TAG_subprogram)
       <7f2>   DW_AT_decl_line   : 268
       <7f4>   DW_AT_decl_column : 30
       <7f5>   DW_AT_decl_file   : 1
       <7f6>   DW_AT_type        : <0x7ea>
       <7fa>   DW_AT_prototyped  : 1
       <7fb>   DW_AT_name        : (indirect string, offset: 0x761): function_foo
       <7ff>   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x761): function_foo
       <803>   DW_AT_low_pc      : 0x4378a0
       <80b>   DW_AT_high_pc     : 0x4378d0
       <813>   DW_AT_external    : 1
    ...

So function 'function_foo' has void return type, but still has a
DW_AT_type attribute for a 0 sized type called void.

What was found was that when the 'finish' command was used to leave
'function_foo', GDB would crash.

The problem is that in infcmd.c:print_return_value GDB tries to filter
out void return types, by looking for the TYPE_CODE_VOID, this fails
for the 'void' type as it has code TYPE_CODE_INT and GDB then tries to
print the 'void' type.

This eventually ends in a call to valprint.c:maybe_negate_by_bytes,
however, the len (length) of the value being negated is 0, which is
not detected or expected by this code, and invalid memory accesses
occur, some of which might cause GDB to crash.

The above DWARF was seen on version 14.0.5.212 of ICC.

I have also tested ICC versions 18.0.2.199 and 17.0.7.259, on both of
these versions, the DW_AT_type on the DW_TAG_subprogram has been
removed, bringing ICC inline with the DWARF standard, and with the
DWARF produced by GCC.

I only have limited access to these specific versions of ICC so I am
unable to get more specific details for when the generated DWARF
became non-standard or when it was changed to be more inline with the
DWARF standard.

Further testing revealed additional places where ICC produced 'void'
related DWARF that GDB struggles with.  When I compiled code that
contained a function with this signature:

    void funcx (void *arg);

on ICC 17/18, I got the following DWARF (notice the void return type
is now gone):

    ...
    <1><32>: Abbrev Number: 2 (DW_TAG_subprogram)
       <33>   DW_AT_decl_line   : 2
       <34>   DW_AT_decl_file   : 1
       <35>   DW_AT_prototyped  : 1
       <36>   DW_AT_name        : (indirect string, offset: 0xc5): funcx
       <3a>   DW_AT_MIPS_linkage_name: (indirect string, offset: 0xc5): funcx
       <3e>   DW_AT_low_pc      : 0x6dc
       <46>   DW_AT_high_pc     : 0x703
       <4e>   DW_AT_external    : 1
    <2><4f>: Abbrev Number: 3 (DW_TAG_formal_parameter)
       <50>   DW_AT_decl_line   : 2
       <51>   DW_AT_decl_file   : 1
       <52>   DW_AT_type        : <0x6a>
       <56>   DW_AT_name        : arg
       <5a>   DW_AT_location    : 2 byte block: 76 70      (DW_OP_breg6 (rbp): -16)
    ...
    <1><6a>: Abbrev Number: 5 (DW_TAG_pointer_type)
       <6b>   DW_AT_type        : <0x6f>
    <1><6f>: Abbrev Number: 6 (DW_TAG_base_type)
       <70>   DW_AT_byte_size   : 0
       <71>   DW_AT_encoding    : 5        (signed)
       <72>   DW_AT_name        : (indirect string, offset: 0xcb): void
    ...

However, the function argument 'arg' does still reference a 'void'
type.  This case doesn't seem as obviously non-standard as the
previous one, but I think that the DWARF standard (V5 5.2) does
suggest that the above is not the recommended approach.  If we compare
to the DWARF generated by GCC 7.3.1:

    ...
    <1><68>: Abbrev Number: 5 (DW_TAG_subprogram)
       <69>   DW_AT_external    : 1
       <69>   DW_AT_name        : (indirect string, offset: 0x221): funcx
       <6d>   DW_AT_decl_file   : 1
       <6e>   DW_AT_decl_line   : 2
       <6f>   DW_AT_prototyped  : 1
       <6f>   DW_AT_low_pc      : 0x400487
       <77>   DW_AT_high_pc     : 0x22
       <7f>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
       <81>   DW_AT_GNU_all_call_sites: 1
       <81>   DW_AT_sibling     : <0xa0>
    <2><85>: Abbrev Number: 6 (DW_TAG_formal_parameter)
       <86>   DW_AT_name        : arg
       <8a>   DW_AT_decl_file   : 1
       <8b>   DW_AT_decl_line   : 2
       <8c>   DW_AT_type        : <0xa0>
       <90>   DW_AT_location    : 2 byte block: 91 58      (DW_OP_fbreg: -40)
    ...
    <1><a0>: Abbrev Number: 7 (DW_TAG_pointer_type)
       <a1>   DW_AT_byte_size   : 8
    ...

Here we see that the DW_TAG_pointer_type doesn't reference any further
type.  This also seems out of line with the DWARF standard (which I
think recommends using a DW_TAG_unspecified_type entry), however GDB
does handle the GCC generated DWARF better.

If we look at how GDB handles the DWARF from GCC, then we see this:

    (gdb) print *arg
    Attempt to dereference a generic pointer.

While on the current HEAD of master dereferencing arg causes undefined
behaviour which will likely crash GDB (for the same reason as was
described above for the 'finish' case).  On earlier versions of GDB
the ICC DWARF would cause this:

    (gdb) print *arg
    $1 = 0

In this patch both the return type, and general variable/parameter
type handling is fixed by transforming the synthetic void entries in
the DWARF, the ones that look like this:

    <1><6f>: Abbrev Number: 6 (DW_TAG_base_type)
       <70>   DW_AT_byte_size   : 0
       <71>   DW_AT_encoding    : 5        (signed)
       <72>   DW_AT_name        : (indirect string, offset: 0xcb): void

into GDB's builtin void type.  My criteria for performing the fix are:

  1. Binary produced by any version of ICC,
  2. We're producing an integer type,
  3. The size is 0, and
  4. The name is "void".

I ignore the signed / unsigned nature of the integer.

Potentially we could drop the ICC detection too, this should be a
reasonably safe transformation to perform, however, I'm generally
pretty nervous when it comes to modifying how the DWARF is parsed so,
for now, I have restricted this to ICC only.

I also added an assertion to maybe_negate_by_bytes.  This is nothing
to do with the actual fix, but should detect incorrect use of this
function in the future, without relying on undefined behaviour to
crash GDB.

I added a new test that makes use the of the testsuite's DWARF
generator.  As it is tricky to create target independent tests that
pass function parameters using the DWARF generator (as specifying the
argument location is target specific) I have instead made use of a
global variable void*.  This still shows the issue.

We already have a predicate in the DWARF parser to detect versions of
ICC prior to 14, however, this issue was spotted on a later version.
As a result I've added a new predicate that is true for any version of
ICC.

gdb/ChangeLog:

	* dwarf2read.c (struct dwarf2_cu): Add producer_is_icc field.
	(producer_is_icc): New function.
	(check_producer): Set producer_is_icc field on dwarf2_cu.
	(dwarf2_init_integer_type): New function.
	(read_base_type): Call dwarf2_init_integer_type instead of
	init_integer_type in all cases.
	(dwarf2_cu::dwarf2_cu): Initialise producer_is_icc field.
	* valprint.c (maybe_negate_by_bytes): Add an assertion that the
	LEN is greater than 0.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/void-type.c: New file.
	* gdb.dwarf2/void-type.exp: New file.
2018-10-31 13:15:59 +00:00
Tom Tromey 4d5d104997 Check return value of bfd_init
Alan recently added a way for BFD library users to check whether they
were in fact loading a compatible version of BFD:

https://sourceware.org/ml/binutils/2018-10/msg00198.html

It seemed reasonable to me that gdb should do this check as well, in
case someone is dynamically linking against BFD.

Simon pointed out that an earlier version of the patch would cause a
gdb crash if the test failed.  This version works around this by
lowering the call to bfd_init and adding a comment explaining where
'error' can safely be called in captured_main_1.

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

	* main.c (captured_main_1): Check return value of bfd_init.
2018-10-30 07:06:17 -06:00
Sergio Durigan Junior fd332753fa Remove relational operators from common/offset-type.h
This patch is a follow-up of:

  https://sourceware.org/ml/gdb-patches/2018-10/msg00601.html

It removes the declaration of the relational operators for
common/offset-type.h.  As it turns out, these overloads are not being
used when a new offset type is declared, because, according to Pedro
Alves:

  I think the functions aren't called because they are templates, and
  thus the built-in (non-template) versions take precedence.  If you
  make them non-templates, then they should be called.  But, the
  built-ins are fine, so yeah, we can just remove the custom
  definitions.

The patch also adjusts the comments on the code.

No regressions introduced.

gdb/ChangeLog:
2018-10-29  Sergio Durigan Junior  <sergiodj@redhat.com>

	* common/offset-type.h (DEFINE_OFFSET_REL_OP): Delete.
	Adjust comments.
2018-10-29 23:48:37 -04:00
Simon Marchi 80e24d0986 Revert "GDBSERVER: Listen on a unix domain (instead of TCP) socket if requested."
This reverts commit f19c7ff839.
2018-10-29 13:28:24 -04:00
Simon Marchi 6a0b3457ee Revert "GDB: Document the unix::/path/to/socket of remote connection."
This reverts commit 6d0f8100c1.
2018-10-29 13:28:15 -04:00
Simon Marchi 6cf3675653 Revert "GDB: Fix documentation for invoking GDBSERVER"
This reverts commit 0a163825df.
2018-10-29 13:24:23 -04:00
Simon Marchi 431f22cc09 Revert "GDB: Remote target can now accept the form unix::/path/to/socket."
This reverts commit 88f5cc8cf8.
2018-10-29 13:22:47 -04:00
Simon Marchi 7f53228719 Revert "GDB: Only build for "unix:" connections if AF_LOCAL is supported."
This reverts commit 98a17ece01.
2018-10-29 13:22:42 -04:00
Rainer Orth 30a7953dbf Provide get_shell declaration in procfs.c
The Solaris build is currently broken:

/vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c: In member function ‘virtual void procfs_target::create_inferior(const char*, const string&, char**, int)’:
/vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:3038:28: error: ‘get_shell’ was not declared in this scope
   const char *shell_file = get_shell ();
                            ^~~~~~~~~
/vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:3038:28: note: suggested alternative: ‘getusershell’
   const char *shell_file = get_shell ();
                            ^~~~~~~~~
                            getusershell

The following patch fixes this.  Tested on amd64-pc-solaris2.11.


2018-10-29  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* procfs.c: Include common/pathstuff.h.
2018-10-29 10:28:40 +01:00
John Darrington 98a17ece01 GDB: Only build for "unix:" connections if AF_LOCAL is supported.
Commit f19c7ff839 added a new member to the
prefixes array which included a use of the symbol AF_LOCAL.   Unfortunately,
not all systems declare this symbol.    This change only compiles the "unix:"
member if the system knows about AF_LOCAL.

gdb/ChangeLog:

* configure.ac: New test HAVE_AF_LOCAL
* common/netstuff.c (parse_connection_spec) [prefixes]: Only compile "unix:"
   if HAVE_AF_LOCAL is true.
* configure: regenerate.
* config.in: regenerate.
2018-10-29 08:07:32 +01:00
Andrew Burgess a3d7226832 gdb/riscv: Add back missing braces in riscv-linux-nat.c
In this commit:

    commit ee67fd7f3f
    Date:   Thu Oct 25 12:03:31 2018 +0100

        gdb/riscv: Use correct regnum in riscv_linux_nat_target::fetch_registers

I incorrectly removed a set of braces in violation of the GDB coding
standard.  This commit adds them back.

gdb/ChangeLog:

	* riscv-linux-nat.c (riscv_linux_nat_target::fetch_registers):
	Add missing braces.  No functional change.
2018-10-28 10:43:26 +00:00
Philippe Waroquiers cd948f5b2b OBVIOUS Use report_unrecognized_option_error in 'demangle' and 'info macro' commands.
Rather than have some local logic to throw an error for an unrecognized option,
use the new cli-utils.h function throwing an error.

At the same time, fix some wrong indentation in info_macro_command
and fix a small bug in 'demangle' error handling:

Without the patch:
  (gdb) demangle -L c++ abcd
  Unrecognized option 'c++' to demangle command.  Try "help demangle".
  (gdb)

With the patch:
  (gdb) demangle -L c++ abcd
  Unrecognized option '-L' to demangle command.  Try "help demangle".

2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* macrocmd.c (info_macro_command): Use report_unrecognized_option_error
	to report a bad option and fix indentation.
	* demangle.c (demangle_command): Use report_unrecognized_option_error
	to report a bad option and correctly report the bad option.
2018-10-27 21:36:53 +02:00
Tom Tromey b50a8b9a91 Cache a copy of the user's shell on macOS
Recent versions of macOS have a feature called System Integrity
Protection.  Among other things, This feature prevents ptrace from
tracing certain programs --- for example, the programs in /bin, which
includes typical shells.

This means that startup-with-shell does not work properly.  This is PR
cli/23364.  Currently there is a workaround in gdb to disable
startup-with-shell when this feature might be in use.

This patch changes gdb to be a bit more precise about when
startup-with-shell will not work, by checking whether the shell
executable is restricted.

If the shell is restricted, then this patch will also cause gdb to
cache a copy of the shell in the gdb cache directory, and then reset
the SHELL environment variable to point to this copy.  This lets
startup-with-shell work again.

Tested on High Sierra by trying to start a program using redirection,
and by running startup-with-shell.exp.

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

	PR cli/23364:
	* darwin-nat.c (copied_shell): New global.
	(may_have_sip): Rename from should_disable_startup_with_shell.
	(copy_shell_to_cache, maybe_cache_shell): New functions.
	(darwin_nat_target::create_inferior): Update.  Use
	copied_shell.
2018-10-27 11:58:41 -06:00
Tom Tromey 36033ef57c Do not reopen temporary files
The current callers of mkostemp close the file descriptor and then
re-open it with fopen.  It seemed better to me to continue to use the
already-opened file descriptor, so this patch rearranges the code a
little in order to do so.  It takes care to ensure that the files are
only unlinked after the file descriptor in question is closed, as
before.

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

	* unittests/scoped_fd-selftests.c (test_to_file): New function.
	(run_tests): Call test_to_file.
	* dwarf-index-write.c (write_psymtabs_to_index): Do not reopen
	temporary files.
	* common/scoped_fd.h (scoped_fd::to_file): New method.
2018-10-27 11:58:41 -06:00
Tom Tromey b3279b601e Use mkostemp, not mkstemp
I noticed that gdb could leak file descriptors coming from mkstemp.
This patch fixes the problem by importing the gnulib mkostemp instead,
and then changing gdb to pass O_CLOEXEC.

A small gnulib patch was needed.  This has already been accepted
upstream.

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

	* unittests/scoped_mmap-selftests.c (test_normal): Use
	gdb_mkostemp_cloexec.
	* unittests/scoped_fd-selftests.c (test_destroy, test_release):
	Use gdb_mkostemp_cloexec.
	* gnulib/aclocal-m4-deps.mk, gnulib/aclocal.m4,
	gnulib/config.in, gnulib/configure,
	gnulib/import/Makefile.am, gnulib/import/Makefile.in,
	gnulib/import/m4/gnulib-cache.m4,
	gnulib/import/m4/gnulib-comp.m4: Update.
	* gnulib/import/m4/mkostemp.m4: New file.
	* gnulib/import/m4/mkstemp.m4: Remove.
	* gnulib/import/mkostemp.c: New file.
	* gnulib/import/mkstemp.m4: Remove.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Remove
	mkstemp, add mkostemp.  Apply new patch.
	* gnulib/import/stdlib.in.h: Apply patch.
	* gnulib/patches/0002-mkostemp-mkostemps-Fix-compilation-error-in-C-mode-o.patch:
	New file.
	* dwarf-index-write.c (write_psymtabs_to_index): Use
	gdb_mkostemp_cloexec.
	* common/filestuff.h (gdb_mkostemp_cloexec): New function.
2018-10-27 11:58:41 -06:00
Tom Tromey e418a61a67 Move mkdir_recursive to common/filestuff.c
This moves mkdir_recursive from dwarf-index-cache.c to
common/filestuff.c, and also changes it to return a boolean that says
whether or not it worked.

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

	* unittests/mkdir-recursive-selftests.c: New file.
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/mkdir-recursive-selftests.c.
	* dwarf-index-cache.c (mkdir_recursive): Move to
	common/filestuff.c.
	(index_cache::store): Check return value of mkdir_recursive.
	(create_dir_and_check, test_mkdir_recursive): Move to new file.
	(_initialize_index_cache): Don't register test.
	* common/filestuff.h (mkdir_recursive): Declare.
	* common/filestuff.c (mkdir_recursive): Move from
	dwarf-index-cache.c.  Return bool.
2018-10-27 11:58:41 -06:00
Tom Tromey 29be4d9dee Move make_temp_filename to common/pathstuff.c
Currently make_temp_filename is a function local to
write_psymtabs_to_index.  This patch moves it to pathstuff.c so that
it can be used from other places in gdb.

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

	* dwarf-index-write.c (write_psymtabs_to_index): Move
	make_temp_filename to common/pathstuff.c.
	* common/pathstuff.h (make_temp_filename): Declare.
	* common/pathstuff.c (make_temp_filename): New function, moved
	from dwarf-index-write.c.
2018-10-27 11:58:40 -06:00
Tom Tromey 974e684463 Unify shell-finding logic
I noticed several places in gdb that were using getenv("SHELL") and
then falling back to "/bin/sh" if it returned NULL.  This unifies
these into a single function.

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

	* procfs.c (procfs_target::create_inferior): Use get_shell.
	* cli/cli-cmds.c (shell_escape): Use get_shell.
	* windows-nat.c (windows_nat_target::create_inferior): Use
	get_shell.
	* common/pathstuff.c (get_shell): New function.
	* nat/fork-inferior.c (SHELL_FILE, get_startup_shell): Remove.
	(fork_inferior): Use get_shell.
	* common/pathstuff.h (get_shell): Declare.
2018-10-27 11:58:40 -06:00
Philippe Waroquiers c8ee3f04a6 Remove a bunch of usages of gdb_suppress_tests in 'runto_main'.
In the 'info -q -t' patch series, I started a new test from
gdb.threads/threadapply.exp, that uses an obsolete way to do
runto_main.

This patch changes all occurrences of runto_main using gdb_suppress_tests
to use instead fail+return.

Note that there are still about 220 occurrences of gdb_suppress_tests
but unclear (to me) if these can be similarly trivially be replaced by a
fail+return.  Further cleanup can be done in follow-up patches.

Tests run on Debian/x86_64.

gdb/testsuite/ChangeLog
2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.arch/altivec-regs.exp: Do not use gdb_suppress_tests in
	runto_main, use fail + return instead.
	gdb.arch/amd64-byte.exp: Likewise.
	gdb.arch/amd64-dword.exp: Likewise.
	gdb.arch/amd64-word.exp: Likewise.
	gdb.arch/e500-abi.exp: Likewise.
	gdb.arch/e500-regs.exp: Likewise.
	gdb.arch/gdb1291.exp: Likewise.
	gdb.arch/gdb1431.exp: Likewise.
	gdb.arch/i386-avx.exp: Likewise.
	gdb.arch/i386-byte.exp: Likewise.
	gdb.arch/i386-prologue.exp: Likewise.
	gdb.arch/i386-sse.exp: Likewise.
	gdb.arch/i386-word.exp: Likewise.
	gdb.arch/iwmmxt-regs.exp: Likewise.
	gdb.arch/pa-nullify.exp: Likewise.
	gdb.arch/powerpc-prologue.exp: Likewise.
	gdb.arch/s390-tdbregs.exp: Likewise.
	gdb.arch/vsx-regs.exp: Likewise.
	gdb.asm/asm-source.exp: Likewise.
	gdb.base/auxv.exp: Likewise.
	gdb.base/bigcore.exp: Likewise.
	gdb.base/overlays.exp: Likewise.
	gdb.base/savedregs.exp: Likewise.
	gdb.base/setshow.exp: Likewise.
	gdb.base/sigaltstack.exp: Likewise.
	gdb.base/sigbpt.exp: Likewise.
	gdb.base/siginfo-addr.exp: Likewise.
	gdb.base/siginfo-obj.exp: Likewise.
	gdb.base/siginfo-thread.exp: Likewise.
	gdb.base/siginfo.exp: Likewise.
	gdb.base/signull.exp: Likewise.
	gdb.base/sigrepeat.exp: Likewise.
	gdb.base/structs2.exp: Likewise.
	gdb.threads/threadapply.exp: Likewise.
	gdb.threads/watchthreads.exp: Likewise.
	gdb.threads/watchthreads2.exp: Likewise.
2018-10-27 14:47:36 +02:00
Philippe Waroquiers 82b5e646c2 Add a test case for info args|functions|locals|variables [-q] [-t TYPEREGEXP] [NAMEREGEXP]
Add a test case for info args|functions|locals|variables [-q] [-t TYPEREGEXP] [NAMEREGEXP]

gdb/testsuite/ChangeLog
2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/info_qt.c: New file.
	* gdb.base/info_qt.exp: New file.
2018-10-27 13:54:12 +02:00
Philippe Waroquiers e0a7911fa2 Announce changes in NEWS to info [args|functions|locals|variables]
Announce changes in NEWS to info [args|functions|locals|variables]

gdb/ChangeLog
2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Mention changes to 'info [args|functions|locals|variables]'
2018-10-27 13:54:08 +02:00
Philippe Waroquiers d321477b39 Document changes to info [args|functions|locals|variables]
Document changes to info [args|functions|locals|variables]

gdb/doc/ChangeLog
2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Information About a Frame): Document changes
	to 'info args' and 'info locals'.
	(Examining the Symbol Table): Document changes to 'info functions'
	and 'info variables'.
2018-10-27 13:49:02 +02:00
Philippe Waroquiers 12615cba84 Add [-q] [-t TYPEREGEXP] [NAMEREGEXP] args to info [args|functions|locals|variables]
Add [-q] [-t TYPEREGEXP] [NAMEREGEXP] args to info [args|functions|locals|variables]

Main changes are:
* stack.c: Add two regexp preg and treg to print_variable_and_value_data
  and used them inside do_print_variable_and_value to filter the
  variables to print.

* symtab.h: Add a new function bool treg_matches_sym_type_name, that
  factorises type matching logic.

* symtab.c: Add type/name matching logic to 'info functions|variables'.

* stack.c : Add type/name matching logic to 'info args|locals'.

gdb/ChangeLog
2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* stack.c (print_variable_and_value_data): Add preg and treg.
	(print_frame_local_vars): Add quiet, regexp and t_regexp arguments,
	and update callers.
	(print_frame_arg_vars): Likewise.
	(prepare_reg): New function.
	(info_locals_command): Extract info print args and use them.
	(info_args_command): Likewise.
	(_initialize_stack): Modify on-line help.
	* symtab.c (treg_matches_sym_type_name): New function.
	(search_symbols): New arg t_regexp.
	(symtab_symbol_info): New args quiet, regexp, t_regexp.
	(info_variables_command): Extract info print args and use them.
	(info_functions_command): Likewise.
	(info_types_command): Update call to symtab_symbol_info.
	(_initialize_symtab): Modify on-line help.
	* symtab.h (treg_matches_sym_type_name): New function.
	(search_symbols): New t_regexp arg.
2018-10-27 13:47:45 +02:00
Philippe Waroquiers 0d4cad90ca New cli-utils.h/.c function extract_info_print_args
New cli-utils.h/.c function extract_info_print_args factorizes
the extraction of the args '[-q] [-t TYPEREGEXP] [NAMEREGEXP]'.
New cli-utils.h/.c function report_unrecognized_option_error
factorizes reporting an unknown option for a command.

These functions will be used by the commands
  info [args|functions|locals|variables]

As extract_info_print_args will be used for 'info functions|variables' which
already have the NAMEREGEXP arg, it provides a backward compatible
behaviour.

cli-utils.c has a new static function extract_arg_maybe_quoted
that extracts an argument, possibly quoted.  The behaviour of this
function is similar to the parsing done by gdb_argv.

gdb/ChangeLog
2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli-utils.c (extract_arg_maybe_quoted): New function.
	(extract_info_print_args): New function.
	(info_print_args_help): New function.
	(report_unrecognized_option_error): New function.
	* cli-utils.h (extract_arg_maybe_quoted): New function.
	(extract_info_print_args): New function.
	(info_print_args_help): New function.
	(report_unrecognized_option_error): New function.
2018-10-27 13:45:57 +02:00
Tom Tromey 4c39bc0354 Remove DEF_VECs from symtab.h
This removes a couple of DEF_VECs from symtab.h, replacing them with
std::vector at the points of use.

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

	* dwarf2read.c (recursively_compute_inclusions): Use std::vector.
	(compute_compunit_symtab_includes): Update.
	* symtab.h: (symtab_ptr): Remove typedef.  Don't define a VEC.
	(compunit_symtab_ptr): Likewise.
2018-10-26 17:15:10 -06:00
John Baldwin fd2b4de5e6 Treat all unknown auxv tags on FreeBSD as unknown.
Previously, default_print_auxv_entry was called for any auxv entries
without a known AT_FREEBSD_* tag.  However, this resulted in false
positive matches when FreeBSD added a new tag that has an existing
AT_* tag with a different meaning.  Instead, only call
default_print_auxv_entry for specific tag values for which FreeBSD
matches the default AT_* values.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_print_auxv_entry): Only use
	default_print_auxv_entry for specific tag values.
2018-10-26 10:20:56 -07:00
John Baldwin d7ded98f4c Support AT_HWCAP2 on FreeBSD.
include/ChangeLog:

	* elf/common.h (AT_FREEBSD_HWCAP2): Define.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_print_auxv_entry): Handle AT_FREEBSD_HWCAP2.
2018-10-26 10:20:56 -07:00
Jim Wilson 77c6f5fcda RISC-V: Linux signal frame support.
Add support for recognizing signal trampolines, parsing the signal frame,
and reading register values from it.

	gdb/
	* riscv-linux-tdep.c: Include tramp-frame.h and trad-frame.h.
	(riscv_linux_sigframe_init): Declare.
	(RISCV_INST_LI_A7_SIGRETURN, RISCV_INT_ECALL): New.
	(riscv_linux_sigframe): New.
	(SIGFRAME_SIGINFO_SIZE, UCONTEXT_MCONTEXT_OFFSET): New.
	(riscv_linux_sigframe_init): Define.
	(riscv_linux_init_abi): Call tramp_frame_prepend_unwinder.
2018-10-26 10:32:58 -07:00
Jim Wilson 8a61382623 RISC-V: Linux signal frame support.
Make riscv_isa_flen available to the linux native code, and clean up duplicate
comments.

	gdb/
	* riscv-tdep.c (riscv_isa_xlen): Refer to riscv-tdep.h comment.
	(riscv_isa_flen): Likewise.  Drop static.
	* riscv-tdep.h (riscv_isa_xlen): Move riscv-tdep.c comment to here.
	(riscv_isa_flen): Likewise.
2018-10-26 10:29:46 -07:00
Edjunior Barbosa Machado 8d619c01db [PowerPC] Add support for HTM registers
This patch adds support for Hardware Transactional Memory registers
for the powerpc linux native and core file targets, and for the
pwoerpc linux server stub.

These registers include both the HTM special-purpose registers (TFHAR,
TEXASR and TFIAR) as well as the set of registers that are
checkpointed (saved) when a transaction is initiated, which the
processor restores in the event of a transaction failure.

The set of checkpointed general-purpose registers is returned by the
linux kernel in the same format as the regular general-purpose
registers, defined in struct pt_regs.  However, the architecture
specifies that only some of the registers present in pt_regs are
checkpointed (GPRs 0-31, CR, XER, LR and CTR).  The kernel fills the
slots for MSR and NIP with other info.  The other fields usually don't
have meaningful values.  GDB doesn't define registers that are not
checkpointed in the architecture, but when generating a core file, GDB
fills the slot for the checkpointed MSR with the regular MSR.  These
are usually similar, although some bits might be different, and in
some cases the checkpointed MSR will have a value of 0 in a
kernel-generated core-file.  The checkpointed NIP is filled with TFHAR
by GDB in the core-file, which is what the kernel does.  The other
fields are set to 0 by GDB.

Core files generated by the kernel have a note section for
checkpointed GPRs with the same size for both 32-bit and 64-bit
threads, and the values for the registers of a 32-bit thread are
squeezed in the first half, with no useful data in the second half.
GDB generates a smaller note section for 32-bit threads, but can read
both sizes.

The checkpointed XER is required to be 32-bit in the target
description documentation, even though the more recent ISAs define it
as 64-bit wide, since the high-order 32-bits are reserved, and because
in Linux there is no way to get a 64-bit checkpointed XER for 32-bit
threads.  If this changes in the future, the target description
feature requirement can be relaxed to allow for a 64-bit checkpointed
XER.

Access to the checkpointed CR (condition register) can be confusing.
The architecture only specifies that CR fields 1 to 7 (the 24 least
significant bits) are checkpointed, but the kernel provides all 8
fields (32 bits).  The value of field 0 is not masked by ptrace, so it
will sometimes show the result of some kernel operation, probably
treclaim., which sets this field.

The checkpointed registers are marked not to be saved and restored.
Inferior function calls during an active transaction don't work well,
and it's unclear what should be done in this case.  TEXASR and TFIAR
can be altered asynchronously, during transaction failure recording,
so they are also not saved and restored.  For consistency neither is
TFHAR.

Record and replay also doesn't work well when transactions are
involved.  This patch doesn't address this, so the values of the HTM
SPRs will sometimes be innacurate when the record/relay target is
enabled.  For instance, executing a "tbegin." alters TFHAR and TEXASR,
but these changes are not currently recorded.

Because the checkpointed registers are only available when a
transaction is active (or suspended), ptrace can return ENODATA when
gdb tries to read these registers and the inferior is not in a
transactional state.  The registers are set to the unavailable state
when this happens.  When gbd tries to write to one of these registers,
and it is unavailable, an error is raised.

The "fill" functions for checkpointed register sets in the server stub
are not implemented for the same reason as for the EBB register set,
since ptrace can also return ENODATA for checkpointed regsets.  The
same issues with 'G' packets apply here.

Just like for the EBB registers, tracepoints will not mark the
checkpointed registers as unavailable if the inferior was not in a
transaction, so their content will also show 0 instead of
<unavailable> when inspecting trace data.

The new tests record the values of the regular registers before
stepping the inferior through a "tbegin." instruction to start a
transaction, then the checkpointed registers are checked against the
recorded pre-transactional values.  New values are written to the
checkpointed registers and recorded, the inferior continues until the
transaction aborts (which is usually immediately when it is resumed),
and the regular registers are checked against the recorded values,
because the abort should have reverted the registers to these values.

Like for the EBB registers, target_store_registers will ignore the
checkpointed registers when called with -1 as the regno
argument (store all registers in one go).

gdb/ChangeLog:
2018-10-26  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
	    Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* arch/ppc-linux-tdesc.h (tdesc_powerpc_isa207_htm_vsx32l)
	(tdesc_powerpc_isa207_htm_vsx64l): Declare.
	* arch/ppc-linux-common.h (PPC_LINUX_SIZEOF_TM_SPRREGSET)
	(PPC32_LINUX_SIZEOF_CGPRREGSET, PPC64_LINUX_SIZEOF_CGPRREGSET)
	(PPC_LINUX_SIZEOF_CFPRREGSET, PPC_LINUX_SIZEOF_CVMXREGSET)
	(PPC_LINUX_SIZEOF_CVSXREGSET, PPC_LINUX_SIZEOF_CPPRREGSET)
	(PPC_LINUX_SIZEOF_CDSCRREGSET, PPC_LINUX_SIZEOF_CTARREGSET):
	Define.
	(struct ppc_linux_features) <htm>: New field.
	(ppc_linux_no_features): Add initializer for htm field.
	* arch/ppc-linux-common.c (ppc_linux_match_description): Return
	new tdescs.
	* nat/ppc-linux.h (PPC_FEATURE2_HTM, NT_PPC_TM_CGPR)
	(NT_PPC_TM_CFPR, NT_PPC_TM_CVMX, NT_PPC_TM_CVSX)
	(NT_PPC_TM_SPR, NT_PPC_TM_CTAR, NT_PPC_TM_CPPR, NT_PPC_TM_CDSCR):
	Define if not already defined.
	* features/Makefile (WHICH): Add rs6000/powerpc-isa207-htm-vsx32l
	and rs6000/powerpc-isa207-htm-vsx64l.
	(XMLTOC): Add rs6000/powerpc-isa207-htm-vsx32l.xml and
	rs6000/powerpc-isa207-htm-vsx64l.xml.
	* features/rs6000/power-htm-spr.xml: New file.
	* features/rs6000/power-htm-core.xml: New file.
	* features/rs6000/power64-htm-core.xml: New file.
	* features/rs6000/power-htm-fpu.xml: New file.
	* features/rs6000/power-htm-altivec.xml: New file.
	* features/rs6000/power-htm-vsx.xml: New file.
	* features/rs6000/power-htm-ppr.xml: New file.
	* features/rs6000/power-htm-dscr.xml: New file.
	* features/rs6000/power-htm-tar.xml: New file.
	* features/rs6000/powerpc-isa207-htm-vsx32l.xml: New file.
	* features/rs6000/powerpc-isa207-htm-vsx64l.xml: New file.
	* features/rs6000/powerpc-isa207-htm-vsx32l.c: Generate.
	* features/rs6000/powerpc-isa207-htm-vsx64l.c: Generate.
	* regformats/rs6000/powerpc-isa207-htm-vsx32l.dat: Generate.
	* regformats/rs6000/powerpc-isa207-htm-vsx64l.dat: Generate.
	* ppc-linux-nat.c (fetch_register, fetch_ppc_registers): Call
	fetch_regset with HTM regsets.
	(store_register, store_ppc_registers): Call store_regset with HTM
	regsets.
	(ppc_linux_nat_target::read_description): Set htm field in the
	features struct if needed.
	* ppc-linux-tdep.c: Include
	features/rs6000/powerpc-isa207-htm-vsx32l.c and
	features/rs6000/powerpc-isa207-htm-vsx64l.c.
	(ppc32_regmap_tm_spr, ppc32_regmap_cgpr, ppc64_le_regmap_cgpr)
	(ppc64_be_regmap_cgpr, ppc32_regmap_cfpr, ppc32_le_regmap_cvmx)
	(ppc32_be_regmap_cvmx, ppc32_regmap_cvsx, ppc32_regmap_cppr)
	(ppc32_regmap_cdscr, ppc32_regmap_ctar): New globals.
	(ppc32_linux_tm_sprregset, ppc32_linux_cgprregset)
	(ppc64_be_linux_cgprregset, ppc64_le_linux_cgprregset)
	(ppc32_linux_cfprregset, ppc32_le_linux_cvmxregset)
	(ppc32_be_linux_cvmxregset, ppc32_linux_cvsxregset)
	(ppc32_linux_cpprregset, ppc32_linux_cdscrregset)
	(ppc32_linux_ctarregset): New globals.
	(ppc_linux_cgprregset, ppc_linux_cvmxregset): New functions.
	(ppc_linux_collect_core_cpgrregset): New function.
	(ppc_linux_iterate_over_regset_sections): Call back with the htm
	regsets.
	(ppc_linux_core_read_description): Check if the tm spr section is
	present and set htm in the features struct.
	(_initialize_ppc_linux_tdep): Call
	initialize_tdesc_powerpc_isa207_htm_vsx32l and
	initialize_tdesc_powerpc_isa207_htm_vsx64l.
	* ppc-linux-tdep.h (ppc_linux_cgprregset, ppc_linux_cvmxregset):
	Declare.
	(ppc32_linux_tm_sprregset, ppc32_linux_cfprregset)
	(ppc32_linux_cvsxregset, ppc32_linux_cpprregset)
	(ppc32_linux_cdscrregset, ppc32_linux_ctarregset): Declare.
	* ppc-tdep.h (struct gdbarch_tdep) <have_htm_spr, have_htm_core>:
	New fields.
	<have_htm_fpu, have_htm_altivec, have_htm_vsx>:
	Likewise.
	<ppc_cppr_regnum, ppc_cdscr_regnum, ppc_ctar_regnum>: Likewise.
	<ppc_cdl0_regnum, ppc_cvsr0_regnum, ppc_cefpr0_regnum>: Likewise.
	(enum) <PPC_TFHAR_REGNUM, PPC_TEXASR_REGNUM, PPC_TFIAR_REGNUM>:
	New enum fields.
	<PPC_CR0_REGNUM, PPC_CCR_REGNUM, PPC_CXER_REGNUM>: Likewise.
	<PPC_CLR_REGNUM, PPC_CCTR_REGNUM, PPC_CF0_REGNUM>: Likewise.
	<PPC_CFPSCR_REGNUM, PPC_CVR0_REGNUM, PPC_CVSCR_REGNUM>: Likewise.
	<PPC_CVRSAVE_REGNUM, PPC_CVSR0_UPPER_REGNUM>: Likewise.
	<PPC_CPPR_REGNUM, PPC_CDSCR_REGNUM>: Likewise.
	<PPC_CTAR_REGNUM>: Likewise.
	(PPC_IS_TMSPR_REGNUM, PPC_IS_CKPTGP_REGNUM, PPC_IS_CKPTFP_REGNUM)
	(PPC_IS_CKPTVMX_REGNUM, PPC_IS_CKPTVSX_REGNUM): Define.
	* rs6000-tdep.c (IS_CDFP_PSEUDOREG, IS_CVSX_PSEUDOREG)
	(IS_CEFP_PSEUDOREG): Define.
	(rs6000_register_name): Hide the upper halves of checkpointed VSX
	registers.  Return names for the checkpointed DFP, VSX, and EFP
	pseudo registers.
	(rs6000_pseudo_register_type): Remove initial assert and raise an
	internal error in the else clause instead.  Return types for the
	checkpointed DFP, VSX, and EFP pseudo registers.
	(dfp_pseudo_register_read, dfp_pseudo_register_write): Handle
	checkpointed DFP pseudo registers.
	(vsx_pseudo_register_read, vsx_pseudo_register_write): Handle
	checkpointed VSX pseudo registers.
	(efp_pseudo_register_read, efp_pseudo_register_write): Rename
	from efpr_pseudo_register_read and
	efpr_pseudo_register_write.  Handle checkpointed EFP pseudo
	registers.
	(rs6000_pseudo_register_read, rs6000_pseudo_register_write):
	Handle checkpointed DFP, VSX, and EFP registers.
	(dfp_ax_pseudo_register_collect, vsx_ax_pseudo_register_collect)
	(efp_ax_pseudo_register_collect): New functions.
	(rs6000_ax_pseudo_register_collect): Move DFP, VSX and EFP pseudo
	register logic to new functions.  Handle checkpointed DFP, VSX,
	and EFP pseudo registers.
	(rs6000_gdbarch_init): Look for and validate the htm features.
	Include checkpointed DFP, VSX and EFP pseudo-registers.
	* NEWS: Mention access to PPR, DSCR, TAR, EBB/PMU registers and
	HTM registers.

gdb/gdbserver/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* configure.srv (ipa_ppc_linux_regobj): Add
	powerpc-isa207-htm-vsx32l-ipa.o and
	powerpc-isa207-htm-vsx64l-ipa.o.
	(powerpc*-*-linux*): Add powerpc-isa207-htm-vsx32l.o and
	powerpc-isa207-htm-vsx64l.o to srv_regobj.  Add
	rs6000/power-htm-spr.xml, rs6000/power-htm-core.xml,
	rs6000/power64-htm-core.xml, rs6000/power-htm-fpu.xml,
	rs6000/power-htm-altivec.xml, rs6000/power-htm-vsx.xml,
	rs6000/power-htm-ppr.xml, rs6000/power-htm-dscr.xml,
	rs6000/power-htm-tar.xml, rs6000/powerpc-isa207-htm-vsx32l.xml,
	and rs6000/powerpc-isa207-htm-vsx64l.xml to srv_xmlfiles.
	* linux-ppc-tdesc-init.h (enum ppc_linux_tdesc)
	<PPC_TDESC_ISA207_HTM_VSX>: New enum value.
	(init_registers_powerpc_isa207_htm_vsx32l)
	(init_registers_powerpc_isa207_htm_vsx64l): Declare.
	* linux-ppc-low.c (ppc_fill_tm_sprregset, ppc_store_tm_sprregset)
	(ppc_store_tm_cgprregset, ppc_store_tm_cfprregset)
	(ppc_store_tm_cvrregset, ppc_store_tm_cvsxregset)
	(ppc_store_tm_cpprregset, ppc_store_tm_cdscrregset)
	(ppc_store_tm_ctarregset): New functions.
	(ppc_regsets): Add entries for HTM regsets.
	(ppc_arch_setup): Set htm in features struct when needed.  Set
	sizes for the HTM regsets.
	(ppc_get_ipa_tdesc_idx): Return PPC_TDESC_ISA207_HTM_VSX.
	(initialize_low_arch): Call
	init_registers_powerpc_isa207_htm_vsx32l and
	init_registers_powerpc_isa207_htm_vsx64l.
	* linux-ppc-ipa.c (get_ipa_tdesc): Handle
	PPC_TDESC_ISA207_HTM_VSX.
	(initialize_low_tracepoint): Call
	init_registers_powerpc_isa207_htm_vsx32l and
	init_registers_powerpc_isa207_htm_vsx64l.

gdb/testsuite/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.arch/powerpc-htm-regs.c: New file.
	* gdb.arch/powerpc-htm-regs.exp: New file.

gdb/doc/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.texinfo (PowerPC Features): Describe new features
	"org.gnu.gdb.power.htm.spr", "org.gnu.gdb.power.htm.core",
	"org.gnu.gdb.power.htm.fpu", "org.gnu.gdb.power.htm.altivec",
	"org.gnu.gdb.power.htm.vsx", "org.gnu.gdb.power.htm.ppr",
	"org.gnu.gdb.power.htm.dscr", "org.gnu.gdb.power.htm.tar".
2018-10-26 10:23:01 -03:00
Pedro Franco de Carvalho 81ab84fd6c [PowerPC] Reject tdescs with VSX and no FPU or Altivec
Currently rs6000_gdbarch_init will accept a tdesc with the
"org.gnu.gdb.power.vsx" feature but without the
"org.gnu.gdb.power.altivec" or "org.gnu.gdb.power.fpu".

It isn't clear from the standard features documentation that these are
requirements.  However, these tdescs would cause trouble in the VSX
pseudo-register functions, so this patch will cause them to be
rejected.

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* rs6000-tdep.c (rs6000_gdbarch_init): Reject tdescs with vsx but
	without altivec or fpu.
2018-10-26 10:18:57 -03:00
Edjunior Barbosa Machado 232bfb8644 [PowerPC] Add support for EBB and PMU registers
This patch adds support for registers of the Event Based Branching and
Performance Monitoring Units for the powerpc linux native and core
file targets, and for the powerpc linux server stub.

All three EBB registers are accessible.  Only a subset of the PMU
registers can be accessed through ptrace.  Because of this, the PMU
registers are enumerated individually in gdbarch_tdep, as opposed to
having a single "have_pmu" flag.  This is intended to make it easier
to add additional PMU registers in the future, since checking a
"have_pmu" flag elsewhere in the code would no longer be correct.  The
tdesc feature is named org.gnu.gdb.power.linux.pmu because of this.

It's unclear if it makes sense to save and restore these registers
across function calls, since some of them can be modified
asynchronously.  They are also not tracked in record-replay mode.

The kernel can return ENODATA when ptrace is used to get the EBB
registers, unless a linux performance event that uses EBB is open in
the inferior.  For this reason, the "fill" functions in the server
stub for the ebb register sets is not implemented.

Since gdbserver writes all registers in one go before resuming the
inferior, this error would not be detected at the time the user tries
to write to one of the registers on the client side, and gdbserver
would print out warnings every time it resumes the inferior when no
ebb performance event is opened, so there is currently no
straightforward way to handle this case.  This means the ebb registers
in the client-side regcache can become dirty when the user tries to
write to them, until the inferior is resumed and stopped again.

A related issue is that 'G' packets used to write to unrelated
registers will include bad data for the EBB registers if they are
unavailable, since no register status information is included in the
'G' packet.  This data won't be written to the inferior by the
gdbserver stub because the "fill" functions are not implemented, and
currently the gdbserver stub doesn't change the status of the
registers in its own regcache in response to 'G' packets.

Another limitation for the ebb registers is that traceframes don't
record if registers are available or not, so if these registers are
collected when a tracepoint is hit and the inferior has no ebb event
opened, the user will see zero values for all of them, instead of the
usual <unavailable>.

Because these registers are often unavailable, trying to store them
with target_store_registers with -1 for the regno argument (all
registers) would almost always fail, so they are ignored in this case.

gdb/ChangeLog:
2018-10-26  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
	    Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* arch/ppc-linux-common.h (PPC_LINUX_SIZEOF_EBBREGSET)
	(PPC_LINUX_SIZEOF_PMUREGSET): Declare.
	* nat/ppc-linux.h (PPC_FEATURE2_EBB, NT_PPC_EBB, NT_PPC_PMU):
	Define if not already defined.
	* features/rs6000/power-ebb.xml: New file.
	* features/rs6000/power-linux-pmu.xml: New file.
	* features/rs6000/powerpc-isa207-vsx32l.xml: Include ebb and pmu
	features.
	* features/rs6000/powerpc-isa207-vsx64l.xml: Likewise.
	* features/rs6000/powerpc-isa207-vsx32l.c: Re-generate.
	* features/rs6000/powerpc-isa207-vsx64l.c: Re-generate.
	* regformats/rs6000/powerpc-isa207-vsx32l.dat: Re-generate.
	* regformats/rs6000/powerpc-isa207-vsx64l.dat: Re-generate.
	* ppc-linux-nat.c (fetch_register, fetch_ppc_registers): Call
	fetch_regset with ebb and pmu regsets.
	(store_register, store_ppc_registers): Call store_regset with ebb
	and pmu regsets.
	(ppc_linux_nat_target::read_description): Set isa207 field in the
	features struct if ebb and pmu are avaiable.
	* ppc-linux-tdep.c (ppc32_regmap_ebb, ppc32_regmap_pmu)
	(ppc32_linux_ebbregset, ppc32_linux_pmuregset): New globals.
	(ppc_linux_iterate_over_regset_sections): Call back with the ebb
	and pmu regsets.
	(ppc_linux_core_read_description): Check if the pmu section is
	present and set isa207 in the features struct.
	* ppc-linux-tdep.h (ppc32_linux_ebbregset)
	(ppc32_linux_pmuregset): Declare.
	* ppc-tdep.h (struct gdbarch_tdep) <ppc_mmcr0_regnum>: New field.
	<ppc_mmcr2_regnum, ppc_siar_regnum, ppc_sdar_regnum>: New fields.
	<ppc_sier_regnum>: New field.
	(enum): <PPC_BESCR_REGNUM, PPC_EBBHR_REGNUM, PPC_EBBRR_REGNUM>:
	New enum values.
	<PPC_MMCR0_REGNUM, PPC_MMCR2_REGNUM, PPC_SIAR_REGNUM>: New enum
	values.
	<PPC_SDAR_REGNUM, PPC_SIER_REGNUM>: New enum values.
	(PPC_IS_EBB_REGNUM, PPC_IS_PMU_REGNUM): Define.
	* rs6000-tdep.c (rs6000_gdbarch_init): Look for and validate the
	ebb and pmu features.

gdb/gdbserver/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* configure.srv (powerpc*-*-linux*): Add rs6000/power-ebb.xml and
	rs6000/power-linux-pmu.xml to srv_xmlfiles.
	* linux-ppc-low.c (ppc_store_ebbregset, ppc_fill_pmuregset)
	(ppc_store_pmuregset): New functions.
	(ppc_regsets): Add entries for ebb and pmu regsets.
	(ppc_arch_setup): Set isa207 in features struct if the ebb and
	pmu regsets are available.  Set sizes for these regsets.

gdb/doc/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.texinfo (PowerPC Features): Describe new features
	"org.gnu.gdb.power.ebb" and "org.gnu.gdb.power.linux.pmu".
2018-10-26 10:15:23 -03:00
Edjunior Barbosa Machado f2cf6173f3 [PowerPC] Add support for TAR
This patch adds support for the Target Address Register for powerpc
linux native and core file targets, and in the powerpc linux server
stub.

gdb/ChangeLog:
2018-10-26  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
	    Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* arch/ppc-linux-tdesc.h (tdesc_powerpc_isa207_vsx32l)
	(tdesc_powerpc_isa207_vsx64l): Declare.
	* arch/ppc-linux-common.h (PPC_LINUX_SIZEOF_TARREGSET): Define.
	(struct ppc_linux_features) <isa207>: New field.
	(ppc_linux_no_features): Add initializer for isa207 field.
	* arch/ppc-linux-common.c (ppc_linux_match_description): Return
	new tdescs.
	* nat/ppc-linux.h (PPC_FEATURE2_ARCH_2_07, PPC_FEATURE2_TAR)
	(NT_PPC_TAR): Define if not already defined.
	* features/Makefile (WHICH): Add rs6000/powerpc-isa207-vsx32l and
	rs6000/powerpc-isa207-vsx64l.
	(XMLTOC): Add rs6000/powerpc-isa207-vsx32l.xml and
	rs6000/powerpc-isa207-vsx64l.xml.
	* features/rs6000/power-tar.xml: New file.
	* features/rs6000/powerpc-isa207-vsx32l.xml: New file.
	* features/rs6000/powerpc-isa207-vsx64l.xml: New file.
	* features/rs6000/powerpc-isa207-vsx32l.c: Generate.
	* features/rs6000/powerpc-isa207-vsx64l.c: Generate.
	* regformats/rs6000/powerpc-isa207-vsx32l.dat: Generate.
	* regformats/rs6000/powerpc-isa207-vsx64l.dat: Generate.
	* ppc-linux-nat.c (fetch_register, fetch_ppc_registers): Call
	fetch_regset with the TAR regset.
	(store_register, store_ppc_registers): Call store_regset with the
	TAR regset.
	(ppc_linux_nat_target::read_description): Set isa207 field in the
	features struct if needed.
	* ppc-linux-tdep.c: Include
	features/rs6000/powerpc-isa207-vsx32l.c and
	features/rs6000/powerpc-isa207-vsx64l.c.
	(ppc32_regmap_tar, ppc32_linux_tarregset): New globals.
	(ppc_linux_iterate_over_regset_sections): Call back with the tar
	regset.
	(ppc_linux_core_read_description): Check if the tar section is
	present and set isa207 in the features struct.
	(_initialize_ppc_linux_tdep): Call
	initialize_tdesc_powerpc_isa207_vsx32l and
	initialize_tdesc_powerpc_isa207_vsx64l.
	* ppc-linux-tdep.h (ppc32_linux_tarregset): Declare.
	* ppc-tdep.h (gdbarch_tdep) <ppc_tar_regnum>: New field.
	(enum) <PPC_TAR_REGNUM>: New enum value.
	* rs6000-tdep.c (rs6000_gdbarch_init): Look for and validate tar
	feature.
	(ppc_process_record_op31): Record changes to TAR.

gdb/gdbserver/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* configure.srv (ipa_ppc_linux_regobj): Add
	powerpc-isa207-vsx64l-ipa.o and powerpc-isa207-vsx32l-ipa.o.
	(powerpc*-*-linux*): Add powerpc-isa207-vsx32l.o and
	powerpc-isa207-vsx64l.o to srv_regobj, add rs6000/power-tar.xml,
	rs6000/powerpc-isa207-vsx32l.xml, and
	rs6000/powerpc-isa207-vsx64l.xml to srv_xmlfiles.
	* linux-ppc-tdesc-init.h (enum ppc_linux_tdesc)
	<PPC_TDESC_ISA207_VSX>: New enum value.
	(init_registers_powerpc_isa207_vsx32l): Declare.
	(init_registers_powerpc_isa207_vsx64l): Declare.
	* linux-ppc-low.c (ppc_fill_tarregset): New function.
	(ppc_store_tarregset): New function.
	(ppc_regsets): Add entry for the TAR regset.
	(ppc_arch_setup): Set isa207 in features struct when needed.  Set
	size for the TAR regsets.
	(ppc_get_ipa_tdesc_idx): Return PPC_TDESC_ISA207_VSX.
	(initialize_low_arch): Call init_registers_powerpc_isa207_vsx32l
	and init_registers_powerpc_isa207_vsx64l.
	* linux-ppc-ipa.c (get_ipa_tdesc): Handle PPC_TDESC_ISA207_VSX.
	(initialize_low_tracepoint): Call
	init_registers_powerpc_isa207_vsx32l and
	init_registers_powerpc_isa207_vsx64l.

gdb/testsuite/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.arch/powerpc-tar.c: New file.
	* gdb.arch/powerpc-tar.exp: New file.

gdb/doc/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.texinfo (PowerPC Features): Describe new feature
	"org.gnu.gdb.power.tar".
2018-10-26 10:11:33 -03:00
Edjunior Barbosa Machado 7ca18ed6d2 [PowerPC] Add support for PPR and DSCR
This patch adds gdb support for the Program Priorty Register and the
Data Stream Control Register, for the powerpc linux native and core
file targets, and for the powerpc linux server stub.

gdb/ChangeLog:
2018-10-26  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
	    Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* arch/ppc-linux-tdesc.h (tdesc_powerpc_isa205_ppr_dscr_vsx32l)
	(tdesc_powerpc_isa205_ppr_dscr_vsx64l): Declare.
	* arch/ppc-linux-common.h (PPC_LINUX_SIZEOF_PPRREGSET)
	(PPC_LINUX_SIZEOF_DSCRREGSET): Define.
	(struct ppc_linux_features) <ppr_dscr>: New field.
	(ppc_linux_no_features): Add initializer for ppr_dscr field.
	* arch/ppc-linux-common.c (ppc_linux_match_description): Return
	new tdescs.
	* nat/ppc-linux.h (PPC_FEATURE2_DSCR, NT_PPC_PPR, NT_PPC_DSCR):
	Define if not already defined.
	* features/Makefile (WHICH): Add
	rs6000/powerpc-isa205-ppr-dscr-vsx32l and
	rs6000/powerpc-isa205-ppr-dscr-vsx64l.
	(XMLTOC): Add rs6000/powerpc-isa205-ppr-dscr-vsx32l.xml and
	rs6000/powerpc-isa205-ppr-dscr-vsx64l.xml.
	* features/rs6000/power-dscr.xml: New file.
	* features/rs6000/power-ppr.xml: New file.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.xml: New file.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.xml: New file.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.c: Generate.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c: Generate.
	* regformats/rs6000/powerpc-isa205-ppr-dscr-vsx32l.dat: Generate.
	* regformats/rs6000/powerpc-isa205-ppr-dscr-vsx64l.dat: Generate.
	* ppc-linux-nat.c: Include <sys/uio.h>.
	(fetch_regset, store_regset, check_regset): New functions.
	(fetch_register, fetch_ppc_registers): Call fetch_regset with
	DSCR and PPR regsets.
	(store_register, store_ppc_registers): Call store_regset with
	DSCR and PPR regsets.
	(ppc_linux_get_hwcap2): New function.
	(ppc_linux_nat_target::read_description): Call
	ppc_linux_get_hwcap2 and check_regset, set ppr_dscr field in the
	features struct if needed.
	* ppc-linux-tdep.c: Include
	features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.c and
	features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c.
	(ppc32_regmap_ppr, ppc32_regmap_dscr, ppc32_linux_pprregset)
	(ppc32_linux_dscrregset): New globals.
	(ppc_linux_iterate_over_regset_sections): Call back with the ppr
	and dscr regsets.
	(ppc_linux_core_read_description): Check if the ppr and dscr
	sections are present and set ppr_dscr in the features struct.
	(_initialize_ppc_linux_tdep): Call
	initialize_tdesc_powerpc_isa205_ppr_dscr_vsx32l and
	initialize_tdesc_powerpc_isa205_ppr_dscr_vsx64l.
	* ppc-linux-tdep.h (ppc32_linux_pprregset)
	(ppc32_linux_dscrregset): Declare.
	* ppc-tdep.h (struct gdbarch_tdep) <ppc_ppr_regnum>: New field.
	<ppc_dscr_regnum>: New field.
	(enum) <PPC_PPR_REGNUM, PPC_DSCR_REGNUM>: New enum values.
	* rs6000-tdep.c (rs6000_gdbarch_init): Look for and validate ppr
	and dscr features.
	(ppc_process_record_op31): Record changes to PPR and DSCR.

gdb/gdbserver/ChangeLog:
2018-10-26  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
	    Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* configure.srv (ipa_ppc_linux_regobj): Add
	powerpc-isa205-ppr-dscr-vsx32l-ipa.o and
	powerpc-isa205-ppr-dscr-vsx64l-ipa.o.
	(powerpc*-*-linux*): Add powerpc-isa205-ppr-dscr-vsx32l.o and
	powerpc-isa205-ppr-dscr-vsx64l.o to srv_regobj, add
	rs6000/power-dscr.xml, rs6000/power-ppr.xml,
	rs6000/powerpc-isa205-ppr-dscr-vsx32l.xml and
	rs6000/powerpc-isa205-ppr-dscr-vsx64l.xml to srv_xmlfiles.
	* linux-ppc-tdesc-init.h (enum ppc_linux_tdesc)
	<PPC_TDESC_ISA205_PPR_DSCR_VSX>: New enum value.
	(init_registers_powerpc_isa205_ppr_dscr_vsx32l)
	(init_registers_powerpc_isa205_ppr_dscr_vsx64l): Declare.
	* linux-ppc-low.c: Include "elf/common.h" and <sys/uio.h>.
	(ppc_hwcap): Add comment.
	(ppc_hwcap2): New global.
	(ppc_check_regset, ppc_fill_pprregset, ppc_store_pprregset)
	(ppc_fill_dscrregset, ppc_store_dscrregset): New functions.
	(ppc_regsets): Add entries for the DSCR and PPR regsets.
	(ppc_arch_setup): Get AT_HWCAP2.  Set ppr_dscr in features struct
	when needed.  Set sizes for the the DSCR and PPR regsets.
	(ppc_get_ipa_tdesc_idx): Return PPC_TDESC_ISA205_PPR_DSCR_VSX.
	(initialize_low_arch): Call
	init_registers_powerpc_isa205_ppr_dscr_vsx32l and
	init_registers_powerpc_isa205_ppr_dscr_vsx64l.
	* linux-ppc-ipa.c (get_ipa_tdesc): Handle
	PPC_TDESC_ISA205_PPR_DSCR_VSX.
	(initialize_low_tracepoint): Call
	init_registers_powerpc_isa205_ppr_dscr_vsx32l and
	init_registers_powerpc_isa205_ppr_dscr_vsx64l.

gdb/testsuite/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.arch/powerpc-ppr-dscr.c: New file.
	* gdb.arch/powerpc-ppr-dscr.exp: New file.

gdb/doc/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.texinfo (PowerPC Features): Describe new features
	"org.gnu.gdb.power.ppr" and "org.gnu.gdb.power.dscr".
2018-10-26 10:03:46 -03:00
Pedro Franco de Carvalho 93b4691f0f [PowerPC] Refactor have_ initializers in rs6000-tdep.c
This patch refactors a series of initializers in rs6000_gdbarch_init
for clarity.  The have_fpu initializer is also changed to set the
variable to 0, like the other similar variables.  This doesn't affect
program behavior.

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* rs6000-tdep.c (rs6000_gdbarch_init): Replace line wrapping by a
	second initializer line for the have_* variables.  Initialize
	have_fpu to 0 instead of 1.
2018-10-26 09:57:07 -03:00
Pedro Franco de Carvalho 71733a7bf6 [PowerPC] Fix indentation in arch/ppc-linux-common.c
This patch parenthesizes the tdesc selection expressions in
arch/ppc-linux-common.c so that they can be tab-indented.

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* arch/ppc-linux-common.c (ppc_linux_match_description):
	Parenthesize tdesc assignements and indent them properly.
2018-10-26 09:54:04 -03:00
Pedro Franco de Carvalho 3d907528ca [PowerPC] Fix two if statements in gdb/ppc-linux-nat.c
This patch changes two if statements to else if statements in
ppc-linux-nat.c:fetch_register for clarity.

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* ppc-linux-nat.c (fetch_register): Change if statement to else
	if.
	(store_register): Likewise.
2018-10-26 09:52:37 -03:00
Pedro Franco de Carvalho 500f01a0e2 [PowerPC] Remove rs6000_pseudo_register_reggroup_p
This patch removes rs6000_pseudo_register_reggroup_p.

Group membership for the pseudoregisters can be detected through their
types in default_register_reggroup_p through
tdesc_register_reggroup_p.

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* rs6000-tdep.c: Remove reggroups.h include.
	(rs6000_pseudo_register_reggroup_p): Remove.
	(rs6000_gdbarch_init): Remove call to
	set_tdesc_pseudo_register_reggroup_p.
2018-10-26 09:51:08 -03:00
Pedro Franco de Carvalho 7ed29001c4 Add decfloat registers to float reggroup
This patch changes default_register_reggroup_p to return true when the
register type is decimal floating point and the reggroup is
float_reggroup.

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* reggroups.c (default_register_reggroup_p): Return true for
	decfloat registers and float_reggroup.
2018-10-26 09:48:33 -03:00
Pedro Franco de Carvalho 5c849b222b [PowerPC] Don't zero-initialize vector register buffers
Now that linux-tdep.c already zero-initializes the buffer used for
generating core file notes, there is no need to do this in the linux
collect functions for the vector regset.  The memsets in gdbserver were
not useful to begin with.

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* ppc-linux-tdep.c (ppc_linux_collect_vrregset): Remove.
	(ppc32_le_linux_vrregset, ppc32_be_linux_vrregset): Replace
	ppc_linux_collect_vrregset by regcache_collect_regset.

gdb/gdbserver/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* linux-ppc-low.c (ppc_fill_vrregset): Remove memset calls.
2018-10-26 09:46:02 -03:00
Pedro Franco de Carvalho afde3032dd Zero-initialize linux note sections
This patches changes linux-tdep.c so that the buffer used to write
note sections when generating a core file is zero-initialized.  This
way, bytes that are not collected won't contain random
data (e.g. padding bytes).

gdb/ChangeLog:
2018-10-26  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* linux-tdep.c (linux_collect_regset_section_cb): Use
	std::vector<gdb_byte> instead of char * and malloc for buf.
	Remove xfree.
2018-10-26 09:41:20 -03:00
Sangamesh Mallayya b971899198 Fix SYMBOL_LANGUAGE assertion failure on AIX. 2018-10-26 15:31:36 +05:30
Andrew Burgess 0b0eff8b1d gdb/riscv: Remove redundant code, and catch more errors when accessing MISA
When reading the MISA register, the RISC-V specification says that, if
MISA can't be found then a default value of 0 should be assumed.

As such, this patch ensures that GDB ignores errors when accessing
both the new and old locations for the MISA register.

Additionally, this patch removes an unneeded flag parameter which
didn't provide any additional functionality beyond checking the MISA
for the default value of 0.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_read_misa_reg): Update comment, remove
	READ_P parameter, catch and ignore register access errors from
	either the old or new MISA location.
	(riscv_has_feature): Update call to riscv_read_misa_reg.
2018-10-26 08:07:19 +01:00
Tom de Vries ac732bc9fd [gdb/testsuite] Move valgrind-db-attach.{c,exp} to valgrind-bt.{c,exp}
Now that valgrind-db-attach.exp no longer use --db-attach, rename
valgrind-db-attach.{c,exp} to valgrind-bt.{c,exp}.

2018-10-25  Tom de Vries  <tdevries@suse.de>

    * gdb.base/valgrind-db-attach.c: Rename to ...
    * gdb.base/valgrind-bt.c: ... this.
    * gdb.base/valgrind-db-attach.exp: Rename to ...
    * gdb.base/valgrind-bt.exp: ... this.
2018-10-25 16:20:05 +02:00
Tom de Vries bfcc0eba9e [gdb/testsuite] Rewrite valgrind-db-attach.exp to use vgdb
The valgrind option --db-attach has been deprecated in version 3.10.0, and
removed in version 3.11.0, so the valgrind-db-attach.exp testcase is
unsupported starting version 3.11.0.

Rewrite the test-case to use vgdb instead (making it supported starting
version 3.7.0).

Tested on x86_64-linux with and without --target_board=native-gdbserver.

2018-10-25  Tom de Vries  <tdevries@suse.de>

	* gdb.base/valgrind-db-attach.exp: Rewrite to use vgdb.
2018-10-25 16:05:58 +02:00
Andrew Burgess b352ceb6b4 gdb/python: Make convert_values_to_python return gdbpy_ref<>
Make convert_values_to_python return a gdbpy_ref<> directly rather
than building a gdbpy_ref<>, releasing it, and then having a new
gdbpy_ref<> created to hold the result.

I also added a header comment to convert_values_to_python.

gdb/ChangeLog:

	* python/py-function.c (convert_values_to_python): Return
	gdbpy_ref<>. Add header comment.
	(fnpy_call): Adjust.
2018-10-25 12:20:18 +01:00
Andrew Burgess 50db9ef4c0 gdb/python: Make cmdpy_completer_helper return gdbpy_ref<>
Make cmdpy_completer_helper return a gdbpy_ref<> directly rather than
building a gdbpy_ref<>, releasing it, and then having a new
gdbpy_ref<> created to hold the result.

gdb/ChangeLog:

	* python/py-cmd.c (cmdpy_completer_helper): Return gdbpy_ref<>.
	(cmdpy_completer_handle_brkchars): Adjust.
	(cmdpy_completer): Adjust.
2018-10-25 12:20:18 +01:00
Andrew Burgess ee67fd7f3f gdb/riscv: Use correct regnum in riscv_linux_nat_target::fetch_registers
In riscv_linux_nat_target::fetch_registers, if we are asked to supply
all registers (regnum parameter is -1), then we currently end up
calling regcache::raw_supply_zeroed with the regnum -1, which is
invalid.  Instead we should be passing the regnum of the specific
register we wish to supply zeroed, in this case RISCV_CSR_MISA_REGNUM.

I removed the extra { ... } block in line with the coding standard
while editing this area.

gdb/ChangeLog:

	* riscv-linux-nat.c (riscv_linux_nat_target::fetch_registers):
	Pass correct regnum to raw_supply_zeroed.
2018-10-25 12:03:31 +01:00
Tom de Vries fe1a5cad30 [gdb/testsuite] Log wait status on process no longer exists error
Proc gdb_test_multiple can run into a process no longer exists error, but when
that happens it shows no details about the process:
...
ERROR: Process no longer exists
...

Fix this by showing the wait status of the process in the log:
...
ERROR: GDB process no longer exists
GDB process exited with wait status 8106 exp8 0 0 CHILDKILLED SIGSEGV \
  {segmentation violation}
...

In order to run the wait commmand we need an explicit pid, so we can't use
any_spawn_id, and duplicate the "-i any_spawn_id eof" pattern for gdb_spawn_id,
and add the wait status logging there.

Build and tested on x86_64-linux.

2018-10-24  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (gdb_test_multiple): Log wait status on process no
	longer exists error.
2018-10-24 16:22:58 +02:00
Tom de Vries a76dc3b770 [gdb/testsuite] Rewrite catch-follow-exec.exp using gdb_test
The testcase catch-follow-exec.exp is written use gdb -batch in order to avoid
a GDB SIGTTOU.  After the commit of "Avoid GDB SIGTTOU on catch exec + set
follow-exec-mode new (PR 23368)", that no longer is necessary.

Rewrite the test using regular gdb_test commands.

Tested with x86_64-linux.

2018-10-24  Tom de Vries  <tdevries@suse.de>

	* gdb.base/catch-follow-exec.exp: Rewrite using gdb_test.
2018-10-24 13:18:04 +02:00
Tom de Vries 4df46df7a4 [gdb/testsuite] Handle removed valgrind option --db-attach
When running valgrind-db-attach.exp with valgrind version 3.13.0, we get:
...
PASS: gdb.base/valgrind-db-attach.exp: spawn valgrind
valgrind: Unknown option: --db-attach=yes
valgrind: Use --help for more information or consult the user manual.
ERROR: Process no longer exists
UNRESOLVED: gdb.base/valgrind-db-attach.exp: valgrind started
...

The valgrind option --db-attach has been deprecated in version 3.10.0, and
removed in version 3.11.0.

Fix valgrind-db-attach.exp to replace the ERROR/UNRESOLVED with:
...
UNSUPPORTED: gdb.base/valgrind-db-attach.exp: valgrind started
...

Tested on x86_64-linux.

2018-10-24  Tom de Vries  <tdevries@suse.de>

	* gdb.base/valgrind-db-attach.exp: Handle removed support for
	--db-attach in valgrind.
2018-10-24 13:11:26 +02:00
Hafiz Abid Qadeer bea556ab08 Fix failing cooked_read selftest for CSKY.
The problem was discussed and approved in
https://sourceware.org/ml/gdb-patches/2018-10/msg00514.html

2018-10-23  Hafiz Abid Qadeer  <abidh@codesourcery.com>

	* regcache.c (cooked_read_test): Add CSKY to the list of
	architectures with a save_reggroup
2018-10-23 23:16:58 +01:00
Simon Marchi 35ed81d4f4 Avoid GDB SIGTTOU on catch exec + set follow-exec-mode new (PR 23368)
Here's a summary of PR 23368:

  #include <unistd.h>
  int main (void)
  {
    char *exec_args[] = { "/bin/ls", NULL };
    execve (exec_args[0], exec_args, NULL);
  }

$ gdb -nx t -ex "catch exec" -ex "set follow-exec-mode new" -ex run
...
[1]  + 13146 suspended (tty output)  gdb -q -nx t -ex "catch exec" -ex "set follow-exec-mode new" -ex run
$

Here's what happens: when the inferior execs with "follow-exec-mode
new", we first "mourn" it before creating the new one.  This ends up
calling inflow_inferior_exit, which sets the per-inferior terminal state
to "is_ours":

  inf->terminal_state = target_terminal_state::is_ours;

At this point, the inferior's terminal_state is is_ours, while the
"reality", tracked by gdb_tty_state, is is_inferior (GDB doesn't own the
terminal).

Later, we continue processing the exec inferior event and decide we want
to stop (because of the "catch exec") and call target_terminal::ours to
make sure we own the terminal.  However, we don't actually go to the
target backend to change the settings, because the core thinks that no
inferior owns the terminal (inf->terminal_state is
target_terminal_state::is_ours, as checked in
target_terminal_is_ours_kind, for both inferiors).  When something in
readline tries to mess with the terminal settings, it generates a
SIGTTOU.

This patch fixes this by tranferring the state of the terminal from the
old inferior to the new inferior.

gdb/ChangeLog:

	PR gdb/23368
	* infrun.c (follow_exec): In the follow_exec_mode_new case,
	transfer terminal state from old new new inferior.
	* terminal.h (swap_terminal_info): New function.
	* inflow.c (swap_terminal_info): New function.
2018-10-23 17:00:41 -04:00
Tom Tromey 79b8d3b090 Fix use-after-free in record_btrace_start_replaying
-fsanitize=address showed a use-after-free in
record_btrace_start_replaying.  The bug occurred because
get_thread_current_frame returned a frame_info, but this object was
then invalidated before the return by ~scoped_restore_current_thread.

This patch fixes the problem by renaming get_thread_current_frame and
having it return a frame id.

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

	* record-btrace.c (get_thread_current_frame_id): Rename from
	get_thread_current_frame.  Return a frame_id.
	(record_btrace_start_replaying): Update.
2018-10-23 13:45:33 -06:00
John Darrington 51d21d60b3 GDB: New target s12z
gdb/
    * configure.tgt: Add configuration for s12z.
    * s12z-tdep.c:  New file.
    * NEWS: Mention new target.
2018-10-23 16:09:35 +02:00
John Darrington 88f5cc8cf8 GDB: Remote target can now accept the form unix::/path/to/socket.
Allow target remote to use the unix::/path/to/socket syntax as well as just
plain /path/to/socket

gdb/

  * ser-uds.c (uds_open): Use parse_connection_spec to deal with the
    comm form unix::/path/to/socket.

  * serial.c (serial_open): Consider the "unix:" prefix when deciding which
    interface to use.
2018-10-23 16:09:34 +02:00
John Darrington 0a163825df GDB: Fix documentation for invoking GDBSERVER
The documentation did not mention the possibility of invoking gdbserver
with the new connection forms such as tcp6:host:port.  This change fixes
that.

gdb/doc/

  * gdb.texinfo (Server): Tabulate the various permitted forms of the @var{comm}
   metasyntactical variable.  Include the unix:@var{host}:@var{socket} form as
   one of them.
2018-10-23 16:09:33 +02:00
John Darrington 6d0f8100c1 GDB: Document the unix::/path/to/socket of remote connection.
gdb/doc:
* gdb.texinfo (Connecting)[Remote Connection Commands]:  Provide alternative
  unix::/tmp/xxx example.  Include @code{unix::@var{local-socket}} in
  the list of remote and extended-remote syntaxes.
2018-10-23 16:09:32 +02:00
John Darrington f19c7ff839 GDBSERVER: Listen on a unix domain (instead of TCP) socket if requested.
When invoking gdbserver, if the COMM parameter takes the form "unix::/path/name"
then a local (unix) domain socket will be created with that name and gdbserver
will listen for connections on that.

    gdb/
    * NEWS: Mention new feature.

    gdb/gdbserver/
    * configure.ac (AC_CHECK_HEADERS): Add sys/un.h.
    * configure: Regenerate.
    * remote-utils.c (remote_prepare): Create a local socket if requested.
     (remote_open):  Don't attempt to open a file if it's a socket.
     (handle_accept_event): Display the name of the socket on connection.

   gdb/common/
   * netstuff.c (parse_connection_spec)[prefixes]: New member for local domain sockets.
2018-10-23 16:09:31 +02:00
Andrew Burgess 420ecd9ce8 gdb/riscv: Give user-friendly names for CSRs
The recent commit:

    commit 0dbfcfffe9
    Date:   Tue Oct 16 22:40:09 2018 +0100

        gdb/riscv: Fix register access for register aliases

broke the CSR names for RISC-V, now all of the CSRs have names like,
csr0, csr1, csr2, etc.  This commit restores the previous
user-friendly names.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_register_name): Use the user-friendly names
	for CSRs.
2018-10-23 13:27:56 +01:00
Joel Brobecker 5a77b1b49f gdb/riscv: expect h/w watchpoints to trigger before the memory is written
When using QEMU as a RISCV simulator, hardware watchpoint events are
reported to GDB before the target memory gets written. GDB currently
expects the event to be reported after it is written. As a result of
this mismatch, upon receiving the event, GDB sees that the target
memory region has not changed, and therefore decides to ignore the
event. It therefore resumes the program's execution with a continue,
which is the start of an infinite loop between QEMU repeatedly
reporting the same watchpoint event over and over, and GDB repeatedly
ignoring it.

This patch fixes the issue by telling GDB to expect the watchpoint
event to be reported ahead of the memory region being modified.
Upon receiving the event, GDB then single-steps the program before
checking the watched memory value.

gdb/ChangeLog:

        * riscv-tdep.c (riscv_gdbarch_init): Set the gdbarch's
        have_nonsteppable_watchpoint attribute to 1.
2018-10-23 11:31:27 +01:00
Andrew Burgess 0dbfcfffe9 gdb/riscv: Fix register access for register aliases
Some confusion over how the register names and aliases are setup in
riscv means that we currently can't access registers through their
architectural name.

This commit fixes this issue, and moves some of the csr register
handling out of the alias handling code and deals with it separately.
This has the benefit that we can now directly access some arrays
rather than having to iterate over them.

A new test is added to ensure that register aliases now work
correctly.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_gdb_reg_names): Update comment, and all
	register names.
	(struct register_alias): Rename to...
	(struct riscv_register_alias): ...this, and update comment.
	(riscv_register_aliases): Update type, and alias names.  Remove
	CSR names from this list.
	(riscv_register_name): Use riscv_gdb_reg_names for int and float
	register names.  Add an extra assertion.
	(riscv_is_regnum_a_named_csr): New function.
	(riscv_register_reggroup_p): Use riscv_is_regnum_a_named_csr.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-reg-aliases.c: New file.
	* gdb.arch/riscv-reg-aliases.exp: New file.
2018-10-23 10:32:34 +01:00
Jim Wilson 3399f1b303 RISC-V: NaN-box FP values smaller than an FP register.
The hardware requires that values in FP registers be NaN-boxed, so we must
extend them with 1's instead of 0's as we do for integer values.

	gdb/
	* riscv-tdep.c (riscv_push_dummy_call) <in_reg>: Check for value in
	FP reg smaller than FP reg size, and fill with -1 instead of 0.
2018-10-22 14:11:55 -07:00
Jim Wilson 270b9329b7 RISC-V: Print FP regs as union of float types.
A 64-bit FP register can hold either a single or double float value, so
print it as both types by using a union type for FP registers.  Likewise
for 128-bit regs which can also hold long double.

	gdb/
	* riscv-tdep.c (riscv_fpreg_d_type, riscv_fpreg_q_type): New.
	(riscv_register_type): Use them.
	(riscv_print_one_register_info): Handle union of floats same as float.
	* riscv-tdep.h (struct gdbarch_tdep): Add riscv_fpreg_d_type and
	riscv_fpreg_q_type fields.
2018-10-22 14:10:13 -07:00
Simon Marchi f6efe3f842 Introduce gdbarch_num_cooked_regs
The expression

  gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch)

is used quite often to find the number of cooked registers (raw + pseudo
registers).  This patch introduces gdbarch_num_cooked_regs, which does
the equivalent.  It substantially reduces required wrapping in some
places, so should improve readability.

There is a for loop in m68hc11_frame_unwind_cache that had iterated
until (the equivalent of) gdbarch_num_cooked_regs (gdbarch) - 1.  During
review, we concluded that this is most likely an off-by-one mistake, so
I replaced it with gdbarch_num_cooked_regs (gdbarch).

gdb/ChangeLog:

	* gdbarch.sh (gdbarch_num_cooked_regs): New.
	* gdbarch.h: Re-generate.
	* ax-gdb.c (gen_expr): Use gdbarch_num_cooked_regs.
	* dwarf2-frame.c (dwarf2_frame_cache): Likewise.
	* eval.c (evaluate_subexp_standard): Likewise.
	* findvar.c (value_of_register): Likewise.
	(value_of_register_lazy): Likewise.
	(address_from_register): Likewise.
	* frame.c (get_frame_register_bytes): Likewise.
	* gdbarch-selftests.c (register_to_value_test): Likewise.
	* h8300-tdep.c (h8300_register_type): Likewise.
	* i386-tdep.c (i386_dbx_reg_to_regnum): Likewise.
	(i386_svr4_reg_to_regnum): Likewise.
	* infcmd.c (default_print_registers_info): Likewise.
	(registers_info): Likewise.
	(print_vector_info): Likewise.
	(default_print_float_info): Likewise.
	* m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise.
	* mdebugread.c (mdebug_reg_to_regnum): Likewise.
	* mi/mi-main.c (mi_cmd_data_list_register_names): Likewise.
	(mi_cmd_data_list_changed_registers): Likewise.
	(mi_cmd_data_list_register_values): Likewise.
	(mi_cmd_data_write_register_values): Likewise.
	(mi_cmd_trace_frame_collected): Likewise.
	* mips-tdep.c (print_gp_register_row): Likewise.
	(mips_print_registers_info): Likewise.
	* nds32-tdep.c (nds32_gdbarch_init): Likewise.
	* regcache.c (init_regcache_descr): Likewise.
	(register_size): Likewise.
	(register_dump::dump): Likewise.
	(cooked_read_test): Likewise.
	(cooked_write_test): Likewise.
	* rs6000-tdep.c (rs6000_register_sim_regno): Likewise.
	(rs6000_gdbarch_init): Likewise.
	* stabsread.c (stab_reg_to_regnum): Likewise.
	* stack.c (info_frame_command): Likewise.
	* target-descriptions.c (tdesc_register_name): Likewise.
	* trad-frame.c (trad_frame_alloc_saved_regs): Likewise.
	* tui/tui-regs.c (tui_show_register_group): Likewise.
	* user-regs.c (user_reg_map_name_to_regnum): Likewise.
	(user_reg_map_regnum_to_name): Likewise.
	(value_of_user_reg): Likewise.
	(maintenance_print_user_registers): Likewise.
	* xtensa-tdep.c (xtensa_find_register_by_name): Likewise.
	(xtensa_register_name): Likewise.
	(xtensa_register_type): Likewise.
	(xtensa_reg_to_regnum): Likewise.
	(xtensa_pseudo_register_read): Likewise.
	(xtensa_pseudo_register_write): Likewise.
2018-10-21 22:29:21 -04:00
Simon Marchi 925047fed0 Allocate buffer with proper size in amd64_pseudo_register_{read_value,write}
Running "maintenance selftest" on an amd64 build with AddressSanitizer
enabled, I get this:

==18126==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffdf72397c1 at pc 0x7fb5f437b011 bp 0x7ffdf7239740 sp 0x7ffdf7238ee8
WRITE of size 8 at 0x7ffdf72397c1 thread T0
    #0 0x7fb5f437b010 in __interceptor_memcpy /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:737
    #1 0x55a1f899c1b3 in readable_regcache::raw_read(int, unsigned char*) /home/simark/src/binutils-gdb/gdb/regcache.c:530
    #2 0x55a1f7db241b in amd64_pseudo_register_read_value /home/simark/src/binutils-gdb/gdb/amd64-tdep.c:384
    #3 0x55a1f8413a2e in gdbarch_pseudo_register_read_value(gdbarch*, readable_regcache*, int) /home/simark/src/binutils-gdb/gdb/gdbarch.c:1992
    #4 0x55a1f899c9d1 in readable_regcache::cooked_read(int, unsigned char*) /home/simark/src/binutils-gdb/gdb/regcache.c:636
    #5 0x55a1f89a2251 in cooked_read_test /home/simark/src/binutils-gdb/gdb/regcache.c:1649

In amd64_pseudo_register_read_value, when we try to read the al
register, for example, we need to read rax and extract al from it.  We
allocate a buffer of the size of al (1 byte):

  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));

but read in it the whole rax value (8 bytes):

  status = regcache->raw_read (gpnum, raw_buf);

Fix it by allocating a buffer correctly sized for the full register from
which the smaller register is extracted.  The
amd64_pseudo_register_write function had the same problem.

gdb/ChangeLog:

	* amd64-tdep.c (amd64_pseudo_register_read_value): Use
	correctly-sized buffer with raw_read.
	(amd64_pseudo_register_write): Use correctly-sized buffer for
	raw_read/raw_write.
2018-10-21 22:10:02 -04:00
Philippe Waroquiers 4051d2d65a [PUSHED/OBVIOUS] ensure help set print type gives the correct help.
Without this patch:
  (gdb) help set print type
  Generic command for setting how types print.

  List of show print type subcommands:

  show print type methods -- Set printing of methods defined in classes
  ...

With this patch:
  (gdb) h set print type
  Generic command for setting how types print.

  List of set print type subcommands:

  set print type methods -- Set printing of methods defined in classes
  ...
2018-10-20 23:00:52 +02:00
Tom Tromey d6677607c2 Fix "make info" in gdb
"make info" in gdb was broken by my last patch.  This fixes it.
Tested by rebuilding; committing as obvious.

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

	* gdb.texinfo (TUI Commands): Add @end table.
	(TUI Configuration): Remove stray @end table.
2018-10-20 12:18:20 -06:00
John Darrington 1a088a2e26 GDB: Documentation: Remove greengrocer's apostrophe.
gdb/doc/gdb.texinfo (gdbserver man): "it's symbol" --> its symbol.
2018-10-20 12:24:20 +02:00
Tom Tromey 7806cea723 Deprecate and replace the "tabset" command
The "tabset" command sets the tab width as used by the TUI for source
and disassembly display.

This command has long seemed to be misnamed to me.  It is more in
keeping with gdb design to call it "set tui tab-width".  Also, making
this change allows for the corresponding "show" command to work.

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

	PR tui/18388:
	* NEWS: Mention tabset deprecation.
	* tui/tui-win.c (tui_tab_width, internal_tab_width): New globals.
	(update_tab_width): New function.
	(tui_set_tab_width, tui_show_tab_width): New functions.
	(tui_set_tab_width_command): Use update_tab_width.
	(_initialize_tui_win): Move to end of file.  Deprecate "tabset".
	Add new "set tui tab-width" command.
	* tui/tui-source.c (tui_set_source_content): Update.
	* tui/tui-disasm.c (tui_set_disassem_content): Update.
	* tui/tui-data.h (tui_default_tab_len, tui_set_default_tab_len):
	Don't declare.
	(tui_tab_width): Declare.
	* tui/tui-data.c (default_tab_len, tui_default_tab_len)
	(tui_set_default_tab_len): Remove.

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

	PR tui/18388:
	* gdb.texinfo (TUI Commands): Remove tabset documentation.
	(TUI Configuration): Document "set tui tab-width".
2018-10-19 17:22:27 -06:00
Tom Tromey 84371624ad Minor cleanups in tui-io.c
I noticed that a couple of functions in tui-io.c could be static, and
that a couple more were unused and could be removed.

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

	* tui/tui-io.h (key_is_start_sequence, key_is_end_sequence)
	(key_is_backspace, tui_getc): Don't declare.
	* tui/tui-io.c (key_is_start_sequence): Now static.
	(key_is_end_sequence, key_is_backspace): Remove.
	(tui_getc): Now static.
2018-10-19 17:22:27 -06:00
Tom Tromey 22ad8107d3 Clear static_links in reread_symbols
-fsanitize=address pointed out a use-after free in
objfile_register_static_link.  The bug turned out to be that
reread_symbols does not clear the static_links field; this leaves a
hash table that is filled with freed pointers.

Jan's (now quite old) idea of replacing reread_symbols with a simple
delete/new still seems good to me, and it's worth noting that it would
have avoided this bug.

Tested by the buildbot and by observing the change with
-fsanitize=address.

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

	* symfile.c (reread_symbols): Clear "static_links".
2018-10-19 10:28:33 -06:00
Alan Hayward 74b3c71318 Aarch64: Better termination checks for sigcontext reading
When reading the reserved section in the sigcontext ensure the
address is updated on an unknown section. Also add additional
checks to prevent reading past the end of the array.

Fixes gdb.base/savedregs.exp

	* aarch64-linux-tdep.c (AARCH64_SIGCONTEXT_RESERVED_SIZE): New
	define.
	(aarch64_linux_sigframe_init): Extra boundary checks.
2018-10-19 13:51:00 +01:00
Andreas Arnez 0667c50682 S390: Fix crash when remote tdesc doesn't define vec128
I've encountered a GDB crash when trying to read registers from a remote
stub that provided a target.xml with vector registers, but without the
'vec128' data type.  The crash is caused by NULL register type entries for
the "concatenated" pseudo-registers v0-v15.  These NULL entries are
introduced by the logic in s390_pseudo_register_type(), where the tdesc
type 'vec128' is returned unconditionally -- even if it doesn't exist (is
NULL).

The fixed logic for determining a "concatenated" vector register's type
now returns the type of the raw register v16 instead.  This also makes
sure that all vector register have the same type.

gdb/ChangeLog:

	* s390-tdep.c (s390_pseudo_register_type): For v0-v15 don't yield
	the possibly non-existent tdesc type 'vec128', but the type of raw
	register v16 instead.
2018-10-19 14:05:08 +02:00
Gary Benson ba543ca5af Fix cli_interp::cli_uiout resource leak found by Coverity
This commit fixes a resource leak found by Coverity, where cli_interp's
constructor creates a new cli_ui_out, but there was no corresponding
destructor to free it.

gdb/ChangeLog:

	* cli/cli-interp.c (cli_interp::~cli_interp): New function.
2018-10-19 11:52:33 +01:00
Alan Hayward b04480b119 Testsuite: Fix racy conditions in py-cmd.exp
The test loop in test_python_inline_or_multiline was not checking for the
gdb prompt. readline_is_used then reads in the prompt causing it to fail
and the final chunk of tests to be skipped.

Spotted this error because sometimes the gdb prompt does get processed
correctly and the final tests are run, causing it to show up in the
racy tests script output.

Fix by ensuring the prompt is always checked for. To do this the list
style needs reformatting so that variables get expanded.

2018-10-19  Alan Hayward  <alan.hayward@arm.com>

	* gdb.python/py-cmd.exp: Check for gdb_prompt.
2018-10-19 11:29:42 +01:00
Alan Hayward 2c6ac8d7ce Testsuite: vla-optimized-out.exp is too pessimistic
On aarch64 (and possibly other ports), for O3 the sizeof "a" can still be shown.

2018-10-19  Alan Hayward  <alan.hayward@arm.com>

	* gdb.base/vla-optimized-out.exp: Allow either optimized out or 6.
2018-10-19 11:21:12 +01:00
Alan Hayward 2bc69f2588 testsuite: ovldbreak.exp: fix regexp
Fix the layout used in the regexp for breakpoints.

Gets rid of two FAILS.

2018-10-18  Alan Hayward  <alan.hayward@arm.com>

	* gdb.cp/ovldbreak.exp: Fix regexps.
2018-10-19 11:13:40 +01:00
Alan Hayward 1f1ae3a34f Testsuite: compile-cplus-print.exp: Start inferior before compiling
skip_compile_feature_tests is only valid if the inferior has already
been started (see proc comments). Move the runto_main earlier.

2018-10-18  Alan Hayward  <alan.hayward@arm.com>

	* gdb.compile/compile-cplus-print.exp: Start inferior earlier.
2018-10-19 11:03:38 +01:00
Sergio Durigan Junior 94c18618a8 Fix PR cli/23785: Check if file exists when invoking "restore FILE binary"
This simple patch fixes the segfault reported on PR cli/23785, which
happens when using the "restore FILE binary" command with a
non-existent file.  We just have to check if the file handler returned
by "gdb_fopen_cloexec" is not NULL, and error out if it is.

A test has also been added to gdb.base/restore.exp in order to
exercise this scenario.

No regressions introduced.

gdb/ChangeLog:
2018-10-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/23785
	* cli/cli-dump.c (restore_binary_file): Check if "file" is
	NULL.

gdb/testsuite/ChangeLog:
2018-10-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/23785
	* gdb.base/restore.exp: New test to check if "restore" with an
	invalid file doesn't segfault.
2018-10-18 17:39:09 -04:00
Tom de Vries 812cd6eb05 [gdb/testsuite] Fix capitalized test names
At https://sourceware.org/gdb/wiki/GDBTestcaseCookbook\
  #Follow_the_test_name_convention we find:
..
Test names should start with a lower case and don't need to end with a period
(they are not sentences).
...

Fix some capitalized test names.

Tested on x86_64-linux.

2018-10-18  Tom de Vries  <tdevries@suse.de>

	* gdb.ada/bp_inlined_func.exp: Fix capitalized test name.
	* gdb.ada/excep_handle.exp: Same.
	* gdb.ada/mi_string_access.exp: Same.
	* gdb.ada/mi_var_union.exp: Same.
	* gdb.arch/arc-analyze-prologue.exp: Same.
	* gdb.arch/arc-decode-insn.exp: Same.
	* gdb.base/readnever.exp: Same.
	* gdb.fortran/printing-types.exp: Same.
	* gdb.guile/scm-lazy-string.exp: Same.
2018-10-18 15:06:38 +02:00
Paul Koning 89eb3c5470 gdb/ChangeLog:
* charset.c (convert_between_encodings): Fix unsigned overflow.

    gdb/charset.c (convert_between_encodings): Fix unsigned overflow.
2018-10-17 19:26:55 -04:00
John Baldwin 6f3b1098e8 Share the code to format "info proc mappings" entries for FreeBSD.
gdb/ChangeLog:

	* fbsd-nat.c (fbsd_nat_target::info_proc) Use
	fbsd_info_proc_mappings_header and fbsd_info_proc_mappings_entry.
	* fbsd-tdep.c (fbsd_vm_map_entry_flags): Mark static.
	(fbsd_info_proc_mappings_header, fbsd_info_proc_mappings_entry):
	New functions.
	(fbsd_core_info_proc_mappings): Use fbsd_info_proc_mappings_header
	and fbsd_info_proc_mappings_header.
	* fbsd-tdep.h (fbsd_vm_map_entry_flags): Remove.
	(fbsd_info_proc_mappings_header, fbsd_info_proc_mappings_entry):
	New.
2018-10-17 11:42:00 -07:00
Joel Brobecker d500b4f23f gdb/MAINTAINERS: Add Rainer Orth as Solaris maintainer for GDB
gdb/ChangeLog:

	* MAINTAINERS (Responsible Maintainers): Add Rainer Orth as
	Solaris Maintainer.
2018-10-17 11:04:14 -07:00
Tom de Vries c4b9078851 [gdb/testsuite] Rewrite catch-follow-exec.exp
There are two problems with the current catch-follow-exec.exp:
- INTERNAL_GDBFLAGS (containing the datadir setting) is not used
- remote host testing doesn't work

Fix the former by using gdb_spawn_with_cmdline_opts.  Fix the latter by
requiring gdb-native.

Build on x86_64-linux with and without ubsan, and tested.

2018-10-16  Tom de Vries  <tdevries@suse.de>

	PR gdb/23730
	* gdb.base/catch-follow-exec.c: Add copyright notice.
	* gdb.base/catch-follow-exec.exp: Rewrite to use
	gdb_spawn_with_cmdline_opts.  Require gdb-native.
2018-10-16 22:40:41 +02:00
Tom Tromey 63a33118e0 Remove unnecessary casts from TUI
This removes a number of unnecessary casts from the TUI.  Some were
found with -Wuseless-cast (which, I think, can't easily be enabled for
gdb); and some were found by inspection.

Tested by rebuilding on x86-64 Fedora 28.
I'm checking this in.

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

	* tui/tui.c (strcat_to_buf): Remove casts.
	* tui/tui-winsource.c (tui_show_source_line)
	(tui_set_is_exec_point_at, tui_line_is_displayed): Remove casts.
	* tui/tui-wingeneral.c (tui_refresh_win, box_win): Remove casts.
	* tui/tui-windata.c (tui_first_data_item_displayed)
	(tui_delete_data_content_windows, tui_erase_data_content)
	(tui_display_all_data, tui_display_data_from)
	(tui_refresh_data_win, tui_vertical_data_scroll): Remove casts.
	* tui/tui-win.c (tui_set_win_height)
	(make_invisible_and_set_new_height, parse_scrolling_args): Remove
	casts.
	* tui/tui-win.c (tui_resize_all): Remove casts.
	(tui_scroll_backward_command, tui_set_focus)
	(tui_set_tab_width_command): Likewise.
	* tui/tui-source.c (tui_vertical_source_scroll): Remove cast.
	* tui/tui-regs.c (tui_show_register_group): Remove cast.
	* tui/tui-layout.c (tui_set_layout_by_name): Remove cast.
	* tui/tui-disasm.c (tui_vertical_disassem_scroll): Remove cast.
	* tui/tui-data.c (tui_partial_win_by_name, tui_free_win_content):
	Remove casts.
2018-10-15 23:01:32 -06:00
Simon Marchi 933e62b1c1 Add Alan Hayward as AArch64/ARM GDB maintainer
gdb/ChangeLog:

	* MAINTAINERS (Responsible Maintainers): Add Alan Hayward as
	AArch64/ARM maintainer.
2018-10-15 15:52:03 -04:00
Sandra Loosemore 8bca297856 Clean up gdb.trace test results on targets not supporting this feature.
2018-10-12  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.trace/actions-changed.exp: Check for arch support.
	* gdb.trace/actions.exp: Likewise.
	* gdb.trace/ax.exp: Likewise.
	* gdb.trace/backtrace.exp: Likewise.
	* gdb.trace/change-loc.exp: Likewise.
	* gdb.trace/deltrace.exp: Likewise.
	* gdb.trace/ftrace-lock.exp: Check for shlib and arch support.
	* gdb.trace/ftrace.exp: Likewise.
	* gdb.trace/infotrace.exp: Check for arch support.
	* gdb.trace/mi-trace-frame-collected.exp: Likewise.
	* gdb.trace/mi-tracepoint-changed.exp: Likewise.
	* gdb.trace/mi-tsv-changed.exp: Likewise.
	* gdb.trace/packetlen.exp: Likewise.
	* gdb.trace/passc-dyn.exp: Likewise.
	* gdb.trace/passcount.exp: Likewise.
	* gdb.trace/pending.exp: Likewise.
	* gdb.trace/range-stepping.exp: Check for shlib support.
	* gdb.trace/report.exp: Check for arch support.
	* gdb.trace/save-trace.exp: Likewise.
	* gdb.trace/signal.exp: Check for signal support.
	* gdb.trace/tfind.exp: Check for arch support.
	* gdb.trace/trace-break.exp: Check for arch and shlib support.
	* gdb.trace/trace-common.h: Add comment.
	* gdb.trace/trace-condition.exp: Check for shlib and arch support.
	* gdb.trace/trace-enable-disable.exp: Likewise.
	* gdb.trace/trace-mt.exp: Likewise.  Remove redundant untested call.
	* gdb.trace/tracecmd.exp: Check for arch support.
	* gdb.trace/tspeed.exp: Check for shlib and target support.
	* gdb.trace/tstatus.exp: Check for arch support.
	* gdb.trace/tsv.exp: Likewise.
	* gdb.trace/while-dyn.exp: Likewise.
	* gdb.trace/while-stepping.exp: Likewise.
	* lib/trace-support.exp (gdb_trace_common_supports_arch): New.
2018-10-12 17:56:13 -07:00
Simon Marchi f9c49bffe6 Fix buglets in gdb.trace/tspeed.{exp,c}
When trying to run gdb.trace/tspeed.exp, I get:

ERROR: can't read "ipalib": no such variable
    while executing
"gdb_load_shlib $ipalib"
    (procedure "prepare_for_trace_test" line 5)

This problem seems to come from commit

    c708f4d256 ("gdb: Don't call gdb_load_shlib unless GDB is running")

which moved the gdb_load_shlib call in prepare_for_trace_test.  In order
to access the ipalib variable, we need to declare "global ipalib" first.

Then, this test uses nowarnings, for no good reason I could find.  We
can remove that and fix the two trivial warnings that appear:

/home/emaisin/src/binutils-gdb/gdb/testsuite/gdb.trace/tspeed.c: In function 'main':
/home/emaisin/src/binutils-gdb/gdb/testsuite/gdb.trace/tspeed.c:87:16: warning: too many arguments for format [-Wformat-extra-args]
        printf ("Negative times, giving up\n", max_iters);
                ^
/home/emaisin/src/binutils-gdb/gdb/testsuite/gdb.trace/tspeed.c:99:7: warning: implicit declaration of function 'sleep' [-Wimplicit-function-declaration]
       sleep (1);  /* set post-run breakpoint here */
       ^

gdb/testsuite/ChangeLog:

	* gdb.trace/tspeed.exp: Remove nowarnings.
	(prepare_for_trace_test): Declare "global ipalib".
	* gdb.trace/tspeed.c: Include unistd.h.
	(main): Remove superfluous printf argument.
2018-10-12 16:27:29 -04:00
Sandra Loosemore d4330bde68 Fix pathname regexp in gdb.base/solib-vanish.exp.
2018-10-11  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.base/solib-vanish.exp: Fix regexp not to require a POSIX
	directory prefix on the filename.
2018-10-11 16:51:26 -07:00
Gary Benson fbe61a3661 Fix interp::m_name resource leak found by Coverity
This commit fixes a resource leak found by Coverity, where interp's
constructor allocated memory for m_name that interp's destructor did
not free.

gdb/ChangeLog:

	* interps.h (interp::m_name): Make private and mutable.
	* interps.c (interp::~interp): Free m_name.
2018-10-11 10:19:26 +01:00
Sergio Durigan Junior 8ecfd7bd4a Add parameter to allow enabling/disabling selftests via configure
This is a follow-up of:

  https://sourceware.org/ml/gdb-patches/2018-08/msg00347.html

Instead of going throttle and always enabling our selftests (even in
non-development builds), this patch is a bit more conservative and
introduces a configure option ("--enable-unit-tests") that allows the
user to choose whether she wants unit tests in the build or not.  Note
that the current behaviour is retained: if no option is provided, GDB
will have selftests included in a development build, and will *not*
have selftests included in a non-development build.

The rationale for having this option is still the same: due to the
many racy testcases and random failures we see when running the GDB
testsuite, it is unfortunately not possible to perform a full test
when one is building a downstream package.  As the Fedora GDB
maintainer and one of the Debian GDB uploaders, I feel like this
situation could be improved by, at least, executing our selftests
after the package has been built.

This patch introduces no regressions to our build.

OK?

gdb/ChangeLog:
2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Simon Marchi <simark@simark.ca>

	* README (`configure' options): Add documentation for new
	"--enable-unit-tests" option.
	* acinclude.m4: Include "selftest.m4".
	* configure: Regenerate.
	* configure.ac: Use "GDB_AC_SELFTEST".
	* maint.c (maintenance_selftest): Update message informing
	that selftests have been disabled.
	(maintenance_info_selftests): Likewise.
	* selftest.m4: New file.

gdb/gdbserver/ChangeLog:
2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Simon Marchi <simark@simark.ca>

	* acinclude.m4: Include "../selftest.m4".
	* configure: Regenerate.
	* configure.ac: Use "GDB_AC_SELFTEST".
	* configure.srv: Use "$enable_unittests" instead of
	"$development" when checking whether unit tests have been
	enabled.
	* server.c (captured_main): Update message informing that
	selftests have been disabled.

gdb/testsuite/ChangeLog:
2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.gdb/unittest.exp: Update expected message informing that
	selftests have been disabled.
	* gdb.server/unittest.exp: Likewise.

squash! Add parameter to allow enabling/disabling selftests via configure
2018-10-10 16:23:56 -04:00
Gary Benson 33b031ce7a Add missing va_end found by Coverity
This commit adds a missing va_end found by Coverity.

gdb/ChangeLog:

	* remote.c (remote_target::remote_send_printf): Add
	missing va_end found by Coverity.
2018-10-10 15:01:50 +01:00
Markus Metzger 2cb2ba9a5b btrace: check for indirect jump return in _Unwind_RaiseException
Some versions of _Unwind_RaiseException, e.g. on Fedora 28, use an
indirect jump to return to the exception handler.

This messes up the output of "record function-call-history /c" since the
return is interpreted as cross-function goto.  It had been detected by
gdb.btrace/exception.exp.

Add a heuristic for "_Unwind_*" functions to interpret an indirect jump
that ends in one of our caller functions as return to the first instance
of that function in our call stack.

gdb/
	* btrace.c (ftrace_update_function): Add indirect jump heuristic.
2018-10-10 12:27:55 +02:00
Tom Tromey 163cffefaf Make @pxref for Inferior.architecture point to gdb.Frame documentation
This fixes he @pxref in Inferior.architecture to point to the "Frames
In Python" node, as originally intended; somewhat reverting an earlier
build fix.  The initial patch had typod the "In".

Tested by "make info".

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

	* python.texi (Inferiors In Python): Link to "Frames In Python",
	not "Unwinding Frames in Python".
2018-10-09 13:59:37 -06:00
Tom Tromey eff98030f9 Disable the undefined behavior sanitizer by default
There have been a few undefined behavior failures reported, and Pedro
suggested that the sanitizer be disabled by default.  This patch
implements this.

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

	* configure: Rebuild.
	* sanitize.m4 (AM_GDB_UBSAN): Default to no.
	* NEWS: Update --enable-ubsan documentation.

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

	* gdb.texinfo (Configure Options): Update --enable-ubsan
	documentation.
2018-10-09 11:51:33 -06:00
Tom de Vries 58bbcd02de [gdb/testsuite] Fix target_supports_scheduler_locking raciness
When calling gdb_start_cmd, it's the caller's responsibility to wait for gdb
to return to the prompt.  In target_supports_scheduler_locking, that's not the
case, and consequently, target_supports_scheduler_locking fails spuriously.

Fix by using runto_main instead.

Build and reg-tested on x86_64-linux.

2018-10-09  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (target_supports_scheduler_locking): Replace gdb_start_cmd
	with runto_main.
2018-10-09 15:33:00 +02:00
Gary Benson 04fd5eed91 Fix buffer overrun found by Coverity
This commit fixes a buffer overrun found by Coverity, where
36 bytes are written into a 24 byte buffer.

gdb/ChangeLog:

	* dwarf2read.c (create_dwp_hash_table): Fix buffer overrun
	found by Coverity.
2018-10-09 14:13:12 +01:00
Tom Tromey a0c3048e3f Remove unused variables from riscv-fbsd-tdep.c
This removes a couple of unused variables from riscv-fbsd-tdep.c.
This allows a --enable-targets=all build to complete on
x86-64 Fedora 28.

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

	* riscv-fbsd-tdep.c (riscv_fbsd_sigframe_init): Remove unused
	variable.
	(riscv_fbsd_init_abi): Likewise.
2018-10-08 16:39:29 -06:00
Weimin Pan a51bb70c8a Fix the [-Werror=shadow=local] warning
Rename local variable in value_struct_elt_for_reference()
to work around the shadowing a previous local warning.
2018-10-08 22:14:11 +00:00
John Baldwin 74792ff782 Add native target for FreeBSD/riscv.
gdb/ChangeLog:

	* Makefile.in (ALLDEPFILES): Add riscv-fbsd-nat.c.
	* NEWS: Mention new FreeBSD/riscv native configuration.
	* configure.host: Add riscv*-*-freebsd*.
	* configure.nat: Likewise.
	* riscv-fbsd-nat.c: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Contributors): Add SRI International and University
	of Cambridge for FreeBSD/riscv.
2018-10-08 14:47:34 -07:00
John Baldwin ed65e20bc7 Add FreeBSD/riscv architecture.
Support for collecting and supplying general purpose and floating
point register sets is provided along with signal frame unwinding.

FreeBSD only supports RV64 currently, so while some provision is made
for RV32 in the general-purpose register set, the changes have only
been tested on RV64.

gdb/ChangeLog:

	* Makefile.in (ALL_TARGET_OBS): Add riscv-fbsd-tdep.o.
	(HFILES_NO_SRCDIR): Add riscv-fbsd-tdep.h.
	(ALLDEPFILES): Add riscv-fbsd-tdep.c.
	* NEWS: Mention new FreeBSD/riscv target.
	* configure.tgt: Add riscv*-*-freebsd*.
	* riscv-fbsd-tdep.c: New file.
	* riscv-fbsd-tdep.h: New file.
2018-10-08 14:47:34 -07:00
John Baldwin 498f740792 Add a helper function to trad_frame to support register cache maps.
Currently, signal frame handlers require explicitly coded calls to
trad_frame_set_reg_addr() to describe the location of saved registers
within a signal frame.  This change permits the regcache_map_entry
arrays used with regcache::supply_regset and regcache::collect_regset
to be used to describe a block of saved registers given an initial
address for the register block.

Some systems use the same layout for registers in core dump notes,
native register sets with ptrace(), and the register contexts saved in
signal frames.  On these systems, a single register map can now be
used to describe the layout of registers in all three places.

If a register map entry's size does not match the native size of a
register, try to match the semantics used by
regcache::transfer_regset.  If a register slot is too large, assume
that the register's value is stored in the first N bytes and ignore
the remaning bytes.  If the register slot is smaller than the
register, assume the slot holds the low N bytes of the register's
value.  Read these low N bytes from the target and zero-extend them to
generate a register value.

While here, document the semantics for both regcache::transfer_regset
and trad_frame with respect to register slot's whose size does not
match the register's size.

gdb/ChangeLog:

	* regcache.h (struct regcache_map_entry): Note that this type can
	be used with traditional frame caches.
	* trad-frame.c (trad_frame_set_reg_regmap): New.
	* trad-frame.h (trad_frame_set_reg_regmap): New.
2018-10-08 14:47:33 -07:00
Weimin Pan 9f6b697b0e Finding data member in virtual base class
This patch fixes the original problem - printing member in a virtual base,
using various expressions, do not yield the same value. Simple test case
below demonstrates the problem:

% cat t.cc
struct base { int i; };
typedef base tbase;
struct derived: virtual tbase { void func() { } };
int main() { derived().func(); }
% g++ -g t.cc
% gdb a.out
(gdb) break derived::func
(gdb) run
(gdb) p i
$1 = 0
(gdb) p base::i
$3 = 0
(gdb) p derived::i
$4 = 4196392

To fix the problem, add function get_baseclass_offset() which searches
recursively for the base class along the class hierarchy. If the base
is virtual, it uses "vptr" in virtual class object, which indexes to
its derived class's vtable, to get and returns the baseclass offset.
If the base is non-virtual, it returns the accumulated offset of its
parent classes. The offset is then added to the address of the class
object to access its member in value_struct_elt_for_reference().
2018-10-08 21:23:50 +00:00
John Darrington c258c396fa GDB: Work around buggy dwarf line information produced by Codewarrior Version 5.0.40 (build 15175).
gdb/ChangeLog:
* dwarf2read.c (dwarf2_cu) <producer_is_codewarrior>: New field.
  (check_producer): Check if the producer is codewarrior.
  (producer_is_codewarrior): New function.
  (lnp_state_machine::record_line): Ignore is_stmt flag for records
   produced by codewarrior.
  (dwarf2_cu::dwarf2_cu): Initialize producer_is_codewarrior.
2018-10-08 10:59:59 +02:00
Andreas Krebbel 9e1698c618 Python doc build fixes
gdb/doc/ChangeLog:

2018-10-08  Andreas Krebbel  <krebbel@linux.ibm.com>

	* python.texi (Inferior.Architecture): Add "@end defun". Rename
	ref target to "Unwinding Frames in Python".
2018-10-08 09:49:48 +02:00