Commit Graph

37130 Commits

Author SHA1 Message Date
Markus Metzger 0ca912dfef btrace: resume all requested threads
The record targets are implicitly schedlocked.  They only step the current
thread and keep other threads where they are.

Change record btrace to step all requested threads in to_resume.

For maintenance and debugging, we keep the old behaviour when the target below
is not non-stop.  Enable with "maint set target-non-stop on".

gdb/
	* record-btrace.c (record_btrace_resume_thread): A move request
	overwrites a previous move request.
	(record_btrace_find_resume_thread): Removed.
	(record_btrace_resume): Resume all requested threads.
2015-09-18 14:24:25 +02:00
Markus Metzger e3cfc1c76d btrace: lock-step
Record btrace's to_wait method picks a single thread to step.  When passed
minus_one_ptid, it picks the current thread.  All other threads remain where
they are.

Change this to step all resumed threads together, one step at a time, until
the first thread reports an event.

We do delay reporting NO_HISTORY events until there are no other events to
report to prevent threads at the end of their execution history from starving
other threads.

We keep threads at the end of their execution history moving and replaying
until we announce their stop in to_wait.  This shouldn't really be user-visible
but its a detail worth mentioning.

Since record btrace's to_resume method also picks only a single thread to
resume, there shouldn't be a difference with the current all-stop.

With non-stop or all-stop on top of non-stop, we will see differences.  The
behaviour should be more natural as we're moving all threads.

gdb/
	* record-btrace.c: Include vec.h.
	(record_btrace_find_thread_to_move): Removed.
	(btrace_step_no_resumed, btrace_step_again)
	(record_btrace_stop_replaying_at_end): New.
	(record_btrace_cancel_resume): Call record_btrace_stop_replaying_at_end.
	(record_btrace_single_step_forward): Remove calls to
	record_btrace_stop_replaying.
	(record_btrace_step_thread): Do only one step for BTHR_CONT and
	BTHR_RCONT.  Keep threads at the end of their history moving.
	(record_btrace_wait): Call record_btrace_step_thread for all threads
	until one reports an event.  Call record_btrace_stop_replaying_at_end
	for the eventing thread.
2015-09-18 14:23:38 +02:00
Markus Metzger cf8f8f0c42 btrace: add missing NO_HISTORY
If a single-step ended right at the end of the execution history, we forgot
to announce that.  Fix it.

gdb/
	* record-btrace.c (record_btrace_single_step_forward): Return
	NO_HISTORY if a step brings us to the end of the execution history.
2015-09-18 14:22:54 +02:00
Markus Metzger 011c71b6cb btrace: move breakpoint checking into stepping functions
Breakpoints are only checked for BTHR_CONT and BTHR_RCONT stepping requests.
A BTHR_STEP and BTHR_RSTEP request will always report stopped without reason.
Since breakpoints are reported correctly, I assume infrun is handling this.

Move the breakpoint check into the btrace single stepping functions.  This
will cause us to report breakpoint hits now also for single-step requests.

One thing to notice is that

  - when executing forwards, the breakpoint is checked before 'executing'
    the instruction, i.e. before moving the PC to the next instruction.

  - when executing backwards,  the breakpoint is checked after 'executing'
    the instruction, i.e. after moving the PC to the preceding instruction
    in the recorded execution.

There is code in infrun (see, for example proceed and adjust_pc_after_break)
that handles this and also depends on this behaviour.

gdb/
	* record-btrace.c (record_btrace_step_thread): Move breakpoint check
	to ...
	(record_btrace_single_step_forward): ... here and
	(record_btrace_single_step_backward): ... here.
2015-09-18 14:22:09 +02:00
Markus Metzger d825d24810 btrace: split record_btrace_step_thread
The code for BTHR_STEP and BTHR_CONT is fairly similar.  Extract the common
parts into a new function record_btrace_single_step_forward.  The function
returns TARGET_WAITKIND_SPURIOUS to indicate that the single-step completed
without triggering a trap.

Same for BTHR_RSTEP and BTHR_RCONT.

gdb/
	* record-btrace.c (btrace_step_spurious)
	(record_btrace_single_step_forward)
	(record_btrace_single_step_backward): New.
	(record_btrace_step_thread): Call record_btrace_single_step_forward
	and record_btrace_single_step_backward.
2015-09-18 14:21:31 +02:00
Markus Metzger 3c615f99d3 btrace: extract the breakpoint check from record_btrace_step_thread
There are two places where record_btrace_step_thread checks for a breakpoint
at the current replay position.  Move this code into its own function.

gdb/
	* record-btrace.c (record_btrace_replay_at_breakpoint): New.
	(record_btrace_step_thread): Call record_btrace_replay_at_breakpoint.
2015-09-18 14:20:44 +02:00
Markus Metzger 987e68b1a3 btrace: improve stepping debugging
gdb/
	* record-btrace.c (btrace_thread_flag_to_str)
	(record_btrace_cancel_resume): New.
	(record_btrace_step_thread): Call btrace_thread_flag_to_str.
	(record_btrace_resume): Print execution direction.
	(record_btrace_resume_thread): Call btrace_thread_flag_to_str.
	(record_btrace_wait): Call record_btrace_cancel_resume.
2015-09-18 14:20:04 +02:00
Markus Metzger 6e4879f0eb btrace: support to_stop
Add support for the to_stop target method to the btrace record target.

gdb/
	* btrace.h (enum btrace_thread_flag) <BTHR_STOP>: New.
	* record-btrace (record_btrace_resume_thread): Clear BTHR_STOP.
	(record_btrace_find_thread_to_move): Also accept threads that have
	BTHR_STOP set.
	(btrace_step_stopped_on_request, record_btrace_stop): New.
	(record_btrace_step_thread): Support BTHR_STOP.
	(record_btrace_wait): Also clear BTHR_STOP when stopping other threads.
	(init_record_btrace_ops): Initialize to_stop.
2015-09-18 14:19:02 +02:00
Markus Metzger 5953356cc4 btrace: fix non-stop check in to_wait
The record btrace target stops other threads in non-stop mode after stepping
the to-be-resumed thread.

The check is done on the non_stop variable.  It should rather be done on
target_is_non_stop_p ().  With all-stop on top of non-stop, infrun will
take care of stopping other threads.

gdb/
	* record-btrace.c (record_btrace_wait): Replace non_stop check with
	target_is_non_stop_p ().
2015-09-18 14:17:41 +02:00
Pierre Langlois 43691ca179 Add test case for tracepoints with conditions
This patch adds a test case for tracepoints with a condition expression.
Each case will test a condition against the number of frames that should
have been traced.  Some of these tests fail on x86_64 and others on
i386, which have been marked as known failures for now, see PR/18955.

gdb/testsuite/ChangeLog:

2015-09-17  Pierre Langlois  <pierre.langlois@arm.com>
	    Yao Qi  <yao.qi@linaro.org>

	* gdb.trace/trace-condition.c: New file.
	* gdb.trace/trace-condition.exp: New file.
2015-09-17 11:39:10 +01:00
Wei-cheng Wang d78908cff5 Fix argument to compiled_cond, and add cases for compiled-condition.
This patch fixes the argument passed to compiled_cond.  It should be
regs buffer instead of tracepoint_hit_ctx.  Test case is added as
well for testing compiled-cond.

gdb/gdbserver/ChangeLog

2015-09-16  Wei-cheng Wang  <cole945@gmail.com>

	* tracepoint.c (eval_result_type): Change prototype.
	(condition_true_at_tracepoint): Fix argument to compiled_cond.

gdb/testsuite/ChangeLog

2015-09-16  Wei-cheng Wang  <cole945@gmail.com>

	* gdb.trace/ftrace.exp: (test_ftrace_condition) New function
	for testing bytecode compilation.
2015-09-16 17:17:50 +01:00
Pedro Alves 1ed415e2b9 non-stop-fair-events.exp slower on software single-step && !displ-step targets
On software single-step targets that don't support displaced stepping,
threads keep hitting each other's single-step breakpoints, and then
GDB needs to pause all threads to step past those.  The end result is
that progress in the main thread will be slower and it may take a bit
longer for the signal to be queued.  This patch bumps the timeout on
such targets.

gdb/testsuite/ChangeLog:
2015-09-16  Pedro Alves  <palves@redhat.com>
	    Sandra Loosemore <sandra@codesourcery.com>

	* gdb.threads/non-stop-fair-events.c (timeout): New global.
	(SECONDS): Redefine.
	(main): Call pthread_kill and alarm early.
	* gdb.threads/non-stop-fair-events.exp: Probe displaced stepping
	support.
	(test): If the target can't hardware step and doesn't support
	displaced stepping, increase the timeout.
2015-09-16 15:51:36 +01:00
Pedro Alves d136eff549 Make it easier to debug non-stop-fair-events.exp
If we enable infrun debug running this test, it quickly fails with a
full expect buffer.  That can be simply handled with a couple
exp_continues.  As it's annoying to hack this every time we need to
debug the test, this patch adds bits to enable debugging support
easily, with a one-line change.

And then, if any iteration of the test fails, we end up with a long
cascade of time outs.  Just bail out when we see the first fail.

gdb/testsuite/
2015-09-16  Pedro Alves  <palves@redhat.com>

	* gdb.threads/non-stop-fair-events.exp (gdb_test_no_anchor)
	(enable_debug): New procedures.
	(test): Use them.  Bail out if waiting for threads fails.
	(top level): Bail out if a test fails.
2015-09-16 15:51:36 +01:00
Yao Qi 991f019c50 Don't skip gdb.asm/asm-source.exp on aarch64
This patch adds gdb.asm/aarch64.inc, so asm-source.exp isn't skipped
on aarch64 any more.

gdb/testsuite:

2015-09-16  Yao Qi  <yao.qi@linaro.org>

	* gdb.asm/asm-source.exp: Set asm-arch for
	aarch64*-*-* target.
	* gdb.asm/aarch64.inc: New file.
2015-09-16 15:13:29 +01:00
Pierre-Marie de Rodat bfca584fae [Ada] Enhance type printing for arrays with variable-sized elements
This change is relevant only for standard DWARF (as opposed to the GNAT
encodings extensions): at the time of writing it only makes a difference
with GCC patches that are to be integrated: see the patch series
submission at
<https://gcc.gnu.org/ml/gcc-patches/2015-07/msg01353.html>.

Given the following Ada declarations:

   subtype Small_Int is Natural range 0 .. 100;
   type R_Type (L : Small_Int := 0) is record
      S : String (1 .. L);
   end record;
   type A_Type is array (Natural range <>) of R_Type;

   A : A_Type := (1 => (L => 0, S => ""),
                  2 => (L => 2, S => "ab"));

Before this change, we would get the following GDB session:

    (gdb) ptype a
    type = array (1 .. 2) of foo.r_type <packed: 838-bit elements>

This is wrong: "a" is not a packed array.  This output comes from the
fact that, because R_Type has a dynamic size (with a maximum), the
compiler has to describe in the debugging information the size allocated
for each array element (i.e. the stride, in DWARF parlance: see
DW_AT_byte_stride).  Ada type printing currently assumes that arrays
with a stride are packed, hence the above output.

In practice, GNAT never performs bit-packing for arrays that contain
variable-sized elements.  Leveraging this fact, this patch enhances type
printing so that ptype does not pretend that arrays are packed when they
have a stride and they contain dynamic elements.  After this change, we
get the following expected output:

    (gdb) ptype a
    type = array (1 .. 2) of foo.r_type

gdb/ChangeLog:

	* ada-typeprint.c (print_array_type): Do not describe arrays as
	packed when they embed dynamic elements.

gdb/testsuite/ChangeLog:

	* gdb.ada/array_of_variable_length.exp: New testcase.
	* gdb.ada/array_of_variable_length/foo.adb: New file.
	* gdb.ada/array_of_variable_length/pck.adb: New file.
	* gdb.ada/array_of_variable_length/pck.ads: New file.

Tested on x86_64-linux, no regression.
2015-09-15 23:16:22 +02:00
Doug Evans b326e5870e Handle clang naming of function static local variable.
clang names the local variable t_structs_a.buf.

gdb/testsuite/ChangeLog:

	* gdb.base/callfuncs.exp (do_function_calls): Handle clang naming
	of function static local variable.
2015-09-15 13:21:28 -07:00
Philippe Waroquiers 5382cfab61 Fix PR/18564 - regression in showing __thread so extern variable
Ensure tls variable address is not relocated, as the msym addr
is an offset in the thread local storage of the shared library/object.
2015-09-15 21:12:39 +02:00
Pedro Alves e68fa6f076 gdb/doc: revert previous vforkdone change
The previous manual change was wrong.  The vfork parent thread ID
should be reported with the usual "thread" magic register:

   Sending packet: $vCont;c:p7260.7260#1e...Packet received: OK
 -   Notification received: Stop:T05vforkdone:;
 +   Notification received: Stop:T05vforkdone:;thread:p7260.7260
                                               ^^^^^^^^^^^^^^^^^

This is already how the parent is reported in the vfork/fork events,
and is actually what the fix made gdbserver do.  Following the
documentation change, the event would have been reported like this
instead:

    Notification received: Stop:T05vforkdone:p7260.7260

gdb/doc/ChangeLog:
2015-09-15  Pedro Alves  <palves@redhat.com>

	PR remote/18965
	* gdb.texinfo (Stop Reply Packets): Revert previous change to
	the vforkdone description.
2015-09-15 19:29:37 +01:00
Pierre Langlois b277c936e0 [AArch64] Use debug_printf instead of fprintf_unfiltered
GDBserver uses debug_printf to print debugging output.  This patch makes
GDB use this too so we can share some of this code with GDBserver later.

gdb/ChangeLog:

	* aarch64-tdep.c (decode_add_sub_imm): Use debug_printf.
	(decode_adrp): Likewise.
	(decode_b): Likewise.
	(decode_bcond): Likewise.
	(decode_br): Likewise.
	(decode_cb): Likewise.
	(decode_eret): Likewise.
	(decode_movz): Likewise.
	(decode_orr_shifted_register_x): Likewise.
	(decode_ret): Likewise.
	(decode_stp_offset): Likewise.
	(decode_stp_offset_wb): Likewise.
	(decode_stur): Likewise.
	(decode_tb): Likewise.
	(aarch64_analyze_prologue): Likewise.
	(pass_in_x): Likewise.
	(pass_in_v): Likewise.
	(pass_on_stack): Likewise.
	(aarch64_push_dummy_call): Likewise.
	(aarch64_extract_return_value): Likewise.
	(aarch64_store_return_value): Likewise.
	(aarch64_return_value): Likewise.
	(aarch64_record_asimd_load_store): Likewise.
	(aarch64_record_load_store): Likewise.
	(aarch64_record_data_proc_simd_fp): Likewise.
2015-09-15 18:38:57 +01:00
Jan Kratochvil 141c5cc4c4 [ppc64le] Use skip_entrypoint for skip_trampoline_code
ppc64le loses control when stepping between two PLT-called functions inside
a shared library:

29        shlib_second (); /* first-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: first-hit
step^M
^M
Program received signal SIGABRT, Aborted.^M
0x00003fffb7cbe578 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56^M
56        return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);^M
(gdb) FAIL: gdb.base/solib-intra-step.exp: second-hit
->
29        shlib_second (); /* first-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: first-hit
step^M
shlib_second () at ./gdb.base/solib-intra-step-lib.c:23^M
23        abort (); /* second-hit */^M
(gdb) PASS: gdb.base/solib-intra-step.exp: second-hit

This is because gdbarch_skip_trampoline_code() will resolve the final function
as shlib_second+0 and place there the breakpoint, but ld.so will jump after
the breakpoint - at shlib_second+8 - as it is ELFv2 local symbol optimization:

Dump of assembler code for function shlib_second:
   0x0000000000000804 <+0>:     addis   r2,r12,2
   0x0000000000000808 <+4>:     addi    r2,r2,30668
   0x000000000000080c <+8>:     mflr    r0

Currently gdbarch_skip_entrypoint() has been called in skip_prologue_sal() and
fill_in_stop_func() but that is not enough.  I believe
gdbarch_skip_entrypoint() should be called after every
gdbarch_skip_trampoline_code().

gdb/ChangeLog
2015-09-15  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linespec.c (minsym_found): Call gdbarch_skip_entrypoint.
	* ppc64-tdep.c (ppc64_skip_trampoline_code): Rename to ...
	(ppc64_skip_trampoline_code_1): ... here.
	(ppc64_skip_trampoline_code): New wrapper function.
	* symtab.c (find_function_start_sal): Call gdbarch_skip_entrypoint.

gdb/testsuite/ChangeLog
2015-09-15  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.opt/solib-intra-step-lib.c: New file.
	* gdb.opt/solib-intra-step-main.c: New file.
	* gdb.opt/solib-intra-step.exp: New file.
2015-09-15 19:08:04 +02:00
Pedro Alves d57e0d5022 gdbserver: Fix exec stop reply reporting conditions
gdb/gdbserver/ChangeLog:
2015-09-15  Pedro Alves  <palves@redhat.com>

	* remote-utils.c (prepare_resume_reply) <TARGET_WAITKIND_EXECD>:
	Check whether to report exec events instead of checking whether
	multiprocess is enabled.
2015-09-15 17:38:07 +01:00
Pedro Alves 5a676acc4b Move ChangeLog entry to proper place
gdb/ChangeLog -> gdb/gdbserver/ChangeLog

2015-09-15  Pedro Alves  <palves@redhat.com>

	PR remote/18965
	* remote-utils.c (prepare_resume_reply): Merge
	TARGET_WAITKIND_VFORK_DONE switch case with the
	TARGET_WAITKIND_FORKED case.
2015-09-15 17:35:21 +01:00
Pedro Alves 8228463cbc PR remote/18965: vforkdone stop reply should indicate parent PID
The vforkdone stop reply misses indicating the thread ID of the vfork
parent which the event relates to:

 @cindex vfork events, remote reply
 @item vfork
 The packet indicates that @code{vfork} was called, and @var{r}
 is the thread ID of the new child process. Refer to
 @ref{thread-id syntax} for the format of the @var{thread-id}
 field.  This packet is only applicable to targets that support
 vfork events.

 @cindex vforkdone events, remote reply
 @item vforkdone
 The packet indicates that a child process created by a vfork
 has either called @code{exec} or terminated, so that the
 address spaces of the parent and child process are no longer
 shared. The @var{r} part is ignored.  This packet is only
 applicable to targets that support vforkdone events.

Unfortunately, this is not just a documentation issue.  GDBserver
is really not specifying the thread ID.  I noticed because
in non-stop mode, gdb complains:

 [Thread 6089.6089] #1 stopped.
 #0  0x0000003615a011f0 in ?? ()
 0x0000003615a011f0 in ?? ()
 (gdb) set debug remote 1
 (gdb) c
 Continuing.
 Sending packet: $QPassSignals:e;10;14;17;1a;1b;1c;21;24;25;2c;4c;#5f...Packet received: OK
 Sending packet: $vCont;c:p17c9.17c9#88...Packet received: OK
   Notification received: Stop:T05vfork:p17ce.17ce;06:40d7ffffff7f0000;07:30d7ffffff7f0000;10:e4c9eb1536000000;thread:p17c9.17c9;core:2;
 Sending packet: $vStopped#55...Packet received: OK
 Sending packet: $D;17ce#af...Packet received: OK
 Sending packet: $vCont;c:p17c9.17c9#88...Packet received: OK
   Notification received: Stop:T05vforkdone:;
 No process or thread specified in stop reply: T05vforkdone:;
 (gdb)

This is not non-stop-mode-specific, however.  Consider e.g., that in
all-stop, you may be debugging more than one process at the same time.
You continue, and both processes vfork.  So when you next get a
T05vforkdone, there's no way to tell which of the parent processes is
done with the vfork.

Tests will be added later.

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-09-15  Pedro Alves  <palves@redhat.com>

	PR remote/18965
	* remote-utils.c (prepare_resume_reply): Merge
	TARGET_WAITKIND_VFORK_DONE switch case with the
	TARGET_WAITKIND_FORKED case.

gdb/doc/ChangeLog:
2015-09-15  Pedro Alves  <palves@redhat.com>

	PR remote/18965
	* gdb.texinfo (Stop Reply Packets): Explain that vforkdone's 'r'
	part indicates the thread ID of the parent process.
2015-09-15 17:32:45 +01:00
Yao Qi 7c5d0fad2e Fix typo
gdb/gdbserver:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* server.c (handle_query): Check string comparison using
	"else if" instead of "if".
2015-09-15 17:29:22 +01:00
Pedro Alves d15dcecdee Fix gdb.threads/non-ldr-exc-3.exp race
gdb.threads/non-ldr-exc-3.exp is sometimes failing like this:

 [Switching to Thread 6831.6832]

 Breakpoint 2, thread_execler (arg=0x0) at /home/pedro/gdb/mygit/build/../src/gdb/testsuite/gdb.threads/non-ldr-exc-3.c:41
 41        if (execl (image, image, argv1, NULL) == -1) /* break-here */
 PASS: gdb.threads/non-ldr-exc-3.exp: lock-sched=on,non-stop=off: continue to breakpoint
 (gdb) set scheduler-locking on
 (gdb) FAIL: gdb.threads/non-ldr-exc-3.exp: lock-sched=on,non-stop=off: set scheduler-locking on

The problem is that the gdb_test_multiple is missing the prompt
anchor.  The problem was introduced by 2fd33e9448.  This reverts the
hunk that introduced the problem, reverting back to
gdb_continue_to_breakpoint.

gdb/testsuite/ChangeLog:
2015-09-15  Pedro Alves  <palves@redhat.com>

	* gdb.threads/non-ldr-exc-3.exp (do_test): Use
	gdb_continue_to_breakpoint instead of gdb_test_multiple.
2015-09-15 17:01:59 +01:00
Yao Qi 750ce8d1ca Support single step by arch or target
Nowadays, GDB only knows whether architecture supports hardware single
step or software single step (through gdbarch hook software_single_step),
and for a given instruction or instruction sequence, GDB knows how to
do single step (hardware or software).  However, GDB doesn't know whether
the target supports hardware single step.  It is possible that the
architecture doesn't support hardware single step, such as arm, but
the target supports, such as simulator.  This was discussed in this
thread https://www.sourceware.org/ml/gdb/2009-12/msg00033.html before.

I encounter this problem for aarch64 multi-arch support.  When aarch64
debugs arm program, gdbarch is arm, so software single step is still
used.  However, the underneath linux kernel does support hardware
single step, so IWBN to use it.

This patch is to add a new target_ops hook to_can_do_single_step, and
only use it in arm_linux_software_single_step to decide whether or not
to use hardware single step.  On the native aarch64 linux target, 1 is
returned.  On other targets, -1 is returned.  On the remote target, if
the target supports s and S actions in the vCont? reply, then target
can do single step.  However,  old GDBserver will send s and S in the
reply to vCont?, which will confuse new GDB.  For example, old GDBserver
on arm-linux will send s and S in the reply to vCont?, but it doesn't
support hardware single step.  On the other hand, new GDBserver, on
arm-linux for example, will not send s and S in the reply to vCont?,
but old GDB thinks it doesn't support vCont packet at all.  In order
to address this problem, I add a new qSupported feature vContSupported,
which indicates GDB wants to know the supported actions in the reply
to vCont?, and qSupported response contains vContSupported if the
stub is able tell supported vCont actions in the reply of vCont?.

If the patched GDB talks with patched GDBserver on x86, the RSP traffic
is like this:

 -> $qSupported:...+;vContSupported+
 <- ...+;vContSupported+
 ...
 -> $vCont?
 <- vCont;c;C;t;s;S;r

then, GDB knows the stub can do single step, and may stop using software
single step even the architecture doesn't support hardware single step.

If the patched GDB talks with patched GDBserver on arm, the last vCont?
reply will become:

 <- vCont;c;C;t

GDB thinks the target doesn't support single step, so it will use software
single step.

If the patched GDB talks with unpatched GDBserver, the RSP traffic is like
this:

 -> $qSupported:...+;vContSupported+
 <- ...+
 ...
 -> $vCont?
 <- vCont;c;C;t;s;S;r

although GDBserver returns s and S, GDB still thinks GDBserver may not
support single step because it doesn't support vContSupported.

If the unpatched GDB talks with patched GDBserver on x86, the RSP traffic
is like:

 -> $qSupported:...+;
 <- ...+;vContSupported+
 ...
 -> $vCont?
 <- vCont;c;C;t;s;S;r

Since GDB doesn't sent vContSupported in the qSupported feature, GDBserver
sends s and S regardless of the support of hardware single step.

gdb:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_linux_can_do_single_step): New
	function.
	(_initialize_aarch64_linux_nat): Install it to to_can_do_single_step.
	* arm-linux-tdep.c (arm_linux_software_single_step): Return 0
	if target_can_do_single_step returns 1.
	* remote.c (struct vCont_action_support) <s, S>: New fields.
	(PACKET_vContSupported): New enum.
	(remote_protocol_features): New element for vContSupported.
	(remote_query_supported): Append "vContSupported+".
	(remote_vcont_probe): Remove support_s and support_S, use
	rs->supports_vCont.s and rs->supports_vCont.S instead.  Disable
	vCont packet if c and C actions are not supported.
	(remote_can_do_single_step): New function.
	(init_remote_ops): Install it to to_can_do_single_step.
	(_initialize_remote): Call add_packet_config_cmd.
	* target.h (struct target_ops) <to_can_do_single_step>: New field.
	(target_can_do_single_step): New macro.
	* target-delegates.c: Re-generated.

gdb/gdbserver:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* server.c (vCont_supported): New global variable.
	(handle_query): Set vCont_supported to 1 if "vContSupported+"
	matches.  Append ";vContSupported+" to own_buf.
	(handle_v_requests): Append ";s;S" to own_buf if target supports
	hardware single step or vCont_supported is false.
	(capture_main): Set vCont_supported to zero.

gdb/doc:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (General Query Packets): Add vContSupported to
	tables of 'gdbfeatures' and 'stub features' supported in the
	qSupported packet, as well as to the list containing stub
	feature details.
2015-09-15 14:09:18 +01:00
Yao Qi 70b90b91bf [gdbserver] Rename supports_conditional_breakpoints to supports_hardware_single_step
In my patch https://sourceware.org/ml/gdb-patches/2015-04/msg01110.html
a new target_ops hook supports_conditional_breakpoints was added to
disable conditional breakpoints if target doesn't have hardware single
step.  This patch is to generalize this hook from
supports_conditional_breakpoints to supports_hardware_single_step,
so that the following patch can use it.

gdb/gdbserver:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (linux_supports_conditional_breakpoints): Rename
	it to ...
	(linux_supports_hardware_single_step): ... New function.
	(linux_target_ops): Update.
	* lynx-low.c (lynx_target_ops): Set field
	supports_hardware_single_step to target_can_do_hardware_single_step.
	* nto-low.c (nto_target_ops): Likewise.
	* spu-low.c (spu_target_ops): Likewise.
	* win32-low.c (win32_target_ops): Likewise.
	* target.c (target_can_do_hardware_single_step): New function.
	* target.h (struct target_ops) <supports_conditional_breakpoints>:
	Remove.  <supports_hardware_single_step>: New field.
	(target_supports_conditional_breakpoints): Remove.
	(target_supports_hardware_single_step): New macro.
	(target_can_do_hardware_single_step): Declare.
	* server.c (handle_query): Use target_supports_hardware_single_step
	instead of target_supports_conditional_breakpoints.
2015-09-15 14:09:18 +01:00
Yao Qi ade90bdeb7 aarch64 multi-arch support (part 2): siginfo fixup
This patch is to fixup the siginfo_t when aarch64 gdb or gdbserver
read from or write to the arm inferior.  It is to convert the
"struct siginfo_t" between aarch64 and arm, which is quite mechanical.

gdb/gdbserver:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_linux_siginfo_fixup): New
	function.
	(struct linux_target_ops the_low_target): Install
	aarch64_linux_siginfo_fixup.

gdb:

2015-09-15  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_linux_siginfo_fixup): New function.
	(_initialize_aarch64_linux_nat): Call linux_nat_set_siginfo_fixup.
	* nat/aarch64-linux.c (aarch64_compat_siginfo_from_siginfo):
	New function.
	(aarch64_siginfo_from_compat_siginfo): New function.
	* nat/aarch64-linux.h: Include signal.h.
	(compat_int_t, compat_uptr_t, compat_time_t): Typedef.
	(compat_timer_t, compat_clock_t): Likewise.
	(struct compat_timeval): New.
	(union compat_sigval): New.
	(struct compat_siginfo): New.
	(cpt_si_pid, cpt_si_uid, cpt_si_timerid): New macros.
	(cpt_si_overrun, cpt_si_status, cpt_si_utime): Likewise.
	(cpt_si_stime, cpt_si_ptr, cpt_si_addr): Likewise.
	(cpt_si_band, cpt_si_fd): Likewise.
2015-09-15 10:25:51 +01:00
Pedro Alves 4c2f2a792a Bail out of processing stop if hook-stop resumes target / changes context
This patch, relative to a tree with
https://sourceware.org/ml/gdb-patches/2015-08/msg00295.html, fixes
issues/crashes that trigger if something unexpected happens during a
hook-stop.

E.g., if the inferior disappears while running the hook-stop, we hit
failed assertions:

 (gdb) define hook-stop
 Type commands for definition of "hook-stop".
 End with a line saying just "end".
 >kill
 >end
 (gdb) si
 Kill the program being debugged? (y or n) [answered Y; input not from terminal]
 /home/pedro/gdb/mygit/build/../src/gdb/thread.c:88: internal-error: 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)

I noticed that if a hook-stop issues a synchronous execution command,
we print the same stop event twice:

 (gdb) define hook-stop
 Type commands for definition of "hook-stop".
 End with a line saying just "end".
 >si
 >end
 (gdb) si
 0x000000000040074a      42          args[i] = 1; /* Init value.  */  <<<<<<< once
 0x000000000040074a      42          args[i] = 1; /* Init value.  */  <<<<<<< twice
 (gdb)

In MI:

 *stopped,reason="end-stepping-range",frame={addr="0x000000000040074a",func="main",args=[],file="threads.c",fullname="/home/pedro/gdb/tests/threads.c",line="42"},thread-id="1",stopped-threads="all",core="0"
 *stopped,reason="end-stepping-range",frame={addr="0x000000000040074a",func="main",args=[],file="threads.c",fullname="/home/pedro/gdb/tests/threads.c",line="42"},thread-id="1",stopped-threads="all",core="0"
 (gdb)

The fix has GDB stop processing the event if the context changed.  I
don't expect people to be doing crazy things from the hook-stop.
E.g., it gives me headaches to try to come up a proper behavior for
handling a thread change from a hook-stop... (E.g., imagine the
hook-stop does thread N; step, with scheduler-locing on).  I think the
most important bit here is preventing crashes.

The patch adds a new hook-stop.exp test that covers the above and also
merges in the old hook-stop-continue.exp and hook-stop-frame.exp into
the same framework.

gdb/ChangeLog:
2015-09-14  Pedro Alves  <palves@redhat.com>

	* infrun.c (current_stop_id): New global.
	(get_stop_id, new_stop_id): New functions.
	(fetch_inferior_event): Handle normal_stop proceeding the target.
	(struct stop_context): New.
	(save_stop_context, release_stop_context_cleanup)
	(stop_context_changed): New functions.
	(normal_stop): Return true if the hook-stop changes the stop
	context.
	* infrun.h (get_stop_id): Declare.
	(normal_stop): Now returns int.  Add documentation.

gdb/testsuite/ChangeLog:
2015-09-14  Pedro Alves  <palves@redhat.com>

	* gdb.base/hook-stop-continue.c: Delete.
	* gdb.base/hook-stop-continue.exp: Delete.
	* gdb.base/hook-stop-frame.c: Delete.
	* gdb.base/hook-stop-frame.exp: Delete.
	* gdb.base/hook-stop.c: New file.
	* gdb.base/hook-stop.exp: New file.
2015-09-14 15:45:14 +01:00
Pierre-Marie de Rodat 919e6dbe9b [Ada] Fix the evaluation of access to packed array subscript
This change is relevant only for standard DWARF (as opposed to the GNAT
encodings extensions): at the time of writing it only makes a difference
with GCC patches that are to be integrated: see in particular
<https://gcc.gnu.org/ml/gcc-patches/2015-07/msg01364.html>.

Given the following Ada declarations:

    type Small is mod 2 ** 6;
    type Array_Type is array (0 .. 9) of Small
       with Pack;
    type Array_Access is access all Array_Type;

    A  : aliased Array_Type := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    AA : constant Array_Type := A'Access;

Before this change, we would get the following GDB session:

    (gdb) print aa.all(2)
    $1 = 3
    (gdb) print aa(2)
    $2 = 16

This is wrong: both expression should yield the same value: 3.  The
problem is simply that the routine which handles accesses to arrays lack
general handling for packed arrays.  After this patch, we have the
expected output:

    (gdb) print aa.all(2)
    $1 = 3
    (gdb) print aa(2)
    $2 = 3

gdb/ChangeLog:

	* ada-lang.c (ada_value_ptr_subscript): Update the heading
	comment.  Handle packed arrays.

gdb/testsuite/ChangeLog:

	* gdb.ada/access_to_packed_array.exp: New testcase.
	* gdb.ada/access_to_packed_array/foo.adb: New file.
	* gdb.ada/access_to_packed_array/pack.adb: New file.
	* gdb.ada/access_to_packed_array/pack.ads: New file.

Tested on x86_64-linux, no regression.
2015-09-14 16:28:23 +02:00
Pedro Alves b027a8fa7d Remove duplicate gdb/NEWS entry
Commit fbea99ea8a added this to both the "Changes in GDB 7.10" and
"Changes since GDB 7.10" sections by mistake.

gdb/ChangeLog:
2015-09-14  Pedro Alves  <palves@redhat.com>

	* NEWS (Changes in GDB 7.10, New commands>: Remove duplicate
	mention of maint set/show target-non-stop.
2015-09-14 14:43:53 +01:00
Markus Metzger 157280a4d6 btrace, test: remove buffer-size test with unlimited buffer size
The gdb.btrace/buffer-size.exp test starts recording with an unlimited
buffer size.  This will, for a short time, use up most if not all BTS
resources.

I don' think this test is necessary.  Remove it.

testsuite/
	* gdb.btrace/buffer-size.exp: Remove recording with unlimited BTS
	buffer size test.
2015-09-14 13:50:06 +02:00
Don Breazeal b459a59be3 Extended-remote exec documentation
This patch adds documentation of support for exec events on
extended-remote Linux targets.

gdb/ChangeLog:

	* NEWS: Announce new remote packets for the exec-events
	feature and the exec-events feature and associated commands.

gdb/doc/ChangeLog:

	* gdb.texinfo (Remote Configuration): Add exec event
	feature to table of packet settings.
	(Stop Reply Packets): Add exec events to the list of stop
	reasons.
	(General Query Packets): Add exec events to tables of
	'gdbfeatures' and 'stub features' supported in the qSupported
	packet, as well as to the list containing stub feature
	details.
2015-09-11 11:12:47 -07:00
Don Breazeal 2fd33e9448 Extended-remote exec test
This patch updates several exec-related tests and some of the library
functions in order to get them running with extended-remote.  There were
three changes that were required, as follows:

In gdb.base/foll-exec.exp, use 'clean_start' in place of proc 'zap_session'
to reset the state of the debugger between tests.  This sets 'remote
exec-file' to execute the correct binary file in each subsequent test.

In gdb.base/pie-execl.exp, there is an expect statement with an expression
that is used to match output from both gdb and the program under debug.
For the remote target, this had to be split into two expressions, using
$inferior_spawn_id to match the output from the program.

Because I had encountered problems with extended-remote exec events in
non-stop mode in my manual testing, I added non-stop testing to the
non-ldr-exc-[1234].exp tests.  In order to set non-stop mode for remote
targets, it is necessary to 'set non-stop on' after gdb has started, but
before it connects to gdbserver.  This is done using 'save_vars' to set
non-stop mode in GDBFLAGS, so GDB sets non-stop mode on startup.

gdb/testsuite/ChangeLog:

	* gdb.base/foll-exec.c: Add copyright header.  Fix
	formatting issues.
	* gdb.base/foll-exec.exp (zap_session): Delete proc.
	(do_exec_tests): Use clean_restart in place of zap_session,
	and for test initialization.  Fix formatting issues.  Use
	fail in place of perror.
	* gdb.base/pie-execl.exp (main): Use 'inferior_spawn_id' in
	an expect statement to match an expression with output from
	the program under debug.
	* gdb.threads/non-ldr-exc-1.exp (do_test, main): Add
	non-stop tests and pass stop mode argument to clean_restart.
	Use save_vars to enable non-stop in GDBFLAGS.
	* gdb.threads/non-ldr-exc-2.exp: Likewise.
	* gdb.threads/non-ldr-exc-3.exp: Likewise.
	* gdb.threads/non-ldr-exc-4.exp: Likewise.
2015-09-11 11:12:46 -07:00
Don Breazeal d46addbb52 Extended-remote catch exec
This patch implements exec catchpoints for extended-remote Linux
targets.  The implementation follows the same approach used for
fork catchpoints, implementing extended-remote target routines for
inserting and removing the catchpoints by just checking if exec events
are supported.  Existing host-side code and previous support for
extended-remote exec events takes care of the rest.

gdb/ChangeLog:

	* remote.c (remote_exec_event_p): New function.
	(remote_insert_exec_catchpoint): New function.
	(remote_remove_exec_catchpoint): New function.
	(init_extended_remote_ops): Initialize extended_remote_ops
	members to_insert_exec_catchpoint and
	to_remove_exec_catchpoint.
2015-09-11 11:12:46 -07:00
Don Breazeal 94585166df Extended-remote follow-exec
This patch implements support for exec events on extended-remote Linux
targets.  Follow-exec-mode and rerun behave as expected.  Catchpoints and
test updates are implemented in subsequent patches.

This patch was derived from a patch posted last October:
https://sourceware.org/ml/gdb-patches/2014-10/msg00877.html.
It was originally based on some work done by Luis Machado in 2013.

IMPLEMENTATION
----------------
Exec events are enabled via ptrace options.

When an exec event is detected by gdbserver, the existing process
data, along with all its associated lwp and thread data, is deleted
and replaced by data for a new single-threaded process.  The new
process data is initialized with the appropriate parts of the state
of the execing process.  This approach takes care of several potential
pitfalls, including:

 * deleting the data for an execing non-leader thread before any
   wait/sigsuspend occurs
 * correctly initializing the architecture of the execed process

We then report the exec event using a new RSP stop reason, "exec".

When GDB receives an "exec" event, it saves the status in the event
structure's target_waitstatus field, like what is done for remote fork
events.  Because the original and execed programs may have different
architectures, we skip parsing the section of the stop reply packet
that contains register data.  The register data will be retrieved
later after the inferior's architecture has been set up by
infrun.c:follow_exec.

At that point the exec event is handled by the existing event handling
in GDB.  However, a few changes were necessary so that
infrun.c:follow_exec could accommodate the remote target.

 * Where follow-exec-mode "new" is handled, we now call
   add_inferior_with_spaces instead of add_inferior with separate calls
   to set up the program and address spaces.  The motivation for this
   is that add_inferior_with_spaces also sets up the initial architecture
   for the inferior, which is needed later by target_find_description
   when it calls target_gdbarch.

 * We call a new target function, target_follow_exec.  This function
   allows us to store the execd_pathname in the inferior, instead of
   using the static string remote_exec_file from remote.c.  The static
   string didn't work for follow-exec-mode "new", since once you switched
   to the execed program, the original remote exec-file was lost.  The
   execd_pathname is now stored in the inferior's program space as a
   REGISTRY field.  All of the requisite mechanisms for this are
   defined in remote.c.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_mourn): Static declaration.
	(linux_arch_setup): Move in front of
	handle_extended_wait.
	(linux_arch_setup_thread): New function.
	(handle_extended_wait): Handle exec events.  Call
	linux_arch_setup_thread.  Make event_lwp argument a
	pointer-to-a-pointer.
	(check_zombie_leaders): Do not check stopped threads.
	(linux_low_ptrace_options): Add PTRACE_O_TRACEEXEC.
	(linux_low_filter_event): Add lwp and thread for exec'ing
	non-leader thread if leader thread has been deleted.
	Refactor code into linux_arch_setup_thread and call it.
	Pass child lwp pointer by reference to handle_extended_wait.
	(linux_wait_for_event_filtered): Update comment.
	(linux_wait_1): Prevent clobbering exec event status.
	(linux_supports_exec_events): New function.
	(linux_target_ops) <supports_exec_events>: Initialize new member.
	* lynx-low.c (lynx_target_ops) <supports_exec_events>: Initialize
	new member.
	* remote-utils.c (prepare_resume_reply): New stop reason 'exec'.
	* server.c (report_exec_events): New global variable.
	(handle_query): Handle qSupported query for exec-events feature.
	(captured_main): Initialize report_exec_events.
	* server.h (report_exec_events): Declare new global variable.
	* target.h (struct target_ops) <supports_exec_events>: New
	member.
	(target_supports_exec_events): New macro.
	* win32-low.c (win32_target_ops) <supports_exec_events>:
	Initialize new member.

gdb/ChangeLog:

	* infrun.c (follow_exec): Use process-style ptid for
	exec message.  Call add_inferior_with_spaces and
	target_follow_exec.
	* nat/linux-ptrace.c (linux_supports_traceexec): New function.
	* nat/linux-ptrace.h (linux_supports_traceexec): Declare.
	* remote.c (remote_pspace_data): New static variable.
	(remote_pspace_data_cleanup): New function.
	(get_remote_exec_file): New function.
	(set_remote_exec_file_1): New function.
	(set_remote_exec_file): New function.
	(show_remote_exec_file): New function.
	(remote_exec_file): Delete static variable.
	(anonymous enum) <PACKET_exec_event_feature> New
	enumeration constant.
	(remote_protocol_features): Add entry for exec-events feature.
	(remote_query_supported): Add client side of qSupported query
	for exec-events feature.
	(remote_follow_exec): New function.
	(remote_parse_stop_reply): Handle 'exec' stop reason.
	(extended_remote_run, extended_remote_create_inferior): Call
	get_remote_exec_file and set_remote_exec_file_1.
	(init_extended_remote_ops) <to_follow_exec>: Initialize new
	member.
	(_initialize_remote): Call
	register_program_space_data_with_cleanup.  Call
	add_packet_config_cmd for remote exec-events feature.
	Modify call to add_setshow_string_noescape_cmd for exec-file
	to use new functions set_remote_exec_file and
	show_remote_exec_file.
	* target-debug.h, target-delegates.c: Regenerated.
	* target.c (target_follow_exec): New function.
	* target.h (struct target_ops) <to_follow_exec>: New member.
	(target_follow_exec): Declare new function.
2015-09-11 11:12:46 -07:00
Pierre Langlois 669e74e829 [AArch64] Cleanup comments in instruction decoding functions
gdb/ChangeLog:

	* aarch64-tdep.c (decode_cb): Move up comment describing the
	encoding.
	(decode_tb): Fix a typo in comment above the function.  Move up
	comment describing the encoding.
2015-09-11 17:00:55 +01:00
Pierre Langlois 4d50586db7 [AArch64] Fix incorrect mask when decoding b.cond instruction
The encoding of the b.cond instruction is described in the architecture
reference manual as:

b.cond  0101 0100 iiii iiii iiii iiii iii0 cccc

So the mask should be 0xff000010.

gdb/ChangeLog:

	* aarch64-tdep.c (decode_bcond): Fix incorrect mask.
2015-09-11 16:47:20 +01:00
Mihail-Marian Nistor 6dcaef99fa gdb/18947: [aarch64]Step into shared library is very slow.
Install gdbarch_skip_solib_resolver on aarch64 GNU/Linux

gdb/ChangeLog:

2015-09-11  Mihail-Marian Nistor  <mihail.nistor@freescale.com>

	PR gdb/18947
	* aarch64-linux-tdep.c: (aarch64_linux_init_abi): Install
	glibc_skip_solib_resolver as gdbarch_skip_solib_resolver callback.

Signed-off-by: Mihail-Marian Nistor <mihail.nistor@freescale.com>
2015-09-11 15:22:11 +01:00
Simon Marchi 5da1a4d34e Small refactor in ada-lang.c:scan_discrim_bound
Factor out common arithmetic operations for clarity.

gdb/ChangeLog:

	* ada-lang.c (scan_discrim_bound): Factor out arithmetic
	operations.
2015-09-10 11:48:47 -04:00
Simon Marchi 108d56a48b Constify variables in ada-lang.c
I found this const/not const mixup found by building in C++ mode.

gdb/ChangeLog:

	* ada-lang.c (ada_search_struct_field): Constify parameters
	and/or variables..
	(xget_renaming_scope): Likewise.
	(ada_is_redundant_range_encoding): Likewise.
	(scan_discrim_bound): Likewise.
	(to_fixed_range_type): Likewise.
2015-09-10 11:12:51 -04:00
Yao Qi dd2e65cc2c Call target_can_download_tracepoint if there are tracepoints to download
Nowadays, GDB calls target_can_download_tracepoint at the entry of
download_tracepoint_locations, which is called by.
update_global_location_list.  Sometimes, it is not needed to call
target_can_download_tracepoint at all because there is no tracepoint
created.  In remote target, target_can_download_tracepoint send
qTStatus to the remote in order to know whether tracepoint can be
downloaded or not.  This means some redundant qTStatus packets are
sent.

This patch is to teach GDB to call target_can_download_tracepoint
lazily, only on the moment there are tracepoint to download.
gdb.perf/single-step.exp (with a local patch to measure RSP packets)
shows the number of RSP packets is reduced because there is no
tracepoint at all, so GDB doesn't send qTStatus any more.

                       # of RSP packets
                       original  patched
single-step rsp 1000   7000      6000
single-step rsp 2000   14000     12000
single-step rsp 3000   21000     18000
single-step rsp 4000   28000     24000

gdb:

2015-09-10  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (download_tracepoint_locations): New local
	can_download_tracepoint.  Check the result of
	target_can_download_tracepoint and save it in
	can_download_tracepoint if there are tracepoints to download.
	* linux-nat.h (enum tribool): Move it to ...
	* common/common-types.h: ... here.
2015-09-10 12:31:36 +01:00
Doug Evans e70b6e8eee * gdb.python/py-prettyprint.exp: Check result of run_lang_tests.
gdb/testsuite/ChangeLog:

	* gdb.python/py-prettyprint.exp: Check result of run_lang_tests.
2015-09-09 11:42:52 -07:00
Doug Evans 7a551a5158 * gdb.base/pie-execl.exp: Fix result test of build_executable.
gdb/testsuite/ChangeLog:

	* gdb.base/pie-execl.exp: Fix result test of build_executable.
2015-09-09 11:17:36 -07:00
Doug Evans 4c666f844a * gdb.base/savedregs.exp: Fix typo.
gdb/testsuite/ChangeLog:

	* gdb.base/savedregs.exp: Fix typo.
2015-09-09 11:00:55 -07:00
Pedro Alves cfe7570334 Delete enum inferior_event_handler::INF_TIMER
Nothing ever uses this.

gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* inf-loop.c (inferior_event_handler): Delete INF_TIMER case.
	* target.h (enum inferior_event_type) <INF_TIMER>: Delete.
2015-09-09 18:25:55 +01:00
Pedro Alves a85a307923 Garbage collect thread continuations
Nothing uses thread continuations anymore.

(inferior continuations are still used by the attach command.)

gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* continuations.c (add_continuation, restore_thread_cleanup)
	(do_all_continuations_ptid, do_all_continuations_thread_callback)
	(do_all_continuations_thread, do_all_continuations)
	(discard_all_continuations_thread_callback)
	(discard_all_continuations_thread, discard_all_continuations)
	(add_intermediate_continuation)
	(do_all_intermediate_continuations_thread_callback)
	(do_all_intermediate_continuations_thread)
	(do_all_intermediate_continuations)
	(discard_all_intermediate_continuations_thread_callback)
	(discard_all_intermediate_continuations_thread)
	(discard_all_intermediate_continuations): Delete.
	* continuations.h (add_continuation, do_all_continuations)
	(do_all_continuations_thread, discard_all_continuations)
	(discard_all_continuations_thread, add_intermediate_continuation)
	(do_all_intermediate_continuations)
	(do_all_intermediate_continuations_thread)
	(discard_all_intermediate_continuations)
	(discard_all_intermediate_continuations_thread): Delete
	declarations.
	* event-top.c (stdin_event_handler): Delete references to
	continuations.
	* gdbthread.h (struct thread_info): Delete continuations and
	intermediate_continuations fields.
	* inf-loop.c (inferior_event_handler): Remove references to
	continuations.
	* infrun.c (infrun_thread_stop_requested_callback): Remove
	references to continuations.
	* target.h (enum inferior_event_type) <INF_EXEC_CONTINUE>: Delete.
	* thread.c: Don't include "continuations.h".
	(clear_thread_inferior_resources): Remove references to
	continuations.
2015-09-09 18:25:33 +01:00
Pedro Alves 0700e23e5f Garbage collect dummy_frame_ctx_saver
Since the "finish" command and infcall's FSMs are now responsible for
saving the return value, the dummy_frame_ctx_saver is no longer needed
anywhere.

gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* infcall.c (struct dummy_frame_context_saver): Delete.
	(dummy_frame_context_saver_free, dummy_frame_context_saver_dtor)
	(dummy_frame_context_saver_drop)
	(dummy_frame_context_saver_cleanup)
	(dummy_frame_context_saver_get_regs)
	(dummy_frame_context_saver_setup): Delete.
	* infcall.h (dummy_frame_context_saver_drop)
	(dummy_frame_context_saver_cleanup)
	(dummy_frame_context_saver_get_regs, dummy_frame_context_saver):
	Delete.
	(get_return_value): Remove 'ctx_saver' paremeter.  Adjust.
	* inferior.h (get_return_value): Remove 'ctx_saver' paremeter.
	* python/py-finishbreakpoint.c (bpfinishpy_pre_stop_hook): Adjust.
2015-09-09 18:25:15 +01:00
Pedro Alves cfc3163382 Convert the until/advance commands to thread_fsm mechanism
gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* breakpoint.c: Include "thread-fsm.h".
	(struct until_break_command_continuation_args): Delete.
	(struct until_break_fsm): New.
	(until_break_fsm_ops): New global.
	(new_until_break_fsm, until_break_fsm_should_stop): New functions.
	(until_break_command_continuation): Delete.
	(until_break_fsm_clean_up): New function.
	(until_break_fsm_async_reply_reason): New function.
	(until_break_command): Adjust to create an until_break_fsm instead
	of a continuation.
	(momentary_bkpt_print_it): No longer print MI's async-stop-reason
	here.
	* infcmd.c (struct until_next_fsm): New.
	(until_next_fsm_ops): New global.
	(new_until_next_fsm, until_next_fsm_should_stop): New function.
	(until_next_continuation): Delete.
	(until_next_fsm_clean_up, until_next_fsm_async_reply_reason): New
	functions.
	(until_next_command): Adjust to create a new until_next_fsm
	instead of a continuation.
2015-09-09 18:24:56 +01:00
Pedro Alves 388a708404 Convert infcalls to thread_fsm mechanism
This removes infcall-specific special casing from normal_stop,
simplifying it.

Like the "finish" command's, the FSM is responsible for storing the
function's return value.

gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* infcall.c: Include thread_fsm.h.
	(struct call_return_meta_info): New.
	(get_call_return_value): New function, factored out from
	call_function_by_hand_dummy.
	(struct call_thread_fsm): New.
	(call_thread_fsm_ops): New global.
	(new_call_thread_fsm, call_thread_fsm_should_stop)
	(call_thread_fsm_should_notify_stop): New functions.
	(run_inferior_call): Add 'sm' parameter.  Associate the FSM with
	the thread.
	(call_function_by_hand_dummy): Create a new call_thread_fsm
	instance, associate it with the thread, and wait for the FSM to
	finish.  If finished successfully, fetch the function's result
	value out of the FSM.
	* infrun.c (fetch_inferior_event): If the FSM says the stop
	shouldn't be notified, don't call normal_stop.
	(maybe_remove_breakpoints): New function, factored out from ...
	(normal_stop): ... here.  Simplify.
	* infrun.h (maybe_remove_breakpoints): Declare.
	* thread-fsm.c (thread_fsm_should_notify_stop): New function.
	(thread-fsm.h) <struct thread_fsm_ops>: New field.
	(thread_fsm_should_notify_stop): Declare.
2015-09-09 18:24:34 +01:00
Pedro Alves 243a925328 Replace "struct continuation" mechanism by something more extensible
This adds an object oriented replacement for the "struct continuation"
mechanism, and converts the stepping commands (step, next, stepi,
nexti) and the "finish" commands to use it.

It adds a new thread "class" (struct thread_fsm) that contains the
necessary info and callbacks to manage the state machine of a thread's
execution command.

This allows getting rid of some hacks.  E.g., in fetch_inferior_event
and normal_stop we no longer need to know whether a thread is doing a
multi-step (e.g., step N).  This effectively makes the
intermediate_continuations unused -- they'll be garbage collected in a
separate patch.  (They were never a proper abstraction, IMO.  See how
fetch_inferior_event needs to check step_multi before knowing whether
to call INF_EXEC_CONTINUE or INF_EXEC_COMPLETE.)

The target async vs !async uiout hacks in mi_on_normal_stop go away
too.

print_stop_event is no longer called from normal_stop.  Instead it is
now called from within each interpreter's normal_stop observer.  This
clears the path to make each interpreter print a stop event the way it
sees fit.  Currently we have some hacks in common code to
differenciate CLI vs TUI vs MI around this area.

The "finish" command's FSM class stores the return value plus that
value's position in the value history, so that those can be printed to
both MI and CLI's streams.  This fixes the CLI "finish" command when
run from MI -- it now also includes the function's return value in the
CLI stream:

  (gdb)
  ~"callee3 (strarg=0x400730 \"A string argument.\") at src/gdb/testsuite/gdb.mi/basics.c:35\n"
  ~"35\t}\n"
 +~"Value returned is $1 = 0\n"
  *stopped,reason="function-finished",frame=...,gdb-result-var="$1",return-value="0",thread-id="1",stopped-threads="all",core="0"
 -FAIL: gdb.mi/mi-cli.exp: CLI finish: check CLI output
 +PASS: gdb.mi/mi-cli.exp: CLI finish: check CLI output

gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMMON_OBS): Add thread-fsm.o.
	* breakpoint.c (handle_jit_event): Print debug output.
	(bpstat_what): Split event callback handling to ...
	(bpstat_run_callbacks): ... this new function.
	(momentary_bkpt_print_it): No longer handle bp_finish here.
	* breakpoint.h (bpstat_run_callbacks): Declare.
	* gdbthread.h (struct thread_info) <step_multi>: Delete field.
	<thread_fsm>: New field.
	(thread_cancel_execution_command): Declare.
	* infcmd.c: Include thread-fsm.h.
	(struct step_command_fsm): New.
	(step_command_fsm_ops): New global.
	(new_step_command_fsm, step_command_fsm_prepare): New functions.
	(step_1): Adjust to use step_command_fsm_prepare and
	prepare_one_step.
	(struct step_1_continuation_args): Delete.
	(step_1_continuation): Delete.
	(step_command_fsm_should_stop): New function.
	(step_once): Delete.
	(step_command_fsm_clean_up, step_command_fsm_async_reply_reason)
	(prepare_one_step): New function, based on step_once.
	(until_next_command): Remove step_multi reference.
	(struct return_value_info): New.
	(print_return_value): Rename to ...
	(print_return_value_1): ... this.  New struct return_value_info
	parameter.  Adjust.
	(print_return_value): Reimplement as wrapper around
	print_return_value_1.
	(struct finish_command_fsm): New.
	(finish_command_continuation): Delete.
	(finish_command_fsm_ops): New global.
	(new_finish_command_fsm, finish_command_fsm_should_stop): New
	functions.
	(finish_command_fsm_clean_up, finish_command_fsm_return_value):
	New.
	(finish_command_continuation_free_arg): Delete.
	(finish_command_fsm_async_reply_reason): New.
	(finish_backward, finish_forward): Change symbol parameter to a
	finish_command_fsm.  Adjust.
	(finish_command): Create a finish_command_fsm.  Adjust.
	* infrun.c: Include "thread-fsm.h".
	(clear_proceed_status_thread): Delete the thread's FSM.
	(infrun_thread_stop_requested_callback): Cancel the thread's
	execution command.
	(clean_up_just_stopped_threads_fsms): New function.
	(fetch_inferior_event): Handle the event_thread's should_stop
	method saying the command isn't done yet.
	(process_event_stop_test): Run breakpoint callbacks here.
	(print_stop_event): Rename to ...
	(print_stop_location): ... this.
	(restore_current_uiout_cleanup): New function.
	(print_stop_event): Reimplement.
	(normal_stop): No longer notify the end_stepping_range observers
	here handle "step N" nor "finish" here.  No longer call
	print_stop_event here.
	* infrun.h (struct return_value_info): Forward declare.
	(print_return_value): Declare.
	(print_stop_event): Change prototype.
	* thread-fsm.c: New file.
	* thread-fsm.h: New file.
	* thread.c: Include "thread-fsm.h".
	(thread_cancel_execution_command): New function.
	(clear_thread_inferior_resources): Call it.
	* cli/cli-interp.c (cli_on_normal_stop): New function.
	(cli_interpreter_init): Install cli_on_normal_stop as normal_stop
	observer.
	* mi/mi-interp.c: Include "thread-fsm.h".
	(restore_current_uiout_cleanup): Delete.
	(mi_on_normal_stop): If the thread has an FSM associated, and it
	finished, ask it for the async-reply-reason to print.  Always call
	print_stop_event here, regardless of the top-level interpreter.
	Check bpstat_what to tell whether an asynchronous breakpoint hit
	triggered.
	* tui/tui-interp.c (tui_on_normal_stop): New function.
	(tui_init): Install tui_on_normal_stop as normal_stop observer.

gdb/testsuite/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* gdb.mi/mi-cli.exp: Add CLI finish tests.
2015-09-09 18:24:00 +01:00
Pedro Alves 0b333c5e7d Merge async and sync code paths some more
This patch makes the execution control code use largely the same
mechanisms in both sync- and async-capable targets.  This means using
continuations and use the event loop to react to target events on sync
targets as well.  The trick is to immediately mark infrun's event loop
source after resume instead of calling wait_for_inferior.  Then
fetch_inferior_event is adjusted to do a blocking wait on sync
targets.

Tested on x86_64 Fedora 20, native and gdbserver, with and without
"maint set target-async off".

gdb/ChangeLog:
2015-09-09  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (bpstat_do_actions_1, until_break_command): Don't
	check whether the target can async.
	* inf-loop.c (inferior_event_handler): Only call target_async if
	the target can async.
	* infcall.c: Include top.h and interps.h.
	(run_inferior_call): For the interpreter to sync mode while
	running the infcall.  Call wait_sync_command_done instead of
	wait_for_inferior plus normal_stop.
	* infcmd.c (prepare_execution_command): Don't check whether the
	target can async when running in the foreground.
	(step_1): Delete synchronous case handling.
	(step_once): Always install a continuation, even in sync mode.
	(until_next_command, finish_forward): Don't check whether the
	target can async.
	(attach_command_post_wait, notice_new_inferior): Always install a
	continuation, even in sync mode.
	* infrun.c (mark_infrun_async_event_handler): New function.
	(proceed): In sync mode, mark infrun's event source instead of
	waiting for events here.
	(fetch_inferior_event): If the target can't async, do a blocking
	wait.
	(prepare_to_wait): In sync mode, mark infrun's event source.
	(infrun_async_inferior_event_handler): No longer bail out if the
	target can't async.
	* infrun.h (mark_infrun_async_event_handler): New declaration.
	* linux-nat.c (linux_nat_wait_1): Remove calls to
	set_sigint_trap/clear_sigint_trap.
	(linux_nat_terminal_inferior): No longer check whether the target
	can async.
	* mi/mi-interp.c (mi_on_sync_execution_done): Update and simplify
	comment.
	(mi_execute_command_input_handler): No longer check whether the
	target is async.  Update and simplify comment.
	* target.c (default_target_wait): New function.
	* target.h (struct target_ops) <to_wait>: Now defaults to
	default_target_wait.
	(default_target_wait): Declare.
	* top.c (wait_sync_command_done): New function, factored out from
	...
	(maybe_wait_sync_command_done): ... this.
	* top.h (wait_sync_command_done): Declare.
	* target-delegates.c: Regenerate.
2015-09-09 18:23:23 +01:00
Markus Metzger 0568462bbf btrace: kernel address filtering
For the BTS recording format, we sometimes get a FROM->TO record where the
FROM address lies in the kernel and the TO address lies in user space at
whatever address the user process was resumed.

GDB has a heuristic to filter out such records based on looking at the most
significant bit in the PC.  This works fine for 64-bit systems but it doesn't
always work for 32-bit systems.  Libraries that are loaded at fairly high
addresses might be mistaken for kernel code and branches inside the library
are filtered out.

Change the heuristic to (again heuristically) try to determine the lowest
address in kernel space.  Any PC that is smaller than that should be in
user space.

On today's systems, there should be a symbol "_text" at that address.
Read /proc/kallsyms and search for that symbol.

It is not guaranteed that /proc/kallsyms is readable on all systems.  On
64-bit systems, we fall back to check the most significant bit.  On 32-bit
systems, we refrain from filtering out addresses.

The filtering should really be done by the kernel.  And it soon will be:
https://lkml.org/lkml/2015/8/31/212.

gdb/
	* nat/linux-btrace.h (struct btrace_target_info) <ptr_bits>: Remove.
	* nat/linux-btrace.c: Include filestuff.h and inttypes.h.
	Remove include of sys/utsname.h.
	(linux_determine_kernel_ptr_bits): Remove.
	(linux_determine_kernel_start): New.
	(perf_event_is_kernel_addr): Remove tinfo argument.  Update users.
	Update check.
	(perf_event_skip_bts_record): Remove tinfo argument.  Update users.
	(linux_enable_bts, linux_enable_pt): Remove tinfo->ptr_bits
	initialization.
	* x86-linux-nat.c (x86_linux_enable_btrace): Remove ptr_bits
	assignment.

gdbserver/
	* linux-low.c (linux_low_enable_btrace): Remove.
	(linux_target_ops): Replace linux_low_enable_btrace with
	linux_enable_btrace.
2015-09-09 10:35:35 +02:00
Sandra Loosemore c0fa8fbd1c Improve hand-call-in-threads.exp failure handling.
2015-09-08  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.threads/hand-call-in-threads.exp: Make sure the thread
	command actually switches threads.  Give up on remaining
	tests if target fails to stop at breakpoint.
2015-09-08 19:49:04 -07:00
Pedro Alves 72e0248351 guile: Add as_a_scm_t_subr
Building GDB in C++ mode on Fedora 20, the gdb/guile/ code shows ~280
errors like:

 src/gdb/guile/guile.c:515:1: error: invalid conversion from ‘scm_unused_struct* (*)(SCM, SCM) {aka scm_unused_struct* (*)(scm_unused_struct*, scm_unused_struct*)}’ to ‘scm_t_subr {aka void*}’ [-fpermissive]

This commit fixes them all.

gdb/ChangeLog:
2015-09-07  Pedro Alves  <palves@redhat.com>

	* guile/guile-internal.h (as_a_scm_t_subr): New.
	* guile/guile.c (misc_guile_functions): Use it.
	* guile/scm-arch.c (arch_functions): Use it.
	* guile/scm-block.c (block_functions, gdbscm_initialize_blocks):
	Use it.
	* guile/scm-breakpoint.c (breakpoint_functions): Use it.
	* guile/scm-cmd.c (command_functions): Use it.
	* guile/scm-disasm.c (disasm_functions): Use it.
	* guile/scm-exception.c (exception_functions)
	(private_exception_functions): Use it.
	* guile/scm-frame.c (frame_functions)
	* guile/scm-gsmob.c (gsmob_functions): Use it.
	* guile/scm-iterator.c (iterator_functions): Use it.
	* guile/scm-lazy-string.c (lazy_string_functions): Use it.
	* guile/scm-math.c (math_functions): Use it.
	* guile/scm-objfile.c (objfile_functions): Use it.
	* guile/scm-param.c (parameter_functions): Use it.
	* guile/scm-ports.c (port_functions, private_port_functions): Use
	it.
	* guile/scm-pretty-print.c (pretty_printer_functions): Use it.
	* guile/scm-progspace.c (pspace_functions): Use it.
	* guile/scm-string.c (string_functions): Use it.
	* guile/scm-symbol.c (symbol_functions): Use it.
	* guile/scm-symtab.c (symtab_functions): Use it.
	* guile/scm-type.c (type_functions, gdbscm_initialize_types): Use
	it.
	* guile/scm-value.c (value_functions): Use it.
2015-09-07 19:34:31 +01:00
Andrew Burgess e65b52456b gdb/tui: Remove casts of NULL during assignment.
In the following code:

    struct symbol *wsym = (struct symbol *) NULL;

the cast of NULL is redundant, it adds noise, and is just one more thing
to change if the type of wsym ever changes.  There are a relatively
small number of places in gdb where the above code pattern is used.
Usually the cast is removed like this:

    struct symbol *wsym = NULL;

This commit updates all the places within the gdb/tui directory where we
cast NULL during assignment, removing the cast.

gdb/ChangeLog:

	* tui/tui-data.c (win_with_focus): Remove cast of NULL pointer.
	(tui_next_win): Likewise.
	(tui_prev_win): Likewise.
	(tui_partial_win_by_name): Likewise.
	(tui_init_generic_part): Likewise.
	(init_content_element): Likewise.
	(tui_del_window): Likewise.
	(tui_free_window): Likewise.
	(tui_del_data_windows): Likewise.
	(tui_free_data_content): Likewise.
	* tui/tui-layout.c (make_source_or_disasm_window): Likewise.
	* tui/tui-regs.c (tui_show_register_group): Likewise.
	* tui/tui-win.c (tui_resize_all): Likewise.
	(tui_set_focus): Likewise.
	(tui_set_win_height): Likewise.
	(make_invisible_and_set_new_height): Likewise.
	* tui/tui-windata.c (tui_delete_data_content_windows): Likewise.
	* tui/tui-wingeneral.c (make_visible): Likewise.
2015-09-04 16:50:41 +01:00
Andrew Burgess b03e6ad9cd gdb/cli: Remove casts of NULL during assignment.
In the following code:

    struct symbol *wsym = (struct symbol *) NULL;

the cast of NULL is redundant, it adds noise, and is just one more thing
to change if the type of wsym ever changes.  There are a relatively
small number of places in gdb where the above code pattern is used.
Usually the cast is removed like this:

    struct symbol *wsym = NULL;

This commit updates all the places within the gdb/cli directory where we
cast NULL during assignment, removing the cast.

gdb/ChangeLog:

	* cli/cli-decode.c (find_cmd): Remove cast of NULL pointer.
2015-09-04 16:50:20 +01:00
Andrew Burgess be90335825 gdb: Remove casts of NULL during assignment.
In the following code:

    struct symbol *wsym = (struct symbol *) NULL;

the cast of NULL is redundant, it adds noise, and is just one more thing
to change if the type of wsym ever changes.  There are a relatively
small number of places in gdb where the above code pattern is used.
Usually the cast is removed like this:

    struct symbol *wsym = NULL;

This commit updates all the places within the gdb/ directory where we
cast NULL during assignment, removing the cast.

gdb/ChangeLog:

	* c-valprint.c (print_unpacked_pointer): Remove cast of NULL
	pointer.
	* dbxread.c (dbx_end_psymtab): Likewise.
	* gnu-nat.c (gnu_write_inferior): Likewise.
	* mdebugread.c (cross_ref): Likewise.
	* p-valprint.c (pascal_val_print): Likewise.
	* xcoffread.c (xcoff_end_psymtab): Likewise.
2015-09-04 16:49:54 +01:00
Yao Qi 02f024f9a5 Mention multi-arch debugging support in NEWS
gdb:

2015-09-04  Yao Qi  <yao.qi@linaro.org>

	* NEWS: Mention the aarch64 multi-arch debugging support.
2015-09-04 15:27:52 +01:00
Pierre-Marie de Rodat cd7c1778e7 [Ada] Make string_char_type a true TYPE_CODE_CHAR type in Ada
Before this change, trying to call an overloaded function with at least
one character literal in argument would fail.  For instance, given these
two functions:

   function F (C : Character) return Integer is
   begin
      return Character'Pos (C);
   end F;

   function F (I : Integer) return Integer is
   begin
      return -I;
   end F;

We would get the following GDB session:

    (gdb) p f('A')
    $1 = -65
    (gdb) p f(1)
    $1 = -1

This is wrong because the first call should select the first F function
and thus return 65.

The root problem is that ada-lang.c:ada_language_arch_info stores in
string_char_type a type whose code is TYPE_CODE_INT instead of
TYPE_CODE_CHAR.  As a result, all parsed character literals are turned
into integer values and during overload matching, the TYPE_CODE_CHAR
formal rejects the TYPE_CODE_INT actual.

This change turns string_char_type into a true TYPE_CODE_CHAR type in
ada-lang.c so that we have instead the expected:

    (gdb) p f('A')
    $1 = 65

gdb/ChangeLog:

	* ada-lang.c (ada_language_arch_info): Create a TYPE_CODE_CHAR
	type instead of a TYPE_CODE_INT one for the string_char_type
	and the ada_primitive_type_char types.

gdb/testsuite/ChangeLog:

	* gdb.ada/funcall_char.exp: New testcase.
	* gdb.ada/funcall_char/foo.adb: New file.

Tested on x86_64-linux, no regression.
2015-09-03 17:52:05 +02:00
Yao Qi 39edd165f4 [aarch64] Check region OK for HW watchpoint in GDBserver
Nowadays, if user requests HW watchpoint to monitor a large memory area
or unaligned area, aarch64 GDB will split into multiple aligned areas,
and use multiple debugging registers to watch them.  However, the
registers are not updated in a transaction way.  GDBserver doesn't revert
updates in previous iterations if some debugging registers fail to update
due to some reason, like no free debugging registers available, in the
latter iteration.  For example, if we have a char buf[34], and watch buf
in gdb,

(gdb) watch buf
Hardware watchpoint 2: buf
(gdb) c
Continuing.
infrun: clear_proceed_status_thread (Thread 13466)
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: step-over queue now empty
infrun: resuming [Thread 13466] for step-over
Sending packet: $m410838,22#35...Packet received: 00000000000000000000000000000000000000000000000000000000000000000000
infrun: skipping breakpoint: stepping past insn at: 0x400524
infrun: skipping breakpoint: stepping past insn at: 0x400524
Sending packet: $Z2,410838,22#80...Packet received: E01 <----- [1]
Packet Z2 (write-watchpoint) is supported
Sending packet: $Z0,7fb7fe0a8c,4#43...Packet received: OK
Warning:
Could not insert hardware watchpoint 2.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

GDB receives E01 for Z2 packet [1] but GDBserver updates the debugging
register status,

insert_point (addr=0x00410838, len=34, type=hw-write-watchpoint):
	BREAKPOINTs:
	BP0: addr=0x0, ctrl=0x00000000, ref.count=0
	BP1: addr=0x0, ctrl=0x00000000, ref.count=0
	BP2: addr=0x0, ctrl=0x00000000, ref.count=0
	BP3: addr=0x0, ctrl=0x00000000, ref.count=0
	BP4: addr=0x0, ctrl=0x00000000, ref.count=0
	BP5: addr=0x0, ctrl=0x00000000, ref.count=0
	WATCHPOINTs:
	WP0: addr=0x410850, ctrl=0x00001ff5, ref.count=1
	WP1: addr=0x410848, ctrl=0x00001ff5, ref.count=1
	WP2: addr=0x410840, ctrl=0x00001ff5, ref.count=1
	WP3: addr=0x410838, ctrl=0x00001ff5, ref.count=1

four debugging registers can not monitor 34-byte long area, so the last
iteration of updating debugging register state fails but previous
iterations succeed.  This makes GDB think no HW watchpoint is inserted
but some debugging registers are used.

This problem was exposed by "watch buf" gdb.base/watchpoint.exp with
aarch64 GDBserver debugging arm 32-bit program.  The buf is 30-byte long
but 4-byte aligned, and four debugging registers can't cover 34-byte
(extend 4 bytes to be 8-byte aligned) area.  However, this problem
does exist on non-multi-arch debugging scenario as well.

This patch moves code in aarch64_linux_region_ok_for_hw_watchpoint to
aarch64_linux_region_ok_for_watchpoint in nat/aarch64-linux-hw-point.c.
Then, checks with aarch64_linux_region_ok_for_watchpoint, like what we
are doing in GDB.  If the region is OK, call aarch64_handle_watchpoint.

Regression tested on aarch64 with both 64-bit program and 32-bit
program.  Some fails in gdb.base/watchpoint.exp are fixed.

gdb:

2015-09-03  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_linux_region_ok_for_hw_watchpoint):
	Move code to aarch64_linux_region_ok_for_watchpoint.  Call
	aarch64_linux_region_ok_for_watchpoint.
	* nat/aarch64-linux-hw-point.c (aarch64_linux_region_ok_for_watchpoint):
	New function.
	* nat/aarch64-linux-hw-point.h (aarch64_linux_region_ok_for_watchpoint):
	Declare it.

gdb/gdbserver:

2015-09-03  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_insert_point): Call
	aarch64_handle_watchpoint if aarch64_linux_region_ok_for_watchpoint
	returns true.
2015-09-03 14:01:49 +01:00
Patrick Palka 6c214e7cb3 Use gdbarch obstack to allocate the TYPE_NAME string in arch_type
Since the type whose name is being set is now being allocated on the
gdbarch obstack, we should allocate its TYPE_NAME on the obstack too.
This reduces the number of individual valgrind warnings for the command
"gdb gdb" from ~300 to ~150.

Tested on x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* gdb_obstack.h (obstack_strdup): Declare.
	* gdb_obstack.c (obstack_strdup): Define.
	* gdbarch.sh (gdbarch_obstack_strdup): Declare and define.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbtypes.c (arch_type): Use gdbarch_obstack_strdup.
2015-09-02 20:53:33 -04:00
Patrick Palka eed8b28a07 Update documentation of function copy_type_recursive
Following commit 8f57eec2fb ("Use gdbarch obstack to allocate types in
alloc_type_arch") it is no longer the case that the type returned by
copy_type_recursive is allocated using malloc.  Because the function
uses alloc_type_arch internally, the new type is now allocated on the
gdbarch associated with the type, and is thus owned by that gdbarch.

gdb/ChangeLog:

	* gdbtypes.c (copy_type_recursive): Update documentation.
2015-09-02 20:50:46 -04:00
Sergio Durigan Junior 73c6b4756a Initialize yet another variable to silence GCC warning from last-but-one commit
Yet another BuildBot e-mail, yet another breakage on RHEL-7.1 s390x
(which uses an older GCC).  This time,
solib-svr4.c:solib_event_probe_action has the probe_argc variable,
which is now inside a TRY..CATCH and therefore needs to be
initialized.  Pushed as obvious.

gdb/ChangeLog:
2015-09-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* solib-svr4.c (solib_event_probe_action): Initialize 'probe_argc'
	as zero.
2015-09-02 00:46:43 -04:00
Sergio Durigan Junior ad1c917a79 Initialize variable and silence GCC warning from last commit
BuildBot e-mailed me to let me know that my last commit broke GDB on
RHEL-7.1 s390x.  On solib-svr4.c:svr4_handle_solib_event, 'val' now
needs to be initialized as NULL because it is inside a TRY..CATCH
block.  This patch does that.  Pushed as obvious.

gdb/ChangeLog:
2015-09-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* solib-svr4.c (svr4_handle_solib_event): Initialize 'val' as NULL
2015-09-02 00:34:22 -04:00
Sergio Durigan Junior 3bd7e5b7ee Catching errors on probes-based dynamic linker interface
This patch is intended to make the interaction between the
probes-based dynamic linker interface and the SystemTap SDT probe code
on GDB more robust.  It does that by wrapping the calls to the probe
API with TRY...CATCH'es, so that any exception thrown will be caught
and handled properly.

The idea for this patch came from
<https://bugzilla.redhat.com/show_bug.cgi?id=1196181>, which is a bug
initially filed against Fedora GDB (but now under Fedora GLIBC).  This
bug happens on armhfp (although it could happen on other targets as
well), and is triggered because GCC generates a strange argument for
one of the probes used by GDB in the dynamic linker interface.  As can
be seen in the bug, this argument is "-4@.L1052".

I don't want to discuss the reasons for this argument to be there
(this discussion belongs to the bug, or to another thread), but GDB
could definitely do a better error handling here.  Currently, one sees
the following message when there is an error in the probes-based
dynamic linker interface:

  (gdb) run
  Starting program: /bin/inferior
  warning: Probes-based dynamic linker interface failed.
  Reverting to original interface.

  Cannot parse expression `.L976 4@r4'.
  (gdb)

Which means that one needs to explicitly issue a "continue" command to
make GDB continue running the inferior, even though this error is not
fatal and GDB will fallback to the old interface automatically.

This is where this patch helps: it makes GDB still print the necessary
warnings or error messages, but it *also* does not stop the inferior
unnecessarily.

I have tested this patch on the systems where this error happens, but
I could not come up with a way to create a testcase for it.
Nevertheless, it should be straightforward to see that this patch does
improve the current situation.

gdb/ChangeLog:
2015-09-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* solib-svr4.c (solib_event_probe_action): Call
	get_probe_argument_count using TRY...CATCH.
	(svr4_handle_solib_event): Likewise, for evaluate_probe_argument.
2015-09-02 00:13:06 -04:00
Sergio Durigan Junior f469e8ce11 Improve error reporting when handling SystemTap SDT probes
This patch improves the error reporting when handling SystemTap SDT
probes.  "Handling", in this case, mostly means "parsing".

On gdb/probe.h, only trivial changes on functions' comments in order
to explicitly mention that some of them can throw exceptions.  This is
just to make the API a bit more clear.

On gdb/stap-probe.c, I have s/internal_error/error/ on two functions
that are responsible for parsing specific bits of the probes'
arguments: stap_get_opcode and stap_get_expected_argument_type.  It is
not correct to call internal_error on such situations because it is
not really GDB's fault if the probes have malformed arguments.  I also
improved the error reported on stap_get_expected_argument_type by also
including the probe name on it.

Aside from that, and perhaps most importantly, I added a check on
stap_get_arg to make sure that we don't try to extract an argument
from a probe that has no arguments.  This check issues an
internal_error, because it really means that GDB is doing something it
shouldn't.

Although it can be considered almost trivial, and despite the fact
that I am the maintainer for this part of the code, I am posting this
patch for review.  I will wait a few days, and if nobody has anything
to say, I will go ahead and push it.

gdb/ChangeLog:
2015-09-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* probe.h (struct probe_ops) <get_probe_argument_count,
	evaluate_probe_argument, enable_probe, disable_probe>: Mention in
	the comment that the function can throw an exception.
	(get_probe_argument_count): Likewise.
	(evaluate_probe_argument): Likewise.
	* stap-probe.c (stap_get_opcode): Call error instead of
	internal_error.
	(stap_get_expected_argument_type): Likewise.  Add argument
	'probe'.  Improve error message by mentioning the probe's name.
	(stap_parse_probe_arguments): Adjust call to
	stap_get_expected_argument_type.
	(stap_get_arg): Add comment.  Assert that 'probe->args_parsed' is
	not zero.  Call internal_error if GDB requests an argument but the
	probe has no arguments.
2015-09-02 00:11:30 -04:00
Pierre-Marie de Rodat dc5c874652 [Ada] Fix completion for multiple function matches
Before this change, trying to complete an expression ending with an
ambiguous function name (i.e. for which there are multiple matches)
would display a menu with a prompt for the user to pick one. For
instance:

    (gdb) p func<tab>Multiple matches for func
    [0] cancel
    [1] pack2.func at pack2.adb:5
    [2] pack.func at pack.adb:5
    >

This is not user friendly and actually triggered a segmentation fault
after the user did pick one. It is not clear whether the segmentation
fault needs a separate fix, but this is the only known case which
exhibits it at the moment, and this case must be fixed itself.

The problem lies in ada-lang.c (ada_resolve_function): when we got
multiple matches, we should not display the menu if we are in completion
mode. This patch adjusts the corresponding condition accordingly.

gdb/ChangeLog:

	* ada-lang.c (ada_resolve_function): Do not ask the user what
	match to use when in completion mode.

gdb/testsuite/ChangeLog:

	* gdb.ada/complete.exp: Add "pck.ambiguous_func" to the relevant
	expected outputs.  Add two testcases for completing ambiguous
	functions.
	* gdb.ada/complete/aux_pck.adb: New file.
	* gdb.ada/complete/aux_pck.ads: New file.
	* gdb.ada/complete/foo.adb: Pull Aux_Pck and call the two
	Ambiguous_Func functions.
	* gdb.ada/complete/pck.ads: Add an Ambiguous_Func function.
	* gdb.ada/complete/pck.adb: Likewise.

Tested on x86_64-linux, no regression.
2015-09-01 14:54:19 +02:00
Andrew Burgess 136765eab1 gdb/tui: Make local variable const.
Small clean up to make a local variable const and remove a cast of NULL.

gdb/ChangeLog:

	* tui/tui-data.c (tui_win_name): Make local variable const, remove
	cast of NULL.
2015-08-31 11:57:44 +01:00
Max Filippov 90b81c5f15 xtensa: initialize call_abi in xtensa_tdep
Use XSHAL_ABI value provided by xtensa-config.h to correctly initialize
xtensa_tdep.call_abi
This fixes calls to functions from GDB that otherwise fail with the
following assertion in call0 configuration:

  gdb/regcache.c:602: internal-error: regcache_raw_read: Assertion
  `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed.

2015-08-31  Max Filippov  <jcmvbkbc@gmail.com>
gdb/
	* xtensa-tdep.h (XTENSA_GDBARCH_TDEP_INSTANTIATE): Initialize
	call_abi using XSHAL_ABI macro.
2015-08-31 11:59:02 +03:00
Doug Evans 1cd36e5408 symtab.h (struct symbol): Tweak comment.
gdb/ChangeLog:

	* symtab.h (struct symbol): Tweak comment.
2015-08-29 17:10:58 -07:00
Patrick Palka 2fee770894 Revert "Use gdbarch obstack to allocate the TYPE_NAME string in arch_type"
This patch manually modified the autogenerated files gdbarch.[ch] instead of
going through gdbarch.sh.

This reverts commit aa78b3b28a.
2015-08-29 18:24:29 -04:00
Patrick Palka aa78b3b28a Use gdbarch obstack to allocate the TYPE_NAME string in arch_type
Since the type whose name is being set is now being allocated on the
gdbarch obstack, we should allocate its TYPE_NAME on the obstack too.
This reduces the number of individual valgrind warnings for the command
"gdb gdb" from ~300 to ~150.

Tested on x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* gdbarch.h (gdbarch_obstack_strdup): Declare.
	* gdbarch.c (gdbarch_obstack_strdup): Define.
	* gdbtypes.c (arch_type): Use it.
2015-08-29 08:53:08 -04:00
Patrick Palka 8f57eec2fb Use gdbarch obstack to allocate types in alloc_type_arch
For the command "gdb gdb" valgrind currently reports 100s of individual
memory leaks, 500 of which originate solely out of the function
alloc_type_arch.  This function allocates a "struct type" associated
with the given gdbarch using malloc but apparently the types allocated
by this function are never freed.

This patch fixes these leaks by making the function alloc_type_arch
allocate these gdbarch-associated types on the gdbarch obstack instead
of on the general heap.  Since, from what I can tell, the types
allocated by this function are all fundamental "wired-in" types, such
types would not benefit from more granular memory management anyway.
They would likely live as long as the gdbarch is alive so allocating
them on the gdbarch obstack makes sense.

With this patch, the number of individual vargrind warnings emitted for
the command "gdb gdb" drops from ~800 to ~300.

Tested on x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* gdbtypes.c (alloc_type_arch): Allocate the type on the given
	gdbarch obstack instead of on the heap.  Update commentary
	accordingly.
2015-08-29 08:52:50 -04:00
Joel Brobecker 38eebd71ba Document the GDB 7.10 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 7.10 released.
2015-08-28 17:40:54 -04:00
Simon Marchi d63dd61e78 Update NEWS entry about non-8-bits addressable memory 2015-08-28 15:35:47 -04:00
Ulrich Weigand 6f05925675 Revert: solib_global_lookup: Fetch arch from objfile.
solib_ops are installed as a property of the inferior gdbarch,
so they need to be systematically looked up via that architecture,
not some objfile architecture.

ChangeLog:

	Revert:
	2014-11-06  Doug Evans  <xdje42@gmail.com>
        * solib.c (solib_global_lookup): Fetch arch from objfile,
        not target_gdbarch.
2015-08-28 19:04:56 +02:00
Ulrich Weigand 70987a9256 Fix incorrect ChangeLog dates. 2015-08-28 19:04:12 +02:00
Simon Marchi 6711b7f8d5 Fix ChangeLog entries starting with "Likewise"
The first lines of these ChangeLog entries are "Likewise"... it doesn't
make much sense.
2015-08-27 13:48:47 -04:00
Ulrich Weigand ef36892e85 [Cell/B.E.] Fix wrong relocation for TLS variable offset
When debugging Cell/B.E. code, the cross-architecture frame unwinding
works by accessing data structures refered to by a thread-local variable
in the inferior.  While accessing this variable via minimal symbol,
code would use BMSYMBOL_VALUE_ADDRESS to determine the offset of the
variable in the thread-local storage block.

This is incorrect, since it adds any relocation offset of the shared
library defining the TLS variable.  That offset would be OK when
accessing the initial copy present in the .tbss section, but it must
not be applied to the offset of the variable in the TLS block at
runtime.  Depending on whether or not the libspe2.so library was
prelinked, access to the variable would fail due to the incorrectly
relocated offset.

ChangeLog:

	* ppc-linux-tdep.c (ppc_linux_spe_context_lookup): Do not
	attempt to relocate a TLS variable offset.
2015-08-27 19:31:04 +02:00
Ulrich Weigand 791bb1f4a6 [Cell/B.E.] Make parse_spufs_run more robust
With recent changes to inferior handling, parse_spufs_run needs to be
more careful in assumptions it makes.  In particular, this patch:

- Bails out early if the current inferior has not yet been registered
  (e.g. during fork procession) to avoid assertion failures in register
  cache code.

- Sets inferior_ptid to the current ptid while calling target_read_memory
  to make sure the correct process is accessed if parse_spufs_run is
  called early when inferior_ptid has not yet been switched by the caller.

ChangeLog:

	* spu-multiarch.c (parse_spufs_run): Bail out if inferior is not
	registered yet.  Set inferior_ptid while calling target_read_memory.
2015-08-27 19:27:40 +02:00
Ulrich Weigand 1db33b5a02 Detect SW breakpoints in Cell/B.E. combined debugging
The Linux target and gdbserver now check the siginfo si_code
reported on a SIGTRAP to detect whether the trap indicates
a software breakpoint was hit.

Unfortunately, on Cell/B.E., the kernel uses an si_code value
of TRAP_BRKPT when a SW breakpoint was hit in PowerPC code,
but a si_code value of SI_KERNEL when a SW breakpoint was
hit in SPU code.

This patch updates Linux target and gdbserver to accept both
si_code values to indicate SW breakpoint on PowerPC.

ChangeLog:

	* nat/linux-ptrace.h (GDB_ARCH_TRAP_BRKPT): Replace by ...
	(GDB_ARCH_IS_TRAP_BRKPT): ... this.  Add __powerpc__ case.
	* linux-nat.c (check_stopped_by_breakpoint): Use
	GDB_ARCH_IS_TRAP_BRKPT instead of GDB_ARCH_TRAP_BRKPT.

gdbserver/ChangeLog:

	* linux-low.c (check_stopped_by_breakpoint): Use
	GDB_ARCH_IS_TRAP_BRKPT instead of GDB_ARCH_TRAP_BRKPT.
2015-08-27 19:26:31 +02:00
Ulrich Weigand e0fd7c47bd Fix assertion failure in linux-thread-db
Since we are no longer using thread events by default in linux-thread-db,
the find_new_threads_once routine contains an assertion that it should
never be called on a live inferior unless using thread events:
  gdb_assert (!target_has_execution || thread_db_use_events ());

However, there is a code path from thread_db_get_thread_local_address
that will in fact call find_new_threads_once in some scenarios.  In
particular, this is currently always triggered when starting up any
Cell/B.E. combined exeuctable.

To fix this, this patch removes the call to thread_db_find_new_threads_1
when the current thread was not yet detected.  In its place, we now just
call thread_from_lwp to detect this one thread if necessary.

ChangeLog:

	* linux-thread-db.c (thread_db_get_thread_local_address): If the
	thread was not yet discovered, use thread_from_lwp instead of
	calling thread_db_find_new_threads_1.
2015-08-27 19:12:49 +02:00
Ulrich Weigand 4e83a1e776 Report UNRESOLVED on failures while detecting Cell/B.E.
The gdb.cell testcases use the predicate skip_cell_tests defined in
lib/cell.exp to determine whether Cell/B.E. test cases ought to be
run. This tests verifies that we have a toolchain that supports
generating combined Cell/B.E. binaries, and that the target machine
actually is a Cell/B.E.

In order to do so, a small test program is built and run (under the
debugger).  Any failure is taken as a sign that we don't have a
Cell/B.E. machine and the tests are to be skipped.

This has the unfortunate effect that a serious bug in GDB that causes
internal compiler errors even on the trivial test program does not
lead to any failures in the testsuite, since now all gdb.cell test
are simply skipped.

This patch changes skip_cell_tests to at least report UNRESOLVED
in cases where execution of the test program fails in unexpected
ways.

testsuite/ChangeLog:

	* lib/cell.exp (skip_cell_tests): Report UNRESOLVED on unexpected
	failures to run the test program under GDB.
2015-08-27 19:06:03 +02:00
Simon Marchi f5cdf4989e Fix inverted statements in m88k_analyze_prologue
These two statements were inverted by mistake in commit "Replace some
xmalloc-family functions with XNEW-family ones".  It obviously doesn't
make sense to have them in this order, which is why I am pushing this as
obvious.

gdb/ChangeLog:

	* m88k-tdep.c (m88k_analyze_prologue): Fix inverted allocation
	statements.
2015-08-27 09:47:14 -04:00
Simon Marchi 5952e15788 Remove duplicate ChangeLog entry 2015-08-27 09:32:19 -04:00
Simon Marchi fd2ae5d6a3 Document non-8-bits addressable memory support in NEWS
I think it would be a good idea to document that gdb now has (basic)
support to read/write memory on architectures with non-8-bits memory.
Hopefully somebody will see it and say "Hey!  We can now (more easily)
port GDB to our strange DSP that has 32-bits-addressable memory!" and do
it.

gdb/ChangeLog:

	* NEWS: Document support for non-8-bits addressable memory.
2015-08-27 09:30:00 -04:00
Pedro Alves ab29043019 gdbserver/proc-service.c: bogus return value conversion
Building in C++ mode shows:

   int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
       ^
  src/gdb/gdbserver/proc-service.c:93:64: error: invalid conversion from ‘int’ to ‘ps_err_e’ [-fpermissive]
     return write_inferior_memory ((unsigned long) addr, buf, size);
								  ^

It only works today by accident, write_inferior_memory does not return
a ps_err_e.

gdb/gdbserver/ChangeLog:
2015-08-27  Pedro Alves  <palves@redhat.com>

	* proc-service.c (ps_pdwrite): Return PS_ERR/PS_OK explicily.
2015-08-27 13:37:01 +01:00
Pedro Alves 14d8814778 gdb: Drop use of obsolete AC_TYPE_SIGNAL
Since we're using sighandler_t, nothing else refers to RETSIGTYPE in
gdb.

(Actually, given gdb/remote.c has been assuming signal handlers return
void for a long time, we could have gotten get rid of this even
without gnulib's sighandler_t.)

gdb/ChangeLog:
2015-08-27  Pedro Alves  <palves@redhat.com>

	* configure.ac: Remove AC_TYPE_SIGNAL call.
	* configure, config.in: Regenerate.
2015-08-27 13:26:23 +01:00
Pedro Alves a40805d4a7 gdb: Use sighandler_t everywhere
This fixes 14 build errors like these in C++ mode:

 src/gdb/extension.c: In function ‘void install_sigint_handler(const signal_handler*)’:
 src/gdb/extension.c:698:41: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t {aka void (*)(int)}’ [-fpermissive]
    signal (SIGINT, handler_state->handler);
					  ^
 In file included from build-gnulib/import/signal.h:52:0,
		  from ../../src/gdb/extension.c:24:
 /usr/include/signal.h:102:23: error:   initializing argument 2 of ‘void (* signal(int, __sighandler_t))(int)’ [-fpermissive]
  extern __sighandler_t signal (int __sig, __sighandler_t __handler)
			^

Instead of this everywhere:

 -  RETSIGTYPE (*handle_sigint_for_compare) () = handle_sigint;
 +  RETSIGTYPE (*handle_sigint_for_compare) (int) = handle_sigint;

Use sighandler_t (a GNU extension).  That's OK to use unconditionaly
because gnulib's signal.h replacement makes sure that it is available.

gdb/ChangeLog:
2015-08-27  Pedro Alves  <palves@redhat.com>

	* cp-support.c (gdb_demangle): Use sighandler_t.  Remove cast.
	* extension-priv.h: Include signal.h.
	(struct signal_handler) <handler>: Change type to sighandler_t.
	* extension.c (install_gdb_sigint_handler): Use sighandler_t.
	* inflow.c (sigint_ours, sigquit_ours): Change type to
	sighandler_t.
	(child_terminal_inferior): Remove casts.
	(child_terminal_ours_1, new_tty): Use sighandler_t.  Remove casts.
	(osig): Change type to sighandler_t.
	* nto-procfs.c (ofunc): Change type to sighandler_t.
	(procfs_wait): Remove casts.
	* remote-m32r-sdi.c (m32r_wait, m32r_load): Use sighandler_t.
	* remote-sim.c (gdbsim_wait): Use sighandler_t.
	* utils.c (wait_to_die_with_timeout): Use sighandler_t.
2015-08-27 13:26:23 +01:00
Pedro Alves 0750520d89 Import the "signal-h" module from gnulib
This gives us a signal.h replacement that makes sure the sighandler_t
typedef (a GNU extension) is always available.  A follow up patch will
make use of this.

gdb/ChangeLog:
2015-08-27  Pedro Alves  <palves@redhat.com>

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add signal-h.
	* gnulib/aclocal.m4: Renegerate.
	* gnulib/config.in: Renegerate.
	* gnulib/configure: Renegerate.
	* gnulib/import/Makefile.am: Update.
	* gnulib/import/Makefile.in: Regenerate.
	* gnulib/import/m4/gnulib-cache.m4: Update.
	* gnulib/import/m4/gnulib-comp.m4: Update.
	* gnulib/import/m4/signal_h.m4: New file.
	* gnulib/import/signal.in.h: New file.
2015-08-27 13:26:22 +01:00
Pedro Alves 7541ab0369 Fix ChangeLog entry date and mention gdb/18804 2015-08-27 13:09:39 +01:00
Pedro Alves a5c0808e22 gdb: remove packet size limit
The remote packet buffer size is currently capped to 16384 mostly for
historical reasons, related to use of alloca.  Stop using alloca and
remove the limitation.

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-27  Pedro Alves  <palves@redhat.com>

	* remote.c (DEFAULT_MAX_MEMORY_PACKET_SIZE)
	(MIN_MEMORY_PACKET_SIZE): New.
	(MAX_REMOTE_PACKET_SIZE, MIN_REMOTE_PACKET_SIZE): Delete.
	(get_memory_packet_size): Adjust.  No longer limit the max packet
	size.
	(set_memory_packet_size): Adjust, and remove dead code.
	(remote_check_symbols): Use xmalloc and a cleanup instead of
	alloca.
	(remote_packet_size): No longer cap the packet size.
	(putpkt_binary): Use xmalloc and a cleanup instead of alloca.
2015-08-27 13:03:15 +01:00
Luis Machado cdaec3f3e7 Mention language in compile error message
This patch improves one of the compile error messages by mentioning the
language.

Before - No compiler support for this language.
After  - No compiler support for language <language>.

gdb/ChangeLog:

2015-08-26  Luis Machado  <lgustavo@codesourcery.com>

	* compile/compile.c (compile_to_object): Mention language in
	error message.
2015-08-27 02:00:16 -03:00
Luis Machado 8ce7415353 Force language to C in gdb.compile/compile-ifunc.exp
Due to the lack of debug information in the binary, GDB is unable to figure
out what language is being used.  This may be a problem when doing remote
debugging and the binary stops at the entry point containing asm code.

In this case GDB will switch to asm as current language and will not switch
back to C when it reaches main, which in turn causes the compile feature check
to malfunction.

This is solved by forcing the language to C after reaching main.

gdb/testsuite/ChangeLog:

2015-08-26  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.compile/compile-ifunc.exp (with_test_prefix): Force language
	to C.
2015-08-27 01:49:05 -03:00
Patrick Palka e9756d52be Unset attach_flag when running a new process
We currently set attach_flag when attaching to a process, so we should
make sure to unset it when forking a new process.  Otherwise attach_flag
would remain set after forking, if the previous process associated with
the inferior was attached to.

gdb/ChangeLog:

	* target.c (target_pre_inferior): Unset attach_flag.

gdb/testsuite/ChangeLog:

	* gdb.base/run-after-attach.exp: New test file.
	* gdb.base/run-after-attach.c: New test file.
2015-08-26 20:50:43 -04:00
Simon Marchi 1dc7a62350 Fix gdbarch.c build error
I made a mistake while handling my previous patch.  A change in
gdbarch causes a build failure.

gdb/ChangeLog:

	* gdbarch.sh (append_name): Fix type in XRESIZEVEC.
	* gdbarch.c: Re-generate.
2015-08-26 17:31:47 -04:00
Simon Marchi 8d7493201c Replace some xmalloc-family functions with XNEW-family ones
This patch is part of the make-gdb-buildable-in-C++ effort.  The idea is
to change some calls to the xmalloc family of functions to calls to the
equivalents in the XNEW family.  This avoids adding an explicit cast, so
it keeps the code a bit more readable.  Some of them also map relatively
well to a C++ equivalent (XNEW (struct foo) -> new foo), so it will be
possible to do scripted replacements if needed.

I only changed calls that were obviously allocating memory for one or
multiple "objects".  Allocation of variable sizes (such as strings or
buffer handling) will be for later (and won't use XNEW).

  - xmalloc (sizeof (struct foo)) -> XNEW (struct foo)
  - xmalloc (num * sizeof (struct foo)) -> XNEWVEC (struct foo, num)
  - xcalloc (1, sizeof (struct foo)) -> XCNEW (struct foo)
  - xcalloc (num, sizeof (struct foo)) -> XCNEWVEC (struct foo, num)
  - xrealloc (p, num * sizeof (struct foo) -> XRESIZEVEC (struct foo, p, num)
  - obstack_alloc (ob, sizeof (struct foo)) -> XOBNEW (ob, struct foo)
  - obstack_alloc (ob, num * sizeof (struct foo)) -> XOBNEWVEC (ob, struct foo, num)
  - alloca (sizeof (struct foo)) -> XALLOCA (struct foo)
  - alloca (num * sizeof (struct foo)) -> XALLOCAVEC (struct foo, num)

Some instances of xmalloc followed by memset to zero the buffer were
replaced by XCNEW or XCNEWVEC.

I regtested on x86-64, Ubuntu 14.04, but the patch touches many
architecture-specific files.  For those I'll have to rely on the
buildbot or people complaining that I broke their gdb.

gdb/ChangeLog:

	* aarch64-linux-nat.c (aarch64_add_process): Likewise.
	* aarch64-tdep.c (aarch64_gdbarch_init): Likewise.
	* ada-exp.y (write_ambiguous_var): Likewise.
	* ada-lang.c (resolve_subexp): Likewise.
	(user_select_syms): Likewise.
	(assign_aggregate): Likewise.
	(ada_evaluate_subexp): Likewise.
	(cache_symbol): Likewise.
	* addrmap.c (allocate_key): Likewise.
	(addrmap_create_mutable): Likewise.
	* aix-thread.c (sync_threadlists): Likewise.
	* alpha-tdep.c (alpha_push_dummy_call): Likewise.
	(alpha_gdbarch_init): Likewise.
	* amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise.
	* arm-linux-nat.c (arm_linux_add_process): Likewise.
	* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
	* arm-tdep.c (push_stack_item): Likewise.
	(arm_displaced_step_copy_insn): Likewise.
	(arm_gdbarch_init): Likewise.
	(_initialize_arm_tdep): Likewise.
	* avr-tdep.c (push_stack_item): Likewise.
	* ax-general.c (new_agent_expr): Likewise.
	* block.c (block_initialize_namespace): Likewise.
	* breakpoint.c (alloc_counted_command_line): Likewise.
	(update_dprintf_command_list): Likewise.
	(parse_breakpoint_sals): Likewise.
	(decode_static_tracepoint_spec): Likewise.
	(until_break_command): Likewise.
	(clear_command): Likewise.
	(update_global_location_list): Likewise.
	(get_breakpoint_objfile_data) Likewise.
	* btrace.c (ftrace_new_function): Likewise.
	(btrace_set_insn_history): Likewise.
	(btrace_set_call_history): Likewise.
	* buildsym.c (add_symbol_to_list): Likewise.
	(record_pending_block): Likewise.
	(start_subfile): Likewise.
	(start_buildsym_compunit): Likewise.
	(push_subfile): Likewise.
	(end_symtab_get_static_block): Likewise.
	(buildsym_init): Likewise.
	* cli/cli-cmds.c (source_command): Likewise.
	* cli/cli-decode.c (add_cmd): Likewise.
	* cli/cli-script.c (build_command_line): Likewise.
	(setup_user_args): Likewise.
	(realloc_body_list): Likewise.
	(process_next_line): Likewise.
	(copy_command_lines): Likewise.
	* cli/cli-setshow.c (do_set_command): Likewise.
	* coff-pe-read.c (read_pe_exported_syms): Likewise.
	* coffread.c (coff_locate_sections): Likewise.
	(coff_symtab_read): Likewise.
	(coff_read_struct_type): Likewise.
	* common/cleanups.c (make_my_cleanup2): Likewise.
	* common/common-exceptions.c (throw_it): Likewise.
	* common/filestuff.c (make_cleanup_close): Likewise.
	* common/format.c (parse_format_string): Likewise.
	* common/queue.h (DEFINE_QUEUE_P): Likewise.
	* compile/compile-object-load.c (munmap_list_add): Likewise.
	(compile_object_load): Likewise.
	* compile/compile-object-run.c (compile_object_run): Likewise.
	* compile/compile.c (append_args): Likewise.
	* corefile.c (specify_exec_file_hook): Likewise.
	* cp-support.c (make_symbol_overload_list): Likewise.
	* cris-tdep.c (push_stack_item): Likewise.
	(cris_gdbarch_init): Likewise.
	* ctf.c (ctf_trace_file_writer_new): Likewise.
	* dbxread.c (init_header_files): Likewise.
	(add_new_header_file): Likewise.
	(init_bincl_list): Likewise.
	(dbx_end_psymtab): Likewise.
	(start_psymtab): Likewise.
	(dbx_end_psymtab): Likewise.
	* dcache.c (dcache_init): Likewise.
	* dictionary.c (dict_create_hashed): Likewise.
	(dict_create_hashed_expandable): Likewise.
	(dict_create_linear): Likewise.
	(dict_create_linear_expandable): Likewise.
	* dtrace-probe.c (dtrace_process_dof_probe): Likewise.
	* dummy-frame.c (register_dummy_frame_dtor): Likewise.
	* dwarf2-frame-tailcall.c (cache_new_ref1): Likewise.
	* dwarf2-frame.c (dwarf2_build_frame_info): Likewise.
	(decode_frame_entry_1): Likewise.
	* dwarf2expr.c (new_dwarf_expr_context): Likewise.
	* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
	* dwarf2read.c (dwarf2_has_info): Likewise.
	(create_signatured_type_table_from_index): Likewise.
	(dwarf2_read_index): Likewise.
	(dw2_get_file_names_reader): Likewise.
	(create_all_type_units): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(init_tu_and_read_dwo_dies): Likewise.
	(init_cutu_and_read_dies): Likewise.
	(create_all_comp_units): Likewise.
	(queue_comp_unit): Likewise.
	(inherit_abstract_dies): Likewise.
	(read_call_site_scope): Likewise.
	(dwarf2_add_field): Likewise.
	(dwarf2_add_typedef): Likewise.
	(dwarf2_add_member_fn): Likewise.
	(attr_to_dynamic_prop): Likewise.
	(abbrev_table_alloc_abbrev): Likewise.
	(abbrev_table_read_table): Likewise.
	(add_include_dir): Likewise.
	(add_file_name): Likewise.
	(dwarf_decode_line_header): Likewise.
	(dwarf2_const_value_attr): Likewise.
	(dwarf_alloc_block): Likewise.
	(parse_macro_definition): Likewise.
	(set_die_type): Likewise.
	(write_psymtabs_to_index): Likewise.
	(create_cus_from_index): Likewise.
	(dwarf2_create_include_psymtab): Likewise.
	(process_psymtab_comp_unit_reader): Likewise.
	(build_type_psymtab_dependencies): Likewise.
	(read_comp_units_from_section): Likewise.
	(compute_compunit_symtab_includes): Likewise.
	(create_dwo_unit_in_dwp_v1): Likewise.
	(create_dwo_unit_in_dwp_v2): Likewise.
	(read_func_scope): Likewise.
	(process_structure_scope): Likewise.
	(mark_common_block_symbol_computed): Likewise.
	(load_partial_dies): Likewise.
	(dwarf2_symbol_mark_computed): Likewise.
	* elfread.c (elf_symfile_segments): Likewise.
	(elf_read_minimal_symbols): Likewise.
	* environ.c (make_environ): Likewise.
	* eval.c (evaluate_subexp_standard): Likewise.
	* event-loop.c (create_file_handler): Likewise.
	(create_async_signal_handler): Likewise.
	(create_async_event_handler): Likewise.
	(create_timer): Likewise.
	* exec.c (build_section_table): Likewise.
	* fbsd-nat.c (fbsd_remember_child): Likewise.
	* fork-child.c (fork_inferior): Likewise.
	* frv-tdep.c (new_variant): Likewise.
	* gdbarch.sh (gdbarch_alloc): Likewise.
	(append_name): Likewise.
	* gdbtypes.c (rank_function): Likewise.
	(copy_type_recursive): Likewise.
	(add_dyn_prop): Likewise.
	* gnu-nat.c (make_proc): Likewise.
	(make_inf): Likewise.
	(gnu_write_inferior): Likewise.
	* gnu-v3-abi.c (build_gdb_vtable_type): Likewise.
	(build_std_type_info_type): Likewise.
	* guile/scm-param.c (compute_enum_list): Likewise.
	* guile/scm-utils.c (gdbscm_parse_function_args): Likewise.
	* guile/scm-value.c (gdbscm_value_call): Likewise.
	* h8300-tdep.c (h8300_gdbarch_init): Likewise.
	* hppa-tdep.c (hppa_init_objfile_priv_data): Likewise.
	(read_unwind_info): Likewise.
	* ia64-tdep.c (ia64_gdbarch_init): Likewise.
	* infcall.c (dummy_frame_context_saver_setup): Likewise.
	(call_function_by_hand_dummy): Likewise.
	* infcmd.c (step_once): Likewise.
	(finish_forward): Likewise.
	(attach_command): Likewise.
	(notice_new_inferior): Likewise.
	* inferior.c (add_inferior_silent): Likewise.
	* infrun.c (add_displaced_stepping_state): Likewise.
	(save_infcall_control_state): Likewise.
	(save_inferior_ptid): Likewise.
	(_initialize_infrun): Likewise.
	* jit.c (bfd_open_from_target_memory): Likewise.
	(jit_gdbarch_data_init): Likewise.
	* language.c (add_language): Likewise.
	* linespec.c (decode_line_2): Likewise.
	* linux-nat.c (add_to_pid_list): Likewise.
	(add_initial_lwp): Likewise.
	* linux-thread-db.c (add_thread_db_info): Likewise.
	(record_thread): Likewise.
	(info_auto_load_libthread_db): Likewise.
	* m32c-tdep.c (m32c_gdbarch_init): Likewise.
	* m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise.
	* m68k-tdep.c (m68k_gdbarch_init): Likewise.
	* m88k-tdep.c (m88k_analyze_prologue): Likewise.
	* macrocmd.c (macro_define_command): Likewise.
	* macroexp.c (gather_arguments): Likewise.
	* macroscope.c (sal_macro_scope): Likewise.
	* macrotab.c (new_macro_table): Likewise.
	* mdebugread.c (push_parse_stack): Likewise.
	(parse_partial_symbols): Likewise.
	(parse_symbol): Likewise.
	(psymtab_to_symtab_1): Likewise.
	(new_block): Likewise.
	(new_psymtab): Likewise.
	(mdebug_build_psymtabs): Likewise.
	(add_pending): Likewise.
	(elfmdebug_build_psymtabs): Likewise.
	* mep-tdep.c (mep_gdbarch_init): Likewise.
	* mi/mi-main.c (mi_execute_command): Likewise.
	* mi/mi-parse.c (mi_parse_argv): Likewise.
	* minidebug.c (lzma_open): Likewise.
	* minsyms.c (terminate_minimal_symbol_table): Likewise.
	* mips-linux-nat.c (mips_linux_insert_watchpoint): Likewise.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* mn10300-tdep.c (mn10300_gdbarch_init): Likewise.
	* msp430-tdep.c (msp430_gdbarch_init): Likewise.
	* mt-tdep.c (mt_registers_info): Likewise.
	* nat/aarch64-linux.c (aarch64_linux_new_thread): Likewise.
	* nat/linux-btrace.c (linux_enable_bts): Likewise.
	(linux_enable_pt): Likewise.
	* nat/linux-osdata.c (linux_xfer_osdata_processes): Likewise.
	(linux_xfer_osdata_processgroups): Likewise.
	* nios2-tdep.c (nios2_gdbarch_init): Likewise.
	* nto-procfs.c (procfs_meminfo): Likewise.
	* objc-lang.c (start_msglist): Likewise.
	(selectors_info): Likewise.
	(classes_info): Likewise.
	(find_methods): Likewise.
	* objfiles.c (allocate_objfile): Likewise.
	(update_section_map): Likewise.
	* osabi.c (gdbarch_register_osabi): Likewise.
	(gdbarch_register_osabi_sniffer): Likewise.
	* parse.c (start_arglist): Likewise.
	* ppc-linux-nat.c (hwdebug_find_thread_points_by_tid): Likewise.
	(hwdebug_insert_point): Likewise.
	* printcmd.c (display_command): Likewise.
	(ui_printf): Likewise.
	* procfs.c (create_procinfo): Likewise.
	(load_syscalls): Likewise.
	(proc_get_LDT_entry): Likewise.
	(proc_update_threads): Likewise.
	* prologue-value.c (make_pv_area): Likewise.
	(pv_area_store): Likewise.
	* psymtab.c (extend_psymbol_list): Likewise.
	(init_psymbol_list): Likewise.
	(allocate_psymtab): Likewise.
	* python/py-inferior.c (add_thread_object): Likewise.
	* python/py-param.c (compute_enum_values): Likewise.
	* python/py-value.c (valpy_call): Likewise.
	* python/py-varobj.c (py_varobj_iter_next): Likewise.
	* python/python.c (ensure_python_env): Likewise.
	* record-btrace.c (record_btrace_start_replaying): Likewise.
	* record-full.c (record_full_reg_alloc): Likewise.
	(record_full_mem_alloc): Likewise.
	(record_full_end_alloc): Likewise.
	(record_full_core_xfer_partial): Likewise.
	* regcache.c (get_thread_arch_aspace_regcache): Likewise.
	* remote-fileio.c (remote_fileio_init_fd_map): Likewise.
	* remote-notif.c (remote_notif_state_allocate): Likewise.
	* remote.c (demand_private_info): Likewise.
	(remote_notif_stop_alloc_reply): Likewise.
	(remote_enable_btrace): Likewise.
	* reverse.c (save_bookmark_command): Likewise.
	* rl78-tdep.c (rl78_gdbarch_init): Likewise.
	* rx-tdep.c (rx_gdbarch_init): Likewise.
	* s390-linux-nat.c (s390_insert_watchpoint): Likewise.
	* ser-go32.c (dos_get_tty_state): Likewise.
	(dos_copy_tty_state): Likewise.
	* ser-mingw.c (ser_windows_open): Likewise.
	(ser_console_wait_handle): Likewise.
	(ser_console_get_tty_state): Likewise.
	(make_pipe_state): Likewise.
	(net_windows_open): Likewise.
	* ser-unix.c (hardwire_get_tty_state): Likewise.
	(hardwire_copy_tty_state): Likewise.
	* solib-aix.c (solib_aix_new_lm_info): Likewise.
	* solib-dsbt.c (dsbt_current_sos): Likewise.
	(dsbt_relocate_main_executable): Likewise.
	* solib-frv.c (frv_current_sos): Likewise.
	(frv_relocate_main_executable): Likewise.
	* solib-spu.c (spu_bfd_fopen): Likewise.
	* solib-svr4.c (lm_info_read): Likewise.
	(svr4_copy_library_list): Likewise.
	(svr4_default_sos): Likewise.
	* source.c (find_source_lines): Likewise.
	(line_info): Likewise.
	(add_substitute_path_rule): Likewise.
	* spu-linux-nat.c (spu_bfd_open): Likewise.
	* spu-tdep.c (info_spu_dma_cmdlist): Likewise.
	* stabsread.c (dbx_lookup_type): Likewise.
	(read_type): Likewise.
	(read_member_functions): Likewise.
	(read_struct_fields): Likewise.
	(read_baseclasses): Likewise.
	(read_args): Likewise.
	(_initialize_stabsread): Likewise.
	* stack.c (func_command): Likewise.
	* stap-probe.c (handle_stap_probe): Likewise.
	* symfile.c (addrs_section_sort): Likewise.
	(addr_info_make_relative): Likewise.
	(load_section_callback): Likewise.
	(add_symbol_file_command): Likewise.
	(init_filename_language_table): Likewise.
	* symtab.c (create_filename_seen_cache): Likewise.
	(sort_search_symbols_remove_dups): Likewise.
	(search_symbols): Likewise.
	* target.c (make_cleanup_restore_target_terminal): Likewise.
	* thread.c (new_thread): Likewise.
	(enable_thread_stack_temporaries): Likewise.
	(make_cleanup_restore_current_thread): Likewise.
	(thread_apply_all_command): Likewise.
	* tic6x-tdep.c (tic6x_gdbarch_init): Likewise.
	* top.c (gdb_readline_wrapper): Likewise.
	* tracefile-tfile.c (tfile_trace_file_writer_new): Likewise.
	* tracepoint.c (trace_find_line_command): Likewise.
	(all_tracepoint_actions_and_cleanup): Likewise.
	(make_cleanup_restore_current_traceframe): Likewise.
	(get_uploaded_tp): Likewise.
	(get_uploaded_tsv): Likewise.
	* tui/tui-data.c (tui_alloc_generic_win_info): Likewise.
	(tui_alloc_win_info): Likewise.
	(tui_alloc_content): Likewise.
	(tui_add_content_elements): Likewise.
	* tui/tui-disasm.c (tui_find_disassembly_address): Likewise.
	(tui_set_disassem_content): Likewise.
	* ui-file.c (ui_file_new): Likewise.
	(stdio_file_new): Likewise.
	(tee_file_new): Likewise.
	* utils.c (make_cleanup_restore_integer): Likewise.
	(add_internal_problem_command): Likewise.
	* v850-tdep.c (v850_gdbarch_init): Likewise.
	* valops.c (find_oload_champ): Likewise.
	* value.c (allocate_value_lazy): Likewise.
	(record_latest_value): Likewise.
	(create_internalvar): Likewise.
	* varobj.c (install_variable): Likewise.
	(new_variable): Likewise.
	(new_root_variable): Likewise.
	(cppush): Likewise.
	(_initialize_varobj): Likewise.
	* windows-nat.c (windows_make_so): Likewise.
	* x86-nat.c (x86_add_process): Likewise.
	* xcoffread.c (arrange_linetable): Likewise.
	(allocate_include_entry): Likewise.
	(process_linenos): Likewise.
	(SYMBOL_DUP): Likewise.
	(xcoff_start_psymtab): Likewise.
	(xcoff_end_psymtab): Likewise.
	* xml-support.c (gdb_xml_parse_attr_ulongest): Likewise.
	* xtensa-tdep.c (xtensa_register_type): Likewise.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.

gdb/gdbserver/ChangeLog:

	* ax.c (gdb_parse_agent_expr): Likewise.
	(compile_bytecodes): Likewise.
	* dll.c (loaded_dll): Likewise.
	* event-loop.c (append_callback_event): Likewise.
	(create_file_handler): Likewise.
	(create_file_event): Likewise.
	* hostio.c (handle_open): Likewise.
	* inferiors.c (add_thread): Likewise.
	(add_process): Likewise.
	* linux-aarch64-low.c (aarch64_linux_new_process): Likewise.
	* linux-arm-low.c (arm_new_process): Likewise.
	(arm_new_thread): Likewise.
	* linux-low.c (add_to_pid_list): Likewise.
	(linux_add_process): Likewise.
	(handle_extended_wait): Likewise.
	(add_lwp): Likewise.
	(enqueue_one_deferred_signal): Likewise.
	(enqueue_pending_signal): Likewise.
	(linux_resume_one_lwp_throw): Likewise.
	(linux_resume_one_thread): Likewise.
	(linux_read_memory): Likewise.
	(linux_write_memory): Likewise.
	* linux-mips-low.c (mips_linux_new_process): Likewise.
	(mips_linux_new_thread): Likewise.
	(mips_add_watchpoint): Likewise.
	* linux-x86-low.c (initialize_low_arch): Likewise.
	* lynx-low.c (lynx_add_process): Likewise.
	* mem-break.c (set_raw_breakpoint_at): Likewise.
	(set_breakpoint): Likewise.
	(add_condition_to_breakpoint): Likewise.
	(add_commands_to_breakpoint): Likewise.
	(clone_agent_expr): Likewise.
	(clone_one_breakpoint): Likewise.
	* regcache.c (new_register_cache): Likewise.
	* remote-utils.c (look_up_one_symbol): Likewise.
	* server.c (queue_stop_reply): Likewise.
	(start_inferior): Likewise.
	(queue_stop_reply_callback): Likewise.
	(handle_target_event): Likewise.
	* spu-low.c (fetch_ppc_memory): Likewise.
	(store_ppc_memory): Likewise.
	* target.c (set_target_ops): Likewise.
	* thread-db.c (thread_db_load_search): Likewise.
	(try_thread_db_load_1): Likewise.
	* tracepoint.c (add_tracepoint): Likewise.
	(add_tracepoint_action): Likewise.
	(create_trace_state_variable): Likewise.
	(cmd_qtdpsrc): Likewise.
	(cmd_qtro): Likewise.
	(add_while_stepping_state): Likewise.
	* win32-low.c (child_add_thread): Likewise.
	(get_image_name): Likewise.
2015-08-26 17:18:12 -04:00
Don Breazeal 17d8546e60 Fix native follow-exec-mode "new"
This patch fixes a segmentation fault in native GDB when
handling an exec event with follow-exec-mode set to "new".

The stack trace from the segfault was this:

 0  0x0000000000669594 in gdbarch_data (gdbarch=0x0, data=0x20da7a0)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/gdbarch.c:4847
 1  0x00000000004d430e in get_remote_arch_state ()
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/remote.c:603
 2  0x00000000004d431e in get_remote_state ()
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/remote.c:616
 3  0x00000000004dda8b in discard_pending_stop_replies (inf=0x217c710)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/remote.c:5775
 4  0x00000000006a5928 in observer_inferior_exit_notification_stub (
    data=0x4dda7a <discard_pending_stop_replies>, args_data=0x7fff12c258f0)
    at ./observer.inc:1137
 5  0x00000000006a419a in generic_observer_notify (subject=0x21dfbe0,
    args=0x7fff12c258f0)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/observer.c:167
 6  0x00000000006a59ba in observer_notify_inferior_exit (inf=0x217c710)
    at ./observer.inc:1162
 7  0x00000000007981d5 in exit_inferior_1 (inftoex=0x217c710, silent=1)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/inferior.c:244
 8  0x00000000007982f2 in exit_inferior_num_silent (num=1)
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/inferior.c:286
 9  0x000000000062f93d in follow_exec (ptid=...,
    execd_pathname=0x7fff12c259a0 "/scratch/dbreazea/sandbox/exec-nat/build/gdb/testsuite/gdb.base/execd-prog")
    at /scratch/dbreazea/sandbox/exec-nat/binutils-gdb/gdb/infrun.c:1195

In follow_exec we were creating a new inferior for the execd program,
as required by the exec mode, but we were doing it before calling
exit_inferior_num_silent on the original inferior.  So on entry to
exit_inferior_num_silent we had two inferiors with the same ptid.

In the calls made by exit_inferior_num_silent, the current inferior
is temporarily saved and replaced in order to make use of functions
that only operate on the current inferior (for example, in
do_all_continuations, called while deleting the threads of the original
inferior).  When we restored the original inferior, we just took the
first inferior that matched the ptid of the original and got the new
(wrong) one.  It hadn't been initialized yet and had no gdbarch
pointer, and GDB segfaulted.

The fix for that is to call exit_inferior_num_silent before adding the new
inferior, so that we never have two inferiors with the same ptid.  Then
exit_inferior_num_silent uses the original inferior as the current inferior
throughout, and can find a valid gdbarch pointer.

Once we have finished with the exit of the old inferior and added the
new one, we need to create a new thread for the new inferior.  In the
function that called follow_exec, handle_inferior_event_1,
ecs->event_thread now points to the thread that was deleted with the
exit of the original inferior.  To remedy this we create the new thread,
and once we return from follow_exec we reset ecs->event_thread.

Note that we are guaranteed that we can reset ecs->event_thread
safely using inferior_thread because we have set the current
inferior in follow_exec, and inferior_ptid was set by the call
to context_switch at the beginning of exec event handling.

gdb/ChangeLog:

	* infrun.c (follow_exec): Re-order operations for
	handling follow-exec-mode "new".
	(handle_inferior_event_1): Assign ecs->event_thread
	to the current thread.
	* remote.c (get_remote_arch_state): Add an assertion.
2015-08-26 14:07:25 -07:00
Don Breazeal 8d37573b43 New test for follow-exec-mode
This patch implements a new GDB test for follow-exec-mode.  Although
there is a GDB test for debugging across an exec, there is no test for
follow-exec-mode.  This test is derived from gdb.base/foll-exec.exp,
and re-uses execd-prog.c as the program to exec.

The following behavior is tested:

follow-exec-mode == "same"
 - 'next' over the exec, check for one inferior
 - 'continue' past the exec to a breakpoint, check for one inferior
 - after the exec, use a 'run' command to run the current binary
follow-exec-mode == "new"
 - 'next' over the exec, check for two inferiors
 - 'continue' past the exec to a breakpoint, check for two inferiors
 - after the exec, use a 'run' command to run the current binary
 - after the exec, use the 'inferior' command to switch inferiors,
   then use a 'run' command to run the current binary

Note that single-step breakpoints do not survive across an exec.
There has to be a breakpoint in the execed program in order for
it to stop right after the exec.

gdb/testsuite/ChangeLog:

	* gdb.base/foll-exec-2.c: New test program.
	* gdb.base/foll-exec-2.exp: New test.
2015-08-26 13:38:40 -07:00
Pedro Alves ba49e44bdc gdb: Add Markus Metzger as btrace maintainer
gdb/ChangeLog:
2015-08-26  Pedro Alves  <palves@redhat.com>

	* MAINTAINERS: Add Markus Metzger as btrace maintainer.
2015-08-26 17:50:02 +01:00
Pedro Alves abc56d60aa remote: allow aborting long operations (e.g., file transfers)
Currently, when remote debugging, if you type Ctrl-C just while the
target stopped for an internal event, and GDB is busy doing something
that takes a while (e.g., fetching chunks of a shared library off of
the target, with vFile, to process ELF headers and debug info), the
Ctrl-C is lost.

The patch hooks up the QUIT macro to a new target method that lets the
target react to the double-Ctrl-C before the event loop is reached,
which allows reacting to a double-Ctrl-C even when GDB is busy doing
some long operation and not waiting for a stop reply.  That end result
is:

 (gdb) c
 Continuing.
 ^C
 ^C
 Interrupted while waiting for the program.
 Give up waiting? (y or n) y
 Quit
 (gdb) info threads
   Id   Target Id         Frame
 * 1    Thread 11673      0x00007ffff7deb240 in _dl_debug_state () from target:/lib64/ld-linux-x86-64.so.2
 (gdb)

If, however, GDB is waiting for a stop reply (because the target has
been resumed, with e.g., vCont;c), but the target isn't responding, we
now get:

 (gdb) c
 Continuing.
 ^C
 ^C
 The target is not responding to interrupt requests.
 Stop debugging it? (y or n) y
 Disconnected from target.
 (gdb) info threads
 No threads.

This offers to disconnect, because when we're waiting for a stop
reply, there's nothing else we can send the target other than an
interrupt request.  And if that doesn't work, there's nothing else we
can do.

The Ctrl-C is presently lost because until we get to a user-visible
stop, the SIGINT handler that is installed is the one that forwards
the interrupt to the remote side, with the \003 "packet" [1].  But,
gdbserver ignores an interrupt request if the program is stopped.
Still, even if it didn't, the server can only report back a
stop-because-of-SIGINT when the program is next resumed.  And it may
take a while to actually re-resume the target.

[1] - In the old sync days, the remote target would react to a
double-Ctrl-C by asking users whether they wanted to give up waiting
and disconnect.  The code is still there, but it it isn't reacheable
on most hosts, which support serial connections in async mode
(probably only DJGPP doesn't).  Even then, in sync mode, remote.c's
SIGINT handler is only installed while the target is resumed, and is
removed as soon as the target sends back a stop reply.  That means
that a Ctrl-C just while GDB is processing an internal event can end
up with an odd "Quit" at the prompt instead of "Program stopped by
SIGINT".  In contrast, in async mode, remote.c's SIGINT handler is set
up as long as target_terminal_inferior or
target_terminal_ours_for_output are in effect (IOW, until we get a
user-visible stop and call target_terminal_ours), so the user
shouldn't get back a spurious Quit.  However, it's still desirable to
be able to interrupt a long-running GDB operation, if GDB takes a
while to re-resume the target or get back to the event loop.

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* defs.h (maybe_quit): Declare.
	(QUIT): Now calls maybe_quit.
	* event-loop.c (clear_async_signal_handler)
	(async_signal_handler_is_marked): New functions.
	* event-loop.h (async_signal_handler_is_marked)
	(clear_async_signal_handler): New declarations.
	* remote.c (remote_check_pending_interrupt): New function.
	(interrupt_query): Use make_cleanup_restore_target_terminal.  No
	longer check whether the target is async.  If waiting for a stop
	reply, and a Ctrl-C as been sent to the target, offer to
	disconnect, and throw TARGET_CLOSE_ERROR instead of a quit.
	Otherwise do not disconnect and throw a quit.
	(_initialize_remote): Install remote_check_pending_interrupt as
	to_check_pending_interrupt.
	* target.c (target_check_pending_interrupt): New function.
	* target.h (struct target_ops) <to_check_pending_interrupt>: New
	field.
	(target_check_pending_interrupt): New declaration.
	* utils.c (maybe_quit): New function.
	* target-delegates.c: Regenerate.
2015-08-25 16:12:11 +01:00
Yao Qi dfe7f77c4a Print tid in debug output of debug_reg_change_callback
In debug_reg_change_callback, we change debug registers of each LWP.
It makes more sense to print LWP's pid rather than group leader's pid.

gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* nat/aarch64-linux-hw-point.c (debug_reg_change_callback):
	Rename local variable pid to tid, and get lwpid of lwp.  Update
	debug output.
2015-08-25 14:45:54 +01:00
Pierre-Marie de Rodat 63e43d3aed DWARF: handle non-local references in nested functions
GDB's current behavior when dealing with non-local references in the
context of nested fuctions is approximative:

  - code using valops.c:value_of_variable read the first available stack
    frame that holds the corresponding variable (whereas there can be
    multiple candidates for this);

  - code directly relying on read_var_value will instead read non-local
    variables in frames where they are not even defined.

This change adds the necessary context to symbol reads (to get the block
they belong to) and to blocks (the static link property, if any) so that
GDB can make the proper decisions when dealing with non-local varibale
references.

gdb/ChangeLog:

	* ada-lang.c (ada_read_var_value): Add a var_block argument
	and pass it to default_read_var_value.
	* block.c (block_static_link): New accessor.
	* block.h (block_static_link): Declare it.
	* buildsym.c (finish_block_internal): Add a static_link
	argument.  If there is a static link, associate it to the new
	block.
	(finish_block): Add a static link argument and pass it to
	finish_block_internal.
	(end_symtab_get_static_block): Update calls to finish_block and
	to finish_block_internal.
	(end_symtab_with_blockvector): Update call to
	finish_block_internal.
	* buildsym.h: Forward-declare struct dynamic_prop.
	(struct context_stack): Add a static_link field.
	(finish_block): Add a static link argument.
	* c-exp.y: Remove an obsolete comment (evaluation of variables
	already start from the selected frame, and now they climb *up*
	the call stack) and propagate the block information to the
	produced expression.
	* d-exp.y: Likewise.
	* f-exp.y: Likewise.
	* go-exp.y: Likewise.
	* jv-exp.y: Likewise.
	* m2-exp.y: Likewise.
	* p-exp.y: Likewise.
	* coffread.c (coff_symtab_read): Update calls to finish_block.
	* dbxread.c (process_one_symbol): Likewise.
	* xcoffread.c (read_xcoff_symtab): Likewise.
	* compile/compile-c-symbols.c (convert_one_symbol): Promote the
	"sym" parameter to struct block_symbol, update its uses and pass
	its block to calls to read_var_value.
	(convert_symbol_sym): Update the calls to convert_one_symbol.
	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update
	call to read_var_value.
	* dwarf2loc.c (block_op_get_frame_base): New.
	(dwarf2_block_frame_base_locexpr_funcs): Implement the
	get_frame_base method.
	(dwarf2_block_frame_base_loclist_funcs): Likewise.
	(dwarf2locexpr_baton_eval): Add a frame argument and use it
	instead of the selected frame in order to evaluate the
	expression.
	(dwarf2_evaluate_property): Add a frame argument.  Update call
	to dwarf2_locexpr_baton_eval to provide a frame in available and
	to handle the absence of address stack.
	* dwarf2loc.h (dwarf2_evaluate_property): Add a frame argument.
	* dwarf2read.c (attr_to_dynamic_prop): Add a forward
	declaration.
	(read_func_scope): Record any available static link description.
	Update call to finish_block.
	(read_lexical_block_scope): Update call to finish_block.
	* findvar.c (follow_static_link): New.
	(get_hosting_frame): New.
	(default_read_var_value): Add a var_block argument.  Use
	get_hosting_frame to handle non-local references.
	(read_var_value): Add a var_block argument and pass it to the
	LA_READ_VAR_VALUE method.
	* gdbtypes.c (resolve_dynamic_range): Update calls to
	dwarf2_evaluate_property.
	(resolve_dynamic_type_internal): Likewise.
	* guile/scm-frame.c (gdbscm_frame_read_var): Update call to
	read_var_value, passing it the block coming from symbol lookup.
	* guile/scm-symbol.c (gdbscm_symbol_value): Update call to
	read_var_value (TODO).
	* infcmd.c (finish_command_continuation): Update call to
	read_var_value, passing it the block coming from symbol lookup.
	* infrun.c (insert_exception_resume_breakpoint): Likewise.
	* language.h (struct language_defn): Add a var_block argument to
	the LA_READ_VAR_VALUE method.
	* objfiles.c (struct static_link_htab_entry): New.
	(static_link_htab_entry_hash): New.
	(static_link_htab_entry_eq): New.
	(objfile_register_static_link): New.
	(objfile_lookup_static_link): New.
	(free_objfile): Free the STATIC_LINKS hashed map if needed.
	* objfiles.h: Include hashtab.h.
	(struct objfile): Add a static_links field.
	(objfile_register_static_link): New.
	(objfile_lookup_static_link): New.
	* printcmd.c (print_variable_and_value): Update call to
	read_var_value.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Likewise.
	* python/py-frame.c (frapy_read_var): Update call to
	read_var_value, passing it the block coming from symbol lookup.
	* python/py-framefilter.c (extract_sym): Add a sym_block
	parameter and set the pointed value to NULL (TODO).
	(enumerate_args): Update call to extract_sym.
	(enumerate_locals): Update calls to extract_sym and to
	read_var_value.
	* python/py-symbol.c (sympy_value): Update call to
	read_var_value (TODO).
	* stack.c (read_frame_local): Update call to read_var_value.
	(read_frame_arg): Likewise.
	(return_command): Likewise.
	* symtab.h (struct symbol_block_ops): Add a get_frame_base
	method.
	(struct symbol): Add a block field.
	(SYMBOL_BLOCK): New accessor.
	* valops.c (value_of_variable): Remove frame/block handling and
	pass the block argument to read_var_value, which does this job
	now.
	(value_struct_elt_for_reference): Update calls to
	read_var_value.
	(value_of_this): Pass the block found to read_var_value.
	* value.h (read_var_value): Add a var_block argument.
	(default_read_var_value): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.base/nested-subp1.exp: New file.
	* gdb.base/nested-subp1.c: New file.
	* gdb.base/nested-subp2.exp: New file.
	* gdb.base/nested-subp2.c: New file.
	* gdb.base/nested-subp3.exp: New file.
	* gdb.base/nested-subp3.c: New file.
2015-08-25 08:13:28 -04:00
Yao Qi ed8b7b421c Move aarch64_linux_new_thread to nat/aarch64-linux.c
This patch moves aarch64_linux_new_thread in GDB and GDBserver to
nat/aarch64-linux.c.

gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_linux_new_thread): Move it to ...
	* nat/aarch64-linux.c (aarch64_linux_new_thread): ... here.
	* nat/aarch64-linux.h (aarch64_linux_new_thread): Declare.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_linux_new_thread): Remove.
2015-08-25 11:39:14 +01:00
Yao Qi db3cb7cb3e Move aarch64_linux_prepare_to_resume to nat/aarch64-linux.c
gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (aarch64-liunx.o): New rule.
	(HFILES_NO_SRCDIR): Add aarch64-linux.h.
	* config/aarch64/linux.mh (NAT_FILE): Add aarch64-linux.o.
	* aarch64-linux-nat.c: Include nat/aarch64-linux.h.
	* aarch64-linux-nat.c (aarch64_get_debug_reg_state): Make it
	extern.
	(aarch64_linux_prepare_to_resume): Move it nat/aarch64-linux.c.
	* nat/aarch64-linux-hw-point.h (aarch64_debug_reg_state): Declare
	* nat/aarch64-linux.c: New file.
	* nat/aarch64-linux.h: New file.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (aarch64-linux.o): New rule.
	* configure.srv (aarch64*-*-linux*): Append aarch64-linux.o to
	srv_tgtobj.
	* linux-aarch64-low.c: Include nat/aarch64-linux.h.
	(aarch64_init_debug_reg_state): Make it extern.
	(aarch64_linux_prepare_to_resume): Remove.
2015-08-25 11:39:14 +01:00
Yao Qi f6011a1c84 Make aarch64_linux_prepare_to_resume the same on GDB and GDBserver
gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_linux_prepare_to_resume): Use
	lwp_arch_private_info and ptid_of_lwp.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_linux_prepare_to_resume): Use
	lwp_arch_private_info and ptid_of_lwp.
2015-08-25 11:39:13 +01:00
Yao Qi 88e2cf7ee2 Add pid argument in aarch64_get_debug_reg_state
This patch addes argument pid in aarch64_get_debug_reg_state, so that
its interface is the same on both GDB and GDBserver.

gdb/gdbserver:

2015-018-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_get_debug_reg_state): Add argument pid.
	Find proc_info by find_process_pid.  All callers updated.
2015-08-25 11:39:13 +01:00
Yao Qi 5e35436ed1 Move debug_reg_change_callback and aarch64_notify_debug_reg_change to nat/aarch64-linux-hw-point.c
gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (struct arch64_dr_update_callback_param):
	Move it to nat/aarch64-linux-hw-point.c.
	(debug_reg_change_callback): Likewise.
	(aarch64_notify_debug_reg_change): :Likewise.
	* nat/aarch64-linux-hw-point.c: Include nat/linux-nat.h.
	(aarch64_dr_update_callback_param): New.
	(debug_reg_change_callback): New function.
	(aarch64_notify_debug_reg_change): Likewise.
	* nat/aarch64-linux-hw-point.h (aarch64_notify_debug_reg_change):
	Remove the declaration.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (struct arch64_dr_update_callback_param):
	Remove.
	(debug_reg_change_callback): Remove.
	(aarch64_notify_debug_reg_change): Remove.
2015-08-25 11:39:13 +01:00
Yao Qi 75e1f0f7a0 Make debug_reg_change_callback the same on GDB and GDBserver
This patch makes function debug_reg_change_callback in GDB and GDBserver
look the same, so that the following patch can move them to
nat/aarch64-linux-hw-point.c.

gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (debug_reg_change_callback): Use
	ptid_of_lwp to get ptid of lwp.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (debug_reg_change_callback): Use
	ptid_of_lwp to get ptid of lwp.
2015-08-25 11:39:13 +01:00
Yao Qi 4a8a7965f2 Make aarch64_notify_debug_reg_change the same on GDB and GDBserver
gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_notify_debug_reg_change):
	Call current_lwp_ptid.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_notify_debug_reg_change):
	Call current_lwp_ptid.
2015-08-25 11:39:13 +01:00
Yao Qi 32a271eeaf Use debug_printf in debug_reg_change_callback
gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (debug_reg_change_callback): Use
	debug_printf.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (debug_reg_change_callback): Use
	debug_printf.
2015-08-25 11:39:12 +01:00
Yao Qi 0d51c8d71c Use phex debug_reg_change_callback
This patch is to use phex in debug_reg_change_callback to make it
identical in GDB and GDBserver.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (debug_reg_change_callback): Use phex.
2015-08-25 11:39:12 +01:00
Yao Qi 5e137137b2 Get pid rather than lwpid
We print PID rather than LWPID in the debug output, so we need call
ptid_get_pid in debug_reg_change_callback.

gdb:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (debug_reg_change_callback): Call
	ptid_get_pid rather than ptid_get_lwp.
2015-08-25 11:39:12 +01:00
Yao Qi 31a43dd5e1 Remove some comments in debug_reg_change_callback
gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (debug_reg_change_callback): Remove comments.
2015-08-25 11:39:12 +01:00
Yao Qi 8ee525679d Re-indent the code
gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (debug_reg_change_callback): Re-indent
	the code.
2015-08-25 11:39:07 +01:00
Yao Qi ff3f0f45c5 [gdbserver] Use iterate_over_lwps in aarch64_notify_debug_reg_change
This patch makes more bits on aarch64 watchpoint between GDB and GDBserver
look similar.

gdb/gdbserver:

2015-08-25  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_dr_update_callback_param) <pid>:
	Remove.
	(debug_reg_change_callback): Remove argument entry and add argument
	lwp.  Remove local variable thread.  Don't print thread id in the
	debugging output.  Don't check whether pid of thread equals to pid.
	(aarch64_notify_debug_reg_change): Don't set param.pid.  Call
	iterate_over_lwps instead find_inferior.
2015-08-25 11:38:28 +01:00
Pedro Alves 3d40fbb53b gdbserver crashes when multiprocess extensions aren't supported
Ref: https://sourceware.org/ml/gdb-patches/2015-08/msg00675.html

If multiprocess extensions are off (because specific gdbserver port
doesn't support them), then when gdbserver doesn't have a thread
selected yet, and GDB sends Hg packet to select one, gdbserver
crashes.  That's because extracting the desired thread id out of the
packet that GDB sent depends on the current thread to fill in the
missing process id ...  Fix this by getting the process id from the
first (and only) process in the processes list instead.

The GNU/Linux port doesn't trip on this because it always runs with
multiprocess extensions enabled.  To make it easier to catch such
regressions going forward, this commit also adds a new smoke test that
spawns gdbserver, connects to it and runs to main with the
multiprocess extensions force-disabled.

gdb/gdbserver/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* inferiors.c (get_first_process): New function.
	* inferiors.h (get_first_process): New declaration.
	* remote-utils.c (read_ptid): Default to the first process in the
	list, instead of to the current thread's process.

gdb/testsuite/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* gdb.server/connect-without-multi-process.c: New file.
	* gdb.server/connect-without-multi-process.exp: New file.
2015-08-24 19:58:31 +01:00
Pedro Alves 73b8c1fda9 Add "set remote multiprocess-extensions-packet" command
Being able to force-disable the RSP multiprocess extensions is useful
for testing.

gdb/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* NEWS (New commands): Mention set/show remote
	multiprocess-extensions-packet.
	* remote.c (remote_query_supported): Only tell the server to use
	the multiprocess extensions if the user hasn't force-disabled them
	with "set remote multiprocess-extensions-packet off".

gdb/doc/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Remote Configuration): Document the "set/show
	remote multiprocess-extensions-packet" commands.
2015-08-24 19:58:31 +01:00
Pedro Alves 4a626d0a0f Update gnulib to current upstream master
2015-08-24  Pedro Alves  <palves@redhat.com>

	* gnulib/update-gnulib.sh (GNULIB_COMMIT_SHA1): Set to
	1029a8112290f6eee9d7878a391c49db42c999bd.
	* gnulib/configure, gnulib/config.in, gnulib/aclocal.m4:
	Regenerate.
	* gnulib/import/Makefile.am: Update.
	* gnulib/import/Makefile.in: Update.
	* gnulib/import/alloca.in.h: Update.
	* gnulib/import/basename-lgpl.c: Update.
	* gnulib/import/canonicalize-lgpl.c: Update.
	* gnulib/import/config.charset: Update.
	* gnulib/import/dirent.in.h: Update.
	* gnulib/import/dirfd.c: Update.
	* gnulib/import/dirname-lgpl.c: Update.
	* gnulib/import/dirname.h: Update.
	* gnulib/import/dosname.h: Update.
	* gnulib/import/errno.in.h: Update.
	* gnulib/import/extra/snippet/arg-nonnull.h: Update.
	* gnulib/import/extra/snippet/c++defs.h: Update.
	* gnulib/import/extra/snippet/warn-on-use.h: Update.
	* gnulib/import/extra/update-copyright: Update.
	* gnulib/import/float+.h: Update.
	* gnulib/import/float.c: Update.
	* gnulib/import/float.in.h: Update.
	* gnulib/import/fnmatch.c: Update.
	* gnulib/import/fnmatch.in.h: Update.
	* gnulib/import/fnmatch_loop.c: Update.
	* gnulib/import/fpucw.h: Update.
	* gnulib/import/frexp.c: Update.
	* gnulib/import/frexpl.c: Update.
	* gnulib/import/gettimeofday.c: Update.
	* gnulib/import/inttypes.in.h: Update.
	* gnulib/import/isnan.c: Update.
	* gnulib/import/isnand-nolibm.h: Update.
	* gnulib/import/isnand.c: Update.
	* gnulib/import/isnanl-nolibm.h: Update.
	* gnulib/import/isnanl.c: Update.
	* gnulib/import/itold.c: Update.
	* gnulib/import/localcharset.c: Update.
	* gnulib/import/localcharset.h: Update.
	* gnulib/import/lstat.c: Update.
	* gnulib/import/m4/00gnulib.m4: Update.
	* gnulib/import/m4/absolute-header.m4: Update.
	* gnulib/import/m4/alloca.m4: Update.
	* gnulib/import/m4/canonicalize.m4: Update.
	* gnulib/import/m4/codeset.m4: Update.
	* gnulib/import/m4/configmake.m4: Update.
	* gnulib/import/m4/dirent_h.m4: Update.
	* gnulib/import/m4/dirfd.m4: Update.
	* gnulib/import/m4/dirname.m4: Update.
	* gnulib/import/m4/double-slash-root.m4: Update.
	* gnulib/import/m4/eealloc.m4: Update.
	* gnulib/import/m4/errno_h.m4: Update.
	* gnulib/import/m4/exponentd.m4: Update.
	* gnulib/import/m4/exponentl.m4: Update.
	* gnulib/import/m4/extensions.m4: Update.
	* gnulib/import/m4/extern-inline.m4: Update.
	* gnulib/import/m4/fcntl-o.m4: Update.
	* gnulib/import/m4/float_h.m4: Update.
	* gnulib/import/m4/fnmatch.m4: Update.
	* gnulib/import/m4/fpieee.m4: Update.
	* gnulib/import/m4/frexp.m4: Update.
	* gnulib/import/m4/frexpl.m4: Update.
	* gnulib/import/m4/gettimeofday.m4: Update.
	* gnulib/import/m4/glibc21.m4: Update.
	* gnulib/import/m4/gnulib-cache.m4: Update.
	* gnulib/import/m4/gnulib-common.m4: Update.
	* gnulib/import/m4/gnulib-comp.m4: Update.
	* gnulib/import/m4/gnulib-tool.m4: Update.
	* gnulib/import/m4/include_next.m4: Update.
	* gnulib/import/m4/inttypes-pri.m4: Update.
	* gnulib/import/m4/inttypes.m4: Update.
	* gnulib/import/m4/isnand.m4: Update.
	* gnulib/import/m4/isnanl.m4: Update.
	* gnulib/import/m4/largefile.m4: Update.
	* gnulib/import/m4/localcharset.m4: Update.
	* gnulib/import/m4/locale-fr.m4: Update.
	* gnulib/import/m4/locale-ja.m4: Update.
	* gnulib/import/m4/locale-zh.m4: Update.
	* gnulib/import/m4/longlong.m4: Update.
	* gnulib/import/m4/lstat.m4: Update.
	* gnulib/import/m4/malloc.m4: Update.
	* gnulib/import/m4/malloca.m4: Update.
	* gnulib/import/m4/math_h.m4: Update.
	* gnulib/import/m4/mbrtowc.m4: Update.
	* gnulib/import/m4/mbsinit.m4: Update.
	* gnulib/import/m4/mbsrtowcs.m4: Update.
	* gnulib/import/m4/mbstate_t.m4: Update.
	* gnulib/import/m4/memchr.m4: Update.
	* gnulib/import/m4/memmem.m4: Update.
	* gnulib/import/m4/mmap-anon.m4: Update.
	* gnulib/import/m4/multiarch.m4: Update.
	* gnulib/import/m4/nocrash.m4: Update.
	* gnulib/import/m4/off_t.m4: Update.
	* gnulib/import/m4/pathmax.m4: Update.
	* gnulib/import/m4/readlink.m4: Update.
	* gnulib/import/m4/rename.m4: Update.
	* gnulib/import/m4/rmdir.m4: Update.
	* gnulib/import/m4/ssize_t.m4: Update.
	* gnulib/import/m4/stat.m4: Update.
	* gnulib/import/m4/stdbool.m4: Update.
	* gnulib/import/m4/stddef_h.m4: Update.
	* gnulib/import/m4/stdint.m4: Update.
	* gnulib/import/m4/stdio_h.m4: Update.
	* gnulib/import/m4/stdlib_h.m4: Update.
	* gnulib/import/m4/string_h.m4: Update.
	* gnulib/import/m4/strstr.m4: Update.
	* gnulib/import/m4/strtok_r.m4: Update.
	* gnulib/import/m4/sys_socket_h.m4: Update.
	* gnulib/import/m4/sys_stat_h.m4: Update.
	* gnulib/import/m4/sys_time_h.m4: Update.
	* gnulib/import/m4/sys_types_h.m4: Update.
	* gnulib/import/m4/time_h.m4: Update.
	* gnulib/import/m4/unistd_h.m4: Update.
	* gnulib/import/m4/warn-on-use.m4: Update.
	* gnulib/import/m4/wchar_h.m4: Update.
	* gnulib/import/m4/wchar_t.m4: Update.
	* gnulib/import/m4/wctype_h.m4: Update.
	* gnulib/import/m4/wint_t.m4: Update.
	* gnulib/import/malloc.c: Update.
	* gnulib/import/malloca.c: Update.
	* gnulib/import/malloca.h: Update.
	* gnulib/import/math.in.h: Update.
	* gnulib/import/mbrtowc.c: Update.
	* gnulib/import/mbsinit.c: Update.
	* gnulib/import/mbsrtowcs-impl.h: Update.
	* gnulib/import/mbsrtowcs-state.c: Update.
	* gnulib/import/mbsrtowcs.c: Update.
	* gnulib/import/memchr.c: Update.
	* gnulib/import/memmem.c: Update.
	* gnulib/import/pathmax.h: Update.
	* gnulib/import/readlink.c: Update.
	* gnulib/import/ref-add.sin: Update.
	* gnulib/import/ref-del.sin: Update.
	* gnulib/import/rename.c: Update.
	* gnulib/import/rmdir.c: Update.
	* gnulib/import/same-inode.h: Update.
	* gnulib/import/stat.c: Update.
	* gnulib/import/stdbool.in.h: Update.
	* gnulib/import/stddef.in.h: Update.
	* gnulib/import/stdint.in.h: Update.
	* gnulib/import/stdio.c: Update.
	* gnulib/import/stdio.in.h: Update.
	* gnulib/import/stdlib.in.h: Update.
	* gnulib/import/str-two-way.h: Update.
	* gnulib/import/streq.h: Update.
	* gnulib/import/string.in.h: Update.
	* gnulib/import/stripslash.c: Update.
	* gnulib/import/strnlen1.c: Update.
	* gnulib/import/strnlen1.h: Update.
	* gnulib/import/strstr.c: Update.
	* gnulib/import/strtok_r.c: Update.
	* gnulib/import/sys_stat.in.h: Update.
	* gnulib/import/sys_time.in.h: Update.
	* gnulib/import/sys_types.in.h: Update.
	* gnulib/import/time.in.h: Update.
	* gnulib/import/unistd.in.h: Update.
	* gnulib/import/verify.h: Update.
	* gnulib/import/wchar.in.h: Update.
	* gnulib/import/wctype.in.h: Update.
	* gnulib/import/gettimeofday.c: New file.
	* gnulib/import/m4/absolute-header.m4: New file.
	* gnulib/import/m4/gettimeofday.m4: New file.
	* gnulib/import/m4/sys_socket_h.m4: New file.
	* gnulib/import/m4/sys_time_h.m4: New file.
	* gnulib/import/stdio.c: Delete file.
	* gnulib/import/sys_time.in.h: New file.
2015-08-24 18:53:49 +01:00
Pedro Alves 438e1e427e Prepare for gnulib update
After the last gnulib import (Dec 2012), gnulib upstream started
replacing mingw's 'struct timeval' with a version with 64-bit time_t,
for POSIX compliance:

 commit f8e84098084b3b53bc6943a5542af1f607ffd477
 Author: Bruno Haible <bruno@clisp.org>
 Date:   Sat Jan 28 18:12:10 2012 +0100
     sys_time: Override 'struct timeval' on some native Windows platforms.

See:

 https://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00372.html

However, that results in conflicts with native Winsock2's 'select':

select()'s argument
	http://sourceforge.net/p/mingw-w64/mailman/message/29610438/

... and libiberty's timeval-utils.h timeval_add/timeval_sub, at the
least.

We don't really need the POSIX compliance, so this patch prepares us
to simply not use gnulib's 'struct timeval' replacement once a more
recent gnulib is imported, thus preserving the current behavior, by
adding a sys/time.h wrapper header that undefs gnulib's replacements,
and including that everywhere instead.

The SIZE -> OSIZE change is necessary because newer gnulib's
sys/time.h also includes windows.h/winsock2.h, which defines a
conflicting SIZE symbol.

Cross build-tested mingw-w64 32-bit and 64-bit.
Regtested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add common/gdb_sys_time.h.
	* common/gdb_sys_time.h: New file.
	* event-loop.c: Include gdb_sys_time.h instead of sys/time.h.
	* gdb_select.h: Likewise.
	* gdb_usleep.c: Likewise.
	* maint.c: Likewise.
	* mi/mi-main.c: Likewise.
	* mi/mi-parse.h: Likewise.
	* remote-fileio.c: Likewise.
	* remote-m32r-sdi.c: Likewise.
	* remote.c: Likewise.
	* ser-base.c: Likewise.
	* ser-pipe.c: Likewise.
	* ser-tcp.c: Likewise.
	* ser-unix.c: Likewise.
	* symfile.c: Likewise.
	* symfile.c: Likewise.  Rename OSIZE to SIZE throughout.
	* target-memory.c: Include gdb_sys_time.h instead of sys/time.h.
	* utils.c: Likewise.

gdb/gdbserver/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* debug.c: Include gdb_sys_time.h instead of sys/time.h.
	* event-loop.c: Likewise.
	* remote-utils.c: Likewise.
	* tracepoint.c: Likewise.
2015-08-24 18:50:55 +01:00
Pedro Alves a8c6d4fcd6 Fix gdbserver SPU build
Ref: https://sourceware.org/ml/gdb-patches/2015-08/msg00675.html

 gdbserver/spu-low.c: In function 'spu_request_interrupt':
 gdbserver/spu-low.c:639: error: incompatible type for argument 1 of 'ptid_get_lwp'

gdb/gdbserver/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* spu-low.c (spu_request_interrupt): Use lwpid_of instead of
	ptid_get_lwp.
2015-08-24 17:58:22 +01:00
Luis Machado 4422ac93e5 Make z int
This makes z an int for gdb/testsuite/gdb.opt/inline-markers.c.

gdb/testsuite/ChangeLog:

2015-08-24  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.opt/inline-markers.c: Make z int.
2015-08-24 13:08:20 -03:00
Luis Machado 91dddb8629 Make z volatile.
This fixes a typo in gdb/testsuite/gdb.opt/inline-markers.c, making
z a volatile variable.

gdb/testsuite/ChangeLog:

2015-08-24  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.opt/inline-markers.c: Make z volatile.
2015-08-24 12:56:15 -03:00
Luis Machado a48847eea5 Prevent GCC from folding inline test functions
While doing some powerpc Linux tests on a ppc 476 board using GCC 5.2, i
noticed inline-bt.exp, inline-cmds.exp and inline-locals.exp failing.

FAIL: gdb.opt/inline-bt.exp: continue to bar (1)
FAIL: gdb.opt/inline-bt.exp: backtrace from bar (1)
FAIL: gdb.opt/inline-bt.exp: continue to bar (2)
FAIL: gdb.opt/inline-bt.exp: backtrace from bar (2)
FAIL: gdb.opt/inline-bt.exp: continue to bar (3)
FAIL: gdb.opt/inline-bt.exp: backtrace from bar (3)
FAIL: gdb.opt/inline-cmds.exp: continue to bar (1)
FAIL: gdb.opt/inline-cmds.exp: backtrace from bar (1)
FAIL: gdb.opt/inline-cmds.exp: continue to bar (2)
FAIL: gdb.opt/inline-cmds.exp: backtrace from bar (2)
FAIL: gdb.opt/inline-cmds.exp: continue to marker
FAIL: gdb.opt/inline-cmds.exp: backtrace from marker
FAIL: gdb.opt/inline-cmds.exp: step into finish marker
FAIL: gdb.opt/inline-locals.exp: continue to bar (1)
FAIL: gdb.opt/inline-locals.exp: continue to bar (2)
FAIL: gdb.opt/inline-locals.exp: backtrace from bar (2)
FAIL: gdb.opt/inline-locals.exp: continue to bar (3)
FAIL: gdb.opt/inline-locals.exp: backtrace from bar (3)

They failed because the breakpoint supposedly inserted at bar was actually
inserted at noinline.

(gdb) break inline-markers.c:20^M
Breakpoint 2 at 0x1000079c: file gdb/testsuite/gdb.opt/inline-markers.c, line 20.^M
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2, noinline () at gdb/testsuite/gdb.opt/inline-markers.c:35^M
35        inlined_fn (); /* inlined */^M

As we can see, line 20 is really inside bar, not noinline:

18 void bar(void)
19 {
20   x += y; /* set breakpoint 1 here */
21 }

Further investigation shows that this is really due to GCC 5's new
ICF pass (-fipa-icf), now enabled by default at -O2, which folds bar
and marker into noinline, where the call to inlined_fn was inlined.

This breaks the testcase since it expects to stop at specific spots.

I thought about two possible fixes for this issue.

- Disable the ICF pass manually when building the binary (-fno-ipa-icf).

This has the advantage of not having to touch the testcase sources themselves,
but the disadvantage of having to add conditional blocks to test the GCC
version. If we ever change GCC's default, we will have to adjust the
conditional block again to match GCC's behavior.

- Modify the testcase sources to make the identical functions unique.

This solution doesn't touch the testcase itself, but changes the source
code slightly in order to make bar, marker and inlined_fn unique. This
causes GCC's ICF pass to ignore these functions and not fold them into
a common identical function.

I'm good with either of them, but i'm more inclined to go with the second
one.

The attached patch implements this by adding the new global variable z, set
to 0, that gets added in different ways to marker and inlined_fn. Since it
is 0, it doesn't affect any possible value checks that we may wish to do
in the future (we currently only check for values changed by bar).

Ok?

ps: I also noticed GDB doesn't do a great job at stating that the breakpoint
was actually inserted at a different source line than previously requested,
so this sounds like a bug that should be fixed, if it is not just wrong
DWARF information (did not investigate it further).

gdb/testsuite/ChangeLog:

2015-08-24  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.opt/inline-bt.c: New volatile global z.
	* gdb.opt/inline-cmds.c: Likewise.
	* gdb.opt/inline-locals.c: Likewise.
	* gdb.opt/inline-markers.c: New extern global z.
	(marker): Use z.
	(inline_fn): Likewise.
2015-08-24 12:33:21 -03:00
Pedro Alves 0ebbc52bee gdb/testsuite/: garbage collect a few references to dead targets
gdb/testsuite/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* config/m32r-stub.exp: Remove file.
	* gdb.base/call-ar-st.exp: Remove reference to sparclet.
	* gdb.base/call-rt-st.exp: Likewise.
	* gdb.base/call-strs.exp: Likewise.
	* gdb.base/default.exp: Remove references to h8300-*-hms and
	*-*-udi*.
	* gdb.base/funcargs.exp: Remove reference to sparclet-*-*.
2015-08-24 15:53:00 +01:00
Pedro Alves bb61542818 gdb manual: Remove references to deleted targets
Support for target dbug/picobug/dink32/m32r/mon2000/ppcbug was just
removed, but support for ARM RDI, Sparclet, Sparclite, Z8000, target
r3900, target array, target sds, target op50n and target w89k had
already been removed many years ago.  Drop it all in one go.

gdb/doc/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Embedded Processors) <ARM>: Remove references to RDI.
	<M32R>: Remove references to M32R/D.
	<M68K>: Remove references to target dbug.
	<MIPS Embedded>: Remove references to target r3900 and target
	array.
	<PowerPC Embedded>: Remove references to target dink32 and target
	ppcbug, target sds
	<PA, Sparclet, Sparclite, Z8000>: Delete nodes.
2015-08-24 15:40:26 +01:00
Pedro Alves 40e0b27177 Delete the remaining ROM monitor targets
Ref: https://sourceware.org/ml/gdb/2015-07/msg00011.html

All of these targets use gdb/monitor.c, which has bit rotted
years ago (I'd guess around ~6), and nobody seems to
have noticed:

 | target         | source               |
 |----------------+----------------------|
 | target dbug    | gdb/dbug-rom.c       |
 | target picobug | gdb/microblaze-rom.c |
 | target dink32  | gdb/dink32-rom.c     |
 | target m32r    | gdb/m32r-rom.c       |
 | target mon2000 | gdb/m32r-rom.c       |
 | target ppcbug  | gdb/ppcbug-rom.c     |

This deletes them, along with finally removing monitor.c.

A manual update will be done separately.

gdb/ChangeLog:
2015-08-24  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention removed support for the various ROM monitors.
	* Makefile.in (ALL_TARGET_OBS): Remove dbug-rom.o, dink32-rom.o,
	ppcbug-rom.o, m32r-rom.o, dsrec.o and monitor.o from gdb_target_obs.
	* configure.tgt (h8300-*-*): Remove monitor.o and m32r-rom.o from
	gdb_target_obs.
	(m68*-*-*): Remove monitor.o dbug-rom.o and dsrec.o from
	gdb_target_obs.
	(microblaze*-linux-*): Remove microblaze-rom.o, monitor.o and
	dsrec.o from gdb_target_obs.
	(microblaze*-*-*): Remove microblaze-rom.o, monitor.o and dsrec.o
	from gdb_target_obs.
	(powerpc-*-lynx*178): Remove monitor.o and dsrec.o from
	gdb_target_obs.
	(powerpc*-*-*): Remove monitor.o, dsrec.o, ppcbug-rom.o and
	dink32-rom.o from gdb_target_obs.
	(sh*-*-linux*): Remove monitor.o and dsrec.o from gdb_target_obs.
	(sh*): Remove monitor.o and dsrec.o from gdb_target_obs.
	* dbug-rom.c, dink32-rom.c, dsrec.c, m32r-rom.c, microblaze-rom.c,
	monitor.c, monitor.h, ppcbug-rom.c, srec.h: Delete files.
2015-08-24 15:40:26 +01:00
Andreas Arnez 77c365df78 gnu_vector.exp: Avoid some more known FAILs
This avoids two more types of FAILs with the gnu_vector test case.

First, for POWER targets newer GCCs emit an ABI note when invoked with
"-mcpu=native".  Then the test case fell back to non-native compile,
producing code for a non-vector ABI.  But that is not supported by GDB.
Thus the compiler note is now suppressed with "-Wno-psabi".

Second, on s390 the test case produced FAILs after falling back to a
non-vector ABI when using "finish" or "return" in a vector-valued
function.  This was due to a long-standing known bug (Bug 8549).  This
case is now detected, and KFAILs are emitted instead.

gdb/testsuite/ChangeLog:

	* gdb.base/gnu_vector.exp: Try compilation with "-mcpu=native
	-Wno-psabi" if "-mcpu=native" fails.  For the tests with "finish"
	and "return" use KFAIL when GDB can not read/write the vector
	return value.
2015-08-24 15:37:40 +02:00
Pedro Alves 99b0bb12cd Fix ax.c:gdb_eval_agent_expr
In C++ mode:

 src/gdb/gdbserver/ax.c: In function ‘eval_result_type gdb_eval_agent_expr(eval_agent_expr_context*, agent_expr*, ULONGEST*)’:
 src/gdb/gdbserver/ax.c:1335:11: error: invalid conversion from ‘int’ to ‘eval_result_type’ [-fpermissive]
     return 1;
	    ^

"1" as an enum eval_result_type is expr_eval_empty_expression, but
clearly this wants to return expr_eval_unhandled_opcode.

gdb/gdbserver/ChangeLog:
2015-08-21  Pedro Alves  <palves@redhat.com>

	* ax.c (gdb_eval_agent_expr): Return expr_eval_unhandled_opcode
	instead of literal 1.
2015-08-21 23:59:33 +01:00
Pedro Alves f890475111 C++: Initialize a couple const globals
In C++ mode, we get:

 src/gdb/gdbserver/tdesc.c:43:33: error: uninitialized const ‘default_description’ [-fpermissive]
  static const struct target_desc default_description;
				  ^
 In file included from src/gdb/gdbserver/tdesc.c:19:0:
 src/gdb/gdbserver/tdesc.h:26:8: note: ‘const struct target_desc’ has no user-provided default constructor
  struct target_desc
	 ^

gdb/ChangeLog:
2015-08-21  Pedro Alves  <palves@redhat.com>

	* frame.c (null_frame_id): Explicitly zero-initialize.

gdb/gdbserver/ChangeLog:
2015-08-21  Pedro Alves  <palves@redhat.com>

	* tdesc.c (default_description): Explicitly zero-initialize.
2015-08-21 23:49:37 +01:00
Tom Tromey 049412e38f gdb/dwarf2read.c: rename a field for c++
Fixes:

 ../../src/gdb/dwarf2read.c:127:15: error: declaration of ‘asection* dwarf2_section_info::<anonymous union>::asection’ [-fpermissive]
      asection *asection;
		^
 In file included from ../../src/gdb/common/common-types.h:35:0,
		  from ../../src/gdb/common/common-defs.h:44,
		  from ../../src/gdb/defs.h:28,
		  from ../../src/gdb/dwarf2read.c:31:
 ../bfd/bfd.h:1596:3: error: changes meaning of ‘asection’ from ‘typedef struct bfd_section asection’ [-fpermissive]
  } asection;
    ^

gdb/ChangeLog:
2015-08-21  Tom Tromey  <tromey@redhat.com>

	* dwarf2read.c (struct dwarf2_section_info): Rename field
	'asection' to 'section'.
	(dwarf2_has_info, get_section_bfd_owner, get_section_bfd_section)
	(dwarf2_locate_sections, dwarf2_locate_sections)
	(locate_dwz_sections, locate_v1_virtual_dwo_sections)
	(dwarf2_locate_dwo_sections, dwarf2_locate_dwo_sections)
	(dwarf2_locate_v2_dwp_sections): Adjust.
2015-08-21 23:45:50 +01:00
Patrick Palka 948578a989 tui: don't overwrite a secondary prompt that was given no input
This patch fixes the following bug in TUI:

  (gdb) break foo
  No symbol table is loaded.  Use the "file" command.
  Make breakpoint pending on future shared library load? (y or [n]) <ENTER>

By submitting an empty command line to a secondary prompt, the line
corresponding to the secondary prompt is undesirably cleared and
overwritten.  Outside of a secondary prompt, clearing the prompt line
after submitting an empty command line is intended behavior which
complements GDB's repeat-command shorthand.  But inside a secondary
prompt, this behavior is undesired since the shorthand is not applicable
in that case.  We should retain the secondary-prompt line even when it's
given no input.

This patch makes sure that a prompt that was given an empty command line
is cleared and overwritten only if it's not a secondary prompt.  To
acheive this, a new predicate is defined which informs us whether the
current input handler is a secondary prompt.

gdb/ChangeLog:

	* top.h (gdb_in_secondary_prompt_p): Declare.
	* top.c (gdb_secondary_prompt_depth): Define.
	(gdb_in_secondary_prompt_p): Define.
	(gdb_readline_wrapper_cleanup): Decrement
	gdb_secondary_prompt_depth.
	(gdb_readline_wrapper): Increment gdb_secondary_prompt_depth.
	* tui/tui-io.c (tui_getc): Don't clear the prompt line if we
	are in a secondary prompt.
2015-08-21 16:18:39 -04:00
Patrick Palka 7a8bcb88e7 Use tui_putc to output newline entered by the user
This is necessary to make sure that start_line is updated after a
command has been entered.  Usually, start_line gets updated anyway
because most commands output text, and outputting text is done through
the function tui_puts, which updates start_line.  However if a command
does not output text, then tui_puts will not get called and start_line
will not get updated in time for the next prompt to be displayed.

One can observe this bug by executing the command "delete" within TUI.
After executing, the prompt line

  (gdb) delete

gets overwritten by the next prompt.  With this patch, the prompt line
gets preserved.

gdb/ChangeLog:

	* tui/tui-io.c (tui_getc): Use tui_putc instead of waddch to
	emit the newline.
2015-08-21 16:17:52 -04:00
Pedro Alves 465a859e0a Fix gdbserver crash exposed by gdb.threads/process-dies-while-handling-bp.exp
Running that test in a loop, I found a gdbserver core dump with the
following back trace:

 Core was generated by `../gdbserver/gdbserver --once --multi :2346'.
 Program terminated with signal SIGSEGV, Segmentation fault.
 #0  0x0000000000406ab6 in inferior_regcache_data (inferior=0x0) at src/gdb/gdbserver/inferiors.c:236
 236       return inferior->regcache_data;
 (gdb) up
 #1  0x0000000000406d7f in get_thread_regcache (thread=0x0, fetch=1) at src/gdb/gdbserver/regcache.c:31
 31        regcache = (struct regcache *) inferior_regcache_data (thread);
 (gdb) bt
 #0  0x0000000000406ab6 in inferior_regcache_data (inferior=0x0) at src/gdb/gdbserver/inferiors.c:236
 #1  0x0000000000406d7f in get_thread_regcache (thread=0x0, fetch=1) at src/gdb/gdbserver/regcache.c:31
 #2  0x0000000000409271 in prepare_resume_reply (buf=0x20dd593 "", ptid=..., status=0x20edce0) at src/gdb/gdbserver/remote-utils.c:1147
 #3  0x000000000040ab0a in vstop_notif_reply (event=0x20edcc0, own_buf=0x20dd590 "T05") at src/gdb/gdbserver/server.c:183
 #4  0x0000000000426b38 in notif_write_event (notif=0x66e6c0 <notif_stop>, own_buf=0x20dd590 "T05") at src/gdb/gdbserver/notif.c:69
 #5  0x0000000000426c55 in handle_notif_ack (own_buf=0x20dd590 "T05", packet_len=8) at src/gdb/gdbserver/notif.c:113
 #6  0x000000000041118f in handle_v_requests (own_buf=0x20dd590 "T05", packet_len=8, new_packet_len=0x7fff742c77b8)
     at src/gdb/gdbserver/server.c:2862
 #7  0x0000000000413850 in process_serial_event () at src/gdb/gdbserver/server.c:4148
 #8  0x0000000000413945 in handle_serial_event (err=0, client_data=0x0) at src/gdb/gdbserver/server.c:4196
 #9  0x000000000041a1ef in handle_file_event (event_file_desc=5) at src/gdb/gdbserver/event-loop.c:429
 #10 0x00000000004199b6 in process_event () at src/gdb/gdbserver/event-loop.c:184
 #11 0x000000000041a735 in start_event_loop () at src/gdb/gdbserver/event-loop.c:547
 #12 0x00000000004123d2 in captured_main (argc=4, argv=0x7fff742c7ac8) at src/gdb/gdbserver/server.c:3562
 #13 0x000000000041252e in main (argc=4, argv=0x7fff742c7ac8) at src/gdb/gdbserver/server.c:3631

Clearly this means that a thread pushed a stop reply in the event
queue, and then before GDB confused the event, the whole process died,
along with its thread.  But the pending thread event was left
dangling.  When GDB fetched that event, gdbserver looked up the
corresponding thread, but found NULL; not expecting this, gdbserver
crashes when it tries to read this thread's registers.

gdb/gdbserver/
2015-08-21  Pedro Alves  <palves@redhat.com>

	PR gdb/18749
	* inferiors.c (remove_thread): Discard any pending stop reply for
	this thread.
	* server.c (remove_all_on_match_pid): Rename to ...
	(remove_all_on_match_ptid): ... this.  Work with a filter ptid
	instead of a pid.
	(discard_queued_stop_replies): Change parameter to a ptid.  Now
	extern.
	(handle_v_kill, kill_inferior_callback)
	(process_serial_event): Adjust.
	(captured_main): Call initialize_notif before starting the
	program, thus before threads are created.
	* server.h (discard_queued_stop_replies): Declare.
2015-08-21 19:52:36 +01:00
Pedro Alves f0db101d98 gdbserver: don't pick a random thread if the current thread dies
In all-stop mode, if the current thread disappears while stopping all
threads, gdbserver calls set_desired_thread(0) ['0' means "I want the
continue thread"] which just picks the first thread in the list.

This looks like a dangerous thing to do.  GDBserver continues
processing whatever it was doing, but to the wrong thread.  If
debugging more than one process, we may even pick the wrong process.
Instead, GDBserver should detect the situation and bail out of
whatever is was doing.

The backends used to pay attention to the set 'cont_thread' (the Hc
thread, used in the old way to resume threads, before vCont), but all
such 'cont_thread' checks have been eliminated meanwhile.  The
remaining implicit dependencies that I found on there being a selected
thread in the backends are in the Ctrl-C handling, which some backends
use as thread to send a signal to.  Even that seems to me to be better
handled by always using the first thread in the list or by using the
signal_pid PID.

In order to make this a systematic approach, I'm making
set_desired_thread never fallback to a random thread, and instead end
up with current_thread == NULL, like already done in non-stop mode.
Then I updated all callers to handle the situation.

I stumbled on this while fixing other bugs exposed by
gdb.threads/fork-plus-threads.exp test.  The problems I saw were fixed
in a different way, but in any case, I think the potential for
problems is more or less obvious, and the resulting code looks a bit
less magical to me.

Tested on x86-64 Fedora 20, w/ native-extended-gdbserver board.

gdb/gdbserver/ChangeLog:
2015-08-21  Pedro Alves  <palves@redhat.com>

	* linux-low.c (wait_for_sigstop): Always switch to no thread
	selected if the previously current thread dies.
	* lynx-low.c (lynx_request_interrupt): Use the first thread's
	process instead of the current thread's.
	* remote-utils.c (input_interrupt): Don't check if there's no
	current thread.
	* server.c (gdb_read_memory, gdb_write_memory): If setting the
	current thread to the general thread fails, error out.
	(handle_qxfer_auxv, handle_qxfer_libraries)
	(handle_qxfer_libraries_svr4, handle_qxfer_siginfo)
	(handle_qxfer_spu, handle_qxfer_statictrace, handle_qxfer_fdpic)
	(handle_query): Check if there's a thread selected instead of
	checking whether there's any thread in the thread list.
	(handle_qxfer_threads, handle_qxfer_btrace)
	(handle_qxfer_btrace_conf): Don't error out early if there's no
	thread in the thread list.
	(handle_v_cont, myresume): Don't set the current thread to the
	continue thread.
	(process_serial_event) <Hg handling>: Also set thread_id if the
	previous general thread is still alive.
	(process_serial_event) <g/G handling>: If setting the current
	thread to the general thread fails, error out.
	* spu-low.c (spu_resume, spu_request_interrupt): Use the first
	thread's lwp instead of the current thread's.
	* target.c (set_desired_thread): If the desired thread was not
	found, leave the current thread pointing to NULL.  Return an int
	(boolean) indicating success.
	* target.h (set_desired_thread): Change return type to int.
2015-08-21 19:20:31 +01:00
Gary Benson 2d7711a367 Make remote file transfers interruptible
This commit makes it possible to interrupt remote file transfers.
2015-08-21 17:11:49 +01:00
Gary Benson 4313b8c0ed Warn when accessing binaries from remote targets
GDB provides no indicator of progress during file operations, and can
appear to have locked up during slow remote transfers.  This commit
updates GDB to print a warning each time a file is accessed over RSP.
An additional message detailing how to avoid remote transfers is
printed for the first transfer only.

gdb/ChangeLog:

	* target.h (struct target_ops) <to_fileio_open>: New argument
	warn_if_slow.  Update comment.  All implementations updated.
	(target_fileio_open_warn_if_slow): New declaration.
	* target.c (target_fileio_open): Renamed as...
	(target_fileio_open_1): ...this.  New argument warn_if_slow.
	Pass warn_if_slow to implementation.  Update debug printing.
	(target_fileio_open): New function.
	(target_fileio_open_warn_if_slow): Likewise.
	* gdb_bfd.c (gdb_bfd_iovec_fileio_open): Use new function
	target_fileio_open_warn_if_slow.

gdb/testsuite/ChangeLog:

	* gdb.trace/pending.exp: Cope with remote transfer warnings.
2015-08-21 17:11:36 +01:00
Gary Benson f36b87190a Fix stale cleanup left by linux_mntns_access_fs
This commit fixes a stale cleanup left by linux_mntns_access_fs.

gdb/ChangeLog:

	* nat/linux-namespaces.c (linux_mntns_access_fs):
	Do not overwrite old_chain.
2015-08-21 16:56:22 +01:00
Max Filippov 40045d9181 xtensa: implement NPTL helpers
These changes allow debugging multithreaded NPTL xtensa applications.

2015-08-20  Max Filippov  <jcmvbkbc@gmail.com>
gdb/gdbserver/
	* configure.srv (xtensa*-*-linux*): Add srv_linux_thread_db=yes.
	* linux-xtensa-low.c (arch/xtensa.h gdb_proc_service.h): New
	#includes.
	(ps_get_thread_area): New function.

2015-08-20  Max Filippov  <jcmvbkbc@gmail.com>
gdb/
	* arch/xtensa.h: New file.
	* xtensa-linux-nat.c (gdb_proc_service.h): New #include.
	(ps_get_thread_area): New function.
	* xtensa-linux-tdep.c (xtensa_linux_init_abi): Add call to
	set_gdbarch_fetch_tls_load_module_address to enable TLS support.
	* xtensa-tdep.c (osabi.h): New #include.
	(xtensa_gdbarch_init): Call gdbarch_init_osabi to register
	xtensa-specific hooks.
	* xtensa-tdep.h (struct xtensa_elf_gregset_t): Add threadptr
	member and move the structure to arch/xtensa.h.
2015-08-21 15:39:40 +03:00
Pedro Alves 80152258b9 Add readahead cache to gdb's vFile:pread
This patch almost halves the time it takes to "target remote + run to
main" on a higher-latency connection.

E.g., I've got a ping time of ~85ms to an x86-64 machine on the gcc
compile farm (almost 2000km away from me), and I'm behind a ~16Mbit
ADSL.  When I connect to a gdbserver debugging itself on that machine
and run to main, it takes almost 55 seconds:

 [palves@gcc76] $ ./gdbserver :9999 ./gdbserver
 [palves@home] $ ssh -L 9999:localhost:9999 gcc76.fsffrance.org
 [palves@home] $ time ./gdb -data-directory=data-directory -ex "tar rem :9999" -ex "b main" -ex "c" -ex "set confirm off" -ex "quit"

 Pristine gdb 7.10.50.20150820-cvs gets us:
 ...
 Remote debugging using :9999
 Reading symbols from target:/home/palves/gdb/build/gdb/gdbserver/gdbserver...done.
 Reading symbols from target:/lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
 0x00007ffff7ddd190 in ?? () from target:/lib64/ld-linux-x86-64.so.2
 Breakpoint 1 at 0x41200c: file ../../../src/gdb/gdbserver/server.c, line 3635.
 Continuing.

 Breakpoint 1, main (argc=1, argv=0x7fffffffe3d8) at ../../../src/gdb/gdbserver/server.c:3635
 3635    ../../../src/gdb/gdbserver/server.c: No such file or directory.
 /home/palves/gdb/build/gdb/gdbserver/gdbserver: No such file or directory.

 real    0m54.803s
 user    0m0.329s
 sys     0m0.064s

While with the readahead cache added by this patch, it drops to:

 real    0m29.462s
 user    0m0.454s
 sys     0m0.054s

I added a few counters to show cache hit/miss, and got:

 readahead cache miss 142
 readahead cache hit 310

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-21  Pedro Alves  <palves@redhat.com>

	* remote.c (struct readahead_cache): New.
	(struct remote_state) <readahead_cache>: New field.
	(remote_open_1): Invalidate the cache.
	(readahead_cache_invalidate, readahead_cache_invalidate_fd): New
	functions.
	(remote_hostio_pwrite): Invalidate the readahead cache.
	(remote_hostio_pread): Rename to ...
	(remote_hostio_pread_vFile): ... this.
	(remote_hostio_pread_from_cache): New function.
	(remote_hostio_pread): Reimplement.
	(remote_hostio_close): Invalidate the readahead cache.
2015-08-21 10:13:27 +01:00
Marcin Cieslak 88fc5eb7e2 procfs.c: Include "filestuff.h"
Fixes implicit function declaration
error in gdb/procfs.c:4927 about undeclared
make_cleanup_close().

gdb/ChangeLog:

	PR build/18843
	* procfs.c: Include "filestuff.h".
2015-08-21 09:10:56 +01:00
Patrick Palka 6f1cb6eac2 Remove fields curch and cur_line from TUI_CMD_WIN
These fields are currently used to track the location of the cursor
inside the command window.  But their usefulness is questionable because
ncurses already internally keeps track of the location of the cursor,
whose coordinates we can query using the functions getyx(), getcurx() or
getcury().  It is an unnecessary pain to keep these fields in sync with
ncurses, and their meaning is not well-defined anyway.  For instance, it
is not clear whether the coordinates held in these fields are
authoritative, or whether the coordinates reported by ncurses are.

So to keep things simple, this patch removes these fields and replaces
existing reads of these fields with calls to the appropriate ncurses
querying functions, and replaces writes to these fields with calls to
wmove() (when necessary and applicable).

In the function tui_cont_sig(), I removed the call to wmove() entirely
because moving to (start_line, curch) makes no sense.  The move should
have been to (cur_line, curch) -- which would now be a no-op.

Tested on x86_64 Fedora 22, no obvious regressions.

gdb/ChangeLog:

	* tui/tui-data.h (tui_command_info): Remove fields cur_line and
	curch.
	* tui/tui-data.c (tui_clear_win_detail) [CMD_WIN]: Don't set
	cur_line or curch, instead call wmove().
	(init_win_info) [CMD_WIN]: Likewise.
	* tui/tui-io.c (tui_puts): Likewise. Don't read cur_line,
	instead call getcury().
	(tui_redisplay_readline): Don't set cur_line or curch.
	(tui_mld_erase_entire_line): Don't read cur_line, instead call
	getcury().
	(tui_cont_sig): Remove call to wmove.
	(tui_getc): Don't read cur_line or curch, instead call getcury()
	or getyx().  Don't set curch.
	* tui/tui-win.c (make_visible_with_new_height) [CMD_WIN]: Don't
	set cur_line or curch.  Always move cursor to (0,0).
2015-08-20 23:06:47 -04:00
Pedro Alves 0e433b3202 Fix gdb.server/solib-list.exp native-extended-gdbserver regression
Commit 221e1a37 (remote non-stop: Process initially stopped threads
before other commands) caused a test regression when testing with the
native-extended-gdbserver board:

  FAIL: gdb.server/solib-list.exp: non-stop 1: non-stop interior stop (timeout)

This "interior stop" now happens before "target remote" prints the
prompt, so we should no longer explicitly expect it.

gdb/testsuite/ChangeLog:
2015-08-20  Pedro Alves  <palves@redhat.com>

	* gdb.server/solib-list.exp: No longer expect an interior stop in
	non-stop mode.
2015-08-20 20:08:48 +01:00
Pedro Alves 221e1a37cd remote non-stop: Process initially stopped threads before other commands
The main motivation for this is making non-stop / all-stop behave
similarly on initial connection, in order to move in the direction of
reimplementing all-stop mode with the remote target always running in
non-stop mode.

When we connect to a remote target in non-stop mode, we may find
threads either running or already stopped.  The act of connecting
itself does not force threads to stop.  To handle that, the remote
non-stop connection is currently roughly like this:

 #1 - Fetch list of remote threads (qXfer:threads:read, qfThreadInfo,
    etc).  All threads are assumed to be running until the target
    reports an asynchronous stop reply for them.

 #2 - Fetch the initial set of threads that were already stopped, with
    the '?'  packet.  (In non-stop, this is coupled with the vStopped
    mechanism to be able to retrieve the status of more than one
    thread.)

The stop replies fetched in #2 are placed in the pending stop reply
queue, and left for the regular event loop to process.  That is,
"target remote" finishes and returns _before_ those stops are
processed.

That means that it's possible to have GDB process further commands
before the initial set of stopped threads is reported to the user.

E.g., before the patch, note how the prompt is printed before the
frame:

 Remote debugging using :9999
 (gdb)
 [Thread 15296] #1 stopped.
 0x0000003615a011f0 in ?? ()

Even though thread #1 was not running, for a moment, the user can see
it as such:

 $ gdb a.out -ex "set non-stop 1" -ex "tar rem :9999"  -ex "info threads" -ex "info registers"
 Remote debugging using :9999
   Id   Target Id         Frame
 * 1    Thread 4772       (running)
 Target is executing.                 <<<<<<< info registers
 (gdb)
 [Thread 4772] #1 stopped.
 0x0000003615a011f0 in ?? ()

To fix that, this commit makes gdb process all threads found already
stopped at connection time, before giving the prompt to the user.

The fix takes a cue from fork-child.c:startup_inferior [1], and
processes the events locally in remote.c, avoiding the whole
wait_for_inferior/handle_inferior_event path.  I decided to try this
approach after noticing that:

 - several cases in handle_inferior_event miss checking stop_soon.
 - we don't want to fetch the thread list in normal_stop.

and trying to fix them was resulting in sprinkling stop_soon checks in
many places, and uglifying normal_stop even more.

While with this patch, I'm avoiding changing GDB's output other than
when the prompt is printed, I think this approach is more flexible if
we do want to change it.  And also, it's likely easier to get rid of
the MI *running event that is still sent for threads that are
initially found stopped, if we want to.

This happens to fix the testsuite too.  All non-stop tests are racy
against "target remote" / gdbserver testing currently.  That is,
sometimes the tests run, but other times they're just skipped without
any indication of PASS/FAIL.  When that happens, the logs show:

 target remote localhost:2346
 Remote debugging using localhost:2346
 (gdb)
 [Thread 25418] #1 stopped.
 0x0000003615a011f0 in ?? ()
 ^CQuit
 (gdb) Remote debugging from host 127.0.0.1
 Killing process(es): 25418
 monitor exit
 (gdb) Remote connection closed
 (gdb) testcase /home/pedro/gdb/mygit/build/../src/gdb/testsuite/gdb.threads/multi-create-ns-info-thr.exp completed in 61 seconds

The trouble here is that there's output after the prompt, and the
regex in question doesn't expect that:

   -re "Remote debugging using .*$serialport_re.*$gdb_prompt $" {
	verbose "Set target to $targetname"
	return 0
    }

[1] - before startup_inferior was added, we'd go through
wait_for_inferior/handle_inferior_event while going through the shell,
and that turned out problematic.

Tested on x86_64 Fedora 20, gdbserver.

gdb/ChangeLog:
2015-08-20  Pedro Alves  <palves@redhat.com>

	* infrun.c (print_target_wait_results): Make extern.
	* infrun.h (print_target_wait_results): Declare.
	* remote.c (set_stop_requested_callback): Delete.
	(process_initial_stop_replies): New function.
	(remote_start_remote): Use it.
	(stop_reply_queue_length): New function.

gdb/testsuite/ChangeLog:
2015-08-20  Pedro Alves  <palves@redhat.com>

	* gdb.server/connect-stopped-target.c: New file.
	* gdb.server/connect-stopped-target.exp: New file.
2015-08-20 18:27:55 +01:00
Pedro Alves 40e3ad0ebb Fix language of compilation unit with unknown file extension
Here, in dwarfread.c:process_full_comp_unit:

      /* Set symtab language to language from DW_AT_language.  If the
	 compilation is from a C file generated by language preprocessors, do
	 not set the language if it was already deduced by start_subfile.  */
      if (!(cu->language == language_c
	    && COMPUNIT_FILETABS (cust)->language != language_c))
	COMPUNIT_FILETABS (cust)->language = cu->language;

in case start_subfile doesn't manage to deduce a language
COMPUNIT_FILETABS(cust)->language ends up as language_unknown, not
language_c.  So the condition above evals false and we never set the
language from the cu's language.

gdb/ChangeLog:
2015-08-20  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (process_full_comp_unit): To tell whether
	start_subfile managed to deduce a language, test for
	language_unknown instead of language_c.

gdb/testsuite/ChangeLog:
2015-08-20  Pedro Alves  <palves@redhat.com>

	* gdb.dwarf2/comp-unit-lang.exp: New file.
	* gdb.dwarf2/comp-unit-lang.c: New file.
2015-08-20 12:30:08 +01:00
Pierre-Marie de Rodat af39b3270a [Ada] Fix parsing for expressions with attributes and characters
Before this change, trying to evaluate the following Ada expression
yielded a syntax error, even though it's completely legal:

    (gdb) p s'first = 'a'
    Error in expression, near `'.

The problem lies in the lexer (gdb/ada-lex.l): at the point we reach "'a'",
we're still in the BEFORE_QUAL_QUOTE start condition (the mechanism to
distinguish character literals from other "tick" usages: qualified
expressions and attributes), so we consider that this quote is actually a
separate "tick".

This changes resets the start condition to INITIAL in the
{TICK}[a-zA-Z][a-zA-Z]+ rule (for attributes): attributes activate this
BEFORE_QUAL_QUOTE condition and in this case the above rule is always
executed rather than the <BEFORE_QUAL_QUOTE>"'" one (in flex, it's
always the longest match that is chosen). We now have instead:

    (gdb) p s'first = 'a'
    $1 = true

gdb/ChangeLog:

	* ada-lex.l: Reset the start condition to INITIAL in the rule
	that matches attributes.

gdb/testsuite/ChangeLog:

	* gdb.ada/attr_ref_and_charlit.exp: New testcase.
	* gdb.ada/attr_ref_and_charlit/foo.adb: New file.

Tested on x86_64-linux, no regression.
2015-08-20 10:12:24 +02:00
Kevin Buettner 7d45c7c3f6 dwarf2read.c: Check type of string valued attributes prior to decoding.
This change introduces a new function, dwarf2_string_attr(), which is
a wrapper for dwarf2_attr().  dwarf2read.c has been updated to
call dwarf2_string_attr in most instances where a string-valued
attribute is decoded to produce a string value.  In most cases, it
simplifies the code; in some instances, the complexity of the code
remains unchanged.

I performed this change by looking for instances where the
result of DW_STRING was used in an assignment.  Many of these
had a pattern which (roughly) looks something like this:

  struct attribute *attr = NULL;

  attr = dwarf2_attr (die, name, cu);
  if (attr != NULL && DW_STRING (attr))
    {
      const char *str;
      ...
      str = DW_STRING (attr);
      ... /* Use str in some fashion.  */
    }

Code of this form is transformed to look like this instead:

  const char *str;

  str = dwarf2_string_attr (die, name, cu)
  if (str != NULL)
    {
       ...
       /* Use str in some fashion.  */
       ...
    }

In addition to invoking dwarf2_attr() and DW_STRING(),
dwarf2_string_attr() checks to make sure that the attribute's
`form' field matches one of DW_FORM_strp, DW_FORM_string, or
DW_FORM_GNU_strp_alt.  If it does not match one of these forms,
it will return a NULL value in addition to calling complaint().

An earlier version of this patch did this type checking for one
particular instance where a string attribute was being decoded.
The situation that I was attempting to handle in that earlier patch is
this:

The Texas Instruments compiler uses the encoding for
DW_AT_MIPS_linkage_name for other purposes.  TI uses the encoding,
0x2007, for TI_AT_TI_end_line which, unlike DW_AT_MIPS_linkage_name,
does not have a string-typed value.  In this instance, GDB was attempting
to use an integer value as a string pointer, with predictable results.
(GDB would die with a segmentation fault.)

I've added a test which reproduces the problem that I was orignally
wanting to fix.  It uses DW_AT_MIPS_linkage name with an associate
value which is a string, and again, where the value is a small
integer.

My test case causes GDB to segfault in an unpatched GDB.  There
will be two PASSes in a patched GDB.

Unpatched GDB:

(gdb) ptype f
ERROR: Process no longer exists
UNRESOLVED: gdb.dwarf2/dw2-bad-mips-linkage-name.exp: ptype f
ERROR: Couldn't send ptype g to GDB.
UNRESOLVED: gdb.dwarf2/dw2-bad-mips-linkage-name.exp: ptype g

Patched GDB:

(gdb) ptype f
type = bool ()
(gdb) PASS: gdb.dwarf2/dw2-bad-mips-linkage-name.exp: ptype f
ptype g
type = bool ()
(gdb) PASS: gdb.dwarf2/dw2-bad-mips-linkage-name.exp: ptype g

I see no regressions on an x86_64 native target.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_string_attr): New function.
	(lookup_dwo_unit, process_psymtab_comp_unit_reader)
	(dwarf2_compute_name, dwarf2_physname, find_file_and_directory)
	(read_call_site_scope, namespace_name, guess_full_die_structure_name)
	(anonymous_struct_prefix, prepare_one_comp_unit): Use
	dwarf2_string_attr in place of dwarf2_attr and DW_STRING.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-bad-mips-linkage-name.c: New file.
	* gdb.dwarf2/dw2-bad-mips-linkage-name.exp: New file.
2015-08-19 11:48:13 -07:00
Gary Benson 45face3ba1 Prelimit number of bytes to read in "vFile:pread:"
While handling "vFile:pread:" packets, gdbserver would read the
number of bytes requested regardless of whether this would fit
into the reply packet.  gdbserver would then return a packet's
worth of data and discard the remainder.  When accessing large
binaries GDB (via BFD) routinely makes large "vFile:pread:"
requests, resulting in gdbserver allocating large unnecessary
buffers and reading some portions of the file many times over.

This commit causes gdbserver to limit the number of bytes to be
read to a sensible maximum prior to allocating buffers and reading
data.

gdb/gdbserver/ChangeLog:

	* hostio.c (handle_pread): Do not attempt to read more data
	than hostio_reply_with_data can fit in a packet.
2015-08-19 13:53:24 +01:00
Joel Brobecker 16d5f64295 gdbserver/linux-aarch32-low: build failure when NT_ARM_VFP not defined
On some older versions of GNU/Linux, gdbserver now fails to build
due to an undefined reference to NT_ARM_VFP. Same issue on Android,
where this macros is undefined until Android API level 21 (Android
5.0 "Lollipop").

This patch modifies linux-aarch32-low.c to define that macros when
not already defined.

gdb/gdbserver/ChangeLog:

        * linux-aarch32-low.c (NT_ARM_VFP): Define if not already defined.
2015-08-18 18:41:31 -04:00
Doug Evans 4d6cceb4e4 PR mi/18833 gdb.execute ("set param value", to_string=True) will crash gdb if using MI
gdb/ChangeLog:

	* cli/cli-logging.c (pop_output_files): Don't restore redirection
	if MI-like.
	* mi/mi-out.c: #include "vec.h".
	(ui_filep): New type.
	(DEV_VEC_P (ui_filep)): New type.
	(struct ui_out_data) <buffer, original_buffer>: Delete.
	(struct ui_out_data) <streams>: New member.
	(mi_ui_out_impl): Add data_destroy field.
	(mi_field_string, mi_field_fmt): Update.
	(mi_flush, mi_redirect, field_separator): Update.
	(mi_open, mi_close): Update.
	(mi_out_buffered, mi_out_rewind, mi_out_put): Update.
	(mi_out_data_ctor, mi_out_data_dtor): New functions.
	(mi_out_new): Call mi_out_data_ctor.

testsuite/gdb/ChangeLog:

	* lib/gdb.exp (skip_python_tests_prompt): Renamed from
	skip_python_tests.  New arg prompt_regexp.
	(skip_python_tests): New function.
	* lib/mi-support.exp (mi_skip_python_tests): New function.
	* gdb.python/py-mi-objfile-gdb.py: New file.
	* gdb.python/py-mi-objfile.c: New file.
	* gdb.python/py-mi-objfile.exp: New file.
2015-08-18 14:02:03 -07:00
Sandra Loosemore 26d56a939e Fix mis-parsing of hex register numbers in 'T' stop replies.
2015-08-18  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* remote.c (strprefix): New.
	(remote_parse_stop_reply): Use strprefix instead of strncmp
	to ensure exact match of keyword.
2015-08-18 10:29:54 -07:00
Andrew Burgess 2b4bf6afd4 gdb/doc: Fix build of 'info' manual.
In commit 18989b3c56 I broke the creation
of gdb's info manual; I added a new section without adding a suitable
menu entry.

This commit adds the missing menu entry and fixes the build of gdb's
info manual.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB Files): Add 'File Caching' menu entry.
2015-08-18 17:09:41 +01:00
Andrew Burgess 566f5e3b38 gdb: Add debug tracing for bfd cache activity.
This patch adds a new debug flag bfd-cache, which when set to non-zero
produces debugging log messages relating to gdb's bfd cache.

gdb/ChangeLog:

	* gdb_bfd.c (debug_bfd_cache): New variable.
	(show_bfd_cache_debug): New function.
	(gdb_bfd_open): Add debug logging.
	(gdb_bfd_ref): Likewise.
	(gdb_bfd_unref): Likewise.
	(_initialize_gdb_bfd): Add new set/show command.
	* NEWS: Mention new command.

gdb/doc/ChangeLog:

	* gdb.texinfo (File Caching): Document "set/show debug bfd-cache".
2015-08-18 14:03:14 +01:00
Andrew Burgess 18989b3c56 gdb: New maintenance command to disable bfd sharing.
In some rare maintainer cases it is desirable to be able to disable bfd
sharing.  This patch adds new commands maintenance set/show commands for
bfd-sharing, allowing gdb's bfd cache to be turned off.

gdb/ChangeLog:

	* gdb_bfd.c (bfd_sharing): New variable.
	(show_bfd_sharing): New function.
	(gdb_bfd_open): Check bfd_sharing variable.
	(_initialize_gdb_bfd): Add new set/show command.
	* NEWS: Mention new command.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Move documentation of "main
	info bfds" to...
	(File Caching): A New section.  Outline bfd caching, and add new
	description for "main set/show bfd-sharing".
2015-08-18 14:03:14 +01:00
Andrew Burgess c04fe68f6b gdb: Improve cache matching criteria for the bfd cache.
Within gdb open bfd objects are reused where possible if an attempt is
made to reopen a file that is already being debugged.  To spot if the on
disc file has changed gdb currently examines the mtime of the file and
compares it to the mtime of the open bfd in the cache.

A problem exists when the on disc file is being rapidly regenerated, as
happens, for example, with automated testing.  In some cases the file is
generated so quickly that the mtime appears not to change, while the on
disc file has changed.

This patch extends the bfd cache to also hold the file size of the file,
the inode of the file, and the device id of the file; gdb can then
compare filename, file size, mtime, inode, and device id to determine if
an existing bfd object can be reused.

gdb/ChangeLog:

	* gdb_bfd.c (struct gdb_bfd_data): Add size, inode, and device id
	field.
	(struct gdb_bfd_cache_search): Likewise.
	(eq_bfd): Compare the size, inode, and device id fields.
	(gdb_bfd_open): Initialise the size, inode, and device id fields.
	(gdb_bfd_ref): Likewise.
	(gdb_bfd_unref): Likewise.
2015-08-18 14:03:14 +01:00
Pedro Alves b2a3343990 x86/Linux: disable all-stop on top of non-stop
Markus reported that ASNS breaks target record-btrace.  In particular,
the gdb.btrace/multi-thread-step.exp test fails (both with BTS and PT
tracing) with a crash in py-inferior.c:

 Program received signal SIGSEGV, Segmentation fault.

 0x00000000006aa40d in add_thread_object (tp=0x27d32d0)

     at /users/mmetzger/team/gdb/git/gdb/python/py-inferior.c:337

 337       entry->next = inf_obj->threads;

My machine doesn't support BTS nor PT, so I missed this...

Disabling ASNS temporarily on x86 until this is addressed.

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-18  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (linux_nat_always_non_stop_p): If the linux_ops
	target implements to_always_non_stop_p, call it.
	* x86-linux-nat.c (x86_linux_always_non_stop_p): New function.
	(x86_linux_create_target): Install it as to_always_non_stop_p
	method.
2015-08-18 11:04:30 +01:00
Doug Evans 71b57e37fe ui-out.c (default_ui_out_impl): Add comment.
gdb/ChangeLog:

	* ui-out.c (default_ui_out_impl): Add comment.
2015-08-17 13:07:11 -07:00
Iain Buclaw 7f3706ebfe [D] Implement looking up members of D enums.
In D, all named enums are explicitly scoped (the C++ equivalent of enum class)
so they should be handled as such in the language-specific symbol lookup
routines.  However so as to support D compilers that don't emit enums as
DW_AT_enum_class, need to make sure that appropriate checks for
TYPE_DECLARED_CLASS are done.

gdb/ChangeLog

	* d-exp.y (type_aggregate_p): New function.
	(PrimaryExpression : TypeExp '.' IdentifierExp): Use it.
	(classify_inner_name): Likewise.
	* d-namespace.c (d_lookup_nested_symbol): Handle TYPE_CODE_ENUM.
2015-08-17 21:53:47 +02:00
Keith Seitz ad89c2aa67 Move strace -m/explicit location test to strace.exp
One of the build slaves shows this error running explicit.exp:

(gdb) strace -m gdbfoobarbaz
Remote failure reply: E.In-process agent library not loaded in process.
Fast and static tracepoints unavailable.
(gdb) FAIL: gdb.linespec/explicit.exp: strace -m gdbfoobarbaz

There are two big problems with this test:
1) The expected output is actually not what the test is meant to test for.
2) This test should really only run where it is supported.

This is most easily fixed by moving the test to gdb.trace/strace.exp.

gdb/testsuite/ChangeLog

	* gdb.linespec/explicit.exp: Move strace test from here ...
	* gdb.trace/strace.exp: ... to here.
2015-08-17 11:57:01 -07:00
Doug Evans 1762568fd6 psymtab.c (add_psymbol_to_bcache): Remove "val" arg.
gdb/ChangeLog:

	* psymtab.c (add_psymbol_to_bcache): Remove "val" arg.  All callers
	updated.
	(add_psymbol_to_list): Ditto.
2015-08-15 22:08:47 -07:00
Doug Evans 8763cedeec Add end_psymtab_common, have all debug info readers call it.
gdb/ChangeLog:

	* dbxread.c (dbx_end_psymtab): Renamed from end_psymtab.  All callers
	updated.  Call end_psymtab_common.
	* dwarf2read.c (process_psymtab_comp_unit_reader): Call
	end_psymtab_common.
	(build_type_psymtabs_reader): Ditto.
	* psympriv.h (sort_pst_symbols): Delete.
	(end_psymtab_common): Declare.
	* psymtab.c (sort_pst_symbols): Make static.
	(end_psymtab_common): New function.
	* xcoffread.c (xcoff_end_psymtab): Call end_psymtab_common.
2015-08-15 16:46:20 -07:00
Doug Evans 51cdc99310 Use macros for some enum bit field sizes.
gdb/ChangeLog:

	* defs.h (LANGUAGE_BITS): Define.
	* psympriv.h (partial_symbol) <domain>: Use SYMBOL_DOMAIN_BITS.
	(partial_symbol) <aclass>: Use SYMBOL_ACLASS_BITS.
	* symtab.h (general_symbol_info> <language>: Usage LANGUAGE_BITS.
	(minimal_symbol_type): Add nr_minsym_types.
	(MINSYM_TYPE_BITS): Define.
	(minimal_symbol) <type>: Use MINSYM_TYPE_BITS.
	(domain_enum_tag): Add NR_DOMAINS.
	(SYMBOL_DOMAIN_BITS): Change from 4 to 3.
	(SYMBOL_ACLASS_BITS): Define from 6 to 5.
2015-08-15 16:25:53 -07:00
Doug Evans 95cf586902 objfiles.h,psympriv.h,psymtab.c: Whitespace.
gdb/ChangeLog:

	* objfiles.h: Whitespace cleanup.
	* psympriv.h: Whitespace cleanup.
	* psymtab.c: Whitespace/coding convention cleanup.
2015-08-15 15:51:00 -07:00
Patrick Palka e3ae3c4345 Fix invoking "[kill|detach] inferiors" on inferiors that are not running
Invoking either of the above commands on an inferior that's not running
triggers the following assert failure:

  .../binutils-gdb/gdb/thread.c:514: internal-error: any_thread_of_process: Assertion `pid != 0' failed.

The fix is straightforward.  This patch also adds a test to check the
basic functionality of these commands, along with testing this fix in
particular.  Tested on x86_64 Linux.

gdb/ChangeLog:

	* inferior.c (detach_inferior_command): Don't call
	any_thread_of_process when pid is 0.
	(kill_inferior_command): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.base/kill-detach-inferiors-cmd.exp: New test file.
	* gdb.base/kill-detach-inferiors-cmd.c: New test file.
2015-08-15 13:32:47 -04:00
Doug Evans 604b263620 perftest/utils.py (select_file): Kill any existing inferior before selecting a new file.
gdb/testsuite/ChangeLog:

	* gdb.perf/lib/perftest/utils.py (select_file): Kill any existing
	inferior before selecting a new file.
2015-08-14 23:29:04 -07:00
Doug Evans 6ff0ba5f7b New /s modifier for the disassemble command.
The "source centric" /m option to the disassemble command is often
unhelpful, e.g., in the presence of optimized code.
This patch adds a /s modifier that is better.
For one, /m only prints instructions from the originating source file,
leaving out instructions from e.g., inlined functions from other files.

gdb/ChangeLog:

	PR gdb/11833
	* NEWS: Document new /s modifier for the disassemble command.
	* cli/cli-cmds.c (disassemble_command): Add support for /s.
	(_initialize_cli_cmds): Update online docs of disassemble command.
	* disasm.c: #include "source.h".
	(struct deprecated_dis_line_entry): Renamed from dis_line_entry.
	All uses updated.
	(dis_line_entry): New struct.
	(hash_dis_line_entry, eq_dis_line_entry): New functions.
	(allocate_dis_line_table): New functions.
	(maybe_add_dis_line_entry, line_has_code_p): New functions.
	(dump_insns): New arg end_pc.  All callers updated.
	(do_mixed_source_and_assembly_deprecated): Renamed from
	do_mixed_source_and_assembly.  All callers updated.
	(do_mixed_source_and_assembly): New function.
	(gdb_disassembly): Handle /s (DISASSEMBLY_SOURCE).
	* disasm.h (DISASSEMBLY_SOURCE_DEPRECATED): Renamed from
	DISASSEMBLY_SOURCE.  All uses updated.
	(DISASSEMBLY_SOURCE): New macro.
	* mi/mi-cmd-disas.c (mi_cmd_disassemble): New modes 4,5.

gdb/doc/ChangeLog:

	* gdb.texinfo (Machine Code): Update docs for mixed source/assembly
	disassembly.
	(GDB/MI Data Manipulation): Update docs for new disassembly modes.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp: Update.
	* gdb.base/disasm-optim.S: New file.
	* gdb.base/disasm-optim.c: New file.
	* gdb.base/disasm-optim.h: New file.
	* gdb.base/disasm-optim.exp: New file.
2015-08-14 21:45:54 -07:00
Keith Seitz b56ccc202a Rename `typename' in d-exp.y to avoid C++ reserved word
A recent patch introduced a variable named `typename' into d-exp.y,
and one of the --enable-with-cxx build slaves consequently failed to compile
this.  This patch simply adds an underscore into the name to avoid the
reserved word.

gdb/ChangeLog

	* d-exp.y (PrimaryExpression : TypeExp '.' IdentifierExp): Rename
	`typename' to `type_name' to avoid C++ reserved word.
2015-08-14 17:28:11 -07:00
Keith Seitz ebdad8fc7f Rename location accessor macro parameters to silence ARI
The locations patch I recently committed contains macro definitions
such as:

This causes an ARI error to be emitted by the server ("Do not use PTR, ISO C
90 implies `void *'").  While this ARI error is bogus in this context,
it is just easiest to squash the error completely by renaming the macro
parameters.

gdb/ChangeLog

	* location.c (EL_TYPE, EL_LINESPEC, EL_PROBE, EL_ADDRESS)
	(EL_EXPLICIT, EL_STRING): Change macro parameter to "P" to
	silence ARI errors.
2015-08-14 15:04:58 -07:00
Keith Seitz 9ca98f9278 Add missing ChangeLog entry for previous commit. 2015-08-14 14:54:37 -07:00
Keith Seitz 6613eb10d1 mi_make_breakpoint: add "evaluated-by" option
For some time now, GDB has permitted target-side evaluation of
breakpoint conditions.  On targets that support this feature, GDB
may output an "evaluated-by" field into the breakpoint reply.

This patch adds handling for this option, and outputs a default
pattern to optionally recognize (and ignore) this pattern in the
reply.

gdb/testsuite/ChangeLog

	* lib/mi-support.exp (mi_make_breakpoint): Add option/handling for
	"evaluated-by".
2015-08-14 13:45:06 -07:00
Iain Buclaw c0fe2ae706 Fix ARI warnings in d-exp.y
This fixes four ARI warnings found in d-exp.y.

This is comprised of three uses of the && or || at the end of a line, and one
use of sprintf.

gdb/ChangeLog

	* d-exp.y (PrimaryExpression : TypeExp '.' IdentifierExp): Use
	xstrprintf instead of malloc and sprintf.
	(PrimaryExpression : IdentifierExp): Avoid operator at end of line.
	(lex_one_token): Likewise.
2015-08-14 21:26:17 +02:00
Matthew Fortune a738da3abe Add support for DT_MIPS_RLD_MAP_REL.
This tag allows debugging of MIPS position independent executables
and provides access to shared library information.

gdb/gdbserver/

	* linux-low.c (get_r_debug): Handle DT_MIPS_RLD_MAP_REL.

gdb/

	* solib-svr4.c (read_program_header): Add base_addr argument to
	report the runtime address of the segment.
	(find_program_interpreter): Update read_program_header call to pass
	a NULL pointer for the new argument.
	(scan_dyntag): Add ptr_addr argument to report the runtime address
	of the tag payload.
	(scan_dyntag_auxv): Likewise and use thew new base_addr argument of
	read_program_header to get the base address of the dynamic segment.
	(elf_locate_base): Update uses of scan_dyntag, scan_dyntag_auxv and
	read_program_header.
	(elf_locate_base): Scan for and handle DT_MIPS_RLD_MAP_REL.
2015-08-14 13:11:21 +01:00
Matthew Fortune f8edc4ff05 Add myself to gdb MAINTAINERS
gdb/
	* MAINTAINERS (Write After Approval): Add Matthew Fortune.
2015-08-14 13:07:23 +01:00
Iain Buclaw 444c1ed891 [D] Move classification of symbols from the grammar to the lexer.
This makes it so that alternating '.' and identifier tokens are resolved to
symbols as early as possible, which should all the addition of D properties -
such as EXP.sizeof and EXP.typeof - without the shift/reduce conflicts that
would occur in the current parsing strategy.

gdb/ChangeLog

	* d-exp.y (%union): Add voidval.
	(%token): Add UNKNOWN_NAME as a token to represent an unclassified
	name in the lexing stage.
	(PostfixExpression): Move symbol completion handling in grammar here
	from PrimaryExpression.
	(PrimaryExpression): Move routines to handle resolving identifier
	tokens in the grammar here from push_expression_name.
	(IdentifierExp): Remove the handling of alternating '.' and identifier
	tokens.
	(TypeExp): Allow TypeExp to be wrapped in parenthesis in the grammar.
	(BasicType): Remove C-style typename rules.
	(d_type_from_name, d_module_from_name, push_variable)
	(push_fieldnames, push_type_name, push_module_name)
	(push_expression_name): Remove.
	(lex_one_token): Rename from yylex.  Replace pstate with par_state.
	(token_and_value): New type.
	(token_fifo, popping, name_obstack): New globals.
	(classify_name): New function.
	(classify_inner_name): Likewise.
	(yylex): Likewise.
	(d_parse): Initialize token_fifo, popping and name_obstack.
2015-08-13 21:48:06 +02:00
Iain Buclaw bc7c9fab61 [D] Support looking up symbols in the current and imported modules.
In D, there is the notion of modules, and importing from one to the other,
whether it is a basic, selective or renamed import declaration.

	module A;
	import X;
	void foo() {
	  import Y : bar;
	}

If the compiler emits DW_TAG_imported_declaration at the appropriate locations,
then we can make use of what gdb stores in using_direct when performing
nonlocal symbol lookups.

gdb/ChangeLog

	* Makefile.in (SFILES): Add d-namespace.c.
	(COMMON_OBS): Add d-namespace.o.
	* d-lang.c (d_language_defn): Use d_lookup_symbol_nonlocal as the
	la_lookup_symbol_nonlocal callback function pointer.
	* d-lang.h (d_lookup_symbol_nonlocal): New declaration.
	(d_lookup_nested_symbol): New declaration.
	* d-namespace.c: New file.
2015-08-13 21:07:09 +02:00
Joel Brobecker 52bbc56052 gdb.base/dso2dso.exp: Improve testcase documentation.
gdb/testsuite/ChangeLog:

        * gdb.base/dso2dso.exp: Improve the testcase's documentation.
2015-08-13 11:16:24 -07:00
Pedro Alves 3207396b95 Fix Python frame unwinder issue caught by Valgrind
Valgrind shows:

 ==17026== Invalid write of size 8
 ==17026==    at 0x54AA80: pending_frame_invalidate (py-unwind.c:477)
 ==17026==    by 0x5AB934: do_my_cleanups (cleanups.c:155)
 ==17026==    by 0x5AB9AF: do_cleanups (cleanups.c:177)
 ==17026==    by 0x54B009: pyuw_sniffer (py-unwind.c:606)
 ==17026==    by 0x755DAC: frame_unwind_try_unwinder (frame-unwind.c:105)
 ==17026==    by 0x755EEE: frame_unwind_find_by_frame (frame-unwind.c:160)
 ==17026==    by 0x750FFA: compute_frame_id (frame.c:454)
 ==17026==    by 0x753BD6: get_prev_frame_if_no_cycle (frame.c:1781)
 ==17026==    by 0x754292: get_prev_frame_always_1 (frame.c:1955)
 ==17026==    by 0x7542DA: get_prev_frame_always (frame.c:1971)
 ==17026==    by 0x7547BE: get_prev_frame (frame.c:2213)
 ==17026==    by 0x7532BD: unwind_to_current_frame (frame.c:1450)
 ==17026==  Address 0xd27b570 is 16 bytes inside a block of size 32 free'd
 ==17026==    at 0x4A07577: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
 ==17026==    by 0x54B276: gdb_Py_DECREF (python-internal.h:185)
 ==17026==    by 0x54B298: py_decref (py-utils.c:34)
 ==17026==    by 0x5AB934: do_my_cleanups (cleanups.c:155)
 ==17026==    by 0x5AB9AF: do_cleanups (cleanups.c:177)
 ==17026==    by 0x54B009: pyuw_sniffer (py-unwind.c:606)
 ==17026==    by 0x755DAC: frame_unwind_try_unwinder (frame-unwind.c:105)
 ==17026==    by 0x755EEE: frame_unwind_find_by_frame (frame-unwind.c:160)
 ==17026==    by 0x750FFA: compute_frame_id (frame.c:454)
 ==17026==    by 0x753BD6: get_prev_frame_if_no_cycle (frame.c:1781)
 ==17026==    by 0x754292: get_prev_frame_always_1 (frame.c:1955)
 ==17026==    by 0x7542DA: get_prev_frame_always (frame.c:1971)
 ==17026==

Simply invalidate the object before releasing it.

gdb/ChangeLog:
2015-08-13  Pedro Alves  <palves@redhat.com>

	* python/py-unwind.c (pyuw_sniffer): Install the invalidate
	cleanup after the decref cleanup, not before.
2015-08-13 18:56:42 +01:00
Keith Seitz 6799407467 Mass rename `explicit' -> `explicit_loc'.
BuildBot reminded me that "explicit" is a reserved keyword in C++.
This patch simply renames all the (illegal) uses of "explicit". This should
fix the build errors with --enable-build-with-cxx bots.

gdb/ChangeLog

	* break-catch-throw.c (re_set_exception_catchpoint) Rename
	reserved C++ keyword "explicit" to "explicit_loc".
	* breakpoint.c (create_overlay_event_breakpoint)
	(create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint, update_static_tracepoint):
	Rename reserved C++ keyword "explicit" to "explicit_loc".
	* completer.c (collect_explicit_location_matches)
	(explicit_location_completer): Rename reserved C++ keyword
	"explicit" to "explicit_loc".
	* linespec.c (struct linespec) <explicit>: Rename to "explicit_loc".
	(canonicalize_linespec, create_sals_line_offset)
	(convert_linespec_to_sals, convert_explicit_location_to_sals)
	(event_location_to_sals, decode_objc): Rename reserved C++ keyword
	"explicit" to "explicit_loc".
	* location.c (struct event_location) <explicit>: Rename to
	"explicit_loc".
	(initialize_explicit_location, new_explicit_location)
	(explicit_location_to_string_internal, explicit_location_to_linespec):
	Rename reserved C++ keyword "explicit" to "explicit_loc".
	* location.h (explicit_location_to_string)
	(explicit_location_to_linespec, initialize_explicit_location)
	(new_explicit_location): Rename reserved C++ keyword "explicit"
	to "explicit_loc".
	* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Rename reserved C++
	keyword "explicit" to "explicit_loc".
2015-08-13 09:48:12 -07:00
Pierre-Marie de Rodat 5d8c3ed327 Add ChangeLog entries for the previous commit 2015-08-13 09:54:09 +02:00
Pierre-Marie de Rodat 22cee43f9a [Ada] Add support for subprogram renamings
Consider the following declaration:

    function Foo (I : Integer) return Integer renames Pack.Bar;

As Foo is not materialized as a routine whose name is derived from Foo,
GDB currently cannot use it:

    (gdb) print foo(0)
    No definition of "foo" in current context.

However, compilers can emit DW_TAG_imported_declaration in order to
materialize the fact that Foo is actually another name for Pack.Bar.
This commit enhances the DWARF reader to record global renamings (it
used to put global ones in a static block) and enhances the Ada engine
to leverage this information during symbol lookup.

gdb/ChangeLog:

	* ada-lang.c: Include namespace.h
	(aux_add_nonlocal_symbols): Fix a function name in comment.
	(ada_add_block_renamings): New.
	(add_nonlocal_symbols): Add global renamings handling.
	(ada_lookup_symbol_list_worker): Move the symbol lookup part
	to...
	(ada_add_all_symbols): ... this new function.
	(ada_add_block_symbols): Try to match the input name against the
	"using directives list", perform a recursive symbol lookup on
	the matched declarations.
	* block.h (struct block): Move the_namespace to top-level as
	namespace_info. Remove the language_specific field.
	(BLOCK_NAMESPACE): Update access to the namespace_info field.
	* buildsym.h (using_directives): Rename into...
	(local_using_directives): ... this.
	(global_using_directives): New.
	(struct context_stack): Rename the using_directives field into
	local_using_directives.
	* buildsym.c (finish_block_internal): Deal with the proper
	using directives repository (local or global).
	(prepare_for_building): Reset local_using_directives. Assert
	that there is no pending global using directive.
	(reset_symtab_globals): Reset global_using_directives and
	local_using_directives.
	(end_symtab_get_static_block): Don't ignore symtabs that have
	only using directives.
	(push_context): Update references to local_using_directives.
	(buildsym_init): Do not reset using_directives.
	* cp-support.c: Include namespace.h.
	* cp-support.h (struct using_direct): Move to namespace.h.
	(cp_add_using_directives): Move to namespace.h.
	* cp-namespace.c: Include namespace.h
	(cp_add_using_directive): Move to namespace.c, rename it to
	add_using_directive, add a "using_directives" argument and use
	it as the pending using directives repository.  All callers
	updated.
	* dwarf2read.c (using_directives): New.
	(read_import_statement): Call using_directives.
	(read_func_scope): Update references to local_using_directives.
	(read_lexical_block_scope): Likewise.
	(read_namespace): Update the heading comment, call
	using_directives.
	* namespace.h: New file.
	* namespace.c: New file.
	* Makefile.in (SFILES): Add namespace.c.
	(COMMON_OBS): Add namespace.o

gdb/testsuite/ChangeLog:

	* gdb.ada/fun_renaming.exp: New testcase.
	* gdb.ada/fun_renaming/fun_renaming.adb: New file.
	* gdb.ada/fun_renaming/pack.adb: New file.
	* gdb.ada/fun_renaming/pack.ads: New file.

Tested on x86_64-linux.  Support for this in GCC is in the pipeline: see
<https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02166.html>.
2015-08-13 09:33:42 +02:00
Keith Seitz ea8812bcea gdb.base/dso2dso.exp sometimes broken
Keith reported that gdb.base/dso2dso.exp is broken, with the following
error:

| $ make check RUNTESTFLAGS=dso2dso.exp
| [snip]
| Running ../../../src/gdb/testsuite/gdb.base/dso2dso.exp ...
| ERROR: tcl error sourcing ../../../src/gdb/testsuite/gdb.base/dso2dso.exp.
| ERROR: couldn't open
| "../../../src/gdb/testsuite/gdb.base/../../../src/gdb/testsuite/gdb.base/dso2dso-dso1.c":
| no such file or directory
|     while executing
| "error "$message""
|     (procedure "gdb_get_line_number" line 14)
|     invoked from within
| "gdb_get_line_number "STOP HERE" $srcfile_libdso1"
|     (file "../../../src/gdb/testsuite/gdb.base/dso2dso.exp" line 60)
|     invoked from within
| "source ../../../src/gdb/testsuite/gdb.base/dso2dso.exp"
|     ("uplevel" body line 1)
|     invoked from within
| "uplevel #0 source ../../../src/gdb/testsuite/gdb.base/dso2dso.exp"
|     invoked from within
| "catch "uplevel #0 source $test_file_name""

This happens because gdb_get_line_number will prepend $srcdir/$subdir
if the given filename does not start with "/", and this happens when
GDB was configured using a relative path to the configure script.
When using an absolute path like I do, we avoid the pre-pending that
Keith is seeing.

gdb/testsuite/ChangeLog:

        Keith Seitz  <keiths@redhat.com>:
        * gdb.base/dso2dso.exp: Pass basename of source file in call
        to gdb_get_line_number.

Tested on x86_64-linux with both scenarios.
2015-08-12 18:47:46 -07:00
Joel Brobecker 4dafcdeb13 [amd64] Invalid return address after displaced stepping
Making all-stop run on top of non-stop caused a small regression
in behavior. This was observed on x86_64-linux. The attached testcase
is in C whereas the investigation was done with an Ada program,
but it's the same scenario, and using a C testcase allows wider testing.
Basically: I am debugging a single-threaded program, and currently
stopped inside a function provided by a shared-library, at a line
calling a subprogram provided by a second shared library, and trying
to "next" over that function call.

Before we changed the default all-stop behavior, we had:

    7             Impl_Initialize;  -- Stop here and try "next" over this line
    (gdb) n
    8             return 5;  <<-- OK

But now, "next" just stops much earlier:

    (gdb) n
    0x00007ffff7bd8560 in impl.initialize@plt () from /[...]/lib/libpck.so

What happens is that next stops at a call instruction, which calls
the function's PLT, and GDB fails to notice that the inferior stepped
into a subroutine, and so decides that we're done. We can see another
symptom of the same issue by looking at the backtrace at the point
GDB stopped:

    (gdb) bt
    #0  0x00007ffff7bd8560 in impl.initialize@plt ()
       from /[...]/lib/libpck.so
    #1  0x00000000f7bd86f9 in ?? ()
    #2  0x00007fffffffdf50 in ?? ()
    #3  0x0000000000401893 in a () at /[...]/a.adb:7
    Backtrace stopped: frame did not save the PC

With a functioning GDB, the backtrace looks like the following instead:

    #0  0x00007ffff7bd8560 in impl.initialize@plt ()
       from /[...]/lib/libpck.so
    #1  0x00007ffff7bd86f9 in sub () at /[...]/pck.adb:7
    #2  0x0000000000401893 in a () at /[...]/a.adb:7

Note how, for frame #1, the address looks quite similar, except
for the high-order bits not being set:

    #1  0x00007ffff7bd86f9 in sub () at /[...]/pck.adb:7   <<<--  OK
    #1  0x00000000f7bd86f9 in ?? ()                        <<<--  WRONG
              ^^^^
              ||||
              Wrong

Investigating this further led me to displaced stepping.
As we are "next"-ing from a location where a breakpoint is inserted,
we need to step out of it, and since we're on non-stop mode, we need
to do it using displaced stepping. And looking at
amd64-tdep.c:amd64_displaced_step_fixup, I found the code that handles
the return address:

    regcache_cooked_read_unsigned (regs, AMD64_RSP_REGNUM, &rsp);
    retaddr = read_memory_unsigned_integer (rsp, retaddr_len, byte_order);
    retaddr = (retaddr - insn_offset) & 0xffffffffUL;

The mask used to compute retaddr looks wrong to me, keeping only
4 bytes instead of 8, and explains why the high order bits of
the backtrace are unset. What happens is that, after the displaced
stepping has completed, GDB restores that return address at the location
where the program expects it.  But because the top half bits of
the address have been masked out, the return address is now invalid.
The incorrect behavior of the "next" command and the backtrace at
that location are the first symptoms of that.  Another symptom is
that this actually alters the behavior of the program, where a "cont"
from there soon leads to a SEGV when the inferior tries to jump back
to that incorrect return address:

    (gdb) c
    Continuing.

    Program received signal SIGSEGV, Segmentation fault.
    0x00000000f7bd86f9 in ?? ()
    ^^^^^^^^^^^^^^^^^^

This patch fixes the issue by using a mask that seems more appropriate
for this architecture.

gdb/ChangeLog:

        * amd64-tdep.c (amd64_displaced_step_fixup): Fix the mask used to
        compute RETADDR.

gdb/testsuite/ChangeLog:

        * gdb.base/dso2dso-dso2.c, gdb.base/dso2dso-dso2.h,
        gdb.base/dso2dso-dso1.c, gdb.base/dso2dso-dso1.h, gdb.base/dso2dso.c,
        gdb.base/dso2dso.exp: New files.

Tested on x86_64-linux, no regression.
2015-08-12 13:19:34 -07:00
Keith Seitz 59ecaff361 Initialize `location' in gdbpy_decode_line
BuildBot flagged an uninitialized variable coming from one of the patches
in my recently committed locations/explicit patchset.

The following patch fixes this.

gdb/ChangeLog

	* python/python.c (gdbpy_decode_line): Initialize `location' to NULL
	and only call decode_line_1 when it is non-NULL.

diff --git a/gdb/python/python.c b/gdb/python/python.c
index c28f98b..14da62c 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -730,7 +730,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
   PyObject *result = NULL;
   PyObject *return_result = NULL;
   PyObject *unparsed = NULL;
-  struct event_location *location;
+  struct event_location *location = NULL;

   if (! PyArg_ParseTuple (args, "|s", &arg))
     return NULL;
@@ -747,7 +747,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)

   TRY
     {
-      if (arg)
+      if (location != NULL)
 	sals = decode_line_1 (location, 0, 0, 0);
       else
 	{
2015-08-12 11:31:24 -07:00
Sergio Durigan Junior 5ba325978c Guarantee save-and-restore of GDBFLAGS on gdb.base/checkpoint-ns.exp
Keith found out that several tests were failing when testing the
native-gdbserver board on Fedora (x86_64).  Strangely, these failures
had not been reported by our BuildBot.  Later, he found that the reason
for this was because the failures only happened when running the
testsuite without FORCE_PARALLEL (i.e., on serial mode; maybe it would
be worth having a builder testing things on serial...).  Then, he
decided to start bisecting the changes to see which one introduced the
failure (it was not trivial to know this only by looking at gdb.log).

After a lot of time, he found that Pedro's commit
e1316e60d4 was the culprit.  There was
nothing wrong in the code, but the new gdb.base/checkpoint-ns.exp
testcase did something that left the GDBFLAGS variable in an
inconsistent state.  This test works by modifying this variable to set
non-stop on, sourcing gdb.base/checkpoint.exp (which does the hard
work), and then restoring the old value on GDBFLAGS.  However, this was
not working because gdb.base/checkpoint.exp bails out if it is being
tested on gdbserver, and when it calls "continue" the control goes back
to the function calling the tests, and not to
gdb.base/checkpoint-ns.exp.

The fix is simple: just wrap the "source" call, and make
gdb.base/checkpoint-ns.exp aware of the "continue"/"return" calls made
by gdb.base/checkpoint.exp.

gdb/testsuite/ChangeLog:
2015-08-12  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>
	    Keith Seitz  <keiths@redhat.com>

	* gdb.base/checkpoint-ns.exp: Use save_vars to save and restore
	GDBFLAGS.
2015-08-12 12:32:16 -04:00
Patrick Palka b6dafabfb1 Use save_vars to replace existing manipulation of globals in tests
gdb/testsuite/ChangeLog:

	* gdb.base/gdbhistsize-history.exp
	(test_histsize_history_setting): Use save_vars.
	* gdb.base/gdbinit-history.exp (test_gdbinit_history_setting):
	Use save_vars.
	(test_no_truncation_of_unlimited_history_file): Use save_vars.
	* gdb.base/readline.exp: Use save_vars.
2015-08-12 11:43:16 -04:00
Patrick Palka abe8e6075b Introduce save_vars, a testsuite proc for safely manipulating globals
gdb/testsuite/ChangeLog:

	* lib/gdb.exp (save_vars): New proc.
2015-08-12 08:39:18 -04:00
Luis Machado 244558af86 [regression] Do not read from catchpoint/watchpoint locations' addresses when checking for a permanent breakpoint
While running bare-metal tests with GDB i noticed some failures in
gdb.base/break.exp, related to the use of the catch commands.

It turns out GDB tries to access memory address 0x0 whenever one tries
to insert a catchpoint, which should obviously not happen.

This was introduced with the changes for permanent breakpoints. In special,
bp_loc_is_permanent tries to check if there is a breakpoint inserted at
the same address as the current breakpoint's location's address. In the
case of catchpoints, this is 0x0.

(top-gdb) catch fork
Sending packet: $m0,1#fa...Packet received: E01
Catchpoint 4 (fork)

(top-gdb) catch vfork
Sending packet: $m0,1#fa...Packet received: E01
Catchpoint 5 (vfork)

It is not obvious to detect because this fails silently for Linux. For our
bare-metal testing, though, this fails with a clear error message from the
target about not being able to read such address.

The attached patch addresses this by bailing out of bp_loc_is_permanent (...)
if the location address is not meaningful. I also took the opportunity to
update the comment for breakpoint_address_is_meaningful, which mentioned
breakpoint addresses as opposed to their locations' addresses.

gdb/ChangeLog:

2015-08-11  Luis Machado  <lgustavo@codesourcery.com>

	* breakpoint.c (bp_loc_is_permanent): Return 0 when breakpoint
	location address is not meaningful.
	(breakpoint_address_is_meaningful): Update comment.
2015-08-12 05:36:09 -03:00
Keith Seitz 629500fae6 Explicit locations: documentation updates
This patch adds documentation for explicit locations to both the
User Manual and gdb's online help system.

gdb/ChangeLog:

	* NEWS: Mention explicit locations.
	* breakpoint.c [LOCATION_HELP_STRING]: New macro.
	[BREAK_ARGS_HELP]: Use LOCATION_HELP_STRING.
	(_initialize_breakpoint): Update documentation for
	"clear", "break", "trace", "strace", "ftrace", and "dprintf".

gdb/doc/ChangeLog:

	* gdb.texinfo (Thread-Specific Breakpoints, Printing Source Lines):
	Use "location(s)"instead of "linespec(s)".
	(Specifying a Location): Rewrite.
	Add subsections describing linespec, address, and explicit locations.
	Add node/menu for each subsection.
	(Source and Machine Code, C Preprocessor Macros)
	(Create and Delete Trace points)
	(Extensions for Ada Tasks): Use "location(s)" instead of "linespec(s)".
	(Continuing at a Different Address): Remove "linespec" examples.
	Add reference to "Specify a Location"
	(The -break-insert Command): Rewrite.  Add anchor.
	Add reference to appropriate manual section discussing locations.
	(The -dprintf-insert Command): Refer to -break-insert for
	specification of 'location'.

gdb/testsuite/ChangeLog:

	* gdb.base/help.exp: Update help_breakpoint_text.
2015-08-11 17:09:36 -07:00
Keith Seitz eb8c4e2e66 Explicit locations: MI support for explicit locations
This patch adds support for explicit locations to MI's -break-insert
command. The new options, documented in the User Manual, are
--source, --line, --function, and --label.

gdb/ChangeLog:

	* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Add support for
	explicit locations, options "--source", "--function",
	"--label", and "--line".

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-break.exp (test_explicit_breakpoints): New proc.
	(at toplevel): Call test_explicit_breakpoints.
	* gdb.mi/mi-dprintf.exp: Add tests for explicit dprintf
	breakpoints.
	* lib/mi-support.exp (mi_make_breakpoint): Add support for
	breakpoint conditions, "-cond".
2015-08-11 17:09:36 -07:00
Keith Seitz 87f0e72047 Explicit locations: add UI features for CLI
This patch exposes explicit locations to the CLI user.  This enables
users to "explicitly" specify attributes of the breakpoint location
to avoid any ambiguity that might otherwise exist with linespecs.

The general syntax of explicit locations is:
-source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME
-label LABEL_NAME

Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users
may use the completer with either options or values.

gdb/ChangeLog:

	* completer.c: Include location.h.
	(enum match_type): New enum.
	(location_completer): Rename to ...
	(linespec_completer): ... this.
	(collect_explicit_location_matches, backup_text_ptr)
	(explicit_location_completer): New functions.
	(location_completer): "New" function; handle linespec
	and explicit location completions.
	(complete_line_internal): Remove all location completer-specific
	handling.
	* linespec.c (linespec_lexer_lex_keyword, is_ada_operator)
	(find_toplevel_char): Export.
	(linespec_parse_line_offset): Export.
	Issue error if STRING is not numerical.
	(gdb_get_linespec_parser_quote_characters): New function.
	* linespec.h (linespec_parse_line_offset): Declare.
	(get_gdb_linespec_parser_quote_characters): Declare.
	(is_ada_operator): Declare.
	(find_toplevel_char): Declare.
	(linespec_lexer_lex_keyword): Declare.
	* location.c (explicit_to_event_location): New function.
	(explicit_location_lex_one): New function.
	(string_to_explicit_location): New function.
	(string_to_event_location): Handle explicit locations.
	* location.h (explicit_to_event_location): Declare.
	(string_to_explicit_location): Declare.

gdb/testsuite/ChangeLog:

	* gdb.linespec/3explicit.c: New file.
	* gdb.linespec/cpexplicit.cc: New file.
	* gdb.linespec/cpexplicit.exp: New file.
	* gdb.linespec/explicit.c: New file.
	* gdb.linespec/explicit.exp: New file.
	* gdb.linespec/explicit2.c: New file.
	* gdb.linespec/ls-errs.exp: Add explicit location tests.
	* lib/gdb.exp (capture_command_output): Regexp-escape `command'
	before using in the matching pattern.
	Clarify that `prefix' is a regular expression.
2015-08-11 17:09:36 -07:00
Keith Seitz 00e52e5376 Explicit locations: introduce explicit locations
This patch add support for explicit locations and switches many linespec
locations to this new location type.  This patch also converts all
linespec locations entered by the user to an explicit representation
internally (thus bypassing the linespec parser when resetting the
breakpoint).

This patch does not introduce any user-visible changes.


gdb/ChangeLog:

	* break-catch-throw.c (re_set_exception_catchpoint): Convert
	linespec into explicit location.
	* breakpoint.c (create_overlay_breakpoint)
	(create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint): Convert linespec into explicit
	location.
	(update_static_tracepoint): Convert linespec into explicit location.
	* linespec.c (enum offset_relative_sign, struct line_offset): Move
	location.h.
	(struct linespec) <expression, expr_pc, source_filename>
	<function_name, label_name, line_offset>: Replace with ...
	<explicit>: ... this.
	<is_linespec>: New member.
	(PARSER_EXPLICIT): New accessor macro.
	(undefined_label_error): New function.
	(source_file_not_found_error): New function.
	(linespec_parse_basic): The parser result is now an explicit location.
	Use PARSER_EXPLICIT to access it.
	Use undefined_label_error.
	(canonicalize_linespec): Convert canonical linespec into explicit
	location.
	Move string representation of location to explicit_location_to_linespec
	and use it and explicit_location_to_string to save string
	representations of the canonical location.
	(create_sals_line_offset, convert_linespec_to_sals): `ls' contains an
	explicit location.  Update all references.
	(convert_explicit_location_to_sals): New function.
	(parse_linespec): Use PARSER_EXPLICIT to access the parser
	result's explicit location.
	(linespec_state_constructor): Initialize is_linespec.
	Use PARSER_EXPLICIT.
	(linespec_parser_delete): Use PARSER_EXPLICIT to access the parser's
	result.
	(event_location_to_sals): For linespec locations, set is_linespec.
	Handle explicit locations.
	(decode_objc): 'ls' contains an explicit location now. Update all
	references.
	(symtabs_from_filename): Use source_file_not_found_error.
	* location.c (struct event_location.u) <explicit>: New member.
	(initialize_explicit_location): New function.
	(initialize_event_location): Initialize explicit locations.
	(new_explicit_location, get_explicit_location)
	(get_explicit_location_const): New functions.
	(explicit_to_string_internal): New function; most of contents moved
	from canonicalize_linespec.
	(explicit_location_to_string): New function.
	(explicit_location_to_linespec): New function.
	(copy_event_location, delete_event_location)
	(event_location_to_string_const, event_location_empty_p): Handle
	explicit locations.
	* location.h (enum offset_relative_sign, struct line_offset): Move
	here from linespec.h.
	(enum event_location_type): Add EXPLICIT_LOCATION.
	(struct explicit_location): New structure.
	(explicit_location_to_string): Declare.
	(explicit_location_to_linespec): Declare.
	(new_explicit_location, get_explicit_locationp
	(get_explicit_location_const, initialize_explicit_location): Declare.
2015-08-11 17:09:35 -07:00
Keith Seitz 5b56227bdc Explicit locations: introduce probe locations
This patch adds support for probe locations and converts existing
probe linespec locations to the new location type.

gdb/ChangeLog:

	* break-catch-throw.c (re_set_exception_catchpoint): Convert
	linespec for stap probe to probe location.
	* breakpoint.c (create_longjmp_master_breakpoint)
	(create_exception_master_breakpoint): Likewise.
	(break_command_1): Remove local variable `arg_cp'.
	Check location type to set appropriate breakpoint ops methods.
	(trace_command): Likewise.
	* linespec.c (event_location_to_sals): Assert on probe locations.
	* location.c (EL_PROBE): Add macro definition.
	(new_probe_location, get_probe_location): New functions.
	(copy_event_location, delete_event_location, event_location_to_string)
	(string_to_event_location, event_location_empty_p): Handle probe
	locations.
	* location.h (enum event_location_type): Add PROBE_LOCATION.
	(new_probe_location, get_probe_location): Declare.
	* probe.c (parse_probes): Assert that LOCATION is a probe location.
	Convert linespec into probe location.
2015-08-11 17:09:35 -07:00
Keith Seitz a06efdd6ef Explicit locations: introduce address locations
This patch adds support for address locations, of the form "*ADDR".
[Support for address linespecs has been removed/replaced by this "new"
location type.] This patch also converts any existing address locations
from its previous linespec type.

gdb/ChangeLog:

	* breakpoint.c (create_thread_event_breakpoint, init_breakpoint_sal):
	Convert linespec to address location.
	* linespec.c (canonicalize_linespec): Do not handle address
	locations here.
	(convert_address_location_to_sals): New function; contents moved
	from ...
	(convert_linespc_to_sals): ... here.
	(parse_linespec): Remove address locations from linespec grammar.
	Remove handling of address locations.
	(linespec_lex_to_end): Remove handling of address linespecs.
	(event_location_to_sals): Handle ADDRESS_LOCATION.
	(linespec_expression_to_pc): Export.
	* linespec.h (linespec_expression_to_pc): Add declaration.
	* location.c (struct event_location.u) <address>: New member.
	(new_address_location, get_address_location): New functions.
	(copy_event_location, delete_event_location, event_location_to_string)
	(string_to_event_location, event_location_empty_p): Handle address
	locations.
	* location.h (enum event_location_type): Add ADDRESS_LOCATION.
	(new_address_location, get_address_location): Declare.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Convert linespec
	to address location.
	* spu-tdep.c (spu_catch_start): Likewise.
2015-08-11 17:09:35 -07:00
Keith Seitz f00aae0f7b Explicit locations: use new location API
This patch converts the code base to use the new struct event_location
API being introduced. This patch preserves the current functionality and
adds no new features.

The "big picture" API usage introduced by this patch may be illustrated
with a simple exmaple. Where previously developers would write:

void
my_command (char *arg, int from_tty)
{
   create_breakpoint (..., arg, ...);
   ...
}

one now uses:

void
my_command (char *arg, int from_tty)
{
   struct event_locaiton *location;
   struct cleanup *back_to;

   location = string_to_event_locaiton (&arg, ...);
   back_to = make_cleanup_delete_event_location (location);
   create_breakpoint (..., location, ...);
   do_cleanups (back_to);
}

Linespec-decoding functions (now called location-decoding) such as
decode_line_full no longer skip argument pointers over processed input.
That functionality has been moved into string_to_event_location as
demonstrated above.

gdb/ChangeLog

	* ax-gdb.c: Include location.h.
	(agent_command_1) Use linespec location instead of address
	string.
	* break-catch-throw.c: Include location.h.
	(re_set_exception_catchpoint): Use linespec locations instead
	of address strings.
	* breakpoint.c: Include location.h.
	(create_overlay_event_breakpoint, create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint, update_breakpoints_after_exec):
	Use linespec location instead of address string.
	(print_breakpoint_location):  Use locations and
	event_location_to_string.
	Print extra_string for pending locations for non-MI streams.
	(print_one_breakpoint_location): Use locations and
	event_location_to_string.
	(init_raw_breakpoint_without_location): Initialize b->location.
	(create_thread_event_breakpoint): Use linespec location instead of
	address string.
	(init_breakpoint_sal): Likewise.
	Only save extra_string if it is non-NULL and not the empty string.
	Use event_location_to_string instead of `addr_string'.
	Constify `p' and `endp'.
	Use skip_spaces_const/skip_space_const instead of non-const versions.
	Copy the location into the breakpoint.
	If LOCATION is NULL, save the breakpoint address as a linespec location
	instead of an address string.
	(create_breakpoint_sal): Change `addr_string' parameter to a struct
	event_location. All uses updated.
	(create_breakpoints_sal): Likewise for local variable `addr_string'.
	(parse_breakpoint_sals): Use locations instead of address strings.
	Remove check for empty linespec with conditional.
	Refactor.
	(decode_static_tracepoint_spec): Make argument const and update
	function.
	(create_breakpoint): Change `arg' to a struct event_location and
	rename.
	Remove `copy_arg' and `addr_start'.
	If EXTRA_STRING is empty, set it to NULL.
	Don't populate `canonical' for pending breakpoints.
	Pass `extra_string' to find_condition_and_thread.
	Clear `extra_string' if `rest' was NULL.
	Do not error with "garbage after location" if setting a dprintf
	breakpoint.
	Copy the location into the breakpoint instead of an address string.
	(break_command_1): Use string_to_event_location and pass this to
	create_breakpoint instead of an address string.
	Check against `arg_cp' for a probe linespec.
	(dprintf_command): Use string_to_event_location and pass this to
	create_breakpoint instead of an address string.
	Throw an exception if no format string was specified.
	(print_recreate_ranged_breakpoint): Use event_location_to_string
	instead of address strings.
	(break_range_command, until_break_command)
	(init_ada_exception_breakpoint): Use locations instead
	of address strings.
	(say_where): Print out extra_string for pending locations.
	(base_breakpoint_dtor): Delete `location' and `location_range_end' of
	the breakpoint.
	(base_breakpoint_create_sals_from_location): Use struct event_location
	instead of address string.
	Remove `addr_start' and `copy_arg' parameters.
	(base_breakpoint_decode_location): Use struct event_location instead of
	address string.
	(bkpt_re_set): Use locations instead of address strings.
	Use event_location_empty_p to check for unset location.
	(bkpt_print_recreate): Use event_location_to_string instead of
	an address string.
	Print out extra_string for pending locations.
	(bkpt_create_sals_from_location, bkpt_decode_location)
 	(bkpt_probe_create_sals_from_location): Use struct event_location
	instead of address string.
	(bkpt_probe_decode_location): Use struct event_location instead of
	address string.
	(tracepoint_print_recreate): Use event_location_to_string to
	recreate the tracepoint.
	(tracepoint_create_sals_from_location, tracepoint_decode_location)
	(tracepoint_probe_create_sals_from_location)
	(tracepoint_probe_decode_location): Use struct event_location
	instead of address string.
	(dprintf_print_recreate): Use event_location_to_string to recreate
	the dprintf.
	(dprintf_re_set): Remove check for valid/missing format string.
	(strace_marker_create_sals_from_location)
	(strace_marker_create_breakpoints_sal, strace_marker_decode_location)
	(update_static_tracepoint): Use struct event_location instead of
	address string.
	(location_to_sals): Likewise.
	Pass `extra_string' to find_condition_and_thread.
	For newly resolved pending breakpoint locations, clear the location's
	string representation.
	Assert that the breakpoint's condition string is NULL when
	condition_not_parsed.
	(breakpoint_re_set_default, create_sals_from_location_default)
	(decode_location_default, trace_command, ftrace_command)
	(strace_command, create_tracepoint_from_upload): Use locations
	instead of address strings.
	* breakpoint.h (struct breakpoint_ops) <create_sals_from_location>:
	Use struct event_location instead of address string.
	Update all uses.
	<decode_location>: Likewise.
	(struct breakpoint) <addr_string>: Change to struct event_location
	and rename `location'.
	<addr_string_range_end>: Change to struct event_location and rename
	`location_range_end'.
	(create_breakpoint): Use struct event_location instead of address
	string.
	* cli/cli-cmds.c: Include location.h.
	(edit_command, list_command): Use locations instead of address strings.
	* elfread.c: Include location.h.
	(elf_gnu_ifunc_resolver_return_stop): Use event_location_to_string.
	* guile/scm-breakpoint.c: Include location.h.
	(bpscm_print_breakpoint_smob): Use event_location_to_string.
	(gdbscm_register_breakpoint): Use locations instead of address
	strings.
	* linespec.c: Include location.h.
	(struct ls_parser) <stream>: Change to const char *.
	(PARSER_STREAM): Update.
	(lionespec_lexer_lex_keyword): According to find_condition_and_thread,
	keywords must be followed by whitespace.
	(canonicalize_linespec): Save a linespec location into `canonical'.
	Save a canonical linespec into `canonical'.
	(parse_linespec): Change `argptr' to const char * and rename `arg'.
	All uses updated.
	Update function description.
	(linespec_parser_new): Initialize `parser'.
	Update initialization of  parsing stream.
	(event_location_to_sals): New function.
	(decode_line_full): Change `argptr' to a struct event_location and
	rename it `location'.
	Use locations instead of address strings.
	Call event_location_to_sals instead of parse_linespec.
	(decode_line_1): Likewise.
	(decode_line_with_current_source, decode_line_with_last_displayed)
	Use locations instead of address strings.
	(decode_objc): Likewise.
	Change `argptr' to const char * and rename `arg'.
	(destroy_linespec_result): Delete the linespec result's location
	instead of freeing the address string.
	* linespec.h (struct linespec_result) <addr_string>: Change to
	struct event_location and rename to ...
	<location>: ... this.
	(decode_line_1, decode_line_full): Change `argptr' to struct
	event_location.  All callers updated.
	* mi/mi-cmd-break.c: Include language.h, location.h, and linespec.h.
	(mi_cmd_break_insert_1): Use locations instead of address strings.
	Throw an error if there was "garbage" at the end of the specified
	linespec.
	* probe.c: Include location.h.
	(parse_probes): Change `argptr' to struct event_location.
	Use event locations instead of address strings.
	* probe.h (parse_probes): Change `argptr' to struct event_location.
	* python/py-breakpoint.c: Include location.h.
	(bppy_get_location): Constify local variable `str'.
	Use event_location_to_string.
	(bppy_init): Use locations instead of address strings.
	* python/py-finishbreakpoint.c: Include location.h.
	(bpfinishpy_init): Remove local variable `addr_str'.
	Use locations instead of address strings.
	* python/python.c: Include location.h.
	(gdbpy_decode_line): Use locations instead of address strings.
	* remote.c: Include location.h.
	(remote_download_tracepoint): Use locations instead of address
	strings.
	* spu-tdep.c: Include location.h.
	(spu_catch_start): Remove local variable `buf'.
	Use locations instead of address strings.
	* tracepoint.c: Include location.h.
	(scope_info): Use locations instead of address strings.
	(encode_source_string): Constify parameter `src'.
	* tracepoint.h (encode_source_string): Likewise.

gdb/testsuite/ChangeLog

	* gdb.base/dprintf-pending.exp: Update dprintf "without format"
	test.
	Add tests for missing ",FMT" and ",".
2015-08-11 17:09:35 -07:00
Keith Seitz c7c1b3e998 Explicit locations: introduce new struct event_location-based API
This patch introduces the new breakpoint/"linespec" API based on
a new struct event_location.  This API currently only supports
traditional linespecs, maintaining the status quo of the code base.
Future patches will add additional functionality for other location
types such as address locations.

gdb/ChangeLog:

	* Makefile.in (SFILES): Add location.c.
	(HFILES_NO_SRCDIR): Add location.h.
	(COMMON_OBS): Add location.o.
	* linespec.c (linespec_lex_to_end): New function.
	* linespec.h (linespec_lex_to_end): Declare.
	* location.c: New file.
	* location.h: New file.
2015-08-11 17:09:35 -07:00
Keith Seitz 5f700d83f7 Explicit locations: rename "address string"/"addr_string" to "location"
This patch renames all occurrances of "addr_string" and "address
string" in the breakpoint/linespec APIs.  This will emphasize the
change from address strings used in setting breakpoints (et al) to the
new locations-based API introduced in subsequent patches.

gdb/ChangeLog:

	* breakpoint.h (struct breakpoint_ops) <create_sals_from_address>:
	Renamed to create_sals_from_location.
	<decode_linespec>: Renamed to decode_location.
	Update all callers.
	* breakpoint.c (create_sals_from_address_default): Renamed to ...
	(create_sals_from_location_default): ... this.
	(addr_string_to_sals): Renamed to ...
	(location_to_sals): ... this.
	(decode_linespec_default): Renamed to ...
	(decode_location_default): ... this.
	(base_breakpoint_create_sals_from_address): Renamed to ...
	(base_breakpoint_create_sals_from_location): ... this.
	(bkpt_create_sals_from_address): Renamed to ...
	(bkpt_create_sals_from_location): ... this.
	(bkpt_decode_linespec): Renamed to ...
	(bkpt_decode_location): ... this.
	(bkpt_probe_create_sals_from_address): Renamed to ...
	(bkpt_probe_create_sals_from_location): ... this.
	(tracepoint_create_sals_from_address): Renamed to ...
	(tracepoint_create_sals_from_location): ... this.
	(tracepoint_decode_linespec): Renamed to ...
	(tracepoint_decode_location): ... this.
	(tracepoint_probe_create_sals_from_address): Renamed to ...
	(tracepoint_probe_create_sals_from_location): ... this.
	(tracepoint_probe_decode_linespec): Renamed to ...
	(tracepoint_probe_decode_location): ... this.
	(strace_marker_create_sals_from_address): Renamed to ...
	(strace_marker_create_sals_from_location): ... this.
	(decode_linespec_default): Renamed to ...
	(decode_location_default): ... this.
2015-08-11 17:09:35 -07:00
Doug Evans 80af41e003 remove trailing space in previous entry 2015-08-10 13:36:36 -07:00
Doug Evans e27852be65 PR gdb/17960 Internal error: tracker != NULL when completing on file:function
gdb/ChangeLog:

	* symtab.c (make_file_symbol_completion_list_1): Renamed from
	make_file_symbol_completion_list and made static.
	(make_file_symbol_completion_list): New function.

gdb/testsuite/ChangeLog:

	* gdb.base/completion.exp: Add location completer tests.
2015-08-10 12:23:09 -07:00
Joel Brobecker fd7dcb94cb gdb/infrun.c: Various trivial ARI fixes.
gdb/ChangeLog:

        * infrun.c (follow_fork, displaced_step_prepare, resume): Remove
        trailing new-line at end of warning message.
        (proceed): Add i18n marker to error messages.
2015-08-10 11:07:56 -07:00
Pedro Alves f12899e9f0 native Linux: enable always non-stop by default
The testsuite shows no regressions with this forced on, on:

 - Native x86_64 Fedora 20, with and output "set displaced off".

 - Native x86_64 Fedora 20, on top of x86 software single-step series.

 - PPC64 Fedora 18.

 - S/390 RHEL 7.1.

Let's try making it the default.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (linux_nat_always_non_stop_p): Return 1.
2015-08-07 17:26:21 +01:00
Pedro Alves 5ac213430b S/390: displaced stepping and PC-relative RIL-b/RIL-c instructions
This adds displaced stepping support for the General-Instruction
Extension Facility instructions, which have a PC-relative displacement
(RIL-b/RIL-c).  We already handle RIL branches, but not others.

Currently, displaced stepping a breakpoint put on any of these
instructions results in the inferior crashing when or after the
instruction is executed out-of-line in the scratch pad.

This patch takes the easy route of patching the displacement in the
copy of the instruction in the scratch pad.  As the displacement is a
signed 32-bit field, it's possible that the stratch pad ends too far
that the needed displacement doesn't fit in the adjusted instruction,
as e.g., if stepping over a breakpoint in a shared library (the
scratch pad is around the main program's entry point).  That case is
detected and GDB falls back to stepping over the breakpoint in-line
(which involves pausing all threads momentarily).

(We could probably do something smarter, but I don't plan on doing it
myself.  This was already sufficient to get "maint set target-non-stop
on" working regression free on S/390.)

Tested on S/390 RHEL 7.1, where it fixes a few hundred FAILs when
testing with displaced stepping force-enabled, with the end result
being no regressions compared to a test run that doesn't force
displaced stepping.  Fixes the non-stop tests compared to mainline
too; most are crashing due to this on the machine I run tests on.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* s390-linux-tdep.c (is_non_branch_ril)
	(s390_displaced_step_copy_insn): New functions.
	(s390_displaced_step_fixup): Update comment.
	(s390_gdbarch_init): Install s390_displaced_step_copy_insn as
	gdbarch_displaced_step_copy_insn hook.
2015-08-07 17:26:21 +01:00
Pedro Alves 7f03bd92e3 PPC64: Fix gdb.arch/ppc64-atomic-inst.exp with displaced stepping
The ppc64 displaced step code can't handle atomic sequences.  Fallback
to stepping over the breakpoint in-line if we detect one.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (displaced_step_prepare_throw): Return -1 if
	gdbarch_displaced_step_copy_insn returns NULL.  Update intro
	comment.
	* rs6000-tdep.c (LWARX_MASK, LWARX_INSTRUCTION, LDARX_INSTRUCTION)
	(STWCX_MASK, STWCX_INSTRUCTION, STDCX_INSTRUCTION): Move higher up
	in file.
	(ppc_displaced_step_copy_insn): New function.
	(ppc_displaced_step_fixup): Update comment.
	(rs6000_gdbarch_init): Install ppc_displaced_step_copy_insn as
	gdbarch_displaced_step_copy_insn hook.
	* gdbarch.sh (displaced_step_copy_insn): Document what happens on
	NULL return.
	* gdbarch.h: Regenerate.

gdb/testsuite/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdb.arch/ppc64-atomic-inst.exp (do_test): New procedure, move
	tests here.
	(top level): Run do_test with and without displaced stepping.
2015-08-07 17:26:21 +01:00
Pedro Alves 3fc8eb30a9 Disable displaced stepping if trying it fails
Running the testsuite with "maint set target-non-stop on" shows:

 (gdb) PASS: gdb.base/valgrind-infcall.exp: continue #98 (false warning)
 continue
 Continuing.
 dl_main (phdr=<optimized out>..., auxv=<optimized out>) at rtld.c:2302
 2302      LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
 Cannot access memory at address 0x400532
 (gdb) PASS: gdb.base/valgrind-infcall.exp: continue #99 (false warning)
 p gdb_test_infcall ()
 $1 = 1
 (gdb) FAIL: gdb.base/valgrind-infcall.exp: p gdb_test_infcall ()

Even though that was a native GNU/Linux test run, this test spawns
Valgrind and connects to it with "target remote".  The error above is
actually orthogonal to target-non-stop.  The real issue is that that
enables displaced stepping, and displaced stepping doesn't work with
Valgrind, because we can't write to the inferior memory (thus can't
copy the instruction to the scratch pad area).

I'm sure there will be other targets with the same issue, so trying to
identify Valgrind wouldn't be sufficient.  The fix is to try setting
up the displaced step anyway.  If we get a MEMORY_ERROR, we disable
displaced stepping for that inferior, and fall back to doing an
in-line step-over.  If "set displaced-stepping" is "on" (as opposed to
"auto), GDB warns displaced stepping failed ("on" is mainly useful for
the testsuite, not for users).

Tested on x86_64 Fedora 20.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* inferior.h (struct inferior) <displaced_stepping_failed>: New
	field.
	* infrun.c (use_displaced_stepping_now_p): New parameter 'inf'.
	Return false if dispaced stepping failed before.
	(resume): Pass the current inferior to
	use_displaced_stepping_now_p.  Wrap displaced_step_prepare in
	TRY/CATCH.  If we get a MEMORY_ERROR, set the inferior's
	displaced_stepping_failed flag, and fall back to an in-line
	step-over.

gdb/testsuite/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/valgrind-disp-step.c: New file.
	* gdb.base/valgrind-disp-step.exp: New file.
2015-08-07 17:26:21 +01:00
Pedro Alves d4569d7bc5 Fix step-over-{trips-on-watchpoint|lands-on-breakpoint}.exp race
On a target that is both always in non-stop mode and can do displaced
stepping (such as native x86_64 GNU/Linux, with "maint set
target-non-stop on"), the step-over-trips-on-watchpoint.exp test
sometimes fails like this:

   (gdb) PASS: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: step: thread 1
   set scheduler-locking off
   (gdb) PASS: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: step: set scheduler-locking off
   step
  -[Switching to Thread 0x7ffff7fc0700 (LWP 11782)]
  -Hardware watchpoint 4: watch_me
  -
  -Old value = 0
  -New value = 1
  -child_function (arg=0x0) at /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.threads/step-over-trips-on-watchpoint.c:39
  -39           other = 1; /* set thread-specific breakpoint here */
  -(gdb) PASS: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: step: step
  +wait_threads () at /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.threads/step-over-trips-on-watchpoint.c:49
  +49       return 1; /* in wait_threads */
  +(gdb) FAIL: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: step: step

Note "scheduler-locking" was set off.  The problem is that on such
targets, the step-over of thread 2 and the "step" of thread 1 can be
set to run simultaneously (since with displaced stepping the
breakpoint isn't ever removed from the target), and sometimes, the
"step" of thread 1 finishes first, so it'd take another resume to see
the watchpoint trigger.  Fix this by replacing the wait_threads
function with a one-line infinite loop that doesn't call any function,
so that the "step" of thread 1 never finishes.

gdb/testsuite/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdb.threads/step-over-lands-on-breakpoint.c (wait_threads):
	Delete function.
	(main): Add alarm.  Run an infinite loop instead of calling
	wait_threads.
	* gdb.threads/step-over-lands-on-breakpoint.exp (do_test): Change
	comment.
	* gdb.threads/step-over-trips-on-watchpoint.c (wait_threads):
	Delete function.
	(main): Add alarm.  Run an infinite loop instead of calling
	wait_threads.
	* gdb.threads/step-over-trips-on-watchpoint.exp (do_test): Change
	comment.
2015-08-07 17:26:21 +01:00
Pedro Alves bfedc46af3 Fix interrupt-noterm.exp on targets always in non-stop
With "maint set target-non-stop on" we get:

 @@ -66,13 +66,16 @@ Continuing.
  interrupt
  (gdb) PASS: gdb.base/interrupt-noterm.exp: interrupt

 -Program received signal SIGINT, Interrupt.
 -PASS: gdb.base/interrupt-noterm.exp: inferior received SIGINT
 -testcase src/gdb/testsuite/gdb.base/interrupt-noterm.exp completed in 0 seconds
 +[process 12119] #1 stopped.
 +0x0000003615ebc6d0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81
 +81     T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
 +FAIL: gdb.base/interrupt-noterm.exp: inferior received SIGINT (timeout)
 +testcase src/gdb/testsuite/gdb.base/interrupt-noterm.exp completed in 10 seconds

That is, we get "[$thread] #1 stopped" instead of SIGINT.

The issue is that we don't currently distinguish send
"interrupt/ctrl-c" to target terminal vs "stop/pause" thread well;
both cases go through "target_stop".

And then, the native Linux backend (linux-nat.c) implements
target_stop with SIGSTOP in non-stop mode, and SIGINT in all-stop
mode.  Since "maint set target-non-stop on" forces the backend to be
always running in non-stop mode, even though the user-visible behavior
is "set non-stop" is "off", "interrupt" causes a SIGSTOP instead of
the SIGINT the test expects.

Fix this by introducing a target_interrupt method to use in the
"interrupt/ctrl-c" case, so "set non-stop off" can always work the
same irrespective of "maint set target-non-stop on/off".  I'm
explictly considering changing the "set non-stop on" behavior as out
of scope here.

Most of the patch is an across-the-board rename of to_stop hook
implementations to to_interrupt.  The only targets where something
more than a rename is being done are linux-nat.c and remote.c, which
are the only targets that support async, and thus are the only ones
the core side calls target_stop on.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* darwin-nat.c (darwin_stop): Rename to ...
	(darwin_interrupt): ... this.
	(_initialize_darwin_inferior): Adjust.
	* gnu-nat.c (gnu_stop): Delete.
	(gnu_target): Don't install gnu_stop.
	* inf-ptrace.c (inf_ptrace_stop): Rename to ...
	(inf_ptrace_interrupt): ... this.
	(inf_ptrace_target): Adjust.
	* infcmd.c (interrupt_target_1): Use target_interrupt instead of
	target_stop.
	* linux-nat (linux_nat_stop): Rename to ...
	(linux_nat_interrupt): ... this.
	(linux_nat_stop): Reimplement.
	(linux_nat_add_target): Install linux_nat_interrupt.
	* nto-procfs.c (nto_interrupt_twice): Rename to ...
	(nto_handle_sigint_twice): ... this.
	(nto_interrupt): Rename to ...
	(nto_handle_sigint): ... this.  Call target_interrupt instead of
	target_stop.
	(procfs_wait): Adjust.
	(procfs_stop): Rename to ...
	(procfs_interrupt): ... this.
	(init_procfs_targets): Adjust.
	* procfs.c (procfs_stop): Rename to ...
	(procfs_interrupt): ... this.
	(procfs_target): Adjust.
	* remote-m32r-sdi.c (m32r_stop): Rename to ...
	(m32r_interrupt): ... this.
	(init_m32r_ops): Adjust.
	* remote-sim.c (gdbsim_stop_inferior): Rename to ...
	(gdbsim_interrupt_inferior): ... this.
	(gdbsim_stop): Rename to ...
	(gdbsim_interrupt): ... this.
	(gdbsim_cntrl_c): Adjust.
	(init_gdbsim_ops): Adjust.
	* remote.c (sync_remote_interrupt): Adjust comments.
	(remote_stop_as): Rename to ...
	(remote_interrupt_as): ... this.
	(remote_stop): Adjust comment.
	(remote_interrupt): New function.
	(init_remote_ops): Install remote_interrupt.
	* target.c (target_interrupt): New function.
	* target.h (struct target_ops) <to_interrupt>: New field.
	(target_interrupt): New declaration.
	* windows-nat.c (windows_stop): Rename to ...
	(windows_interrupt): ... this.
	* target-delegates.c: Regenerate.
2015-08-07 17:26:20 +01:00
Pedro Alves d55007b583 Fix signal-while-stepping-over-bp-other-thread.exp on targets always in non-stop
With "maint set target-non-stop on" we get:

 -PASS: gdb.threads/signal-while-stepping-over-bp-other-thread.exp: step
 +FAIL: gdb.threads/signal-while-stepping-over-bp-other-thread.exp: step

The issue is simply that switch_back_to_stepped_thread is not used in
non-stop mode, thus infrun doesn't output the expected "switching back
to stepped thread" log.

gdb/testsuite/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* signal-while-stepping-over-bp-other-thread.exp: Expect "restart
	threads" as alternative to "switching back to stepped thread".
2015-08-07 17:26:20 +01:00
Pedro Alves fbea99ea8a Implement all-stop on top of a target running non-stop mode
This finally implements user-visible all-stop mode running with the
target_ops backend always in non-stop mode.  This is a stepping stone
towards finer-grained control of threads, being able to do interesting
things like thread groups, associating groups with breakpoints, etc.
From the user's perspective, all-stop mode is really just a special
case of being able to stop and resume specific sets of threads, so it
makes sense to do this step first.

With this, even in all-stop, the target is no longer in charge of
stopping all threads before reporting an event to the core -- the core
takes care of it when it sees fit.  For example, when "next"- or
"step"-ing, we can avoid stopping and resuming all threads at each
internal single-step, and instead only stop all threads when we're
about to present the stop to the user.

The implementation is almost straight forward, as the heavy lifting
has been done already in previous patches.  Basically, we replace
checks for "set non-stop on/off" (the non_stop global), with calls to
a new target_is_non_stop_p function.  In a few places, if "set
non-stop off", we stop all threads explicitly, and in a few other
places we resume all threads explicitly, making use of existing
methods that were added for teaching non-stop to step over breakpoints
without displaced stepping.

This adds a new "maint set target-non-stop on/off/auto" knob that
allows both disabling the feature if we find problems, and
force-enable it for development (useful when teaching a target about
this.  The default is "auto", which means the feature is enabled if a
new target method says it should be enabled.  The patch implements the
method in linux-nat.c, just for illustration, because it still returns
false.  We'll need a few follow up fixes before turning it on by
default.  This is a separate target method from indicating regular
non-stop support, because e.g., while e.g., native linux-nat.c is
close to regression free with all-stop-non-stop (with following
patches will fixing the remaining regressions), remote.c+gdbserver
will still need more fixing, even though it supports "set non-stop
on".

Tested on x86_64 Fedora 20, native, with and without "set displaced
off", and with and without "maint set target-non-stop on"; and also
against gdbserver.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention "maint set/show target-non-stop".
	* breakpoint.c (update_global_location_list): Check
	target_is_non_stop_p instead of non_stop.
	* infcmd.c (attach_command_post_wait, attach_command): Likewise.
	* infrun.c (show_can_use_displaced_stepping)
	(can_use_displaced_stepping_p, start_step_over_inferior):
	Likewise.
	(internal_resume_ptid): New function.
	(resume): Use it.
	(proceed): Check target_is_non_stop_p instead of non_stop.  If in
	all-stop mode but the target is always in non-stop mode, start all
	the other threads that are implicitly resumed too.
	(for_each_just_stopped_thread, fetch_inferior_event)
	(adjust_pc_after_break, stop_all_threads): Check
	target_is_non_stop_p instead of non_stop.
	(handle_inferior_event): Likewise.  Handle detach-fork in all-stop
	with the target always in non-stop mode.
	(handle_signal_stop) <random signal>: Check target_is_non_stop_p
	instead of non_stop.
	(switch_back_to_stepped_thread): Check target_is_non_stop_p
	instead of non_stop.
	(keep_going_stepped_thread): Use internal_resume_ptid.
	(stop_waiting): If in all-stop mode, and the target is in non-stop
	mode, stop all threads.
	(keep_going_pass): Likewise, when starting a new in-line step-over
	sequence.
	* linux-nat.c (get_pending_status, select_event_lwp)
	(linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check
	target_is_non_stop_p instead of non_stop.
	(linux_nat_always_non_stop_p): New function.
	(linux_nat_stop): Check target_is_non_stop_p instead of non_stop.
	(linux_nat_add_target): Install linux_nat_always_non_stop_p.
	* target-delegates.c: Regenerate.
	* target.c (target_is_non_stop_p): New function.
	(target_non_stop_enabled, target_non_stop_enabled_1): New globals.
	(maint_set_target_non_stop_command)
	(maint_show_target_non_stop_command): New functions.
	(_initilize_target): Install "maint set/show target-non-stop"
	commands.
	* target.h (struct target_ops) <to_always_non_stop_p>: New field.
	(target_non_stop_enabled): New declaration.
	(target_is_non_stop_p): New declaration.

gdb/doc/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Maintenance Commands): Document "maint set/show
	target-non-stop".
2015-08-07 17:24:01 +01:00
Pedro Alves 372316f128 Teach non-stop to do in-line step-overs (stop all, step, restart)
That is, step past breakpoints by:

 - pausing all threads
 - removing breakpoint at PC
 - single-step
 - reinsert breakpoint
 - restart threads

similarly to all-stop (with displaced stepping disabled).  This allows
non-stop to work on targets/architectures without displaced stepping
support.  That is, it makes displaced stepping an optimization instead
of a requirement.  For example, in principle, all GNU/Linux ports
support non-stop mode at the target_ops level, but not all
corresponding gdbarch's implement displaced stepping.  This should
make non-stop work for all (albeit, not as efficiently).  And then
there are scenarios where even if the architecture supports displaced
stepping, we can't use it, because we e.g., don't find a usable
address to use as displaced step scratch pad.  It should also fix
stepping past watchpoints on targets that have non-continuable
watchpoints in non-stop mode (e.g., PPC, untested).  Running the
instruction out of line in the displaced stepping scratch pad doesn't
help that case, as the copied instruction reads/writes the same
watched memory...  We can fix that too by teaching GDB to only remove
the watchpoint from the thread that we want to move past the
watchpoint (currently, removing a watchpoint always removes it from
all threads), but again, that can be considered an optimization; not
all targets would support it.

For those familiar with the gdb and gdbserver Linux target_ops
backends, the implementation should look similar, except it is done on
the core side.  When we pause threads, we may find they stop with an
interesting event that should be handled later when the thread is
re-resumed, thus we store such events in the thread object, and mark
the event as pending.  We should only consume pending events if the
thread is indeed resumed, thus we add a new "resumed" flag to the
thread object.  At a later stage, we might add new target methods to
accelerate some of this, like "pause all threads", with corresponding
RSP packets, but we'd still need a fallback method for remote targets
that don't support such packets, so, again, that can be deferred as
optimization.

My _real_ motivation here is making it possible to reimplement
all-stop mode on top of the target always working on non-stop mode, so
that e.g., we can send RSP packets to a remote target even while the
target is running -- can't do that in the all-stop RSP variant, by
design).

Tested on x86_64 Fedora 20, with and without "set displaced off"
forced.  The latter forces the new code paths whenever GDB needs to
step past a breakpoint.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <pedro@codesourcery.com>

	* breakpoint.c (breakpoints_should_be_inserted_now): If any thread
	has a pending status, return true.
	* gdbthread.h: Include target/waitstatus.h.
	(struct thread_suspend_state) <stop_reason, waitstatus_pending_p,
	stop_pc>: New fields.
	(struct thread_info) <resumed>: New field.
	(set_resumed): Declare.
	* infrun.c: Include "event-loop.h".
	(infrun_async_inferior_event_token, infrun_is_async): New globals.
	(infrun_async): New function.
	(clear_step_over_info): Add debug output.
	(displaced_step_in_progress_any_inferior): New function.
	(displaced_step_fixup): New returns int.
	(start_step_over): Handle in-line step-overs too.  Assert the
	thread is marked resumed.
	(resume_cleanups): Clear the thread's resumed flag.
	(resume): Set the thread's resumed flag.  Return early if the
	thread has a pending status.  Allow stepping a breakpoint with no
	signal.
	(proceed): Adjust to check 'resumed' instead of 'executing'.
	(clear_proceed_status_thread): If the thread has a pending status,
	and that status is a finished step, discard the pending status.
	(clear_proceed_status): Don't clear step_over_info here.
	(random_pending_event_thread, do_target_wait): New functions.
	(prepare_for_detach, wait_for_inferior, fetch_inferior_event): Use
	do_target_wait.
	(wait_one): New function.
	(THREAD_STOPPED_BY): New macro.
	(thread_stopped_by_watchpoint, thread_stopped_by_sw_breakpoint)
	(thread_stopped_by_hw_breakpoint): New functions.
	(switch_to_thread_cleanup, save_waitstatus, stop_all_threads): New
	functions.
	(handle_inferior_event): Also call set_resumed(false) on all
	threads implicitly stopped by the event.
	(restart_threads, resumed_thread_with_pending_status): New
	functions.
	(finish_step_over): If we were doing an in-line step-over before,
	and no longer are after trying to start a new step-over, restart
	all threads.  If we have multiple threads with pending events,
	save the current event and go through the event loop again.
	(handle_signal_stop): Return early if finish_step_over returns
	false.
	<random signal>: If we get a signal while stepping over a
	breakpoint in-line in non-stop mode, restart all threads.  Clear
	step_over_info before delivering the signal.
	(keep_going_stepped_thread): Use internal_error instead of
	gdb_assert.  Mark the thread as resumed.
	(keep_going_pass_signal): Assert the thread isn't already resumed.
	If some other thread is doing an in-line step-over, defer the
	resume.  If we just started a new in-line step-over, stop all
	threads.  Don't clear step_over_info.
	(infrun_async_inferior_event_handler): New function.
	(_initialize_infrun): Create async event handler with
	infrun_async_inferior_event_handler as callback.
	(infrun_async): New declaration.
	* target.c (target_async): New function.
	* target.h (target_async): Declare macro and readd as function
	declaration.
	* target/waitstatus.h (enum target_stop_reason)
	<TARGET_STOPPED_BY_SINGLE_STEP>: New value.
	* thread.c (new_thread): Clear the new waitstatus field.
	(set_resumed): New function.
2015-08-07 17:24:00 +01:00
Pedro Alves 2ac7589cfe Factor out code to re-resume stepped thread
Just a code refactor, no funcionality change intended.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (keep_going_stepped_thread): New function, factored out
	from ...
	(switch_back_to_stepped_thread): ... here.
2015-08-07 17:23:59 +01:00
Pedro Alves 8b06156348 Add comments to currently_stepping and target_resume
Clarify that currently_stepping works at a higher level than
target_resume.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (currently_stepping): Extend intro comment.
	* target.h (target_resume): Extend intro comment.
2015-08-07 17:23:59 +01:00
Pedro Alves 1afd5965ed Misc switch_back_to_stepped_thread cleanups
Several misc cleanups that prepare the tail end of this function, the
part that actually re-resumes the stepped thread.

The most non-obvious would be the currently_stepping change, I guess.
That's because it isn't ever correct to pass step=1 to target_resume
on software single-step targets, and currently_stepping works at a
conceptual higher level, it returns step=true even on software step
targets.  It doesn't really matter on hardware step targets, as the
breakpoint will be hit immediately, but it's just wrong on software
step targets.  I tested it against my x86 software single-step branch,
and it indeed fixes failed assertions (that catch spurious
PTRACE_SINGLESTEP requests) there.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (switch_back_to_stepped_thread): Use ecs->ptid instead
	of inferior_ptid.  If the stepped thread vanished, return 0
	instead of resuming here.  Use reset_ecs.  Print the prev_pc and
	the current stop_pc in log message.  Clear trap_expected if the
	thread advanced.  Don't pass currently_stepping to
	do_target_resume.
2015-08-07 17:23:58 +01:00
Pedro Alves 4d9d9d0423 Use keep_going in proceed and start_step_over too
The main motivation of this patch is sharing more code between the
proceed (starting the inferior for the first time) and keep_going
(restarting the inferior after handling an event) paths and using the
step_over_chain queue now embedded in the thread_info object for
pending in-line step-overs too (instead of just for displaced
stepping).

So this commit:

 - splits out a new keep_going_pass_signal function out of keep_going
   that is just like keep_going except for the bits that clear the
   signal to pass if the signal is set to "handle nopass".

 - makes proceed use keep_going too.

 - Makes start_step_over use keep_going_pass_signal instead of lower
   level displaced stepping things.

One user visible change: if inserting breakpoints while trying to
proceed fails, we now get:

  (gdb) si
  Warning:
  Could not insert hardware watchpoint 7.
  Could not insert hardware breakpoints:
  You may have requested too many hardware breakpoints/watchpoints.

  Command aborted.
  (gdb)

while before we only saw warnings with no indication that the command
was cancelled:

  (gdb) si
  Warning:
  Could not insert hardware watchpoint 7.
  Could not insert hardware breakpoints:
  You may have requested too many hardware breakpoints/watchpoints.

  (gdb)

Tested on x86_64-linux-gnu, ppc64-linux-gnu and s390-linux-gnu.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (struct thread_info) <prev_pc>: Extend comment.
	* infrun.c (struct execution_control_state): Move higher up in the
	file.
	(reset_ecs): New function.
	(start_step_over): Now returns int.  Rewrite to use
	keep_going_pass_signal instead of manually starting a displaced step.
	(resume): Don't call set_running here.  If displaced stepping
	can't start now, clear trap_expected.
	(find_thread_needs_step_over): Delete function.
	(proceed): Set up finish_thread_state_cleanup.  Call set_running.
	If the current thread needs a step over, push it in the step-over
	chain.  Don't set insert breakpoints nor call resume directly
	here.  Instead rewrite to use start_step_over and
	keep_going_pass_signal.
	(finish_step_over): New function.
	(handle_signal_stop): Call finish_step_over instead of
	start_step_over.
	(switch_back_to_stepped_thread): If the event thread needs another
	step-over do that first.  Use start_step_over.
	(keep_going_pass_signal): New function, factored out from ...
	(keep_going): ... here.
	(_initialize_infrun): Comment moved here.
	* thread.c (set_running_thread): New function.
	(set_running, finish_thread_state): Use set_running_thread.
2015-08-07 17:23:58 +01:00
Pedro Alves c2829269f5 Embed the pending step-over chain in thread_info objects
In order to teach non-stop mode to do in-line step-overs (pause all
threads, remove breakpoint, single-step, reinsert breakpoint, restart
threads), we'll need to be able to queue in-line step over requests,
much like we queue displaced stepping (out-of-line) requests.
Actually, the queue should be the same -- threads wait for their turn
to step past something (breakpoint, watchpoint), doesn't matter what
technique we end up using when the step over actually starts.

I found that the queue management ends up simpler and more efficient
if embedded in the thread objects themselves.  This commit converts
the existing displaced stepping queue to that.  Later patches will
make the in-line step-overs code paths use it too.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (struct thread_info) <step_over_prev,
	step_over_next>: New fields.
	(thread_step_over_chain_enqueue, thread_step_over_chain_remove)
	(thread_step_over_chain_next, thread_is_in_step_over_chain): New
	declarations.
	* infrun.c (struct displaced_step_request): Delete.
	(struct displaced_step_inferior_state) <step_request_queue>:
	Delete field.
	(displaced_step_prepare): Assert that trap_expected is set.  Use
	thread_step_over_chain_enqueue.  Split starting a new displaced
	step to ...
	(start_step_over): ... this new function.
	(resume): Assert the thread isn't waiting for a step over already.
	(proceed): Assert the thread isn't waiting for a step over
	already.
	(infrun_thread_stop_requested): Adjust to remove threads from the
	embedded step-over chain.
	(handle_inferior_event) <fork/vfork>: Call start_step_over after
	displaced_step_fixup.
	(handle_signal_stop): Call start_step_over after
	displaced_step_fixup.
	* infrun.h (step_over_queue_head): New declaration.
	* thread.c (step_over_chain_enqueue, step_over_chain_remove)
	(thread_step_over_chain_next, thread_is_in_step_over_chain)
	(thread_step_over_chain_enqueue)
	(thread_step_over_chain_remove): New functions.
	(delete_thread_1): Remove thread from the step-over chain.
2015-08-07 17:23:57 +01:00
Pedro Alves 6c4cfb244b Make thread_still_needs_step_over consider stepping_over_watchpoint too
I noticed that even though keep_going knows to start a step over for a
watchpoint, thread_still_needs_step_over forgets it.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (thread_still_needs_step_over): Rename to ...
	(thread_still_needs_step_over_bp): ... this.
	(enum step_over_what): New.
	(thread_still_needs_step_over): Reimplement.
2015-08-07 17:23:57 +01:00
Pedro Alves 567420d108 remote.c/all-stop: Implement TARGET_WAITKIND_NO_RESUMED and TARGET_WNOHANG
Even though "target remote" supports target-async, the all-stop
target_wait implementation ignores TARGET_WNOHANG.  If the core
happens to poll for events and we've already read the stop reply out
of the serial/socket, remote_wait_as hangs forever instead of
returning an indication that there are no events to process.  This
can't happen currently, but later changes will trigger this.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_wait_as): If not waiting for a stop reply,
	return TARGET_WAITKIND_NO_RESUMED.  If TARGET_WNOHANG is
	requested, don't block waiting forever.
2015-08-07 17:23:56 +01:00
Pedro Alves d8dd4d5fe6 Change adjust_pc_after_break's prototype
Prepare to use it in contexts without an ecs handy.  Follow up patches
will make use of this.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <pedro@codesourcery.com>

	* infrun.c (adjust_pc_after_break): Now takes thread_info and
	waitstatus pointers instead of an ecs.  Adjust.
	(handle_inferior_event): Adjust caller.
2015-08-07 17:23:56 +01:00
Pedro Alves e1316e60d4 Fix and test "checkpoint" in non-stop mode
Letting a "checkpoint" run to exit with "set non-stop on" behaves
differently compared to the default all-stop mode ("set non-stop
off").

Currently, in non-stop mode:

  (gdb) start
  Temporary breakpoint 1 at 0x40086b: file src/gdb/testsuite/gdb.base/checkpoint.c, line 28.
  Starting program: build/gdb/testsuite/gdb.base/checkpoint

  Temporary breakpoint 1, main () at src/gdb/testsuite/gdb.base/checkpoint.c:28
  28        char *tmp = &linebuf[0];
  (gdb) checkpoint
  checkpoint 1: fork returned pid 24948.
  (gdb) c
  Continuing.
  Copy complete.
  Deleting copy.
  [Inferior 1 (process 24944) exited normally]
  [Switching to process 24948]
  (gdb) info threads
    Id   Target Id         Frame
    1    process 24948 "checkpoint" (running)

  No selected thread.  See `help thread'.
  (gdb) c
  The program is not being run.
  (gdb)

Two issues above:

 1. Thread 1 got stuck in "(running)" state (it isn't really running)

 2. While checkpoints try to preserve the illusion that the thread is
    still the same when the process exits, GDB switched to "No thread
    selected." instead of staying with thread 1 selected.

Problem #1 is caused by handle_inferior_event and normal_stop not
considering that when a
TARGET_WAITKIND_SIGNALLED/TARGET_WAITKIND_EXITED event is reported,
and the inferior is mourned, the target may still have execution.

Problem #2 is caused by the make_cleanup_restore_current_thread
cleanup installed by fetch_inferior_event not being able to find the
original thread 1's ptid in the thread list, thus not being able to
restore thread 1 as selected thread.  The fix is to make the cleanup
installed by make_cleanup_restore_current_thread aware of thread ptid
changes, by installing a thread_ptid_changed observer that adjusts the
cleanup's data.

After the patch, we get the same in all-stop and non-stop modes:

  (gdb) c
  Continuing.
  Copy complete.
  Deleting copy.
  [Inferior 1 (process 25109) exited normally]
  [Switching to process 25113]
  (gdb) info threads
    Id   Target Id         Frame
  * 1    process 25113 "checkpoint" main () at src/gdb/testsuite/gdb.base/checkpoint.c:28
  (gdb)

Turns out the whole checkpoints.exp file can run in non-stop mode
unmodified.  I thought of moving most of the test file's contents to a
procedure that can be called twice, once in non-stop mode and another
in all-stop mode.  But then, the test already takes close to 30
seconds to run on my machine, so I thought it'd be nicer to run
all-stop and non-stop mode in parallel.  Thus I added a new
checkpoint-ns.exp file that just appends "set non-stop on" to GDBFLAGS
and sources checkpoint.exp.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (handle_inferior_event): If we get
	TARGET_WAITKIND_SIGNALLED or TARGET_WAITKIND_EXITED in non-stop
	mode, mark all threads of the exiting process as not-executing.
	(normal_stop): If we get TARGET_WAITKIND_SIGNALLED or
	TARGET_WAITKIND_EXITED in non-stop mode, finish all threads of the
	exiting process, if inferior_ptid still points at a process.
	* thread.c (struct current_thread_cleanup) <next>: New field.
	(current_thread_cleanup_chain): New global.
	(restore_current_thread_ptid_changed): New function.
	(restore_current_thread_cleanup_dtor): Remove the cleanup from the
	current_thread_cleanup_chain list.
	(make_cleanup_restore_current_thread): Add the cleanup data to the
	current_thread_cleanup_chain list.
	(_initialize_thread): Install restore_current_thread_ptid_changed
	as thread_ptid_changed observer.

gdb/testsuite/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/checkpoint-ns.exp: New file.
	* gdb.base/checkpoint.exp: Pass explicit "checkpoint.c" to
	standard_testfile.
2015-08-07 17:23:55 +01:00
Joel Brobecker 47e9c225c1 ignore invalid DOF provider sections
On x86-solaris 10, we noticed that starting a program would sometimes
cause the debugger to crash. For instance:

    % gdb a
    (gdb) break adainit
    Breakpoint 1 at 0x8051f03
    (gdb) run
    Starting program: /[...]/a
    [Thread debugging using libthread_db enabled]
    zsh: 24398 segmentation fault (core dumped)  /[...]/gdb a

The exception occurs in dtrace_process_dof_probe, while trying
to process each probe referenced by a DTRACE_DOF_SECT_TYPE_PROVIDER
DOF section from /lib/libc.so.1. For reference, the ELF section
in that shared library providing the DOF data has the following
characteristics:

    Idx Name          Size      VMA       LMA       File off  Algn
     14 .SUNW_dof     0000109d  000b4398  000b4398  000b4398  2**3
                      CONTENTS, ALLOC, LOAD, READONLY, DATA

The function dtrace_process_dof gets passed the contents of that
ELF section, which allows it to determine the location of the table
where all DOF sections are described. I dumped the contents of
each DOF section as seen by GDB, and it seemed to be plausible,
because the offset of each DOF section was pretty much equal to
the sum of the offset and size of the previous DOF section. Also,
the offset + sum of the last section corresponds to the size of
the .SUNW_dof section.

Things start to break down when processing one of the DOF sections
that has a type of DTRACE_DOF_SECT_TYPE_PROVIDER. It gets the contents
of this DOF section via:

        struct dtrace_dof_provider *provider = (struct dtrace_dof_provider *)
          DTRACE_DOF_PTR (dof, DOF_UINT (dof, section->dofs_offset));

Said more simply, the struct dtrace_dof_provider data is at
section->dofs_offset of the entire DOF contents. Given that
the contents of SECTION seemed to make sense, so far so good.

However, what SECTION tells us is that our DOF provider section
is 40 bytes long:

    (gdb) print *section
    $36 = {dofs_type = 15, dofs_align = 4, dofs_flags = 1,
           dofs_entsize = 0, dofs_offset = 3264, dofs_size = 40}
                                                 ^^^^^^^^^^^^^^

But on the other hand:

    (gdb) p sizeof (struct dtrace_dof_provider)
    $54 = 44

In other words GDB expected a bigger DOF section and when we try to
fetch the value of the last field of that DOF section (dofpv_prenoffs)...

    eoffsets_s = DTRACE_DOF_SECT (dof,
                                  DOF_UINT (dof, provider->dofpv_prenoffs));

... we end up reading data that actually belongs to another DOF
section, and therefore irrelevant. This in turn means that the value
of eofftab gets incorrectly set, since it depends on eoffsets_s:

    eofftab = DTRACE_DOF_PTR (dof, DOF_UINT (dof, eoffsets_s->dofs_offset));

This invalid address quickly catches up to us when we pass it to
dtrace_process_dof_probe shortly after, where we crash because
we try to subscript it:

    Program received signal SIGSEGV, Segmentation fault.
    0x08155bba in dtrace_process_dof_probe ([...]) at [...]/dtrace-probe.c:378
    378             = ((uint32_t *) eofftab)[...];

This patch fixes the issue by detecting provider DOF sections
that are smaller than expected, and discarding the DOF data.

gdb/ChangeLog:

        * dtrace-probe.c (dtrace_process_dof): Ignore the objfile's DOF
        data if a DTRACE_DOF_SECT_TYPE_PROVIDER section is found to be
        smaller than expected.
2015-08-07 08:17:52 -07:00
Andrew Burgess 060967202b gdb: Move get_frame_language from stack.c to frame.c.
The get_frame_language feels like it would be more at home in frame.c
rather than in stack.c, while the declaration, that is currently in
language.h can be moved into frame.h to match.

A couple of new includes are added, but otherwise no substantial change
here.

gdb/ChangeLog:

	* stack.c (get_frame_language): Moved ...
	* frame.c (get_frame_language): ... to here.
	* language.h (get_frame_language): Declaration moved to frame.h.
	* frame.h: Add language.h include, for language enum.
	(get_frame_language): Declaration moved from language.h.
	* language.c: Add frame.h include.
	* top.c: Add frame.h include.
	* symtab.h (struct obj_section): Declare.
	(struct cmd_list_element): Declare.
2015-08-07 11:55:20 +02:00
Andrew Burgess 7ff38b1c89 gdb: get_frame_language now takes a frame parameter.
As part of a drive to remove deprecated_safe_get_selected_frame, make
the get_frame_language function take a frame parameter.  Given the name
of the function this actually seems to make a lot of sense.

The task of fetching a suitable frame is then passed to the calling
functions.  For get_frame_language there are not many callers, these are
updated to get the selected frame in a suitable way.

gdb/ChangeLog:

	* language.c (show_language_command): Find selected frame before
	asking for the language of that frame.
	(set_language_command): Likewise.
	* language.h (get_frame_language): Add frame parameter.
	* stack.c (get_frame_language): Add frame parameter, assert
	parameter is not NULL, update comment and reindent.
	* top.c (check_frame_language_change): Pass the selected frame
	into get_frame_language.
2015-08-07 11:54:59 +02:00
Markus Metzger da8c46d296 btrace: indicate speculative execution
Indicate speculatively executed instructions with a leading '?'.  We use the
space that is normally used for the PC prefix.  In the case where the
instruction at the current PC had been executed speculatively before, the PC
prefix will be partially overwritten resulting in "?> ".

As a side-effect, the /p modifier to omit the PC prefix in the "record
instruction-history" command now uses a 3-space PC prefix "   " in order to
have enough space for the speculative execution indication.

gdb/
	* btrace.c (btrace_compute_ftrace_bts): Clear insn flags.
	(pt_btrace_insn_flags): New.
	(ftrace_add_pt): Call pt_btrace_insn_flags.
	* btrace.h (btrace_insn_flag): New.
	(btrace_insn) <flags>: New.
	* record-btrace.c (btrace_insn_history): Print insn prefix.
	* NEWS: Announce it.

doc/
	* gdb.texinfo (Process Record and Replay): Document prefixing of
	speculatively executed instructions in the "record instruction-history"
	command.

testsuite/
	* gdb.btrace/instruction_history.exp: Update.
	* gdb.btrace/tsx.exp: New.
	* gdb.btrace/tsx.c: New.
	* lib/gdb.exp (skip_tsx_tests, skip_btrace_pt_tests): New.
2015-08-07 10:22:39 +02:00
Markus Metzger 5599c40462 configure: check for perf_event.h version
Intel(R) Processor Trace support requires a recent linux/perf_event.h header.

When GDB is built on an older system, Intel(R) Processor Trace will not be
available and there is no indication in the configure and build log as to
what went wrong.

Check for a compatible linux/perf_event.h at configure-time.

gdb/
	* configure.ac: Check for PERF_ATTR_SIZE_VER5 in linux/perf_event.h
	* configure: Regenerate.
2015-08-07 10:19:01 +02:00
DJ Delorie 016a325163 Yaakov Selkowitz: fixes for in-tree libiconv
* Makefile.def (libiconv): Define bootstrap=true.
        Mark pdf/html/info as missing.
        (configure-gcc): Depend on all-libiconv.
        (all-gcc): Ditto.
        (configure-libcpp): Ditto.
        (all-libcpp): Ditto.
        (configure-intl): Ditto.
        (all-intl): Ditto.
        * Makefile.in: Regenerate.

binutils/
        * configure: Regenerate.

gdb/
        * Makefile.in (LIBICONV): Define.
        (CLIBS): Add LIBICONV.
        * acinclude.m4: Use config/iconv.m4 instead of custom AM_ICONV.
        * configure: Regenerate.
2015-08-06 23:55:06 -04:00
Pedro Alves de1c2c5223 Bump timeouts for a couple gdb.reverse/*-precsave.exp tests
The buildbot shows that PPC64 and x86_64 builders, both native and
extended-remote gdbserver frequently timeout these tests.
until-precsave.exp times out on my x86_64 occasionally as well.
Inspecting the logs, we see that if we waited some more, the tests
would pass.

Simply bump until-precsave.exp timeouts further, and apply the same
treatment to step-precsave.exp.

gdb/testsuite/ChangeLog:
2015-08-06  Pedro Alves <palves@redhat.com>

	* gdb.reverse/step-precsave.exp: Use with_timeout_factor to
	increase timeout.
	* gdb.reverse/until-precsave.exp: Bump timeouts.
2015-08-07 00:09:35 +01:00
Pedro Alves 782e0bf46a Fix gdb.base/valgrind-infcall.exp with the native-extended-gdbserver board
This test fails with --target_board=native-extended-gdbserver because
it misses the usual "disconnect":

 (gdb)  target remote | /usr/lib64/valgrind/../../bin/vgdb --pid=30454
 Already connected to a remote target.  Disconnect? (y or n) n
 Still connected.
 (gdb) FAIL: gdb.base/valgrind-infcall.exp: target remote for vgdb (got interactive prompt)

gdb/testsuite/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* gdb.base/valgrind-infcall.exp: Issue a "disconnect".
2015-08-06 23:38:51 +01:00
Simon Marchi aead7601eb Add casts for legitimate integer to enum conversions
This patch is mostly extracted from Pedro's C++ branch.  It adds explicit
casts from integer to enum types, where it is really the intention to do
so.  This could be because we are ...

 * iterating on enum values (we need to iterate on an equivalent integer)
 * converting from a value read from bytes (dwarf attribute, agent
 expression opcode) to the equivalent enum
 * reading the equivalent integer value from another language (Python/Guile)

An exception to that is the casts in regcache.c.  It seems to me like
struct regcache's register_status field could be a pointer to an array of
enum register_status.  Doing so would waste a bit of memory (4 bytes
used by the enum vs 1 byte used by the current signed char, for each
register).  If we switch to C++11 one day, we can define the underlying
type of an enum type, so we could have the best of both worlds.

gdb/ChangeLog:

	* arm-tdep.c (set_fp_model_sfunc): Add cast from integer to enum.
	(arm_set_abi): Likewise.
	* ax-general.c (ax_print): Likewise.
	* c-exp.y (exp : string_exp): Likewise.
	* compile/compile-loc2c.c (compute_stack_depth_worker): Likewise.
	(do_compile_dwarf_expr_to_c): Likewise.
	* cp-name-parser.y (demangler_special : DEMANGLER_SPECIAL start):
	Likewise.
	* dwarf2expr.c (execute_stack_op): Likewise.
	* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
	(disassemble_dwarf_expression): Likewise.
	* dwarf2read.c (dwarf2_add_member_fn): Likewise.
	(read_array_order): Likewise.
	(abbrev_table_read_table): Likewise.
	(read_attribute_value): Likewise.
	(skip_unknown_opcode): Likewise.
	(dwarf_decode_macro_bytes): Likewise.
	(dwarf_decode_macros): Likewise.
	* eval.c (value_f90_subarray): Likewise.
	* guile/scm-param.c (gdbscm_make_parameter): Likewise.
	* i386-linux-tdep.c (i386_canonicalize_syscall): Likewise.
	* infrun.c (handle_command): Likewise.
	* memory-map.c (memory_map_start_memory): Likewise.
	* osabi.c (set_osabi): Likewise.
	* parse.c (operator_length_standard): Likewise.
	* ppc-linux-tdep.c (ppc_canonicalize_syscall): Likewise, and use
	single return point.
	* python/py-frame.c (gdbpy_frame_stop_reason_string): Likewise.
	* python/py-symbol.c (gdbpy_lookup_symbol): Likewise.
	(gdbpy_lookup_global_symbol): Likewise.
	* record-full.c (record_full_restore): Likewise.
	* regcache.c (regcache_register_status): Likewise.
	(regcache_raw_read): Likewise.
	(regcache_cooked_read): Likewise.
	* rs6000-tdep.c (powerpc_set_vector_abi): Likewise.
	* symtab.c (initialize_ordinary_address_classes): Likewise.
	* target-debug.h (target_debug_print_signals): Likewise.
	* utils.c (do_restore_current_language): Likewise.
2015-08-06 17:22:49 -04:00
Simon Marchi 84da3f0cf9 Add missing ChangeLog entry header 2015-08-06 15:36:41 -04:00
Simon Marchi 9d996aba1a Fix ChangeLog formatting
Spaces -> Tab.
2015-08-06 14:28:00 -04:00
Pedro Alves 33ebda9d68 gdbserver/tracepoint.c: make exported IPA global int instead of enum
Fixes another C++ -fpermissive error:

  src/gdb/gdbserver/tracepoint.c:4535:21: error: invalid conversion from ‘int’ to ‘eval_result_type’ [-fpermissive]
    expr_eval_result = ipa_expr_eval_result;

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* tracepoint.c (expr_eval_result): Now an int.
2015-08-06 17:44:08 +01:00
Pedro Alves a44892be35 gdbserver: no point in hiding the regcache type nowadays
The regcache used to be hidden inside inferiors.c, but since the
tracepoints support that it's a first class object.  This also fixes a
few implicit pointer conversion errors in C++ mode, caused by a few
places missing the explicit cast.

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (struct regcache): Forward declare.
	(struct thread_info) <regcache_data>: Now a struct regcache
	pointer.
	* inferiors.c (inferior_regcache_data)
	(set_inferior_regcache_data): Now work with struct regcache
	pointers.
	* inferiors.h (struct regcache): Forward declare.
	(inferior_regcache_data, set_inferior_regcache_data): Now work
	with struct regcache pointers.
	* regcache.c (get_thread_regcache, regcache_invalidate_thread)
	(free_register_cache_thread): Remove struct regcache pointer
	casts.
2015-08-06 17:29:01 +01:00
Clem Dickey ca0a5f0bd3 PR python/17136
gdb/ChangeLog:

	* python/lib/gdb/command/type_printers.py (InfoTypePrinter): Fix typo.
2015-08-06 09:24:58 -07:00
Pedro Alves 608a1e4639 gdbserver: fix silent error exit
Running gdb.threads/process-dies-while-handling-bp.exp against
gdbserver sometimes FAILs because GDBserver drops the connection, but
the logs leave no clue on what the reason could be.  Running manually
a few times, I saw the same:

 $  ./gdbserver/gdbserver --multi :9999 testsuite/gdb.threads/process-dies-while-handling-bp
 Process testsuite/gdb.threads/process-dies-while-handling-bp created; pid = 12766
 Listening on port 9999
 Remote debugging from host 127.0.0.1
 Listening on port 9999

 Child exited with status 0

 Child exited with status 0

What happened is that an exception escaped and gdbserver reopened the
connection, which led to that second "Listening on port 9999" output.

The error was a failure to access registers from a now-dead thread.
The exception probably shouldn't have escaped here, but meanwhile,
this at least makes the issue less mysterious.

Tested on x86_64 Fedora 20.

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* server.c (captured_main): On error, print the exception message
	to stderr, and if run_once is set, throw a quit.
2015-08-06 17:10:09 +01:00
Simon Marchi 05d999b089 Change type of struct complaints::series
Found while processing the C++ enum changes.  It seems like series
should be of type enum complaint_series, instead of adding a cast.

Redundant and out of date comments are also removed.

gdb/ChangeLog:

	* complaints.c (enum complaint_series): Add newlines and remove
	out of date comment.
	(struct complaints) <series>: Change type to enum
	complaint_series and remove out of date comment.
	(symfile_complaint_hook): Use equivalent enum value
	ISOLATED_MESSAGE instead of 0.
2015-08-06 12:01:05 -04:00
Pedro Alves f0ce0d3a33 gdbserver: move_out_of_jump_pad_callback misses switching current thread
While hacking on the fix for PR threads/18600 (Threads left stopped
after fork+thread spawn), I once saw its test (fork-plus-threads.exp)
FAIL against gdbserver because move_out_of_jump_pad_callback has a
gdb_breakpoint_here call, and the caller isn't making sure the current
thread points to the right thread.  In the case I saw, the current
thread pointed to the wrong process, so gdb_breakpoint_here returned
the wrong answer.  Unfortunately I didn't save logs.  Still, seems
obvious enough and it should fix a potential occasional racy FAIL.

Tested on x86_64 Fedora 20.

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* linux-low.c (move_out_of_jump_pad_callback): Temporarily switch
	the current thread.
2015-08-06 14:30:07 +01:00
Pedro Alves bf47e2482d Fix gdbserver --debug issues caught by Valgrind
Running gdbserver --debug under Valgrind shows:

 ==4803== Invalid read of size 4
 ==4803==    at 0x432B62: linux_write_memory (linux-low.c:5320)
 ==4803==    by 0x4143F7: write_inferior_memory (target.c:83)
 ==4803==    by 0x415895: remove_memory_breakpoint (mem-break.c:362)
 ==4803==    by 0x432EF5: linux_remove_point (linux-low.c:5460)
 ==4803==    by 0x416319: delete_raw_breakpoint (mem-break.c:802)
 ==4803==    by 0x4163F3: release_breakpoint (mem-break.c:842)
 ==4803==    by 0x416477: delete_breakpoint_1 (mem-break.c:869)
 ==4803==    by 0x4164EF: delete_breakpoint (mem-break.c:891)
 ==4803==    by 0x416843: delete_gdb_breakpoint_1 (mem-break.c:1069)
 ==4803==    by 0x4168D8: delete_gdb_breakpoint (mem-break.c:1098)
 ==4803==    by 0x4134E3: process_serial_event (server.c:4051)
 ==4803==    by 0x4138E4: handle_serial_event (server.c:4196)
 ==4803==  Address 0x4c6b930 is 0 bytes inside a block of size 1 alloc'd
 ==4803==    at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
 ==4803==    by 0x4240C6: xmalloc (common-utils.c:43)
 ==4803==    by 0x41439C: write_inferior_memory (target.c:80)
 ==4803==    by 0x415895: remove_memory_breakpoint (mem-break.c:362)
 ==4803==    by 0x432EF5: linux_remove_point (linux-low.c:5460)
 ==4803==    by 0x416319: delete_raw_breakpoint (mem-break.c:802)
 ==4803==    by 0x4163F3: release_breakpoint (mem-break.c:842)
 ==4803==    by 0x416477: delete_breakpoint_1 (mem-break.c:869)
 ==4803==    by 0x4164EF: delete_breakpoint (mem-break.c:891)
 ==4803==    by 0x416843: delete_gdb_breakpoint_1 (mem-break.c:1069)
 ==4803==    by 0x4168D8: delete_gdb_breakpoint (mem-break.c:1098)
 ==4803==    by 0x4134E3: process_serial_event (server.c:4051)
 ==4803==

And:

 ==7272== Conditional jump or move depends on uninitialised value(s)
 ==7272==    at 0x3615E48361: vfprintf (vfprintf.c:1634)
 ==7272==    by 0x414E89: debug_vprintf (debug.c:60)
 ==7272==    by 0x42800A: debug_printf (common-debug.c:35)
 ==7272==    by 0x43937B: my_waitpid (linux-waitpid.c:149)
 ==7272==    by 0x42D740: linux_wait_for_event_filtered (linux-low.c:2441)
 ==7272==    by 0x42DADA: linux_wait_for_event (linux-low.c:2552)
 ==7272==    by 0x42E165: linux_wait_1 (linux-low.c:2860)
 ==7272==    by 0x42F5D8: linux_wait (linux-low.c:3453)
 ==7272==    by 0x4144A4: mywait (target.c:107)
 ==7272==    by 0x413969: handle_target_event (server.c:4214)
 ==7272==    by 0x41A1A6: handle_file_event (event-loop.c:429)
 ==7272==    by 0x41996D: process_event (event-loop.c:184)

gdb/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* nat/linux-waitpid.c (my_waitpid): Only print *status if waitpid
	returned > 0.

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_write_memory): Rewrite debug output to avoid
	reading beyond the passed in buffer length.
2015-08-06 13:32:27 +01:00
Pedro Alves f6a9d9c7db Revert "test slowdown"
That was pushed by mistake.
2015-08-06 12:45:45 +01:00
Pedro Alves 83e97ed023 Test for PR18749: problems if whole process dies while (ptrace-) stopped
This adds a kfailed test that has the whole process exit just while
several threads continuously step over a breakpoint.  Usually, the
process exits just while GDB or GDBserver is handling the breakpoint
hit.  In other words, the process disappears while the event thread is
(ptrace-) stopped.  This exposes several issues in GDB and GDBserver.
Errors, crashes, etc.

I fixed some of these issues recently, but there's a lot more to do.
It's a bit like playing whack-a-mole at the moment.  You fix an issue,
which then exposes several others.

E.g., with the native target, you get (among other errors):

  (...)
  [New Thread 0x7ffff47b9700 (LWP 18077)]
  [New Thread 0x7ffff3fb8700 (LWP 18078)]
  [New Thread 0x7ffff37b7700 (LWP 18079)]
  Cannot find user-level thread for LWP 18076: generic error
  (gdb) KFAIL: gdb.threads/process-dies-while-handling-bp.exp: non_stop=on: cond_bp_target=1: inferior 1 exited (prompt) (PRMS: gdb/18749)

gdb/testsuite/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	PR gdb/18749
	* gdb.threads/process-dies-while-handling-bp.c: New file.
	* gdb.threads/process-dies-while-handling-bp.exp: New file.
2015-08-06 12:33:20 +01:00
Pedro Alves 4807d3f329 test slowdown 2015-08-06 12:33:19 +01:00
Pierre Langlois b6b9ffccac Remove required field in agent's symbols
This field was never set nor used.  This patch removes it.

gdb/ChangeLog:

	* common/agent.c (symbol_list) <required>: Remove.

gdb/gdbserver/ChangeLog:

	* tracepoint.c (symbol_list) <required>: Remove.
2015-08-06 12:27:32 +01:00
Pedro Alves 863d01bde2 gdbserver: Fix non-stop / fork / step-over issues
Ref: https://sourceware.org/ml/gdb-patches/2015-07/msg00868.html

This adds a test that has a multithreaded program have several threads
continuously fork, while another thread continuously steps over a
breakpoint.

This exposes several intertwined issues, which this patch addresses:

 - When we're stopping and suspending threads, some thread may fork,
   and we missed setting its suspend count to 1, like we do when a new
   clone/thread is detected.  When we next unsuspend threads, the fork
   child's suspend count goes below 0, which is bogus and fails an
   assertion.

 - If a step-over is cancelled because a signal arrives, but then gdb
   is not interested in the signal, we pass the signal straight back
   to the inferior.  However, we miss that we need to re-increment the
   suspend counts of all other threads that had been paused for the
   step-over.  As a result, other threads indefinitely end up stuck
   stopped.

 - If a detach request comes in just while gdbserver is handling a
   step-over (in the test at hand, this is GDB detaching the fork
   child), gdbserver internal errors in stabilize_thread's helpers,
   which assert that all thread's suspend counts are 0 (otherwise we
   wouldn't be able to move threads out of the jump pads).  The
   suspend counts aren't 0 while a step-over is in progress, because
   all threads but the one stepping past the breakpoint must remain
   paused until the step-over finishes and the breakpoint can be
   reinserted.

 - Occasionally, we see "BAD - reinserting but not stepping." being
   output (from within linux_resume_one_lwp_throw).  That was because
   GDB pokes memory while gdbserver is busy with a step-over, and that
   suspends threads, and then re-resumes them with proceed_one_lwp,
   which missed another reason to tell linux_resume_one_lwp that the
   thread should be set back to stepping.

 - In a couple places, we were resuming threads that are meant to be
   suspended.  E.g., when a vCont;c/s request for thread B comes in
   just while gdbserver is stepping thread A past a breakpoint.  The
   resume for thread B must be deferred until the step-over finishes.

 - The test runs with both "set detach-on-fork" on and off.  When off,
   it exercises the case of GDB detaching the fork child explicitly.
   When on, it exercises the case of gdb resuming the child
   explicitly.  In the "off" case, gdb seems to exponentially become
   slower as new inferiors are created.  This is _very_ noticeable as
   with only 100 inferiors gdb is crawling already, which makes the
   test take quite a bit to run.  For that reason, I've disabled the
   "off" variant for now.

gdb/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* target/waitstatus.h (enum target_stop_reason)
	<TARGET_STOPPED_BY_SINGLE_STEP>: New value.

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* linux-low.c (handle_extended_wait): Set the fork child's suspend
	count if stopping and suspending threads.
	(check_stopped_by_breakpoint): If stopped by trace, set the LWP's
	stop reason to TARGET_STOPPED_BY_SINGLE_STEP.
	(linux_detach): Complete an ongoing step-over.
	(lwp_suspended_inc, lwp_suspended_decr): New functions.  Use
	throughout.
	(resume_stopped_resumed_lwps): Don't resume a suspended thread.
	(linux_wait_1): If passing a signal to the inferior after
	finishing a step-over, unsuspend and re-resume all lwps.  If we
	see a single-step event but the thread should be continuing, don't
	pass the trap to gdb.
	(stuck_in_jump_pad_callback, move_out_of_jump_pad_callback): Use
	internal_error instead of gdb_assert.
	(enqueue_pending_signal): New function.
	(check_ptrace_stopped_lwp_gone): Add debug output.
	(start_step_over): Use internal_error instead of gdb_assert.
	(complete_ongoing_step_over): New function.
	(linux_resume_one_thread): Don't resume a suspended thread.
	(proceed_one_lwp): If the LWP is stepping over a breakpoint, reset
	it stepping.

gdb/testsuite/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* gdb.threads/forking-threads-plus-breakpoint.exp: New file.
	* gdb.threads/forking-threads-plus-breakpoint.c: New file.
2015-08-06 10:30:18 +01:00
Pedro Alves 00db26facc Linux gdbserver confused when event randomization picks process exit event
The tail end of linux_wait_1 isn't expecting that the select_event_lwp
machinery can pick a whole-process exit event to report to GDB.  When
that happens, both gdb and gdbserver end up quite confused:

 ...
 (gdb)
 [Thread 24971.24971] #1 stopped.
 0x0000003615a011f0 in ?? ()
 c&
 Continuing.
 (gdb) [New Thread 24971.24981]
 [New Thread 24983.24983]
 [New Thread 24971.24982]

 [Thread 24983.24983] #3 stopped.
 0x0000003615ebc7cc in __libc_fork () at ../nptl/sysdeps/unix/sysv/linux/fork.c:130
 130       pid = ARCH_FORK ();
 [New Thread 24984.24984]
 Error in re-setting breakpoint -16: PC register is not available
 Error in re-setting breakpoint -17: PC register is not available
 Error in re-setting breakpoint -18: PC register is not available
 Error in re-setting breakpoint -19: PC register is not available
 Error in re-setting breakpoint -24: PC register is not available
 Error in re-setting breakpoint -25: PC register is not available
 Error in re-setting breakpoint -26: PC register is not available
 Error in re-setting breakpoint -27: PC register is not available
 Error in re-setting breakpoint -28: PC register is not available
 Error in re-setting breakpoint -29: PC register is not available
 Error in re-setting breakpoint -30: PC register is not available
 PC register is not available
 (gdb)

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* linux-low.c (add_lwp): Set waitstatus to TARGET_WAITKIND_IGNORE.
	(linux_thread_alive): Use lwp_is_marked_dead.
	(extended_event_reported): Delete.
	(linux_wait_1): Check if waitstatus is TARGET_WAITKIND_IGNORE
	instead of extended_event_reported.
	(mark_lwp_dead): Don't set the 'dead' flag.  Store the waitstatus
	as well.
	(lwp_is_marked_dead): New function.
	(lwp_running): Use lwp_is_marked_dead.
	* linux-low.h: Delete 'dead' field, and update 'waitstatus's
	comment.
2015-08-06 10:30:17 +01:00
Pedro Alves ad071a3055 Linux gdbserver fork event debug output
The "extended event with waitstatus" debug output is unreachable, as
it is guarded by "if (!report_to_gdb)".  If extended_event_reported is
true, then so is report_to_gdb.  Move it to where we print why we're
reporting an event to GDB.

Also, the debug output currently tries to print the wrong struct
target_waitstatus.

gdb/gdbserver/ChangeLog:
2015-08-06  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_wait_1): Move fork event output out of the
	!report_to_gdb check.  Pass event_child->waitstatus to
	target_waitstatus_to_string instead of ourstatus.
2015-08-06 10:30:16 +01:00
Pedro Alves 0a39bb3218 stepping is disturbed by setjmp/longjmp | try/catch in other threads
At https://sourceware.org/ml/gdb-patches/2015-08/msg00097.html, Joel
observed that trying to next/step a program on GNU/Linux sometimes
results in the following failed assertion:

	% gdb -q .obj/gprof/main
    (gdb) start
    (gdb) n
    (gdb) step
    [...]/infrun.c:2391: internal-error:
    resume: Assertion `sig != GDB_SIGNAL_0' failed.

What happened is that, during the "next" operation, GDB hit a
longjmp/exception/step-resume breakpoint but failed to see that this
breakpoint was set for a different thread than the one being stepped.

Joel's detailed analysis follows:

More precisely, at the end of the "start" command, we are stopped at
the start of function Main in main.adb; there are 4 threads in total,
and we are in the main thread (which is thread 1):

    (gdb) info thread
      Id   Target Id         Frame
      4    Thread 0xb7a56ba0 (LWP 28379) 0xffffe410 in __kernel_vsyscall ()
      3    Thread 0xb7c5aba0 (LWP 28378) 0xffffe410 in __kernel_vsyscall ()
      2    Thread 0xb7e5eba0 (LWP 28377) 0xffffe410 in __kernel_vsyscall ()
    * 1    Thread 0xb7ea18c0 (LWP 28370) main () at /[...]/main.adb:57

All the logs below reference Thread ID/LWP, but it'll be easier to
talk about the threads by GDB thread number.  For instance, thread 1
is LWP 28370 while thread 3 is LWP 28378.  So, the explanations below
translate the LWPs into thread numbers.

Back to what happens while we are trying to "next' our program:
    (gdb) n
    infrun: clear_proceed_status_thread (Thread 0xb7a56ba0 (LWP 28379))
    infrun: clear_proceed_status_thread (Thread 0xb7c5aba0 (LWP 28378))
    infrun: clear_proceed_status_thread (Thread 0xb7e5eba0 (LWP 28377))
    infrun: clear_proceed_status_thread (Thread 0xb7ea18c0 (LWP 28370))
    infrun: proceed (addr=0xffffffff, signal=GDB_SIGNAL_DEFAULT)
    infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0xb7ea18c0 (LWP 28370)] at 0x805451e
    infrun: target_wait (-1.0.0, status) =
    infrun:   28370.28370.0 [Thread 0xb7ea18c0 (LWP 28370)],
    infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
    infrun: TARGET_WAITKIND_STOPPED
    infrun: stop_pc = 0x8054523

We've resumed thread 1 (LWP 28370), and received in return a signal
that the same thread stopped slightly further.  It's still in the
range of instructions for the line of source we started the "next"
from, as evidenced by the following trace...

    infrun: stepping inside range [0x805451e-0x8054531]

... and thus, we decide to continue stepping the same thread:

    infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0xb7ea18c0 (LWP 28370)] at 0x8054523
    infrun: prepare_to_wait

That's when we get an event from a different thread (thread 3)...

    infrun: target_wait (-1.0.0, status) =
    infrun:   28370.28378.0 [Thread 0xb7c5aba0 (LWP 28378)],
    infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
    infrun: TARGET_WAITKIND_STOPPED
    infrun: stop_pc = 0x80782d0
    infrun: context switch
    infrun: Switching context from Thread 0xb7ea18c0 (LWP 28370) to Thread 0xb7c5aba0 (LWP 28378)

... which we find to be at the address where we set a breakpoint on
"the unwinder debug hook" (namely "_Unwind_DebugHook").  But GDB fails
to notice that the breakpoint was inserted for thread 1 only, and so
decides to handle it as...

    infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME

... and inserts a breakpoint at the corresponding resume address, as
evidenced by this the next log:

    infrun: exception resume at 80542a2

That breakpoint seems innocent right now, but will play a role fairly
quickly.  But for now, GDB has inserted the exception-resume
breakpoint, and needs to single-step thread 3 past the breakpoint it
just hit.  Thus, it temporarily disables the exception breakpoint, and
requests a step of that thread:

    infrun: skipping breakpoint: stepping past insn at: 0x80782d0
    infrun: skipping breakpoint: stepping past insn at: 0x80782d0
    infrun: skipping breakpoint: stepping past insn at: 0x80782d0
    infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=1, current thread [Thread 0xb7c5aba0 (LWP 28378)] at 0x80782d0
    infrun: prepare_to_wait

We then get a notification, still from thread 3, that it's now past
that breakpoint...

    infrun: prepare_to_wait
    infrun: target_wait (-1.0.0, status) =
    infrun:   28370.28378.0 [Thread 0xb7c5aba0 (LWP 28378)],
    infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
    infrun: TARGET_WAITKIND_STOPPED
    infrun: stop_pc = 0x8078424

... so we can resume what we were doing before, which is single-stepping
thread 1 until we get to a new line of code:

    infrun: switching back to stepped thread
    infrun: Switching context from Thread 0xb7c5aba0 (LWP 28378) to Thread 0xb7ea18c0 (LWP 28370)
    infrun: expected thread still hasn't advanced
    infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0xb7ea18c0 (LWP 28370)] at 0x8054523

The "resume" log above shows that we're resuming thread 1 from where
we left off (0x8054523).  We get one more stop at 0x8054529, which is
still inside our stepping range so we go again.  That's when we get
the following event, from thread 3:

    infrun: prepare_to_wait
    infrun: target_wait (-1.0.0, status) =
    infrun:   28370.28378.0 [Thread 0xb7c5aba0 (LWP 28378)],
    infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
    infrun: TARGET_WAITKIND_STOPPED
    infrun: stop_pc = 0x80542a2

Now the stop_pc address is interesting, because it's the address of
"exception resume" breakpoint...

    infrun: context switch
    infrun: Switching context from Thread 0xb7ea18c0 (LWP 28370) to Thread 0xb7c5aba0 (LWP 28378)
    infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME

... and since that location is at a different line of code, this is
where it decides the "next" operation should stop:

    infrun: stop_waiting
    [Switching to Thread 0xb7c5aba0 (LWP 28378)]
    0x080542a2 in inte_tache_rt.ttache_rt (
        <_task>=0x80968ec <inte_tache_rt_inst.tache2>)
        at /[...]/inte_tache_rt.adb:54
    54            end loop;

However, what GDB should have noticed earlier that the exception
breakpoint we hit was for a different thread, thus should have
single-stepped that thread out of the breakpoint _without_ inserting
the exception-return breakpoint, and then resumed the single-stepping
of the initial thread (thread 1) until that thread stepped out of its
stepping range.

This is what this patch does, and after applying it, GDB now correctly
stops on the next line of code.

The patch adds a C++ test that exercises this, both for setjmp/longjmp
and exception breakpoints.  With an unpatched GDB it shows:

 (gdb) next
 [Switching to Thread 22445.22455]
 thread_try_catch (arg=0x0) at /home/pedro/gdb/mygit/build/../src/gdb/testsuite/gdb.threads/next-other-thr-longjmp.c:59
 59            catch (...)
 (gdb) FAIL: gdb.threads/next-other-thr-longjmp.exp: next to line 1
 next
 /home/pedro/gdb/mygit/build/../src/gdb/infrun.c:4865: internal-error: process_event_stop_test: Assertion `ecs->event_thread->control.exception_resume_breakpoint != NULL' fa
 iled.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/next-other-thr-longjmp.exp: next to line 2 (GDB internal error)
 Resyncing due to internal error.
 n

Tested on x86_64-linux, no regressions.

gdb/ChangeLog:
2015-08-05  Pedro Alves  <palves@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>

        * breakpoint.c (bpstat_what) <bp_longjmp, bp_longjmp_call_dummy>
	<bp_exception, bp_longjmp_resume, bp_exception_resume>: Handle the
	case where BS->STOP is not set.

gdb/testsuite/ChangeLog:
2015-08-05  Pedro Alves  <palves@redhat.com>

	* gdb.threads/next-while-other-thread-longjmps.c: New file.
	* gdb.threads/next-while-other-thread-longjmps.exp: New file.
2015-08-05 20:01:42 +01:00
Ulrich Weigand 260439cb8e Protect nat/gdb_thread_db.h against multiple inclusion.
Fixes a build error due to typedef redefinition with some compilers.

Also added missing copyright header.

gdb/
	* nat/gdb_thread_db.h: Add copyright header.
	Protect against multiple inclusion.
2015-08-05 16:30:57 +02:00
Yao Qi d89fa914ad Remove get_thread_id
This patch removes get_thread_id from aarch64-linux-nat.c,
arm-linux-nat.c and xtensa-linux-nat.c.

get_thread_id was added in this commit below in 2000,

  41c49b06c4
  https://sourceware.org/ml/gdb-patches/2000-04/msg00398.html

which predates the ptid_t stuff added into GDB.  Nowadays, lwpid of
inferior_ptid is only zero when the inferior is created (in
fork-child.c:fork_inferior) and its lwpid will be set after
linux_nat_wait_1 gets the first event.  After that, lwpid of
inferior_ptid is not zero for linux-nat target, then we can use
ptid_get_lwp, so this function isn't needed anymore.

Even when GDB attaches to a process, the lwp of inferior_ptid
isn't zero,  see linux-nat.c:linux_nat_attach,

  /* The ptrace base target adds the main thread with (pid,0,0)
     format.  Decorate it with lwp info.  */
  ptid = ptid_build (ptid_get_pid (inferior_ptid),
		     ptid_get_pid (inferior_ptid),
		     0);

Note that linux_nat_xfer_partial shifts lwpid to pid for inferior_ptid
temperately for calling linux_ops->to_xfer_partial, but all the
affected functions in this patch are not called in
linux_ops->to_xfer_partial.

I think we can safely remove get_thread_id for all linux native targets.

Regression tested on arm-linux and aarch64-linux.  Unable to build
native GDB and test it on xtensa-linux.

gdb:

2015-08-05  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (get_thread_id): Remove.
	(debug_reg_change_callback): Call ptid_get_lwp instead of
	get_thread_id.
	(fetch_gregs_from_thread): Likewise.
	(store_gregs_to_thread): Likewise.
	(fetch_fpregs_from_thread): Likewise.
	(store_fpregs_to_thread): Likewise.
	(aarch64_linux_get_debug_reg_capacity): Likewise.
	* arm-linux-nat.c (get_thread_id): Remove.
	(GET_THREAD_ID): Update macro to use ptid_get_lwp.
	* xtensa-linux-nat.c (get_thread_id): Remove.
	(GET_THREAD_ID): Update macro to use ptid_get_lwp.
	* arm-linux-nat.c (get_thread_id): Remove.
	(GET_THREAD_ID): Remove.
	(fetch_fpregs): Call ptid_get_lwp instead of GET_THREAD_ID.
	(store_fpregs, fetch_regs, store_regs): Likewise.
	(fetch_wmmx_regs, store_wmmx_regs): Likewise.
	(fetch_vfp_regs, store_vfp_regs): Likewise.
	(arm_linux_read_description): Likewise.
	(arm_linux_get_hwbp_cap): Likewise.
	* xtensa-linux-nat.c (get_thread_id): Remove.
	(GET_THREAD_ID): Remove.
	(fetch_gregs, store_gregs): Call ptid_get_lwp instead of
	GET_THREAD_ID.
2015-08-05 08:41:19 +01:00
Ciro Santilli 4efd80aa8a python: fix Linetable case to LineTable in docstrings and comments
The class is called LineTable, not Linetable, as specified by
py-linetable.c/gdbpy_initialize_linetable:

    if (gdb_pymodule_addobject (gdb_module, "LineTable",

gdb/ChangeLog:

        * python/py-linetable.c: Fix case of Linetable to LineTable
        in docstrings and code comments.
        * python/py-symtab.c: Same.
2015-08-04 09:50:53 -07:00
Yao Qi 524b57e6b3 Disable tracepoint support for aarch32
We only support tracepoint for aarch64.  Although arm program can run
on aarch64, GDBserver doesn't support tracepoint for it.

gdb/gdbserver:

2015-08-04  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_supports_tracepoints): Return 0
	if current_thread is 32 bit.
2015-08-04 14:34:14 +01:00
Yao Qi 6085d6f695 Disable Z0 packet on aarch64 on multi-arch debugging
In multi-arch debugging, if GDB sends Z0 packet, GDBserver should be
able to do several things below:

 - choose the right breakpoint instruction to insert according to the
   information available, such as 'kind' in Z0 packet and address,

 - choose the right breakpoint instruction to check memory writes and
   validate inserted memory breakpoint

 - be aware of different breakpoint instructions in $ARCH_breakpoint_at.

unfortunately GDBserver can't do them now.  Although x86 GDBserver
supports multi-arch, it doesn't need to support them above because
breakpoint instruction on i686 and x86_64 is the same.  However,
breakpoint instructions on aarch64 and arm (arm mode, thumb1, and thumb2)
are different.

I tried to teach aarch64 GDBserver backend to be really
multi-arch-capable in the following ways,

 - linux_low_target return the right breakpoint instruction according to
   the 'kind' in Z0 packet, and insert_memory_breakpoint can do the right
   thing.
 - once breakpoint is inserted, the breakpoint data and length is recorded
   in each breakpoint object, so that validate_breakpoint and
   check_mem_write can get the right breakpoint instruction from each
   breakpoint object, rather than from global variable breakpoint_data.
 - linux_low_target needs another hook function for pc increment after
   hitting a breakpoint.
 - let set_breakpoint_at, which is widely used for tracepoint, use the
   'default' breakpoint instruction.  We can always use aarch64 breakpoint
   instruction since arm doesn't support tracepoint yet.

looks it is not a small piece of work, so I decide to disable Z0 packet
on multi-arch, which means aarch64 GDBserver only supports Z0 packet
if it is started to debug only one process (extended protocol is not
used) and process target description is 64-bit.

gdb/gdbserver:

2015-08-04  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_supports_z_point_type): Return
	0 for Z_PACKET_SW_BP if it may be used in multi-arch debugging.
	* server.c (extended_protocol): Remove "static".
	* server.h (extended_protocol): Declare it.
2015-08-04 14:34:14 +01:00
Yao Qi 8a7e4587c4 Get and set PC correctly on aarch64 in multi-arch
gdb/gdbserver:

2015-08-04  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_get_pc): Get PC register on
	both aarch64 and aarch32.
	(aarch64_set_pc): Likewise.
2015-08-04 14:34:14 +01:00