Commit Graph

35597 Commits

Author SHA1 Message Date
Andreas Arnez d1fbcd564a Eliminate literal line numbers in mi-console.exp
Remove the literal line number from a regexp in mi-console.exp.  Add
an appropriate eye-catcher to mi-console.c and refer to that instead.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-console.c: Add eye-catcher.
	* gdb.mi/mi-console.exp (semihosted_string): Refer to eye-catcher
	instead of literal line number.
2014-11-13 10:20:39 +01:00
Andreas Arnez b0e59b8f1c Eliminate literal line numbers in shlib-call.exp
Remove the literal line number from a regexp in shlib-call.exp.  Add
an appropriate eye-catcher to shr2.c and refer to that instead.

gdb/testsuite/ChangeLog:

	* gdb.base/shr2.c: Add eye-catcher.
	* gdb.base/shlib-call.exp: Refer to eye-catcher instead of literal
	line number.
2014-11-13 10:20:39 +01:00
Andreas Arnez 78f98cca31 Eliminate literal line numbers in jump.exp
Remove literal line numbers from the regexps in jump.exp.  Add
appropriate eye-catchers to jump.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/jump.c: Add eye-catchers.
	* gdb.base/jump.exp: Refer to eye-catchers instead of literal line
	numbers.
2014-11-13 10:20:38 +01:00
Andreas Arnez 58fa2af0b3 Eliminate literal line numbers in foll-exec.exp
Remove literal line numbers from the regexps in foll-exec.exp.  Add
appropriate eye-catchers to foll-exec.c and execd-proc.c and refer to
those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/execd-prog.c: Add eye-catchers.
	* gdb.base/foll-exec.c: Likewise.
	* gdb.base/foll-exec.exp: Refer to eye-catchers instead of literal
	line numbers.
2014-11-13 10:20:38 +01:00
Andreas Arnez 04e5059ba6 Eliminate literal line numbers in ending-run.exp
Remove literal line numbers from the regexps in ending-run.exp.  Add
appropriate eye-catchers to ending-run.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/ending-run.c: Add eye-catchers.
	* gdb.base/ending-run.exp: Refer to eye-catchers instead of
	literal line numbers.
2014-11-13 10:20:37 +01:00
Andreas Arnez dbfdb174e3 Eliminate literal line numbers in call-rt-st.exp
Remove literal line numbers from the regexps in call-rt-st.exp.  Add
appropriate eye-catchers to call-rt-st.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/call-rt-st.c: Add eye-catchers.
	* gdb.base/call-rt-st.exp: Refer to eye-catchers instead of
	literal line numbers.
2014-11-13 10:14:30 +01:00
Andreas Arnez 888a2adec7 Eliminate literal line numbers in call-ar-st.exp
Remove literal line numbers from the regexps in call-ar-st.exp.  Add
appropriate eye-catchers to call-ar-st.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/call-ar-st.c: Add eye-catchers.
	* gdb.base/call-ar-st.exp: Refer to eye-catchers instead of
	literal line numbers.
2014-11-13 10:14:30 +01:00
Andreas Arnez 6acc2ddee2 Eliminate literal line numbers in dbx.exp
Remove literal line numbers from the commands and regexps in dbx.exp.
Add appropriate eye-catchers to average.c and sum.c and refer to those
instead.

gdb/testsuite/ChangeLog:

	* gdb.base/average.c: Add eye-catchers.
	* gdb.base/sum.c: Likewise.
	* gdb.base/dbx.exp: Use eye-catchers to determine line numbers for
	regexps dynamically.
2014-11-13 10:14:29 +01:00
Andreas Arnez 9ecfcd1d02 Eliminate literal line numbers in so-impl-ld.exp
Remove literal line numbers from the regexps in so-impl-ld.exp.  Add
appropriate eye-catchers to solib1.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/solib1.c: Add eye-catchers.
	* gdb.base/so-impl-ld.exp: Match against eye-catchers instead of
	literal line numbers.
2014-11-13 10:14:29 +01:00
Pedro Alves 40e91bc71f GDBserver: clean up 'cont_thread' handling
As no place in the backends check cont_thread anymore, we can stop
setting and clearing it in places that resume the target and wait for
events.  Instead simply clear it whenever a new GDB connects.

gdb/gdbserver/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* server.c (cont_thread): Update comment.
	(start_inferior, attach_inferior): No longer clear cont_thread.
	(handle_v_cont): No longer set cont_thread.
	(captured_main): Clear cont_thread each time a GDB connects.
2014-11-12 11:30:49 +00:00
Pedro Alves c2c118cfe1 GDBserver: don't resume all threads if the Hc thread disapears
There's code in linux_wait_1 that resumes all threads if the Hc thread
disappears.  It's the wrong thing to do, as GDB has told GDBserver to
resume only one thread, because e.g., the user has scheduler-locking
enabled, or because GDB was stepping the program over a breakpoint.
Resuming all threads behind GDB's back can't be good in either case.

The right thing to do is to detect that that the (only) resumed thread
is gone, and let GDB know about it.  The Linux backend is already
doing that nowadays, since:

 commit fa96cb382c
 Author:     Pedro Alves <palves@redhat.com>
 AuthorDate: Thu Feb 27 14:30:08 2014 +0000

     Teach GDBserver's Linux backend about no unwaited-for children (TARGET_WAITKIND_NO_RESUMED).

The backend detects that all resumed threads have disappeared, and
returns TARGET_WAITKIND_NO_RESUMED to the core of GDBserver, which
then reports an error to GDB.

There's no need to frob the passed in ptid to wait for the continue
thread either -- linux_wait_for_event only returns events for resumed
threads.

The badness (of resuming threads) can actually be observed in the
testsuite, if we force-disable vCont support in GDBserver -- before
the patch, gdb.threads/no-unwaited-for-left.exp hangs if we disable
vCont:

 (gdb) continue
 Continuing.
 FAIL: gdb.threads/no-unwaited-for-left.exp: continue to breakpoint: break-here (timeout)
 ... more cascading timeouts ....

After the patch, gdb.threads/no-unwaited-for-left.exp behaves the same
with or without vCont support:

 (gdb) continue
 Continuing.
 [New Thread 32226]
 [Switching to Thread 32226]

 Breakpoint 2, thread_a (arg=0x0) at /home/pedro/gdb/mygit/build/../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28
 28	  return 0; /* break-here */
 (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: continue to breakpoint: break-here
...
 continue
 Continuing.
 warning: Remote failure reply: E.No unwaited-for children left.

 [Thread 32222] #1 stopped.
 (gdb) FAIL: gdb.threads/no-unwaited-for-left.exp: continue stops when the main thread exits

Overall, this is also good for getting rid of a RSP detail from the backend.

gdb/gdbserver/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_wait_1): Don't force a wait for the Hc
	thread, and don't resume all threads if the Hc thread has exited.
2014-11-12 11:30:49 +00:00
Pedro Alves 78708b7c8c GDBserver: ctrl-c after leader has exited
The target->request_interrupt callback implements the handling for
ctrl-c.  User types ctrl-c in GDB, GDB sends a \003 to the remote
target, and the remote targets stops the program with a SIGINT, just
like if the user typed ctrl-c in GDBserver's terminal.

The trouble is that using kill_lwp(signal_pid, SIGINT) sends the
SIGINT directly to the program's main thread.  If that thread has
exited already, then that kill won't do anything.

Instead, send the SIGINT to the process group, just like GDB
does (see inf-ptrace.c:inf_ptrace_stop).

gdb.threads/leader-exit.exp is extended to cover the scenario.  It
fails against GDBserver before the patch.

Tested on x86_64 Fedora 20, native and GDBserver.

gdb/gdbserver/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_request_interrupt): Always send a SIGINT to
	the process group instead of to a specific LWP.

gdb/testsuite/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* gdb.threads/leader-exit.exp: Test sending ctrl-c works after the
	leader has exited.
2014-11-12 11:30:49 +00:00
Pedro Alves 6218dc4bdb Garbage collect the infwait_state global
No longer used since the non-continuable watchpoints handling rework.

gdb/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* infrun.c (enum infwait_states, infwait_state): Delete.
2014-11-12 11:02:11 +00:00
Pedro Alves af48d08f97 fix skipping permanent breakpoints
The gdb.arch/i386-bp_permanent.exp test is currently failing an
assertion recently added:

 (gdb) stepi
 ../../src/gdb/infrun.c:2237: internal-error: resume: Assertion `sig != GDB_SIGNAL_0' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n)
 FAIL: gdb.arch/i386-bp_permanent.exp: Single stepping past permanent breakpoint. (GDB internal error)

The assertion expects that the only reason we currently need to step a
breakpoint instruction is when we have a signal to deliver.  But when
stepping a permanent breakpoint (with or without a signal) we also
reach this code.

The assertion is correct and the permanent breakpoints skipping code
is wrong.

Consider the case of the user doing "step/stepi" when stopped at a
permanent breakpoint.  GDB's `resume' calls the
gdbarch_skip_permanent_breakpoint hook and then happily continues
stepping:

  /* Normally, by the time we reach `resume', the breakpoints are either
     removed or inserted, as appropriate.  The exception is if we're sitting
     at a permanent breakpoint; we need to step over it, but permanent
     breakpoints can't be removed.  So we have to test for it here.  */
  if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
    {
      gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
    }

But since gdbarch_skip_permanent_breakpoint already advanced the PC
manually, this ends up executing the instruction that is _after_ the
breakpoint instruction.  The user-visible result is that a single-step
steps two instructions.

The gdb.arch/i386-bp_permanent.exp test is actually ensuring that
that's indeed how things work.  It runs to an int3 instruction, does
"stepi", and checks that "leave" was executed with that "stepi".  Like
this:

 (gdb) b *0x0804848c
 Breakpoint 2 at 0x804848c
 (gdb) c
 Continuing.

 Breakpoint 2, 0x0804848c in standard ()
 (gdb) disassemble
 Dump of assembler code for function standard:
    0x08048488 <+0>:     push   %ebp
    0x08048489 <+1>:     mov    %esp,%ebp
    0x0804848b <+3>:     push   %edi
 => 0x0804848c <+4>:     int3
    0x0804848d <+5>:     leave
    0x0804848e <+6>:     ret
    0x0804848f <+7>:     nop
 (gdb) si
 0x0804848e in standard ()
 (gdb) disassemble
 Dump of assembler code for function standard:
    0x08048488 <+0>:     push   %ebp
    0x08048489 <+1>:     mov    %esp,%ebp
    0x0804848b <+3>:     push   %edi
    0x0804848c <+4>:     int3
    0x0804848d <+5>:     leave
 => 0x0804848e <+6>:     ret
    0x0804848f <+7>:     nop
 End of assembler dump.
 (gdb)

One would instead expect that a stepi at 0x0804848c stops at
0x0804848d, _before_ the "leave" is executed.  This commit changes GDB
this way.  Care is taken to make stepping into a signal handler when
the step starts at a permanent breakpoint instruction work correctly.

The patch adjusts gdb.arch/i386-bp_permanent.exp in this direction,
and also makes it work on x86_64 (currently it only works on i*86).

The patch also adds a new gdb.base/bp-permanent.exp test that
exercises many different code paths related to stepping permanent
breakpoints, including the stepping with signals cases.  The test uses
"hack/trick" to make it work on all (or most) platforms -- it doesn't
really hard code a breakpoint instruction.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* infrun.c (resume): Clear the thread's 'stepped_breakpoint' flag.
	Rewrite stepping over a permanent breakpoint.
	(thread_still_needs_step_over, proceed): Don't set
	stepping_over_breakpoint for permanent breakpoints.
	(handle_signal_stop): Don't clear stepped_breakpoint.  Also pull
	single-step breakpoints out of the target on hardware step
	targets.
	(process_event_stop_test): If stepping a permanent breakpoint
	doesn't hit the step-resume breakpoint, delete the step-resume
	breakpoint.
	(switch_back_to_stepped_thread): Also check if the stepped thread
	has advanced already on hardware step targets.
	(currently_stepping): Return true if the thread stepped a
	breakpoint.

gdb/testsuite/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* gdb.arch/i386-bp_permanent.c: New file.
	* gdb.arch/i386-bp_permanent.exp: Don't skip on x86_64.
	(srcfile): Set to i386-bp_permanent.c.
	(top level): Adjust to work in both 32-bit and 64-bit modes.  Test
	that stepi does not execute the 'leave' instruction, instead of
	testing it does execute.
	* gdb.base/bp-permanent.c: New file.
	* gdb.base/bp-permanent.exp: New file.
2014-11-12 10:39:00 +00:00
Pedro Alves 1a853c5224 make "permanent breakpoints" per location and disableable
"permanent"-ness is currently a property of the breakpoint.  But, it
should actually be an implementation detail of a _location_.  Consider
this bit in infrun.c:

  /* Normally, by the time we reach `resume', the breakpoints are either
     removed or inserted, as appropriate.  The exception is if we're sitting
     at a permanent breakpoint; we need to step over it, but permanent
     breakpoints can't be removed.  So we have to test for it here.  */
  if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
    {
      if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
	gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
      else
	error (_("\
The program is stopped at a permanent breakpoint, but GDB does not know\n\
how to step past a permanent breakpoint on this architecture.  Try using\n\
a command like `return' or `jump' to continue execution."));
    }

This will wrongly skip a non-breakpoint instruction if we have a
multiple location breakpoint where the whole breakpoint was set to
"permanent" because one of the locations happened to be permanent,
even if the one GDB is resuming from is not.

Related, because the permanent breakpoints are only marked as such in
init_breakpoint_sal, we currently miss marking momentary breakpoints
as permanent.  A test added by a following patch trips on that.
Making permanent-ness be per-location, and marking locations as such
in add_location_to_breakpoint, the natural place to do this, fixes
this issue...

... and then exposes a latent issue with mark_breakpoints_out.  It's
clearing the inserted flag of permanent breakpoints.  This results in
assertions failing like this:

 Breakpoint 1, main () at testsuite/gdb.base/callexit.c:32
 32        return 0;
 (gdb) call callexit()
 [Inferior 1 (process 15849) exited normally]
 gdb/breakpoint.c:12854: internal-error: allegedly permanent breakpoint is not actually inserted
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.

The call dummy breakpoint, which is a momentary breakpoint, is set on
top of a manually inserted breakpoint instruction, and so is now
rightfully marked as a permanent breakpoint.  See "Write a legitimate
instruction at the point where the infcall breakpoint is going to be
inserted." comment in infcall.c.

Re. make_breakpoint_permanent.  That's only called by solib-pa64.c.
Permanent breakpoints were actually originally invented for HP-UX [1].
I believe that that call (the only one in the tree) is unnecessary
nowadays, given that nowadays the core breakpoints code analyzes the
instruction under the breakpoint to automatically detect whether it's
setting a breakpoint on top of a breakpoint instruction in the
program.  I know close to nothing about HP-PA/HP-UX, though.

[1] https://sourceware.org/ml/gdb-patches/1999-q3/msg00245.html, and
    https://sourceware.org/ml/gdb-patches/1999-q3/msg00242.html

In addition to the per-location issue, "permanent breakpoints" are
currently always displayed as enabled=='n':

 (gdb) b main
 Breakpoint 3 at 0x40053c: file ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S, line 29.
 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 3       breakpoint     keep n   0x000000000040053c ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29

But OTOH they're always enabled; there's no way to disable them...

In turn, this means that if one adds commands to such a breakpoint,
they're _always_ run:

 (gdb) start
 Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.arch/i386-permbkpt
 ...
 Temporary breakpoint 1, main () at ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29
 29              int3
 (gdb) b main
 Breakpoint 2 at 0x40053c: file ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S, line 29.
 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 2       breakpoint     keep n   0x000000000040053c ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29
 (gdb) commands
 Type commands for breakpoint(s) 2, one per line.
 End with a line saying just "end".
 >echo "hello!"
 >end
 (gdb) disable 2
 (gdb) start
 The program being debugged has been started already.
 Start it from the beginning? (y or n) y
 Temporary breakpoint 3 at 0x40053c: file ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S, line 29.
 Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.arch/i386-permbkpt

 Breakpoint 2, main () at ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29
 29              int3
 "hello!"(gdb)

IMO, one should be able to disable such a breakpoint, and GDB should
then behave just like if the user hadn't created the breakpoint in the
first place (that is, report a SIGTRAP).

By making permanent-ness a property of the location, and eliminating
the bp_permanent enum enable_state state ends up fixing that as well.

No tests are added for these changes yet; they'll be added in a follow
up patch, as skipping permanent breakpoints is currently broken and
trips on an assertion in infrun.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/ChangeLog:
2014-11-12  Pedro Alves  <palves@redhat.com>

	Mark locations as permanent, not the whole breakpoint.
	* breakpoint.c (remove_breakpoint_1, remove_breakpoint): Adjust.
	(mark_breakpoints_out): Don't mark permanent breakpoints as
	uninserted.
	(breakpoint_init_inferior): Use mark_breakpoints_out.
	(breakpoint_here_p): Adjust.
	(bpstat_stop_status, describe_other_breakpoints): Remove handling
	of permanent breakpoints.
	(make_breakpoint_permanent): Mark each location as permanent,
	instead of marking the breakpoint.
	(add_location_to_breakpoint): If the location is permanent, mark
	it as such, and as inserted.
	(init_breakpoint_sal): Don't make the breakpoint permanent here.
	(bp_location_compare, update_global_location_list): Adjust.
	(update_breakpoint_locations): Don't make the breakpoint permanent
	here.
	(disable_breakpoint, enable_breakpoint_disp): Don't skip permanent
	breakpoints.
	* breakpoint.h (enum enable_state) <bp_permanent>: Delete field.
	(struct bp_location) <permanent>: New field.
	* guile/scm-breakpoint.c (bpscm_enable_state_to_string): Remove
	reference to bp_permanent.
2014-11-12 10:37:57 +00:00
Pedro Alves ae9bb220ca add a default method for gdbarch_skip_permanent_breakpoint
breakpoint.c uses gdbarch_breakpoint_from_pc to determine whether a
breakpoint location points at a permanent breakpoint:

 static int
 bp_loc_is_permanent (struct bp_location *loc)
 {
 ...
   addr = loc->address;
   bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
 ...
  if (target_read_memory (loc->address, target_mem, len) == 0
      && memcmp (target_mem, bpoint, len) == 0)
    retval = 1;
 ...

So I think we should default the gdbarch_skip_permanent_breakpoint
hook to advancing the PC by the length of the breakpoint instruction,
as determined by gdbarch_breakpoint_from_pc.  I believe that simple
implementation does the right thing for most architectures.  If
there's an oddball architecture where that doesn't work, then it
should override the hook, just like it should be overriding the hook
if there was no default anyway.

The only two implementation of skip_permanent_breakpoint are
i386_skip_permanent_breakpoint, for x86, and
hppa_skip_permanent_breakpoint, for PA-RISC/HP-UX

The x86 implementation is trivial, and can clearly be replaced by the
new default.

I don't know about the HP-UX one though, I know almost nothing about
PA.  It may well be advancing the PC ends up being equivalent.
Otherwise, it must be that "jump $pc_after_bp" doesn't work either...

Tested on x86_64 Fedora 20 native and gdbserver.

gdb/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* arch-utils.c (default_skip_permanent_breakpoint): New function.
	* arch-utils.h (default_skip_permanent_breakpoint): New
	declaration.
	* gdbarch.sh (skip_permanent_breakpoint): Now an 'f' function.
	Install default_skip_permanent_breakpoint as default method.
	* i386-tdep.c (i386_skip_permanent_breakpoint): Delete function.
	(i386_gdbarch_init): Don't install it.
	* infrun.c (resume): Assume there's always a
	gdbarch_skip_permanent_breakpoint implementation.
	* gdbarch.h, gdbarch.c: Regenerate.
2014-11-12 10:32:53 +00:00
Daniel Colascione 015de6884f Warn users about mismatched PID namespaces
Linux supports multiple "PID namespaces".  Processes in different PID
namespaces have different views of the system process list.  Sometimes,
a single process can appear in more than one PID namespace, but with a
different PID in each.  When GDB and its target are in different PID
namespaces, various features can break due to the mismatch between
what the target believes its PID to be and what GDB believes its PID
to be.  The most visible broken functionality is thread enumeration
silently failing.

This patch explicitly warns users against trying to debug across PID
namespaces.

The patch introduced no new failures in my test suite run on an x86_64
installation of Ubuntu 14.10.  It doesn't include a test: writing an
automated test that exercises this code would be very involved because
CLONE_NEWNS requires CAP_SYS_ADMIN; the easier way to reproduce the
problem is to start a new lxc container.

gdb/
2014-11-11  Daniel Colascione  <dancol@dancol.org>

	Warn about cross-PID-namespace debugging.
	* nat/linux-procfs.h (linux_proc_pid_get_ns): New prototype.
	* nat/linux-procfs.c (linux_proc_pid_get_ns): New function.
	* linux-thread-db.c (check_pid_namespace_match): New function.
	(thread_db_inferior_created): Call it.
2014-11-11 14:18:23 +00:00
Doug Evans 26a8485972 symmisc.c: Remove trailing whitespace.
gdb/ChangeLog:

	* symmisc.c (print_objfile_statistics): Remove trailing whitespace.
	(maintenance_info_symtabs, maintenance_check_symtabs): Ditto.
2014-11-10 17:19:57 -08:00
Doug Evans 712a2e6d22 source.c (select_source_symtab): Rewrite to use ALL_SYMTABS.
gdb/ChangeLog:

	* source.c (select_source_symtab): Rewrite to use ALL_SYMTABS.
2014-11-10 16:49:44 -08:00
Doug Evans af3768e945 PR 17564: Fix objfile search order for static symbols.
When searching static symbols, gdb would search over all
expanded symtabs of all objfiles, and if that fails only then
would it search all partial/gdb_index tables of all objfiles.
This means that the user could get a random instance of the
symbol depending on what symtabs have been previously expanded.
Now the search is consistent, searching each objfile completely
before proceeding to the next one.

gdb/ChangeLog:

	PR symtab/17564
	* symtab.c (lookup_symbol_in_all_objfiles): Delete.
	(lookup_static_symbol): Move definition to new location and rewrite.
	(lookup_symbol_in_objfile): New function.
	(lookup_symbol_global_iterator_cb): Call it.

gdb/testsuite/ChangeLog:

	PR symtab/17564
	* gdb.base/symtab-search-order.exp: New file.
	* gdb.base/symtab-search-order.c: New file.
	* gdb.base/symtab-search-order-1.c: New file.
	* gdb.base/symtab-search-order-shlib-1.c: New file.
2014-11-10 15:48:49 -08:00
Ulrich Weigand b1f28d992c Work around GCC bug 63748
A recent change to eval.c triggered a GCC bug that causes a false positive
"may be used uninitialized" warning in evaluate_subexp_standard.  This seems
to be triggered by a specific CFG constructed via setjmp and gotos.

While the GCC bug is in the process of being fixed, there are released
compiler versions (in particular GCC 4.9) in the field that show this
problem.  In order to allow compiling GDB with one of those compilers,
this commit slightly reworks the CFG (in an equivalent way) of the
affected function, so that the GCC bug is no longer triggered.

gdb/ChangeLog:

	* eval.c (evaluate_subexp_standard): Work around GCC bug 63748.
2014-11-10 15:11:44 +01:00
Pedro Alves 9de00a4aa0 gdb.base/sigstep.exp: xfail gdb/17511 on i?86 Linux
Running gdb.base/sigstep.exp with --target=i686-pc-linux-gnu on a
64-bit kernel naturally trips on PR gdb/17511 as well, given this is a
kernel bug.

I haven't really tested a real 32-bit kernel/machine, but given the
code in question in the kernel is shared between 32-bit and 64-bit,
I'm quite sure the bug triggers in those cases as well.

So, simply xfail i?86-*-linux* too.

gdb/testsuite/
2014-11-07  Pedro Alves  <palves@redhat.com>

	PR gdb/17511
	* gdb.base/sigstep.exp (in_handler_map) <si+advance>: xfail
	i?86-*-linux*.
2014-11-07 15:20:47 +00:00
Pedro Alves b7a084bebe Revert old nexti prologue check and eliminate in_prologue
The in_prologue check in the nexti code is obsolete; this commit
removes that, and then removes the in_prologue function as nothing
else uses it.

Looking at the code in GDB that makes use in_prologue, all we find is
this one caller:

      if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
	  || ((ecs->event_thread->control.step_range_end == 1)
	      && in_prologue (gdbarch, ecs->event_thread->prev_pc,
			      ecs->stop_func_start)))
	{
	  /* I presume that step_over_calls is only 0 when we're
	     supposed to be stepping at the assembly language level
	     ("stepi").  Just stop.  */
	  /* Also, maybe we just did a "nexti" inside a prolog, so we
	     thought it was a subroutine call but it was not.  Stop as
	     well.  FENN */
	  /* And this works the same backward as frontward.  MVS */
	  end_stepping_range (ecs);
	  return;
	}

This was added by:

 commit 100a02e1de
 ...
     From Fernando Nasser:
     * infrun.c (handle_inferior_event): Handle "nexti" inside function
     prologues.

The mailing list thread is here:

  https://sourceware.org/ml/gdb-patches/2001-01/msg00047.html

Not much discussion there, and no test, but looking at the code around
what was patched in that revision, we see that the checks that detect
whether the program has just stepped into a subroutine didn't rely on
the unwinders at all back then.

From 'git show 100a02e1:gdb/infrun.c':

    if (stop_pc == ecs->stop_func_start         /* Quick test */
        || (in_prologue (stop_pc, ecs->stop_func_start) &&
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
        || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
        || ecs->stop_func_name == 0)
      {
        /* It's a subroutine call.  */

        if ((step_over_calls == STEP_OVER_NONE)
            || ((step_range_end == 1)
                && in_prologue (prev_pc, ecs->stop_func_start)))
          {
            /* I presume that step_over_calls is only 0 when we're
               supposed to be stepping at the assembly language level
               ("stepi").  Just stop.  */
            /* Also, maybe we just did a "nexti" inside a prolog,
               so we thought it was a subroutine call but it was not.
               Stop as well.  FENN */
            stop_step = 1;
            print_stop_reason (END_STEPPING_RANGE, 0);
            stop_stepping (ecs);
            return;
          }

Stripping the IN_SOLIB_RETURN_TRAMPOLINE checks for simplicity, we had:

    if (stop_pc == ecs->stop_func_start         /* Quick test */
        || in_prologue (stop_pc, ecs->stop_func_start)
        || ecs->stop_func_name == 0)
      {
        /* It's a subroutine call.  */

That is, detecting a subroutine call was based on prologue detection
back then.  So the in_prologue check in the current tree only made
sense back then as it was undoing a bad decision the in_prologue check
that used to exist above did.

Today, the check for a subroutine call relies on frame ids instead,
which are stable throughout the function.  So we can just remove the
in_prologue check for nexti, and the whole in_prologue function along
with it.

Tested on x86_64 Fedora 20, and also by nexti-ing manually a prologue.

gdb/
2014-11-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (process_event_stop_test) <subroutine check>: Don't
	check if we did a "nexti" inside a prologue.
	* symtab.c (in_prologue): Delete function.
	* symtab.h (in_prologue): Delete declaration.
2014-11-07 13:53:01 +00:00
Doug Evans 67be31e5aa symtab.h (lookup_global_symbol): Improve function comment.
gdb/ChangeLog:

	* symtab.h (lookup_global_symbol): Improve function comment.
2014-11-06 23:51:21 -08:00
Doug Evans 08724ab7ca Rename lookup_symbol_global to lookup_global_symbol.
gdb/ChangeLog:

	* symtab.c (lookup_global_symbol): Renamed from lookup_symbol_global.
	All callers updated.
	* symtab.h (lookup_global_symbol): Update decl.
	(lookup_static_symbol): Move decl to better location.
2014-11-06 23:48:18 -08:00
Doug Evans d9060ba60d symtab.c (basic_lookup_symbol_nonlocal): Add comment.
gdb/ChangeLog:

	* symtab.c (basic_lookup_symbol_nonlocal): Add comment.
2014-11-06 23:34:28 -08:00
Doug Evans 74016e1224 Rename some "aux" functions.
"aux" doesn't contribute anything to the name, and it makes the
reader wonder what it's supposed to mean.

gdb/ChangeLog:

	* symtab.c (lookup_local_symbol): Renamed from lookup_symbol_aux_local.
	All callers updated.
	(lookup_symbol_in_all_objfiles): Renamed from
	lookup_symbol_aux_symtabs.  All callers updated.
	(lookup_symbol_via_quick_fns): Renamed from lookup_symbol_aux_quick.
	All callers updated.
	(lookup_symbol_in_objfile_symtabs): Renamed from
	lookup_symbol_aux_objfile.  All callers updated.
2014-11-06 23:29:49 -08:00
Doug Evans d1a2d36d58 lookup_symbol_in_block: Renamed from lookup_symbol_aux_block.
gdb/ChangeLog:

	* symtab.c (lookup_symbol_in_block): Renamed from
	lookup_symbol_aux_block.  All callers updated.
2014-11-06 23:04:15 -08:00
Doug Evans 24d864bb95 Rename lookup_symbol_static to lookup_symbol_in_static_block,
and lookup_static_symbol_aux to lookup_static_symbol.

gdb/ChangeLog:

	* symtab.c (lookup_static_symbol): Renamed from
	lookup_static_symbol_aux.  All callers updated.
	(lookup_symbol_in_static_block): Renamed from lookup_symbol_static.
	All callers updated.
2014-11-06 22:56:46 -08:00
Doug Evans 358d6ab39c New macro ALL_BLOCK_SYMBOLS_WITH_NAME.
gdb/ChangeLog:

	* block.h (ALL_BLOCK_SYMBOLS_WITH_NAME): New macro.
	* block.c (block_lookup_symbol): Use it.
	* cp-support.c (make_symbol_overload_list_block): Use it.
	* symtab.c (iterate_over_symbols): Use it.
2014-11-06 22:50:12 -08:00
Doug Evans 16b2eaa164 Move lookup_block_symbol to block.c, rename to block_lookup_symbol.
There is another function, lookup_symbol_aux_block, and
the names lookup_block_symbol and lookup_symbol_aux_block don't
convey any real difference between them.

The difference is that lookup_block_symbol lives in the lower level
block API, and lookup_symbol_aux_block lives in the higher level symtab API.
This patch makes this distinction clear.

gdb/ChangeLog:

	* symtab.c (lookup_block_symbol): Moved to ...
	* block.c (block_lookup_symbol):  ... here and renamed.
	All callers updated.
	* block.h (block_lookup_symbol): Declare.
	* symtab.h (lookup_block_symbol): Delete.
2014-11-06 22:32:25 -08:00
Doug Evans 2dd2cd1c92 Use ALL_PRIMARY_SYMTABS instead of ALL_SYMTABS in some places.
Non-primary symtabs share the block vector with their primary symtabs.
In these cases there's no need to use ALL_SYMTABS.

gdb/ChangeLog:

	* ada-lang.c (ada_make_symbol_completion_list): Use
	ALL_PRIMARY_SYMTABS instead of ALL_SYMTABS.
	* symtab.c (lookup_objfile_from_block): Ditto.
2014-11-06 17:27:55 -08:00
Doug Evans d4c589159d Forgotten ChangeLog entry for previous commit.
gdb/ChangeLog:

	* gdbtypes.h (TYPE_CODE_CLASS): Delete.  All uses changed to use
	TYPE_CODE_STRUCT.
2014-11-06 17:24:12 -08:00
Doug Evans 4753d33b40 Delete TYPE_CODE_CLASS, it's just an alias of TYPE_CODE_STRUCT.
gdb/ChangeLog:

	* gdbtypes.h (TYPE_CODE_CLASS): Delete.  All uses changed to use
	TYPE_CODE_STRUCT.
2014-11-06 17:19:06 -08:00
Doug Evans 9c1877ead0 solib_global_lookup: Fetch arch from objfile, not target_gdbarch.
gdb/ChangeLog:

	* objfiles.c (get_objfile_arch): Constify.
	* objfiles.h (get_objfile_arch): Update prototype.
	* solib.c (solib_global_lookup): Fetch arch from objfile,
	not target_gdbarch.
2014-11-06 17:10:51 -08:00
Sandra Loosemore 426a40796a Update Nios II prologue analysis to remove detection of long-obsolete
code sequences.

2014-11-06  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* nios2-tdep.c (wild_insn): Delete.
	(profiler_insn, irqentry_insn): Delete.
	(nios2_match_sequence): Delete.
	(nios2_analyze_prologue): Update comments.  Remove matching
	of obsolete profiler_insn and irqentry_insn sequences.
2014-11-06 12:56:27 -08:00
Alan Modra 1ae1b8cc65 Cast result of obstack_next_free
obstack_next_free is supposed to return a void*, rather than a char*
as it does currently.  Avoid warning on void* arithmetic when
obstack_next_free gets it proper return type.

	* cp-valprint.c (cp_print_value_fields): Cast obstack_next_free
	to char* before doing pointer arithmetic.
2014-11-05 16:38:10 +10:30
Alan Modra ee11262d06 Use obstack_blank_fast to shrink obstacks
obstack_blank isn't the correct macro to call for shrinking obstacks
since it does size checking.

	* charset.c (convert_between_encodings): Shrink obstack using
	obstack_blank_fast.
	* minsyms.c (install_minimal_symbols): Likewise.
2014-11-05 16:38:02 +10:30
Simon Marchi c87e6d0015 tui: Fix newterm call for older ncurses
Older versions of ncurses' newterm can't take NULL for their ofp and ifp
parameters. Newer versions can, and they fall back on stdout/stdin if
that is the case.

This patch explicitly passes stdout/stdin to the call to newterm to
avoid segfaulting with older ncurses.

gdb/Changelog:

2014-11-04  Simon Marchi  <simon.marchi@ericsson.com>

	* tui/tui.c (tui_enable): Pass stdout and stdin to newterm.
2014-11-04 14:15:53 -05:00
Pedro Alves 441ef17f09 garbage collect gdb/breakpoint.c:breakpoint_thread_match
Used to be necessary for the thread-hop code, but that's gone now.
Nothing uses this anymore.

gdb/
2014-11-04  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (breakpoint_thread_match): Delete function.
	* breakpoint.h (breakpoint_thread_match): Delete declaration.
2014-11-04 18:42:28 +00:00
Siva Chandra e0f52461c2 Fix evaluation of method calls under EVAL_SKIP.
When evaluating method calls under EVAL_SKIP, the "object" and the
arguments to the method should also be evaluated under EVAL_SKIP,
instead of skipping to evaluate them as was being done previously.

gdb/ChangeLog:

	PR c++/17494
	* eval.c (evaluate_subexp_standard): Evaluate the "object" and
	the method args also under EVAL_SKIP when evaluating method
	calls under EVAL_SKIP.

gdb/testsuite/ChangeLog:

	PR c++/17494
	* gdb.cp/pr17494.cc: New file.
	* gdb.cp/pr17494.exp: New file.
2014-11-03 18:01:39 -08:00
Yao Qi a0b4d89011 Add missing changelog entries
Some changelog entries are missing in previous commits.  Add them.
2014-11-03 20:12:18 +08:00
Doug Evans e82149ff2a mdebugread.c (parse_procedure): Delete unnecessary forward decl.
gdb/ChangeLog:

	* mdebugread.c (parse_procedure): Delete unnecessary forward decl.
2014-11-02 21:34:59 -08:00
Doug Evans d7ee84f117 xcoffread.c (process_linenos): Delete unnecessary code.
gdb/ChangeLog:

	* xcoffread.c (process_linenos): Delete unnecessary zeroing of
	main_subfile before returning.
2014-11-02 20:17:12 -08:00
Victor Kamensky ca45ab26f5 read_pieced_value do big endian processing only in case of valid gdb_regnum
During armv7b testing gdb.base/store.exp test was failling with
'GDB internal error' with the following message:

Temporary breakpoint 1, wack_double (u=
../../binutils-gdb/gdb/regcache.c:177: internal-error: register_size: Assertion `regnum >= 0 && regnum < (gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch))' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

It turns out that compiler generated DWARF with non-existent
register numbers. The compiler issue is present in both little endian
(armv7) and big endian (armv7b) (it is separate issue). Here is
example for one of formal parameters of wack_double function:

 <2><792>: Abbrev Number: 10 (DW_TAG_formal_parameter)
    <793>   DW_AT_name        : u
    <795>   DW_AT_decl_file   : 1
    <796>   DW_AT_decl_line   : 115
    <797>   DW_AT_type        : <0x57c>
    <79b>   DW_AT_location    : 6 byte block: 6d 93 4 6c 93 4   (DW_OP_reg29 (r29); DW_OP_piece: 4; DW_OP_reg28 (r28); DW_OP_piece: 4)

In both big and little endian cases gdbarch_dwarf2_reg_to_regnum
returns -1 which is stored into gdb_regnum. But it causes severe
problem only in big endian case because in read_pieced_value and
write_pieced_value functions BFD_ENDIAN_BIG related processing
happen regardless of gdb_regnum value, for example register_size
function is called and in case of gdb_regnum=-1, it cause
'GDB internal error' and crash.

Solution is to move BFD_ENDIAN_BIG related processing under
(gdb_regnum != -1) branch of processing.

gdb/ChangeLog:

2014-11-02  Victor Kamensky  <victor.kamensky@linaro.org>

	* dwarf2loc.c (read_pieced_value): Do big endian
	processing only if gdb_regnum is not -1.
	(write_pieced_value): Ditto.
2014-11-02 13:30:14 -08:00
Victor Kamensky dcd4a3a4e7 ARM: arm_breakpoint should be little endian form in case for arm BE8
tdep->arm_breakpoint, tdep->thumb_breakpoint, tdep->thumb2_breakpoint
should be set le_ variants in case of arm BE8 code. Those instruciton
sequences are writen to target with simple write_memory, without
regarding gdbarch_byte_order_for_code. But in BE8 case even data
memory is in big endian form, instructions are still in little endian
form.

Because of this issue there are many issues while running gdb test
case in armv7b mode. For example gdb.arch/arm-disp-step.exp test fails
because it gets SIGILL when displaced instrucion sequence reaches
break instruction, which is in wrong byte order.

Solution is to set tdep->xxx_breakpoint sequences in BE8 case (i.e
when gdbarch_byte_order_for_code is BFD_ENDIAN_BIG.

gdb/ChangeLog:

2014-11-02  Victor Kamensky  <victor.kamensky@linaro.org>

	* arm-linux-tdep.c (arm_linux_init_abi): Use
	info.byte_order_for_code to choose endianity of breakpoint
	instructions snippets.
2014-11-02 13:30:02 -08:00
Victor Kamensky 2959fed98c ARM: extract_arm_insn function need to read instrs correctly in be8 case
extract_arm_insn function needs to read instructions in
gdbarch_byte_order_for_code byte order, because in case armv7b,
even data is big endian, instructions are still little endian.
Currently function uses gdbarch_byte_order which would be
big endian in armv7b case.

Because of this issue pretty much all gdb.reverse/ tests are
failing with 'Process record does not support instruction' message.

Fix is to change gdbarch_byte_order to gdbarch_byte_order_for_code,
when passed to extract_unsigned_integer that reads instruction.

gdb/ChangeLog:

2014-11-02  Victor Kamensky  <victor.kamensky@linaro.org>

	* arm-tdep.c (extract_arm_insn): Use
	gdbarch_byte_order_for_code to read arm instruction.
2014-11-02 13:29:45 -08:00
Yao Qi 6ce8c98020 Match the working directory on remote host
The test in gdb.python/python.exp tests "extended-prompt" and expects
working directory is printed.  However, working directory on remote
host doesn't have "gdb/testsuite", so the test fails on remote host
like:

set extended-prompt \w ^M
^M
/home/yao FAIL: gdb.python/python.exp: set extended prompt working directory (timeout)

This patch is to get the working directory first, and use it to match
the output of "set extended-prompt \\w ".  It works for remote host
and non remote host.

gdb/testsuite:

2014-11-02  Yao Qi  <yao@codesourcery.com>

	* gdb.python/python.exp: Get working directory and match the
	output of "set extended-prompt \\w " with it.
2014-11-02 21:08:06 +08:00
Doug Evans 4f072d17b2 objfiles.h: Remove some unused macros.
gdb/ChangeLog:

	* objfiles.h (ALL_PSPACE_OBJFILES_SAFE): Delete, unused.
	(ALL_PSPACE_SYMTABS, ALL_PSPACE_PRIMARY_SYMTABS): Ditto.
2014-10-31 21:46:08 -07:00
Doug Evans 8301c89eb5 valops.c: Fix some whitespace.
gdb/ChangeLog:

	* valops.c (value_cast_pointers): Fix whitespace.
	(typecmp, search_struct_method, value_struct_elt, find_oload_champ):
	Ditto.
2014-10-31 20:20:48 -07:00
Doug Evans 02be9a7100 Add ability to add attributes to gdb.Objfile and gdb.Progspace objects.
gdb/ChangeLog:

	* NEWS: Mention ability add attributes to gdb.Objfile and
	gdb.Progspace objects.
	* python/py-objfile.c (objfile_object): New member dict.
	(objfpy_dealloc): Py_XDECREF dict.
	(objfpy_initialize): Initialize dict.
	(objfile_getset): Add __dict__.
	(objfile_object_type): Set tp_dictoffset member.
	* python/py-progspace.c (progspace_object): New member dict.
	(pspy_dealloc): Py_XDECREF dict.
	(pspy_initialize): Initialize dict.
	(pspace_getset): Add __dict__.
	(pspace_object_type): Set tp_dictoffset member.

gdb/doc/ChangeLog:

	* python.texi (Progspaces In Python): Document ability to add
	random attributes to gdb.Progspace objects.
	(Objfiles In Python): Document ability to add random attributes to
	gdb.objfile objects.

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Add tests for setting random attributes
	in objfiles.
	* gdb.python/py-progspace.exp: Add tests for setting random attributes
	in progspaces.
2014-10-30 17:05:17 -07:00
Luis Machado 3bdff46b67 Skip tests that use cd for remote hosts
Several GDB tests change directory before compiling the test program
in order to test source file names that include directories.  This
doesn't work on a remote host because default_target_compile in
DejaGnu's target.exp copies each source file with
"[remote_download host $x]" which uses "[file tail $file] to strip
off the directory of each file.  If the source directory is remote
mounted on the host, this also leaves copied files in the source
directory.

A similar skip is already used in gdb.test/fullname.exp:

    # We rely on being able to copy things around.

    if { [is_remote host] } {
	untested "setting breakpoints by full path"
	return -1
    }

This patch causes three GDB tests that use "cd" to be skipped for a
remote host.  For gdb.base/fullpath-expand.exp this eliminates two
failures and prevents the test from leaving files fullpath-expand.c
and fullpath-expand-func.c in gdb/testsuite.  For
gdb.base/realname-expand.exp it eliminates two failures.  For
gdb.linespec/macro-relative.exp it prevents file macro-relative.c
from being left in gdb/testsuite/gdb.linespec/base/two.

gdb/testsuite/

	* gdb.base/fullpath-expand.exp: Skip for a remote host.
	* gdb.base/realname-expand.exp: Likewise.
	* gdb.linespec/macro-relative.exp: Likewise.
2014-10-30 09:48:10 -02:00
Yao Qi 6427bef6d1 Don't replace '\' with '\\' in before_prompt_hook
In gdb/command/prompt.py:before_prompt_hook, the '\' in the new prompt
is replaced with '\\', shown as below,

>     def before_prompt_hook(self, current):
>         if self.value is not '':
>             newprompt = gdb.prompt.substitute_prompt(self.value)
>             return newprompt.replace('\\', '\\\\')
>         else:
>             return None

I don't see any explanations on this in comments nor email.  As doc
said, "set extended-prompt \w" substitute the current working
directory, but it prints something different from what pwd or
os.getcwdu() prints on mingw32 host.

(gdb) python print os.getcwdu()^M
\\build2-lucid-cs\yqi\yqi\arm-none-eabi

(gdb) pwd^M
Working directory \\build2-lucid-cs\yqi\yqi\arm-none-eabi

(gdb) set extended-prompt \w
\\\\build2-lucid-cs\\yqi\\yqi\\arm-none-eabi

This makes me think whether the substitution in before_prompt_hook is
necessary or not.  This patch is to remove this substitution.

Run gdb.python on x86_64-linux and arm-none-eabi on mingw32 host.  No
regressions.

gdb:

2014-10-30  Yao Qi  <yao@codesourcery.com>

	* python/lib/gdb/command/prompt.py (before_prompt_hook): Don't
	replace '\\' with '\\\\'.
2014-10-30 09:42:36 +08:00
Joel Brobecker f60325bea5 Document the GDB 7.8.1 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 7.8.1 released.
2014-10-29 12:57:04 -07:00
Pedro Alves ab917dfb5a This PR shows that GDB can easily trigger an assertion here, in
infrun.c:

 5392              /* Did we find the stepping thread?  */
 5393              if (tp->control.step_range_end)
 5394                {
 5395                  /* Yep.  There should only one though.  */
 5396                  gdb_assert (stepping_thread == NULL);
 5397
 5398                  /* The event thread is handled at the top, before we
 5399                     enter this loop.  */
 5400                  gdb_assert (tp != ecs->event_thread);
 5401
 5402                  /* If some thread other than the event thread is
 5403                     stepping, then scheduler locking can't be in effect,
 5404                     otherwise we wouldn't have resumed the current event
 5405                     thread in the first place.  */
 5406                  gdb_assert (!schedlock_applies (currently_stepping (tp)));
 5407
 5408                  stepping_thread = tp;
 5409                }

Like:

 gdb/infrun.c:5406: internal-error: switch_back_to_stepped_thread: Assertion `!schedlock_applies (1)' failed.

The way the assertion is written is assuming that with schedlock=step
we'll always leave threads other than the one with the stepping range
locked, while that's not true with the "next" command.  With schedlock
"step", other threads still run unlocked when "next" detects a
function call and steps over it.  Whether that makes sense or not,
still, it's documented that way in the manual.  If another thread hits
an event that doesn't cause a stop while the nexting thread steps over
a function call, we'll get here and fail the assertion.

The fix is just to adjust the assertion.  Even though we found the
stepping thread, we'll still step-over the breakpoint that just
triggered correctly.

Surprisingly, gdb.threads/schedlock.exp doesn't have any test that
steps over a function call.  This commits fixes that.  This ensures
that "next" doesn't switch focus to another thread, and checks whether
other threads run locked or not, depending on scheduler locking mode
and command.  There's a lot of duplication in that file that this ends
cleaning up.  There's more that could be cleaned up, but that would
end up an unrelated change, best done separately.

This new coverage in schedlock.exp happens to trigger the internal
error in question, like so:

 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (1) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (3) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (5) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (7) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (9) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next does not change thread (switched to thread 0)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: current thread advanced - unlocked (wrong amount)

That's because we have more than one thread running the same loop, and
while one thread is stepping over a function call, the other thread
hits the step-resume breakpoint of the first, which needs to be
stepped over, and we end up in switch_back_to_stepped_thread exactly
in the problem case.

I think a simpler and more directed test is also useful, to not rely
on internal breakpoint magics.  So this commit also adds a test that
has a thread trip on a conditional breakpoint that doesn't cause a
user-visible stop while another thread is stepping over a call.  That
currently fails like this:

 FAIL: gdb.threads/next-bp-other-thread.exp: schedlock=step: next over function call (GDB internal error)

Tested on x86_64 Fedora 20.

gdb/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR gdb/17408
	* infrun.c (switch_back_to_stepped_thread): Use currently_stepping
	instead of assuming a thread with a stepping range is always
	stepping.

gdb/testsuite/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR gdb/17408
	* gdb.threads/schedlock.c (some_function): New function.
	(call_function): New global.
	(MAYBE_CALL_SOME_FUNCTION): New macro.
	(thread_function): Call it.
	* gdb.threads/schedlock.exp (get_args): Add description parameter,
	and use it instead of a global counter.  Adjust all callers.
	(get_current_thread): Use "find current thread" for test message
	here rather than having all callers pass down the same string.
	(goto_loop): New procedure, factored out from ...
	(my_continue): ... this.
	(step_ten_loops): Change parameter from test message to command to
	use.  Adjust.
	(list_count): Delete global.
	(check_result): New procedure, factored out from duplicate top
	level code.
	(continue tests): Wrap in with_test_prefix.
	(test_step): New procedure, factored out from duplicate top level
	code.
	(top level): Test "step" in combination with all scheduler-locking
	modes.  Test "next" in combination with all scheduler-locking
	modes, and in combination with stepping over a function call or
	not.
	* gdb.threads/next-bp-other-thread.c: New file.
	* gdb.threads/next-bp-other-thread.exp: New file.
2014-10-29 18:25:27 +00:00
Pedro Alves 354204061c PR 17408 - assertion failure in switch_back_to_stepped_thread
This PR shows that GDB can easily trigger an assertion here, in
infrun.c:

 5392              /* Did we find the stepping thread?  */
 5393              if (tp->control.step_range_end)
 5394                {
 5395                  /* Yep.  There should only one though.  */
 5396                  gdb_assert (stepping_thread == NULL);
 5397
 5398                  /* The event thread is handled at the top, before we
 5399                     enter this loop.  */
 5400                  gdb_assert (tp != ecs->event_thread);
 5401
 5402                  /* If some thread other than the event thread is
 5403                     stepping, then scheduler locking can't be in effect,
 5404                     otherwise we wouldn't have resumed the current event
 5405                     thread in the first place.  */
 5406                  gdb_assert (!schedlock_applies (currently_stepping (tp)));
 5407
 5408                  stepping_thread = tp;
 5409                }

Like:

 gdb/infrun.c:5406: internal-error: switch_back_to_stepped_thread: Assertion `!schedlock_applies (1)' failed.

The way the assertion is written is assuming that with schedlock=step
we'll always leave threads other than the one with the stepping range
locked, while that's not true with the "next" command.  With schedlock
"step", other threads still run unlocked when "next" detects a
function call and steps over it.  Whether that makes sense or not,
still, it's documented that way in the manual.  If another thread hits
an event that doesn't cause a stop while the nexting thread steps over
a function call, we'll get here and fail the assertion.

The fix is just to adjust the assertion.  Even though we found the
stepping thread, we'll still step-over the breakpoint that just
triggered correctly.

Surprisingly, gdb.threads/schedlock.exp doesn't have any test that
steps over a function call.  This commits fixes that.  This ensures
that "next" doesn't switch focus to another thread, and checks whether
other threads run locked or not, depending on scheduler locking mode
and command.  There's a lot of duplication in that file that this ends
cleaning up.  There's more that could be cleaned up, but that would
end up an unrelated change, best done separately.

This new coverage in schedlock.exp happens to trigger the internal
error in question, like so:

 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (1) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (3) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (5) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (7) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next to increment (9) (GDB internal error)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: next does not change thread (switched to thread 0)
 FAIL: gdb.threads/schedlock.exp: schedlock=step: cmd=next: call_function=1: current thread advanced - unlocked (wrong amount)

That's because we have more than one thread running the same loop, and
while one thread is stepping over a function call, the other thread
hits the step-resume breakpoint of the first, which needs to be
stepped over, and we end up in switch_back_to_stepped_thread exactly
in the problem case.

I think a simpler and more directed test is also useful, to not rely
on internal breakpoint magics.  So this commit also adds a test that
has a thread trip on a conditional breakpoint that doesn't cause a
user-visible stop while another thread is stepping over a call.  That
currently fails like this:

 FAIL: gdb.threads/next-bp-other-thread.exp: schedlock=step: next over function call (GDB internal error)

Tested on x86_64 Fedora 20.

gdb/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR gdb/17408
	* infrun.c (switch_back_to_stepped_thread): Use currently_stepping
	instead of assuming a thread with a stepping range is always
	stepping.

gdb/testsuite/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR gdb/17408
	* gdb.threads/schedlock.c (some_function): New function.
	(call_function): New global.
	(MAYBE_CALL_SOME_FUNCTION): New macro.
	(thread_function): Call it.
	* gdb.threads/schedlock.exp (get_args): Add description parameter,
	and use it instead of a global counter.  Adjust all callers.
	(get_current_thread): Use "find current thread" for test message
	here rather than having all callers pass down the same string.
	(goto_loop): New procedure, factored out from ...
	(my_continue): ... this.
	(step_ten_loops): Change parameter from test message to command to
	use.  Adjust.
	(list_count): Delete global.
	(check_result): New procedure, factored out from duplicate top
	level code.
	(continue tests): Wrap in with_test_prefix.
	(test_step): New procedure, factored out from duplicate top level
	code.
	(top level): Test "step" in combination with all scheduler-locking
	modes.  Test "next" in combination with all scheduler-locking
	modes, and in combination with stepping over a function call or
	not.
	* gdb.threads/next-bp-other-thread.c: New file.
	* gdb.threads/next-bp-other-thread.exp: New file.
2014-10-29 18:15:39 +00:00
Pedro Alves d3d4baedb6 PR python/17372 - Python hangs when displaying help()
This is more of a readline/terminal issue than a Python one.

PR17372 is a regression in 7.8 caused by the fix for PR17072:

 commit 0017922d02
 Author: Pedro Alves <palves@redhat.com>
 Date:   Mon Jul 14 19:55:32 2014 +0100

    Background execution + pagination aborts readline/gdb

    gdb_readline_wrapper_line removes the handler after a line is
    processed.  Usually, we'll end up re-displaying the prompt, and that
    reinstalls the handler.  But if the output is coming out of handling
    a stop event, we don't re-display the prompt, and nothing restores the
    handler.  So the next input wakes up the event loop and calls into
    readline, which aborts.
...
    gdb/
    2014-07-14  Pedro Alves  <palves@redhat.com>

        PR gdb/17072
        * top.c (gdb_readline_wrapper_line): Tweak comment.
        (gdb_readline_wrapper_cleanup): If readline is enabled, reinstall
        the input handler callback.

The problem is that installing the input handler callback also preps
the terminal, putting it in raw mode and with echo disabled, which is
bad if we're going to call a command that assumes cooked/canonical
mode, and echo enabled, like in the case of the PR, Python's
interactive shell.  Another example I came up with that doesn't depend
on Python is starting a subshell with "(gdb) shell /bin/sh" from a
multi-line command.  Tests covering both these examples are added.

The fix is to revert the original fix for PR gdb/17072, and instead
restore the callback handler after processing an asynchronous target
event.

Furthermore, calling rl_callback_handler_install when we already have
some input in readline's line buffer discards that input, which is
obviously a bad thing to do while the user is typing.  No specific
test is added for that, because I first tried calling it even if the
callback handler was still installed and that resulted in hundreds of
failures in the testsuite.

gdb/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR python/17372
	* event-top.c (change_line_handler): Call
	gdb_rl_callback_handler_remove instead of
	rl_callback_handler_remove.
	(callback_handler_installed): New global.
	(gdb_rl_callback_handler_remove, gdb_rl_callback_handler_install)
	(gdb_rl_callback_handler_reinstall): New functions.
	(display_gdb_prompt): Call gdb_rl_callback_handler_remove and
	gdb_rl_callback_handler_install instead of
	rl_callback_handler_remove and rl_callback_handler_install.
	(gdb_disable_readline): Call gdb_rl_callback_handler_remove
	instead of rl_callback_handler_remove.
	* event-top.h (gdb_rl_callback_handler_remove)
	(gdb_rl_callback_handler_install)
	(gdb_rl_callback_handler_reinstall): New declarations.
	* infrun.c (reinstall_readline_callback_handler_cleanup): New
	cleanup function.
	(fetch_inferior_event): Install it.
	* top.c (gdb_readline_wrapper_line) Call
	gdb_rl_callback_handler_remove instead of
	rl_callback_handler_remove.
	(gdb_readline_wrapper_cleanup): Don't call
	rl_callback_handler_install.

gdb/testsuite/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR python/17372
	* gdb.python/python.exp: Test a multi-line command that spawns
	interactive Python.
	* gdb.base/multi-line-starts-subshell.exp: New file.
2014-10-29 17:29:26 +00:00
Pedro Alves 6e5d7f393e Fix uninitialized value access when very first GDB command entered is <RET>
While running GDB under Valgrind, I noticed that if the very first
command entered is just <RET>, GDB accesses an uninitialized value:

 $ valgrind ./gdb -q -nx
 ==26790== Memcheck, a memory error detector
 ==26790== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
 ==26790== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
 ==26790== Command: ./gdb -q -nx
 ==26790==

 (gdb)
 ==26790== Conditional jump or move depends on uninitialised value(s)
 ==26790==    at 0x619DFC: command_line_handler (event-top.c:588)
 ==26790==    by 0x7813D5: rl_callback_read_char (callback.c:220)
 ==26790==    by 0x6194B4: rl_callback_read_char_wrapper (event-top.c:166)
 ==26790==    by 0x61988A: stdin_event_handler (event-top.c:372)
 ==26790==    by 0x61847D: handle_file_event (event-loop.c:762)
 ==26790==    by 0x617964: process_event (event-loop.c:339)
 ==26790==    by 0x617A2B: gdb_do_one_event (event-loop.c:403)
 ==26790==    by 0x617A7B: start_event_loop (event-loop.c:428)
 ==26790==    by 0x6194E6: cli_command_loop (event-top.c:181)
 ==26790==    by 0x60F86B: current_interp_command_loop (interps.c:317)
 ==26790==    by 0x610A34: captured_command_loop (main.c:321)
 ==26790==    by 0x60C728: catch_errors (exceptions.c:237)
 ==26790==
 (gdb)

It's this check here:

  /* If we just got an empty line, and that is supposed to repeat the
     previous command, return the value in the global buffer.  */
  if (repeat && p == linebuffer && *p != '\\')
    {

The problem is that linebuffer's contents were never initialized at
this point.

gdb/
2014-10-29  Pedro Alves  <palves@redhat.com>

	* event-top.c (command_line_handler): Clear the first byte of
	linebuffer, when it is first allocated.
2014-10-29 14:54:17 +00:00
Pedro Alves 1e1e619b6b PR tui/16138 is about failure to initialize curses resulting in GDB
exiting instead of throwing an error.  E.g.:

 $ TERM=foo gdb
 (gdb) layout asm
 Error opening terminal: foo.
 $

The problem is that we're calling initscr to initialize the screen.
As mentioned in
http://pubs.opengroup.org/onlinepubs/7908799/xcurses/initscr.html:

 If errors occur, initscr() writes an appropriate error message to
 standard error and exits.
                    ^^^^^

Instead, we should use newterm:

 "A program that needs an indication of error conditions, so it can
 continue to run in a line-oriented mode if the terminal cannot support
 a screen-oriented program, would also use this function."

After the patch:

 $ TERM=foo gdb -q -nx
 (gdb) layout asm
 Cannot enable the TUI: error opening terminal [TERM=foo]
 (gdb)

And then PR tui/17519 is about GDB not validating whether the terminal
has the necessary capabilities when enabling the TUI.  If one tries to
enable the TUI with TERM=dumb (and e.g., from a shell within emacs),
GDB ends up with a clear screen, the cursor is placed at the
bottom/right corner of the screen, there's no prompt, typing shows no
echo, and there's no indication of what's going on.  c-x,a gets you
out of the TUI, but it's completely non-obvious.

After the patch, we get:

 $ TERM=dumb gdb -q -nx
 (gdb) layout asm
 Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
 (gdb)

While at it, I've moved all the tui_allowed_p validation to
tui_enable, and expanded the error messages.  Previously we'd get:

 $ gdb -q -nx -i=mi
 (gdb)
 layout asm
 &"layout asm\n"
 &"TUI mode not allowed\n"
 ^error,msg="TUI mode not allowed"

and:

 $ gdb -q -nx -ex "layout asm" > foo
 TUI mode not allowed

While now we get:

 $ gdb -q -nx -i=mi
 (gdb)
 layout asm
 &"layout asm\n"
 &"Cannot enable the TUI when the interpreter is 'mi'\n"
 ^error,msg="Cannot enable the TUI when the interpreter is 'mi'"
 (gdb)

and:

 $ gdb -q -nx -ex "layout asm" > foo
 Cannot enable the TUI when output is not a terminal

Tested on x86_64 Fedora 20.

gdb/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR tui/16138
	PR tui/17519
	* tui/tui-interp.c (tui_is_toplevel): Delete global.
	(tui_allowed_p): Delete function.
	* tui/tui.c: Include "interps.h".
	(tui_enable): Don't use tui_allowed_p.  Error out here with
	detailed error messages if the TUI is the top level interpreter,
	or if output is not a terminal.  Use newterm instead of initscr,
	and error out if initializing the terminal fails.  Also error out if
	the terminal doesn't support cursor addressing.
	* tui/tui.h (tui_allowed_p): Delete declaration.
2014-10-29 14:49:05 +00:00
Pedro Alves 551cb6a52d TUI: don't let exceptions escape while handling readline key bindings
I noticed that with:

 $ TERM=dumb ./gdb -q -nx
 <c-x,a>
 Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
 (gdb)

The next key the user types is silently eaten.

The problem is that we're throwing an exception while in a readline
callback that isn't prepared for that:

(top-gdb) bt
#0  tui_enable () at /home/pedro/gdb/mygit/build/../src/gdb/tui/tui.c:388
#1  0x000000000051f47b in tui_rl_switch_mode (notused1=1, notused2=1) at /home/pedro/gdb/mygit/build/../src/gdb/tui/tui.c:101
#2  0x0000000000768d6f in _rl_dispatch_subseq (key=1, map=0xd069c0 <emacs_ctlx_keymap>, got_subseq=0) at /home/pedro/gdb/mygit/build/../src/readline/readline.c:774
#3  0x0000000000768acb in _rl_dispatch_callback (cxt=0x1ce6190) at /home/pedro/gdb/mygit/build/../src/readline/readline.c:686
#4  0x000000000078120b in rl_callback_read_char () at /home/pedro/gdb/mygit/build/../src/readline/callback.c:170
#5  0x0000000000619445 in rl_callback_read_char_wrapper (client_data=0x0) at /home/pedro/gdb/mygit/build/../src/gdb/event-top.c:166
#6  0x000000000061981b in stdin_event_handler (error=0, client_data=0x0) at /home/pedro/gdb/mygit/build/../src/gdb/event-top.c:372
#7  0x000000000061840e in handle_file_event (data=...) at /home/pedro/gdb/mygit/build/../src/gdb/event-loop.c:762
#8  0x00000000006178f5 in process_event () at /home/pedro/gdb/mygit/build/../src/gdb/event-loop.c:339
#9  0x00000000006179bc in gdb_do_one_event () at /home/pedro/gdb/mygit/build/../src/gdb/event-loop.c:403
#10 0x0000000000617a0c in start_event_loop () at /home/pedro/gdb/mygit/build/../src/gdb/event-loop.c:428

Here, in _rl_dispatch_subseq:

769
770               rl_executing_keymap = map;
771
772               rl_dispatching = 1;
773               RL_SETSTATE(RL_STATE_DISPATCHING);
774               (*map[key].function)(rl_numeric_arg * rl_arg_sign, key);
775               RL_UNSETSTATE(RL_STATE_DISPATCHING);
776               rl_dispatching = 0;
777
778               /* If we have input pending, then the last command was a prefix
779                  command.  Don't change the state of rl_last_func.  Otherwise,

GDB is called from line 774, but longjmp'ing at that point leaves
rl_dispatching and RL_STATE_DISPATCHING set.

Fix this by wrapping tui_rl_switch_mode in a TRY_CATCH.

gdb/
2014-10-29  Pedro Alves  <palves@redhat.com>

	* tui/tui.c (tui_rl_switch_mode): Wrap tui_enable/tui_disable in
	TRY_CATCH.
2014-10-29 14:36:21 +00:00
Pedro Alves 84eda397bc PR tui/16138, PR tui/17519, and misc failures to initialize the terminal
PR tui/16138 is about failure to initialize curses resulting in GDB
exiting instead of throwing an error.  E.g.:

 $ TERM=foo gdb
 (gdb) layout asm
 Error opening terminal: foo.
 $

The problem is that we're calling initscr to initialize the screen.
As mentioned in
http://pubs.opengroup.org/onlinepubs/7908799/xcurses/initscr.html:

 If errors occur, initscr() writes an appropriate error message to
 standard error and exits.
                    ^^^^^

Instead, we should use newterm:

 "A program that needs an indication of error conditions, so it can
 continue to run in a line-oriented mode if the terminal cannot support
 a screen-oriented program, would also use this function."

After the patch:

 $ TERM=foo gdb -q -nx
 (gdb) layout asm
 Cannot enable the TUI: error opening terminal [TERM=foo]
 (gdb)

And then PR tui/17519 is about GDB not validating whether the terminal
has the necessary capabilities when enabling the TUI.  If one tries to
enable the TUI with TERM=dumb (and e.g., from a shell within emacs),
GDB ends up with a clear screen, the cursor is placed at the
bottom/right corner of the screen, there's no prompt, typing shows no
echo, and there's no indication of what's going on.  c-x,a gets you
out of the TUI, but it's completely non-obvious.

After the patch, we get:

 $ TERM=dumb gdb -q -nx
 (gdb) layout asm
 Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
 (gdb)

While at it, I've moved all the tui_allowed_p validation to
tui_enable, and expanded the error messages.  Previously we'd get:

 $ gdb -q -nx -i=mi
 (gdb)
 layout asm
 &"layout asm\n"
 &"TUI mode not allowed\n"
 ^error,msg="TUI mode not allowed"

and:

 $ gdb -q -nx -ex "layout asm" > foo
 TUI mode not allowed

While now we get:

 $ gdb -q -nx -i=mi
 (gdb)
 layout asm
 &"layout asm\n"
 &"Cannot enable the TUI when the interpreter is 'mi'\n"
 ^error,msg="Cannot enable the TUI when the interpreter is 'mi'"
 (gdb)

and:

 $ gdb -q -nx -ex "layout asm" > foo
 Cannot enable the TUI when output is not a terminal

Tested on x86_64 Fedora 20.

gdb/
2014-10-29  Pedro Alves  <palves@redhat.com>

	PR tui/16138
	PR tui/17519
	* tui/tui-interp.c (tui_is_toplevel): Delete global.
	(tui_allowed_p): Delete function.
	* tui/tui.c: Include "interps.h".
	(tui_enable): Don't use tui_allowed_p.  Error out here with
	detailed error messages if the TUI is the top level interpreter,
	or if output is not a terminal.  Use newterm instead of initscr,
	and error out if initializing the terminal fails.  Also error out if
	the terminal doesn't support cursor addressing.
	* tui/tui.h (tui_allowed_p): Delete declaration.
2014-10-29 14:23:57 +00:00
Yao Qi 563e8d8516 Prepare directory in case test_system fails
In gdb.base/fileio.c, some functions may depend on others.  For
example, test_rename renames a file to one directory which is created
in test_system.  That is means, if test_system fails, test_rename
fails too, which is not a good practise, IMO.

In test_system, system ("mkdir -p XX") is used to create directories
needed for test_rename.  In this patch, we use dejagnu remote_exec
proc to create these directories on host.

In my gdb testing, mingw32 host and arm-none-eabi target, system
("mkdir -p XX") doesn't work properly (this issue can be addressed
separately), and this patch fixes the following fails.

FAIL: gdb.base/fileio.exp: Renaming a directory to a non-empty directory returns ENOTEMPTY or EEXIST
FAIL: gdb.base/fileio.exp: Unlink a file
FAIL: gdb.base/fileio.exp: Unlinking a file in a directory w/o write access returns EACCES

gdb/testsuite:

2014-10-29  Yao Qi  <yao@codesourcery.com>

	* gdb.base/fileio.exp: Make directories on host.
2014-10-29 21:43:05 +08:00
Yao Qi 0ea4d52e43 Close the file in fileio.exp test
I see the following fail in fileio.exp on mingw32 host gdb,

rename 1: ret = -1, errno = 13^M
^M
Breakpoint 2, stop () at fileio.c:76^M
76      static void stop () {}^M
(gdb) FAIL: gdb.base/fileio.exp: Rename a file

the test fails to rename a file which is not expected.  The previous
test test_write doesn't close the file, so the rename fails as a
result on Windows.  This patch fixes it by closing file in test_write,
and the fail goes away.

rename 1: ret = 0, errno = 0 OK^M
^M
Breakpoint 2, stop () at fileio.c:76^M
76      static void stop () {}^M
(gdb) PASS: gdb.base/fileio.exp: Rename a file

gdb/testsuite:

2014-10-29  Yao Qi  <yao@codesourcery.com>

	* gdb.base/fileio.c (test_write): Close the file.
2014-10-29 21:43:05 +08:00
Joel Brobecker 6041179a74 ARM: stricter __stack_chk_guard check during prologue analysis
We are trying to insert a breakpoint on line 4 for the following
Ada code.

  3 procedure STR is
  4    XX : String (1 .. Blocks.Sz) := (others => 'X'); -- STOP
  5    K : Integer;
  6 begin
  7    K := 13;

The code generated on ARM (-march=armv7-m) starts like this:

    (gdb) disass str'address
    Dump of assembler code for function _ada_str:
       --# Line str.adb:3
       0x08000014 <+0>:     push    {r4, r7, lr}
       0x08000016 <+2>:     sub     sp, #28
       0x08000018 <+4>:     add     r7, sp, #0
       0x0800001a <+6>:     mov     r3, sp
       0x0800001c <+8>:     mov     r4, r3
       --# Line str.adb:4
       0x0800001e <+10>:    ldr     r3, [pc, #84]   ; (0x8000074 <_ada_str+96>)
       0x08000020 <+12>:    ldr     r3, [r3, #0]
       0x08000022 <+14>:    str     r3, [r7, #20]
       0x08000024 <+16>:    ldr     r3, [r7, #20]
       [...]

When computing the address related to str.adb:4, GDB correctly
resolves it to 0x0800001e first, but then considers the next
3 instructions as being part of the prologue because it thinks
they are part of stack-protector code. As a result, instead
of inserting the breakpoint at line 4, it skips those instruction
and consequently the rest of the instructions until the start
of the next line, which his line 7.

The stack-protector code is expected to start like this...

        ldr     Rn, .Label
        ....
        .Lable:
        .word   __stack_chk_guard

... but the implementation actually accepts a sequence where
the ldr location points to an address for which there is no symbol.
It only aborts if the address points to a symbol which is not
__stack_chk_guard.

Since the __stack_chk_guard symbol is always expected to exist
when used (it lives in .dynsym), this patch fixes the issue by
requiring that the ldr gets the address of the __stack_chk_guard
symbol. If the address could not be resolved, then it rejects
the sequence as being stack-protector code.

gdb/ChangeLog:

        * arm-tdep.c (arm_skip_stack_protector): Return early if
        address loaded by first "ldr" instruction does not have
        a corresponding minimal symbol.  Update comment.

Tested on arm-eabi using AdaCore's testsuite.
Tested on arm-linux-gnueabi by Yao as well.
2014-10-29 06:10:24 -07:00
Yao Qi 6ae274b7dc Fix skipping stack protector on arm
This patch fixes the bug in my patch skipping stack protector
https://www.sourceware.org/ml/gdb-patches/2010-12/msg00110.html

In my skipping stack protector patch, I misunderstood the constant vs.
immediate on instruction encodings, and treated immediate as constant
by mistake.  The instruction 'ldr Rd, [PC, #immed]' loads the
address of __stack_chk_guard to Rd, and #immed is an offset from PC.
We should get the __stack_chk_guard from *(pc + #immed).

As a result of this mistake, arm_analyze_load_stack_chk_guard returns
the wrong address of __stack_chk_guard, and the symbol
__stack_chk_guard can't be found.  However, we continue to match the
following instructions when symbol isn't found, so the code still
works.  In other words, the code just matches the instruction pattern
without checking __stack_chk_guard symbol correctly.

Joel's patch <https://sourceware.org/ml/gdb-patches/2014-10/msg00605.html>
makes the heuristics stricter that we stop matching instructions if
symbol __stack_chk_guard isn't found.  Then the bug is exposed.  This
patch is to correct the load address computation for ldr instruction,
and it fixes some fails in gdb.mi/gdb792.exp on armv4t both arm and
thumb mode.

Regression tested on arm-linux-gnueabi target with
{armv4t, armv7-a} x {marm, mthumb} x {-fstack-protector,-fno-stack-protector}

gdb:

2014-10-29  Yao Qi  <yao@codesourcery.com>

	* arm-tdep.c (arm_analyze_load_stack_chk_guard): Compute the
	loaded address correctly of ldr instruction.
2014-10-29 13:39:16 +08:00
Pedro Alves 7f5ef60532 PR gdb/12623: non-stop crashes inferior, PC adjustment and 1-byte insns
TL;DR - if we step an instruction that is as long as
decr_pc_after_break (1-byte on x86) right after removing the
breakpoint at PC, in non-stop mode, adjust_pc_after_break adjusts the
PC, but it shouldn't.

In non-stop mode, when a breakpoint is removed, it is moved to the
"moribund locations" list.  This is because other threads that are
running may have tripped on that breakpoint as well, and we haven't
heard about it.  When a trap is reported, we check if perhaps it was
such a deleted breakpoint that caused the trap.  If so, we also need
to adjust the PC (decr_pc_after_break).

Now, say that, on x86:

 - a breakpoint was placed at an address where we have an instruction
of the same length as decr_pc_after_break on this arch (1 on x86).

 - the breakpoint is removed, and thus put on the moribund locations
   list.

 - the thread is single-stepped.

As there's no breakpoint inserted at PC anymore, the single-step
actually executes the 1-byte instruction normally.  GDB should _not_
adjust the PC for the resulting SIGTRAP.  But, adjust_pc_after_break
confuses the step SIGTRAP reported for this single-step as being a
SIGTRAP for the moribund location of the breakpoint that used to be at
the previous PC, and so infrun applies the decr_pc_after_break
adjustment incorrectly.

The confusion comes from the special case mentioned in the comment:

 static void
 adjust_pc_after_break (struct execution_control_state *ecs)
 {
 ...
	  As a special case, we could have hardware single-stepped a
	  software breakpoint.  In this case (prev_pc == breakpoint_pc),
	  we also need to back up to the breakpoint address.  */

       if (thread_has_single_step_breakpoints_set (ecs->event_thread)
	   || !ptid_equal (ecs->ptid, inferior_ptid)
	   || !currently_stepping (ecs->event_thread)
	   || (ecs->event_thread->stepped_breakpoint
	       && ecs->event_thread->prev_pc == breakpoint_pc))
	 regcache_write_pc (regcache, breakpoint_pc);

The condition that incorrectly triggers is the
"ecs->event_thread->prev_pc == breakpoint_pc" one.

Afterwards, the next resume resume re-executes an instruction that had
already executed, which if you're lucky, results in the inferior
crashing.  If you're unlucky, you'll get silent bad behavior...

The fix is to remember that we stepped a breakpoint.  Turns out the
only case we step a breakpoint instruction today isn't covered by the
testsuite.  It's the case of a 'handle nostop" signal arriving while a
step is in progress _and_ we have a software watchpoint, which forces
always single-stepping.  This commit extends sigstep.exp to cover
that, and adds a new test for the adjust_pc_after_break issue.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-28  Pedro Alves  <palves@redhat.com>

	PR gdb/12623
	* gdbthread.h (struct thread_info) <stepped_breakpoint>: New
	field.
	* infrun.c (resume) <stepping breakpoint instruction>: Set the
	thread's stepped_breakpoint field.  Skip if reverse debugging.
	Add comment.
	(init_thread_stepping_state, handle_signal_stop): Clear the
	thread's stepped_breakpoint field.

gdb/testsuite/
2014-10-28  Pedro Alves  <palves@redhat.com>

	PR gdb/12623
	* gdb.base/sigstep.c (no_handler): New global.
	(main): If 'no_handler is true, set the signal handlers to
	SIG_IGN.
	* gdb.base/sigstep.exp (breakpoint_over_handler): Add
	with_sw_watch and no_handler parameters.  Handle them.
	(top level) <stepping over handler when stopped at a breakpoint
	test>: Add a test axis for testing with a software watchpoint, and
	another for testing with the signal handler set to SIG_IGN.
	* gdb.base/step-sw-breakpoint-adjust-pc.c: New file.
	* gdb.base/step-sw-breakpoint-adjust-pc.exp: New file.
2014-10-28 16:00:06 +00:00
Pedro Alves abbdbd03db Test for PR gdb/17511, spurious SIGTRAP after stepping into+in signal handler
I noticed that when I single-step into a signal handler with a
pending/queued signal, the following single-steps while the program is
in the signal handler leave $eflags.TF set.  That means subsequent
continues will trap after one instruction, resulting in a spurious
SIGTRAP being reported to the user.

This is a kernel bug; I've reported it to kernel devs (turned out to
be a known bug).  I'm seeing it on x86_64 Fedora 20 (Linux
3.16.4-200.fc20.x86_64), and I was told it's still not fixed upstream.

This commit extends gdb.base/sigstep.exp to cover this use case,
xfailed.

Here's what the bug looks like:

 (gdb) start
 Temporary breakpoint 1, main () at si-handler.c:48
 48        setup ();
 (gdb) next
 50        global = 0; /* set break here */

Let's queue a signal, so we can step into the handler:

 (gdb) handle SIGUSR1
 Signal        Stop      Print   Pass to program Description
 SIGUSR1       Yes       Yes     Yes             User defined signal 1
 (gdb) queue-signal SIGUSR1

TF is not set:

 (gdb) display $eflags
 1: $eflags = [ PF ZF IF ]

Now step into the handler -- "si" does PTRACE_SINGLESTEP+SIGUSR1:

 (gdb) si
 sigusr1_handler (sig=0) at si-handler.c:31
 31      {
 1: $eflags = [ PF ZF IF ]

No TF yet.  But another single-step...

 (gdb) si
 0x0000000000400621      31      {
 1: $eflags = [ PF ZF TF IF ]

... ends up with TF left set.  This results in PTRACE_CONTINUE
trapping after each instruction is executed:

 (gdb) c
 Continuing.

 Program received signal SIGTRAP, Trace/breakpoint trap.
 0x0000000000400624 in sigusr1_handler (sig=0) at si-handler.c:31
 31      {
 1: $eflags = [ PF ZF TF IF ]

 (gdb) c
 Continuing.

 Program received signal SIGTRAP, Trace/breakpoint trap.
 sigusr1_handler (sig=10) at si-handler.c:32
 32        global = 0;
 1: $eflags = [ PF ZF TF IF ]
 (gdb)

Note that even another PTRACE_SINGLESTEP does not fix it:

 (gdb) si
 33      }
 1: $eflags = [ PF ZF TF IF ]
 (gdb)

Eventually, it gets "fixed" by the rt_sigreturn syscall, when
returning out of the handler:

 (gdb) bt
 #0  sigusr1_handler (sig=10) at si-handler.c:33
 #1  <signal handler called>
 #2  main () at si-handler.c:50
 (gdb) set disassemble-next-line on
 (gdb) si
 0x0000000000400632      33      }
    0x0000000000400631 <sigusr1_handler+17>:     5d      pop    %rbp
 => 0x0000000000400632 <sigusr1_handler+18>:     c3      retq
 1: $eflags = [ PF ZF TF IF ]
 (gdb)
 <signal handler called>
 => 0x0000003b36a358f0 <__restore_rt+0>: 48 c7 c0 0f 00 00 00    mov    $0xf,%rax
 1: $eflags = [ PF ZF TF IF ]
 (gdb) si
 <signal handler called>
 => 0x0000003b36a358f7 <__restore_rt+7>: 0f 05   syscall
 1: $eflags = [ PF ZF TF IF ]
 (gdb)
 main () at si-handler.c:50
 50        global = 0; /* set break here */
 => 0x000000000040066b <main+9>: c7 05 cb 09 20 00 00 00 00 00   movl   $0x0,0x2009cb(%rip)        # 0x601040 <global>
 1: $eflags = [ PF ZF IF ]
 (gdb)

The bug doesn't happen if we instead PTRACE_CONTINUE into the signal
handler -- e.g., set a breakpoint in the handler, queue a signal, and
"continue".

gdb/testsuite/
2014-10-28  Pedro Alves  <palves@redhat.com>

	PR gdb/17511
	* gdb.base/sigstep.c (handler): Add a few more writes to 'done'.
	* gdb.base/sigstep.exp (other_handler_location): New global.
	(advance): Support stepping into the signal handler, and running
	commands while in the handler.
	(in_handler_map): New global.
	(top level): In the advance test, add combinations for getting
	into the handler with stepping commands, and for running commands
	in the handler.  Add comment descripting the advancei tests.
2014-10-28 15:51:30 +00:00
Pedro Alves 1df4399f27 gdb.base/sigstep.exp: cleanup and make it easier to extend
Hacking on sigstep.exp, I found it harder to understand and extend
than ideal.

 - GDB is currently not restarted between the different
   tests/combinations in the file, and some parts of the tests' setup
   are done on the top level, and shared between tests.  It's not
   trivial to understand which breakpoints each test procedure expects
   to be set or not set.  And it's not trivial to disable parts of the
   test if you want quickly try out just a subset of the tests
   (running the whole file takes a bit).

 - Because GDB is currently not restarted between tests, if some test
   triggers a ptrace/kernel bug, the following tests may end up with
   cascading fails.  That makes it hard to add a test to cover a
   kernel bug that isn't fixed yet, with a xfail/kfail.  E.g,. note
   how with kernels with bug gdb/8744 (stepi over sigreturn syscall
   exits program) the test program exits, and nothing restarts it
   afterwards...

 - The manual test message prefix management gets a bit in the way.
   Nowadays, we have with_test_prefix which makes it simpler.

 - 'i' is used as parameter name in the various procedures, meaning
   'the command the test', which isn't as obvious as it could.

This commit addresses all that.

gdb/testsuite/
2014-10-28  Pedro Alves  <palves@redhat.com>

	* gdb.base/sigstep.exp: Use build_executable instead of
	prepare_for_testing.
	(top level): Move code that starts GDB, runs to main and creates a
	display to ...
	(restart): ... this new procedure.
	(top level): Move backtrace from signal handler test to ...
	(validate_backtrace): ... this new procedure.
	(advance, advancei): Rename parameter from 'i' to 'cmd'.  Use
	with_test_prefix.  Always restart GDB.
	(skip_to_handler): Rename parameter from 'i' to 'cmd'.  Use
	with_test_prefix.  Always restart GDB.  No need to delete
	breakpoints after the test.
	(test_skip_handler): Remove prefix parameter.
	(skip_over_handler, breakpoint_to_handler)
	(breakpoint_to_handler_entry, breakpoint_over_handler): Rename
	parameter from 'i' to 'cmd'.  Use with_test_prefix.  Always
	restart GDB.  No need to delete breakpoints after the test.
	(top level): Use foreach to call the test procedures with
	different commands.
2014-10-28 15:34:00 +00:00
Pedro Alves a5b6e449e3 update bug numbers (GNATS -> Bugzilla) in a few signal related tests
This makes it easier to find the bugs in Bugzilla.

gdb/testsuite/
2014-10-28  Pedro Alves  <palves@redhat.com>

	* gdb.base/sigaltstack.exp: Update to use Bugzilla bug numbers
	instead of GNATS numbers.
	* gdb.base/sigbpt.exp: Likewise.
	* gdb.base/siginfo.exp: Likewise.
	* gdb.base/sigstep.exp: Likewise.
2014-10-28 15:31:55 +00:00
Pedro Alves 7d1a114c44 Workaround remote targets that report an empty list to qfThreadInfo
In https://sourceware.org/ml/gdb-patches/2014-10/msg00652.html, Sandra
shows a target that was broken by the recent update_thread_list
optimization:

 (gdb) target remote qa8-centos32-cs:10514
 ...
 (gdb) continue
 Continuing.
 Cannot execute this command without a live selected thread.
 (gdb)

The error means that the current thread is in "exited" state when the
continue command is processed.  The root of the problem was found
here:

 > Sending packet: $Hg0#df...Packet received:
 ...
 > Sending packet: $?#3f...Packet received: S00
 > Sending packet: $qfThreadInfo#bb...Packet received: l
 > Sending packet: $Hc-1#09...Packet received:
 > Sending packet: $qC#b4...Packet received: unset

This target doesn't really support threads (no thread indication in
stop reply packets; no support for qC), but then supports
qfThreadInfo, and returns an empty thread list to GDB.

See https://sourceware.org/ml/gdb-patches/2014-10/msg00665.html for
why the target does that.

As remote_update_thread_list deletes threads from GDB's list that are
not found in the thread list that the target reports, the result is
that GDB deletes the "fake" main thread that GDB added itself.  (As
that thread is currently selected, it is marked "exited" instead of
being deleted straight away.)

This commit avoids deleting the main thread in this scenario.

gdb/
2014-10-27  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_thread_alive): New, factored out from ...
	(remote_thread_alive): ... this.
	(remote_update_thread_list): Bail out before deleting threads if
	the target returned an empty list, and, the current thread has a
	magic/fake ptid.
2014-10-28 11:35:10 +00:00
Pedro Alves e5f8a7cc2d stepi/nexti: skip signal handler if "handle nostop" signal arrives
I noticed that "si" behaves differently when a "handle nostop" signal
arrives while the step is in progress, depending on whether the
program was stopped at a breakpoint when "si" was entered.
Specifically, in case GDB needs to step off a breakpoint, the handler
is skipped and the program stops in the next "mainline" instruction.
Otherwise, the "si" stops in the first instruction of the signal
handler.

I was surprised the testsuite doesn't catch this difference.  Turns
out gdb.base/sigstep.exp covers a bunch of cases related to stepping
and signal handlers, but does not test stepi nor nexti, only
step/next/continue.

My first reaction was that stopping in the signal handler was the
correct thing to do, as it's where the next user-visible instruction
that is executed is.  I considered then "nexti" -- a signal handler
could be reasonably considered a subroutine call to step over, it'd
seem intuitive to me that "nexti" would skip it.

But then, I realized that signals that arrive while a plain/line
"step" is in progress _also_ have their handler skipped.  A user might
well be excused for being confused by this, given:

  (gdb) help step
  Step program until it reaches a different source line.

And the signal handler's sources will be in different source lines,
after all.

I think that having to explain that "stepi" steps into handlers, (and
that "nexti" wouldn't according to my reasoning above), while "step"
does not, is a sign of an awkward interface.

E.g., if a user truly is interested in stepping into signal handlers,
then it's odd that she has to either force the signal to "handle
stop", or recall to do "stepi" whenever such a signal might be
delivered.  For that use case, it'd seem nicer to me if "step" also
stepped into handlers.

This suggests to me that we either need a global "step-into-handlers"
setting, or perhaps better, make "handle pass/nopass stop/nostop
print/noprint" have have an additional axis - "handle
stepinto/nostepinto", so that the user could configure whether
handlers for specific signals should be stepped into.

In any case, I think it's simpler (and thus better) for all step
commands to behave the same.  This commit thus makes "si/ni" skip
handlers for "handle nostop" signals that arrive while the command was
already in progress, like step/next do.

To be clear, nothing changes if the program was stopped for a signal,
and the user enters a stepping command _then_ -- GDB still steps into
the handler.  The change concerns signals that don't cause a stop and
that arrive while the step is in progress.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-27  Pedro Alves  <palves@redhat.com>

	* infrun.c (handle_signal_stop): Also skip handlers when a random
	signal arrives while handling a "stepi" or a "nexti".  Set the
	thread's 'step_after_step_resume_breakpoint' flag.

gdb/doc/
2014-10-27  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Continuing and Stepping): Add cross reference to
	info on stepping and signal handlers.
	(Signals): Explain stepping and signal handlers.  Add context
	index entry, and cross references.

gdb/testsuite/
2014-10-27  Pedro Alves  <palves@redhat.com>

	* gdb.base/sigstep.c (dummy): New global.
	(main): Issue a couple writes to the new global.
	* gdb.base/sigstep.exp (get_next_pc, test_skip_handler): New
	procedures.
	(skip_over_handler): Use test_skip_handler.
	(top level): Call skip_over_handler for stepi and nexti too.
	(breakpoint_over_handler): Use test_skip_handler.
	(top level): Call breakpoint_over_handler for stepi and nexti too.
2014-10-27 20:26:12 +00:00
Yao Qi 763905a3ad Fix trace file fails on powerpc64
I see the following fails on powerpc64-linux,

(gdb) target tfile tfile-basic.tf^M
warning: Uploaded tracepoint 1 has no source location, using raw address^M
Tracepoint 1 at 0x10012358^M
Created tracepoint 1 for target's tracepoint 1 at 0x10012358.^M
(gdb) PASS: gdb.trace/tfile.exp: target tfile tfile-basic.tf
info trace^M
Num     Type           Disp Enb Address            What^M
1       tracepoint     keep y   0x0000000010012358 <write_basic_trace_file>^M
        installed on target^M
(gdb) FAIL: gdb.trace/tfile.exp: info tracepoints on trace file

-target-select tfile tfile-basic.tf^M
=thread-group-started,id="i1",pid="1"^M
=thread-created,id="1",group-id="i1"^M
&"warning: Uploaded tracepoint 1 has no source location, using raw address\n"^M
=breakpoint-created,bkpt={number="1",type="tracepoint",disp="keep",enabled="y",
addr="0x0000000010012358",at="<write_basic_trace_file>",thread-groups=["i1"],
times="0",installed="y",original-location="*0x10012358"}^M
~"Created tracepoint 1 for target's tracepoint 1 at 0x10012358.\n"^M
^connected^M
(gdb) ^M
FAIL: gdb.trace/mi-traceframe-changed.exp: tfile: select trace file

These fails are caused by writing function descriptor address into trace
file instead of function address.  This patch is to teach tfile.c to
write function address on powerpc64 target.  With this patch applied,
fails in tfile.exp and mi-traceframe-changed.exp are fixed.  Is it
OK?

gdb/testsuite:

2014-10-27  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/tfile.c (adjust_function_address)
	[__powerpc64__ && _CALL_ELF != 2]: Get function address from
	function descriptor.
2014-10-27 20:09:19 +08:00
Luis Machado 71e396f920 Fix ARM machine state testcase failures
When running GDB's reverse debugging testsuite against a few ARM
multilibs, i noticed failures in the machinestate* testcases.

Further investigation showed that push and pop instruction encodings
A1 and A2 were not being handled properly, thus we missed saving
important contents from registers and memory. When going backwards,
such contents were not restored and thus we ended up with a corrupted
state that did not correspond to the real values we had at a
particular point in time.

Attached is a patch that fixes around 36 failures for both
gdb.reverse/machinestate.exp and
gdb.reverse/machinestate-precsave.exp testcases, making them fully
pass. This is for both armv7 and armv4. I still see failures for
armv4 thumb though, so it needs a bit more investigation.

I see no regressions due to this patch for armv7, armv7 thumb, armv4
and armv4 thumb.

gdb/ChangeLog:

	* arm-tdep.c (INSN_S_L_BIT_NUM): Document.
	(arm_record_ld_st_imm_offset): Reimplement to cover all
	load/store cases for ARM opcode 010.
	(arm_record_ld_st_multiple): Reimplement to cover all
	load/store cases for ARM opcode 100.
2014-10-27 08:57:58 -02:00
Doug Evans 3aee438bbb symtab.c (lookup_symbol_aux_local): Fix typo in comment.
gdb/ChangeLog:

	* symtab.c (lookup_symbol_aux_local): Fix typo in comment.
2014-10-26 16:46:52 -07:00
Doug Evans f88cb4b683 Rename parameter "kind" to "block_index" in quick lookup functions.
gdb/ChangeLog:

	* symfile.h (struct quick_symbol_functions) <lookup_symbol>: Rename
	parameter "kind" to "block_index".
	* symtab.c (error_in_psymtab_expansion): Rename parameter "kind" to
	"block_index".
	(lookup_symbol_aux_quick, basic_lookup_transparent_type_quick): Ditto.
2014-10-26 13:53:58 -07:00
Doug Evans a023a30fb4 * block.h (ALL_BLOCK_SYMBOLS): Fix comment.
gdb/ChangeLog:

	* block.h (ALL_BLOCK_SYMBOLS): Fix comment.
2014-10-26 12:26:20 -07:00
Doug Evans 4c35218eab block.c (allocate_block): Use OBSTACK_ZALLOC instead of obstack_alloc.
gdb/ChangeLog:

	* block.c (allocate_block): Use OBSTACK_ZALLOC instead of
	obstack_alloc.
2014-10-26 11:36:59 -07:00
Doug Evans f08e8df3ab Move block_found decl to symtab.h.
gdb/ChangeLog:

	* parser-defs.h (block_found): Move decl from here ...
	* symtab.h (block_found): ... to here.
2014-10-26 10:42:26 -07:00
Doug Evans cf901d3bba Clean up some function comments in symtab.[ch].
gdb/ChangeLog:

	* symtab.h (struct field_of_this_result): Fix typo in comment.
	(lookup_symbol_in_language): Move function comment here.
	(lookup_symbol): Improve function comment.
	(basic_lookup_symbol_nonlocal): Ditto.
	(lookup_symbol_static, lookup_symbol_global): Ditto.
	(lookup_symbol_aux_block): Ditto.
	(lookup_language_this): Add function comment.
	(lookup_static_symbol_aux): Explicitly mark as extern.  Improve
	function comment.
	(lookup_block_symbol): Improve function comment.
	(lookup_struct): Fix capitalization in function comment.
	(lookup_transparent_type): Add function comment.
	(lookup_global_symbol_from_objfile): Explicitly mark as extern.
	Improve function comment.
	(lookup_objfile_from_block): Add function comment.
	* symtab.c (lookup_symbol_in_language): Update function comment.
	(lookup_symbol, lookup_language_this): Ditto.
	(lookup_static_symbol_aux, lookup_objfile_from_block): Ditto.
	(lookup_symbol_aux_block, lookup_global_symbol_from_objfile): Ditto.
	(basic_lookup_symbol_nonlocal): Ditto.
	(lookup_symbol_static, lookup_symbol_global): Ditto.
	(lookup_transparent_type, lookup_block_symbol): Ditto.
2014-10-26 09:35:53 -07:00
Doug Evans ff6c39cf9c symtab.c: forward decl cleanup
gdb/ChangeLog:

	* symtab.c (types_info): Delete forward decl.
	(functions_info, variables_info, sources_info): Ditto.
	(_initialize_symtab): Rewrite forward decl to use
	initialize_file_ftype.
2014-10-25 22:22:47 -07:00
Doug Evans ec201f0cd1 symtab.c (lookup_symbol_aux_quick): Set block_found upon success.
gdb/ChangeLog:

	* symtab.c (lookup_symbol_aux_quick): Set block_found upon success.
2014-10-25 22:07:54 -07:00
Doug Evans ca040673e0 Remove second (nested) copy of local var child_die.
gdb/ChangeLog:

	* dwarf2read.c (process_structure_scope): Remove second (nested) copy
	of local var child_die.
2014-10-25 21:46:00 -07:00
Don Breazeal 6f259a235d Follow-fork message printing improvements
This commit modifies the code that prints attach and detach messages
related to following fork and vfork.  The changes include using
target_terminal_ours_for_output instead of target_terminal_ours,
printing "vfork" instead of "fork" for all vfork-related messages,
and using _() for the format strings of all of the messages.

We also add a "detach" message for when a fork parent is detached.
Previously in this case the only message was notification of attaching
to the child.  We still do not print any messages when following the
parent and detaching the child (the default).  The rationale for this
is that from the user's perspective the new child was never attached.

Note that all of these messages are only printed when 'verbose' is set
or when debugging is turned on.

The tests gdb.base/foll-fork.exp and gdb.base/foll-vfork.exp were
modified to check for the new message.

Tested on x64 Ubuntu Lucid, native only.

gdb/ChangeLog:

	* infrun.c (follow_fork_inferior): Update fork message printing
	to use target_terminal_ours_for_output instead of
	target_terminal_ours, to use _() for all format strings, to print
	"vfork" instead of "fork" for vforks, and to add a detach message.
	(handle_vfork_child_exec_or_exit): Update message printing to use
	target_terminal_ours_for_output instead of target_terminal_ours, to
	use _() for all format strings, and to fix some formatting.

gdb/testsuite/ChangeLog:

	* gdb.base/foll-fork.exp (test_follow_fork,
	catch_fork_child_follow): Check for updated fork messages emitted
	from infrun.c.
	* gdb.base/foll-vfork.exp (vfork_parent_follow_through_step,
	vfork_parent_follow_to_bp, vfork_and_exec_child_follow_to_main_bp,
	vfork_and_exec_child_follow_through_step): Check for updated vfork
	messages emitted from infrun.c.
2014-10-24 11:36:06 -07:00
Pedro Alves 09dd9a6907 Remove Vax Ultrix and VAX BSD support
Built and tested on x86_64 Fedora 20, with --enable-targets=all.

gdb/
2014-10-24  Pedro Alves  <palves@redhat.com>

	* Makefile.in (ALLDEPFILES): Remove vax-nat.c.
	* NEWS (Removed targets): Add VAX BSD and VAX Ultrix.
	* config/vax/vax.mh: Delete.
	* configure.host: Move vax-*-bsd* and vax-*-ultrix* to the
	obsolete configurations section.
	* configure.tgt (vax-*-*): Don't mention 4.2BSD nor Ultrix.
	* vax-nat.c: Delete file.

gdb/testsuite/
2014-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.base/corefile.exp: Remove references to ultrix.
	* gdb.base/interrupt.exp: Likewise.
	* gdb.base/whatis.exp: Likewise.
	* gdb.gdb/selftest.exp: Likewise.
	* gdb.threads/manythreads.exp: Likewise.
	* gdb.threads/print-threads.exp: Likewise.
	* gdb.threads/pthreads.exp:: Likewise.
	* gdb.threads/schedlock.exp: Likewise.
2014-10-24 17:56:56 +01:00
Pedro Alves 5ab806deff NEWS: Clarify removed targets
gdb/
2014-10-24  Pedro Alves  <palves@redhat.com>

	* NEWS (Removed targets): Add OS/arch column.
2014-10-24 17:56:29 +01:00
Siva Chandra 3433cfa51f Guard a call to TYPE_TARGET_TYPE in gnuv3_pass_by_reference.
gdb/ChangeLog:

	* gnu-v3-abi.c (gnuv3_pass_by_reference): Call TYPE_TARGET_TYPE
	on the arg type of a constructor only if it is of reference type.

gdb/testsuite/ChangeLog:

	* gdb.cp/non-trivial-retval.cc: Add a test case.
	* gdb.cp/non-trivial-retval.exp: Add a test.
2014-10-24 05:45:06 -07:00
Sandra Loosemore 96ba42336f Refactoring/cleanup of nios2 opcodes and assembler code.
2014-10-23  Sandra Loosemore  <sandra@codesourcery.com>

	include/opcode/
	* nios2.h (enum iw_format_type): New.
	(struct nios2_opcode): Update comments.  Add size and format fields.
	(NIOS2_INSN_OPTARG): New.
	(REG_NORMAL, REG_CONTROL, REG_COPROCESSOR): New.
	(struct nios2_reg): Add regtype field.
	(GET_INSN_FIELD, SET_INSN_FIELD): Delete.
	(IW_A_LSB, IW_A_MSB, IW_A_SZ, IW_A_MASK): Delete.
	(IW_B_LSB, IW_B_MSB, IW_B_SZ, IW_B_MASK): Delete.
	(IW_C_LSB, IW_C_MSB, IW_C_SZ, IW_C_MASK): Delete.
	(IW_IMM16_LSB, IW_IMM16_MSB, IW_IMM16_SZ, IW_IMM16_MASK): Delete.
	(IW_IMM26_LSB, IW_IMM26_MSB, IW_IMM26_SZ, IW_IMM26_MASK): Delete.
	(IW_OP_LSB, IW_OP_MSB, IW_OP_SZ, IW_OP_MASK): Delete.
	(IW_OPX_LSB, IW_OPX_MSB, IW_OPX_SZ, IW_OPX_MASK): Delete.
	(IW_SHIFT_IMM5_LSB, IW_SHIFT_IMM5_MSB): Delete.
	(IW_SHIFT_IMM5_SZ, IW_SHIFT_IMM5_MASK): Delete.
	(IW_CONTROL_REGNUM_LSB, IW_CONTROL_REGNUM_MSB): Delete.
	(IW_CONTROL_REGNUM_SZ, IW_CONTROL_REGNUM_MASK): Delete.
	(OP_MASK_OP, OP_SH_OP): Delete.
	(OP_MASK_IOP, OP_SH_IOP): Delete.
	(OP_MASK_IRD, OP_SH_IRD): Delete.
	(OP_MASK_IRT, OP_SH_IRT): Delete.
	(OP_MASK_IRS, OP_SH_IRS): Delete.
	(OP_MASK_ROP, OP_SH_ROP): Delete.
	(OP_MASK_RRD, OP_SH_RRD): Delete.
	(OP_MASK_RRT, OP_SH_RRT): Delete.
	(OP_MASK_RRS, OP_SH_RRS): Delete.
	(OP_MASK_JOP, OP_SH_JOP): Delete.
	(OP_MASK_IMM26, OP_SH_IMM26): Delete.
	(OP_MASK_RCTL, OP_SH_RCTL): Delete.
	(OP_MASK_IMM5, OP_SH_IMM5): Delete.
	(OP_MASK_CACHE_OPX, OP_SH_CACHE_OPX): Delete.
	(OP_MASK_CACHE_RRS, OP_SH_CACHE_RRS): Delete.
	(OP_MASK_CUSTOM_A, OP_SH_CUSTOM_A): Delete.
	(OP_MASK_CUSTOM_B, OP_SH_CUSTOM_B): Delete.
	(OP_MASK_CUSTOM_C, OP_SH_CUSTOM_C): Delete.
	(OP_MASK_CUSTOM_N, OP_SH_CUSTOM_N): Delete.
	(OP_<insn>, OPX_<insn>, OP_MATCH_<insn>, OPX_MATCH_<insn>): Delete.
	(OP_MASK_<insn>, OP_MASK): Delete.
	(GET_IW_A, GET_IW_B, GET_IW_C, GET_IW_CONTROL_REGNUM): Delete.
	(GET_IW_IMM16, GET_IW_IMM26, GET_IW_OP, GET_IW_OPX): Delete.
	Include nios2r1.h to define new instruction opcode constants
	and accessors.
	(nios2_builtin_opcodes): Rename to nios2_r1_opcodes.
	(bfd_nios2_num_builtin_opcodes): Rename to nios2_num_r1_opcodes.
	(bfd_nios2_num_opcodes): Rename to nios2_num_opcodes.
	(NUMOPCODES, NUMREGISTERS): Delete.
	* nios2r1.h: New file.

	opcodes/
	* nios2-opc.c (nios2_builtin_regs): Add regtype field initializers.
	(nios2_builtin_opcodes): Rename to nios2_r1_opcodes.  Use new
	MATCH_R1_<insn> and MASK_R1_<insn> macros in initializers.  Add
	size and format initializers.  Merge 'b' arguments into 'j'.
	(NIOS2_NUM_OPCODES): Adjust definition.
	(bfd_nios2_num_builtin_opcodes): Rename to nios2_num_r1_opcodes.
	(nios2_opcodes): Adjust.
	(bfd_nios2_num_opcodes): Rename to nios2_num_opcodes.
	* nios2-dis.c (INSNLEN): Update comment.
	(nios2_hash_init, nios2_hash): Delete.
	(OPCODE_HASH_SIZE): New.
	(nios2_r1_extract_opcode): New.
	(nios2_disassembler_state): New.
	(nios2_r1_disassembler_state): New.
	(nios2_init_opcode_hash): Add state parameter.  Adjust to use it.
	(nios2_find_opcode_hash): Use state object.
	(bad_opcode): New.
	(nios2_print_insn_arg): Add op parameter.  Use it to access
	format.  Remove 'b' case.
	(nios2_disassemble): Remove special case for nop.  Remove
	hard-coded instruction size.

	gas/
	* config/tc-nios2.c (nios2_insn_infoS): Add constant_bits field.
	(nios2_arg_infoS, nios2_arg_hash, nios2_arg_lookup): Delete.
	(nios2_control_register_arg_p): Delete.
	(nios2_coproc_reg): Delete.
	(nios2_relax_frag): Remove hard-coded instruction size.
	(md_convert_frag): Use new insn accessor macros.
	(nios2_diagnose_overflow): Remove hard-coded instruction size.
	(md_apply_fix): Likewise.
	(bad_opcode): New.
	(nios2_parse_reg): New.
	(nios2_assemble_expression): Remove prev_reloc parameter.  Adjust
	uses and callers.
	(nios2_assemble_arg_c): New.
	(nios2_assemble_arg_d): New.
	(nios2_assemble_arg_s): New.
	(nios2_assemble_arg_t): New.
	(nios2_assemble_arg_i): New.
	(nios2_assemble_arg_u): New.
	(nios2_assemble_arg_o): New.
	(nios2_assemble_arg_j): New.
	(nios2_assemble_arg_l): New.
	(nios2_assemble_arg_m): New.
	(nios2_assemble_args): New.
	(nios2_assemble_args_dst): Delete.
	(nios2_assemble_args_tsi): Delete.
	(nios2_assemble_args_tsu): Delete.
	(nios2_assemble_args_sto): Delete.
	(nios2_assemble_args_o): Delete.
	(nios2_assemble_args_is): Delete.
	(nios2_assemble_args_m): Delete.
	(nios2_assemble_args_s): Delete.
	(nios2_assemble_args_tis): Delete.
	(nios2_assemble_args_dc): Delete.
	(nios2_assemble_args_cs): Delete.
	(nios2_assemble_args_ds): Delete.
	(nios2_assemble_args_ldst): Delete.
	(nios2_assemble_args_none): Delete.
	(nios2_assemble_args_dsj): Delete.
	(nios2_assemble_args_d): Delete.
	(nios2_assemble_args_b): Delete.
	(nios2_arg_info_structs): Delete.
	(NIOS2_NUM_ARGS): Delete.
	(nios2_consume_arg): Remove insn parameter.  Use new macros.
	Don't check register arguments here.  Remove 'b' case.
	(nios2_consume_separator): Move check for missing separators to...
	(nios2_parse_args): ...here.  Remove special case for optional
	arguments.
	(output_insn): Avoid using hard-coded insn size.
	(output_ubranch): Likewise.
	(output_cbranch): Likewise.
	(output_call): Use new macros.
	(output_addi): Likewise.
	(output_ori): Likewise.
	(output_xori): Likewise.
	(output_movia): Likewise.
	(md_begin): Remove nios2_arg_info_structs initialization.
	(md_assemble): Initialize constant_bits field.  Use
	nios2_parse_args instead of looking up parse function in hash table.

	gdb/
	* nios2-tdep.c (nios2_analyze_prologue): Use new instruction field
	accessors and constants from nios2 opcodes update.
	(nios2_get_next_pc): Likewise.
2014-10-23 09:54:15 -07:00
Simon Marchi fab3a15dfb Small fixes to the Python API doc
First:
"Breakpoint.delete" is missing parenthesis.

Second:
Someone on IRC asked, how come there is no disable() method in the
Breakpoint object.  It turns out you have to do "bp.enabled = False".
Since every normal person would probably search for "disable" in that page
if their intent is to disable a python breakpoint, I thought it would be
useful if the description contained "disable" so it would be easy to find.
The result might seem a bit silly and redundant, so I am open to
suggestions.

gdb/doc/ChangeLog:

	* python.texi (Breakpoints In Python): Add parenthesis after
	Breakpoint.delete.  Clarify Breakpoint.enabled description so
	that it	contains "disable".
2014-10-20 13:29:36 -04:00
Yao Qi 092f880b8e Rename py-objfile-script-gdb.py.in to py-objfile-script-gdb.py
Patch <https://sourceware.org/ml/gdb-patches/2011-07/msg00225.html> was
to fix the problem that py-objfile-script-gdb.py is removed after an
in-tree build and test.  As a result of the previous patch (we don't
remove files copied to host any more), this patch is no longer needed.
This patch is to revert it logically.

gdb/testsuite:

2014-10-20  Yao Qi  <yao@codesourcery.com>

	* gdb.python/py-objfile-script-gdb.py.in: Rename it to ...
	* gdb.python/py-objfile-script-gdb.py: New file.
	* gdb.python/py-objfile-script.exp: Update reference to
	py-objfile-script-gdb.py.in.  Use gdb_remote_donwload instead
	of remote_download.  Remove the dest file.
2014-10-20 13:34:33 +08:00
Yao Qi acbdb7f355 Don't remove files copied to host
Nowadays, if we do in-tree build and run tests sequentially, some source
files are removed, due to the following pattern:

set pi_txt [gdb_remote_download host ${srcdir}/${subdir}/pi.txt]

remote_exec host "rm -f $pi_txt"

If testing is run sequentially, file ${srcdir}/${subdir}/pi.txt is
copied to ${objdir}/${subdir}/pi.txt.  However, ${objdir} is ${srcdir}
in the in-tree build/test, so the file is coped to itself, as a nop.
As a result, the file in source is removed at the end of test.

This patch fixes this problem by not removing files copied to host in
each test.  This patch also addresses the question we've had that why
don't we keep files copied to host because they are needed to reproduce
certain fails.

gdb/testsuite:

2014-10-20  Yao Qi  <yao@codesourcery.com>

	* gdb.base/checkpoint.exp: Don't remove file copied on host.
	* gdb.base/step-line.exp: Likewise.
	* gdb.dwarf2/dw2-anonymous-func.exp: Likewise.
	* gdb.dwarf2/dw2-basic.exp: Likewise.
	* gdb.dwarf2/dw2-compressed.exp: Likewise.
	* gdb.dwarf2/dw2-filename.exp: Likewise.
	* gdb.dwarf2/dw2-intercu.exp: Likewise.
	* gdb.dwarf2/dw2-intermix.exp: Likewise.
	* gdb.dwarf2/dw2-producer.exp: Likewise.
	* gdb.dwarf2/mac-fileno.exp: Likewise.
	* gdb.python/py-frame-args.exp: Likewise.
	* gdb.python/py-framefilter.exp: Likewise.
	* gdb.python/py-mi.exp: Likewise.
	* gdb.python/py-objfile-script.exp: Likewise
	* gdb.python/py-pp-integral.exp: Likewise.
	* gdb.python/py-pp-re-notag.exp: Likewise.
	* gdb.python/py-prettyprint.exp: Likewise.
	* gdb.python/py-section-script.exp: Likewise.
	* gdb.python/py-typeprint.exp: Likewise.
	* gdb.python/py-xmethods.exp: Likewise.
	* gdb.stabs/weird.exp: Likewise.
	* gdb.xml/tdesc-regs.exp: Likewise.
2014-10-20 13:34:28 +08:00
Doug Evans 28153fd321 Fix some comments to say minus_one_ptid instead of PID == -1.
gdb/ChangeLog:

	* gdbthread.h (set_running): Fix comment.
	(set_executing, finish_thread_state): Fix comment.
2014-10-19 13:36:54 -07:00
Doug Evans fc9b8e475d linux-nat.c (linux_nat_wait_1): Make local prev_mask non-static.
gdb/ChangeLog:

	linux-nat.c (linux_nat_wait_1): Make local prev_mask non-static.
2014-10-18 21:24:47 -07:00
Kwok Cheung Yeung bd286a290b Fix the gdb.dwarf2/dw2-dir-file-name.exp test on MIPS
This patch fixes the failures that occur with the
gdb.dwarf2/dw2-dir-file-name.exp test on 64-bit MIPS and compressed
MIPS ISAs (i.e. MIPS16 and microMIPS).

The failures on 64-bit occur because the generated DWARF address
information is always 32-bit, which causes the upper 32-bits of
addresses to be truncated and causes breakpoints to be set on the
wrong address if any of the upper 32-bits are non-zero.  I suspect
that other 64-bit architectures get away with it because they
place all their instructions at a VMA lower than 2^32 by default.
This patch causes 64-bit addresses to be generated if a 64-bit
target is detected.

The failures on MIPS16 and microMIPS occur because the breakpoint
address needs to have the LSB set to 1 (used to indicate that the
code is compressed). However, the function name is interpreted as
a data label, causing GDB to set breakpoints at even addresses.
This is fixed by explicitly adding a '.insn' directive (see
https://sourceware.org/binutils/docs/as/MIPS-insn.html) after the
label on MIPS only.

gdb/testsuite/

2014-10-18  Kwok Cheung Yeung  <kcy@codesourcery.com>

	* gdb.dwarf2/dw2-dir-file-name.exp (addr_len): New.
	(out_cu): Use addr_len for the size of addresses.
	(out_line): Likewise.  Size DW_LNE_set_address instruction
	according to addr_len.
	* gdb.dwarf2/dw2-dir-file-name.c (START_INSNS): New.
	(FUNC): Add START_INSNS to definition.
2014-10-18 21:53:15 +01:00
Yao Qi 673dc4a054 Skip testing argv[0] on target argv[0] isn't available
I see the following two fails on arm-none-eabi target, because argv[0]
isn't available.

print argv[0]^M
$1 = 0x1f78 "/dev/null"^M
(gdb) FAIL: gdb.base/argv0-symlink.exp: kept file symbolic link name

print argv[0]^M
$1 = 0x1f78 "/dev/null"^M
(gdb) FAIL: gdb.base/argv0-symlink.exp: kept directory symbolic link name

My first thought is to check [target_info exists noargs], and skip the
test if it returns true.  However, noargs is set in gdbserver board
files, so argv0-symlink.exp will be skipped on gdbserver board file.
The change is too aggressive.

When the program is running with gdbserver, argv[1] to argv[N] aren't
available, but argv[0] is.  Fortunately, argv0-symlink.exp only
requires argv[0].  argv0-symlink.exp can be run with gdbserver board
file, as what we do now.

What we need to check is whether argv[0] is available, so I add a new
proc gdb_has_argv0 to do so by starting a program, and check
argc/argv[0] to see whether argv[0] is available.

Dan fixed the similar problem by checking noargs, which is too strong.
https://sourceware.org/ml/gdb-patches/2010-02/msg00398.html as a
result, the test is skipped on gdbserver.  This patch fixed it too.

gdb/testsuite:

2014-10-18  Yao Qi  <yao@codesourcery.com>

	* gdb.base/argv0-symlink.exp: Check argv[0] value if
	gdb_has_argv0 return true.
	* gdb.guile/scm-value.exp (test_value_in_inferior): Don't
	check [target_info exists noargs], check [gdb_has_argv0]
	instead.
	* gdb.python/py-value.exp (test_value_in_inferior): Likewise.
	* lib/gdb.exp (gdb_has_argv0, gdb_has_argv0_1): New
	procedures.
2014-10-18 20:58:06 +08:00
Doug Evans 4ffbba72f3 New python event "clear_objfiles".
If one is watching new_objfile events in python, it helps to know
when the list of objfiles is cleared.  This patch adds a new
clear_objfiles event to support this.

This patch is all just cut-n-paste-n-tweak derived from
the new_objfiles event.

gdb/ChangeLog:

	* NEWS: Mention new event gdb.clear_objfiles.
	* python/py-event.h (emit_clear_objfiles_event): Clear
	* python/py-events.h (events_object): New member clear_objfiles.
	* python/py-evts.c (gdbpy_initialize_py_events): Add clear_objfiles
	event.
	* python/py-inferior.c (python_new_objfile): If objfile is NULL,
	emit clear_objfiles event.
	* python/py-newobjfileevent.c (create_clear_objfiles_event_object): New
	function.
	(emit_clear_objfiles_event): New function.
	(clear_objfiles): New event.
	* python/python-internal.h (gdbpy_initialize_clear_objfiles_event):
	Declare.
	* python/python.c (_initialize_python): Call
	gdbpy_initialize_clear_objfiles_event.

gdb/doc/ChangeLog:

	* python.texi (Events In Python): Document clear_objfiles event.

gdb/testsuite/ChangeLog:

	* gdb.python/py-events.exp: Update expected output for clear_objfiles
	event.
	* gdb.python/py-events.py: Add clear_objfiles event.
2014-10-17 11:12:17 -07:00
Doug Evans d096d8c11e Add gdb.Objfile.progspace attribute.
gdb/ChangeLog:

	* NEWS: Mention new gdb.Objfile.progspace attribute.
	* python/py-objfile.c (objfpy_get_progspace): New function.
	(objfile_getset): New entry for "progspace".

gdb/doc/ChangeLog:

	* python.texi (Objfiles In Python): Document new progspace attribute.

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Test progspace attribute.
2014-10-17 10:57:26 -07:00
Luis Machado a80db0157c Fix mingw32 failures due to incorrect directory separator in pattern
Some testcases, mostly gdb.reverse ones, assume the presence of a
'/' directory separator before the source file name. This is
incorrect for mingw32 hosts, generating false failures for those
tests.

I attempted to catch most of the occurrences of the pattern
".*/$srcfile" and replaced them with ".*$srcfile". The latter
is used elsewhere in the testsuite. The resulting patch is attached.

I also see other occurrences of the same assumption throughout the
testsuite, but usually they are arguments for function calls and i
seem to recall either the test harness or GDB deals with those
paths properly.

gdb/testsuite:

2014-10-17  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.guile/scm-breakpoint.exp: Do not assume any
	directory separators when matching source file paths.
	* gdb.python/py-breakpoint.exp: Likewise.
	* gdb.reverse/break-precsave.exp: Likewise.
	* gdb.reverse/break-reverse.exp: Likewise.
	* gdb.reverse/consecutive-precsave.exp: Likewise.
	* gdb.reverse/finish-precsave.exp: Likewise.
	* gdb.reverse/finish-reverse-bkpt.exp: Likewise.
	* gdb.reverse/finish-reverse.exp: Likewise.
	* gdb.reverse/i386-precsave.exp: Likewise.
	* gdb.reverse/i387-env-reverse.exp: Likewise.
	* gdb.reverse/i387-stack-reverse.exp: Likewise.
	* gdb.reverse/machinestate-precsave.exp: Likewise.
	* gdb.reverse/machinestate.exp: Likewise.
	* gdb.reverse/sigall-precsave.exp: Likewise.
	* gdb.reverse/solib-precsave.exp: Likewise.
	* gdb.reverse/step-precsave.exp: Likewise.
	* gdb.reverse/until-precsave.exp: Likewise.
	* gdb.reverse/watch-precsave.exp: Likewise.
	* gdb.reverse/watch-reverse.exp: Likewise.
2014-10-17 11:28:17 -03:00
Yao Qi b22089abcb Copy xml files to host
When I run test with board file local-remote-host-native.exp, I see
the following warning,

$ make check RUNTESTFLAGS="--host_board=local-remote-host-native
--target_board=local-remote-host-native tdesc-arch.exp
HOST_DIR=/tmp/foo/"

(gdb) set tdesc filename ../../../../git/gdb/testsuite/gdb.xml/trivial.xml^M
warning: Could not open "../../../../git/gdb/testsuite/gdb.xml/trivial.xml"
(gdb) quit^

because "${srcdir}/gdb.xml/trivial.xml" doesn't exist on host.  This
patch is to copy trivial.xml to host and the warning goes away.

(gdb) set tdesc filename /tmp/foo/trivial.xml^M
(gdb) quit^

tdesc-regs.exp has the similar problem that single-reg.xml may not
exist on host at all, and it should be copied to host too.

gdb/testsuite:

2014-10-17  Yao Qi  <yao@codesourcery.com>

	* lib/gdb.exp (gdb_skip_xml_test): Copy trivial.xml to host.
	* gdb.xml/tdesc-regs.exp: Copy single-reg.xml to host.
2014-10-17 21:22:55 +08:00
Pedro Alves 6c4486e63f PR gdb/17471: Repeating a background command makes it foreground
When we repeat a command, by just pressing <ret>, the input from the
previous command is reused for the new command invocation.

When an execution command strips the "&" out of its incoming argument
string, to detect background execution, we poke a '\0' directly to the
incoming argument string.

Combine both, and a repeat of a background command loses the "&".

This is actually only visible if args other than "&" are specified
(e.g., "c 1&" or "next 2&" or "c -a&"), as in the special case of "&"
alone (e.g. "c&") doesn't actually clobber the incoming string.

Fix this by making strip_bg_char return a new string instead of poking
a hole in the input string.

New test included.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-17  Pedro Alves  <palves@redhat.com>

	PR gdb/17471
	* infcmd.c (strip_bg_char): Change prototype and rewrite.  Now
	returns a copy of the input.
	(run_command_1, continue_command, step_1, jump_command)
	(signal_command, until_command, advance_command, finish_command)
	(attach_command): Adjust and install a cleanup to free the
	stripped args.

gdb/testsuite/
2014-10-17  Pedro Alves  <palves@redhat.com>

	PR gdb/17471
	* gdb.base/bg-execution-repeat.c: New file.
	* gdb.base/bg-execution-repeat.exp: New file.
2014-10-17 13:34:16 +01:00
Pedro Alves 0ff33695ee PR gdb/17300: Input after "c -a" crashes readline/GDB
If all threads in the target were already running when the user does
"c -a", nothing puts the inferior's terminal settings in effect and
removes stdin from the event loop, which we must when running a
foreground command.  The result is that user input afterwards crashes
readline/gdb:

 (gdb) start
 Temporary breakpoint 1 at 0x4005d4: file continue-all-already-running.c, line 23.
 Starting program: continue-all-already-running

 Temporary breakpoint 1, main () at continue-all-already-running.c:23
 23        sleep (10);
 (gdb) c -a&
 Continuing.
 (gdb) c -a
 Continuing.
 p 1
 readline: readline_callback_read_char() called with no handler!
 Aborted (core dumped)
 $

Backtrace:

 Program received signal SIGABRT, Aborted.
 0x0000003b36a35877 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 56        return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
 (top-gdb) p 1
 $1 = 1
 (top-gdb) bt
 #0  0x0000003b36a35877 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #1  0x0000003b36a36f68 in __GI_abort () at abort.c:89
 #2  0x0000000000784aa9 in rl_callback_read_char () at readline/callback.c:116
 #3  0x0000000000619181 in rl_callback_read_char_wrapper (client_data=0x0) at gdb/event-top.c:167
 #4  0x0000000000619557 in stdin_event_handler (error=0, client_data=0x0) at gdb/event-top.c:373
 #5  0x000000000061814a in handle_file_event (data=...) at gdb/event-loop.c:763
 #6  0x0000000000617631 in process_event () at gdb/event-loop.c:340
 #7  0x00000000006176f8 in gdb_do_one_event () at gdb/event-loop.c:404
 #8  0x0000000000617748 in start_event_loop () at gdb/event-loop.c:429
 #9  0x00000000006191b3 in cli_command_loop (data=0x0) at gdb/event-top.c:182
 #10 0x000000000060f538 in current_interp_command_loop () at gdb/interps.c:318
 #11 0x0000000000610701 in captured_command_loop (data=0x0) at gdb/main.c:323
 #12 0x000000000060c3f5 in catch_errors (func=0x6106e6 <captured_command_loop>, func_args=0x0, errstring=0x9002c1 "", mask=RETURN_MASK_ALL)
     at gdb/exceptions.c:237
 #13 0x0000000000611bff in captured_main (data=0x7fffffffd780) at gdb/main.c:1151
 #14 0x000000000060c3f5 in catch_errors (func=0x610afe <captured_main>, func_args=0x7fffffffd780, errstring=0x9002c1 "", mask=RETURN_MASK_ALL)
     at gdb/exceptions.c:237
 #15 0x0000000000611c28 in gdb_main (args=0x7fffffffd780) at gdb/main.c:1159
 #16 0x000000000045ef97 in main (argc=5, argv=0x7fffffffd888) at gdb/gdb.c:32
 (top-gdb)

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-17  Pedro Alves  <palves@redhat.com>

	PR gdb/17300
	* infcmd.c (continue_1): If continuing all threads in the
	foreground, make sure the inferior's terminal settings are put in
	effect.

gdb/testsuite/
2014-10-17  Pedro Alves  <palves@redhat.com>

	PR gdb/17300
	* gdb.base/continue-all-already-running.c: New file.
	* gdb.base/continue-all-already-running.exp: New file.
2014-10-17 13:33:30 +01:00
Pedro Alves 6fdebc3d1c PR gdb/17472: With annotations, input while executing in the foreground crashes readline/GDB
Jan caught an intermittent GDB crash with the annota1.exp test:

 Starting program: .../gdb/testsuite/gdb.base/annota1 ^M
 [...]
 FAIL: gdb.base/annota1.exp: run until main breakpoint (timeout)
 [...]
 readline: readline_callback_read_char() called with no handler!^M
 ERROR: Process no longer exists

All we need to is to continue the inferior in the foreground, and type
a command while the inferior is running.  E.g.:

 (gdb) set annotate 2

 ▒▒pre-prompt
 (gdb)
 ▒▒prompt
 c

 ▒▒post-prompt
 Continuing.

 ▒▒starting

 ▒▒frames-invalid

 *inferior is running now*

 p 1<ret>

 readline: readline_callback_read_char() called with no handler!
 Aborted (core dumped)
 $


When we run a foreground execution command we call
target_terminal_inferior to stop GDB from processing input, and to put
the inferior's terminal settings in effect.  Then we tell readline to
hide the prompt with display_gdb_prompt, which clears readline's input
callback too.  When the target stops, we call target_terminal_ours,
which re-installs stdin in the event loop, and then we redisplay the
prompt, reinstalling the readline callbacks.

However, when annotations are in effect, the "frames-invalid"
annotation code calls target_terminal_ours after 'resume' had already
called target_terminal_inferior:

 (top-gdb) bt
 #0  0x000000000056b82f in annotate_frames_invalid () at gdb/annotate.c:219
 #1  0x000000000072e6cc in reinit_frame_cache () at gdb/frame.c:1705
 #2  0x0000000000594bb9 in registers_changed_ptid (ptid=...) at gdb/regcache.c:612
 #3  0x000000000064cca1 in target_resume (ptid=..., step=1, signal=GDB_SIGNAL_0) at gdb/target.c:2136
 #4  0x00000000005f57af in resume (step=1, sig=GDB_SIGNAL_0) at gdb/infrun.c:2263
 #5  0x00000000005f6051 in proceed (addr=18446744073709551615, siggnal=GDB_SIGNAL_DEFAULT, step=1) at gdb/infrun.c:2613

And then once we hide the prompt and remove readline's input handler
callback, we're in a bad state.  We end up with the target running
supposedly in the foreground, but with stdin still installed on the
event loop.  Any input then calls into readline, which aborts because
no rl_linefunc callback handler is installed:

 Program received signal SIGABRT, Aborted.
 0x0000003b36a35877 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 56        return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);

 (top-gdb) bt
 #0  0x0000003b36a35877 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #1  0x0000003b36a36f68 in __GI_abort () at abort.c:89
 During symbol reading, debug info gives source 9 included from file at zero line 0.
 During symbol reading, debug info gives command-line macro definition with non-zero line 19: _STDC_PREDEF_H 1.
 #2  0x0000000000784a25 in rl_callback_read_char () at src/readline/callback.c:116
 #3  0x0000000000619111 in rl_callback_read_char_wrapper (client_data=0x0) at src/gdb/event-top.c:167
 #4  0x00000000006194e7 in stdin_event_handler (error=0, client_data=0x0) at src/gdb/event-top.c:373
 #5  0x00000000006180da in handle_file_event (data=...) at src/gdb/event-loop.c:763
 #6  0x00000000006175c1 in process_event () at src/gdb/event-loop.c:340
 #7  0x0000000000617688 in gdb_do_one_event () at src/gdb/event-loop.c:404
 #8  0x00000000006176d8 in start_event_loop () at src/gdb/event-loop.c:429
 #9  0x0000000000619143 in cli_command_loop (data=0x0) at src/gdb/event-top.c:182
 #10 0x000000000060f4c8 in current_interp_command_loop () at src/gdb/interps.c:318
 #11 0x0000000000610691 in captured_command_loop (data=0x0) at src/gdb/main.c:323
 #12 0x000000000060c385 in catch_errors (func=0x610676 <captured_command_loop>, func_args=0x0, errstring=0x900241 "", mask=RETURN_MASK_ALL)
     at src/gdb/exceptions.c:237
 #13 0x0000000000611b8f in captured_main (data=0x7fffffffd7b0) at src/gdb/main.c:1151
 #14 0x000000000060c385 in catch_errors (func=0x610a8e <captured_main>, func_args=0x7fffffffd7b0, errstring=0x900241 "", mask=RETURN_MASK_ALL)
     at src/gdb/exceptions.c:237
 #15 0x0000000000611bb8 in gdb_main (args=0x7fffffffd7b0) at src/gdb/main.c:1159
 #16 0x000000000045ef57 in main (argc=3, argv=0x7fffffffd8b8) at src/gdb/gdb.c:32

The fix is to make the annotation code call target_terminal_inferior
again after printing, if the inferior's settings were in effect.

While at it, when we're doing output only, instead of
target_terminal_ours, we should call target_terminal_ours_for_output.
The latter doesn't actually remove stdin from the event loop, and also
leaves SIGINT forwarded to the target.

New test included.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-17  Pedro Alves  <palves@redhat.com>

	PR gdb/17472
	* annotate.c (annotate_breakpoints_invalid): Use
	target_terminal_our_for_output instead of target_terminal_ours.
	Give back the terminal to the target.
	(annotate_frames_invalid): Likewise.

gdb/testsuite/
2014-10-17  Pedro Alves  <palves@redhat.com>

	PR gdb/17472
	* gdb.base/annota-input-while-running.c: New file.
	* gdb.base/annota-input-while-running.exp: New file.
2014-10-17 13:32:26 +01:00
Pedro Alves 5842f62aad Make common code handle target_terminal_* idempotency
I found a place that should be giving back the terminal to the target,
but only if the target was already owning it.  So I need to add a
getter for who owns the terminal.

The trouble is that several places/target have their own globals to
track this state:

 - inflow.c:terminal_is_ours
 - remote.c:remote_async_terminal_ours_p
 - linux-nat.c:async_terminal_is_ours
 - go32-nat.c:terminal_is_ours

While one might think of adding a new target_ops method to query this,
conceptually, this state isn't really part of a particular target_ops.
Considering multi-target, the core shouldn't have to ask all targets
to know whether it's GDB that owns the terminal.  There's only one GDB
(or rather, only one top level interpreter).

So what this comment does is add a new global that is tracked by the
core instead.  A subsequent pass may later remove the other globals.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-17  Pedro Alves  <palves@redhat.com>

	* target.c (enum terminal_state): New enum.
	(terminal_state): New global.
	(target_terminal_init): New function.
	(target_terminal_inferior): Skip if inferior already owns the
	terminal.
	(target_terminal_ours, target_terminal_ours_for_output): New
	functions.
	* target.h (target_terminal_init): Convert to function prototype.
	(target_terminal_ours_for_output): Convert to function prototype
	and tweak comment.
	(target_terminal_ours): Convert to function prototype and tweak
	comment.
	* windows-nat.c (do_initial_windows_stuff): Call
	target_terminal_init instead of child_terminal_init_with_pgrp.
2014-10-17 13:31:25 +01:00
Pedro Alves 32a8097ba5 Delete Tru64 support
This commit does most of the mechanical removal.  IOW, the easy part.

procfs.c isn't touched beyond removing a couple obvious bits that are
guarded by a couple macros defined in config/alpha/nm-osf3.h.  Going
beyond that for procfs.c & co would be a harder excision that
potentially affects Solaris.

Some comments in the generic alpha code ABIs that may still be
relevant and I wouldn't know what to do with them.  That can always be
done on a separate pass, preferably by someone who can test on alpha.

A couple other spots have references to OSF/Tru64 and related files
being removed, but it felt like removing them would make things worse,
not better.  We can revisit those when we next need to touch that
code.

I didn't remove a reference to osf in testsuite/lib/future.exp, as I
believe that code is imported from DejaGNU.

Built and tested on x86_64 Fedora 20, with --enable-targets=all.

Tested that building for --target=alpha-osf3 on x86_64 Fedora 20
fails with:

 checking for default auto-load directory... $debugdir:$datadir/auto-load
 checking for default auto-load safe-path... $debugdir:$datadir/auto-load
 *** Configuration alpha-unknown-osf3 is obsolete.
 *** Support has been REMOVED.
 make[1]: *** [configure-gdb] Error 1
 make[1]: Leaving directory `build-osf'
 make: *** [all] Error 2

gdb/
2014-10-17  Pedro Alves  <palves@redhat.com>

	* Makefile.in (ALL_64_TARGET_OBS): Remove alpha-osf1-tdep.o.
	(HFILES_NO_SRCDIR): Remove config/alpha/nm-osf3.h.
	(ALLDEPFILES): Remove alpha-nat.c, alpha-osf1-tdep.c and
	solib-osf.c.
	* NEWS: Mention that support for alpha*-*-osf* has been removed.
	* ada-lang.h [__alpha__ && __osf__]
	(ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS): Delete.
	* alpha-nat.c, alpha-osf1-tdep.c: Delete files.
	* alpha-tdep.c (alpha_gdbarch_init): Remove reference to
	GDB_OSABI_OSF1.
	* config/alpha/alpha-osf3.mh, config/alpha/nm-osf3.h: Delete
	files.
	* config/djgpp/fnchange.lst (config/alpha/alpha-osf1.mh)
	(config/alpha/alpha-osf2.mh, config/alpha/alpha-osf3.mh): Delete.
	* configure: Regenerate.
	* configure.ac: Remove references to osf.
	* configure.host: Handle alpha*-*-osf* in the obsolete hosts
	section.  Remove all other references to osf.
	* configure.tgt: Add alpha*-*-osf* to the obsolete targets section.
	Remove all other references to osf.
	* dec-thread.c: Delete file.
	* defs.h (GDB_OSABI_OSF1): Delete.
	* inferior.h (START_INFERIOR_TRAPS_EXPECTED): New unconditionally
	defined.
	* osabi.c (gdb_osabi_names): Delete "OSF/1".
	* procfs.c (procfs_debug_inferior) [PROCFS_DONT_TRACE_FAULTS]:
	Delete code.
	(unconditionally_kill_inferior)
	[PROCFS_NEED_CLEAR_CURSIG_FOR_KILL]: Delete code.
	* solib-osf.c: Delete file.

gdb/testsuite/
2014-10-17  Pedro Alves  <palves@redhat.com>

	* gdb.base/callfuncs.exp: emove references to osf.
	* gdb.base/sigall.exp: Likewise.
	* gdb.gdb/selftest.exp: Likewise.
	* gdb.hp/gdb.base-hp/callfwmall.exp: Likewise.
	* gdb.mi/non-stop.c: Likewise.
	* gdb.mi/pthreads.c: Likewise.
	* gdb.reverse/sigall-precsave.exp: Likewise.
	* gdb.reverse/sigall-reverse.exp: Likewise.
	* gdb.threads/pthreads.c: Likewise.
	* gdb.threads/pthreads.exp: Likewise.

gdb/doc/
2014-10-17  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Ada Tasks and Core Files): Delete mention of Tru64.
	(SVR4 Process Information): Delete mention of OSF/1.
2014-10-17 11:18:59 +01:00
Pedro Alves 80134cf5b3 Fix build without libexpat
clear_threads_listing_context is used for thread listing methods other
than the xml based, but it's only defined when HAVE_LIBEXPAT is defined.

gdb/
2014-10-17  Pedro Alves  <palves@redhat.com>

	* remote.c (clear_threads_listing_context): Move higher up, out of
	the HAVE_LIBEXPAT guard.
2014-10-17 11:05:06 +01:00
Yao Qi 7a3517ffeb Don't check target_info exists noargs in commands.exp
I am confused by the noargs checking at each proc in commands.exp,

    if [target_info exists noargs] {
        verbose "Skipping progvar_simple_while_test because of noargs."
        return
    }
    gdb_test_no_output "set args 5" "set args in progvar_simple_while_test"
    if { ![runto factorial] } then { gdb_suppress_tests }
    # Don't depend upon argument passing, since most simulators don't
    # currently support it.  Bash value variable to be what we want.
    gdb_test "p value=5" ".*" "set value to 5 in progvar_simple_if_test #2"

They are conflicting to me.  If the argument passing can't be done on
the target, we skip this test, why do we still have to set value below?
On the other hand, the test case is compiled with -DFAKEARGV, it doesn't
get anything from argv[1], why do we need to skip it if noargs is true?

I don't find any useful clues from the git log, as the code is quite
old, predating import to sourceware cvs.  However, I find something
useful from the ChangeLog.

Thu Jul 20 13:28:36 1995  Jeffrey A. Law  <law@rtl.cygnus.com>

        .....
        * gdb.base/commands.exp: Protect tests which need arguments with
        $noargs conditionals.

Mon Apr 21 13:38:58 1997  Fred Fish  <fnf@cygnus.com>

        * gdb.base/run.c: Use FAKEARGV to build test executable that
        does not require a command line arg, since most simulators
        don't currently support passing such an arg into the simulated
        program.
        * gdb.base/commands.exp: Change tests to insert the proper
        value as the arg to the first recursive factorial call.  Change
        compilation line to define FAKEARGV at compile time.

Jeff added noargs checking as argument is passed to the inferior.  Then,
I presume Fred wanted to run this test on simulators which don't support
argument passing, and change the code not get input from argv.  (I guess)
noargs wasn't set in simulator board files at that moment.

Since Fred changed test to set input by gdb, instead of getting input
from argv, the test should be able to run on target doesn't support
argument passing, such as simulator and gdbserver.

This patch is to remove these checks to noargs and "set args".  I run
commands.exp with these board files, and no fail is found

 - unix and native-gdbserver
 - arm-none-eabi with qemu
 - gdbserver on arm-linux-gnueabi with qemu

gdb/testsuite:

2014-10-17  Yao Qi  <yao@codesourcery.com>

	* gdb.base/commands.exp (gdbvar_complex_if_while_test): Don't check
	'target_info exists noargs'.
	(test_command_prompt_position): Likewise.
	(progvar_simple_if_test): Don't check 'target_info exists noargs'.
	 Remove "set args".
	(progvar_simple_while_test): Likewise.
	(progvar_complex_if_while_test): Likewise.
	(if_while_breakpoint_command_test): Likewise.
	(infrun_breakpoint_command_test): Likewise.
	(breakpoint_command_test): Likewise.
	(watchpoint_command_test): Likewise.
	(bp_deleted_in_command_test): Likewise.
	(temporary_breakpoint_commands): Likewise.
2014-10-17 13:04:34 +08:00
Tristan Gingold 89c7137fad Darwin: sanitize %gs and %fs values.
Some Darwin kernels return values out of bounds for gs and fs segments.
With this commit, they are masked to avoid garbage.

gdb/ChangeLog:
	* i386-darwin-nat.c (i386_darwin_fetch_inferior_registers)
	(i386_darwin_store_inferior_registers): Sanitize gs and fs values
	on amd64.
2014-10-16 13:52:24 +02:00
Yao Qi bb99c4726c Don't check noargs in remotetimeout.exp
The condition [target_info exists noargs] is checked when
remotetimeout.exp was added
https://sourceware.org/ml/gdb-patches/2005-02/msg00052.html

noargs means GDB does not support argument passing for inferior,
rather than doesn't support argument passing to GDB.  remotetimeout.exp
passes -l to GDB only, doesn't pass any arguments to the inferior.

This patch is to remove such unnecessary checking, and
remotetimeout.exp then can be run with native-gdbserver board file.

gdb/testsuite:

2014-10-16  Yao Qi  <yao@codesourcery.com>

	* gdb.base/remotetimeout.exp: Remove noargs checking.
2014-10-16 12:55:01 +08:00
Pedro Alves 44ee4a526d DEC threads: Simplify updating the thread list
Seems to me that we can simplify DEC thread's
target_update_thread_list implementation, avoiding the need to build
the array of GDB threads.

I have no way to test this, but then again support for Tru64 is about
to be removed.

Pushing anyway to have the last version in git be the cleanest one
should start from, if this file turns out to be resurrected in the
future.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* dec-thread.c (dec_thread_count_gdb_threads)
	(dec_thread_add_gdb_thread): Delete.
	(dec_thread_update_thread_list): Delete.
	(dec_thread_find_new_threads): Rename to ...
	(dec_thread_update_thread_list): ... this.  Delete GDB-size
	threads that are no longer found in dec_thread_list.
	(resync_thread_list): Delete.
	(dec_thread_wait): Call dec_thread_update_thread_list instead of
	resync_thread_list.
2014-10-15 22:56:21 +01:00
Pedro Alves ab970af197 remote: get rid of all the T packets when syncing the thread list
This commit avoids the prune_threads call in the remote target's
target_update_thread_list's implementation, eliminating all the "thread
alive" RSP traffic (one packet per thread) whenever we fetch the
thread list.

IOW, this:

 Sending packet: $Tp2141.2150#82...Packet received: OK
 Sending packet: $Tp2141.214f#b7...Packet received: OK
 Sending packet: $Tp2141.2141#82...Packet received: OK
 ... more T packets; it's one per previously known live thread ...
 Sending packet: $qXfer:threads:read::0,fff#03...Packet received: l<threads>\n<thread id="p2141.2141" core="2"/>\n<thread id="p2141.214f" core="1"/>\n<thread id="p2141.2150" core="2"/>\n</threads>\n

Becomes:

 Sending packet: $qXfer:threads:read::0,fff#03...Packet received: l<threads>\n<thread id="p2141.2141" core="2"/>\n<thread id="p2141.214f" core="1"/>\n<thread id="p2141.2150" core="2"/>\n</threads>\n

Tested on x86_64 Fedora 20, native gdbserver:
  - tests the qXfer:threads:read method.

Tested on x86_64 Fedora 20, native gdbserver with qXfer:threads:read
force-disabled in gdbserver:
  - So that GDB falls back to the qfThreadInfo/qsThreadInfo method.

And also manually smoked tested force disabling both
qXfer:threads:read and qfThreadInfo/qsThreadInfo in gdbserver.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (ALL_NON_EXITED_THREADS_SAFE): New macro.
	* remote.c (remote_update_thread_list): Skip calling prune_threads
	if any thread listing method is supported, and instead walk over
	the set of remote threads listed, deleting those that are not
	found in GDB's thread list.
2014-10-15 22:55:14 +01:00
Pedro Alves e8032dde10 Push pruning old threads down to the target
When GDB wants to sync the thread list with the target's (e.g., due to
"info threads"), it calls update_thread_list:

 update_thread_list (void)
 {
   prune_threads ();
   target_find_new_threads ();
   update_threads_executing ();
 }

And then prune_threads does:

 prune_threads (void)
 {
   struct thread_info *tp, *next;

   for (tp = thread_list; tp; tp = next)
     {
       next = tp->next;
       if (!thread_alive (tp))
	 delete_thread (tp->ptid);
     }
 }

Calling thread_live on each thread one by one is expensive.

E.g., on Linux, it ends up doing kill(SIG0) once for each thread.  Not
a big deal, but still a bunch of syscalls...

With the remote target, it's cumbersome.  That thread_alive call ends
up generating one T packet per thread:

 Sending packet: $Tp2141.2150#82...Packet received: OK
 Sending packet: $Tp2141.214f#b7...Packet received: OK
 Sending packet: $Tp2141.2141#82...Packet received: OK
 Sending packet: $qXfer:threads:read::0,fff#03...Packet received: l<threads>\n<thread id="p2141.2141" core="2"/>\n<thread id="p2141.214f" core="1"/>\n<thread id="p2141.2150" core="2"/>\n</threads>\n

That seems a bit silly when target_find_new_threads method
implementations will always fetch the whole current set of target
threads, and then add those that are not in GDB's thread list, to
GDB's thread list.

This patch thus pushes down the responsibility of pruning dead threads
to the target_find_new_threads method instead, so a target may
implement pruning dead threads however it wants.

Once we do that, target_find_new_threads becomes a misnomer, so the
patch renames it to target_update_thread_list.

The patch doesn't attempt to do any optimization to any target yet.
It simply exports prune_threads, and makes all implementations of
target_update_thread_list call that.  It's meant to be a no-op.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* ada-tasks.c (print_ada_task_info, task_command_1): Adjust.
	* bsd-uthread.c (bsd_uthread_find_new_threads): Rename to ...
	(bsd_uthread_update_thread_list): ... this.  Call prune_threads.
	(bsd_uthread_target): Adjust.
	* corelow.c (core_open): Adjust.
	* dec-thread.c (dec_thread_find_new_threads): Update comment.
	(dec_thread_update_thread_list): New function.
	(init_dec_thread_ops): Adjust.
	* gdbthread.h (prune_threads): New declaration.
	* linux-thread-db.c (thread_db_find_new_threads): Rename to ...
	(thread_db_update_thread_list): ... this.  Call prune_threads.
	(init_thread_db_ops): Adjust.
	* nto-procfs.c (procfs_find_new_threads): Rename to ...
	(procfs_update_thread_list): ... this.  Call prune_threads.
	(procfs_attach, procfs_create_inferior, init_procfs_targets):
	Adjust.
	* obsd-nat.c (obsd_find_new_threads): Rename to ...
	(obsd_update_thread_list): ... this.  Call prune_threads.
	(obsd_add_target): Adjust.
	* procfs.c (procfs_target): Adjust.
	(procfs_notice_thread): Update comment.
	(procfs_find_new_threads): Rename to ...
	(procfs_update_thread_list): ... this.  Call prune_threads.
	* ravenscar-thread.c (ravenscar_update_inferior_ptid): Update
	comment.
	(ravenscar_wait): Adjust.
	(ravenscar_find_new_threads): Rename to ...
	(ravenscar_update_thread_list): ... this.  Call prune_threads.
	(init_ravenscar_thread_ops): Adjust.
	* record-btrace.c (record_btrace_find_new_threads): Rename to ...
	(record_btrace_update_thread_list): ... this.  Adjust comment.
	(init_record_btrace_ops): Adjust.
	* remote.c (remote_threads_info): Rename to ...
	(remote_update_thread_list): ... this.  Call prune_threads.
	(remote_start_remote, extended_remote_attach_1, init_remote_ops):
	Adjust.
	* sol-thread.c (check_for_thread_db): Adjust.
	(sol_find_new_threads_callback): Rename to ...
	(sol_update_thread_list_callback): ... this.
	(sol_find_new_threads): Rename to ...
	(sol_update_thread_list): ... this.  Call prune_threads.  Adjust.
	(sol_get_ada_task_ptid, init_sol_thread_ops): Adjust.
	* target-delegates.c: Regenerate.
	* target.c (target_find_new_threads): Rename to ...
	(target_update_thread_list): ... this.
	* target.h (struct target_ops): Rename to_find_new_threads field
	to to_update_thread_list.
	(target_find_new_threads): Rename to ...
	(target_update_thread_list): ... this.
	* thread.c (prune_threads): Make extern.
	(update_thread_list): Adjust.
2014-10-15 22:54:13 +01:00
Pedro Alves 6dc54d9124 Merge remote thread listing methods
We have three methods to list the current remote thread list:

1. The qXfer:threads:read method (the preferred one nowadays), builds a
remote thread list while parsing the XML, and then after the XML
parsing is done, goes over the built list and adds threads GDB doesn't
know about yet to GDB's list.

2. If the qXfer method isn't available, we fallback to using the
qfThreadInfo/qsThreadInfo packets.  When we do this, we adds threads
to GDB's list immediately as we parse the qfThreadInfo/qsThreadInfo
packet replies.

3. And then if the previous method isn't available either, we try the
old deprecated qL packet.  This path is already looking somewhat
broken for not using remote_notice_new_inferior to add threads to
GDB's list.

This patch makes all variants work in two passes, like the qXfer
method, and then makes all variants share the code path that adds
threads to GDB's list.

Tested on x86_64 Fedora 20 with native gdbserver.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* remote.c (remote_get_threadlist, remote_threadlist_iterator):
	Add describing comment.  Return -1 if the qL packet is not
	supported.
	(struct thread_item, thread_item_t): Move higher up in
	the file.  Add comments.
	(struct threads_parsing_context): Move higher up in
	the file, add comments, and remote to ...
	(struct threads_listing_context): ... this.
	(remote_newthread_step): Don't add the thread to GDB's thread
	database here.  Instead push it to the thread_listing_context
	list.
	(remote_find_new_threads): Rename to ...
	(remote_get_threads_with_ql): ... this.  Add target_ops and
	targets_listing_context parameters.  Pass down context.
	(start_thread): Adjust.
	(clear_threads_parsing_context): Rename to ...
	(clear_threads_listing_context): ... this.
	(remote_get_threads_with_qxfer): New, with parts salvaged from old
	remote_threads_info.
	(remote_get_threads_with_qthreadinfo): Ditto.
	(remote_threads_info): Reimplement.
2014-10-15 22:43:59 +01:00
Pedro Alves 36728e82bd Non-stop + software single-step archs: don't force displaced-stepping for all single-steps
This finally reverts this bit of commit 929dfd4f:

  2009-07-31  Pedro Alves  <pedro@codesourcery.com>
	      Julian Brown  <julian@codesourcery.com>

	 ...
	 (resume): If this is a software single-stepping arch, and
	 displaced-stepping is enabled, use it for all single-step
	 requests.
	 ...

That means that in non-stop (or really displaced-stepping) mode, on
software single-step archs - even those that only use sss breakpoints
to deal with atomic sequences, like PPC - if we have more than one
thread single-stepping, we'll always serialize the threads'
single-steps, as only one thread may be displaced stepping at a given
time, because there's only one scratch pad.

We originally did that because GDB didn't support having multiple
threads software-single-stepping simultaneously.  The previous patches
fixed that limitation, so we can now finally revert this too.

Tested on:

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

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* infrun.c (resume): Don't force displaced-stepping for all
	single-steps on software single-stepping archs.
2014-10-15 20:18:32 +01:00
Pedro Alves 34b7e8a6ad Make single-step breakpoints be per-thread
This patch finally makes each thread have its own set of single-step
breakpoints.  This paves the way to have multiple threads software
single-stepping, though this patch doesn't flip that switch on yet.
That'll be done on a subsequent patch.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (single_step_breakpoints): Delete global.
	(insert_single_step_breakpoint): Adjust to store the breakpoint
	pointer in the current thread.
	(single_step_breakpoints_inserted, remove_single_step_breakpoints)
	(cancel_single_step_breakpoints): Delete functions.
	(breakpoint_has_location_inserted_here): Make extern.
	(single_step_breakpoint_inserted_here_p): Adjust to walk the
	breakpoint list.
	* breakpoint.h (breakpoint_has_location_inserted_here): New
	declaration.
	(single_step_breakpoints_inserted, remove_single_step_breakpoints)
	(cancel_single_step_breakpoints): Remove declarations.
	* gdbthread.h (struct thread_control_state)
	<single_step_breakpoints>: New field.
	(delete_single_step_breakpoints)
	(thread_has_single_step_breakpoints_set)
	(thread_has_single_step_breakpoint_here): New declarations.
	* infrun.c (follow_exec): Also clear the single-step breakpoints.
	(singlestep_breakpoints_inserted_p, singlestep_ptid)
	(singlestep_pc): Delete globals.
	(infrun_thread_ptid_changed): Remove references to removed
	globals.
	(resume_cleanups): Delete the current thread's single-step
	breakpoints.
	(maybe_software_singlestep): Remove references to removed globals.
	(resume): Adjust to use thread_has_single_step_breakpoints_set and
	delete_single_step_breakpoints.
	(init_wait_for_inferior): Remove references to removed globals.
	(delete_thread_infrun_breakpoints): Delete the thread's
	single-step breakpoints too.
	(delete_just_stopped_threads_infrun_breakpoints): Don't delete
	single-step breakpoints here.
	(delete_stopped_threads_single_step_breakpoints): New function.
	(adjust_pc_after_break): Adjust to use
	thread_has_single_step_breakpoints_set.
	(handle_inferior_event): Remove references to removed globals.
	Use delete_stopped_threads_single_step_breakpoints.
	(handle_signal_stop): Adjust to per-thread single-step
	breakpoints.  Swap test order to do cheaper tests first.
	(switch_back_to_stepped_thread): Extend debug output.  Remove
	references to removed globals.
	* record-full.c (record_full_wait_1): Adjust to per-thread
	single-step breakpoints.
	* thread.c (delete_single_step_breakpoints)
	(thread_has_single_step_breakpoints_set)
	(thread_has_single_step_breakpoint_here): New functions.
	(clear_thread_inferior_resources): Also delete the thread's
	single-step breakpoints.
2014-10-15 20:18:32 +01:00
Pedro Alves 5b834a0a5d thread.c: cleanup breakpoint deletion
A little refactoring to reduce duplicate code.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* thread.c (delete_thread_breakpoint): New function.
	(delete_step_resume_breakpoint)
	(delete_exception_resume_breakpoint): Use it.
	(delete_at_next_stop): New function.
	(clear_thread_inferior_resources): Use delete_at_next_stop.
2014-10-15 20:18:32 +01:00
Pedro Alves a1fd2fa599 Remove deprecated_insert_raw_breakpoint and friends
There are no users of deprecated_{insert,remove}_raw_breakpoint left.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (regular_breakpoint_inserted_here_p): Inline ...
	(breakpoint_inserted_here_p): ... here.  Remove special case for
	software single-step breakpoints.
	(find_non_raw_software_breakpoint_inserted_here): Inline ...
	(software_breakpoint_inserted_here_p): ... here.  Remove special
	case for software single-step breakpoints.
	(bp_target_info_copy_insertion_state)
	(deprecated_insert_raw_breakpoint)
	(deprecated_remove_raw_breakpoint): Delete functions.
	* breakpoint.h (deprecated_insert_raw_breakpoint)
	(deprecated_remove_raw_breakpoint): Remove declarations.
2014-10-15 20:18:31 +01:00
Pedro Alves 7c16b83e05 Put single-step breakpoints on the bp_location chain
This patch makes single-step breakpoints "real" breakpoints on the
global location list.

There are several benefits to this:

- It removes the currently limitation that only 2 single-step
  breakpoints can be inserted.  See an example here of a discussion
  around a case that wants more than 2, possibly unbounded:

  https://sourceware.org/ml/gdb-patches/2014-03/msg00663.html

- makes software single-step work on read-only code regions.

  The logic to convert a software breakpoint to a hardware breakpoint
  if the memory map says the breakpoint address is in read only memory
  is in insert_bp_location.  Because software single-step breakpoints
  bypass all that go and straight to target_insert_breakpoint, we
  can't software single-step over read only memory.  This patch
  removes that limitation, and adds a test that makes sure that works,
  by forcing a code region to read-only with "mem LOW HIGH ro" and
  then stepping through that.

- Fixes PR breakpoints/9649

  This is an assertion failure in insert_single_step_breakpoint in
  breakpoint.c, because we may leave stale single-step breakpoints
  behind on error.

  The tests for stepping through read-only regions exercise the root
  cause of the bug, which is that we leave single-step breakpoints
  behind if we fail to insert any single-step breakpoint.  Deleting
  the single-step breakpoints in resume_cleanups,
  delete_just_stopped_threads_infrun_breakpoints, and
  fetch_inferior_event fixes this.  Without that, we'd no longer hit
  the assertion, as that code is deleted, but we'd instead run into
  errors/warnings trying to insert/remove the stale breakpoints on
  next resume.

- Paves the way to have multiple threads software single-stepping at
  the same time, leaving update_global_location_list to worry about
  duplicate locations.

- Makes the moribund location machinery aware of software single-step
  breakpoints, paving the way to enable software single-step on
  non-stop, instead of forcing serialized displaced stepping for all
  single steps.

- It's generaly cleaner.

  We no longer have to play games with single-step breakpoints
  inserted at the same address as regular breakpoints, like we
  recently had to do for 7.8.  See this discussion:

  https://sourceware.org/ml/gdb-patches/2014-06/msg00052.html.

Tested on x86_64 Fedora 20, on top of my 'single-step breakpoints on
x86' series.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	PR breakpoints/9649
	* breakpoint.c (single_step_breakpoints, single_step_gdbarch):
	Delete array globals.
	(single_step_breakpoints): New global.
	(breakpoint_xfer_memory): Remove special handling for single-step
	breakpoints.
	(update_breakpoints_after_exec): Delete bp_single_step
	breakpoints.
	(detach_breakpoints): Remove special handling for single-step
	breakpoints.
	(breakpoint_init_inferior): Delete bp_single_step breakpoints.
	(bpstat_stop_status): Add comment.
	(bpstat_what, bptype_string, print_one_breakpoint_location)
	(adjust_breakpoint_address, init_bp_location): Handle
	bp_single_step.
	(new_single_step_breakpoint): New function.
	(set_momentary_breakpoint, bkpt_remove_location): Remove special
	handling for single-step breakpoints.
	(insert_single_step_breakpoint, single_step_breakpoints_inserted)
	(remove_single_step_breakpoints, cancel_single_step_breakpoints):
	Rewrite.
	(detach_single_step_breakpoints, find_single_step_breakpoint):
	Delete functions.
	(breakpoint_has_location_inserted_here): New function.
	(single_step_breakpoint_inserted_here_p): Rewrite.
	* breakpoint.h: Remove FIXME.
	(enum bptype) <bp_single_step>: New enum value.
	(insert_single_step_breakpoint): Update comment.
	* infrun.c (resume_cleanups)
	(delete_step_thread_step_resume_breakpoint): Remove single-step
	breakpoints.
	(fetch_inferior_event): Install a cleanup that removes infrun
	breakpoints.
	(switch_back_to_stepped_thread) <expect thread advanced also>:
	Clear step-over info.

gdb/testsuite/
2014-10-15  Pedro Alves  <palves@redhat.com>

	PR breakpoints/9649
	* gdb.base/breakpoint-in-ro-region.c (main): Add more instructions.
	* gdb.base/breakpoint-in-ro-region.exp
	(probe_target_hardware_step): New procedure.
	(top level): Probe hardware stepping and hardware breakpoint
	support.  Test stepping through a read-only region, with both
	"breakpoint auto-hw" on and off and both "always-inserted" on and
	off.
2014-10-15 20:18:31 +01:00
Pedro Alves 0cbcdb96ea infrun.c: add for_each_just_stopped_thread
This is a preparatory/cleanup patch that does two things:

- Renames 'delete_step_thread_step_resume_breakpoint'.  The
  "step_resume" part is misnomer these days, as the function deletes
  other kinds of breakpoints, not just the step-resume breakpoint.  A
  following patch will want to make it delete yet another kind of
  breakpoint, even.

- Splits out the logic of which threads get those breakpoints deleted
  to a separate "for_each"-style function, so that the same following
  patch may use it with a different callback.

Tested on x86_64 Fedora 20.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* infrun.c (delete_step_resume_breakpoint_callback): Delete.
	(delete_thread_infrun_breakpoints): New function, with parts
	salvaged from delete_step_resume_breakpoint_callback.
	(delete_step_thread_step_resume_breakpoint): Delete.
	(for_each_just_stopped_thread_callback_func): New typedef.
	(for_each_just_stopped_thread): New function.
	(delete_just_stopped_threads_infrun_breakpoints): New function.
	(delete_step_thread_step_resume_breakpoint_cleanup): Rename to ...
	(delete_just_stopped_threads_infrun_breakpoints_cleanup):
	... this.  Adjust.
	(wait_for_inferior, fetch_inferior_event): Adjust to renames.
2014-10-15 20:18:30 +01:00
Pedro Alves 963f9c80cb Rewrite non-continuable watchpoints handling
When GDB finds out the target triggered a watchpoint, and the target
has non-continuable watchpoints, GDB sets things up to step past the
instruction that triggered the watchpoint.  This is just like stepping
past a breakpoint, but goes through a different mechanism - it resumes
only the thread that needs to step past the watchpoint, but also
switches a "infwait state" global, that has the effect that the next
target_wait only wait for events only from that thread.

This forcing of a ptid to pass to target_wait obviously becomes a
bottleneck if we ever support stepping past different watchpoints
simultaneously (in separate processes).

It's also unnecessary -- the target should only return events for
threads that have been resumed; if no other thread than the one we're
stepping past the watchpoint has been resumed, then those other
threads should not report events.  If we couldn't assume that, then
stepping past regular breakpoints would be broken for not likewise
forcing a similar infwait_state.

So this patch eliminates infwait_state, and instead teaches keep_going
to mark step_over_info in a way that has the breakpoints module skip
inserting watchpoints (because we're stepping past one), like it skips
breakpoints when we're stepping past one.

Tested on:

 - x86_64 Fedora 20 (continuable watchpoints)
 - PPC64 Fedora 18  (non-steppable watchpoints)

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (should_be_inserted): Don't insert watchpoints if
	trying to step past a non-steppable watchpoint.
	* gdbthread.h (struct thread_info) <stepping_over_watchpoint>: New
	field.
	* infrun.c (struct step_over_info): Add new field
	'nonsteppable_watchpoint_p' and adjust comments.
	(set_step_over_info): New 'nonsteppable_watchpoint_p' parameter.
	Adjust.
	(clear_step_over_info): Clear nonsteppable_watchpoint_p as well.
	(stepping_past_nonsteppable_watchpoint): New function.
	(step_over_info_valid_p): Also return true if stepping past a
	nonsteppable watchpoint.
	(proceed): Adjust call to set_step_over_info.  Remove reference to
	init_infwait_state.
	(init_wait_for_inferior): Remove reference to init_infwait_state.
	(waiton_ptid): Delete global.
	(struct execution_control_state)
	<stepped_after_stopped_by_watchpoint>: Delete field.
	(wait_for_inferior, fetch_inferior_event): Always pass
	minus_one_ptid to target_wait.
	(init_thread_stepping_state): Clear 'stepping_over_watchpoint'
	field.
	(init_infwait_state): Delete function.
	(handle_inferior_event): Remove infwait_state handling.
	(handle_signal_stop) <watchpoints handling>: Adjust after
	stepped_after_stopped_by_watchpoint removal.  Don't remove
	breakpoints here nor set infwait_state.  Set the thread's
	stepping_over_watchpoint flag, and call keep_going instead.
	(keep_going): Handle stepping_over_watchpoint.  Adjust
	set_step_over_info calls.
	* infrun.h (stepping_past_nonsteppable_watchpoint): Declare
	function.
2014-10-15 20:18:30 +01:00
Pedro Alves 6cc83d2a40 Decide whether we may have removed breakpoints based on step_over_info
... instead of trap_expected.

Gets rid of one singlestep_breakpoints_inserted_p reference, and is
generally more to the point.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* infrun.c (step_over_info_valid_p): New function.
	(resume): Use step_over_info_valid_p instead of checking the
	threads's trap_expected flag.
2014-10-15 20:18:29 +01:00
Pedro Alves a2abc7de68 gdbserver/win32: Rewrite debug registers handling
Don't use debug_reg_state for both:

 * "intent" - what we want the debug registers to look like

 * "reality" - what/which were the contents of the DR registers when
   the event triggered

Reserve it for the former only, like in the GNU/Linux port.

Otherwise the core x86 debug registers code can get confused if the
inferior itself changes the debug registers since GDB last set them.

This is also a requirement for being able to set watchpoints while the
target is running, if/when we get to it on Windows.  See the big
comment in x86_dr_stopped_data_address.

Seems to me this may also fixes propagating watchpoints to all threads
-- continue_one_thread only calls win32_set_thread_context (what
copies the DR registers to the thread), if something already fetched
the thread's context before.  Something else may be masking this
issue, I haven't checked.

Smoke tested by running gdbserver under Wine, connecting to it from
GNU/Linux, and checking that I could trigger a watchpoint as expected.

Joel tested it on x86-windows using AdaCore's testsuite.

gdb/gdbserver/
2014-10-15  Pedro Alves  <palves@redhat.com>

	PR server/17487
	* win32-arm-low.c (arm_set_thread_context): Remove current_event
	parameter.
	(arm_set_thread_context): Delete.
	(the_low_target): Adjust.
	* win32-i386-low.c (debug_registers_changed)
	(debug_registers_used): Delete.
	(update_debug_registers_callback): New function.
	(x86_dr_low_set_addr, x86_dr_low_set_control): Mark all threads as
	needing to update their debug registers.
	(win32_get_current_dr): New function.
	(x86_dr_low_get_addr, x86_dr_low_get_control)
	(x86_dr_low_get_status): Fetch the debug register from the thread
	record's context.
	(i386_initial_stuff): Adjust.
	(i386_get_thread_context): Remove current_event parameter.  Don't
	clear debug_registers_changed nor copy DR values to
	debug_reg_state.
	(i386_set_thread_context): Delete.
	(i386_prepare_to_resume): New function.
	(i386_thread_added): Mark the thread as needing to update irs
	debug registers.
	(the_low_target): Remove i386_set_thread_context and install
	i386_prepare_to_resume.
	* win32-low.c (win32_get_thread_context): Adjust.
	(win32_set_thread_context): Use SetThreadContext
	directly.
	(win32_prepare_to_resume): New function.
	(win32_require_context): New function, factored out from ...
	(thread_rec): ... this.
	(continue_one_thread): Call win32_prepare_to_resume on each thread
	we're about to continue.
	(win32_resume): Call win32_prepare_to_resume on the event thread.
	* win32-low.h (struct win32_thread_info)
	<debug_registers_changed>: New field.
	(struct win32_target_ops): Change prototype of set_thread_context,
	delete set_thread_context and add prepare_to_resume.
	(win32_require_context): New declaration.
2014-10-15 19:55:50 +01:00
Doug Evans 6979730b1b PR python/17364
gdb/ChangeLog:

	* python/lib/gdb/__init__.py (packages): Add "printer".
	* python/lib/gdb/command/bound_registers.py: Moved to ...
	* python/lib/gdb/printer/bound_registers.py: ... here.
	Add printer to global set of builtin printers.  Rename printer from
	"bound" to "mpx_bound128".
	* python/lib/gdb/printing.py (_builtin_pretty_printers): New global,
	registered as global "builtin" printer.
	(add_builtin_pretty_printer): New function.
	* data-directory/Makefile.in (PYTHON_FILE_LIST): Update, and add
	gdb/printer/__init__.py.
2014-10-15 11:43:49 -07:00
Iain Buclaw 35a49624e2 Remove d-support.c and use gdb_demangle for demangling D symbols.
gdb/ChangeLog

	* Makefile.in (SFILES): Remove d-support.c.
	(COMMON_OBS): Remove d-support.o.
	* d-lang.h (d_parse_symbol): Remove declaration.
	* d-lang.c (d_demangle): Use gdb_demangle to demangle D symbols.
	* d-support.c: Remove file.

gdb/testsuite/ChangeLog

	* gdb.dlang/demangle.exp: Update for demangling changes.
2014-10-15 19:28:19 +01:00
Andreas Arnez 8fa0c4f8ed Remove non-address bits for longjmp resume breakpoint
On 32-bit S390 targets the longjmp target address "naturally" has the
most significant bit set.  That bit indicates the addressing mode and
is not part of the address itself.  Thus, in analogy with similar
cases (like when computing the caller PC in
insert_step_resume_breakpoint_at_caller), this change removes
non-address bits from the longjmp target address before using it as a
breakpoint address.

Note that there are two ways for determining the longjmp target
address: via a probe or via a gdbarch method.  This change only
affects the probe method, because it is assumed that the address
returned by the gdbarch method is usable as-is.

This change was tested together with a patch that enables longjmp
probes in glibc for S/390:

  https://sourceware.org/ml/libc-alpha/2014-10/msg00277.html

gdb/ChangeLog:

	* gdb/infrun.c (process_event_stop_test): Apply
	gdbarch_addr_bits_remove to longjmp resume address.
2014-10-15 17:32:38 +02:00
Pedro Alves 3666da817e Delete gdb/regformats/microblaze.dat
This file:

 - Isn't used by GDBserver currently.

 - Isn't included in the WHICH list in features/Makefile, so hasn't
   been regenerated to pick the latest microblaze or generic fixes.

Just delete it.

gdb/
2014-10-15  Pedro Alves  <palves@redhat.com>

	* regformats/microblaze.dat: Delete file.
2014-10-15 16:21:59 +01:00
Ajit Kumar Agarwal 449aa9dfd1 Microblaze: Replace microblaze-expedite from pc to rpc
The Microblaze PC register is called "rpc", not "pc", as can be seen
in microblaze-core.xml.  Fix this, so GDBserver can find the register in
the regcache.

gdb/
2014-10-15  Ajit Agarwal  <ajitkum@xilinx.com>

	* features/Makefile (microblaze-expedite): Replace pc with rpc.
	* regformats/microblaze-with-stack-protect.dat: Regenerate.
2014-10-15 15:21:39 +01:00
Siva Chandra ebb8ece2ef Fix gnuv3_pass_by_reference to treat dynamic classes as non-trivial.
gdb/ChangeLog:

	* gnu-v3-abi.c (gnuv3_pass_by_reference): Treat dynamic classes
	as non-trivial.
2014-10-15 04:28:38 -07:00
Siva Chandra 2d1c107c1b Add new non-trial return value tests.
gdb/testsuite/ChangeLog:

	* gdb.cp/non-trivial-retval.cc: Add new test cases.
	* gdb.cp/non-trivial-retval.exp: Add new tests.
2014-10-15 04:27:13 -07:00
Siva Chandra 82c48ac732 Fix gnuv3_pass_by_reference to lookup copy c-tors with qualified args.
Before this, a copy constructor declared as in the following snippet was
not being treated as a copy constructor.

class A
{
public:
  A (A &); // OK.
  A (const A &); // Not being treated as a copy constructor because of the
                 // 'const' qualifier.
};

gdb/ChangeLog:

	PR c++/13403
	PR c++/15154
	* gnu-v3-abi.c (gnuv3_pass_by_reference): Lookup copy constructors
	with qualified args.
2014-10-15 04:25:32 -07:00
Siva Chandra 778811d5e7 Non trivial return value tests.
gdb/testsuite/ChangeLog:

	PR c++/13403
	PR c++/15154
	* gdb.cp/non-trivial-retval.cc: New file.
	* gdb.cp/non-trivial-retval.exp: New file.
2014-10-15 04:23:54 -07:00
Yao Qi 10c5f0a8a8 Fix py-parameter.exp for remote host
Test gdb.python/py-parameter.exp expects output "$srcdir/$subdir:\$cdir:\$cwd",
but proc gdb_reinitialize_dir doesn't set $srcdir/$subdir in search
directories on remote host because it doesn't exist on remote host.

proc gdb_reinitialize_dir { subdir } {
    global gdb_prompt

    if [is_remote host] {
	return ""
    }

It causes the fail below:

(gdb) python print (gdb.parameter ('directories'))^M
/tmp/gdb:$cdir:$cwd^M
(gdb) FAIL: gdb.python/py-parameter.exp: python print (gdb.parameter ('directories'))

This patch is to fix this fail by not matching $srcdir/$subdir on remote host.

gdb/testsuite:

2014-10-15  Yao Qi  <yao@codesourcery.com>

	* gdb.python/py-parameter.exp: Don't match $srcdir/$subdir on
	remote host.
2014-10-15 15:33:24 +08:00
Yao Qi 65d7b369af Fix file name matching on remote host.
I see the following fails in the remote host testing we do for mingw32
hosted GDB,

python print (symtab[1][0].symtab)^M
python.c^M
(gdb) FAIL: gdb.python/python.exp: Test decode_line current locationn filename

python print (symtab[1][0].symtab)^M
python.c^M
(gdb) FAIL: gdb.python/python.exp: Test decode_line python.c:26 filename

The test cases doesn't consider remote host and assumes that directory
on build also exists on host.  In this patch, we only match file base
name if host is remote, otherwise, match file with dir name.

gdb/testsuite:

2014-10-15  Yao Qi  <yao@codesourcery.com>

	* gdb.python/py-symbol.exp: Match file base name if host is
	remote, otherwise match file name with dir name.
	* gdb.python/py-symtab.exp: Likewise.
	* gdb.python/python.exp: Likewise.
2014-10-15 15:33:24 +08:00
Yao Qi 46dc139462 Clean up gdb.python/ tests
This patch is to clean up various gdb.python/*.exp tests, such as
removing trailing ".*" from the pattern and fix one typo I find during
reading the code.

gdb/testsuite:

2014-10-15  Yao Qi  <yao@codesourcery.com>

	* gdb.python/python.exp: Remove trailing ".*".  Fix typo
	locationn.
	* gdb.python/py-symbol.exp: Remove trailing ".*" in the
	pattern.
	* gdb.python/py-symtab.exp: Likewise.
2014-10-15 15:33:15 +08:00
Joel Brobecker c40cc657bc [Ada] Error adding/subtracting pointer value to/from integral.
When trying to evaluate an expression which adds a pointer and
an integral, the evaluation succeeds if the pointer is on
the left handside of the operator, but not when it is on the right
handside:

    (gdb) p something'address + 0
    $1 = (system.address) 0x613418 <pck.something>
    (gdb) p 0 + something'address
    Argument to arithmetic operation not a number or boolean.

Same issue when doing subtractions:

    (gdb) p something'address - 0
    $2 = (system.address) 0x613418 <pck.something>
    (gdb) p 0 - something'address
    Argument to arithmetic operation not a number or boolean.

This patch enhances the Ada expression evaluator to handle
these two situations.

gdb/ChangeLog:

        * ada-lang.c (ada_evaluate_subexp) <BINOP_ADD>: Add handling
        of the case where the second operand is a pointer.
        <BINOP_SUB>: Likewise.

gdb/testsuite/ChangeLog:

        * gdb.ada/addr_arith: New testcase.

Tested on x86_64-linux.
2014-10-14 14:05:11 -07:00
Maciej W. Rozycki 2abf49e11e gdb.dwarf2: Testsuite 64-bit pointer truncation fixes
* gdb.dwarf2/dw2-case-insensitive-debug.S: Handle 64-bit pointers.
	* gdb.dwarf2/dw2-case-insensitive.exp: Update accordingly.
	* gdb.dwarf2/dw2-skip-prologue.S: Handle 64-bit pointers.
	* gdb.dwarf2/dw2-skip-prologue.exp: Update accordingly.
2014-10-14 21:16:07 +01:00
Sergio Durigan Junior 0ea5cda861 Only call {set,clear}_semaphore probe function if they are not NULL
This patch is a response to what I commented on:

  <https://sourceware.org/ml/gdb-patches/2014-10/msg00046.html>

When reviewing Jose's USDT probe support patches.  Basically, in his
patch he had to create dummy functions for the set_semaphore and the
clear_semaphore methods of probe_ops (gdb/probe.h), because those
functions were called inconditionally from inside gdb/breakpoint.c and
gdb/tracepoint.c.  However, the semaphore concept may not apply to all
types of probes, and this is the case here: USDT probes do not have
semaphores (although SDT probes do).

Anyway, this is a simple (almost obvious) patch to guard the call to
{set,clear}_semaphore.  It does not introduce any regression on a
Fedora 20 x86_64.

I will apply it in a few days in case there is no comment.

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

	* breakpoint.c (bkpt_probe_insert_location): Call set_semaphore
	only if it is not NULL.
	(bkpt_probe_remove_location): Likewise, for clear_semaphore.
	* probe.h (struct probe_ops) <set_semaphore>: Update comment.
	(struct probe_ops) <clear_semaphore>: Likewise.
	* tracepoint.c (start_tracing): Call set_semaphore only if it is
	not NULL.
	(stop_tracing): Likewise, for clear_semaphore.
2014-10-14 14:46:18 -04:00
Sergio Durigan Junior f7088df3b1 Explicitly use language_c when evaluating a SDT probe argument
Joel contacted me offlist with a question about a warning that one of
his customers was seeing.  The message came from the new
linker-debugger interface, which uses SDT probes internally.  The
warning said:

    (gdb) run
    [...]
    warning: Probes-based dynamic linker interface failed.
    Reverting to original interface.

    Argument to arithmetic operation not a number or boolean.

This should not have happened in the environment the customer was
using (RHEL-6.x), so I found it strange.  Another thing caught my
attention: the last message, saying "Argument to arithmetic operation
not a number or boolean.".

Joel kindly investigated the issue further, and found the answer for
this.  To quote him:

	(gdb) set lang c
	(gdb) p 48+$ebp
	$4 = (void *) 0xffffd0f8

    So far so good. But...

	(gdb) set lang ada
	(gdb) p 48+$ebp
	Argument to arithmetic operation not a number or boolean.

    Ooops! Interestingly, if you revert the order of the operands...

	(gdb) p $ebp+48
	$5 = (access void) 0xffffd0f8

So the problem is doing pointer arithmetics when the language is set
to Ada.

I remembered that, during the parsing and the evaluation of SDT probe
arguments, the code sets the language as current_language, because, at
that time, I thought it was not necessary to worry about the language
given that the code implements its own parser.  I was wrong.  So here
is a patch to fix that, by setting the language as C, which should
guarantee that the maths are done in the right way (TM).

It was somewhat hard to find a reproducer for this issue.  In the end,
what I had to do was to create a testcase that used the %ebp register
on some displacement (e.g., "-4(%ebp)"), which finally triggered the
bug.  I am not sure why I could not trigger it when using other
registers, but I did not want to spend too much time investigating
this issue, which seemed like an Ada issue.  Also, because of this
peculiar way to trigger the problem, the testcase only covers x86-like
targets (i.e., i*86 and x86_64 with -m32).

Joel kindly tested this for me, and it worked.  I also ran a full
regression test here on my Fedora 20 x86_64, and everything is fine.

I will push this patch in a few days if there are no comments.

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

	* stap-probe.c (stap_parse_argument): Initialize expout explicitly
	using language_c, instead of current_language.

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

	* gdb.arch/stap-eval-lang-ada.S: Likewise.
	* gdb.arch/stap-eval-lang-ada.c: Likewise.
	* gdb.arch/stap-eval-lang-ada.exp: New file.
2014-10-14 14:33:31 -04:00
Yao Qi 4dc06805c2 Fix fail in mi-var-child.exp and mi-var-display.exp
Hi,
I see the following fails on arm-none-eabi target,

-var-list-children --simple-values struct_declarations  ^M
^done,numchild="11",children=[...,child={name="struct_declarations.func_ptr_struct",exp="func_ptr_struct",numchild="0",value="0x0 <_ftext>",type="struct _struct_decl (*)(int, char *, long)",thread-id="1"},child={name="struct_declarations.func_ptr_ptr",exp="func_ptr_ptr",numchild="0",value="0x0 <_ftext>",type="struct _struct_decl *(*)(int, char *, long)",thread-id="1"},...
(gdb) ^M
FAIL: gdb.mi/mi-var-child.exp: listing of children, simple types: names, type and values, complex types: names and types

-var-set-format weird.func_ptr_ptr natural^M
^done,format="natural",value="0x0 <_ftext>"^M
(gdb) ^M
FAIL: gdb.mi/mi-var-display.exp: set format variable weird.func_ptr_ptr in natural

In the test, "0x0" is expected, but "0x0 <_ftext>" is in the output.
Function pointers point to address zero, and tests assume there is no
symbol on address zero.  However, on my arm-none-eabi target, there is
a code symbol _ftext on address zero, and test fails.  Note that "set
print symbol off" doesn't take effect for function pointer.

int (*f) (void);
f = main;

(gdb) p f
$1 = (int (*)(void)) 0x8048400 <main>
(gdb) set print symbol off
(gdb) p f
$2 = (int (*)(void)) 0x8048400 <main>

In order to erase the difference, we can assign some function address
explicitly to function pointer, so the test behaves in a unique way.
In this patch, we assign nothing1 and nothing2 to function pointers
func_ptr_struct and func_ptr_ptr respectively, and update test as the
source file is changed.

gdb/testsuite:

2014-10-14  Yao Qi  <yao@codesourcery.com>

	* gdb.mi/mi-var-child.c (nothing1): New function.
	(nothing2): New function.
	(do_children_tests): Set function pointers by nothing1 and
	nothing2.
	* gdb.mi/mi-var-child.exp: Step over new added statements.
	Update test to match the new output.
	* gdb.mi/var-cmd.c (nothing1): New function.
	(nothing2): New function.
	(do_children_tests): Set function pointers by  nothing1 and
	nothing2.
	* gdb.mi/mi-var-display.exp: Update test to match output.
	Step to the line specified by $line_dct_nothing.
	Increase the number of lines to step.
2014-10-14 19:42:51 +08:00
Yao Qi 46a93de2ab Use mi_varobj_update in mi-var-child.exp and mi2-var-child.exp
Hi,
I modify mi-var-child.exp and find that the pattern to match the output
of -var-update * is quite complicated.  However, it can be simplified by
using mi_varobj_update.  That is what this patch does.

gdb/testsuite:

2014-10-14  Yao Qi  <yao@codesourcery.com>

	* gdb.mi/mi-var-child.exp: Use mi_varobj_update to simplify
	tests.
	* gdb.mi/mi2-var-child.exp: Likewise.
2014-10-14 19:42:45 +08:00
Doug Evans 14ea52eecb Change name of file name test in py-objfile.exp.
Tests should each have their own name.

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Change name of file name test.
2014-10-13 14:50:32 -07:00
Doug Evans e5c6e92bbe Fix dw2-op-out-param.S CU offset values.
This test will pass if the CU is the first CU in the binary.
If libc debugging info is installed it may not be, in which case
the CU offset values are wrong.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-op-out-param.S: Make DW_FORM_ref4 values be the offset
	from the start of the CU.
2014-10-13 14:05:34 -07:00
Doug Evans 6ff5a0f675 fix file paths in previous commit 2014-10-13 13:33:09 -07:00
Doug Evans 4e1bbde013 Remove some code duplication in py-objfile.c, py-progspace.c.
gdb/ChangeLog:

	* py-objfile.c (objfpy_initialize): New function.
	(objfpy_new, objfile_to_objfile_object): Call it.
	* py-progspace.c (pspy_initialize): New function.
	(pspy_new, pspace_to_pspace_object): Call it.
2014-10-13 12:24:54 -07:00
Jan Kratochvil c780cc2f50 Fix "save breakpoints" for "catch" command
gdb/ChangeLog
2014-10-13  Miroslav Franc  <mfranc@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix "save breakpoints" for "catch" command.
	* break-catch-sig.c (signal_catchpoint_print_recreate): Add trailing
	newline.

gdb/testsuite/ChangeLog
2014-10-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Yao Qi  <yao@codesourcery.com>

	Fix "save breakpoints" for "catch" command.
	* gdb.base/catch-signal.exp: Add gdb_breakpoint "main".
	Remove -nonewline.  Match also the added "main" line.
2014-10-13 13:39:48 +02:00
Jan Kratochvil 99894e1175 Fix "save breakpoints" for "disable $bpnum" command.
gdb/ChangeLog
2014-10-12  Miroslav Franc  <mfranc@redhat.com>

	Fix "save breakpoints" for "disable $bpnum" command.
	* breakpoint.c (save_breakpoints): Add $bpnum for disable.

gdb/testsuite/ChangeLog
2014-10-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix "save breakpoints" for "disable $bpnum" command.
	* gdb.base/save-bp.c (main): Add label.
	* gdb.base/save-bp.exp: Add 8th disabled breakpoint.  Match it.
2014-10-12 21:52:39 +02:00
Jan Kratochvil 6e1ac5a373 Use gdb_test_sequence in gdb.base/save-bp.exp.
But IMO it is a functionality regression as:

 * gdb_test_sequence permits arbitary number of lines of text between those
   lines being matched.  Former regex string did not allow it.
   This may make a difference if GDB regresses by printing some unexpected
   line after the breakpoint info line (like a "silent" line).

>  * \[\r\n\]+ can be used to anchor the beginning of the pattern, in the sense
>    of Perl regex ^ /m match.  At least I have found such cases in existing
>    *.exp files so I used that.  Using ^ really does not work.
>
>    But I am not aware how to do Perl regex $ /m match.  Using $ really does
>    not work.  But this means that for example the trailing
>      ( \\((host|target) evals\\))?
>    on the line
>      "\[\r\n\]+\[ \t\]+stop only if i == 1( \\((host|target) evals\\))?"
>    originally made sense there but now it can be removed as it has no longer
>    any functionality there - it will match now any trailing line garbage.

by Yao Qi:

In this test case, ( \\((host|target) evals\\))? isn't needed in the
pattern.  What we test here is to save breakpoints into file and restore
them from file.  The contents saved in file are:

break save-bp.c:31
  condition $bpnum i == 1

the information about the place where the condition is evaluated isn't
saved, so we don't need to check.  Breakpoint save and restore has
nothing to do with where the condition is evaluated (host or target).  I
am fine to leave it here now.

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

	* gdb.base/save-bp.exp (info break): Use gdb_test_sequence.
2014-10-12 21:47:13 +02:00
Yao Qi 754dd2b00f Enable qTStatus packet in case it is disabled
Nowadays, we are using command "tstatus" to send a packet to GDBserver
in order to check the connection.  However, on the target doesn't
support tracepoint, the following error is emitted before sending any
packet to GDBserver.

tstatus^M
Trace can not be run on this target.^M
(gdb) FAIL: gdb.server/server-kill.exp: tstatus

qTStatus is disabled after receiving the empty reply during connecting
to the remote target.  When the test executes command "tstatus" again,
remote_get_trace_status returns -1 at the very beginning, and no RSP
packet is sent out.

This patch is to enable qTStatus packet again.

gdb/testsuite:

2014-10-11  Yao Qi  <yao@codesourcery.com>

	* gdb.server/server-kill.exp: Execute command
	"set remote trace-status-packet on" before "tstatus".
2014-10-11 11:13:39 +08:00
Yao Qi f90183d7e3 Get GDBserver pid on remote target
Hi,
We see the following fail in the real remote testing...

(gdb) Executing on target: kill -9 29808    (timeout = 300)
spawn [open ...]^M
sh: 1: kill: No such process

The test tries to kill gdbserver in this way:

set server_pid [exp_pid -i [board_info target fileid]]
remote_exec target "kill -9 $server_pid"

in native testing, we'll get the pid of spawned gdbserver, however, in
remote testing, we'll get the pid of ssh session, since we start
gdbserver on the remote target through ssh.  The pid on build doesn't
exist on target.

In this patch, we tweak server-kill.c to get the parent pid, which is
the pid of GDBserver.  GDB gets it and kill GDBserver on target.

gdb/testsuite:

2014-10-11  Yao Qi  <yao@codesourcery.com>

	* gdb.server/server-kill.c: Include sys/types.h and unistd.h.
	(main): Call getppid.
	* gdb.server/server-kill.exp: Set breakpoint on line "i = 0;"
	and continue to it.  Read variable "server_pid".
2014-10-11 11:13:34 +08:00
Yao Qi bf40a6078f Clean up server-kill.exp
This patch is to remove some lines which looks unnecessary.  These
lines were added when server-kill.exp was added.  In the version 1,
https://sourceware.org/ml/gdb-patches/2013-03/msg00691.html the test
calls runto_main and delete breakpoint on main,

+if ![runto_main] {
+    return -1
+}
+
+# Otherwise the breakpoint at 'main' would not cause insert
breakpoints during
+# first step.
+delete_breakpoints

However, in the version 2
https://sourceware.org/ml/gdb-patches/2013-03/msg00854.html runto_main
is removed but delete_breakpoints is still there.  AFAICS, the line of
delete_breakpoints can be removed too.

gdb/testsuite:

2014-10-11  Yao Qi  <yao@codesourcery.com>

	* gdb.server/server-kill.exp: Remove "delete_breakpoints".
2014-10-11 11:12:23 +08:00
Yao Qi 052ca37073 No longer pull thread list explicitly
As the result of the patch below, GDB updates thread list when a stop is
presented to user.  The tests don't have to fetch thread list explicitly.

  [PATCH 3/3] Fix non-stop regressions caused by "breakpoints always-inserted off" changes
  https://sourceware.org/ml/gdb-patches/2014-09/msg00734.html

This patch is to remove the test code updating thread list.

Run these three tests many times on arm-linux-gnueabi and x86-linux.
No regressions.

gdb/testsuite:

2014-10-11  Yao Qi  <yao@codesourcery.com>

	* gdb.threads/thread-find.exp: Don't execute command
	"info threads".
	* gdb.threads/attach-into-signal.exp (corefunc): Likewise.
	* gdb.threads/linux-dp.exp: Don't check the condition
	$threads_created equals to zero.
2014-10-11 08:32:52 +08:00
Pedro Alves 3831839c08 Delete IRIX support
This does most of the mechanical removal.  IOW, the easy part.

This doesn't touch procfs.c as that'd be a harder excision,
potentially affecting Solaris.

mips-tdep.c is left alone.  E.g., I didn't delete the GDB_OSABI_IRIX
enum value, nor references to it in mips-tdep.c.  Some comments
mentioning IRIX ABIs may still be relevant and I wouldn't know what to
do with them. in That can always be done on a separate pass,
preferably by someone who can test on MIPS.

I didn't remove a reference to IRIX in testsuite/lib/future.exp, as I
believe that code is imported from DejaGNU.

Built and tested on x86_64 Fedora 20, with --enable-targets=all.

Tested that building for --target=mips-sgi-irix6 on x86_64 Fedora 20
fails with:

 checking for default auto-load directory... $debugdir:$datadir/auto-load
 checking for default auto-load safe-path... $debugdir:$datadir/auto-load
 *** Configuration mips-sgi-irix6 is obsolete.
 *** Support has been REMOVED.
 make[1]: *** [configure-gdb] Error 1
 make[1]: Leaving directory `/home/pedro/gdb/mygit/build-irix'
 make: *** [all] Error 2

gdb/
2014-10-10  Pedro Alves  <palves@redhat.com>

	* Makefile.in (ALL_TARGET_OBS): Remove mips-irix-tdep.o and solib-irix.o.
	(ALLDEPFILES): Remove mips-irix-tdep.c and solib-irix.c.
	(HFILES_NO_SRCDIR): Remove solib-irix.h.
	* NEWS: Mention that support for mips-sgi-irix5* mips-sgi-irix6*
	and been removed.
	* config/mips/irix5.mh, config/mips/irix6.mh: Delete files.
	* configure.ac: Remove references to IRIX.
	* configure.host: Add *-*-irix* to the obsolete hosts section.
	Remove all other references to irix.
	* irix5-nat.c, mips-irix-tdep.c, solib-irix.c, solib-irix.h:
	Delete files.

gdb/testsuite/
2014-10-10  Pedro Alves  <palves@redhat.com>

	* gdb.base/bigcore.exp: Remove references to IRIX.
	* gdb.base/funcargs.exp: Likewise.
	* gdb.base/interrupt.exp: Likewise.
	* gdb.base/mips_pro.exp: Likewise.
	* gdb.base/nodebug.exp: Likewise.
	* gdb.base/setvar.exp: Likewise.
	* lib/gdb.exp (gdb_compile_shlib): Remove mips-sgi-irix* case.
2014-10-10 18:18:52 +01:00
Ajit Kumar Agarwal cc3afae25a Microblaze: Reject invalid target descriptions
We currently validate the target description, but then forget to
reject it if found invalid.

Tested that incorrect descriptions are rejected and GDB warns about
them.

Tested the Microblaze Design with and without stack-protect registers.
The gdb command "info registers" displayed the register correctly.  If
a stack protect design is not selected, only core registers are
displayed.  When the stack-protect registers are selected in the
design, the core registers along with stack-protect registers are
displayed.

gdb/
2014-10-10  Ajit Agarwal  <ajitkum@xilinx.com>

	* microblaze-tdep.c (microblaze_gdbarch_init): If the description
	isn't valid, release the tdesc arch data and return NULL.
2014-10-10 18:07:06 +01:00
Pedro Alves cdfa0b0ac1 Cache the vsyscall/vDSO range per-inferior
We're now doing a vsyscall/vDSO address range lookup whenever we fetch
shared libraries, either through an explicit "info shared", or when
the target reports new libraries have been loaded, in order to filter
out the vDSO from glibc's DSO list.  Before we started doing that, GDB
would only ever lookup the vsyscall's address range once in the
process's lifetime.

Looking up the vDSO address range requires an auxv lookup (which is
already cached, so no problem), but also reading the process's
mappings from /proc to find out the vDSO's mapping's size.  That
generates extra RSP traffic when remote debugging.  Particularly
annoying when the process's mappings grow linearly as more libraries
are mapped in, and we went through the trouble of making incremental
DSO list updates work against gdbserver (when the probes-based dynamic
linker interface is available).

The vsyscall/vDSO is mapped by the kernel when the process is
initially mapped in, and doesn't change throughout the process's
lifetime, so we can cache its address range.

Caching at this level brings GDB back to one and only one vsyscall
address range lookup per process.

Tested on x86_64 Fedora 20.

gdb/
2014-10-10  Pedro Alves  <palves@redhat.com>

	* linux-tdep.c: Include observer.h.
	(linux_inferior_data): New global.
	(struct linux_info): New structure.
	(invalidate_linux_cache_inf, linux_inferior_data_cleanup)
	(get_linux_inferior_data): New functions.
	(linux_vsyscall_range): Rename to ...
	(linux_vsyscall_range_raw): ... this.
	(linux_vsyscall_range): New function; handles caching.
	(_initialize_linux_tdep): Register linux_inferior_data.  Install
	inferior_exit and inferior_appeared observers.
2014-10-10 16:36:38 +01:00
Pedro Alves 8b9a549d3a PR symtab/14466: Work around PR libc/13097 "linux-vdso.so.1"
With upstream glibc, GDB prints:

  warning: Could not load shared library symbols for linux-vdso.so.1.
  Do you need "set solib-search-path" or "set sysroot"?

A bug's been filed for glibc a few years back:

  http://sourceware.org/bugzilla/show_bug.cgi?id=13097

but it's still not resolved.  It's not clear whether there's even
consensus that this is indeed a glibc bug.  It would actually be nice
if GDB also listed the vDSO in the shared library list, but there are
some design considerations with that:

 - the vDSO is mapped by the kernel, not userspace, therefore we
   should load its symbols right from the process's start of life,
   even before glibc / the userspace loader sets up the initial DSO
   list.  The program might even be using a custom loader or no
   loader.

 - that kind of hints at that solib.c should handle retrieving shared
   library lists from more than one source, and that symfile-mem.c's
   loading of the vDSO would be converted to load and relocate the
   vDSO's bfd behind the target_so_ops interface.

 - and then, once glibc links in the vDSO to its DSO list, we'd need
   to either:

    a) somehow hand over the vDSO from one target_so_ops to the other

    b) simply keep hiding glibc's entry.

And then b) seems the simplest.

With that in mind, this patch simply discards the vDSO from glibc's
reported shared library list.

We can match the vDSO address range with the addresses found iterating
the dynamic linker list, to tell which dynamic linker entry is the
vDSO.

Tested on x86_64 Fedora 20.

gdb/
2014-10-10  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	PR symtab/14466
	* solib-svr4.c (svr4_read_so_list): Rename to ...
	(svr4_current_sos_1): ... this and change the function comment.
	(svr4_current_sos): New function.

gdb/testsuite/
2014-10-10  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	PR symtab/14466
	* gdb.base/vdso-warning.c: New file.
	* gdb.base/vdso-warning.exp: New file.
2014-10-10 16:30:59 +01:00
Pedro Alves 3437254d7b Split vDSO range lookup to a gdbarch hook
We have a case in solib-svr4.c where we could reuse symfile-mem.c's
vDSO range lookup.  Since symfile-mem.c is not present in all
configurations solib-svr4.c is, move that lookup to a gdbarch hook.

This has the minor (good) side effect that we stop even trying the
target_auxv_search lookup against targets that don't have a concept of
a vDSO, in case symfile-mem.c happens to be linked in the build
(--enable-targets=all).

Tested on x86_64 Fedora 20.

gdb/
2014-10-10  Pedro Alves  <palves@redhat.com>

	* arch-utils.c (default_vsyscall_range): New function.
	* arch-utils.h (default_vsyscall_range): New declaration.
	* gdbarch.sh (vsyscall_range): New hook.
	* gdbarch.h, gdbarch.c: Regenerate.
	* linux-tdep.c (linux_vsyscall_range): New function.
	(linux_init_abi): Install linux_vsyscall_range as
	vsyscall_range gdbarch hook.
	* memrange.c (address_in_mem_range): New function.
	* memrange.h (address_in_mem_range): New declaration.
	* symfile-mem.c (find_vdso_size): Delete function.
	(add_vsyscall_page): Use gdbarch_vsyscall_range.
2014-10-10 15:57:13 +01:00
Pedro Alves 31cc0b807b infrun.c:normal_stop: Fix typo in comment
gdb/
2014-10-10  Pedro Alves  <palves@redhat.com>

	* infrun.c (normal_stop): Fix typo in comment.
2014-10-10 13:50:05 +01:00
Sergio Durigan Junior 3e3286a28a PR tdep/9390: Fix typo on xstorxstormy16-tdep.c
This patch fixes the bug described in PR tdep/9390, which is about a
wrong check in the following code:

    ...

    /* optional copying of args in r2-r7 to r10-r13.  */
    /* Probably only in optimized case but legal action for prologue.  */
    else if ((inst & 0xff00) == 0x4600	/* 46SD   mov rD, rS */
	     && (inst & 0x00f0) >= 0x0020 && (inst & 0x00f0) <= 0x0070
	     && (inst & 0x000f) >= 0x00a0 && (inst & 0x000f) <= 0x000d)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
    ...

This condition will never trigger, and the fix proposed in the bug
(which made sense to me) was to test against 0x000a.  I tried finding
documentation about this target, but couldn't find anything.  I don't
even know if it is still used, but decided to submit the fix anyway.

Tested on my x86_64 Fedora 20 GNU/Linux.

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

	PR tdep/9390
	* xstorxstormy16-tdep.c (xstormy16_analyze_prologue): Fix possible
	typo when using logical AND to determine instruction type.
2014-10-09 13:45:09 -04:00
Yao Qi fcbdedf866 Remove unused local variable
As a result of commit b57bacec, local variable 'printed' is no longer
used.  This patch is to remove it.

gdb:

2014-10-09  Yao Qi  <yao@codesourcery.com>

	* infrun.c (handle_signal_stop): Remove local variable 'printed'.
2014-10-09 09:48:42 +08:00
Stan Shebs db98461618 Add Yao Qi as global maintainer
gdb/ChangeLog:

2014-10-08  Stan Shebs  <stan@codesourcery.com>

	    * MAINTAINERS (GLOBAL MAINTAINERS): Add Yao Qi.
2014-10-08 11:23:16 -07:00
Gary Benson 3ba37e6c30 Do not include unnecessary files in fbsd-tdep.c
This commit makes fbsd-tdep.c not include string.h or gdb_assert.h
as both are already included by defs.h.

gdb/ChangeLog:

	* fbsd-tdep.c: Do not include string.h or gdb_assert.h.
2014-10-08 09:52:38 +01:00
Gary Benson a442d0713a Include common-exceptions.h in common-defs.h
This commit includes common-exceptions.h in common-defs.h and removes
all other inclusions.

gdb/ChangeLog:

	* common/common-defs.h: Include common-exceptions.h.
	* exceptions.h: Do not include common-exceptions.h.

gdb/gdbserver/ChangeLog:

	* server.h: Do not include common-exceptions.h.
2014-10-08 09:33:22 +01:00
Gary Benson 6f1947e8a2 Include cleanups.h in common-defs.h
This commit includes cleanups.h in common-defs.h and removes all other
inclusions.

gdb/ChangeLog:

	* common/common-defs.h: Include cleanups.h.
	* common/common-exceptions.c: Do not include cleanups.h.
	* utils.h: Likewise.

gdb/gdbserver/ChangeLog:

	* server.h: Do not include cleanups.h.
2014-10-08 09:33:22 +01:00
Gary Benson c765fdb902 Remove spurious exceptions.h inclusions
defs.h includes utils.h, and utils.h includes exceptions.h.  All GDB
.c files include defs.h as their first line, so no file other than
utils.h needs to include exceptions.h.  This commit removes all such
inclusions.

gdb/ChangeLog:

	* ada-lang.c: Do not include exceptions.h.
	* ada-valprint.c: Likewise.
	* amd64-tdep.c: Likewise.
	* auto-load.c: Likewise.
	* block.c: Likewise.
	* break-catch-throw.c: Likewise.
	* breakpoint.c: Likewise.
	* btrace.c: Likewise.
	* c-lang.c: Likewise.
	* cli/cli-cmds.c: Likewise.
	* cli/cli-interp.c: Likewise.
	* cli/cli-script.c: Likewise.
	* completer.c: Likewise.
	* corefile.c: Likewise.
	* corelow.c: Likewise.
	* cp-abi.c: Likewise.
	* cp-support.c: Likewise.
	* cp-valprint.c: Likewise.
	* darwin-nat.c: Likewise.
	* dwarf2-frame-tailcall.c: Likewise.
	* dwarf2-frame.c: Likewise.
	* dwarf2loc.c: Likewise.
	* dwarf2read.c: Likewise.
	* eval.c: Likewise.
	* event-loop.c: Likewise.
	* event-top.c: Likewise.
	* f-valprint.c: Likewise.
	* frame-unwind.c: Likewise.
	* frame.c: Likewise.
	* gdbtypes.c: Likewise.
	* gnu-v2-abi.c: Likewise.
	* gnu-v3-abi.c: Likewise.
	* guile/scm-auto-load.c: Likewise.
	* guile/scm-breakpoint.c: Likewise.
	* guile/scm-cmd.c: Likewise.
	* guile/scm-frame.c: Likewise.
	* guile/scm-lazy-string.c: Likewise.
	* guile/scm-param.c: Likewise.
	* guile/scm-symbol.c: Likewise.
	* guile/scm-type.c: Likewise.
	* hppa-hpux-tdep.c: Likewise.
	* i386-tdep.c: Likewise.
	* inf-loop.c: Likewise.
	* infcall.c: Likewise.
	* infcmd.c: Likewise.
	* infrun.c: Likewise.
	* interps.c: Likewise.
	* interps.h: Likewise.
	* jit.c: Likewise.
	* linespec.c: Likewise.
	* linux-nat.c: Likewise.
	* linux-thread-db.c: Likewise.
	* m32r-rom.c: Likewise.
	* main.c: Likewise.
	* memory-map.c: Likewise.
	* mi/mi-cmd-break.c: Likewise.
	* mi/mi-cmd-stack.c: Likewise.
	* mi/mi-interp.c: Likewise.
	* mi/mi-main.c: Likewise.
	* monitor.c: Likewise.
	* nto-procfs.c: Likewise.
	* objc-lang.c: Likewise.
	* p-valprint.c: Likewise.
	* parse.c: Likewise.
	* ppc-linux-tdep.c: Likewise.
	* printcmd.c: Likewise.
	* probe.c: Likewise.
	* python/py-auto-load.c: Likewise.
	* python/py-breakpoint.c: Likewise.
	* python/py-cmd.c: Likewise.
	* python/py-finishbreakpoint.c: Likewise.
	* python/py-frame.c: Likewise.
	* python/py-framefilter.c: Likewise.
	* python/py-function.c: Likewise.
	* python/py-gdb-readline.c: Likewise.
	* python/py-inferior.c: Likewise.
	* python/py-infthread.c: Likewise.
	* python/py-lazy-string.c: Likewise.
	* python/py-linetable.c: Likewise.
	* python/py-param.c: Likewise.
	* python/py-prettyprint.c: Likewise.
	* python/py-symbol.c: Likewise.
	* python/py-type.c: Likewise.
	* python/py-value.c: Likewise.
	* python/python-internal.h: Likewise.
	* python/python.c: Likewise.
	* record-btrace.c: Likewise.
	* record-full.c: Likewise.
	* regcache.c: Likewise.
	* remote-fileio.c: Likewise.
	* remote-mips.c: Likewise.
	* remote.c: Likewise.
	* rs6000-aix-tdep.c: Likewise.
	* rs6000-nat.c: Likewise.
	* skip.c: Likewise.
	* solib-darwin.c: Likewise.
	* solib-dsbt.c: Likewise.
	* solib-frv.c: Likewise.
	* solib-ia64-hpux.c: Likewise.
	* solib-spu.c: Likewise.
	* solib-svr4.c: Likewise.
	* solib.c: Likewise.
	* spu-tdep.c: Likewise.
	* stack.c: Likewise.
	* stap-probe.c: Likewise.
	* symfile-mem.c: Likewise.
	* symmisc.c: Likewise.
	* target.c: Likewise.
	* thread.c: Likewise.
	* top.c: Likewise.
	* tracepoint.c: Likewise.
	* tui/tui-interp.c: Likewise.
	* typeprint.c: Likewise.
	* utils.c: Likewise.
	* valarith.c: Likewise.
	* valops.c: Likewise.
	* valprint.c: Likewise.
	* value.c: Likewise.
	* varobj.c: Likewise.
	* windows-nat.c: Likewise.
	* xml-support.c: Likewise.
2014-10-08 09:33:22 +01:00
Maciej W. Rozycki 484933d11f MIPS: Rewrite `add_offset_16' to match its name
A helper function called `add_offset_16' is used by
`extended_mips16_next_pc' to calculate branch destinations.  Weirdly
enough the helper does not do what the name suggests and rather than
doing its work for a 16-bit immediate branch offset it makes its
calculations on a 26-bit immediate target used by JAL and JALX
instructions.  Furthermore the JAL/JALX calculation is only needed once
by `extended_mips16_next_pc' while a 16-bit branch offset calculation
is made inline several times across `extended_mips16_next_pc'.

This change therefore replaces the contents of `add_offset_16' with the
16-bit branch offset calculation and updates `extended_mips16_next_pc'
accordingly.

	* mips-tdep.c (add_offset_16): Rewrite to implement what the
	name implies.
	(extended_mips16_next_pc): Update accordingly.
2014-10-05 23:37:53 +01:00
Maciej W. Rozycki ab50adb6a6 MIPS: Correct heuristic prologue termination conditions
This change addresses a regression in gdb.dwarf2/dw2-skip-prologue.exp
across MIPS16 multilibs:

(gdb) file .../gdb.dwarf2/dw2-skip-prologue
Reading symbols from .../gdb.d/gdb.dwarf2/dw2-skip-prologue...done.
(gdb) delete breakpoints
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break main
warning: Breakpoint address adjusted from 0x00400725 to 0x00400721.
Breakpoint 1 at 0x400721
(gdb) set remotetimeout 5
(gdb) kill
The program is not being run.
(gdb)
[...]
target remote ...:2345
Reading symbols from .../mips16/lib/ld.so.1...done.
warning: Breakpoint address adjusted from 0x00400725 to 0x00400721.
warning: Breakpoint address adjusted from 0x00400725 to 0x00400721.
0x2aaa8e81 in __start () from .../mips16/lib/ld.so.1
(gdb) continue
Continuing.
warning: Breakpoint address adjusted from 0x00400725 to 0x00400721.
warning: Breakpoint 1 address previously adjusted from 0x00400725 to
0x00400721.
Breakpoint 1, 0x00400721 in main ()
(gdb) break func
Breakpoint 2 at 0x4006a1: func. (2 locations)
(gdb) continue
Continuing.
warning: GDB can't find the start of the function at 0x4006dd.

    GDB is unable to find the start of the function at 0x4006dd
and thus can't determine the size of that function's stack frame.
This means that GDB may be unable to access that stack frame, or
the frames below it.
    This problem is most likely caused by an invalid program counter or
stack pointer.
    However, if you think GDB should simply search farther back
from 0x4006dd for code which looks like the beginning of a
function, you can increase the range of the search using the `set
heuristic-fence-post' command.

Program received signal SIGBUS, Bus error.
0x0040072b in main ()
(gdb) FAIL: gdb.dwarf2/dw2-skip-prologue.exp: continue to breakpoint: func

-- notice the breakpoint adjustment messages that are already a bad
sign.  These happen when a breakpoint is requested in a branch delay
slot and are not supposed to happen unless explicitly requested with an
address pointing to a branch delay slot instruction.  No symbol or line
debug information is supposed to direct GDB to place a breakpoint in a
delay slot.

Here's how `main' looks like:

00400718 <main>:
  400718:	64f5      	save	40,ra,s0-s1
  40071a:	1a00 01a8 	jal	4006a0 <func>
  40071e:	0104      	addiu	s1,sp,16
  400720:	1a00 01b7 	jal	4006dc <func+0x3c>
  400724:	6702      	move	s0,v0
  400726:	e049      	addu	v0,s0,v0
  400728:	65b9      	move	sp,s1
  40072a:	6473      	restore	24,ra,s0-s1
  40072c:	e8a0      	jrc	ra
  40072e:	6500      	nop

-- so 0x400725 is the MIPS16 instruction address of the first MOVE
instruction seen above, in a delay slot of the preceding JAL instruction
indeed.  This test case arranges for `main' to have no debug information
so it is one of the heuristic prologue scanners, `mips16_scan_prologue'
specifically in this case, that is responsible for finding the right
location for the breakpoint to place.

In this case the prologue really ends with the ADDIU instruction,
reordered into the delay slot of the first JAL instruction.  Of course
we can't place the breakpoint for `main' after it as by doing so we'll
let `func' to be called before hitting this breakpoint.  So the
breakpoint has to go at the JAL instruction instead, or 0x40071b.

To make a general case out of it we must never consider any jump or
branch instruction to be a part of a function's prologue.  In the
presence of a jump or branch at the beginning of a function the furthest
instruction examined for the purpose of constructing frame information
can be one in the delay slot of that jump or branch if present, and
otherwise -- that is when the jump or branch is compact and has no delay
slot -- the instruction immediately preceding the jump or branch.

This change implements that approach across prologue scanners for the
three instruction ISAs.  In implementing it I have factored out code
from the existing `*_instruction_has_delay_slot' handlers to be shared
and a side effect for the microMIPS implementation is it now always
fetches the second 16-bit halfword of 32-bit instructions even if it
eventually is not going to be needed.  I think it's an acceptable
tradeoff for the purpose of code sharing.

To make things more consistent I also carried logic from
`micromips_scan_prologue' over to the other two scanners to accept (and
ignore) a single non-prologue non-control transfer instruction reordered
by the compiler into the prologue.  While doing this I simplified the
exit path from the scan loop such that `end_prologue_addr' is set only
once.  This made some concerns expressed in comments no longer
applicable, although even before they were not valid.

I have not fixed the logic around `load_immediate_bytes' in
`mips32_scan_prologue' though, it remains broken, although I took care
not to break it more.  An approach similar to one taken for handling
larger stack adjustments in `micromips_scan_prologue' will have to be
eventually implemented here.

For regression testing I used my usual choice of the mips-linux-gnu
target and the following multilibs:

-EB
-EB -msoft-float
-EB -mips16
-EB -mips16 -msoft-float
-EB -mmicromips
-EB -mmicromips -msoft-float
-EB -mabi=n32
-EB -mabi=n32 -msoft-float
-EB -mabi=64
-EB -mabi=64 -msoft-float

and the -EL variants of same.

That removed gdb.dwarf2/dw2-skip-prologue.exp failures across MIPS16
multilibs, the test log now shows:

(gdb) file .../gdb.dwarf2/dw2-skip-prologue
Reading symbols from .../gdb.d/gdb.dwarf2/dw2-skip-prologue...done.
(gdb) delete breakpoints
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break main
Breakpoint 1 at 0x40071b
(gdb) set remotetimeout 5
(gdb) kill
The program is not being run.
(gdb)
[...]
target remote ...:2345
Reading symbols from .../mips16/lib/ld.so.1...done.
0x2aaa8e81 in __start () from .../mips16/lib/ld.so.1
(gdb) continue
Continuing.

Breakpoint 1, 0x0040071b in main ()
(gdb) break func
Breakpoint 2 at 0x4006a1: func. (2 locations)
(gdb) continue
Continuing.

Breakpoint 2, func (param=0) at main.c:5
5	   This program is free software; you can redistribute it and/or modify
(gdb) PASS: gdb.dwarf2/dw2-skip-prologue.exp: continue to breakpoint: func

-- so things look like intended.

That also did regress, again across MIPS16 multilibs, another test case,
gdb.base/step-symless.exp:

(gdb) file .../gdb.d/gdb.base/step-symless
Reading symbols from .../gdb.base/step-symless...done.
(gdb) delete breakpoints
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break main
Breakpoint 1 at 0x4006d3
(gdb) set remotetimeout 5
(gdb) kill
The program is not being run.
(gdb)
[...]
target remote ...:2345
Reading symbols from .../mips16/lib/ld.so.1...done.
0x2aaa8e81 in __start () from .../mips16/lib/ld.so.1
(gdb) continue
Continuing.

Breakpoint 1, 0x004006d3 in main ()
(gdb) break symful
Breakpoint 2 at 0x4006a5
(gdb) step
Single stepping until exit from function main,
which has no line number information.
warning: GDB can't find the start of the function at 0x4006b9.

    GDB is unable to find the start of the function at 0x4006b9
and thus can't determine the size of that function's stack frame.
This means that GDB may be unable to access that stack frame, or
the frames below it.
    This problem is most likely caused by an invalid program counter or
stack pointer.
    However, if you think GDB should simply search farther back
from 0x4006b9 for code which looks like the beginning of a
function, you can increase the range of the search using the `set
heuristic-fence-post' command.
0x004006b9 in ?? ()
(gdb) FAIL: gdb.base/step-symless.exp: step

-- but that is actually a good sign.  Here `main', again, has no debug
information and code involved looks like:

004006a0 <symful>:
  4006a0:	6491      	save	8,s1
  4006a2:	673d      	move	s1,sp
  4006a4:	b204      	lw	v0,4006b4 <symful+0x14>
  4006a6:	9a40      	lw	v0,0(v0)
  4006a8:	4261      	addiu	v1,v0,1
  4006aa:	b203      	lw	v0,4006b4 <symful+0x14>
  4006ac:	da60      	sw	v1,0(v0)
  4006ae:	65b9      	move	sp,s1
  4006b0:	6411      	restore	8,s1
  4006b2:	e8a0      	jrc	ra
  4006b4:	0041      	addiu	s0,sp,260
  4006b6:	0860      	la	s0,400834 <__libc_start_main@mips16plt+0x54>
  4006b8:	6491      	save	8,s1
  4006ba:	673d      	move	s1,sp
  4006bc:	b204      	lw	v0,4006cc <symful+0x2c>
  4006be:	9a40      	lw	v0,0(v0)
  4006c0:	4261      	addiu	v1,v0,1
  4006c2:	b203      	lw	v0,4006cc <symful+0x2c>
  4006c4:	da60      	sw	v1,0(v0)
  4006c6:	65b9      	move	sp,s1
  4006c8:	6411      	restore	8,s1
  4006ca:	e8a0      	jrc	ra
  4006cc:	0041      	addiu	s0,sp,260
  4006ce:	0860      	la	s0,40084c <__libc_start_main@mips16plt+0x6c>

004006d0 <main>:
  4006d0:	64d4      	save	32,ra,s1
  4006d2:	1a00 01ae 	jal	4006b8 <symful+0x18>
  4006d6:	0104      	addiu	s1,sp,16
  4006d8:	1a00 01a8 	jal	4006a0 <symful>
  4006dc:	6500      	nop
  4006de:	6740      	move	v0,zero
  4006e0:	65b9      	move	sp,s1
  4006e2:	6452      	restore	16,ra,s1
  4006e4:	e8a0      	jrc	ra
  4006e6:	6500      	nop
  4006e8:	6500      	nop
  4006ea:	6500      	nop
  4006ec:	6500      	nop
  4006ee:	6500      	nop

-- and the original log:

(gdb) file .../gdb.base/step-symless
Reading symbols from .../gdb.base/step-symless...done.
(gdb) delete breakpoints
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break main
warning: Breakpoint address adjusted from 0x004006dd to 0x004006d9.
Breakpoint 1 at 0x4006d9
(gdb) set remotetimeout 5
(gdb) kill
The program is not being run.
(gdb)
[...]
target remote ...:2345
Reading symbols from .../mips16/lib/ld.so.1...done.
warning: Breakpoint address adjusted from 0x004006dd to 0x004006d9.
warning: Breakpoint address adjusted from 0x004006dd to 0x004006d9.
0x2aaa8e81 in __start () from .../mips16/lib/ld.so.1
(gdb) continue
Continuing.
warning: Breakpoint address adjusted from 0x004006dd to 0x004006d9.
warning: Breakpoint 1 address previously adjusted from 0x004006dd to
0x004006d9.
Breakpoint 1, 0x004006d9 in main ()
(gdb) break symful
Breakpoint 2 at 0x4006a5
(gdb) step
Single stepping until exit from function main,
which has no line number information.

Breakpoint 2, 0x004006a5 in symful ()
(gdb) PASS: gdb.base/step-symless.exp: step

So the breakpoint at `main' was actually set at an instruction after the
call to `symful+0x18' aka `symless' and the test only passed because
single-stepping through `symless' wasn't actually done at all.  With
this change in place this test fails for MIPS16 multilibs consistently
with all the other multilibs where it already failed in this manner
previously.

	* mips-tdep.c (mips16_instruction_is_compact_branch): New
	function.
	(micromips_instruction_is_compact_branch): Likewise.
	(mips16_scan_prologue): Terminate scanning upon seeing a branch
	or a compact jump, reaching a jump delay slot, or seeing a
	second non-prologue instruction.
	(micromips_scan_prologue): Also terminate scanning upon seeing a
	compact branch or jump, or reaching a branch or jump delay slot.
	(mips32_scan_prologue): Terminate scanning upon reaching a branch
	or jump delay slot, or seeing a second non-prologue instruction.
	(mips32_instruction_has_delay_slot): Retain instruction
	examination code only, update arguments accordingly and move
	instruction fetch pieces to...
	(mips32_insn_at_pc_has_delay_slot): ... this new function.
	(micromips_instruction_has_delay_slot): Likewise and to...
	(micromips_insn_at_pc_has_delay_slot): ... this new function.
	(mips16_instruction_has_delay_slot): Likewise and to...
	(mips16_insn_at_pc_has_delay_slot): ... this new function.
	(mips_single_step_through_delay): Update accordingly.
	(mips_adjust_breakpoint_address): Likewise.
2014-10-05 23:20:10 +01:00
Maciej W. Rozycki ae79065284 MIPS: Correct MUSTBE32 interpretation in delay slot handling
This change addresses `micromips_instruction_has_delay_slot' and
`mips16_instruction_has_delay_slot' that both incorrectly interpret
their MUSTBE32 argument.  Their callers assume that when the flag is
clear these functions will return 1 when any non-compact jump or branch
instruction is present at ADDR, while in fact they will only return 1
for 16-bit such instructions only.  This change makes the implementation
match the expectations.

	* mips-tdep.c (micromips_instruction_has_delay_slot): When
	!mustbe32 also return 1 for 32-bit instructions.
	(mips16_instruction_has_delay_slot): Likewise.  Add an
	explanatory comment.
2014-10-05 21:50:47 +01:00
Maciej W. Rozycki 9b807e7bbb Also mark ELF solib trampoline minimal symbols special
In installing minimal symbols for ELF shared library trampolines
we "forget" to make individual symbols special where required.  This
leads to problems on the MIPS target using microMIPS SVR4 lazy stubs.
Lacking the special annotation these stubs are treated as standard
MIPS code and this makes GDB insert the wrong software breakpoint
instruction, breaking e.g. single-stepping through these stubs.  This
is not a very frequent scenario as microMIPS SVR4 lazy stubs are
typically only used in shared libraries with the main executable
using PLT, handled elsewhere.  Still it triggers e.g. when a software
watchpoint has been installed.  The symptom is SIGILL or the program
going astray, depending on the endianness.  Disassembly of these stubs
is also wrong.

	* elfread.c (elf_symtab_read): Also mark solib trampoline minimal
	symbols special.
2014-10-03 17:38:39 +01:00
Maciej W. Rozycki 0d5ed15352 Avoid software breakpoint's instruction shadow inconsistency
This change:

commit b775012e84
Author: Luis Machado <luisgpm@br.ibm.com>
Date:   Fri Feb 24 15:10:59 2012 +0000

    2012-02-24  Luis Machado  <lgustavo@codesourcery.com>

	* remote.c (remote_supports_cond_breakpoints): New forward
	declaration.
[...]

changed the way breakpoints are inserted and removed such that
`insert_bp_location' can now be called with the breakpoint being handled
already in place, while previously the call was only ever made for
breakpoints that have not been put in place.  This in turn caused an
issue for software breakpoints and targets for which a breakpoint's
`placed_address' may not be the same as the original requested address.

The issue is `insert_bp_location' overwrites the previously adjusted
value in `placed_address' with the original address, that is only
replaced back with the correct adjusted address later on when
`gdbarch_breakpoint_from_pc' is called.  Meanwhile there's a window
where the value in `placed_address' does not correspond to data stored
in `shadow_contents', leading to incorrect instruction bytes being
supplied when `one_breakpoint_xfer_memory' is called to supply the
instruction overlaid by the breakpoint.

And this is exactly what happens on the MIPS target with software
breakpoints placed in microMIPS code.  In this case not only
`placed_address' is not the original address because of the ISA bit, but
`mips_breakpoint_from_pc' has to read the original instruction to
determine which one of the two software breakpoint instruction encodings
to choose as well.  The 16-bit encoding is used to replace 16-bit
instructions and similarly the 32-bit one is used with 32-bit
instructions, to satisfy branch delay slot size requirements.

The mismatch between `placed_address' and the address data in
`shadow_contents' has been obtained from leads to the wrong encoding
being used in some cases, which in the case of a 32-bit software
breakpoint instruction replacing a 16-bit instruction causes corruption
to the adjacent following instruction and leads the debug session astray
if execution reaches there e.g. with a jump.

To address this problem I made the change below, that adds a
`reqstd_address' field to `struct bp_target_info' and leaves
`placed_address' unchanged once it has been set.  This ensures data in
`shadow_contents' is always consistent with `placed_address'.

This approach also has this good side effect that all the places that
examine the breakpoint's address see a consistent value, either
`reqstd_address' or `placed_address', as required.  Currently some
places see either the original or the adjusted address in
`placed_address', depending on whether they have been called before
`gdbarch_remote_breakpoint_from_pc' or afterwards.  This is in
particular true for subsequent calls to
`gdbarch_remote_breakpoint_from_pc' itself, e.g. from
`one_breakpoint_xfer_memory'.  This is also important for places like
`find_single_step_breakpoint' where a breakpoint's address is compared
to the raw value of $pc.

	* breakpoint.h (bp_target_info): Add `reqstd_address' member,
	update comments.
	* breakpoint.c (one_breakpoint_xfer_memory): Use `reqstd_address'
	for the breakpoint's address.  Don't preinitialize `placed_size'.
	(insert_bp_location): Set `reqstd_address' rather than
	`placed_address'.
	(bp_target_info_copy_insertion_state): Also copy `placed_address'.
	(bkpt_insert_location): Use `reqstd_address' for the breakpoint's
	address.
	(bkpt_remove_location): Likewise.
	(deprecated_insert_raw_breakpoint): Likewise.
	(deprecated_remove_raw_breakpoint): Likewise.
	(find_single_step_breakpoint): Likewise.
	* mem-break.c (default_memory_insert_breakpoint): Use
	`reqstd_address' for the breakpoint's address.  Don't set
	`placed_address' or `placed_size' if breakpoint contents couldn't
	have been determined.
	* remote.c (remote_insert_breakpoint): Use `reqstd_address' for
	the breakpoint's address.
	(remote_insert_hw_breakpoint): Likewise.  Don't set
	`placed_address' or `placed_size' if breakpoint couldn't have been
	set.
	* aarch64-linux-nat.c (aarch64_linux_insert_hw_breakpoint): Use
	`reqstd_address' for the breakpoint's address.
	* arm-linux-nat.c (arm_linux_hw_breakpoint_initialize): Likewise.
	* ia64-tdep.c (ia64_memory_insert_breakpoint): Likewise.
	* m32r-tdep.c (m32r_memory_insert_breakpoint): Likewise.
	* microblaze-linux-tdep.c
	(microblaze_linux_memory_remove_breakpoint): Likewise.
	* monitor.c (monitor_insert_breakpoint): Likewise.
	* nto-procfs.c (procfs_insert_breakpoint): Likewise.
	(procfs_insert_hw_breakpoint): Likewise.
	* ppc-linux-nat.c (ppc_linux_insert_hw_breakpoint): Likewise.
	* ppc-linux-tdep.c (ppc_linux_memory_remove_breakpoint): Likewise.
	* remote-m32r-sdi.c (m32r_insert_breakpoint): Likewise.
	* remote-mips.c (mips_insert_breakpoint): Likewise.
	* x86-nat.c (x86_insert_hw_breakpoint): Likewise.
2014-10-03 12:54:34 +01:00
Luis Machado 3e87153251 MIPS bit field failures in gdb.base/store.exp
On MIPS64 little endian, attempting an assignment to a bit field
that lives in a register yields the wrong result. It just corrupts
the data in the register depending on the specific position of the
bit field inside the structure.

FAIL: gdb.base/store.exp: f_1.j
FAIL: gdb.base/store.exp: f_1.k
FAIL: gdb.base/store.exp: F_1.i
FAIL: gdb.base/store.exp: F_1.j
FAIL: gdb.base/store.exp: F_1.k
FAIL: gdb.base/store.exp: f_2.j
FAIL: gdb.base/store.exp: f_2.k
FAIL: gdb.base/store.exp: F_2.i
FAIL: gdb.base/store.exp: F_2.j
FAIL: gdb.base/store.exp: F_2.k
FAIL: gdb.base/store.exp: f_3.j
FAIL: gdb.base/store.exp: f_3.k
FAIL: gdb.base/store.exp: F_3.i
FAIL: gdb.base/store.exp: F_3.j
FAIL: gdb.base/store.exp: F_3.k
FAIL: gdb.base/store.exp: f_4.j
FAIL: gdb.base/store.exp: f_4.k
FAIL: gdb.base/store.exp: F_4.i
FAIL: gdb.base/store.exp: F_4.j
FAIL: gdb.base/store.exp: F_4.k

                === gdb Summary ===

Now, GDB knows how to do bit field assignment properly, but MIPS is
one of those architectures that uses a hook for the register-to-value
conversion. Although we can properly tell when the type being passed
is a structure or union, we cannot tell when it is a bit field,
because the bit field data lives in a value structure.  Such data
only lives in a "type" structure when the parent structure is being
referenced, thus you can collect them from the flds_bnds members.

A bit field type structure looks pretty much the same as any other
primitive type like int or char, so we can't distinguish them.
Forcing more fields into the type structure wouldn't help much,
because the type structs are shared.

2014-10-03  Luis Machado  <lgustavo@codesourcery.com>

	* valops.c (value_assign): Check for bit field assignments
	before calling architecture-specific register value
	conversion functions.
2014-10-03 08:21:33 -03:00
Pierre Muller ec48dc8bd4 [RFA] Stabs: Ignore N_BNSYM/N_ENSYM entry types
Trying to debug gdb with itself,
I stumbled on the following complaints
Unknown symbol type 0x2e
or
Unknown symbol type 0x4e

It appears that those corrspond to N_BNSYM and N_ENSYM,
which are MacOS extensions of stabs debugging format.
But these extensions have been used inside gcc probalby
for a while already, see:
https://gcc.gnu.org/ml/gcc/2004-08/msg00157.html

As the only purpose of these entries is to allow for removal
of stabs information if the function is removed,
it can be safely ignored by GDB.

This patch simply adds those two entry types to the list
of ignored entry type in read_dbx_symtab function.

Is this OK?

Pierre Muller

2014-10-03  Pierre Muller  <muller@sourceware.org>

	* dbxread.c (read_dbx_symtab): Also ignore N_BNSYM/N_ENSYM.
2014-10-03 09:29:57 +02:00
Doug Evans d48ba5e8cf gdb.base/structs.c (main): Don't run forever.
gdb/testsuite/ChangeLog:

	* gdb.base/structs.c (main): Don't run forever.
2014-10-02 13:07:40 -07:00
Pedro Alves 2278c276a8 gdb.threads/manythreads.exp: clean up and add comment
In git b57bacec, I said:

> With that in place, the need to delay "Program received signal FOO"
> was actually caught by the manythreads.exp test.  Without that bit, I
> was getting:
>
>   [Thread 0x7ffff7f13700 (LWP 4499) exited]
>   [New Thread 0x7ffff7f0b700 (LWP 4500)]
>   ^C
>   Program received signal SIGINT, Interrupt.
>   [New Thread 0x7ffff7f03700 (LWP 4501)]           <<< new output
>   [Switching to Thread 0x7ffff7f0b700 (LWP 4500)]
>   __GI___nptl_death_event () at events.c:31
>   31      {
>   (gdb) FAIL: gdb.threads/manythreads.exp: stop threads 1
>
> That is, I was now getting "New Thread" lines after the "Program
> received signal" line, and the test doesn't expect them.  As the
> number of new threads discovered before and after the "Program
> received signal" output is unbounded, it's much nicer to defer
> "Program received signal" until after synching the thread list, thus
> close to the "switching to thread" output and "current frame/source"
> info:
>
>   [Thread 0x7ffff7863700 (LWP 7647) exited]
>   ^C[New Thread 0x7ffff786b700 (LWP 7648)]
>
>   Program received signal SIGINT, Interrupt.
>   [Switching to Thread 0x7ffff7fc4740 (LWP 6243)]
>   __GI___nptl_create_event () at events.c:25
>   25      {
>   (gdb) PASS: gdb.threads/manythreads.exp: stop threads 1

This commit factors out the two places in the test that are effected
by this, and adds there a destilled version of the comment above.

gdb/testsuite/
2014-10-02  Pedro Alves  <palves@redhat.com>

	* gdb.threads/manythreads.exp (interrupt_and_wait): New procedure.
	(top level) <stop threads 1, stop threads 2>: Use it.
2014-10-02 10:13:56 +01:00
Pedro Alves b57bacecd5 Fix non-stop regressions caused by "breakpoints always-inserted off" changes
Commit a25a5a45 (Fix "breakpoint always-inserted off"; remove
"breakpoint always-inserted auto") regressed non-stop remote
debugging.

This was exposed by mi-nsintrall.exp intermittently failing with a
spurious SIGTRAP.

The problem is that when debugging with "target remote", new threads
the target has spawned but have never reported a stop aren't visible
to GDB until it explicitly resyncs its thread list with the target's.

For example, in a program like this:

 int
 main (void)
 {
   pthread_t child_thread;
   pthread_create (&child_thread, NULL, child_function, NULL);
   return 0;  <<<< set breakpoint here
 }

If the user sets a breakpoint at the "return" statement, and runs the
program, when that breakpoint hit is reported, GDB is only aware of
the main thread.  So if we base the decision to remove or insert
breakpoints from the target based on whether all the threads we know
about are stopped, we'll miss that child_thread is running, and thus
we'll remove breakpoints from the target, even through they should
still remain inserted, otherwise child_thread will miss them.

The break-while-running.exp test actually should also be exposing this
thread-list-out-of-synch problem.  That test sets a breakpoint while
the main thread is stopped, but other threads are running.  Because
other threads are running, the breakpoint is supposed to be inserted
immediately.  But, unless something forces a refetch of the thread
list, like, e.g., "info threads", GDB won't be aware of the other
threads that had been spawned by the main thread, and so won't insert
new or old breakpoints in the target.  And it turns out that the test
is exactly doing an explicit "info threads", masking out the
problem...  This commit adjust the test to exercise the case of not
issuing "info threads".  The test then fails without the GDB fix.

In the ni-nsintrall.exp case, what happens is that several threads hit
the same breakpoint, and when the first thread reports the stop,
because GDB wasn't aware other threads exist, all threads known to GDB
are found stopped, so GDB removes the breakpoints from the target.
The other threads follow up with SIGTRAPs too for that same
breakpoint, which has already been removed.  For the first few
threads, the moribund breakpoints machinery suppresses the SIGTRAPs,
but after a few events (precisely '3 * thread_count () + 1' at the
time the breakpoint was removed, see update_global_location_list), the
moribund breakpoint machinery is no longer aware of the removed
breakpoint, and the SIGTRAP is reported as a spurious stop.

The fix is naturally then to stop assuming that if no thread in the
list is executing, then the target is fully stopped.  We can't know
that until we fully sync the thread list.  Because updating the thread
list on every stop would be too much RSP traffic, I chose instead to
update it whenever we're about to present a stop to the user.

Actually updating the thread list at that point happens to be an item
I had added to the local/remote parity wiki page a while ago:

  Native GNU/Linux debugging adds new threads to the thread list as
  the program creates them "The [New Thread foo] messages". Remote
  debugging can't do that, and it's arguable whether we shouldn't even
  stop native debugging from doing that, as it hinders inferior
  performance. However, a related issue is that with remote targets
  (and gdbserver), even after the program stops, the user still needs
  to do "info threads" to pull an updated thread list. This, should
  most likely be addressed, so that GDB pulls the list itself, perhaps
  just before presenting a stop to the user.

With that in place, the need to delay "Program received signal FOO"
was actually caught by the manythreads.exp test.  Without that bit, I
was getting:

  [Thread 0x7ffff7f13700 (LWP 4499) exited]
  [New Thread 0x7ffff7f0b700 (LWP 4500)]
  ^C
  Program received signal SIGINT, Interrupt.
  [New Thread 0x7ffff7f03700 (LWP 4501)]           <<< new output
  [Switching to Thread 0x7ffff7f0b700 (LWP 4500)]
  __GI___nptl_death_event () at events.c:31
  31      {
  (gdb) FAIL: gdb.threads/manythreads.exp: stop threads 1

That is, I was now getting "New Thread" lines after the "Program
received signal" line, and the test doesn't expect them.  As the
number of new threads discovered before and after the "Program
received signal" output is unbounded, it's much nicer to defer
"Program received signal" until after synching the thread list, thus
close to the "switching to thread" output and "current frame/source"
info:

  [Thread 0x7ffff7863700 (LWP 7647) exited]
  ^C[New Thread 0x7ffff786b700 (LWP 7648)]

  Program received signal SIGINT, Interrupt.
  [Switching to Thread 0x7ffff7fc4740 (LWP 6243)]
  __GI___nptl_create_event () at events.c:25
  25      {
  (gdb) PASS: gdb.threads/manythreads.exp: stop threads 1

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-02  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (breakpoints_should_be_inserted_now): Use
	threads_are_executing.
	* breakpoint.h (breakpoints_should_be_inserted_now): Add
	describing comment.
	* gdbthread.h (threads_are_executing): Declare.
	(handle_signal_stop) <random signals>: Don't print about the
	signal here if stopping.
	(end_stepping_range): Don't notify observers here.
	(normal_stop): Update the thread list.  If stopped by a random
	signal or a stepping range ended, notify observers.
	* thread.c (threads_executing): New global.
	(init_thread_list): Clear 'threads_executing'.
	(set_executing): Set or clear 'threads_executing'.
	(threads_are_executing): New function.
	(update_threads_executing): New function.
	(update_thread_list): Use it.

gdb/testsuite/
2014-10-02  Pedro Alves  <palves@redhat.com>

	* gdb.threads/break-while-running.exp (test): Add new
	'update_thread_list' argument.  Skip "info threads" if false.
	(top level): Add new 'update_thread_list' axis.
2014-10-02 10:08:00 +01:00
Pedro Alves 13fd3ff343 PR17431: following execs with "breakpoint always-inserted on"
Following an exec with "breakpoint always-inserted on" tries to insert
breakpoints in the new image at the addresses the symbols had in the
old image.

With "always-inserted off", we see:

 gdb gdb.multi/multi-arch-exec -ex "set breakpoint always-inserted off"
 GNU gdb (GDB) 7.8.50.20140924-cvs
 ...
 (gdb) b main
 Breakpoint 1 at 0x400664: file gdb.multi/multi-arch-exec.c, line 24.
		 ^^^^^^^^
 (gdb) c
 The program is not being run.
 (gdb) r
 Starting program: testsuite/gdb.multi/multi-arch-exec

 Breakpoint 1, main () at gdb/testsuite/gdb.multi/multi-arch-exec.c:24
 24        execl (BASEDIR "/multi-arch-exec-hello",
 (gdb) c
 Continuing.
 process 9212 is executing new program: gdb/testsuite/gdb.multi/multi-arch-exec-hello

 Breakpoint 1, main () at gdb/testsuite/gdb.multi/hello.c:40
 40        bar();
 (gdb) info breakpoints
 Num     Type           Disp Enb Address    What
 1       breakpoint     keep y   0x080484e4 in main at gdb/testsuite/gdb.multi/hello.c:40
				 ^^^^^^^^^^
	 breakpoint already hit 2 times
 (gdb)

Note how main was 0x400664 in multi-arch-exec, and 0x080484e4 in
gdb.multi/hello.

With "always-inserted on", we get:

 Breakpoint 1, main () at gdb/testsuite/gdb.multi/multi-arch-exec.c:24
 24        execl (BASEDIR "/multi-arch-exec-hello",
 (gdb) c
 Continuing.
 infrun: target_wait (-1, status) =
 infrun:   9444 [process 9444],
 infrun:   status->kind = execd
 infrun: infwait_normal_state
 infrun: TARGET_WAITKIND_EXECD
 Warning:
 Cannot insert breakpoint 1.
 Cannot access memory at address 0x400664

(gdb)

That is, GDB is trying to insert a breakpoint at 0x400664, after the
exec, and then that address happens to not be mapped at all in the new
image.

The problem is that update_breakpoints_after_exec is creating
breakpoints, which ends up in update_global_location_list immediately
inserting breakpoints if "breakpoints always-inserted" is "on".
update_breakpoints_after_exec is called very early when we see an exec
event.  At that point, we haven't loaded the symbols of the new
post-exec image yet, and thus haven't reset breakpoint's addresses to
whatever they may be in the new image.  All we should be doing in
update_breakpoints_after_exec is deleting breakpoints that no longer
make sense after an exec.  So the fix removes those breakpoint
creations.

The question is then, if not here, where are those breakpoints
re-created?  Turns out we don't need to do anything else, because at
the end of follow_exec, we call breakpoint_re_set, whose tail is also
creating exactly the same breakpoints update_breakpoints_after_exec is
currently creating:

  breakpoint_re_set (void)
  {
  ...
    create_overlay_event_breakpoint ();
    create_longjmp_master_breakpoint ();
    create_std_terminate_master_breakpoint ();
    create_exception_master_breakpoint ();
  }

A new test is added to exercise this.

Tested on x86_64 Fedora 20.

gdb/
2014-10-02  Pedro Alves  <palves@redhat.com>

	PR breakpoints/17431
	* breakpoint.c (update_breakpoints_after_exec): Don't create
	overlay, longjmp, std terminate nor exception breakpoints here.

gdb/testsuite/
2014-10-02  Pedro Alves  <palves@redhat.com>

	PR breakpoints/17431
	* gdb.base/execl-update-breakpoints.c: New file.
	* gdb.base/execl-update-breakpoints.exp: New file.
2014-10-02 10:05:46 +01:00
Pedro Alves 32990adaad Reduce Hg packet (select remote general thread) bouncing
A patch I wrote made GDB pull the thread list sooner when debugging
with target remote, and I noticed an intended consequence.  GDB
started bouncing around the currently selected remote/general thread
more frequently.  E.g.:

  Sending packet: $qTMinFTPILen#3b...Packet received: 5
 +Sending packet: $Hgp726d.726d#53...Packet received: OK
  Sending packet: $m400680,40#2f...Packet received: 85c0741455bff00d60004889e5ffd05de97bffffff0f1f00e973ffffff0f1f00554889e5c745fc00000000c745fc01000000e900000000c745fc02000000b800
 +Sending packet: $Hgp726d.7278#28...Packet received: OK
  Sending packet: $m4006b2,1#28...Packet received: e9
  Fast tracepoint 2 at 0x4006b2: file gdb/testsuite/gdb.trace/range-stepping.c, line 53.
  Sending packet: $qTStatus#49...Packet received: T0;tnotrun:0;tframes:0;tcreated:0;tfree:500000;tsize:500000;circular:0;disconn:0;starttime:0;stoptime:0;username:;notes::

This ended up breaking "tstart" when one has fast tracepoints set,
because gdbserver isn't expecting an Hg packet in response to
qRelocInsn:

 (gdb) ftrace *set_point
 Fast tracepoint 3 at 0x4006b2: file gdb/testsuite/gdb.trace/range-stepping.c, line 53.
 (gdb) PASS: gdb.trace/range-stepping.exp: ftrace: ftrace *set_point
 tstart
 gdbserver: Malformed response to qRelocInsn, ignoring: Hgp2783.2783

 Target does not support this command.
 (gdb) FAIL: gdb.trace/range-stepping.exp: ftrace: tstart

remote_trace_start should probably start by making sure the remote
current thread matches inferior_ptid (calling set_general_thread), but
still, reducing unnecessary bouncing is a good idea.  It happens
because the memory/symbol/breakpoint routines use
switch_to_program_space_and_thread to do something in the right
context and then revert back to the previously current thread.

The fix is to simply make any_thread_of_process,
find_inferior_for_program_space, etc. give preference to the current
thread/inferior it if matches.

gdb/
2014-10-02  Pedro Alves  <palves@redhat.com>

	* gdbthread.h (any_thread_of_process, any_live_thread_of_process):
	Adjust comments.
	* inferior.c (find_inferior_for_program_space): Give preference to
	the current inferior.
	* inferior.h (find_inferior_for_program_space): Update comment.
	* progspace.c (switch_to_program_space_and_thread): Prefer the
	current inferior if it's bound to the program space requested.  If
	the inferior found doesn't have a PID yet, don't bother looking up
	a thread.
	* progspace.h (switch_to_program_space_and_thread): Adjust
	comment.
	* thread.c (any_thread_of_process, any_live_thread_of_process):
	Give preference to the current thread.
2014-10-02 09:55:38 +01:00
Pedro Alves 0fec99e8be Really fail inserting software breakpoints on read-only regions
Currently, with "set breakpoint auto-hw off", we'll still try to
insert a software breakpoint at addresses covered by supposedly
read-only or inacessible regions:

 (top-gdb) mem 0x443000 0x450000 ro
 (top-gdb) set mem inaccessible-by-default off
 (top-gdb) disassemble
 Dump of assembler code for function main:
    0x0000000000443956 <+34>:    movq   $0x0,0x10(%rax)
 => 0x000000000044395e <+42>:    movq   $0x0,0x18(%rax)
    0x0000000000443966 <+50>:    mov    -0x24(%rbp),%eax
    0x0000000000443969 <+53>:    mov    %eax,-0x20(%rbp)
 End of assembler dump.
 (top-gdb) b *0x0000000000443969
 Breakpoint 5 at 0x443969: file ../../src/gdb/gdb.c, line 29.
 (top-gdb) c
 Continuing.
 warning: cannot set software breakpoint at readonly address 0x443969

 Breakpoint 5, 0x0000000000443969 in main (argc=1, argv=0x7fffffffd918) at ../../src/gdb/gdb.c:29
 29        args.argc = argc;
 (top-gdb)

We warn, saying that the insertion can't be done, but then proceed
attempting the insertion anyway, and in case of manually added
regions, the insert actually succeeds.

This is a regression; GDB used to fail inserting the breakpoint.  More
below.

I stumbled on this as I wrote a test that manually sets up a read-only
memory region with the "mem" command, in order to test GDB's behavior
with breakpoints set on read-only regions, even when the real memory
the breakpoints are set at isn't really read-only.  I wanted that in
order to add a test that exercises software single-stepping through
read-only regions.

Note that the memory regions that target_memory_map returns aren't
like e.g., what would expect to see in /proc/PID/maps on Linux.
Instead, they're the physical memory map from the _debuggers_
perspective.  E.g., a read-only region would be real ROM or flash
memory, while a read-only+execute mapping in /proc/PID/maps is still
read-write to the debugger (otherwise the debugger wouldn't be able to
set software breakpoints in the code segment).

If one tries to manually write to memory that falls within a memory
region that is known to be read-only, with e.g., "p foo = 1", then we
hit a check in memory_xfer_partial_1 before the write mananges to make
it to the target side.

But writing a software/memory breakpoint nowadays goes through
target_write_raw_memory, and unlike when writing memory with
TARGET_OBJECT_MEMORY, nothing on the TARGET_OBJECT_RAW_MEMORY path
checks whether we're trying to write to a read-only region.

At the time "breakpoint auto-hw" was added, we didn't have the
TARGET_OBJECT_MEMORY vs TARGET_OBJECT_RAW_MEMORY target object
distinction yet, and the code path in memory_xfer_partial that blocks
writes to read-only memory was hit for memory breakpoints too.  With
GDB 6.8 we had:

 warning: cannot set software breakpoint at readonly address 0000000000443943
 Warning:
 Cannot insert breakpoint 1.
 Error accessing memory address 0x443943: Input/output error.

So I started out by fixing this by adding the memory region validation
to TARGET_OBJECT_RAW_MEMORY too.

But later, when testing against GDBserver, I realized that that would
only block software/memory breakpoints GDB itself inserts with
gdb/mem-break.c.  If a target has a to_insert_breakpoint method, the
insertion request will still pass through to the target.  So I ended
up converting the "cannot set breakpoint" warning in breakpoint.c to a
real error return, thus blocking the insertion sooner.

With that, we'll end up no longer needing the TARGET_OBJECT_RAW_MEMORY
changes once software single-step breakpoints are converted to real
breakpoints.  We need them today as software single-step breakpoints
bypass insert_bp_location.  But, it'll be best to leave that in as
safeguard anyway, for other direct uses of TARGET_OBJECT_RAW_MEMORY.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (insert_bp_location): Error out if inserting a
	software breakpoint at a read-only address.
	* target.c (memory_xfer_check_region): New function, factored out
	from ...
	(memory_xfer_partial_1): ... this.  Make the 'reg_len' local a
	ULONGEST.
	(target_xfer_partial) <TARGET_OBJECT_RAW_MEMORY>: Check the access
	against the memory region attributes.

gdb/testsuite/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* gdb.base/breakpoint-in-ro-region.c: New file.
	* gdb.base/breakpoint-in-ro-region.exp: New file.
2014-10-01 23:31:55 +01:00
Simon Marchi 2ddf430110 Exit code of exited inferiors in -list-thread-groups
Don't reset the exit code at inferior exit and print it in
-list-thread-groups.

gdb/ChangeLog:

	* NEWS: Announce new exit-code field in -list-thread-groups
	output.
	* inferior.c (exit_inferior_1): Don't clear exit code.
	(inferior_appeared): Clear exit code.
	* mi/mi-main.c (print_one_inferior): Add printing of the exit
	code.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-exit-code.exp: New file.
	* gdb.mi/mi-exit-code.c: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Miscellaneous gdb/mi Commands): Document new
	exit-code field in -list-thread-groups output.
2014-10-01 10:20:49 -04:00
Pedro Alves 5fdeec1db0 Add read-only markers to generated gdb/regformats/ .dat files
We have read-only markers in most generated sources already, so that
Emacs/Vi users won't edit them accidentally, but were missing them on
the generated gdb/regformats/ .dat files.

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* features/Makefile ($(outdir)/%.dat): Output "THIS FILE IS
	GENERATED" along with emacs/vi read-only markers.
	* regformats/aarch64.dat: Regenerate.
	* regformats/arm-with-iwmmxt.dat: Regenerate.
	* regformats/arm-with-neon.dat: Regenerate.
	* regformats/arm-with-vfpv2.dat: Regenerate.
	* regformats/arm-with-vfpv3.dat: Regenerate.
	* regformats/i386/amd64-avx-linux.dat: Regenerate.
	* regformats/i386/amd64-avx.dat: Regenerate.
	* regformats/i386/amd64-avx512-linux.dat: Regenerate.
	* regformats/i386/amd64-avx512.dat: Regenerate.
	* regformats/i386/amd64-linux.dat: Regenerate.
	* regformats/i386/amd64-mpx-linux.dat: Regenerate.
	* regformats/i386/amd64-mpx.dat: Regenerate.
	* regformats/i386/amd64.dat: Regenerate.
	* regformats/i386/i386-avx-linux.dat: Regenerate.
	* regformats/i386/i386-avx.dat: Regenerate.
	* regformats/i386/i386-avx512-linux.dat: Regenerate.
	* regformats/i386/i386-avx512.dat: Regenerate.
	* regformats/i386/i386-linux.dat: Regenerate.
	* regformats/i386/i386-mmx-linux.dat: Regenerate.
	* regformats/i386/i386-mmx.dat: Regenerate.
	* regformats/i386/i386-mpx-linux.dat: Regenerate.
	* regformats/i386/i386-mpx.dat: Regenerate.
	* regformats/i386/i386.dat: Regenerate.
	* regformats/i386/x32-avx-linux.dat: Regenerate.
	* regformats/i386/x32-avx.dat: Regenerate.
	* regformats/i386/x32-avx512-linux.dat: Regenerate.
	* regformats/i386/x32-avx512.dat: Regenerate.
	* regformats/i386/x32-linux.dat: Regenerate.
	* regformats/i386/x32.dat: Regenerate.
	* regformats/microblaze-with-stack-protect.dat: Regenerate.
	* regformats/mips-dsp-linux.dat: Regenerate.
	* regformats/mips-linux.dat: Regenerate.
	* regformats/mips64-dsp-linux.dat: Regenerate.
	* regformats/mips64-linux.dat: Regenerate.
	* regformats/nios2-linux.dat: Regenerate.
	* regformats/rs6000/powerpc-32.dat: Regenerate.
	* regformats/rs6000/powerpc-32l.dat: Regenerate.
	* regformats/rs6000/powerpc-64l.dat: Regenerate.
	* regformats/rs6000/powerpc-altivec32l.dat: Regenerate.
	* regformats/rs6000/powerpc-altivec64l.dat: Regenerate.
	* regformats/rs6000/powerpc-cell32l.dat: Regenerate.
	* regformats/rs6000/powerpc-cell64l.dat: Regenerate.
	* regformats/rs6000/powerpc-e500l.dat: Regenerate.
	* regformats/rs6000/powerpc-vsx32l.dat: Regenerate.
	* regformats/rs6000/powerpc-vsx64l.dat: Regenerate.
	* regformats/s390-linux32.dat: Regenerate.
	* regformats/s390-linux32v1.dat: Regenerate.
	* regformats/s390-linux32v2.dat: Regenerate.
	* regformats/s390-linux64.dat: Regenerate.
	* regformats/s390-linux64v1.dat: Regenerate.
	* regformats/s390-linux64v2.dat: Regenerate.
	* regformats/s390-te-linux64.dat: Regenerate.
	* regformats/s390x-linux64.dat: Regenerate.
	* regformats/s390x-linux64v1.dat: Regenerate.
	* regformats/s390x-linux64v2.dat: Regenerate.
	* regformats/s390x-te-linux64.dat: Regenerate.
	* regformats/tic6x-c62x-linux.dat: Regenerate.
	* regformats/tic6x-c62x.dat: Regenerate.
	* regformats/tic6x-c64x-linux.dat: Regenerate.
	* regformats/tic6x-c64x.dat: Regenerate.
	* regformats/tic6x-c64xp-linux.dat: Regenerate.
	* regformats/tic6x-c64xp.dat: Regenerate.
2014-10-01 13:40:13 +01:00
Pedro Alves db74e4ba01 features/Makefile: Make 'make cfiles' default to generating all C files
This makes it easier to rebuild all GDB's generated target description
C files.

It also clarifies the comments a bit.  One might think we need a GDB
configured for the particular arquitecture (--target=foo).  But a
build that includes support for the target description is sufficient.
(GDB rejects target descriptions that explicitly specify the
architecture, with an <architecture> element, if the architecture is
unknown.)

Tested that "make clean-cfiles" deletes all .c files under
src/gdb/features/, and that "make cfiles" generates them all without
error, and that diffing the newly generated C files against master
comes out an empty diff.

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* features/Makefile: Update comments.
	(XMLTOC): List all xml files we build C files from.
	(clean-cfiles): New rule.
2014-10-01 12:08:40 +01:00
Pedro Alves d63f2f8402 Regenerate AVX512 target description C files
I regenerated all the .c files under src/gdb/features/ and this is
what I got.

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* features/i386/amd64-avx512-linux.c: Regenerate.
	* features/i386/amd64-avx512.c: Regenerate.
	* features/i386/x32-avx512-linux.c: Regenerate.
	* features/i386/x32-avx512.c: Regenerate.
2014-10-01 11:59:46 +01:00
Pedro Alves 20ad026db6 gdb/regformats: Don't build .dat files that aren't used by GDBserver
The only reason .dat files exist is for GBBserver to use them in its
build system.

A few .dat files are listed as targets for generation that shouldn't.
The target descriptions these files are built from aren't used by
GDBserver.  They're fallback descriptions GDB itself has baked in.

Remove them from the list of .dat files to be generated, otherwise a
plain "make" under src/gdb/features/ generates new .dat files that
aren't even in the tree today.

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* features/Makefile (WHICH): Remove arm-with-m,
	arm-with-m-fpa-layout and arm-with-m-vfp-d16.
2014-10-01 11:12:04 +01:00
Pedro Alves acc9fe4500 features/Makefile: Add a "clean" rule.
So that we can do "make clean all" to regenerate all the renerated
.dat files.

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* features/Makefile (clean): New rule.
2014-10-01 11:07:39 +01:00
Pedro Alves e001e535f6 Fix features/i386/64bit-avx512.xml
This file's format is invalid, as it's missing some end quotes.

I noticed this because I tried to regenerate all the .dat files in
gdb/regformats/.  I got:

    sh ../../move-if-change ../regformats/i386/x32-avx.tmp ../regformats/i386/x32-avx.dat
    echo "# DO NOT EDIT: generated from i386/x32-avx512.xml" > ../regformats/i386/x32-avx512.tmp
    echo "name:`echo x32-avx512 | sed 's/-/_/g'`" >> ../regformats/i386/x32-avx512.tmp
    echo "xmltarget:x32-avx512.xml" >> ../regformats/i386/x32-avx512.tmp
    echo "expedite:rbp,rsp,rip" \
      >> ../regformats/i386/x32-avx512.tmp
    xsltproc --path "/home/pedro/gdb/mygit/src/gdb/features" --xinclude number-regs.xsl i386/x32-avx512.xml | \
      xsltproc sort-regs.xsl - | \
      xsltproc gdbserver-regs.xsl - >> ../regformats/i386/x32-avx512.tmp
    i386/64bit-avx512.xml:81: parser error : Unescaped '<' not allowed in attributes values
      <reg name="zmm11h" bitsize="256" type="v2ui128/>
      ^
    i386/64bit-avx512.xml:81: parser error : attributes construct error
      <reg name="zmm11h" bitsize="256" type="v2ui128/>
      ^
    i386/64bit-avx512.xml:81: parser error : Couldn't find end of Start Tag reg line 80
      <reg name="zmm11h" bitsize="256" type="v2ui128/>
      ^
    i386/64bit-avx512.xml:82: parser error : Unescaped '<' not allowed in attributes values
      <reg name="zmm12h" bitsize="256" type="v2ui128/>
      ^
    i386/64bit-avx512.xml:82: parser error : attributes construct error
      <reg name="zmm12h" bitsize="256" type="v2ui128/>
      ^
...
    i386/x32-avx512.xml:17: element include: XInclude error : could not load i386/64bit-avx512.xml, and no fallback was found
    -:1: parser error : Document is empty

    ^
    -:1: parser error : Start tag expected, '<' not found

    ^
    unable to parse -
    -:1: parser error : Document is empty

    ^
    -:1: parser error : Start tag expected, '<' not found

    ^
    unable to parse -
    make: *** [../regformats/i386/x32-avx512.dat] Error 6

Interestingly, gdb/expat manages to grok the broken file.

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* features/i386/64bit-avx512.xml (zmm10h, zmm11h, zmm12h, zmm13h)
	(zmm14h): Add missing end quotes.
2014-10-01 10:52:54 +01:00
Pedro Alves bdc144174b Aarch64: Make CPSR a 32-bit register again in the target description
This reverts commit a4d9ba85 - 'AARCH64: Change cpsr type to be
64bit.'.

Even though Linux's ptrace exposes CPSR as 64-bit, CPSR is really
32-bit, and basing GDB's fundamentals on a particular OS's ptrace(2)
implementation is a bad idea.

In addition, while that commit intended to fix big endian Aarch64, it
ended up breaking floating point debugging against GDBserver, for both
big and little endian, because it changed the CPSR to be 64-bit in the
features/aarch64-core.xml file, but missed regenerating the
regformats/aarch64.dat file.  If we generate it now, we see this:

  diff --git c/gdb/regformats/aarch64.dat w/gdb/regformats/aarch64.dat
  index afe1028..0d32183 100644
  --- c/gdb/regformats/aarch64.dat
  +++ w/gdb/regformats/aarch64.dat
  @@ -35,7 +35,7 @@ expedite:x29,sp,pc
   64:x30
   64:sp
   64:pc
  -32:cpsr
  +64:cpsr
   128:v0
   128:v1
   128:v2

IOW, that commit left regformats/aarch64.dat still considering CPSR as
32-bits.  regformats/aarch64.dat is used by GDBserver for its internal
regcache layout, and for the g/G packet register block.  See the
generated aarch64.c file in GDBserver's build dir.

So the target description xml file that GDBserver reports to GDB is
now claiming that CPSR is 64-bit, but what GDBserver actually puts in
the g/G register packets is 32-bits.  Because GDB thinks CPSR is
64-bit (because that's what the XML description says), GDB will be
reading the remaining 32-bit bits of CPSR out of v0 (the register
immediately afterwards), and then all the registers that follow CPSR
in the register packet end up wrong in GDB, because they're being read
from the wrong offsets...

gdb/
2014-10-01  Pedro Alves  <palves@redhat.com>

	* features/aarch64-core.xml (cpsr): Change back to 32-bit.
	* features/aarch64.c: Regenerate.
2014-10-01 10:06:45 +01:00
Don Breazeal d83ad864a2 Refactor native follow-fork.
This patch reorganizes the code that implements follow-fork and
detach-on-fork in preparation for implementation of those features for the
extended-remote target.  The function linux-nat.c:linux_child_follow_fork
contained target-independent code mixed in with target-dependent code.  The
target-independent pieces need to be accessible for the host-side
implementation of follow-fork for extended-remote Linux targets.

The changes are fairly mechanical.  A new routine, follow_fork_inferior,
is implemented in infrun.c, containing those parts of
linux_child_follow_fork that manage inferiors and the inferior list.  The
parts of linux_child_follow_fork that deal with LWPs and target-specifics
were left in-place.  Although the order of some operations was changed, the
resulting functionality was not.

Modifications were made to the other native target follow-fork functions,
inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them
to work with follow_fork_inferior.  Some other adjustments were necessary
in inf-ttrace.c.  The changes to inf-ttrace.c and inf-ptrace.c were not
tested.

gdb/ChangeLog:

	* inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent
	code so as to work with follow_fork_inferior.
	* inf-ttrace.c (inf_ttrace_follow_fork): Ditto.
	(inf_ttrace_create_inferior): Remove reference to
	inf_ttrace_vfork_ppid.
	(inf_ttrace_attach): Ditto.
	(inf_ttrace_detach): Ditto.
	(inf_ttrace_kill): Use current_inferior instead of
	inf_ttrace_vfork_ppid.
	(inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report
	TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the
	inferior away from the parent.
	* infrun.c (follow_fork): Call follow_fork_inferior instead of
	target_follow_fork.
	(follow_fork_inferior): New function.
	(follow_inferior_reset_breakpoints): Make function static.
	* infrun.h (follow_inferior_reset_breakpoints): Remove declaration.
	* linux-nat.c (linux_child_follow_fork): Move target-independent
	code to infrun.c:follow_fork_inferior.
2014-09-30 11:01:57 -07:00
James Hogan 63b434a437 Clean up after generated c files for MIPS DSP targets
The gdbserver "clean" Makefile target wasn't removing the generated files
mips-dsp-linux.c and mips64-dsp-linux.c. Add rm commands to delete them.

gdb/gdbserver/ChangeLog:

	* Makefile.in (clean): Add rm -f commands for mips-dsp-linux.c and
	mips64-dsp-linux.c.
2014-09-30 15:50:21 +01:00
Andreas Arnez 29082443fc Drop 'regset_from_core_section' gdbarch method
Now that all instances of the regset_from_core_section gdbarch method
have been replaced by the new iterator method, delete the obsolete
method from the gdbarch interface.  Adjust all invocations and
references to it.

gdb/ChangeLog:

	* gdbarch.sh (regset_from_core_section): Remove gdbarch method.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Likewise.
	* corelow.c (sniff_core_bfd): Drop presence check for deleted
	gdbarch method 'regset_from_core_section'.
	(get_core_register_section): Remove handling for the case that
	regset == NULL and regset_from_core_section is defined.
	(get_core_registers): Drop check for deleted method.
	* procfs.c (procfs_do_thread_registers): Adjust comment.
2014-09-30 09:14:39 +02:00
Andreas Arnez f968fe80b0 Linux targets: drop fall back to target method for 'make_corefile_notes'
Now that all Linux targets use the regset iterator, the fall back to
the deprecated target method is dropped.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_collect_thread_registers): Remove.
	(linux_nat_make_corefile_notes): Remove.
	(linux_target_install_ops): Do not set target method
	'make_corefile_notes'.
	* linux-tdep.c (struct linux_corefile_thread_data)<collect>:
	Remove field.
	(linux_corefile_thread_callback): Instead of args->collect, call
	linux_collect_thread_registers.
	(linux_make_corefile_notes): Remove 'collect' parameter.  Return
	NULL unless there is a regset iterator.
	(linux_make_corefile_notes_1): Remove.
	(linux_init_abi): Replace reference to linux_make_corefile_notes_1
	by linux_make_corefile_notes.
	* linux-tdep.h (linux_make_corefile_notes): Remove prototype.
2014-09-30 09:14:39 +02:00
Andreas Arnez 174ad59a8e Drop target method 'fbsd_make_corefile_notes'
Now that all users of the target method 'fbsd_make_corefile_notes'
have been converted to the version in fbsd-tdep.c, the old method is
removed.

gdb/ChangeLog:

	* fbsd-nat.c (find_signalled_thread, find_stop_signal)
	(fbsd_collect_regset_section_cb, fbsd_make_corefile_notes):
	Remove.
	* fbsd-nat.h (fbsd_make_corefile_notes): Remove prototype.
2014-09-30 09:14:39 +02:00
Andreas Arnez 970940347a XTENSA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For Xtensa targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* xtensa-tdep.c (xtensa_regset_from_core_section): Remove.
	(xtensa_iterate_over_regset_sections): New.
	(xtensa_gdbarch_init): Adjust gdbarch initialization.
2014-09-30 09:14:39 +02:00
Andreas Arnez f73d3ce7f8 VAX: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For VAX targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* vax-tdep.c (vax_regset_from_core_section): Remove.
	(vax_iterate_over_regset_sections): New.
	(vax_gdbarch_init): Adjust gdbarch initialization.
2014-09-30 09:14:38 +02:00
Andreas Arnez cb24567a55 TILEGX: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For TILE-Gx GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* tilegx-linux-tdep.c (TILEGX_LINUX_SIZEOF_GREGSET): New macro.
	(tilegx_regset_from_core_section): Remove.
	(tilegx_iterate_over_regset_sections): New.
	(tilegx_linux_init_abi): Adjust gdbarch initialization.
2014-09-30 09:14:38 +02:00
Andreas Arnez e5139de88e SPARC: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For SPARC targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* sparc-tdep.c (sparc_regset_from_core_section): Remove.
	(sparc_iterate_over_regset_sections): New.
	(sparc32_gdbarch_init): Adjust gdbarch initialization.
	* configure.tgt (gdb_target_obs): Add fbsd-tdep.o for SPARC FreeBSD
	targets.
	* sparc64fbsd-tdep.c (fbsd-tdep.h): Include.
	(sparc64fbsd_init_abi): Call fbsd_init_abi.
	* sparc64fbsd-nat.c (_initialize_sparc64fbsd_nat): Do not set
	target method 'make_corefile_notes'.
2014-09-30 09:14:38 +02:00
Andreas Arnez c6d41a6f53 SH: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For Super-H targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* sh-linux-tdep.c (sh_linux_init_abi): Set tdep fields
	'sizeof_gregset' and 'sizeof_fpregset'.
	* sh-tdep.c (sh_regset_from_core_section): Remove.
	(sh_iterate_over_regset_sections): New.
	(sh_gdbarch_init): Adjust gdbarch initialization.
	* sh-tdep.h (struct gdbarch_tdep): New fields sizeof_gregset and
	sizeof_fpregset.
	* shnbsd-tdep.c (shnbsd_init_abi): Set tdep field
	'sizeof_gregset'.
2014-09-30 09:14:37 +02:00
Andreas Arnez 9845a0b521 SCORE: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For S+core targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* score-tdep.c (score7_linux_regset_from_core_section): Remove.
	(score7_linux_iterate_over_regset_sections): New.
	(score_gdbarch_init): Adjust gdbarch initialization.
2014-09-30 09:14:37 +02:00
Andreas Arnez 23ea9aebce PPC: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For PPC targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* configure.tgt (gdb_target_obs): Add fbsd-tdep.o for PowerPC
	FreeBSD targets.
	* ppcfbsd-nat.c (_initialize_ppcfbsd_nat): Do not set target
	method 'make_corefile_notes'.
	* ppcfbsd-tdep.c (fbsd-tdep.h): Include.
	(ppcfbsd_regset_from_core_section): Remove.
	(ppcfbsd_iterate_over_regset_sections): New.
	(ppcfbsd_init_abi): Call fbsd_init_abi.  Adjust gdbarch
	initialization.
	* ppcnbsd-tdep.c (ppcnbsd_regset_from_core_section): Remove.
	(ppcnbsd_iterate_over_regset_sections): New.
	(ppcnbsd_init_abi): Adjust.
	* ppcobsd-tdep.c (ppcobsd_regset_from_core_section): Remove.
	(ppcobsd_iterate_over_regset_sections): New.
	(ppcobsd_init_abi): Adjust.
	* rs6000-aix-tdep.c (rs6000_aix_regset_from_core_section): Remove.
	(rs6000_aix_iterate_over_regset_sections): New.
	(rs6000_aix_init_osabi): Adjust.
2014-09-30 09:14:37 +02:00
Andreas Arnez c5b8d704bc NIOS2: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For Nios II GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* nios2-linux-tdep.c (NIOS2_GREGS_SIZE): New macro.
	(nios2_regset_from_core_section): Remove.
	(nios2_iterate_over_regset_sections): New.
	(nios2_linux_init_abi): Adjust gdbarch initialization.
2014-09-30 09:14:37 +02:00
Andreas Arnez 3636e6083c MN10300: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'.
For MN10300 GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* mn10300-linux-tdep.c (am33_regset_from_core_section): Remove.
	(am33_iterate_over_regset_sections): New.
	(am33_linux_init_osabi): Adjust gdbarch initialization.
2014-09-30 09:14:36 +02:00
Andreas Arnez d40362355c MIPS: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For MIPS targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* mips-linux-tdep.c (mips_linux_regset_from_core_section): Remove.
	(mips_linux_iterate_over_regset_sections): New.
	(mips_linux_init_abi): Adjust gdbarch initialization.
	* mips64obsd-tdep.c (mips64obsd_regset_from_core_section): Remove.
	(mips64obsd_iterate_over_regset_sections): New.
	(mips64obsd_init_abi): Adjust.
	* mipsnbsd-tdep.c (mipsnbsd_regset_from_core_section): Remove.
	(mipsnbsd_iterate_over_regset_sections): New.
	(mipsnbsd_init_abi): Adjust.
2014-09-30 09:14:36 +02:00
Andreas Arnez b61ddd6e24 M88K: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For M88K targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* m88k-tdep.c (m88k_regset_from_core_section): Remove.
	(m88k_iterate_over_regset_sections): New.
	(m88k_gdbarch_init): Adjust gdbarch initialization.
2014-09-30 09:14:36 +02:00
Andreas Arnez 55a2906a41 IA64: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For IA-64 GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* ia64-linux-tdep.c (ia64_linux_regset_from_core_section): Remove.
	(ia64_linux_iterate_over_regset_sections): New.
	(ia64_linux_init_abi): Adjust gdbarch initialization.
2014-09-30 09:14:36 +02:00
Andreas Arnez 022c98ab88 M68K: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For m68k BSD and GNU/Linux targets, no longer define the gdbarch
method 'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* m68kbsd-tdep.c (m68kbsd_regset_from_core_section): Remove.
	(m68kbsd_iterate_over_regset_sections): New.
	(m68kbsd_init_abi): Adjust gdbarch initialization.
	* m68klinux-tdep.c (m68k_linux_regset_from_core_section): Remove.
	(m68k_linux_iterate_over_regset_sections): New.
	(m68k_linux_init_abi): Adjust gdbarch initialization.
2014-09-30 09:14:35 +02:00
Andreas Arnez 5fac247f47 M32R: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For m32r GNU/Linux targets, don't define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* m32r-linux-tdep.c (M32R_LINUX_GREGS_SIZE): New macro.
	(m32r_linux_regset_from_core_section): Remove.
	(m32r_linux_iterate_over_regset_sections): New.
	(m32r_linux_init_abi): Adjust gdbarch initialization.
2014-09-30 09:14:35 +02:00
Andreas Arnez 490496c342 X86: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For all I386 and AMD64 targets, replace all occurrences of
regset_from_core_section by the iterator method.

gdb/ChangeLog:

	* amd64obsd-tdep.c (amd64obsd_regset_from_core_section): Remove.
	(amd64obsd_iterate_over_regset_sections): New.
	(amd64obsd_core_init_abi): Adjust gdbarch initialization.
	* i386-cygwin-tdep.c (i386_windows_regset_from_core_section):
	Remove.
	(i386_cygwin_init_abi): Clear tdep->sizeof_fpregset.  Drop
	regset_from_core_section initialization.
	* i386-tdep.c (i386_regset_from_core_section): Remove.
	(i386_iterate_over_regset_sections): New.
	(i386_gdbarch_init): Adjust gdbarch initialization.
	* i386-tdep.h (i386_regset_from_core_section): Remove prototype.
	(i386_iterate_over_regset_sections): New prototype.
	* i386obsd-tdep.c (i386obsd_aout_regset_from_core_section):
	Remove.
	(i386obsd_aout_iterate_over_regset_sections): New.
	(i386obsd_aout_init_abi): Adjust gdbarch initialization.
	* configure.tgt (gdb_target_obs): Add fbsd-tdep.o for all x86 FreeBSD
	targets.
	* amd64fbsd-tdep.c (fbsd-tdep.h): Include.
	(amd64fbsd_init_abi): Call fbsd_init_abi.
	* i386fbsd-tdep.c (fbsd-tdep.h): Include.
	(i386fbsd4_init_abi): Call fbsd_init_abi.
	* amd64fbsd-nat.c (_initialize_amd64fbsd_nat): No longer set
	target method 'make_corefile_notes'.
	* i386fbsd-nat.c (_initialize_i386fbsd_nat): Likewise.
2014-09-30 09:14:35 +02:00
Andreas Arnez 50c5eb5335 HPPA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For HP PA-RISC targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* hppa-hpux-tdep.c (hppa_hpux_regset_from_core_section): Remove.
	(hppa_hpux_iterate_over_regset_sections): New.
	(hppa_hpux_init_abi): Adjust gdbarch initialization.
	* hppa-linux-tdep.c (hppa_linux_regset_from_core_section): Remove.
	(hppa_linux_iterate_over_regset_sections): New.
	(hppa_linux_init_abi): Adjust.
	* hppanbsd-tdep.c (hppaobsd_regset_from_core_section): Remove.
	(hppanbsd_iterate_over_regset_sections): New.
	(hppanbsd_init_abi): Adjust.
	* hppaobsd-tdep.c (hppaobsd_regset_from_core_section): Remove.
	(hppaobsd_iterate_over_regset_sections): New.
	(hppaobsd_init_abi): Adjust.
2014-09-30 09:14:34 +02:00
Andreas Arnez 66afae4f0a FRV: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For FR-V GNU/Linux targets, no longer define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* frv-linux-tdep.c (frv_linux_regset_from_core_section): Remove.
	(frv_linux_iterate_over_regset_sections): New.
	(frv_linux_init_abi): Adjust gdbarch initialization.
2014-09-30 09:14:34 +02:00
Andreas Arnez ed09174e35 ARM: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
For ARM BSD targets, don't define the gdbarch method
'regset_from_core_section', but the iterator method instead.

gdb/ChangeLog:

	* arm-tdep.h (armbsd_regset_from_core_section): Remove prototype.
	(armbsd_iterate_over_regset_sections): New prototype.
	* armbsd-tdep.c (armbsd_regset_from_core_section): Remove.
	(armbsd_iterate_over_regset_sections): New.
	* armobsd-tdep.c (armobsd_init_abi): Adjust gdbarch
	initialization.
2014-09-30 09:14:34 +02:00
Andreas Arnez dff2166ef9 ALPHA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
Don't define the 'regset_from_core_section' method, but the iterator
method instead.  Do this for GNU/Linux- as well as
Net/OpenBSD-targets.  In the case of GNU/Linux this should enable
non-native use of the 'generate-core-file' command.

gdb/ChangeLog:

	* alpha-linux-tdep.c (alpha_linux_regset_from_core_section): Remove.
	(alpha_linux_iterate_over_regset_sections): New.
	(alpha_linux_init_abi): Adjust gdbarch initialization.
	* alphabsd-tdep.h (alphanbsd_regset_from_core_section): Remove
	prototype.
	(alphanbsd_iterate_over_regset_sections): New prototype.
    	* alphafbsd-tdep.c (alphafbsd_init_abi): Add comment for missing
    	fbsd_init_abi invocation.
	* alphanbsd-tdep.c (alphanbsd_supply_gregset): Move below
	alphanbsd_aout_supply_gregset.  Invoke the latter for the
	appropriate size.
	(alphanbsd_aout_gregset): Remove.
	(alphanbsd_regset_from_core_section): Remove.
	(alphanbsd_iterate_over_regset_sections): New.
	(alphanbsd_init_abi): Adjust gdbarch initialization.
	* alphaobsd-tdep.c (alphaobsd_init_abi): Likewise.
2014-09-30 09:14:34 +02:00
Andreas Arnez 4108500a2a AARCH64: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
Don't define the 'regset_from_core_section' method, but the iterator
method instead.  This slightly reduces the code and enables non-native
use of the 'generate-core-file' command.

Also, when all instances of 'regset_from_core_section' are replaced,
it can be dropped from the gdbarch interface.

gdb/ChangeLog:

	* aarch64-linux-tdep.c (aarch64_linux_regset_from_core_section):
	Remove.
	(aarch64_linux_iterate_over_regset_sections): New.
	(aarch64_linux_init_abi): Adjust gdbarch initialization.
2014-09-30 09:14:33 +02:00
Andreas Arnez a904c024b0 Add multi-arch capable 'fbsd_make_corefile_notes' variant
This creates a new version of the FreeBSD core file note generation
logic in the new target-dependent file "fbsd-tdep.c".  The new version
is mostly copied from "fbsd-nat.c", but uses the iterator instead of
regset_from_core_section and defines fbsd_make_corefile_notes as a
gdbarch method instead of a target method.

Consecutive architecture-dependent changes exploit the new version,
migrating away from the target method.  When all FreeBSD targets are
changed, the target method can go away.

gdb/ChangeLog:

	* fbsd-tdep.c: New file.
	* fbsd-tdep.h: New file.
	* Makefile.in (ALL_TARGET_OBS): Add fbsd-tdep.o.
	(HFILES_NO_SRCDIR): Add fbsd-tdep.h.
	(ALLDEPFILES): Add fbsd-tdep.c.
2014-09-30 09:14:33 +02:00
Andreas Arnez 8f0435f75e Add 'regset' parameter to 'iterate_over_regset_sections_cb'
This adds the 'regset' parameter to the iterator callback.
Consequently the 'regset_from_core_section' method is dropped for all
targets that provide the iterator method.

This change prepares for replacing regset_from_core_section
everywhere, thereby eliminating one gdbarch interface.  Since the
iterator is usually no more complex than regset_from_core_section
alone, targets that previously didn't define core_regset_sections will
then gain multi-arch capable core file generation support without
increased complexity.

gdb/ChangeLog:

	* gdbarch.sh (iterate_over_regset_sections_cb): Add regset
	parameter.
	* gdbarch.h: Regenerate.
	* corelow.c (sniff_core_bfd): Don't sniff if gdbarch has a regset
	iterator.
	(get_core_register_section): Add parameter 'regset' and use it, if
	set.  Add parameter 'min_size' and verify the bfd section size
	against it.
	(get_core_registers_cb): Add parameter 'regset' and pass it to
	get_core_register section.  For the "standard" register sections
	".reg" and ".reg2", set an appropriate default for human_name.
	(get_core_registers): Don't abort when the gdbarch has an iterator
	but no regset_from_core_section.  Add NULL/0 for parameters
	'regset'/'min_size' in calls to get_core_register_section.
	* linux-tdep.c (linux_collect_regset_section_cb): Add parameter
	'regset' and use it instead of calling the
	regset_from_core_section gdbarch method.
	* i386-tdep.h (struct gdbarch_tdep): Add field 'fpregset'.
	* i386-tdep.c (i386_supply_xstateregset)
	(i386_collect_xstateregset, i386_xstateregset): Moved to
	i386-linux-tdep.c.
	(i386_regset_from_core_section): Drop handling for .reg-xfp and
	.reg-xstate.
	(i386_gdbarch_init): Set tdep field 'fpregset'.  Enable generic
	core file support only if the regset iterator hasn't been set.
	* i386-linux-tdep.c (i386_linux_supply_xstateregset)
	(i386_linux_collect_xstateregset, i386_linux_xstateregset): New.
	Moved from i386-tdep.c and renamed to *_linux*.
	(i386_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.  Allow any .reg-xstate size when reading
	from a core file.
	* amd64-tdep.c (amd64_supply_xstateregset)
	(amd64_collect_xstateregset, amd64_xstateregset): Moved to
	amd64-linux-tdep.c.
	(amd64_regset_from_core_section): Remove.
	(amd64_init_abi): Set new tdep field 'fpregset'.  No longer
	install an amd64-specific regset_from_core_section gdbarch method.
	* amd64-linux-tdep.c (amd64_linux_supply_xstateregset)
	(amd64_linux_collect_xstateregset, amd64_linux_xstateregset): New.
	Moved from amd64-tdep.c and renamed to *_linux*.
	(amd64_linux_iterate_over_regset_sections): Add regset parameter
	to each callback invocation.  Allow any .reg-xstate size when
	reading from a core file.
	* arm-linux-tdep.c (arm_linux_regset_from_core_section): Remove.
	(arm_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.
	(arm_linux_init_abi): No longer set the regset_from_core_section
	gdbarch method.
	* ppc-linux-tdep.c (ppc_linux_regset_from_core_section): Remove.
	(ppc_linux_iterate_over_regset_sections): Add regset parameter to
	each callback invocation.
	(ppc_linux_init_abi): No longer set the regset_from_core_section
	gdbarch method.
	* s390-linux-tdep.c (struct gdbarch_tdep): Remove the fields
	gregset, sizeof_gregset, fpregset, and sizeof_fpregset.
	(s390_regset_from_core_section): Remove.
	(s390_iterate_over_regset_sections): Add regset parameter to each
	callback invocation.
	(s390_gdbarch_init): No longer set the regset_from_core_section
	gdbarch method.  Drop initialization of deleted tdep fields.
2014-09-30 09:14:33 +02:00
Andreas Arnez 5aa82d050d Replace 'core_regset_sections' by iterator method
The core_regset_sections list in gdbarch (needed for multi-arch
capable core file generation support) is replaced by an iterator
method.  Overall, this reduces the code a bit, and it allows for more
flexibility.

gdb/ChangeLog:

	* amd64-linux-tdep.c (amd64_linux_regset_sections): Remove.
	(amd64_linux_iterate_over_regset_sections): New.
	(amd64_linux_init_abi_common): Don't install the regset section
	list, but the new iterator in gdbarch.
	* arm-linux-tdep.c (arm_linux_fpa_regset_sections)
	(arm_linux_vfp_regset_sections): Remove.  Move combined logic...
	(arm_linux_iterate_over_regset_sections): ...here.  New function.
	(arm_linux_init_abi): Set iterator instead of section list.
	* corelow.c (get_core_registers_cb): New function, logic moved
	from...
	(get_core_registers): ...loop body here.  Use new iterator method
	instead of walking through the regset section list.
	* gdbarch.sh: Remove 'core_regset_sections'.  New method
	'iterate_over_regset_sections'.  New typedef
	'iterate_over_regset_sections_cb'.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Likewise.
	* i386-linux-tdep.c (i386_linux_regset_sections)
	(i386_linux_sse_regset_sections, i386_linux_avx_regset_sections):
	Remove.
	(i386_linux_iterate_over_regset_sections): New.
	(i386_linux_init_abi): Don't choose a regset section list, but
	install new iterator in gdbarch.
	* linux-tdep.c (struct linux_collect_regset_section_cb_data): New.
	(linux_collect_regset_section_cb): New function, logic moved
	from...
	(linux_collect_thread_registers): ...loop body here.  Use iterator
	method instead of walking through list.
	(linux_make_corefile_notes_1): Check for presence of iterator
	method instead of regset section list.
	* ppc-linux-tdep.c (ppc_linux_vsx_regset_sections)
	(ppc_linux_vmx_regset_sections, ppc_linux_fp_regset_sections)
	(ppc64_linux_vsx_regset_sections, ppc64_linux_vmx_regset_sections)
	(ppc64_linux_fp_regset_sections): Remove.  Move combined logic...
	(ppc_linux_iterate_over_regset_sections): ...here.  New function.
	(ppc_linux_init_abi): Don't choose from above regset section
	lists, but install new iterator in gdbarch.
	* regset.h (struct core_regset_section): Remove.
	* s390-linux-tdep.c (struct gdbarch_tdep): Add new fields
	have_linux_v1, have_linux_v2, and have_tdb.
	(s390_linux32_regset_sections, s390_linux32v1_regset_sections)
	(s390_linux32v2_regset_sections, s390_linux64_regset_sections)
	(s390_linux64v1_regset_sections, s390_linux64v2_regset_sections)
	(s390x_linux64_regset_sections, s390x_linux64v1_regset_sections)
	(s390x_linux64v2_regset_sections): Remove.  Move combined logic...
	(s390_iterate_over_regset_sections): ...here.  New function.  Use
	new tdep fields.
	(s390_gdbarch_init): Set new tdep fields.  Don't choose from above
	regset section lists, but install new iterator.
2014-09-30 09:14:32 +02:00
Yao Qi 6a5f3f4353 Error in build_executable_own_libs for non-native target
gdb/testsuite:

2014-09-30  Yao Qi  <yao@codesourcery.com>

	* lib/prelink-support.exp (build_executable_own_libs): Error if
	the target isn't native.
2014-09-30 11:42:56 +08:00
Yao Qi 345bcc73f2 Skip dlopen-libpthread.exp in cross testing
I see the following fails on arm-linux-gnueabi,

result of ldd build-git/arm/gdb/testsuite/gdb.threads/dlopen-libpthread.so is 1
output of ldd build-git/arm/gdb/testsuite/gdb.threads/dlopen-libpthread.so is not a dynamic executable
child process exited abnormally
FAIL: gdb.threads/dlopen-libpthread.exp: ldd dlopen-libpthread.so
FAIL: gdb.threads/dlopen-libpthread.exp: ldd dlopen-libpthread.so output contains libs

the test script invokes ldd (on host) for the target libraries, which
is wrong.  ldd can't be cross because it invokes dynamic linker with
LD_TRACE_LOADED_OBJECTS and gets the dependent libraries.  My first
reaction to this problem is to execute ld.so on the target (like
remote_exec target).  When I start to hack proc build_executable_own_libs,
I find it has assumptions here and there that the native testing is
performed.  Then I check the callers of build_executable_own_libs,
and they are all skipped if isnative is false.  It is reasonable to do
the same in dlopen-libpthread.exp too.

gdb/testsuite:

2014-09-30  Yao Qi  <yao@codesourcery.com>

	* gdb.threads/dlopen-libpthread.exp: Skip it if isnative is
	false.
2014-09-30 11:42:51 +08:00
Jan Kratochvil 2eca4a8d84 Fix library-list.dtd -> library-list-svr4.dtd
commit 2268b414f4
added file "features/library-list-svr4.dtd" but the added code uses
"library-list.dtd" instead.

Curiously after changing for a test s/name/nXme/ in the DTD making the
gdbserver output non-conforming there is no warning or regression seen (tested
gdb.base/shlib-call.exp, using_xfer is still 1).  I did not check more why the
DTD conformance verification does not work.

gdb/ChangeLog
2014-09-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* solib-svr4.c (svr4_parse_libraries): Use "library-list-svr4.dtd".
2014-09-29 17:38:12 +02:00
Simon Marchi a73c2b56cd Don't prune program spaces when doing "maintenance info program-spaces"
Remove the pruning of program spaces in print_program_space to remove
unwanted side-effects. "info" commands and print routines should
generally not change the state of the debugger.

gdb/Changelog:

	* progspace.c (print_program_space): Don't prune program spaces
	before printing them.
2014-09-26 10:35:12 -04:00
Pedro Alves 03d4695724 infrun.c:user_visible_resume_ptid: Don't check singlestep_breakpoints_inserted_p
What matters for this function, is whether the user requested a
"step", for "set scheduler-locking step", not whether GDB is doing an
internal step for some reason.

 /* Return a ptid representing the set of threads that we will proceed,
    in the perspective of the user/frontend.  */
 extern ptid_t user_visible_resume_ptid (int step);

Therefore, the check for singlestep_breakpoints_inserted_p is actually
incorrect, and we end up applying schedlock more often on sss targets
than on non-sss targets.

Found by inspection while working on a patch that eliminates the
singlestep_breakpoints_inserted_p global.

Tested on x86_64 Fedora 20 on top of my 'software single-step on x86'
series.

gdb/
2014-09-25  Pedro Alves  <palves@redhat.com>

	* infrun.c (user_visible_resume_ptid): Don't check
	singlestep_breakpoints_inserted_p.
2014-09-25 16:56:00 +01:00
Pedro Alves e558d7c109 breakpoint.c: debug output when we skip inserting a breakpoint
gdb/
2014-09-25  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (should_be_inserted): Add debug output.
2014-09-25 16:49:43 +01:00
Pedro Alves 7f89fd6519 infrun.c: comment/typo fixes
gdb/
2014-09-25  Pedro Alves  <palves@redhat.com>

	* infrun.c (stepping_past_instruction_at)
	(clear_exit_convenience_vars): Point at infrun.h instead of
	inferior.h.
	(handle_signal_stop): Fix typo.
2014-09-25 16:31:04 +01:00
Yao Qi b7576e5cf4 Fix typo in thumb_in_function_epilogue_p
This patch fixes a typo in the bit mask I've made in my previous code
refactor.  If PC is in the register list, the bit 8 is one, so bit
mask 0xff00 should be used.  Current condition is a constant false.

gdb:

2014-09-24  Yao Qi  <yao@codesourcery.com>

	* arm-tdep.c (thumb_in_function_epilogue_p): Fix typo in the
	bitmask.
2014-09-24 20:55:01 +08:00
Yao Qi c4d9ceb647 Honour SIGILL and SIGSEGV in cancel breakpoint and event lwp selection
I see the following fail on arm-none-linux-gnueabi testing,

(gdb) continue^M
Continuing.^M
^M
Program received signal SIGILL, Illegal instruction.^M
[Switching to Thread 1003]^M
handler (signo=10) at
/scratch/yqi/arm-none-linux-gnueabi/src/gdb-trunk/gdb/testsuite/gdb.threads/sigstep-threads.c:33^M
33        tgkill (getpid (), gettid (), SIGUSR1);       /* step-2 */^M
(gdb) FAIL: gdb.threads/sigstep-threads.exp: continue

the cause is that GDBserver doesn't cancel the breakpoint if the stop
signal is SIGILL.  The kernel used here is a little old, 2.6.x, and
doesn't translate SIGILL to SIGTRAP when program hits breakpoint
instruction (which is an illegal instruction actually).  GDB and
GDBserver can translate SIGILL to SIGTRAP under certain circumstance,
so it is not a problem here.  See gdbserver/linux-low.c:linux_wait_1

  /* If this event was not handled before, and is not a SIGTRAP, we
     report it.  SIGILL and SIGSEGV are also treated as traps in case
     a breakpoint is inserted at the current PC.  If this target does
     not support internal breakpoints at all, we also report the
     SIGTRAP without further processing; it's of no concern to us.  */
  maybe_internal_trap
    = (supports_breakpoints ()
       && (WSTOPSIG (w) == SIGTRAP
	   || ((WSTOPSIG (w) == SIGILL
		|| WSTOPSIG (w) == SIGSEGV)
	       && (*the_low_target.breakpoint_at) (event_child->stop_pc))));

However, SIGILL and SIGSEGV is not considered when cancelling
breakpoint, which causes the fail above.  That is, when GDB is doing
software single step on address ADDR, both thread A and thread B hits the
software single step breakpoint, and get SIGILL.  GDB selects the event
from thread A, removes the software single step breakpoint, and resume
the program.  The event (SIGILL) from thread B is reported to GDB, but
GDB doesn't regard this SIGILL as SIGTRAP, because the breakpoint on
address ADDR was removed, so GDB reports "Program received signal
SIGILL".

The patch is to allow calling cancel_breakpoint if the signal is
SIGILL and SIGSEGV.  This patch fixes the fail above.  Likewise, event
lwp selection should honour SIGILL and SIGSEGV too.

gdb/gdbserver:

2014-09-23  Yao Qi  <yao@codesourcery.com>

	* linux-low.c (lp_status_maybe_breakpoint): New function.
	(linux_low_filter_event): Call lp_status_maybe_breakpoint.
	(count_events_callback): Likewise.
	(select_event_lwp_callback): Likewise.
	(cancel_breakpoints_callback): Likewise.
2014-09-23 20:36:38 +08:00
Jan-Benedict Glaw 342cc09114 2014-09-22 Jan-Benedict Glaw <jbglaw@lug-owl.de>
* gdb.texinfo (Set Breaks): Add missing "@end table".
2014-09-22 13:02:10 +02:00
Gary Benson 9a6cf3683d Update target_stop's documentation
This commit updates target_stop's documentation to clarify that
it is asynchronous.

gdb/ChangeLog:

	* target.c (target_stop): Updated comment.
2014-09-22 11:33:59 +01:00
Gary Benson 03f4463bfc Rename target_{stop,continue}_ptid
This commit renames target_stop_ptid as target_stop_and_wait and
target_continue_ptid as target_continue_no_signal.  Comments are
updated to more fully describe the functions' behaviour.

gdb/ChangeLog:

	* target/target.h (target_stop_ptid): Renamed as...
	(target_stop_and_wait): New function.  Updated comment.
	All uses updated.
	(target_continue_ptid): Renamed as...
	(target_continue_no_signal): New function.  Updated comment.
	All uses updated.
2014-09-22 11:33:59 +01:00
Pedro Alves a25a5a45ef Fix "breakpoint always-inserted off"; remove "breakpoint always-inserted auto"
By default, GDB removes all breakpoints from the target when the
target stops and the prompt is given back to the user.  This is useful
in case GDB crashes while the user is interacting, as otherwise,
there's a higher chance breakpoints would be left planted on the
target.

But, as long as any thread is running free, we need to make sure to
keep breakpoints inserted, lest a thread misses a breakpoint.  With
that in mind, in preparation for non-stop mode, we added a "breakpoint
always-inserted on" mode.  This traded off the extra crash protection
for never having threads miss breakpoints, and in addition is more
efficient if there's a ton of breakpoints to remove/insert at each
user command (e.g., at each "step").

When we added non-stop mode, and for a period, we required users to
manually set "always-inserted on" when they enabled non-stop mode, as
otherwise GDB removes all breakpoints from the target as soon as any
thread stops, which means the other threads still running will miss
breakpoints.  The test added by this patch exercises this.

That soon revealed a nuisance, and so later we added an extra
"breakpoint always-inserted auto" mode, that made GDB behave like
"always-inserted on" when non-stop was enabled, and "always-inserted
off" when non-stop was disabled.  "auto" was made the default at the
same time.

In hindsight, this "auto" setting was unnecessary, and not the ideal
solution.  Non-stop mode does depends on breakpoints always-inserted
mode, but only as long as any thread is running.  If no thread is
running, no breakpoint can be missed.  The same is true for all-stop
too.  E.g., if, in all-stop mode, and the user does:

 (gdb) c&
 (gdb) b foo

That breakpoint at "foo" should be inserted immediately, but it
currently isn't -- currently it'll end up inserted only if the target
happens to trip on some event, and is re-resumed, e.g., an internal
breakpoint triggers that doesn't cause a user-visible stop, and so we
end up in keep_going calling insert_breakpoints.  The test added by
this patch also covers this.

IOW, no matter whether in non-stop or all-stop, if the target fully
stops, we can remove breakpoints.  And no matter whether in all-stop
or non-stop, if any thread is running in the target, then we need
breakpoints to be immediately inserted.  And then, if the target has
global breakpoints, we need to keep breakpoints even when the target
is stopped.

So with that in mind, and aiming at reducing all-stop vs non-stop
differences for all-stop-on-stop-of-non-stop, this patch fixes
"breakpoint always-inserted off" to not remove breakpoints from the
target until it fully stops, and then removes the "auto" setting as
unnecessary.  I propose removing it straight away rather than keeping
it as an alias, unless someone complains they have scripts that need
it and that can't adjust.

Tested on x86_64 Fedora 20.

gdb/
2014-09-22  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention merge of "breakpoint always-inserted" modes "off"
	and "auto" merged.
	* breakpoint.c (enum ugll_insert_mode): New enum.
	(always_inserted_mode): Now a plain boolean.
	(show_always_inserted_mode): No longer handle AUTO_BOOLEAN_AUTO.
	(breakpoints_always_inserted_mode): Delete.
	(breakpoints_should_be_inserted_now): New function.
	(insert_breakpoints): Pass UGLL_INSERT to
	update_global_location_list instead of calling
	insert_breakpoint_locations manually.
	(create_solib_event_breakpoint_1): New, factored out from ...
	(create_solib_event_breakpoint): ... this.
	(create_and_insert_solib_event_breakpoint): Use
	create_solib_event_breakpoint_1 instead of calling
	insert_breakpoint_locations manually.
	(update_global_location_list): Change parameter type from boolean
	to enum ugll_insert_mode.  All callers adjusted.  Adjust to use
	breakpoints_should_be_inserted_now and handle UGLL_INSERT.
	(update_global_location_list_nothrow): Change parameter type from
	boolean to enum ugll_insert_mode.
	(_initialize_breakpoint): "breakpoint always-inserted" option is
	now a boolean command.  Update help text.
	* breakpoint.h (breakpoints_always_inserted_mode): Delete declaration.
	(breakpoints_should_be_inserted_now): New declaration.
	* infrun.c (handle_inferior_event) <TARGET_WAITKIND_LOADED>:
	Remove breakpoints_always_inserted_mode check.
	(normal_stop): Adjust to use breakpoints_should_be_inserted_now.
	* remote.c (remote_start_remote): Likewise.

gdb/doc/
2014-09-22  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Set Breaks): Document that "set breakpoint
	always-inserted off" is the default mode now.  Delete
	documentation of "set breakpoint always-inserted auto".

gdb/testsuite/
2014-09-22  Pedro Alves  <palves@redhat.com>

	* gdb.threads/break-while-running.exp: New file.
	* gdb.threads/break-while-running.c: New file.
2014-09-22 10:07:04 +01:00
Pedro Alves 04086b458a Tell update_global_location_list to insert breakpoints
This adds a new mode for update_global_location_list, that allows
callers saying "please insert breakpoints, even if
breakpoints_always_inserted_mode() is false".  This allows removing a
couple breakpoints_always_inserted_mode checks.

gdb/
2014-09-22  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (enum ugll_insert_mode): Add UGLL_INSERT.
	(insert_breakpoints): Don't call insert_breakpoint_locations here.
	Instead, pass UGLL_INSERT to update_global_location_list.
	(update_global_location_list): Change parameter type from boolean
	to enum ugll_insert_mode.  All callers adjusted.  Adjust to use
	breakpoints_should_be_inserted_now and handle UGLL_INSERT.
	(create_solib_event_breakpoint_1): New, factored out from ...
	(create_solib_event_breakpoint): ... this.
	(create_and_insert_solib_event_breakpoint): Use
	create_solib_event_breakpoint_1 instead of calling
	insert_breakpoint_locations manually.
	(update_global_location_list): Handle UGLL_INSERT.
2014-09-22 10:06:25 +01:00
Pedro Alves 447023601a Change parameter type of update_global_location_list from boolean to enum
Later we'll want a tristate, but for now, convert to an enum that maps 1-1
with the current boolean's true/false.

gdb/
2014-09-22  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (enum ugll_insert_mode): New enum.
	(update_global_location_list)
	(update_global_location_list_nothrow): Change parameter type from
	boolean to enum ugll_insert_mode.  All callers adjusted.
2014-09-22 09:56:54 +01:00
Joel Brobecker 93c6145af6 Add Sergio Durigan Junior as maintainer of SystemTap support in GDB.
gdb/ChangeLog:

	* MAINTAINERS: Add Sergio Durigan Junior as maintainer of
	SystemTap support in GDB.
2014-09-19 16:50:28 -07:00
Don Breazeal 89a5711c56 Refactor ptrace extended event status.
This commit implements functions for identifying and extracting extended
ptrace event information from a Linux wait status.  These are just
convenience functions intended to hide the ">> 16" used to extract the
event from the wait status word, replacing the hard-coded shift with a more
descriptive function call.  This is preparatory work for implementation of
follow-fork and detach-on-fork for extended-remote linux targets.

gdb/ChangeLog:

	* linux-nat.c (linux_handle_extended_wait): Call
	linux_ptrace_get_extended_event.
	(wait_lwp): Call linux_is_extended_waitstatus.
	(linux_nat_filter_event): Call linux_ptrace_get_extended_event
	and linux_is_extended_waitstatus.
	* nat/linux-ptrace.c (linux_test_for_tracefork): Call
	linux_ptrace_get_extended_event.
	(linux_ptrace_get_extended_event): New function.
	(linux_is_extended_waitstatus): New function.
	* nat/linux-ptrace.h (linux_ptrace_get_extended_event)
	(linux_is_extended_waitstatus): New declarations.

gdb/gdbserver/ChangeLog:

	* linux-low.c (handle_extended_wait): Call
	linux_ptrace_get_extended_event.
	(get_stop_pc, get_detach_signal, linux_low_filter_event): Call
	linux_is_extended_waitstatus.

---
2014-09-19 10:54:34 -07:00
Yao Qi 00ba3162ed Run dw2-var-zero-addr.exp with --readnow
This patch is to extend dw2-var-zero-add.exp to cover the case that
partial symtabl is not used while full symtab is used, in order to
cover the changes in patch 2/3.  This patch restarts GDB with
--readnow and does the same test again.

gdb/testsuite:

2014-09-19  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/dw2-var-zero-addr.exp: Move test into new proc test.
	Invoke test.  Restart GDB with --readnow and invoke test again.
2014-09-19 16:53:34 +08:00
Yao Qi c3b7b696c2 Check function is GC'ed
I see the following fail on arm-none-eabi target,

(gdb) b 24^M
Breakpoint 1 at 0x4: file
../../../../git/gdb/testsuite/gdb.base/break-on-linker-gcd-function.cc,
line 24.^M
(gdb) FAIL: gdb.base/break-on-linker-gcd-function.exp: b 24

Currently, we are using flag has_section_at_zero to determine whether
address zero in debug info means the corresponding code has been
GC'ed, like this:

	case DW_LNE_set_address:
	  address = read_address (abfd, line_ptr, cu, &bytes_read);

	  if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
	    {
	      /* This line table is for a function which has been
		 GCd by the linker.  Ignore it.  PR gdb/12528 */

However, this is incorrect on some bare metal targets, as .text
section is located at 0x0, so dwarf2_per_objfile->has_section_at_zero
is true.  If a function is GC'ed by linker, the address is zero.  GDB
thinks address zero is a function's address rather than this function
is GC'ed.

In this patch, we choose 'lowpc' got in read_file_scope to check
whether 'lowpc' is greater than zero.  If it isn't, address zero really
means the function is GC'ed.  In this patch, we pass 'lowpc' in
read_file_scope through handle_DW_AT_stmt_list and dwarf_decode_lines,
and to dwarf_decode_lines_1 finally.

This patch fixes the fail above. This patch also covers the path that
partial symbol isn't used, which is tested by starting gdb with
--readnow option.

It is regression tested on x86-linux with
target_board=dwarf4-gdb-index, and arm-none-eabi.  OK to apply?

gdb:

2014-09-19  Yao Qi  <yao@codesourcery.com>

	* dwarf2read.c (dwarf_decode_lines): Update declaration.
	(handle_DW_AT_stmt_list): Add argument 'lowpc'.  Update
	comments.  Callers update.
	(dwarf_decode_lines): Likewise.
	(dwarf_decode_lines_1): Add argument 'lowpc'.  Update
	comments.  Skip the line table if  'lowpc' is greater than
	'address'.  Don't check
	dwarf2_per_objfile->has_section_at_zero.

gdb/testsuite:

2014-09-19  Yao Qi  <yao@codesourcery.com>

	* gdb.base/break-on-linker-gcd-function.exp: Move test into new
	proc set_breakpoint_on_gcd_function.  Invoke
	set_breakpoint_on_gcd_function.  Restart GDB with --readnow and
	invoke set_breakpoint_on_gcd_function again.
2014-09-19 16:53:27 +08:00
Doug Evans 2b4fd423cf New "producer" attribute of python gdb.Symtab.
gdb/ChangeLog:

	* NEWS: Mention new "producer" attribute of gdb.Symtab.
	* python/py-symtab.c (stpy_get_producer): New function.
	(symtab_object_getset): Add "producer" attribute.

gdb/doc/ChangeLog:

	* python.texi (Symbol Tables In Python): Document "producer"
	attribute of gdb.Symtab objects.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/symtab-producer.exp: New file.
2014-09-18 10:09:12 -07:00
Ulrich Weigand 5e43d46791 PR gdb/17384: Do not print memory errors in safe_read_memory_integer
If accessing memory via safe_read_memory_integer fails, that function
used to print an error message even though callers were perfectly able
to handle (and even expected!) failures.

This patch removes the confusing message by changing the routine to
directly use target_read_memory.

gdb/ChangeLog:

	PR gdb/17384
	* corefile.c (struct captured_read_memory_integer_arguments): Remove.
	(do_captured_read_memory_integer): Remove.
	(safe_read_memory_integer): Use target_read_memory directly instead
	of catching errors in do_captured_read_memory_integer.
2014-09-17 17:29:27 +02:00
Sergio Durigan Junior a594760181 Add test for global variable that is nested by another DSO
This is just a testcase addition that I am proposing for upstream GDB.
We have this in our internal tree, and the related RH bug is:

  <https://bugzilla.redhat.com/show_bug.cgi?id=809179>

(You might not be able to see all the comments without privileges.)

This bug is about a global variable that got incorrectly displayed by
GDB.  This bug has already been fixed a long time ago by Joel's
commit:

  commit 19630284f5
  Author: Joel Brobecker <brobecker@gnat.com>
  Date:   Tue Jun 5 13:50:50 2012 +0000

But I think a testcase for it wouldn't hurt.

So, consider the following scenario:

  $ cat solib1.c
  int test;
  void c_main (void)
  {
    test = 42;
  }

  $ cat solib2.c
  int test;
  void b_main (void)
  {
    test = 42;
  }

  $ cat main.c
  int main (int argc, char *argv[])
  {
    c_main ();
    b_main ();
    return 0;
  }

  $ gcc -g -fPIC -shared -o libSO1.so -c solib1.c
  $ gcc -g -fPIC -shared -o libSO2.so -c solib2.c
  $ gcc -g -o main -L$PWD -lSO1 -lSO2 main.c
  $ LD_LIBRARY_PATH=. gdb -q -batch -ex 'b c_main' -ex r -ex n -ex 'p test' ./main
  ...
  $1 = 0

This happened with GDB before Joel's commit above.  Now, things work
and GDB is able to correctly display the nested global variable:

  $ LD_LIBRARY_PATH=. gdb -q -batch -ex 'b c_main' -ex r -ex n -ex 'p test' ./main
  ...
  $1 = 42

The testcase attached tests this behavior.

gdb/testsuite/ChangeLog:
2014-09-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/global-var-nested-by-dso-solib1.c: New file.
	* gdb.base/global-var-nested-by-dso-solib2.c: Likewise.
	* gdb.base/global-var-nested-by-dso.c: Likewise.
	* gdb.base/global-var-nested-by-dso.exp: Likewise.
2014-09-16 22:57:06 -04:00
Maciej W. Rozycki 04e799796f CONTRIBUTE: For internals refer to wiki, not gdb/doc 2014-09-16 23:45:30 +01:00
Joel Brobecker bffc0964c7 Fix CPPFLAGS handling in gdbserver's build.
In gdb/gdbserver/Makefile.in, IPAGENT_CFLAGS is defined using
an expression which references $(CPPFLAGS). But CPPFLAGS isn't
actually defined.

This patch first adds a CPPFLAGS definition, so as to inherit
the value passed at configure time (if any). And it then makes it
part of INTERNAL_CFLAGS_BASE, instead. There is no reason that
CPPFLAGS be useful for a certain class of source files, and not
the rest. This is also consistent with what's done in GDB.

gdb/gdbserver/ChangeLog:

        * Makefile.in (CPPFLAGS): Define.
        (INTERNAL_CFLAGS_BASE): Add ${CPPFLAGS}.
        (IPAGENT_CFLAGS): Remove ${CPPFLAGS}.

Tested by rebuilding GDBserver with a dummy CPPFLAGS, and verifying
that the compilation command was altered as expected.
2014-09-16 13:31:07 -07:00
Sergio Durigan Junior 76aeec5b98 Remove dead code from objc-lang.c (spurious "fprintf (stderr...")
This obvious change removes dead code from objc-lang.c.  I was
grepping for "fprintf (stderr..." and found this code between "#if
0".."#endif" blocks.

2014-09-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* objc-lang.c (find_implementation_from_class): Remove dead code.
2014-09-16 15:34:27 -04:00
Sergio Durigan Junior 2f693f9d21 Replace "fprintf (stderr..." by "fprintf_unfiltered (gdb_stdlog..."
This is an obvious replacement of "fprintf (stderr..." by
"fprintf_unfiltered (gdb_stdlog...", which is the standard to use in
these cases.

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

	PR cli/7233
	* linux-nat.c (linux_nat_wait_1): Replace "fprintf (stderr..." by
	"fprintf_unfiltered (gdb_stdlog...)".
2014-09-16 15:30:41 -04:00
Sergio Durigan Junior 91c190590a gdb.base/watch-bitfields.exp: Improve test
Make test messages unique and a couple other tweaks.

gdb/testsuite/
2014-09-16  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/watch-bitfields.exp: Pass string other than test file
	name to prepare_for_testing.
	(watch): New procedure.
	(expect_watchpoint): Use with_test_prefix.
	(top level): Factor out tests to ...
	(test_watch_location, test_regular_watch): ... these new
	procedures, and use with_test_prefix and gdb_continue_to_end.
2014-09-16 17:55:21 +01:00
Patrick Palka bb9d5f81c3 Fix PR12526: -location watchpoints for bitfield arguments
PR 12526 reports that -location watchpoints against bitfield arguments
trigger false positives when bits around the bitfield, but not the
bitfield itself, are modified.

This happens because -location watchpoints naturally operate at the
byte level, not at the bit level.  When the address of a bitfield
lvalue is taken, information about the bitfield (i.e. its offset and
size) is lost in the process.

This information must first be retained throughout the lifetime of the
-location watchpoint.  This patch achieves this by adding two new
fields to the watchpoint struct: val_bitpos and val_bitsize.  These
fields are set when a watchpoint is first defined in watch_command_1.
They are both equal to zero if the watchpoint is not a -location
watchpoint or if the argument is not a bitfield.

Then these bitfield parameters are used inside update_watchpoint and
watchpoint_check to extract the actual value of the bitfield from the
watchpoint address, with the help of a local helper function
extract_bitfield_from_watchpoint_value.

Finally when creating a HW breakpoint pointing to a bitfield, we
optimize the address and length of the breakpoint.  By skipping over
the bytes that don't cover the bitfield, this step reduces the
frequency at which a read watchpoint for the bitfield is triggered.
It also reduces the number of times a false-positive call to
check_watchpoint is triggered for a write watchpoint.

gdb/
	PR breakpoints/12526
	* breakpoint.h (struct watchpoint): New fields val_bitpos and
	val_bitsize.
	* breakpoint.c (watch_command_1): Use these fields to retain
	bitfield information.
	(extract_bitfield_from_watchpoint_value): New function.
	(watchpoint_check): Use it.
	(update_watchpoint): Use it.  Optimize the address and length of a
	HW watchpoint pointing to a bitfield.
	* value.h (unpack_value_bitfield): New prototype.
	* value.c (unpack_value_bitfield): Make extern.

gdb/testsuite/
	PR breakpoints/12526
	* gdb.base/watch-bitfields.exp: New file.
	* gdb.base/watch-bitfields.c: New file.
2014-09-16 17:40:06 +01:00
Pedro Alves deb8ff2b7a Remove documention of dead "target vxworks"
"target vxworks" and friends have been removed 10 years ago already:

  commit e84ecc995d
  Author:     Andrew Cagney <cagney@redhat.com>
  AuthorDate: Sat Nov 13 23:10:02 2004 +0000

     2004-11-13  Andrew Cagney  <cagney@gnu.org>

         * configure.tgt: Delete i[34567]86-*-vxworks*, m68*-netx-*,
         m68*-*-vxworks*, mips*-*-vxworks*, powerpc-*-vxworks*, and
         sparc-*-vxworks*.
         * NEWS: Mention that vxworks was deleted.
     (...)
         * remote-vxmips.c, remote-vx.c: Delete.
         * remote-vx68.c: Delete.
     (...)

This removes related leftover cruft from the manual.

gdb/doc/
2014-09-16  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Starting) <run command>: Don't mention VxWorks.
	(Embedded OS): Remove VxWorks menu entry.
	(VxWorks): Remove node.
2014-09-16 16:38:12 +01:00
Gary Benson 0bfdf32fa1 Rename current_inferior as current_thread in gdbserver
GDB has a function named "current_inferior" and gdbserver has a global
variable named "current_inferior", but the two are not equivalent;
indeed, gdbserver does not have any real equivalent of what GDB calls
an inferior.  What gdbserver's "current_inferior" is actually pointing
to is a structure describing the current thread.  This commit renames
current_inferior as current_thread in gdbserver to clarify this.  It
also renames the function "set_desired_inferior" to "set_desired_thread"
and renames various local variables from foo_inferior to foo_thread.

gdb/gdbserver/ChangeLog:

	* inferiors.h (current_inferior): Renamed as...
	(current_thread): New variable.  All uses updated.
	* linux-low.c (get_pc): Renamed saved_inferior as saved_thread.
	(maybe_move_out_of_jump_pad): Likewise.
	(cancel_breakpoint): Likewise.
	(linux_low_filter_event): Likewise.
	(wait_for_sigstop): Likewise.
	(linux_resume_one_lwp): Likewise.
	(need_step_over_p): Likewise.
	(start_step_over): Likewise.
	(linux_stabilize_threads): Renamed save_inferior as saved_thread.
	* linux-x86-low.c (x86_linux_update_xmltarget): Likewise.
	* proc-service.c (ps_lgetregs): Renamed reg_inferior as reg_thread
	and save_inferior as saved_thread.
	* regcache.c (get_thread_regcache): Renamed saved_inferior as
	saved_thread.
	(regcache_invalidate_thread): Likewise.
	* remote-utils.c (prepare_resume_reply): Likewise.
	* thread-db.c (thread_db_get_tls_address): Likewise.
	(disable_thread_event_reporting): Likewise.
	(remove_thread_event_breakpoints): Likewise.
	* tracepoint.c (gdb_agent_about_to_close): Renamed save_inferior
	as saved_thread.
	* target.h (set_desired_inferior): Renamed as...
	(set_desired_thread): New declaration.  All uses updated.
	* server.c (myresume): Updated comment to reference thread instead
	of inferior.
	(handle_serial_event): Likewise.
	(handle_target_event): Likewise.
2014-09-16 15:57:13 +01:00
Pedro Alves 635856f584 Fix watchpoint-stops-at-right-insn.exp
Silly typo...

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

	* gdb.base/watchpoint-stops-at-right-insn.exp (test): Compare
	software and hardware addresses, not software address against
	itself.
2014-09-16 14:27:57 +01:00
Pedro Alves 7280ceea02 Add test to make sure GDB knows which "kind" of watchpoint the target has
This adds a test that makes sure GDB knows whether the target has
continuable, or non-continuable watchpoints.

That is, the test confirms that GDB presents a watchpoint value change
at the first instruction right after the instruction that changes
memory.

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

	* gdb.base/watchpoint-stops-at-right-insn.c: New file.
	* gdb.base/watchpoint-stops-at-right-insn.exp: New file.
2014-09-16 14:05:06 +01:00
Samuel Thibault 05db5edd79 Add hardware watchpoint support for x86 GNU Hurd.
gdb/
	* config/i386/i386gnu.mh (NATDEPFILES): Add x86-nat.o and
	x86-dregs.o.
	* gnu-nat.c (inf_threads): New function.
	* gnu-nat.h (inf_threads_ftype): New typedef.
	(inf_threads): New declaration.
	* i386gnu-nat.c: Include "x86-nat.h" and "inf-child.h".
	[i386_DEBUG_STATE] (i386_gnu_dr_get, i386_gnu_dr_set)
	(i386_gnu_dr_set_control_one, i386_gnu_dr_set_control)
	(i386_gnu_dr_set_addr_one, i386_gnu_dr_set_addr)
	(i386_gnu_dr_get_reg, i386_gnu_dr_get_addr, 386_gnu_dr_get_status)
	(i386_gnu_dr_get_control): New functions.
	(reg_addr): New structure.
	(_initialize_i386gnu_nat) [i386_DEBUG_STATE]: Initialize hardware
	i386 debugging register hooks.
	* NEWS: Mention this.
2014-09-16 14:38:09 +02:00
Pedro Alves 428b16bd5a Remove support for testing against dead "target vxworks"
"target vxworks" and friends have been removed 10 years ago already:

 commit e84ecc995d
 Author:     Andrew Cagney <cagney@redhat.com>
 AuthorDate: Sat Nov 13 23:10:02 2004 +0000

    2004-11-13  Andrew Cagney  <cagney@gnu.org>

        * configure.tgt: Delete i[34567]86-*-vxworks*, m68*-netx-*,
        m68*-*-vxworks*, mips*-*-vxworks*, powerpc-*-vxworks*, and
        sparc-*-vxworks*.
        * NEWS: Mention that vxworks was deleted.
	(...)
        * remote-vxmips.c, remote-vx.c: Delete.
        * remote-vx68.c: Delete.
	(...)

This removes related leftover cruft from the testsuite.

Tested on x86_64 Fedora 20, native and gdbserver.

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

	* config/vx.exp, config/vxworks.exp, config/vxworks29k.exp: Delete
	files.
	* gdb.base/a2-run.exp: Remove all code guarded by istarget
	"*-*-vxworks*" throughout.
	* gdb.base/break.exp: Likewise.
	* gdb.base/default.exp: Likewise.
	* gdb.base/scope.exp: Likewise.
	* gdb.base/sepdebug.exp: Likewise.
	* gdb.base/break.c: Remove all code guarded by #ifdef vxworks
	throughout.
	* gdb.base/run.c: Likewise.
	* gdb.base/sepdebug.c: Likewise.
	* gdb.hp/gdb.aCC/run.c: Likewise.
	* gdb.reverse/until-reverse.c: Likewise.
	* lib/gdb.exp (gdb_compile): Remove is_vxworks branch.
2014-09-16 12:37:03 +01:00
Yao Qi 666d413cc3 Another board file for remote host
In the recent review to my patch about copying files to remote host,
we find that we need a board file which is more closely mapped real
remote host testing to improve coverage.  With the board file
local-remote-host-native.exp, DejaGNU copies files to
$build/gdb/testsuite/remote-host to emulate the effect of remote host.
Is it OK?

gdb/testsuite:

2014-09-16  Yao Qi  <yao@codesourcery.com>

	* boards/local-remote-host-native.exp: New file.
2014-09-16 19:13:01 +08:00
Omair Javaid 5a578da5e2 Implement support for recording vector data transfer instructions
gdb:

2014-08-13  Omair Javaid  <omair.javaid@linaro.org>

	* arm-tdep.c (arm_record_vdata_transfer_insn): Added record handler for
	vector data transfer instructions.
	(arm_record_coproc_data_proc): Updated.
2014-09-16 04:06:43 +05:00
Omair Javaid f20f80ddff Implement support for recording extension register ld/st insn
gdb:

2014-08-13  Omair Javaid  <omair.javaid@linaro.org>

	* arm-tdep.c (arm_record_asimd_vfp_coproc): Replace stub handler with
	arm_record_exreg_ld_st_insn.
	(arm_record_exreg_ld_st_insn): Add record handler for ex-register
	load/store insns.
2014-09-16 04:04:20 +05:00
Omair Javaid 851f26ae7b Implement support for recording VFP data processing instructions
gdb:

2014-08-13  Omair Javaid  <omair.javaid@linaro.org>

	* arm-tdep.c (arm_record_coproc_data_proc): Updated.
	(arm_record_vfp_data_proc_insn): Added record handler for VFP data
	processing instructions.
2014-09-16 04:01:24 +05:00
Omair Javaid 1e1b656356 Implement support for recording thumb2 ASIMD struct ld/st insns
gdb:

2014-08-13  Omair Javaid  <omair.javaid@linaro.org>

	* arm-tdep.c (thumb2_record_asimd_struct_ld_st): Add record handler
	for advance SIMD struct ld/st insn.
	(thumb2_record_decode_insn_handler): Replace stub handler with
	thumb2_record_asimd_struct_ld_st.
2014-09-16 03:56:38 +05:00