Commit Graph

35935 Commits

Author SHA1 Message Date
Pedro Alves faf09f0119 Linux native: Use TRAP_BRKPT/TRAP_HWBPT
This patch adjusts the native Linux target backend to tell the core
whether a trap was caused by a breakpoint.

It teaches the target to get that information out of the si_code of
the SIGTRAP siginfo.

Tested on x86-64 Fedora 20, s390 RHEL 7, and PPC64 Fedora 18.  An
earlier version was tested on ARM Fedora 21.

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

	* linux-nat.c (save_sigtrap): Check for breakpoints before
	checking watchpoints.
	(status_callback) [USE_SIGTRAP_SIGINFO]: Don't check whether a
	breakpoint is inserted if relying on SIGTRAP's siginfo.si_code.
	(check_stopped_by_breakpoint) [USE_SIGTRAP_SIGINFO]: Decide whether
	a breakpoint triggered based on the SIGTRAP's siginfo.si_code.
	(linux_nat_stopped_by_sw_breakpoint)
	(linux_nat_supports_stopped_by_sw_breakpoint)
	(linux_nat_stopped_by_hw_breakpoint)
	(linux_nat_supports_stopped_by_hw_breakpoint): New functions.
	(linux_nat_wait_1): Don't re-increment the PC if relying on
	SIGTRAP's siginfo->si_code.
	(linux_nat_add_target): Install new target methods.
	* linux-thread-db.c (check_event): Don't account for breakpoint PC
	offset if the target already adjusted the PC.
	* nat/linux-ptrace.h (USE_SIGTRAP_SIGINFO): New.
	(GDB_ARCH_TRAP_BRKPT): New.
	(TRAP_HWBKPT): Define if not already defined.
2015-03-04 20:41:16 +00:00
Pedro Alves f7e6eed528 remote+docs: software/hardware breakpoint traps
This adjusts target remote to tell the core whether a trap was caused
by a breakpoint.

To that end, the patch teaches GDB about new RSP stop reasons "T05
swbreak" and "T05 hwbreak", that remote targets report back to GDB,
similarly to how "T05 watch" indicates a stop caused by a watchpoint.

Because targets that can report these events are expected to
themselves adjust the PC after a software breakpoint, these new stop
reasons must only be reported if the stub is talking to a GDB that
understands them.  Because of that, the use of the new stop reasons
needs to be handshaked on initial connection, using the qSupported
mechanism.  GDB simply sends "swbreak+" in its qSupports query, and
the stub reports back "swbreak+" too.

Because these new stop reasons are required to fix a fundamental
non-stop mode problem, this commit extends the remote non-stop intro
section in the manual, documenting the events as required.

To be clear, GDB will still cope with remote targets that don't
support these new stop reasons; it will behave just like today.

Tested on x86-64 Fedora 20, native and gdbserver.

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

	* NEWS: Mention the new "swbreak" and "hwbreak" stop reasons.
	* remote.c (struct remote_state) <remote_stopped_by_watchpoint_p>:
	Delete field.
	<stop_reason>: New field.
	(PACKET_swbreak_feature, PACKET_hwbreak_feature): New enum values.
	(packet_set_cmd_state): New function.
	(remote_protocol_features): Register the "swbreak" and "hwbreak"
	features.
	(remote_query_supported): If not disabled with the corresponding
	"set remote foo-packet" command, report support for the swbreak
	and hwbreak features.
	(struct stop_reply) <remote_stopped_by_watchpoint_p>: Delete
	field.
	<stop_reason>: New field.
	(remote_parse_stop_reply): Handle "swbreak" and "hwbreak".
	(remote_wait_as): Adjust.
	(remote_stopped_by_sw_breakpoint)
	(remote_supports_stopped_by_sw_breakpoint)
	(remote_stopped_by_hw_breakpoint)
	(remote_supports_stopped_by_hw_breakpoint): New functions.
	(remote_stopped_by_watchpoint): New function.
	(init_remote_ops): Install them.
	(_initialize_remote): Register new "set/show remote
	swbreak-feature-packet" and "set/show remote
	swbreak-feature-packet" commands.

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

	* gdb.texinfo (Remote Configuration): Document the "set/show
	remote swbreak-feature-packet" and "set/show remote
	hwbreak-feature-packet" commands.
	(Packets) <Z0>: Add cross link to the "swbreak" stop reason's
	decription.
	(Stop Reply Packets): Document the swbreak and hwbreak stop
	reasons.
	(General Query Packets): Document the swbreak and hwbreak
	qSupported features.
	(Remote Non-Stop): Explain that swbreak and hwbreak are required.
2015-03-04 20:41:16 +00:00
Pedro Alves 9e8915c6ce record-full/record-btrace: software/hardware breakpoint trap
This adjusts the record targets to tell the core whether a trap was
caused by a breakpoint.  Targets that can do this should report
breakpoint traps with the PC already adjusted, so this removes the
re-incrementing record-full was doing.

These targets need to be adjusted before process_stratum targets
beneath are, otherwise target_supports_stopped_by_sw_breakpoint,
etc. would fall through to the target beneath while
recording/replaying, and the core would get confused.

Tested on x86-64 Fedora 20, native and gdbserver.

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

	* btrace.h: Include target/waitstatus.h.
	(struct btrace_thread_info) <stop_reason>: New field.
	* record-btrace.c (record_btrace_step_thread): Use
	record_check_stopped_by_breakpoint instead of breakpoint_here_p.
	(record_btrace_decr_pc_after_break): Delete.
	(record_btrace_stopped_by_sw_breakpoint)
	(record_btrace_supports_stopped_by_sw_breakpoint)
	(record_btrace_stopped_by_hw_breakpoint)
	(record_btrace_supports_stopped_by_hw_breakpoint): New functions.
	(init_record_btrace_ops): Install them.
	* record-full.c (record_full_hw_watchpoint): Delete and replace
	with ...
	(record_full_stop_reason): ... this throughout.
	(record_full_exec_insn): Adjust.
	(record_full_wait_1): Adjust.  No longer re-increment the PC.
	(record_full_wait_1): Adjust.  Use
	record_check_stopped_by_breakpoint instead of breakpoint_here_p.
	(record_full_stopped_by_watchpoint): Adjust.
	(record_full_stopped_by_sw_breakpoint)
	(record_full_supports_stopped_by_sw_breakpoint)
	(record_full_supports_stopped_by_sw_breakpoint)
	(record_full_stopped_by_hw_breakpoint)
	(record_full_supports_stopped_by_hw_breakpoint): New functions.
	(init_record_full_ops, init_record_full_core_ops): Install them.
	* record.c (record_check_stopped_by_breakpoint): New function.
	* record.h: Include target/waitstatus.h.
	(record_check_stopped_by_breakpoint): New declaration.
2015-03-04 20:41:15 +00:00
Pedro Alves 15c66dd626 enum lwp_stop_reason -> enum target_stop_reason
We're going to need the same enum as enum lwp_stop_reason in more
targets, so this promotes it to common code.

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

	enum lwp_stop_reason -> enum target_stop_reason
	* linux-low.c (check_stopped_by_breakpoint): Adjust.
	(thread_still_has_status_pending_p, check_stopped_by_watchpoint)
	(linux_wait_1, stuck_in_jump_pad_callback)
	(move_out_of_jump_pad_callback, linux_resume_one_lwp)
	(linux_stopped_by_watchpoint):
	* linux-low.h (enum lwp_stop_reason): Delete.
	(struct lwp_info) <stop_reason>: Now an enum target_stop_reason.
	* linux-x86-low.c (x86_linux_prepare_to_resume): Adjust.

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

	enum lwp_stop_reason -> enum target_stop_reason
	* linux-nat.c (linux_resume_one_lwp, check_stopped_by_watchpoint)
	(linux_nat_stopped_by_watchpoint, status_callback)
	(linux_nat_wait_1): Adjust.
	* linux-nat.h (enum lwp_stop_reason): Delete.
	(struct lwp_info) <stop_reason>: Now an enum target_stop_reason.
	* x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
	* target/waitstatus.h (enum target_stop_reason): New.
2015-03-04 20:41:15 +00:00
Pedro Alves 1cf4d9513a Teach GDB about targets that can tell whether a trap is a breakpoint event
The moribund locations heuristics are problematic.  This patch teaches
GDB about targets that can reliably tell whether a trap was caused by
a software or hardware breakpoint, and thus don't need moribund
locations, thus bypassing all the problems that mechanism has.

The non-stop-fair-events.exp test is frequently failing currently.
E.g., see https://sourceware.org/ml/gdb-testers/2015-q1/msg03148.html.

The root cause is a fundamental problem with moribund locations.  For
example, the stepped_breakpoint logic added by af48d08f breaks in this
case (which is what happens with that test):

 - Step thread A, no breakpoint is set at PC.

 - The kernel doesn't schedule thread A yet.

 - Insert breakpoint at A's PC, for some reason (e.g., a step-resume
   breakpoint for thread B).

 - Kernel finally schedules thread A.

 - thread A's stepped_breakpoint flag is not set, even though it now
   stepped a breakpoint instruction.

 - adjust_pc_after_break gets the PC wrong, because PC == PREV_PC, but
   stepped_breakpoint is not set.

We needed the stepped_breakpoint logic to workaround moribund
locations, because otherwise adjust_pc_after_break could apply an
adjustment when it shouldn't just because there _used_ to be a
breakpoint at PC (a moribund breakpoint location).  For example, on
x86, that's wrong if the thread really hasn't executed an int3, but
instead executed some other 1-byte long instruction.  Getting the PC
adjustment wrong of course leads to the inferior executing the wrong
instruction.

Other problems with moribund locations are:

 - if a true SIGTRAP happens to be raised when the program is
   executing the PC that used to have a breakpoint, GDB will assume
   that is a trap for a breakpoint that has recently been removed, and
   thus we miss reporting the random signal to the user.

 - to minimize that, we get rid of moribund location after a while.
   That while is defined as just a certain number of events being
   processed.  That number of events sometimes passes by before a
   delayed breakpoint is processed, and GDB confuses the trap for a
   random signal, thus reporting the random trap.  Once the user
   resumes the thread, the program crashes because the PC was not
   adjusted...

The fix for all this is to bite the bullet and get rid of heuristics
and instead rely on the target knowing accurately what caused the
SIGTRAP.  The target/kernel/stub is in the best position to know what
that, because it can e.g. consult priviledged CPU flags GDB has no
access to, or by knowing which exception vector entry was called when
the instruction trapped, etc.  Most debug APIs I've seen to date
report breakpoint hits as a distinct event in some fashion.  For
example, on the Linux kernel, whether a breakpoint was executed is
exposed to userspace in the si_code field of the SIGTRAP's siginfo.
On Windows, the debug API reports a EXCEPTION_BREAKPOINT exception
code.

We needed to keep around deleted breakpoints in an on-the-side list
(the moribund locations) for two main reasons:

  - Know that a SIGTRAP actually is a delayed event for a hit of a
    breakpoint that was removed before the event was processed, and
    thus should not be reported as a random signal.

  - So we still do the decr_pc_after_break adjustment in that case, so
    that the thread is resumed at the correct address.

In the new model, if GDB processes an event the target tells is a
breakpoint trap, and GDB doesn't find the corresponding breakpoint in
its breakpoint tables, it means that event is a delayed event for a
breakpoint that has since been removed, and thus the event should be
ignored.

For the decr_pc_after_after issue, it ends up being much simpler that
on targets that can reliably tell whether a breakpoint trapped, for
the breakpoint trap to present the PC already adjusted.  Proper
multi-threading support already implies that targets needs to be doing
decr_pc_after_break adjustment themselves, otherwise for example, in
all-stop if two threads hit a breakpoint simultaneously, and the user
does "info threads", he'll see the non-event thread that hit the
breakpoint stopped at the wrong PC.

This way (target adjusts) also ends up eliminating the need for some
awkward re-incrementing of the PC in the record-full and Linux targets
that we do today, and the need for the target_decr_pc_after_break
hook.

If the target always adjusts, then there's a case where GDB needs to
re-increment the PC.  Say, on x86, an "int3" instruction that was
explicitly written in the program traps.  In this case, GDB should
report a random SIGTRAP signal to the user, with the PC pointing at
the instruction past the int3, just like if GDB was not debugging the
program.  The user may well decide to pass the SIGTRAP to the program
because the program being debugged has a SIGTRAP handler that handles
its own breakpoints, and expects the PC to be unadjusted.

Tested on x86-64 Fedora 20.

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

	* breakpoint.c (need_moribund_for_location_type): New function.
	(bpstat_stop_status): Don't skipping checking moribund locations
	of breakpoint types which the target tell caused a stop.
	(program_breakpoint_here_p): New function, factored out from ...
	(bp_loc_is_permanent): ... this.
	(update_global_location_list): Don't create a moribund location if
	the target supports reporting stops of the type of the removed
	breakpoint.
	* breakpoint.h (program_breakpoint_here_p): New declaration.
	* infrun.c (adjust_pc_after_break): Return early if the target has
	already adjusted the PC.  Add comments.
	(handle_signal_stop): If nothing explains a signal, and the target
	tells us the stop was caused by a software breakpoint, check if
	there's a breakpoint instruction in the memory.  If so, adjust the
	PC before presenting the stop to the user.  Otherwise, ignore the
	trap.  If nothing explains a signal, and the target tells us the
	stop was caused by a hardware breakpoint, ignore the trap.
	* target.h (struct target_ops) <to_stopped_by_sw_breakpoint,
	to_supports_stopped_by_sw_breakpoint, to_stopped_by_hw_breakpoint,
	to_supports_stopped_by_hw_breakpoint>: New fields.
	(target_stopped_by_sw_breakpoint)
	(target_supports_stopped_by_sw_breakpoint)
	(target_stopped_by_hw_breakpoint)
	(target_supports_stopped_by_hw_breakpoint): Define.
	* target-delegates.c: Regenerate.
2015-03-04 20:41:15 +00:00
Pedro Alves be9957b82f Fix gdb.threads/thread-specific-bp.exp race
Gary stumbled on this:

 (gdb) PASS: gdb.threads/thread-specific-bp.exp: all-stop: continue to end
 info threads
   Id   Target Id         Frame
 * 1    Thread 0x7ffff7fdb700 (LWP 13717) "thread-specific" end () at /home/gary/work/archer/startswith/src/gdb/testsuite/gdb.threads/thread-specific-bp.c:29
 (gdb) FAIL: gdb.threads/thread-specific-bp.exp: all-stop: thread start is gone
 info breakpoint

The problem is that "...archer/startswith/src..." has a "start" in it,
which matches the too-lax regex in the test.

Rather than tweaking the regex, we can just remove the whole "info
threads", like we removed similar ones in other files -- GDB nowadays
does this implicitly already, so things should work without it.  Thus
removing this even improves testing here a bit.

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

	* gdb.threads/thread-specific-bp.exp: Delete "info threads" test.
2015-03-04 17:23:55 +00:00
Pedro Alves 79639e1132 follow-fork: don't lose the ptids as set by the target
This Linuxism has made its way into infrun.c, in the follow-fork code:

       inferior_ptid = ptid_build (child_pid, child_pid, 0);

The OS-specific code should fill in the LWPID, TID parts with the
appropriate values, if any, and the core code should not be peeking at
the components of the ptids.

gdb/
2015-03-04  Pedro Alves  <palves@redhat.com>

	* infrun.c (follow_fork_inferior): Use the whole of the
	inferior_ptid and pending_follow.related_pid ptids instead of
	building ptids from the process components.  Adjust verbose output
	to use target_pid_to_str.
	* linux-nat.c (linux_child_follow_fork): Use the whole of the
	inferior_ptid and pending_follow.related_pid ptids instead of
	building ptids from the process components.
2015-03-04 15:03:33 +00:00
Mark Kettenis d57be0f442 Stupid git!
Apparently fixing a typo while you're editing the commit message doesn't work.
2015-03-04 15:40:27 +01:00
Yao Qi 98fc70d642 Add linux-aarch64-low.c in SFILE
gdb/gdbserver:

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

	* Makefile.in (SFILES): Add linux-aarch64-low.c.
2015-03-04 14:22:17 +00:00
Mark Kettenis 4727d6136a Enable gdb.base/foll-fork.exp on OpenBSD
gdb/testsuite/
2015-03-04  Mark Kettenis  <kettenis@gnu.org>

        * gdb.base/foll-fork.exp: Enable on *-*-openbsd*.
2015-03-04 14:53:14 +01:00
Mark Kettenis e85e8e5eff Make "catch fork" work on systems with PT_GET_PROCESS_STATE
These systems (OpenBSD and HP-UX 10.x) already support follow-fork
including the events needed to for "catch fork".  This just makes
the upper layers realize this.

gdb/
2015-03-04  Mark Kettenis  <kettenis@gnu.org>

        * inf-ptrace.c [PT_GET_PROCESS_STATE]
        (inf_ptrace_insert_fork_catchpoint): New function.
        (inf_ptrace_remove_fork_catchpoint): New function.
        (inf_ptrace_target) [PT_GET_PROCESS_STATE]: Install them.
2015-03-04 14:36:12 +01:00
Andreas Arnez 87de11c052 S390: Name "invisible" registers with the empty string instead of NULL
When adding vector register support to GDB, s390_register_name() was
added to suppress the right halves of the first 16 vector registers.
However, that function returned NULL instead of an empty string in such
a case.  This leads to an incomplete list of registers returned by
"complete info registers ", because completion stops at the first NULL
return value from user_reg_map_regnum_to_name().

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_register_name): Return empty string
	instead of NULL for registers that shouldn't be visible.
2015-03-04 10:40:41 +01:00
Andreas Arnez c214c7cfd3 breakpoint-in-ro-region.exp: Support targets stopping in mid-line after "si"
On some targets each of the assignments "i = 0" in the C source for
"breakpoint-in-ro-region.exp" are compiled to a single instruction.
Then each "si" stops at the beginning of the next source line.  But on
some other targets (like s390) such an assignment compiles to multiple
instructions.  Then "si" may stop in mid-line, and GDB displays the PC
address in addition to the source line number.  This was not considered
by the regexp for this case.

gdb/testsuite/ChangeLog:

	* gdb.base/breakpoint-in-ro-region.exp (test_single_step): In the
	regexps for GDB's current line display, accept a hex address
	preceding the line number.
2015-03-04 10:40:40 +01:00
Andreas Arnez 6d74a497ba catch-syscall.exp: Fix missing architecture name for s390:31-bit
For the "multiple targets" test in catch-syscall.exp, set the 'arch1'
variable to a valid string.

gdb/testsuite/ChangeLog:

	* gdb.base/catch-syscall.exp (test_catch_syscall_multi_arch): Set
	the 'arch1' variable for "s390*-linux*" targets.
2015-03-04 10:40:40 +01:00
Andreas Arnez d851a69aa2 S390: Fix syscall list for s390x
This patch fixes a typo that caused the wrong syscall XML file to be
used for s390x targets.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_gdbarch_init): Use the correct syscall
	XML file for 64-bit targets.
2015-03-04 10:40:40 +01:00
Pedro Alves 511aee7c39 gdb.threads/clone-thread_db.c: Add missing includes and fix pthread_join call
This fixes:

> gdb compile failed, /gdb/testsuite/gdb.threads/clone-thread_db.c: In function 'main':
> /gdb/testsuite/gdb.threads/clone-thread_db.c:67:3: warning: implicit declaration of function 'alarm' [-Wimplicit-function-declaration]
>    alarm (300);
>    ^
> /gdb/testsuite/gdb.threads/clone-thread_db.c:69:3: warning: implicit declaration of function 'pthread_create' [-Wimplicit-function-declaration]
>    pthread_create (&child, NULL, thread_fn, NULL);
>    ^
> /gdb/testsuite/gdb.threads/clone-thread_db.c:70:3: warning: implicit declaration of function 'pthread_join' [-Wimplicit-function-declaration]
>    pthread_join (child);
>    ^

And then adding the missing headers revealed the pthread_join call was
incorrect.  This probably fixes the crash we see on ppc64be, e.g., at

 https://sourceware.org/ml/gdb-testers/2015-q1/msg04415.html

the logs there show:

 ...
 Program received signal SIGSEGV, Segmentation fault.
 [Switching to Thread 0x3fffb7ff54a0 (LWP 9275)]
 0x00003fffb7f3ce74 in .pthread_join () from /lib64/libpthread.so.0
 (gdb) FAIL: gdb.threads/clone-thread_db.exp: continue to end
 ...

Tested on x86_64 Fedora 20.

gdb/testsuite/
2015-03-04  Pedro Alves  <palves@redhat.com>

	* gdb.threads/clone-thread_db.c: Include unistd.h and pthread.h.
	(main): Pass missing retval argument to pthread_join call.
2015-03-04 09:13:49 +00:00
Simon Marchi b072f6c163 Remove unused function declarations in target.h
find_default_create_inferior and find_default_attach were removed in b3ccfe11.

gdb/ChangeLog:

	* target.h (find_default_create_inferior): Remove declaration.
	(find_default_attach): Likewise.
2015-03-03 17:39:30 -05:00
Pedro Alves c1593e4fa9 inf-ptrace.c: use ptid_get_pid when resuming all threads
In this case, we want to resume the entire process and not an
individual thread.

gdb/
2015-03-03  Pedro Alves  <palves@redhat.com>

	* inf-ptrace.c (inf_ptrace_resume): Remove spurious whitespace.
	Use ptid_get_pid to get the overall process id when resuming all
	threads.
2015-03-03 16:28:15 +00:00
Philippe Proulx a64c9f7b85 Fix GDB/MI doc: duplicate syscall-entry under *stopped
gdb/doc/ChangeLog:

2015-03-03  Philippe Proulx  eeppeliteloop@gmail.com

	* gdb.texinfo (gdb/mi Async Records): Fix duplicate syscall-entry
	under *stopped.
2015-03-03 10:29:26 -05:00
Pedro Alves 90ad5e1d4f Linux/ptrace: don't convert ptids when asking inf-ptrace layer to resume LWP
Ref: https://sourceware.org/ml/gdb-patches/2015-03/msg00060.html

The record-btrace target can hit an assertion here:

 Breakpoint 1, record_btrace_fetch_registers (ops=0x974bfc0 <record_btrace_ops>,
     regcache=0x9a0a798, regno=8) at gdb/record-btrace.c:1202
 1202	  gdb_assert (tp != NULL);

 (gdb) p regcache->ptid
 $3 = {pid = 23856, lwp = 0, tid = 0}

The problem is that the linux-nat layer converts the ptid to a
single-process ptid before passing the request down to the inf-ptrace
layer, which loses information, and then record-btrace can't find the
corresponding thread in GDB's thread list:

 (gdb) bt
 #0  record_btrace_fetch_registers (ops=0x974bfc0 <record_btrace_ops>, regcache=0x9a0a798, regno=8)
     at gdb/record-btrace.c:1202
 #1  0x083f4ee2 in delegate_fetch_registers (self=0x974bfc0 <record_btrace_ops>, arg1=0x9a0a798,
     arg2=8) at gdb/target-delegates.c:149
 #2  0x08406562 in target_fetch_registers (regcache=0x9a0a798, regno=8)
     at gdb/target.c:3279
 #3  0x08355255 in regcache_raw_read (regcache=0x9a0a798, regnum=8,
     buf=0xbfffe6c0 "¨\003\222\tÀ8kIøæÿ¿HO5\b\035]")
     at gdb/regcache.c:643
 #4  0x083558a7 in regcache_cooked_read (regcache=0x9a0a798, regnum=8,
     buf=0xbfffe6c0 "¨\003\222\tÀ8kIøæÿ¿HO5\b\035]")
     at gdb/regcache.c:734
 #5  0x08355de3 in regcache_cooked_read_unsigned (regcache=0x9a0a798, regnum=8, val=0xbfffe738)
     at gdb/regcache.c:838
 #6  0x0827a106 in i386_linux_resume (ops=0x9737ca0 <linux_ops_saved>, ptid=..., step=1,
     signal=GDB_SIGNAL_0) at gdb/i386-linux-nat.c:670
 #7  0x08280c12 in linux_resume_one_lwp (lp=0x9a0a5b8, step=1, signo=GDB_SIGNAL_0)
     at gdb/linux-nat.c:1529
 #8  0x08281281 in linux_nat_resume (ops=0x98da608, ptid=..., step=1, signo=GDB_SIGNAL_0)
     at gdb/linux-nat.c:1708
 #9  0x0850738e in record_btrace_resume (ops=0x98da608, ptid=..., step=1, signal=GDB_SIGNAL_0)
     at gdb/record-btrace.c:1760
 ...

The fix is just to not lose information, and let the intact ptid reach
record-btrace.c.

Tested on x86-64 Fedora 20, -m32.

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

	* i386-linux-nat.c (i386_linux_resume): Get the ptrace PID out of
	the lwp field of ptid.  Pass the full ptid to get_thread_regcache.
	* inf-ptrace.c (get_ptrace_pid): New function.
	(inf_ptrace_resume): Use it.
	* linux-nat.c (linux_resume_one_lwp): Pass the LWP's ptid ummodified
	to the lower layer.
2015-03-03 13:33:44 +00:00
Gary Benson dd2ac17449 Fix incorrect vFile: prefix lengths
gdb/gdbserver/ChangeLog:

	* hostio.c (handle_vFile): Fix prefix lengths.
2015-03-03 12:36:25 +00:00
Markus Metzger d68e53f479 btrace: support 32-bit inferior on 64-bit host
The heuristic for filtering out kernel addressess in BTS trace checks the
most significant bit in each address.  This works fine for 32-bit and 64-bit
mode.

For 32-bit compatibility mode, i.e. a 32-bit inferior running on 64-bit
host, we need to check bit 63 (or any bit bigger than 31), not bit 31.

Use the machine field in struct utsname provided by a uname call to
determine whether we are running on a 64-bit host.

Thanks to Jan Kratochvil for reporting the issue.

gdb/
	* nat/linux-btrace.c: Include sys/utsname.h.
	(linux_determine_kernel_ptr_bits): New.
	(linux_enable_bts): Call linux_determine_kernel_ptr_bits.
	* x86-linux-nat.c (x86_linux_enable_btrace): Do not overwrite non-zero
	ptr_bits.

gdbserver/
	* linux-low.c (linux_low_enable_btrace): Do not overwrite non-zero
	ptr_bits.
2015-03-03 12:47:41 +01:00
Markus Metzger 986b66010c btrace: work around _dl_runtime_resolve returning to resolved function
On some systems, _dl_runtime_resolve returns to the resolved function
instead of jumping to it.  Since btrace will not find the function in
the current stack back trace, it will start a new back trace on the
same level.  It will look the same to the user via the backtrace
command but the frames will have different id's which confuses stepping.

This fixes a test fail with 32-bit inferior reported by Jan Kratochvil.

gdb/
	* btrace.c (ftrace_update_function): Treat return as tailcall for
	"_dl_runtime_resolve".
2015-03-03 09:52:27 +01:00
Markus Metzger ce0dfbeaad btrace: compute line range when printing
The "record function-call-history" command prints the range of source lines
for a function segment when given the /l modifier.  This information is
computed for the entire execution history when processing the recorded branch
trace.

To speed up the initial trace processing, we compute the information when
we print a function segment and only if requested.  The computation is fast
enough (due to the limited scope) that it is not worth storing the data in
struct btrace_function, anymore.

gdb/
	* btrace.h (btrace_function) <lbegin, lend>: Remove.
	* btrace.c (ftrace_debug): Do not print the line range.
	(ftrace_skip_file, ftrace_update_lines): Remove.
	(ftrace_new_function): Remove lbegin and lend initialization.
	(btrace_compute_ftrace_bts): Remove call to ftrace_update_lines.
	* record-btrace.c (btrace_compute_src_line_range): New.
	(btrace_call_history_src_line): Call btrace_compute_src_line_range.
2015-03-03 09:50:06 +01:00
Pedro Alves 95e50b2723 follow-exec: delete all non-execing threads
This fixes invalid reads Valgrind first caught when debugging against
a GDBserver patched with a series that adds exec events to the remote
protocol.  Like these, using the gdb.threads/thread-execl.exp test:

$ valgrind ./gdb -data-directory=data-directory ./testsuite/gdb.threads/thread-execl  -ex "tar extended-remote :9999" -ex "b thread_execler" -ex "c" -ex "set scheduler-locking on"
...
Breakpoint 1, thread_execler (arg=0x0) at src/gdb/testsuite/gdb.threads/thread-execl.c:29
29        if (execl (image, image, NULL) == -1)
(gdb) n
Thread 32509.32509 is executing new program: build/gdb/testsuite/gdb.threads/thread-execl
[New Thread 32509.32532]
==32510== Invalid read of size 4
==32510==    at 0x5AA7D8: delete_breakpoint (breakpoint.c:13989)
==32510==    by 0x6285D3: delete_thread_breakpoint (thread.c:100)
==32510==    by 0x628603: delete_step_resume_breakpoint (thread.c:109)
==32510==    by 0x61622B: delete_thread_infrun_breakpoints (infrun.c:2928)
==32510==    by 0x6162EF: for_each_just_stopped_thread (infrun.c:2958)
==32510==    by 0x616311: delete_just_stopped_threads_infrun_breakpoints (infrun.c:2969)
==32510==    by 0x616C96: fetch_inferior_event (infrun.c:3267)
==32510==    by 0x63A2DE: inferior_event_handler (inf-loop.c:57)
==32510==    by 0x4E0E56: remote_async_serial_handler (remote.c:11877)
==32510==    by 0x4AF620: run_async_handler_and_reschedule (ser-base.c:137)
==32510==    by 0x4AF6F0: fd_event (ser-base.c:182)
==32510==    by 0x63806D: handle_file_event (event-loop.c:762)
==32510==  Address 0xcf333e0 is 16 bytes inside a block of size 200 free'd
==32510==    at 0x4A07577: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==32510==    by 0x77CB74: xfree (common-utils.c:98)
==32510==    by 0x5AA954: delete_breakpoint (breakpoint.c:14056)
==32510==    by 0x5988BD: update_breakpoints_after_exec (breakpoint.c:3765)
==32510==    by 0x61360F: follow_exec (infrun.c:1091)
==32510==    by 0x6186FA: handle_inferior_event (infrun.c:4061)
==32510==    by 0x616C55: fetch_inferior_event (infrun.c:3261)
==32510==    by 0x63A2DE: inferior_event_handler (inf-loop.c:57)
==32510==    by 0x4E0E56: remote_async_serial_handler (remote.c:11877)
==32510==    by 0x4AF620: run_async_handler_and_reschedule (ser-base.c:137)
==32510==    by 0x4AF6F0: fd_event (ser-base.c:182)
==32510==    by 0x63806D: handle_file_event (event-loop.c:762)
==32510==
[Switching to Thread 32509.32532]

Breakpoint 1, thread_execler (arg=0x0) at src/gdb/testsuite/gdb.threads/thread-execl.c:29
29        if (execl (image, image, NULL) == -1)
(gdb)

The breakpoint in question is the step-resume breakpoint of the
non-main thread, the one that was "next"ed.

The exact same issue can be seen on mainline with native debugging, by
running the thread-execl.exp test in non-stop mode, because the kernel
doesn't report a thread exit event for the execing thread.

Tested on x86_64 Fedora 20.

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

	* infrun.c (follow_exec): Delete all threads of the process except
	the event thread.  Extended comments.

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

	* gdb.threads/thread-execl.exp (do_test): Handle non-stop.
	(top level): Call do_test with non-stop as well.
2015-03-03 01:25:17 +00:00
Pedro Alves 28054d694f gdb_test_multiple: return -1 on internal error
gdb_test_multiple is supposed to return -1 on internal error:

  # Returns:
  #    1 if the test failed, according to a built-in failure pattern
  #    0 if only user-supplied patterns matched
  #   -1 if there was an internal error.

But alas, that's broken, it returns success...  It looks like the code
is assuming an earlier 'set result -1' is still in effect, but
'result' is set to 0 at the end, just before we call gdb_expect:

    set result 0
    set code [catch {gdb_expect $code} string]

gdb/testsuite/
2015-03-02  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_test_multiple) <internal error>: Set result to
	-1.
2015-03-02 20:05:25 +00:00
Doug Evans 9a284c9794 gdb.texinfo (Specify Location): Fix syntax of filename:function.
gdb/doc/ChangeLog:

	* gdb.texinfo (Specify Location): Fix syntax of filename:function.
2015-03-02 08:33:10 -08:00
Joel Brobecker 00e474c2e9 Revert "Remove true and false ARI checks now that we use stdbool.h."
As we cannot use type bool until conversion to C++ is official,
this patch re-instates the ARI checks for "true/false".

gdb/ChangeLog:

        * contrib/ari/gdb_ari.sh: Reinstate checks for "true" and "false".
2015-03-02 06:05:01 -08:00
Joel Brobecker cc7039d31a Remove use of stdbool.h in GDB sources.
Using type bool from stdbool unfortunately causes problems trying
to build GDB on AiX and Solaris:

    In file included from ../../src/gdb/utils.h:24:0,
                     from ../../src/gdb/defs.h:707,
                     from ../../src/gdb/utils.c:20:
    /[...]/curses.h:96:14: error: two or more data types in declaration
    specifiers
     typedef char bool;
                  ^
    make[2]: *** [utils.o] Error 1

In theory, the problem is in curses.h which, in both cases, do
something similar. On Solaris:

    #if !defined(__cplusplus) && !defined(_BOOL)
    typedef char bool;
    #endif /* !defined(__cplusplus) && !defined(_BOOL) */

On AiX:

    #if !defined(__cplusplus) || (defined(__IBMCPP__) &&(__IBMCPP__<400))
    #ifndef _BOOL
    #define _BOOL
    typedef int bool;
    #endif
    #endif

You can reproduce the same problem by trying to compile:

    % cat toto.c
    #include <stdbool.h>
    #include <curses.h>
    % gcc -c toto.c
    In file included from toto.c:1:0:
    /[...]/curses.h:159:13: error: two or more data types in declaration
    specifiers
     typedef int bool;
             ^

This specific issue wouldn't occur if we included curses.h before
including stdbool.h, and I looked at that just to be complete.
Here is a small schematic representation of the include logic:

  * utils.c:
      -> defs.h -> utils.h -> stdbool.h
      -> gdb_curses.h -> curses.h

Because defs.h should always be first on the list, it means that
stdbool.h will always necessarily be included ahead of curses.h.

But, thinking beyond this very specific issue, it shows that using
stdbool.h is going to cause problems on these systems until either
GCC fixes those includes in a way that makes them work; or we switch
to C++.

In the meantime, I think the path of least resistance is to revert
the use of stdbool.h, and use integers, the way we've done up until
now. The benefits of using type "bool" are modest, IMO, so not
a great loss, and a temporary one.

gdb/ChangeLog:

        * utils.h: Remove <stdbool.h> #include.
        (producer_is_gcc): Change return type to "int".
        * utils.c (producer_is_gcc): Change return type to int.
        Return 1 instead of true, and 0 instead of false.
        Adjust function documentation accordingly.
2015-03-02 06:02:11 -08:00
Andreas Arnez 4fa5d7b436 S390: Vector register test case
Add a test case for S/390 vector registers support.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-vregs.exp: New test.
	* gdb.arch/s390-vregs.S: New file.
2015-03-02 10:57:40 +01:00
Andreas Arnez bf2d68ab8c S390: Add vector register support to gdbserver
On S/390 targets with vector registers, enable gdbserver to advertise
and handle the feature "org.gnu.gdb.s390.vx".

gdb/gdbserver/ChangeLog:

	* Makefile.in (s390-vx-linux64.c, s390-tevx-linux64.c)
	(s390x-vx-linux64.c, s390x-tevx-linux64.c): New rules.
	(clean): Add "rm -f" for above C files.
	* configure.srv (srv_regobj): Add s390-vx-linux64.o,
	s390-tevx-linux64.o, s390x-vx-linux64.o, and s390x-tevx-linux64.o.
	(srv_xmlfiles): Add s390-vx-linux64.xml, s390-tevx-linux64.xml,
	s390x-vx-linux64.xml, s390x-tevx-linux64.xml, and s390-vx.xml.
	* linux-s390-low.c (HWCAP_S390_VX): New macro.
	(init_registers_s390_vx_linux64, init_registers_s390_tevx_linux64)
	(init_registers_s390x_vx_linux64)
	(init_registers_s390x_tevx_linux64)
	(tdesc_s390_vx_linux64, tdesc_s390_tevx_linux64)
	(tdesc_s390x_vx_linux64, tdesc_s390x_tevx_linux64): New extern
	declarations.
	(s390_fill_vxrs_low, s390_store_vxrs_low, s390_fill_vxrs_high)
	(s390_store_vxrs_high): New functions.
	(s390_regsets): Add entries for NT_S390_VXRS_LOW and
	NT_S390_VXRS_HIGH.
	(s390_arch_setup): Add logic for selecting one of the new target
	descriptions.  Activate the new vector regsets if applicable.
	(initialize_low_arch): Also invoke init_registers_s390_vx_linux64,
	init_registers_s390_tevx_linux64, init_registers_s390x_vx_linux64,
	and init_registers_s390x_tevx_linux64.
2015-03-02 10:57:40 +01:00
Andreas Arnez 550bdf96ca S390: Add vector register support to gdb
Recognize S/390 targets with the new vector feature and present their
vector registers appropriately: as 32 new 128-bit wide registers
v0-v31, where the first 16 embed the floating point registers f0-f15.
Each of the full registers v0-v15 is modelled as a pseudo register.

gdb/ChangeLog:

	* s390-linux-nat.c (have_regset_vxrs): New static variable.
	(s390_linux_fetch_inferior_registers): Handle vector registers, if
	present.
	(s390_linux_store_inferior_registers): Likewise.
	(s390_get_hwcap): Remove function.  Embed its logic...
	(s390_read_description): ...here.  Yield a target description with
	vector registers if applicable.
	* s390-linux-tdep.c: Include "features/s390-vx-linux64.c",
	"features/s390-tevx-linux64.c", "features/s390x-vx-linux64.c", and
	"features/s390x-tevx-linux64.c".
	(struct gdbarch_tdep) <v0_full_regnum>: New field.
	(s390_dwarf_regmap): Add vector registers.  Remove bogus entries
	for "GNU/Linux-specific registers".
	(s390_dwarf_reg_r0l): New enum value.
	(s390_dwarf_reg_to_regnum): Support vector registers.
	(s390_adjust_frame_regnum): Adjust pseudo DWARF register numbers
	of GPR lower halves.
	(regnum_is_vxr_full): New function.
	(s390_register_name): New function.
	(s390_pseudo_register_name): Handle v0-v15, which are composed of
	f0-f15 and v0l-v15l.
	(s390_pseudo_register_type): Likewise.
	(s390_pseudo_register_read): Likewise.
	(s390_pseudo_register_write): Likewise.
	(s390_value_from_register): Account for the fact that values are
	placed left-justified in vector registers.
	(s390_pseudo_register_reggroup_p): Add pseudo registers v0-v15 to
	the vector reggroup and omit them from the general reggroup.
	(s390_regmap_vxrs_low, s390_regmap_vxrs_high): New register maps.
	(s390_vxrs_low_regset, s390_vxrs_high_regset): New regsets.
	(s390_iterate_over_regset_sections): Add iterations for the two
	new vector regsets.
	(s390_core_read_description): Yield a target description with
	vector registers if applicable.
	(s390_gdbarch_init): Handle target descriptions with vector
	registers.  Add "register_name" gdbarch method.
	(_initialize_s390_tdep): Call new tdesc initialization functions.
	* s390-linux-tdep.h (HWCAP_S390_VX): New macro.
	(S390_V0_LOWER_REGNUM, S390_V1_LOWER_REGNUM, S390_V2_LOWER_REGNUM)
	(S390_V3_LOWER_REGNUM, S390_V4_LOWER_REGNUM, S390_V5_LOWER_REGNUM)
	(S390_V6_LOWER_REGNUM, S390_V7_LOWER_REGNUM, S390_V8_LOWER_REGNUM)
	(S390_V9_LOWER_REGNUM, S390_V10_LOWER_REGNUM)
	(S390_V11_LOWER_REGNUM, S390_V12_LOWER_REGNUM)
	(S390_V13_LOWER_REGNUM, S390_V14_LOWER_REGNUM)
	(S390_V15_LOWER_REGNUM, S390_V16_REGNUM, S390_V17_REGNUM)
	(S390_V18_REGNUM, S390_V19_REGNUM, S390_V20_REGNUM)
	(S390_V21_REGNUM, S390_V22_REGNUM, S390_V23_REGNUM)
	(S390_V24_REGNUM, S390_V25_REGNUM, S390_V26_REGNUM)
	(S390_V27_REGNUM, S390_V28_REGNUM, S390_V29_REGNUM)
	(S390_V30_REGNUM, S390_V31_REGNUM): New macros.
	(S390_NUM_REGS): Adjust value.
	(s390_vxrs_low_regset, s390_vxrs_high_regset): Declare.
	(tdesc_s390_vx_linux64, tdesc_s390_tevx_linux64)
	(tdesc_s390x_vx_linux64, tdesc_s390x_tevx_linux64): Likewise.
	* NEWS: Announce S/390 vector register support.
2015-03-02 10:57:39 +01:00
Andreas Arnez 446899e472 S390: Add target descriptions for vector register sets
The IBM z13 has new vector registers v0-v31 which are presented by the
Linux kernel as two additional register sets.  This patch adds XML
descriptions and the respective autogenerated .c and .dat files for
S390 targets with this feature.  Note that supported combinations
include targets with and without a transactional execution facility.

gdb/ChangeLog:

	* features/s390-tevx-linux64.xml: New file.
	* features/s390-vx-linux64.xml: New file.
	* features/s390-vx.xml: New file.
	* features/s390x-tevx-linux64.xml: New file.
	* features/s390x-vx-linux64.xml: New file.
	* features/Makefile (WHICH): Add s390-vx-linux64,
	s390x-vx-linux64, s390-tevx-linux64, and s390x-tevx-linux64.
	(s390-vx-linux64-expedite, s390-tevx-linux64-expedite)
	(s390x-vx-linux64-expedite, s390x-tevx-linux64-expedite): New
	macros.
	* features/s390-tevx-linux64.c: New generated file.
	* features/s390-vx-linux64.c: Likewise.
	* features/s390x-tevx-linux64.c: Likewise.
	* features/s390x-vx-linux64.c: Likewise.
	* regformats/s390-tevx-linux64.dat: Likewise.
	* regformats/s390-vx-linux64.dat: Likewise.
	* regformats/s390x-tevx-linux64.dat: Likewise.
	* regformats/s390x-vx-linux64.dat: Likewise.

gdb/doc/ChangeLog:

	* gdb.texinfo (S/390 and System z Features): Describe new feature
	"org.gnu.gdb.s390.vx".
2015-03-02 10:57:39 +01:00
Pedro Alves c966a859b9 Fix 32-bit x86 in-process agent build
Git commit 3c14e5a39b added a declaration for
gdb_agent_get_raw_reg to tracepoint.h, and this now caught that the
32-bit x86 implementation has the wrong prototype:

 ../../../src/gdb/gdbserver/linux-i386-ipa.c:103:1: error: conflicting types for ‘gdb_agent_get_raw_reg’
  gdb_agent_get_raw_reg (unsigned char *raw_regs, int regnum)
  ^
 In file included from ../../../src/gdb/gdbserver/linux-i386-ipa.c:24:0:
 ../../../src/gdb/gdbserver/tracepoint.h:168:31: note: previous declaration of ‘gdb_agent_get_raw_reg’ was here
  IP_AGENT_EXPORT_FUNC ULONGEST gdb_agent_get_raw_reg
				^
 make[2]: *** [linux-i386-ipa.o] Error 1

gdb/gdbserver/
2015-03-01  Pedro Alves  <palves@redhat.com>

	* linux-i386-ipa.c (gdb_agent_get_raw_reg): Constify 'raw_regs'
	parameter.
2015-03-01 14:55:29 +00:00
Doug Evans b7236fbee4 symtab.h (struct symtab) <next>: Fix comment.
gdb/ChangeLog:

	* symtab.h (struct symtab) <next>: Fix comment.
2015-02-28 12:05:27 -08:00
Simon Marchi 02e62830e2 Fix Python 3 build: rename GdbMethods
Rename forgotten GdbMethods to python_GdbMethods.

gdb/ChangeLog:

	* python/python.c (python_GdbModuleDef): Rename GdbMethods to
	python_GdbMethods.
2015-02-27 18:02:40 -05:00
Pedro Alves bf36a1e7df More redefinition errors in C++ mode
In C++, we can't forward declare objects like in C.  The compiler
complains about symbol redefinition.  Most cases of this were fixed in
e36122e9, but dtrace probes introduced a new one meanwhile.  This
patch fixes it the same way e36122e9 fixed the others.

gdb/
2015-02-27  Pedro Alves  <palves@redhat.com>

	* dtrace-probe.c (dtrace_probe_ops): Make extern.
2015-02-27 17:59:25 +00:00
Pedro Alves ad6aff7dea Move exception_none to common code, and use it
gdb/ChangeLog:
2015-02-27  Pedro Alves  <palves@redhat.com>

	* common/common-exceptions.h (exception_none): Declare.
	* common/common-exceptions.c (exception_none): Moved from
	exceptions.c.
	(exceptions_state_mc_init): Use exception_none.
	* exceptions.c (exception_none): Move to
	common/common-exceptions.c.
	* exceptions.h (exception_none): Move to
	common/common-exceptions.h.
2015-02-27 17:43:10 +00:00
Pedro Alves 97c185659a catch_command_errors: Remove 'mask' parameter
All callers of catch_command_errors pass RETURN_MASK_ALL as mask
argument.  This patch eliminates the mask parameter as unnecessary.

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

	* main.c (catch_command_errors, catch_command_errors_const):
	Remove 'mask' argument.  Adjust.
	(captured_main): Adjust callers.

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

	* gdb.gdb/python-interrupts.exp (test_python_interrupts): Adjust
	call to catch_command_errors.
	* gdb.gdb/python-selftest.exp (selftest_python): Adjust call to
	catch_command_errors.
2015-02-27 17:42:21 +00:00
Pedro Alves a37bfa3001 Adjust self tests to cope with GDB built as a C++ program
gdb/testsuite/
2015-02-27  Pedro Alves  <palves@redhat.com>

	* gdb.gdb/complaints.exp (test_initial_complaints): Also accept
	"true" for boolean result.
	* gdb.gdb/selftest.exp (test_with_self): Also accept full
	prototype of main.
2015-02-27 17:41:44 +00:00
Pedro Alves e992c591af python/python-internal.h: enum ‘ext_lang_rc’ not defined
Fixes this in C++ mode:

  src/gdb/python/python-internal.h: At global scope:
  src/gdb/python/python-internal.h:313:13: error: use of enum ‘ext_lang_rc’ without previous declaration
   extern enum ext_lang_rc gdbpy_apply_val_pretty_printer
	       ^
  src/gdb/python/python-internal.h:320:41: error: invalid type in declaration before ‘;’ token
      const struct language_defn *language);
					   ^

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

	* python/python-internal.h: Include "extension-priv.h".
2015-02-27 17:41:13 +00:00
Pedro Alves 64166036b3 breakpoint.h: move enum ‘print_stop_action’
Building GDB in C++, we get:

  src/gdb/breakpoint.h:529:8: error: use of enum ‘print_stop_action’ without previous declaration

We can't forward declare enums in C++.

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

	* breakpoint.h (enum print_stop_action): Move further up in the
	file.
2015-02-27 17:40:35 +00:00
Pedro Alves 8a526fa69a gdbarch.h: include regcache.h
Building GDB in C++ mode, I got:

  src/gdb/gdbarch.h:240:149: error: invalid type in declaration before ‘;’ token
  src/gdb/gdbarch.h:240:14: error: use of enum ‘register_status’ without previous declaration
  src/gdb/gdbarch.h:241:13: error: use of enum ‘register_status’ without previous declaration
  src/gdb/gdbarch.h:241:140: error: invalid type in declaration before ‘;’ token

That's because 'enum register_status' has not been declared (and we can't
forward declare enums in C++).

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

	* gdbarch.sh: Include regcache.h.
	* gdbarch.h: Regenerate.
2015-02-27 17:39:54 +00:00
Pedro Alves 0fa9c223dd Remove duplicate const
Building --enable-targets=all in C++ mode fails with:

  gdb/sparc-sol2-tdep.c:179:7: error: duplicate ‘const’
  gdb/arm-tdep.c:13878:33: error: duplicate ‘const’
  gdb/arm-tdep.c:13891:33: error: duplicate ‘const’

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

	* arm-tdep.c (decode_insn) <arm_handle_insn, thumb_handle_insn>:
	Remove duplicate const.
	* sparc-sol2-tdep.c (sparc_sol2_static_transform_name): Remove
	duplicate const.
2015-02-27 17:39:19 +00:00
Pedro Alves 7cf99fb1c7 Exported const objects
const works different in C vs C++.  In C++, a global "const" variable
has internal linkage by default, resulting in link errors like:

  ...
  extension.o: In function `get_ext_lang_defn(extension_language)':
  gdb/extension.c:126: undefined reference to `extension_language_guile'
  gdb/extension.c:124: undefined reference to `extension_language_guile'
  ...

The fix is to define exported const objects with "extern const".  But
that in C would not be a definition.  So we need to #ifdef C vs C++ in
this case.

EXPORTED_CONST comes from include/ansidecl.h, but in the
feature_to_c.sh case I think it's better to leave the script with no
dependencies.

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

	* cp-valprint.c (vtbl_ptr_name): Use EXPORTED_CONST.
	* guile/guile.c (extension_language_guile): Use EXPORTED_CONST.
	* features/feature_to_c.sh: Tag the generated xml_builtin array
	with extern const in C++ mode.
2015-02-27 17:31:45 +00:00
Tom Tromey 1424c16eab Rename struct lzma_stream to avoid clash with system header
/home/pedro/gdb/mygit/src/gdb/minidebug.c: At global scope:
/home/pedro/gdb/mygit/src/gdb/minidebug.c:55:8: error: using typedef-name ‘lzma_stream’ after ‘struct’
 struct lzma_stream
        ^
In file included from /usr/include/lzma.h:281:0,
                 from /home/pedro/gdb/mygit/src/gdb/minidebug.c:28:
/usr/include/lzma/base.h:498:3: note: ‘lzma_stream’ has a previous declaration here
 } lzma_stream;
   ^

gdb/ChangeLog:
2015-02-27  Tom Tromey  <tromey@redhat.com>

	* minidebug.c (struct lzma_stream): Rename to ...
	(struct gdb_lzma_stream): ... this.
	(lzma_open, lzma_pread, lzma_close, lzma_stat): Adjust.
2015-02-27 17:31:18 +00:00
Pedro Alves 10367c7c94 mi/mi-cmd-stack.c|frame filters: print_values <-> ext_lang_frame_args
The enums are value compatible by design, but building in C++ mode trips
on them, like:

  ...
  gdb/mi/mi-cmd-stack.c:363:34: error: cannot convert ‘print_values’ to ‘ext_lang_frame_args’ for argument ‘3’ to ‘ext_lang_bt_status apply_ext_lang_frame_filter(frame_info*, int, ext_lang_frame_args, ui_out*, int, int)’
  ...

Fix this by adding a helper function.

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

	* mi/mi-cmd-stack.c (mi_apply_ext_lang_frame_filter): New
	function.
	(mi_cmd_stack_list_locals, mi_cmd_stack_list_args)
	(mi_cmd_stack_list_variables): Use it.
2015-02-27 17:30:57 +00:00
Pedro Alves 4180215b9d x86 Linux/ptrace: fix offsetof usage in C++ mode
In C++ mode, we get:

  gdb/gdbserver/linux-x86-low.c: In function ‘void x86_linux_dr_set(ptid_t, int, long unsigned int)’:
  gdb/gdbserver/linux-x86-low.c:558:38: error: ‘regnum’ cannot appear in a constant-expression
      offsetof (struct user, u_debugreg[regnum]), value);
                                      ^
gdb/gdbserver/ChangeLog:
2015-02-27  Pedro Alves  <palves@redhat.com>

	* linux-x86-low.c (u_debugreg_offset): New function.
	(x86_linux_dr_get, x86_linux_dr_set): Use it.

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

	* x86-linux-nat.c (u_debugreg_offset): New function.
	(x86_linux_dr_get, x86_linux_dr_set): Use it.
2015-02-27 17:30:09 +00:00
Pedro Alves 2f56f7c302 Don't forward declare enum target_hw_bp_type
Can't do that in C++.

2015-02-27  Pedro Alves  <palves@redhat.com>

	* nat/x86-dregs.h (enum target_hw_bp_type): Remove forward
	declaration.
	Include break-common.h.
2015-02-27 17:29:42 +00:00
Tom Tromey 570dc176ff Do not increment of decrement enums
In C++, we can't do arithmetic on enums.  This patch fixes build errors like:

 src/gdb/i386-tdep.c: In function ‘int i386_stap_parse_special_token(gdbarch*, stap_parse_info*)’:
 src/gdb/i386-tdep.c:4309:7: error: no match for ‘operator++’ (operand type is ‘i386_stap_parse_special_token(gdbarch*, stap_parse_info*)::<anonymous enum>’)
	++current_state;
	^
 ...
 src/gdb/rs6000-tdep.c:4265:18: error: no match for ‘operator++’ (operand type is ‘powerpc_vector_abi’)
 src/gdb/arm-tdep.c:9428:71: error: no match for ‘operator++’ (operand type is ‘arm_float_model’)
 src/gdb/arm-tdep.c:9465:64: error: no match for ‘operator++’ (operand type is ‘arm_abi_kind’)
 ...

gdb/ChangeLog:
2015-02-27  Tom Tromey  <tromey@redhat.com>
	    Pedro Alves <palves@redhat.com>

	* arm-tdep.c (set_fp_model_sfunc, arm_set_abi): Use 'int' for
	local used to iterate over enums.
	* completer.c (signal_completer): Likewise.
	* i386-tdep.c (i386_stap_parse_special_token): Likewise.
	* rs6000-tdep.c (powerpc_set_vector_abi): Likewise.
	* tui/tui-data.c (tui_next_win, tui_prev_win): Likewise.
	* tui/tui-layout.c (next_layout, prev_layout): Likewise.
	* tui/tui-win.c (tui_refresh_all_win, tui_rehighlight_all)
	(tui_resize_all, tui_set_focus_command, tui_all_windows_info): Likewise.
	* tui-wingeneral.c (tui_refresh_all):  Likewise.
2015-02-27 17:29:11 +00:00