Commit Graph

36283 Commits

Author SHA1 Message Date
Gary Benson 4bd7dc4255 Introduce target_filesystem_is_local
This commit introduces a new target method target_filesystem_is_local
which can be used to determine whether or not the filesystem accessed
by the target_fileio_* methods is the local filesystem.

gdb/ChangeLog:

	* target.h (struct target_ops) <to_filesystem_is_local>:
	New field.
	(target_filesystem_is_local): New macro.
	* target-delegates.c: Regenerate.
	* remote.c (remote_filesystem_is_local): New function.
	(init_remote_ops): Initialize to_filesystem_is_local.
2015-04-02 13:38:28 +01:00
Gary Benson 9b15c1f041 Introduce target_fileio_fstat
This commit introduces a new target method target_fileio_fstat
which can be used to retrieve information about files opened with
target_fileio_open.

gdb/ChangeLog:

	* target.h (struct target_ops) <to_fileio_fstat>: New field.
	(target_fileio_fstat): New declaration.
	* target.c (target_fileio_fstat): New function.
	* inf-child.c (inf_child_fileio_fstat): Likewise.
	(inf_child_target): Initialize to_fileio_fstat.
	* remote.c (init_remote_ops): Likewise.
2015-04-02 13:38:28 +01:00
Sasha Smundak d11916aa89 Add support for writing unwinders in Python.
gdb/ChangeLog:

	* Makefile.in (SUBDIR_PYTHON_OBJS): Add py-unwind.o.
	(SUBDIR_PYTHON_SRCS): Add py-unwind.c.
	(py-unwind.o): New recipe.
	* NEWS: mention Python frame unwinding.
	* data-directory/Makefile.in (PYTHON_FILE_LIST): Add
	gdb/unwinder.py and gdb/command/unwinder.py
	* python/lib/gdb/__init__.py (packages): Add frame_unwinders
	list.
	(execute_unwinders): New function.
	* python/lib/gdb/command/unwinders.py: New file.
	* python/lib/gdb/unwinder.py: New file.
	* python/py-objfile.c (objfile_object): Add frame_unwinders field.
	(objfpy_dealloc): Decrement frame_unwinders reference count.
	(objfpy_initialize): Create frame_unwinders list.
	(objfpy_get_frame_unwinders): New function.
	(objfpy_set_frame_unwinders): Ditto.
	(objfile_getset): Add frame_unwinders attribute to Objfile.
	* python/py-progspace.c (pspace_object): Add frame_unwinders field.
	(pspy_dealloc): Decrement frame_unwinders reference count.
	(pspy_initialize): Create frame_unwinders list.
	(pspy_get_frame_unwinders): New function.
	(pspy_set_frame_unwinders): Ditto.
	(pspy_getset): Add frame_unwinders attribute to gdb.Progspace.
	* python/py-unwind.c: New file.
	* python/python-internal.h (pspy_get_name_unwinders): New prototype.
	(objpy_get_frame_unwinders): New prototype.
	(gdbpy_initialize_unwind): New prototype.
	* python/python.c (gdbpy_apply_type_printers): Call
	gdbpy_initialize_unwind.

gdb/doc/ChangeLog:

	* doc/python.texi (Writing a Frame Unwinder in Python): Add
	section.

gdb/testsuite/ChangeLog:

	* gdb.python/py-unwind-maint.c: New file.
	* gdb.python/py-unwind-maint.exp: New test.
	* gdb.python/py-unwind-maint.py: New file.
	* gdb.python/py-unwind.c: New file.
	* gdb.python/py-unwind.exp: New test.
	* gdb.python/py-unwind.py: New test.
2015-04-01 11:49:12 -07:00
Pedro Alves 6b403daae9 infrun.c:resume: currently_stepping after clearing stepped_breakpoint
My all-stop-on-top-of-non-stop series manages to shows regressions due
to this latent bug.  currently_stepping returns true if
stepped_breakpoint is set.  Obviously we should clear
it before checking currently_stepping, not after.

Tested on x86_64 Fedora 20.

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

	* infrun.c (resume): Check currently_stepping after clearing
	stepped_breakpoint, not before.
2015-04-01 15:35:38 +01:00
Pedro Alves a14711808e gdb.threads/manythreads.exp: can't read "test": no such variable
If interrupt_and_wait manages to trigger the FAIL path, we get:

  ERROR OCCURED: can't read "test": no such variable

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

	* gdb.threads/manythreads.exp (interrupt_and_wait): Pass $message
	to fail instead of non-existent $test.
2015-04-01 15:30:13 +01:00
Pedro Alves 0bbeccb1ee Fix gdb_spawn_with_cmdline_opts with non-empty GDBFLAGS
Running attach.exp with a DejaGnu board that sets GDBFLAGS, like
e.g.,:

  set GDBFLAGS "-ex \"set displaced off\""

fails with (line breaks added for clarity):

 (gdb) PASS: gdb.base/attach.exp: starting with --pid
 Executing on build: kill -9 3537    (timeout = 300)
 spawn -ignore SIGHUP kill -9 3537
 spawn of build/gdb/gdb -nw -nx \
  -data-directory build/gdb/testsuite/../data-directory  \
  -ex "set displaced off"-iex "set height 0" -iex "set width 0" \
                     ^^^^^^^^
  --pid=4468 -ex "start"  failed
 ERROR: Spawning build/gdb/gdb failed.
 UNRESOLVED: gdb.base/attach.exp: cmdline attach run: run to prompt

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

	* lib/gdb.exp (gdb_spawn_with_cmdline_opts): Append space to
	GDBFLAGS if not empty.
2015-04-01 15:25:21 +01:00
Pedro Alves 1176ecec70 Make print_target_wait_results print the whole ptid
Makes "set debug infrun 1" a bit clearer.  Before:

infrun: target_wait (-1, status) =
 infrun:   6299 [Thread 0x7ffff7fc1700 (LWP 6340)],

after:

 infrun: target_wait (-1.0.0, status) =
 infrun:   7233.7237.0 [Thread 0x7ffff7fc1700 (LWP 7237)],

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

	* infrun.c (print_target_wait_results): Print all the ptid
	elements.
2015-04-01 15:21:47 +01:00
Pedro Alves de1fe8c8ab keep_going: Add missing discard_cleanups call
By inspection, I noticed a path where we return without discarding the
cleanups.

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

	* infrun.c (keep_going): Also discard cleanups if inserting
	breakpoints fails.
2015-04-01 15:18:41 +01:00
Pedro Alves e6f5c25b57 wait_for_inferior and errors thrown from target_wait
Noticed that if an error is thrown out of target_wait, we miss running
finish_thread_state_cleanup.

Tested on x86_64 Fedora 20, with "maint set target-async off".

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

	* infrun.c (wait_for_inferior): Install the
	finish_thread_state_cleanup cleanup across the whole function, not
	just around handle_inferior_event.
2015-04-01 14:58:56 +01:00
Pedro Alves 1ac806b8a7 Use do_target_resume when stepping past permanent breakpoint too
We can use the recently added do_target_resume do simplify the code a
bit here.

Tested on x86_64 Fedora 20.

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

	* infrun.c (resume) <step past permanent breakpoint>: Use
	do_target_resume.
2015-04-01 14:29:05 +01:00
Pedro Alves 2ee52aa428 linux_nat.c: Mark new thread running even if momentarily pausing
My all-stop-on-top-of-non-stop series manages to trip on a bug in the
linux-nat.c backend while running the testsuite.  If a thread is
discovered while threads are being momentarily paused (without the
core's intervention), the thread ends up stuck in THREAD_STOPPED
state, even though from the user's perspective, the thread is running
even while it is paused.

From inspection, in the current sources, this can happen if we call
stop_and_resume_callback, though there's no way to test that with
current Linux kernels.

(While trying to come up with test to exercise this, I stumbled on:
  https://sourceware.org/ml/gdb-patches/2015-03/msg00850.html

... which does include a non-trivial test, so I think I can still
claim I come out net positive. :-) )

Tested on x86_64 Fedora 20.

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

	* linux-nat.c (linux_handle_extended_wait): Always call set_running.
2015-04-01 14:23:10 +01:00
Pierre-Marie de Rodat 3c724c8ca9 Share the "multi_line" helper among all testcases
gdb/testsuite/ChangeLog:

	* gdb.ada/complete.exp: Remove "multi_line".
	* gdb.ada/info_exc.exp: Remove "multi_line".
	* gdb.ada/packed_tagged.exp: Remove "multi_line".
	* gdb.ada/ptype_field.exp: Remove "multi_line".
	* gdb.ada/sym_print_name.exp: Remove "multi_line".
	* gdb.ada/tagged.exp: Remove "multi_line".
	* gdb.btrace/buffer-size.exp: Replace [join [list ...]] with
	[multi_line ...]
	* gdb.btrace/delta.exp: Likewise.
	* gdb.btrace/exception.exp: Likewise.
	* gdb.btrace/function_call_history.exp: Likewise.
	* gdb.btrace/instruction_history.exp: Likewise.
	* gdb.btrace/nohist.exp: Likewise.
	* gdb.btrace/record_goto.exp: Likewise.
	* gdb.btrace/segv.exp: Likewise.
	* gdb.btrace/stepi.exp: Likewise.
	* gdb.btrace/tailcall.exp: Likewise.
	* gdb.btrace/unknown_functions.exp: Likewise.
	* gdb.dwarf2/dw2-undefined-ret-addr.exp: Likewise.
	* lib/gdb.exp: Add the "multi_line" helper.
2015-04-01 15:06:39 +02:00
Pierre-Marie de Rodat 5445da1b76 Add myself as a write-after-approval GDB maintainer
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add "Pierre-Marie de
	Rodat".
2015-04-01 15:06:07 +02:00
Pedro Alves 4eec2deb06 Crash on thread id wrap around
On GNU/Linux, if the target reuses the TID of a thread that GDB still
has in its list marked as THREAD_EXITED, GDB crashes, like:

 (gdb) continue
 Continuing.
 src/gdb/thread.c:789: internal-error: set_running: Assertion `tp->state != THREAD_EXITED' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/tid-reuse.exp: continue to breakpoint: after_reuse_time (GDB internal error)

Here:

 (top-gdb) bt
 #0  internal_error (file=0x953dd8 "src/gdb/thread.c", line=789, fmt=0x953da0 "%s: Assertion `%s' failed.")
     at src/gdb/common/errors.c:54
 #1  0x0000000000638514 in set_running (ptid=..., running=1) at src/gdb/thread.c:789
 #2  0x00000000004bda42 in linux_handle_extended_wait (lp=0x16f5760, status=0, stopping=0) at src/gdb/linux-nat.c:2114
 #3  0x00000000004bfa24 in linux_nat_filter_event (lwpid=20570, status=198015) at src/gdb/linux-nat.c:3127
 #4  0x00000000004c070e in linux_nat_wait_1 (ops=0xe193d0, ptid=..., ourstatus=0x7fffffffd2c0, target_options=1) at src/gdb/linux-nat.c:3478
 #5  0x00000000004c1015 in linux_nat_wait (ops=0xe193d0, ptid=..., ourstatus=0x7fffffffd2c0, target_options=1) at src/gdb/linux-nat.c:3722
 #6  0x00000000004c92d2 in thread_db_wait (ops=0xd80b60 <thread_db_ops>, ptid=..., ourstatus=0x7fffffffd2c0, options=1)
     at src/gdb/linux-thread-db.c:1525
 #7  0x000000000066db43 in delegate_wait (self=0xd80b60 <thread_db_ops>, arg1=..., arg2=0x7fffffffd2c0, arg3=1) at src/gdb/target-delegates.c:116
 #8  0x000000000067e54b in target_wait (ptid=..., status=0x7fffffffd2c0, options=1) at src/gdb/target.c:2206
 #9  0x0000000000625111 in fetch_inferior_event (client_data=0x0) at src/gdb/infrun.c:3275
 #10 0x0000000000648a3b in inferior_event_handler (event_type=INF_REG_EVENT, client_data=0x0) at src/gdb/inf-loop.c:56
 #11 0x00000000004c2ecb in handle_target_event (error=0, client_data=0x0) at src/gdb/linux-nat.c:4655

I managed to come up with a test that reliably reproduces this.  It
spawns enough threads for the pid number space to wrap around, so
could potentially take a while.  On my box that's 4 seconds; on
gcc110, a PPC box which has max_pid set to 65536, it's over 10
seconds.  So I made the test compute how long that would take, and cap
the time waited if it would be unreasonably long.

Tested on x86_64 Fedora 20.

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

	* linux-thread-db.c (record_thread): Readd the thread to gdb's
	list if it was marked exited.

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

	* gdb.threads/tid-reuse.c: New file.
	* gdb.threads/tid-reuse.exp: New file.
2015-04-01 13:38:06 +01:00
H.J. Lu afa59b7900 Regenerate configure in bfd/binutils/gas/gdb
bfd/

2015-04-01  H.J. Lu  <hongjiu.lu@intel.com>

	* configure: Regenerated.

binutils/

2015-04-01  H.J. Lu  <hongjiu.lu@intel.com>

	* configure: Regenerated.

gas/

2015-04-01  H.J. Lu  <hongjiu.lu@intel.com>

	* configure: Regenerated.

gdb/

2015-04-01  H.J. Lu  <hongjiu.lu@intel.com>

	* configure: Regenerated.
2015-04-01 04:55:48 -07:00
Pedro Alves 41f98f0276 GDBServer: give more complete usage information
--attach/--multi are currently only mentioned on the usage info first
lines, the meaning of PROG is completely absent and the COMM text does
not mention '-/stdio'.

A few options are missing:

 . --disable-randomization / --no-disable-randomization is not mentioned.

Although the manual has a comment saying these are superceded by
QDisableRandomization, that only makes sense for "run" in
extended-remote mode.  When we start gdbserver passing it a PROG,
--disable-randomization / --no-disable-randomization do take effect.
So I think we should document these.

 . We show --debug / --remote-debug, so might as well show --disable-packet too.

GDB's --help has this "For more information, consult the GDB manual"
blurb that is missing in GDBserver's --help.

Then shuffle things around a bit into "Operating modes", "Other
options" and "Debug options" sections, similarly to GDB's --help
structure.

Before:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ ./gdbserver/gdbserver --help
Usage:  gdbserver [OPTIONS] COMM PROG [ARGS ...]
        gdbserver [OPTIONS] --attach COMM PID
        gdbserver [OPTIONS] --multi COMM

COMM may either be a tty device (for serial debugging), or
HOST:PORT to listen for a TCP connection.

Options:
  --debug               Enable general debugging output.
  --debug-format=opt1[,opt2,...]
                        Specify extra content in debugging output.
                          Options:
                            all
                            none
                            timestamp
  --remote-debug        Enable remote protocol debugging output.
  --version             Display version information and exit.
  --wrapper WRAPPER --  Run WRAPPER to start new programs.
  --once                Exit after the first connection has closed.
Report bugs to "<http://www.gnu.org/software/gdb/bugs/>".
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ ./gdbserver/gdbserver --help
Usage:  gdbserver [OPTIONS] COMM PROG [ARGS ...]
        gdbserver [OPTIONS] --attach COMM PID
        gdbserver [OPTIONS] --multi COMM

COMM may either be a tty device (for serial debugging),
HOST:PORT to listen for a TCP connection, or '-' or 'stdio' to use
stdin/stdout of gdbserver.
PROG is the executable program.  ARGS are arguments passed to inferior.
PID is the process ID to attach to, when --attach is specified.

Operating modes:

  --attach              Attach to running process PID.
  --multi               Start server without a specific program, and
                        only quit when explicitly commanded.
  --once                Exit after the first connection has closed.
  --help                Print this message and then exit.
  --version             Display version information and exit.

Other options:

  --wrapper WRAPPER --  Run WRAPPER to start new programs.
  --disable-randomization
                        Run PROG with address space randomization disabled.
  --no-disable-randomization
                        Don't disable address space randomization when
                        starting PROG.

Debug options:

  --debug               Enable general debugging output.
  --debug-format=opt1[,opt2,...]
                        Specify extra content in debugging output.
                          Options:
                            all
                            none
                            timestamp
  --remote-debug        Enable remote protocol debugging output.
  --disable-packet=opt1[,opt2,...]
                        Disable support for RSP packets or features.
                          Options:
                            vCont, Tthread, qC, qfThreadInfo and
                            threads (disable all threading packets).

For more information, consult the GDB manual (available as on-line
info or a printed manual).
Report bugs to "<http://www.gnu.org/software/gdb/bugs/>".
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

gdb/gdbserver/ChangeLog:
2015-04-01  Pedro Alves  <palves@redhat.com>
	    Cleber Rosa  <crosa@redhat.com>

	* server.c (gdbserver_usage): Reorganize and extend the usage
	message.
2015-04-01 11:01:44 +01:00
Sergio Durigan Junior df8411da08 Implement support for checking /proc/PID/coredump_filter
This patch, as the subject says, extends GDB so that it is able to use
the contents of the file /proc/PID/coredump_filter when generating a
corefile.  This file contains a bit mask that is a representation of
the different types of memory mappings in the Linux kernel; the user
can choose to dump or not dump a certain type of memory mapping by
enabling/disabling the respective bit in the bit mask.  Currently,
here is what is supported:

  bit 0  Dump anonymous private mappings.
  bit 1  Dump anonymous shared mappings.
  bit 2  Dump file-backed private mappings.
  bit 3  Dump file-backed shared mappings.
  bit 4 (since Linux 2.6.24)
         Dump ELF headers.
  bit 5 (since Linux 2.6.28)
         Dump private huge pages.
  bit 6 (since Linux 2.6.28)
         Dump shared huge pages.

(This table has been taken from core(5), but you can also read about it
on Documentation/filesystems/proc.txt inside the Linux kernel source
tree).

The default value for this file, used by the Linux kernel, is 0x33,
which means that bits 0, 1, 4 and 5 are enabled.  This is also the
default for GDB implemented in this patch, FWIW.

Well, reading the file is obviously trivial.  The hard part, mind you,
is how to determine the types of the memory mappings.  For that, I
extended the code of gdb/linux-tdep.c:linux_find_memory_regions_full and
made it rely *much more* on the information gathered from
/proc/<PID>/smaps.  This file contains a "verbose dump" of the
inferior's memory mappings, and we were not using as much information as
we could from it.  If you want to read more about this file, take a look
at the proc(5) manpage (I will also write a blog post soon about
everything I had to learn to get this patch done, and when I it is ready
I will post it here).

With Oleg Nesterov's help, we could improve the current algorithm for
determining whether a memory mapping is anonymous/file-backed,
private/shared.  GDB now also respects the MADV_DONTDUMP flag and does
not dump the memory mapping marked as so, and will always dump
"[vsyscall]" or "[vdso]" mappings (just like the Linux kernel).

In a nutshell, what the new code is doing is:

- If the mapping is associated to a file whose name ends with
  " (deleted)", or if the file is "/dev/zero", or if it is "/SYSV%08x"
  (shared memory), or if there is no file associated with it, or if
  the AnonHugePages: or the Anonymous: fields in the /proc/PID/smaps
  have contents, then GDB considers this mapping to be anonymous.
  There is a special case in this, though: if the memory mapping is a
  file-backed one, but *also* contains "Anonymous:" or
  "AnonHugePages:" pages, then GDB considers this mapping to be *both*
  anonymous and file-backed, just like the Linux kernel does.  What
  that means is simple: this mapping will be dumped if the user
  requested anonymous mappings *or* if the user requested file-backed
  mappings to be present in the corefile.

  It is worth mentioning that, from all those checks described above,
  the most fragile is the one to see if the file name ends with
  " (deleted)".  This does not necessarily mean that the mapping is
  anonymous, because the deleted file associated with the mapping may
  have been a hard link to another file, for example.  The Linux
  kernel checks to see if "i_nlink == 0", but GDB cannot easily do
  this check (as it has been discussed, GDB would need to run as root,
  and would need to check the contents of the /proc/PID/map_files/
  directory in order to determine whether the deleted was a hardlink
  or not).  Therefore, we made a compromise here, and we assume that
  if the file name ends with " (deleted)", then the mapping is indeed
  anonymous.  FWIW, this is something the Linux kernel could do
  better: expose this information in a more direct way.

- If we see the flag "sh" in the VmFlags: field (in /proc/PID/smaps),
  then certainly the memory mapping is shared (VM_SHARED).  If we have
  access to the VmFlags, and we don't see the "sh" there, then
  certainly the mapping is private.  However, older Linux kernels (see
  the code for more details) do not have the VmFlags field; in that
  case, we use another heuristic: if we see 'p' in the permission
  flags, then we assume that the mapping is private, even though the
  presence of the 's' flag there would mean VM_MAYSHARE, which means
  the mapping could still be private.  This should work OK enough,
  however.

Finally, it is worth mentioning that I added a new command, 'set
use-coredump-filter on/off'.  When it is 'on', it will read the
coredump_filter' file (if it exists) and use its value; otherwise, it
will use the default value mentioned above (0x33) to decide which memory
mappings to dump.

gdb/ChangeLog:
2015-03-31  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Oleg Nesterov  <oleg@redhat.com>

	PR corefiles/16092
	* linux-tdep.c: Include 'gdbcmd.h' and 'gdb_regex.h'.
	New enum identifying the various options of the coredump_filter
	file.
	(struct smaps_vmflags): New struct.
	(use_coredump_filter): New variable.
	(decode_vmflags): New function.
	(mapping_is_anonymous_p): Likewise.
	(dump_mapping_p): Likewise.
	(linux_find_memory_regions_full): New variables
	'coredumpfilter_name', 'coredumpfilterdata', 'pid', 'filterflags'.
	Removed variable 'modified'.  Read /proc/<PID>/smaps file; improve
	parsing of its information.  Implement memory mapping filtering
	based on its contents.
	(show_use_coredump_filter): New function.
	(_initialize_linux_tdep): New command 'set use-coredump-filter'.
	* NEWS: Mention the possibility of using the
	'/proc/PID/coredump_filter' file when generating a corefile.
	Mention new command 'set use-coredump-filter'.

gdb/doc/ChangeLog:
2015-03-31  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR corefiles/16092
	* gdb.texinfo (gcore): Mention new command 'set
	use-coredump-filter'.
	(set use-coredump-filter): Document new command.

gdb/testsuite/ChangeLog:
2015-03-31  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR corefiles/16092
	* gdb.base/coredump-filter.c: New file.
	* gdb.base/coredump-filter.exp: Likewise.
2015-03-31 19:32:34 -04:00
Sergio Durigan Junior 416f679e68 Catch exception on solib_svr4_r_ldsomap
When loading a corefile that has some inaccessible memory region(s),
GDB complains about it:

   (gdb) core /my/corefile
   [New LWP 28468]
   Cannot access memory at address 0x355fc21148
   Cannot access memory at address 0x355fc21140
   (gdb)

However, despite not seeing the message "Core was generated by...", it
is still possible to inspect the corefile using regular GDB commands.
The reason for that is because read_memory_unsigned_integer throws an
exception when it cannot read the memory region, but
solib_svr4_r_ldsomap was not catching it.  The fix is to catch the
exception and act accordingly.

Tested on Fedora 20 x86_64, no regressions found.

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

	* solib-svr4.c (solib_svr4_r_ldsomap): Catch possible exception by
	read_memory_unsigned_integer.
2015-03-31 19:17:23 -04:00
H.J. Lu 711a72d3d6 Add --with-system-zlib in gdb
This patch adds --with-system-zlib and removes --with-zlib in gdb.

	* Makefile.in (ZLIB): New.
	(ZLIBINC): Likewise.
	(INTERNAL_CFLAGS_BASE): Add $(ZLIBINC).
	(CLIBS): Add $(ZLIB).
	* acinclude.m4: (GDB_AC_CHECK_BFD): Add $zlibdir to LDFLAGS.
	Add -lz to LIBS.
	* gdb_bfd.c: Don't check HAVE_ZLIB_H to include <zlib.h>.
	* top.c (print_gdb_configuration): Remove --with-zlib and
	--without-zlib.
	* config.in: Regenerated.
	* configure: Likewise.
2015-03-31 08:24:18 -07:00
Petr Machata 6ef37366be dwarf.exp: Allow generating a stub .debug_line section
Example of use:

	Dwarf::assemble "foo.s" {
	    build_id 0102030405060708

	    declare_labels L;
	    cu {is_64 0 version 4 addr_size 8} {
		DW_TAG_compile_unit {
		    {DW_AT_stmt_list $L DW_FORM_sec_offset}
		} {
		    DW_TAG_subprogram {
			# We can now reference the source file.
			{DW_AT_decl_file 1 DW_FORM_data1}
		    }
		}
	    }

	    lines {is_64 0 version 2 addr_size 8} L {
		include_dir "foo"
		include_dir "bar"
		file_name "foo.c" 1
		file_name "bar.c" 1
		file_name "baz.c" 2
	    }
	}

Signed-off-by: Petr Machata <pmachata@redhat.com>
2015-03-31 16:25:07 +02:00
Antoine Tremblay d33279b3bb Add cpu information to the info os command on linux.
This patch adds cpu information on linux based on /proc/cpuinfo as :
cpus       Listing of all cpus/cores on the system

This patch also reorders the info os commands so that they are listed
in alphabetical order.

gdb/ChangeLog:

	* NEWS: Mention info os cpus support.
	* gdb/nat/linux-osdata.c (linux_xfer_osdata_cpus): New function.
	(struct osdata_type): Add cpus entry, reorder the entries in
	alphabetical order.

gdb/doc/ChangeLog:

	* gdb.texinfo (Operating System Auxiliary Information): Add info os cpus
	documentation, reorder the info os entries in alphabetical order.
2015-03-31 09:31:52 -04:00
Matthias Klose 71b30f27af Fix the triplet regexp to recognize triplets, not only quadruplets
This allows triplets where the vendor is not set.

gdb/ChangeLog:
2015-03-31  Matthias Klose  <doko@ubuntu.com>

	* compile/compile.c (compile_to_object): Allow triplets with or
	without vendor set.
2015-03-31 14:15:42 +01:00
Doug Evans 13ce922274 PR c++/18141
gdb/ChangeLog:

	PR c++/18141
	* cp-namespace.c (cp_search_static_and_baseclasses): Always look for
	klass in VAR_DOMAIN.
2015-03-30 16:41:05 -07:00
Gary Benson 20f796c970 Remove three redundant wrapper functions in remote.c
gdb/ChangeLog:

	* remote.c (remote_mourn_1): Remove function.  Update all callers
	to use remote_mourn.
	(extended_remote_mourn_1): Remove function.  Update all callers
	to use extended_remote_mourn.
	(extended_remote_attach_1): Remove function.  Update all callers
	to use extended_remote_attach.
2015-03-30 15:07:07 +01:00
James Bowman 49d45b20c0 gdb: ft32: new port
FT32 is a new high performance 32-bit RISC core developed by FTDI for
embedded applications.
2015-03-28 02:13:34 -04:00
Jan Kratochvil 1c4ff0802b Revert: Code cleanup: Move print_command_1 expr variable scope
Simon Marchi:

I think this patch is wrong. Starting with that commit (f30d5c7),
some tests (e.g. mi-break.exp) started to fail for me, because
of gdb segfaulting.

The address of expr is passed to the cleanup. When the cleanup is ran,
expr is no longer in scope, so what is at that address is probably not
safe to use anymore. That's my guess.

gdb/ChangeLog
2015-03-27  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Revert:
	2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
	Code cleanup.
	* printcmd.c (print_command_1): Move expr variable scope.
2015-03-27 20:19:37 +01:00
Joel Brobecker 79498702ef Initialize EXPR in dtrace-probe::dtrace_process_dof_probe
GCC 4.4.7 generates the following warning:

 | cc1: warnings being treated as errors
 | dtrace-probe.c: In function ‘dtrace_process_dof_probe’:
 | dtrace-probe.c:416: error: ‘expr’ may be used uninitialized in this function
 | make[2]: *** [dtrace-probe.o] Error 1

Later versions (GCC 5) do a better job and don't generate the warning,
but it does not hurt to pre-initialize "expr" to NULL.

gdb/ChangeLog:

        * dtrace-probe.c (dtrace_process_dof_probe): Initialize expr to NULL.
2015-03-27 08:25:28 -07:00
Andrzej Kaczmarek ce9c0ca18f Fix gdb_bfd_section_index for special sections
Indexes returned for special sections are off by one, i.e. with N+4
sections last one has index N+4 returned which is outside allocated
obstack (at the same time index N is not used at all).

In worst case, if sections obstack is allocated up to end of chunk,
writing last section data will cause buffer overrun and some data
corruption.

Here's output from Valgrind::

==14630== Invalid write of size 8
==14630==    at 0x551B1A: add_to_objfile_sections_full (objfiles.c:225)
==14630==    by 0x552768: allocate_objfile (objfiles.c:324)
==14630==    by 0x4E8E2E: symbol_file_add_with_addrs (symfile.c:1171)
==14630==    by 0x4E9453: symbol_file_add_from_bfd (symfile.c:1280)
==14630==    by 0x4E9453: symbol_file_add (symfile.c:1295)
==14630==    by 0x4E94B7: symbol_file_add_main_1 (symfile.c:1320)
==14630==    by 0x514246: catch_command_errors_const (main.c:398)
==14630==    by 0x5150AA: captured_main (main.c:1061)
==14630==    by 0x51123C: catch_errors (exceptions.c:240)
==14630==    by 0x51569A: gdb_main (main.c:1164)
==14630==    by 0x408824: main (gdb.c:32)
==14630==  Address 0x635f3b8 is 8 bytes after a block of size 4,064 alloc'd
==14630==    at 0x4C2ABA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14630==    by 0x60F797: xmalloc (common-utils.c:41)
==14630==    by 0x5E787FB: _obstack_begin (obstack.c:184)
==14630==    by 0x552679: allocate_objfile (objfiles.c:294)
==14630==    by 0x4E8E2E: symbol_file_add_with_addrs (symfile.c:1171)
==14630==    by 0x4E9453: symbol_file_add_from_bfd (symfile.c:1280)
==14630==    by 0x4E9453: symbol_file_add (symfile.c:1295)
==14630==    by 0x4E94B7: symbol_file_add_main_1 (symfile.c:1320)
==14630==    by 0x514246: catch_command_errors_const (main.c:398)
==14630==    by 0x5150AA: captured_main (main.c:1061)
==14630==    by 0x51123C: catch_errors (exceptions.c:240)
==14630==    by 0x51569A: gdb_main (main.c:1164)
==14630==    by 0x408824: main (gdb.c:32)

gdb/ChangeLog:
	* gdb_bfd.c (gdb_bfd_section_index): Fix off-by-one for special
	sections.
2015-03-27 12:09:02 +00:00
Jon Turney 7ec911b0fb testsuite: Don't set SYMBOL_PREFIX for x86_64_*_cygwin
Exactly like x86_64-*-mingw, SYMBOL_PREFIX should not be set to "_" for
x86_64_*_cygwin

gdb/testuite/ChangeLog:

	* lib/gdb.exp (gdb_target_symbol_prefix_flags): Don't set
	SYMBOL_PREFIX for x86_64-*-cygwin.
2015-03-26 22:37:24 +00:00
Joel Brobecker 429e1e811b dtrace-probe: Handle error while parsing probe argument.
The debugger on Solaris has been broken since the introduction of
DTrace probe support:

    (gdb) start
    Temporary breakpoint 1 at 0x80593bc: file simple_main.adb, line 4.
    Starting program: /[...]/simple_main
    [Thread debugging using libthread_db enabled]
    No definition of "mutex_t" in current context.

The problem occurs while trying to parse a probe's argument,
and the exception propagates all the way to the top. This patch
fixes the issue by containing the exception and falling back on
using the "long" builtin type if the argument's type could not
be determined.

Also, the parsing should be done using the C language parser.

gdb/ChangeLog:

        * dtrace-probe.c (dtrace_process_dof_probe): Contain any
        exception raised while parsing the probe arguments.
        Force parsing to be done using the C language parser.
        * expression.h (parse_expression_with_language): Declare.
        * parse.c (parse_expression_with_language): New function.
2015-03-26 13:56:51 -07:00
Jon Turney 4593441bc5 Add myself as a write-after-approval GDB maintainer
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add "Jon Turney".
2015-03-26 20:32:07 +00:00
Simon Marchi 852f8402ca Fix copy-paste typo in -data-write-memory-bytes doc
* gdb.texinfo (GDB/MI Data Manipulation): Fix copy-paste typo in
	-data-write-memory-bytes.
2015-03-26 15:10:10 -04:00
Andy Wingo ff908ebf86 Properly intern constants into psymtab
Variables with a DW_AT_const_value but without a DW_AT_location were not
getting added to the partial symbol table.  They are added to the full
symbol table, however, when the compilation unit's psymtabs are
expanded.

Before:

   (gdb) p one
   No symbol "one" in current context.
   (gdb) mt flush-symbol-cache
   (gdb) mt expand one.c
   (gdb) p one
   $1 = 1

After:

   (gdb) p one
   $1 = 1

To the user it's pretty strange, as depending on whether tab completion
has forced expansion of all CUs or not the lookup might succeed, or not
if the failure was already added to the symbol cache.

This commit simply makes sure to add constants to the partial symbol
tables.

gdb/testsuite/ChangeLog:

	PR symtab/18148
	* gdb.dwarf2/dw2-intercu.S (one, two): Add variables that have a
	const_value but not a location.
	* gdb.dwarf2/dw2-intercu.exp: Add tests that constants without
	location defined in non-main CUs are visible.

gdb/ChangeLog:

	PR symtab/18148
	* dwarf2read.c (struct partial_die_info): Add has_const_value
	member.
	(add_partial_symbol): Don't punt on symbols that have const_value
	attributes.
	(read_partial_die): Detect DW_AT_const_value.
2015-03-26 19:41:54 +01:00
Jan Kratochvil f30d5c78fa Code cleanup: Move print_command_1 expr variable scope
gdb/ChangeLog
2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Code cleanup.
	* printcmd.c (print_command_1): Move expr variable scope.
2015-03-26 18:44:38 +01:00
Jan Kratochvil 8d89f51a70 Code cleanup: Make validate_format parameter const
gdb/ChangeLog
2015-03-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Code cleanup.
	* printcmd.c (validate_format): Make the parameter cmdname const.
2015-03-26 18:41:24 +01:00
Don Breazeal 0b736949a8 Clarify comment on the purpose of the assertion loop in _initialize_remote.
gdb/ChangeLog:
2015-03-26  Don Breazeal  <donb@codesourcery.com>

	* remote.c (_initialize_remote): Update comment.
2015-03-26 10:23:05 -07:00
Pedro Alves 20d35291fb Don't set breakpoints on import stubs on Windows amd64
On Windows amd64, setting a breakpoint on a symbol imported from a
shared library after that library is loaded creates a breakpoint with
two locations, one on the import stub, and another in the shared
library, while on i386, the breakpoint is only set in the shared
library.

This is due to the minimal symbol for the import stub not being
correctly given the type mst_solib_trampoline on Windows amd64, unlike
Windows i386.

As currently written, coff_symfile_read is always skipping over the
character after the "__imp_" (amd64) or "_imp_" (i386) prefix,
assuming that it is '_'.  However, while i386 is an underscored
target, amd64 is not.

On x86_64-pc-cygwin, it fixes:

 - FAIL: gdb.base/solib-symbol.exp: foo in libmd
 + PASS: gdb.base/solib-symbol.exp: foo in libmd

Unfortunately, several other tests which passed now fail but that's
because this issue was masking other problems.

No change on i686-pc-cygwin.

gdb/ChangeLog:
2015-03-26  Pedro Alves  <palves@redhat.com>
	    Jon TURNEY  <jon.turney@dronecode.org.uk>

	* coffread.c (coff_symfile_read): When constructing the name of an
	import stub symbol from import symbol for amd64, only skip the
	char after _imp_ if the target is underscored (like i386) and the
	char is indeed the target's leading char.
2015-03-26 10:21:07 +00:00
Yao Qi 6d5f0679fe Handle the effect of skipping prologue
break-asm-file.exp has some manually written dwarf to create some line
number entries like this,

  [0x0000013d]  Extended opcode 2: set Address to 0x40053f
  [0x00000144]  Advance Line by 4 to 7
  [0x00000146]  Copy
  [0x00000147]  Extended opcode 2: set Address to 0x400541
  [0x0000014e]  Advance Line by 1 to 8
  [0x00000150]  Copy
  [0x00000151]  Extended opcode 2: set Address to 0x400547
  [0x00000158]  Extended opcode 1: End of Sequence

0x40053f is the start address of function func, and is mapped to line
7.  0x400541 is within function func, and is mapped to line 8.

(gdb) disassemble /r 0x40053f,+8
Dump of assembler code from 0x40053f to 0x400547:
   0x000000000040053f <func+0>: 00 00   add    %al,(%rax)
   0x0000000000400541 <func+2>: 00 00   add    %al,(%rax)
   0x0000000000400543 <func+4>: 00 00   add    %al,(%rax)
   0x0000000000400545 <func+6>: 00 00   add    %al,(%rax)

in the following test,

(gdb) break a/break-asm-file0.s:func
Breakpoint 1 at 0x40053f: file a/break-asm-file0.s, line 7.

As we can see, breakpoint is set at the start address of function func
on x86, which means no prologue is skipped.  On other targets, such as
arm and aarch64, breakpoint is set at the address *after* the start
address, which is mapped to line 8.  Then test fails.

In fact, it is lucky this test doesn't fail on x86 and x86_64, whose
gdbarch method skip_prologue doesn't reply on skip_prologue_using_sal
if producer isn't clang.

  if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
    {
      CORE_ADDR post_prologue_pc
	= skip_prologue_using_sal (gdbarch, func_addr);
      struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);

      /* Clang always emits a line note before the prologue and another
	 one after.  We trust clang to emit usable line notes.  */
      if (post_prologue_pc
	  && (cust != NULL
	      && COMPUNIT_PRODUCER (cust) != NULL
	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
        return max (start_pc, post_prologue_pc);
    }

so it doesn't return and go further to prologue analyser.  Since ".int 0"
isn't an instruction of prologue, nothing is skipped, starting address
is used, and test passes.

however, on targets which don't have such producer checking, the first
line number entry is skipped, and skip_prologue_using_sal returns sal
represents the second line number entry.

The idea of this patch is to force GDB stop at somewhere which is stilled
mapped to line 7 after skipping prologue.  I choose to add a new line
number entry for the following instruction but mapped to the same line (7),
because I see the comments in dwarf2read.c,

   ... fact that two consecutive
   line number entries for the same line is a heuristic used by gcc
   to denote the end of the prologue.

then the line table becomes:

  [0x000000d4]  Extended opcode 2: set Address to 0x400529
  [0x000000db]  Advance Line by 4 to 7
  [0x000000dd]  Copy
  [0x000000de]  Extended opcode 2: set Address to 0x40052a
  [0x000000e5]  Advance Line by 0 to 7
  [0x000000e7]  Copy
  [0x000000e8]  Extended opcode 2: set Address to 0x40052b
  [0x000000ef]  Advance Line by 1 to 8
  [0x000000f1]  Copy
  [0x000000f2]  Extended opcode 2: set Address to 0x40052c
  [0x000000f9]  Extended opcode 1: End of Sequence

gdb/testsuite:

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

	PR testsuite/18139
	* gdb.linespec/break-asm-file0.s (func): New label .Lfunc_2.
	Add a line number entry for the same line.
	* gdb.linespec/break-asm-file1.s (func): New label .Lfunc_2.
	Add a line number entry for the same line.
2015-03-26 08:29:48 +00:00
Yao Qi 2898689ba3 Remove some hard-coded stuff in tests
There are some hard-coded stuff in .s files, such as .int 0 and
address offset, which isn't portable.  This patch is to replace
".int 0" with nop and address offset with labels.

gdb/testsuite:

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

	* gdb.linespec/break-asm-file0.s (func2): Use nop instead of
	.int 0.
	(func): Likewise.  Add .Lfunc_1 label.
	Use .Lfunc_1 label.
	* gdb.linespec/break-asm-file1.s (func3): Use nop instead of
	.int 0.
	(func): Likewise.
	Use .Lfunc_1 label.
2015-03-26 08:29:48 +00:00
Yao Qi 8518049884 Compile break-asm-file{0,1}.s without debug info
If I add some nop into break-asm-file1.s like this,

--- INDEX:/gdb/testsuite/gdb.linespec/break-asm-file1.s
+++ WORKDIR:/gdb/testsuite/gdb.linespec/break-asm-file1.s
@@ -31,8 +31,8 @@ _func:
 	.type func, %function
 func:
 .Lbegin_func:
-	.int 0
-	.int 0
+	nop
+	nop
 .Lend_func:
 	.size func, .-func
 .Lend_text1:

I get the following error:

Running gdb/testsuite/gdb.linespec/break-asm-file.exp ...
gdb/testsuite/gdb.linespec/break-asm-file1.s: Assembler messages:^M
gdb/testsuite/gdb.linespec/break-asm-file1.s: Fatal error: duplicate .debug_line sections

break-asm-file0.s and break-asm-file1.s have already had debug information
(written manually), so don't need to generate debug infor for them.

gdb/testsuite:

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

	* gdb.linespec/break-asm-file.exp: Don't call prepare_for_testing.
	Call gdb_compile instead to compile each .s files without debug
	information.
2015-03-26 08:29:48 +00:00
Yao Qi 8aa08a8dd5 Relax pattern to match the output of "info frame" in gdb.base/savedregs.exp
Hi,
I see the following two fails in gdb.base/savedregs.exp on aarch64-linux,

info frame 2^M
Stack frame at 0x7ffffffa60:^M
 pc = 0x40085c in thrower (/home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.base/savedregs.c:49); saved pc = 0x400898^M
 called by frame at 0x7ffffffa70, caller of frame at 0x7fffffe800^M
 source language c.^M
 Arglist at 0x7ffffffa60, args: ^M
 Locals at 0x7ffffffa60, Previous frame's sp is 0x7ffffffa60^M
(gdb) FAIL: gdb.base/savedregs.exp: Get thrower info frame

info frame 2^M
Stack frame at 0x7fffffe800:^M
 pc = 0x400840 in catcher (/home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.base/savedregs.c:42); saved pc = 0x7fb7ffc350^M
 called by frame at 0x7fffffe800, caller of frame at 0x7fffffe7e0^M
 source language c.^M
 Arglist at 0x7fffffe7f0, args: sig=11^M
 Locals at 0x7fffffe7f0, Previous frame's sp is 0x7fffffe800
(gdb) FAIL: gdb.base/savedregs.exp: Get catcher info frame

looks the test expects to match "Saved registers:" from the output of
"info frame", but no registers are saved on these two frames, because
thrower and catcher are simple and leaf functions.

(gdb) disassemble thrower
Dump of assembler code for function thrower:
   0x0000000000400858 <+0>:	mov	x0, #0x0                   	// #0
   0x000000000040085c <+4>:	strb	wzr, [x0]
   0x0000000000400860 <+8>:	ret
End of assembler dump.
(gdb) disassemble catcher
Dump of assembler code for function catcher:
   0x0000000000400838 <+0>:	sub	sp, sp, #0x10
   0x000000000040083c <+4>:	str	w0, [sp,#12]
   0x0000000000400840 <+8>:	adrp	x0, 0x410000
   0x0000000000400844 <+12>:	add	x0, x0, #0xb9c
   0x0000000000400848 <+16>:	mov	w1, #0x1                   	// #1
   0x000000000040084c <+20>:	str	w1, [x0]
   0x0000000000400850 <+24>:	add	sp, sp, #0x10
   0x0000000000400854 <+28>:	ret

There are two ways to fix these fails, one is to modify functions to
force some registers saved (for example, doing function call in them),
and the other one is to relax the pattern to optionally match
"Saved registers:".  I did both, and feel that the latter is simple,
so here is it.

gdb/testsuite:

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

	* gdb.base/savedregs.exp (process_saved_regs): Make
	"Saved registers:" optional in the pattern.
2015-03-26 08:16:20 +00:00
Markus Metzger 66849923d2 btrace: fix tests for 32-bit
The x86-record_goto.S assembly source file does not build on 32-bit.
This breaks many tests that use this file.

Split it into x86_64-record_goto.S and i686-record_goto.S.  Luckily, we
can use either one with the same test .exp file.

It further turned out that most tests do not really need a fixed binary;
they should work pretty well with a newly-compiled C program.  The
one thing that breaks this is the heavy use of "record goto" to navigate
inside the recorded execution.

Combine step.exp, next,exp, and finish.exp into a single test step.exp
and use normal stepping and reverse-stepping commands for navigation.

testsuite/
	* gdb.btrace/next.exp: Merged into step.exp.
	* gdb.btrace/finish.exp: Merged into step.exp.
	* gdb.btrace/nexti.exp: Merged into stepi.exp.
	* gdb.btrace/step.exp: Use record_goto.c as test file.  Avoid using
	"record goto" and checking the exact replay position.
	* gdb.btrace/stepi.exp: Choose test file based on target.  Do not
	check for "Recording format" in "info record" output.
	* gdb.btrace/record_goto.exp: Choose test file based on target.
	* gdb.btrace/x86-record_goto.S: Renamed into ...
	* gdb.btrace/x86_64-record_goto.S: ... this.
	* gdb.btrace/i686-record_goto.S: New.
	* gdb.btrace/x86-tailcall.S: Renamed into ...
	* gdb.btrace/x86_64-tailcall.S: ... this.
	* gdb.btrace/i686-tailcall.S: New.
	* gdb.btrace/x86-tailcall.c: Renamed into ...
	* gdb.btrace/tailcall.c: ... this.  Split "return ++answer" into two
	separate statements.  Update test.
	* gdb.btrace/delta.exp: Use record_goto.c as test file.
	* gdb.btrace/gcore.exp: Use record_goto.c as test file.
	* gdb.btrace/nohist.exp: Use record_goto.c as test file.
	* gdb.btrace/tailcall.exp: Choose test file based on target.
	* gdb.btrace/Makefile.in: Remove next, finish, and nexti.
2015-03-25 14:18:02 +01:00
Markus Metzger 11cc1b7453 btrace: increase buffer size for exception test
The trace for throwing and catching an exception can be quite big.
Increase the buffer size to avoid spurious fails.

testsuite/
	* gdb.btrace/exception.exp: Increase BTS buffer size.
2015-03-25 14:15:07 +01:00
Pedro Alves 6a3753b34b Simplify target_async hook interface
All callers of target_async pass it the same callback
(inferior_event_handler).  Since both common code and target backends
need to be able to put the target in and out of target async mode at
any given time, there's really no way that a different callback could
be passed.  This commit simplifies things, and removes the indirection
altogether.  Bonus: with this, gdb's target_async method ends up with
the same signature as gdbserver's.

Tested on x86_64 Fedora 20, native and gdbserver.

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

	* target.h <to_async>: Replace 'callback' and 'context' parameters
	with boolean 'enable' parameter.
	(target_async): Replace CALLBACK and CONTEXT parameters with
	boolean ENABLE parameter.
	* inf-loop.c (inferior_event_handler): Adjust.
	* linux-nat.c (linux_nat_attach, linux_nat_resume)
	(linux_nat_resume): Adjust.
	(async_client_callback, async_client_context): Delete.
	(handle_target_event): Call inferior_event_handler directly.
	(linux_nat_async): Replace 'callback' and 'context' parameters
	with boolean 'enable' parameter.  Adjust.  Remove references to
	async_client_callback and async_client_context.
	(linux_nat_close): Adjust.
	* record-btrace.c (record_btrace_async): Replace 'callback' and
	'context' parameters with boolean 'enable' parameter.  Adjust.
	(record_btrace_resume): Adjust.
	* record-full.c (record_full_async): Replace 'callback' and
	'context' parameters with boolean 'enable' parameter.  Adjust.
	(record_full_resume, record_full_core_resume): Adjust.
	* remote.c (struct remote_state) <async_client_callback,
	async_client_context>: Delete fields.
	(remote_start_remote, extended_remote_attach_1, remote_resume)
	(extended_remote_create_inferior): Adjust.
	(remote_async_serial_handler): Call inferior_event_handler
	directly.
	(remote_async): Replace 'callback' and 'context' parameters with
	boolean 'enable' parameter.  Adjust.
	* top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper):
	Adjust.
	* target-delegates.c: Regenerate.
2015-03-25 11:28:31 +00:00
Gary Benson 1c4b552ba5 Associate target_ops with target_fileio file descriptors
Various target_fileio_* functions use integer file descriptors to
refer to open files.  File operation functions are looked up from
the target stack as they are used, which causes problems if the
target stack changes after the file is opened.

For example, if a file is opened on a remote target and the remote
target disconnects or closes the remote target will be popped off
the stack.  If target_fileio_close is then called on that file and
"set auto-connect-native-target" is "on" (the default) then the
native target's close method will be called.  If the file opened
on the remote happens to share the same number with a file open in
GDB then that file will be closed by mistake.

This commit changes target_fileio_open to store newly opened file
descriptors in a table together with the target_ops used to open
them.  The index into the table is returned and used as the file
descriptor argument to all target_fileio_* functions that accept
file descriptor arguments.

gdb/ChangeLog:

	* target.c (fileio_ft_t): New typedef, define object vector.
	(fileio_fhandles): New static variable.
	(is_closed_fileio_fh): New macro.
	(lowest_closed_fd): New static variable.
	(acquire_fileio_fd): New function.
	(release_fileio_fd): Likewise.
	(fileio_fd_to_fh): New macro.
	(target_fileio_open): Wrap the file descriptor on success.
	(target_fileio_pwrite): Updated to use wrapped file descriptor.
	(target_fileio_pread): Likewise.
	(target_fileio_close): Likewise.
2015-03-25 11:26:43 +00:00
Pedro Alves a25d8bf9c5 Fix "thread apply all" with exited threads
I noticed that "thread apply all" sometimes crashes.

The problem is that thread_apply_all_command doesn take exited threads
into account, and we qsort and then walk more elements than there
really ever were put in the array.  Valgrind shows:

 The current thread <Thread ID 3> has terminated.  See `help thread'.
 (gdb) thread apply all p 1

 Thread 1 (Thread 0x7ffff7fc2740 (LWP 29579)):
 $1 = 1
 ==29576== Use of uninitialised value of size 8
 ==29576==    at 0x639CA8: set_thread_refcount (thread.c:1337)
 ==29576==    by 0x5C2C7B: do_my_cleanups (cleanups.c:155)
 ==29576==    by 0x5C2CE8: do_cleanups (cleanups.c:177)
 ==29576==    by 0x63A191: thread_apply_all_command (thread.c:1477)
 ==29576==    by 0x50374D: do_cfunc (cli-decode.c:105)
 ==29576==    by 0x506865: cmd_func (cli-decode.c:1893)
 ==29576==    by 0x7562CB: execute_command (top.c:476)
 ==29576==    by 0x647DA4: command_handler (event-top.c:494)
 ==29576==    by 0x648367: command_line_handler (event-top.c:692)
 ==29576==    by 0x7BF7C9: rl_callback_read_char (callback.c:220)
 ==29576==    by 0x64784C: rl_callback_read_char_wrapper (event-top.c:171)
 ==29576==    by 0x647CB5: stdin_event_handler (event-top.c:432)
 ==29576==
 ...

This can happen easily today as linux-nat.c/linux-thread-db.c are
forgetting to purge non-current exited threads.  But even with that
fixed, we can always do "thread apply all" with an exited thread
selected, which won't be deleted until the user switches to another
thread.  That's what the test added by this commit exercises.

Tested on x86_64 Fedora 20.

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

	* thread.c (thread_apply_all_command): Take exited threads into
	account.

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

	* gdb.threads/no-unwaited-for-left.exp: Test "thread apply all".
2015-03-24 21:01:29 +00:00
Pedro Alves 44a1ee5173 Fix switch_back_to_stepped_thread comment references
Whoops, switch_back_to_stepping doesn't exist...

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

	* infrun.c (resume, proceed): Mention
	switch_back_to_stepped_thread, not switch_back_to_stepping.
2015-03-24 19:01:05 +00:00
Pedro Alves f3263aa47e Shuffle user_visible_resume_ptid
... and move comment to declaration.

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

	* infrun.c (user_visible_resume_ptid): Rewrite going from
	most-locked to unlocked instead of the opposite.  Move comment ...
	* infrun.h (user_visible_resume_ptid): ... here.
2015-03-24 18:35:40 +00:00
Pedro Alves 2bf6fb9d85 Debug output tweaks in the Linux target backends
This adds/tweaks a few debug logs I found useful recently.

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

	* linux-low.c (check_stopped_by_breakpoint): Tweak debug log
	output.  Also dump TRAP_TRACE.
	(linux_low_filter_event): In debug output, distinguish a
	resume_stop SIGSTOP from a delayed SIGSTOP.

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

	* linux-nat.c (linux_nat_resume): Output debug logs before trying
	to resume the event lwp.  Use the lwp's ptid instead of the passed
	in (maybe wildcard) ptid.
	(stop_wait_callback): Tweak debug log output.
	(check_stopped_by_breakpoint): Tweak debug log output.  Also dump
	TRAP_TRACE.
	(linux_nat_filter_event): In debug output, distinguish a
	resume_stop SIGSTOP from a delayed SIGSTOP.  Output debug logs
	before trying to resume the lwp.
2015-03-24 18:31:51 +00:00
Joel Brobecker 283a99589a Do not make "prop" field of struct dynamic_prop_list a pointer.
struct dynamic_prop_list is declared as follow:

    struct dynamic_prop_list
    {
      [...]
      /* The dynamic property itself.  */
      struct dynamic_prop *prop;
      [...]
    };

In this case, the pointer indirection is unnecessary and costing us,
for each dynamic property, the memory needed to store one pointer.
This patch removes this pointer indirection, savin us a tiny bit of
memory, as well as reduces a bit the complexity by removing the need
to allocate memory for the property, as the allocation is now part
of the struct itself.

gdb/ChangeLog:

        * gdbtypes.h (struct dynamic_prop_list) <prop>: Remove
        pointer indirection.
        * gdbtypes.c (get_dyn_prop): Adjust, following change above.
        (add_dyn_prop, copy_dynamic_prop_list): Likewise.

Tested on x86_64-linux.
2015-03-24 11:25:46 -07:00
Joel Brobecker 93a8e2276f GDB: rename DYN_ATTR_DATA_LOCATION into DYN_PROP_DATA_LOCATION.
The terminology we've been using is (dynamic) "property" rather than
"attribute", so this patch renames an enum to use the same terminology.

No behavior change.

gdb/ChangeLog:

        * gdbtypes.h (enum dynamic_prop_node_kind) <DYN_PROP_DATA_LOCATION>:
        Renames DYN_ATTR_DATA_LOCATION.
        (TYPE_DATA_LOCATION): Use DYN_PROP_DATA_LOCATION instead of
        DYN_ATTR_DATA_LOCATION.
        * dwarf2read.c (set_die_type): Use DYN_PROP_DATA_LOCATION
        instead of DYN_ATTR_DATA_LOCATION.

Tested on x86_64-linux.
2015-03-24 11:24:43 -07:00
Pedro Alves 64ce06e4cd Remove 'step' parameters from 'proceed' and 'resume'
The "step" parameters of 'proceed' and 'resume' aren't really useful
as indication of whether run control wants to single-step the target,
as that information must already be retrievable from
currently_stepping.  In fact, if currently_stepping disagrees with
whether we single-stepped the target, then things break.  Thus instead
of having the same information in two places, this patch removes those
parameters.

Setting 'step_start_function' is the only user of proceed's 'step'
argument, other than passing the 'step' argument down to 'resume' and
debug log output.  Move that instead to set_step_frame, where we
already set other related fields.

clear_proceed_status keeps its "step" parameter for now because it
needs to know which set of threads should have their state cleared,
and is called before the "stepping_command" flag is set.

Tested on x86_64 Fedora 20, native and gdbserver.

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

	* breakpoint.c (until_break_command): Adjust call to proceed.
	* gdbthread.h (struct thread_control_state) <stepping_command>:
	New field.
	* infcall.c (run_inferior_call): Adjust call to proceed.
	* infcmd.c (run_command_1, proceed_thread_callback, continue_1):
	Adjust calls to proceed.
	(set_step_frame): Set the current thread's step_start_function
	here.
	(step_once): Adjust calls to proceed.
	(jump_command, signal_command, until_next_command)
	(finish_backward, finish_forward, proceed_after_attach_callback)
	(attach_command_post_wait): Adjust calls to proceed.
	* infrun.c (proceed_after_vfork_done): Adjust call to proceed.
	(do_target_resume): New function, factored out from ...
	(resume): ... here.  Remove 'step' parameter.  Instead, check
	currently_stepping to determine whether the thread should be
	single-stepped.
	(proceed): Remove 'step' parameter and don't set the thread's
	step_start_function here.  Adjust call to 'resume'.
	(handle_inferior_event): Adjust calls to 'resume'.
	(switch_back_to_stepped_thread): Use do_target_resume instead of
	'resume'.
	(keep_going): Adjust calls to 'resume'.
	* infrun.h (proceed): Remove 'step' parameter.
	(resume): Likewise.
	* windows-nat.c (do_initial_windows_stuff): Adjust call to
	'resume'.
	* mi/mi-main.c (proceed_thread): Adjust call to 'proceed'.
2015-03-24 17:55:53 +00:00
Pedro Alves 856e7dd698 Make "set scheduler-locking step" depend on user intention, only
Currently, "set scheduler-locking step" is a bit odd.  The manual
documents it as being optimized for stepping, so that focus of
debugging does not change unexpectedly, but then it says that
sometimes other threads may run, and thus focus may indeed change
unexpectedly...  A user can then be excused to get confused and wonder
why does GDB behave like this.

I don't think a user should have to know about details of how "next"
or whatever other run control command is implemented internally to
understand when does the "scheduler-locking step" setting take effect.

This patch completes a transition that the code has been moving
towards for a while.  It makes "set scheduler-locking step" hold
threads depending on whether the _command_ the user entered was a
stepping command [step/stepi/next/nexti], or not.

Before, GDB could end up locking threads even on "continue" if for
some reason run control decides a thread needs to be single stepped
(e.g., for a software watchpoint).

After, if a "continue" happens to need to single-step for some reason,
we won't lock threads (unless when stepping over a breakpoint,
naturally).  And if a stepping command wants to continue a thread for
bit, like when skipping a function to a step-resume breakpoint, we'll
still lock threads, so focus of debugging doesn't change.

In order to make this work, we need to record in the thread structure
whether what set it running was a stepping command.

(A follow up patch will remove the "step" parameters of 'proceed' and 'resume')

FWIW, Fedora GDB, which defaults to "scheduler-locking step" (mainline
defaults to "off") carries a different patch that goes in this
direction as well.

Tested on x86_64 Fedora 20, native and gdbserver.

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

	* gdbthread.h (struct thread_control_state) <stepping_command>:
	New field.
	* infcmd.c (step_once): Pass step=1 to clear_proceed_status.  Set
	the thread's stepping_command field.
	* infrun.c (resume): Check the thread's stepping_command flag to
	determine which threads should be resumed.  Rename 'entry_step'
	local to user_step.
	(clear_proceed_status_thread): Clear 'stepping_command'.
	(schedlock_applies): Change parameter type to struct thread_info
	pointer.  Adjust.
	(find_thread_needs_step_over): Remove 'step' parameter.  Adjust.
	(switch_back_to_stepped_thread): Adjust calls to
	'schedlock_applies'.
	(_initialize_infrun): Adjust "set scheduler-locking step" help.

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

	* gdb.threads/schedlock.exp (test_step): No longer expect that
	"set scheduler-locking step" with "next" over a function call runs
	threads unlocked.

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

	* gdb.texinfo (test_step) <set scheduler-locking step>: No longer
	mention that threads may sometimes run unlocked.
2015-03-24 17:50:31 +00:00
Pedro Alves 885eeb5b8e Make step_start_function be per thread
I noticed that step_start_function is still a global, while it
obviously should be a per-thread field.

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

	* infrun.c (step_start_function): Delete and ...
	* gdbthread.h (struct thread_control_state) <step_start_function>:
	... now a field here.
	* infrun.c (clear_proceed_status_thread): Clear the thread's
	step_start_function.
	(proceed, process_event_stop_test, print_stop_event): Adjust.
2015-03-24 17:50:30 +00:00
Pedro Alves 3333f03ae1 No longer handle negative 'step' in 'proceed'
Nothing ever passes a negative 'step' to proceed.
Gets rid of one of the few remaining stop_after_trap references.

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

	* infrun.c (proceed): No longer handle negative step.
2015-03-24 17:50:29 +00:00
Antoine Tremblay ad235a410a Fix mi-pending.exp test output to allow stable test diffing
gdb/testsuite/ChangeLog:

	* gdb.mi/mi-pending.exp: Fix output of breakpoint test.
2015-03-24 13:38:19 -04:00
Gary Benson 369f6daa21 Move duplicated Linux x86 code to nat/x86-linux.c
This commit moves two identical functions from gdb/x86-linux-nat.c and
gdb/gdbserver/linux-x86-low.c into the shared file gdb/nat/x86-linux.c.

gdb/ChangeLog:

	* nat/x86-linux.h (x86_linux_new_thread): New declaration.
	(x86_linux_prepare_to_resume): Likewise.
	* x86-linux-nat.c (x86_linux_new_thread):
	Moved to nat/x86-linux.c.
	(x86_linux_prepare_to_resume): Likewise.
	* nat/x86-linux.c (x86_linux_new_thread): New function.
	(x86_linux_prepare_to_resume): Likewise.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_linux_new_thread): Moved to
	nat/x86-linux.c.
	(x86_linux_prepare_to_resume): Likewise.
2015-03-24 14:05:45 +00:00
Gary Benson 8e5d407004 Move low-level Linux x86 debug register code to a shared file
This commit moves the now-identical low-level Linux x86 debug register
code from gdb/x86-linux-nat.c and gdb/gdbserver/linux-x86-low.c into a
new shared file gdb/nat/x86-linux-dregs.c.

gdb/ChangeLog:

	* nat/x86-linux-dregs.h: New file.
	* nat/x86-linux-dregs.c: Likewise.
	* Makefile.in (HFILES_NO_SRCDIR): Add nat/x86-linux-dregs.h.
	(x86-linux-dregs.o): New rule.
	* config/i386/linux.mh (NATDEPFILES): Add x86-linux-dregs.o.
	* config/i386/linux64.mh (NATDEPFILES): Likewise.
	* x86-linux-nat.c: Include nat/x86-linux-dregs.h.
	(u_debugreg_offset): Moved to nat/x86-linux-dregs.c.
	(x86_linux_dr_get): Likewise.
	(x86_linux_dr_set): Likewise.
	(x86_linux_dr_get_addr): Likewise.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.
	(update_debug_registers_callback): Likewise.
	(x86_linux_dr_set_control): Likewise.
	(x86_linux_dr_set_addr): Likewise.
	(x86_linux_update_debug_registers): Likewise.

gdb/gdbserver/ChangeLog:

	* Makefile.in (x86-linux-dregs.o): New rule.
	* configure.srv: Add x86-linux-dregs.o to relevant targets.
	* linux-x86-low.c: Include nat/x86-linux-dregs.h.
	(u_debugreg_offset): Moved to nat/x86-linux-dregs.c.
	(x86_linux_dr_get): Likewise.
	(x86_linux_dr_set): Likewise.
	(update_debug_registers_callback): Likewise.
	(x86_linux_dr_set_addr): Likewise.
	(x86_linux_dr_get_addr): Likewise.
	(x86_linux_dr_set_control): Likewise.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.
	(x86_linux_update_debug_registers): Likewise.
2015-03-24 14:05:45 +00:00
Gary Benson 2b95d44038 Introduce x86_linux_update_debug_registers
This commit moves the entire body of both GDB's and gdbserver's
x86_linux_prepare_to_resume functions into new functions,
x86_linux_update_debug_registers.  This reorganisation allows
all Linux x86 low-level debug register code to be placed in one
shared file, separate from general Linux x86 shared code.

gdb/ChangeLog:

	* x86-linux-nat.c (x86_linux_update_debug_registers):
	New function, factored out from...
	(x86_linux_prepare_to_resume): ...this.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_linux_update_debug_registers):
	New function, factored out from...
	(x86_linux_prepare_to_resume): ...this.
2015-03-24 14:05:44 +00:00
Gary Benson 14b0bc68e8 Linux x86 low-level debug register comment synchronization
This commit updates comments in the low-level debug register code for
Linux x86, making GDB's and gdbserver's implementations identical.

gdb/ChangeLog:

	* x86-linux-nat.c (x86_linux_dr_get): Update comments.
	(x86_linux_dr_set): Likewise.
	(x86_linux_dr_get_addr): Likewise.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.
	(update_debug_registers_callback): Likewise.
	(x86_linux_dr_set_control): Likewise.
	(x86_linux_dr_set_addr): Likewise.
	(x86_linux_prepare_to_resume): Likewise.
	(x86_linux_new_thread): Likewise.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_linux_dr_get): Update comments.
	(x86_linux_dr_set): Likewise.
	(update_debug_registers_callback): Likewise.
	(x86_linux_dr_set_addr): Likewise.
	(x86_linux_dr_get_addr): Likewise.
	(x86_linux_dr_set_control): Likewise.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.
	(x86_linux_prepare_to_resume): Likewise.
2015-03-24 14:05:44 +00:00
Gary Benson 5dfe6ca8a8 Linux x86 low-level debug register code synchronization
This commit makes several small changes to the low-level debug
register code for Linux x86, making the code in the GDB and
gdbserver implementations identical.

gdb/ChangeLog:

	* x86-linux-nat.c (x86_linux_dr_set_addr): Update assertion.
	(x86_linux_new_thread): Rename argument.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_linux_dr_get): Add assertion.
	Use perror_with_name.  Pass string through gettext.
	(x86_linux_dr_set): Likewise.
2015-03-24 14:05:44 +00:00
Gary Benson d33472adfc Rename gdbserver's low-level Linux x86 debug register accessors
This commit renames gdbserver's low-level Linux x86 debug register
accessors to the same names used by GDB.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_dr_low_set_addr): Rename to...
	(x86_linux_dr_set_addr): ...this.
	(x86_dr_low_get_addr): Rename to...
	(x86_linux_dr_get_addr): ...this.
	(x86_dr_low_set_control): Rename to...
	(x86_linux_dr_set_control): ...this.
	(x86_dr_low_get_control): Rename to...
	(x86_linux_dr_get_control): ...this.
	(x86_dr_low_get_status): Rename to...
	(x86_linux_dr_get_status): ...this.
	(x86_dr_low): Update with new function names.
2015-03-24 14:05:44 +00:00
Gary Benson 4b134ca108 Make lwp_info.arch_private handling shared
This commit moves the code to handle lwp_info.arch_private for
Linux x86 into a new shared file, nat/x86-linux.c.

gdb/ChangeLog:

	* nat/x86-linux.h: New file.
	* nat/x86-linux.c: Likewise.
	* Makefile.in (HFILES_NO_SRCDIR): Add nat/x86-linux.h.
	(x86-linux.o): New rule.
	* config/i386/linux.mh (NATDEPFILES): Add x86-linux.o.
	* config/i386/linux64.mh (NATDEPFILES): Likewise.
	* nat/linux-nat.h (struct arch_lwp_info): New forward declaration.
	(lwp_set_arch_private_info): New declaration.
	(lwp_arch_private_info): Likewise.
	* linux-nat.c (lwp_set_arch_private_info): New function.
	(lwp_arch_private_info): Likewise.
	* x86-linux-nat.c: Include nat/x86-linux.h.
	(arch_lwp_info): Removed structure.
	(update_debug_registers_callback):
	Use lwp_set_debug_registers_changed.
	(x86_linux_prepare_to_resume): Use lwp_debug_registers_changed
	and lwp_set_debug_registers_changed.
	(x86_linux_new_thread): Use lwp_set_debug_registers_changed.

gdb/gdbserver/ChangeLog:

	* Makefile.in (x86-linux.o): New rule.
	* configure.srv: Add x86-linux.o to relevant targets.
	* linux-low.c (lwp_set_arch_private_info): New function.
	(lwp_arch_private_info): Likewise.
	* linux-x86-low.c: Include nat/x86-linux.h.
	(arch_lwp_info): Removed structure.
	(update_debug_registers_callback):
	Use lwp_set_debug_registers_changed.
	(x86_linux_prepare_to_resume): Use lwp_debug_registers_changed
	and lwp_set_debug_registers_changed.
	(x86_linux_new_thread): Use lwp_set_debug_registers_changed.
2015-03-24 14:05:44 +00:00
Gary Benson 34c703da6c Change signature of linux_target_ops.new_thread
This commit changes the signature of linux_target_ops.new_thread in
gdbserver to match that used in GDB's equivalent.

gdb/gdbserver/ChangeLog:

	* linux-low.h (linux_target_ops) <new_thread>: Changed signature.
	* linux-arm-low.c (arm_new_thread): Likewise.
	* linux-aarch64-low.c (aarch64_linux_new_thread): Likewise.
	* linux-mips-low.c (mips_linux_new_thread): Likewise.
	* linux-x86-low.c (x86_linux_new_thread): Likewise.
	* linux-low.c (add_lwp): Update the_low_target.new_thread call.
2015-03-24 14:05:44 +00:00
Gary Benson cff068da9d Introduce basic LWP accessors
This commit introduces three accessors that shared Linux code can
use to access fields of struct lwp_info.  The GDB and gdbserver
Linux x86 code is modified to use them.

gdb/ChangeLog:

	* nat/linux-nat.h (ptid_of_lwp): New declaration.
	(lwp_is_stopped): Likewise.
	(lwp_stop_reason): Likewise.
	* linux-nat.c (ptid_of_lwp): New function.
	(lwp_is_stopped): Likewise.
	(lwp_is_stopped_by_watchpoint): Likewise.
	* x86-linux-nat.c (update_debug_registers_callback):
	Use lwp_is_stopped.
	(x86_linux_prepare_to_resume): Use ptid_of_lwp and
	lwp_stop_reason.

gdb/gdbserver/ChangeLog:

	* linux-low.c (ptid_of_lwp): New function.
	(lwp_is_stopped): Likewise.
	(lwp_stop_reason): Likewise.
	* linux-x86-low.c (update_debug_registers_callback):
	Use lwp_is_stopped.
	(x86_linux_prepare_to_resume): Use ptid_of_lwp and
	lwp_stop_reason.
2015-03-24 14:05:44 +00:00
Gary Benson b2f7c7e8b7 Make linux_stop_lwp be a shared function
Both GDB and gdbserver had linux_stop_lwp functions with identical
declarations.  This commit moves these to nat/linux-nat.h to allow
shared code to use the function.

gdb/ChangeLog:

	* linux-nat.h (linux_stop_lwp): Move declaration to...
	* nat/linux-nat.h (linux_stop_lwp): New declaration.

gdb/gdbserver/ChangeLog:

	* linux-low.h (linux_stop_lwp): Remove declaration.
2015-03-24 14:05:44 +00:00
Gary Benson 6d4ee8c6ad Add iterate_over_lwps to gdbserver
This commit introduces a new function, iterate_over_lwps, that
shared Linux code can use to call a function for each LWP that
matches certain criteria.  This function already existed in GDB
and was in use by GDB's various low-level Linux x86 debug register
setters.  An equivalent was written for gdbserver and gdbserver's
low-level Linux x86 debug register setters were modified to use
it.

gdb/ChangeLog:

	* linux-nat.h: Include nat/linux-nat.h.
	(iterate_over_lwps): Move declaration to nat/linux-nat.h.
	* nat/linux-nat.h (struct lwp_info): New forward declaration.
	(iterate_over_lwps_ftype): New typedef.
	(iterate_over_lwps): New declaration.
	* linux-nat.h (iterate_over_lwps): Update comment.  Use
	iterate_over_lwps_ftype.  Update callback return value check.

gdb/gdbserver/ChangeLog:

	* linux-low.h: Include nat/linux-nat.h.
	* linux-low.c (iterate_over_lwps_args): New structure.
	(iterate_over_lwps_filter): New function.
	(iterate_over_lwps): Likewise.
	* linux-x86-low.c (update_debug_registers_callback):
	Update signature to what iterate_over_lwps expects.
	Remove PID check that iterate_over_lwps now performs.
	(x86_dr_low_set_addr): Use iterate_over_lwps.
	(x86_dr_low_set_control): Likewise.
2015-03-24 14:05:43 +00:00
Gary Benson 70a0bb6b59 Add x86_debug_reg_state to gdbserver
This commit introduces a new function, x86_debug_reg_state, that
shared x86 code can use to access the local mirror of a process's
debug registers.  This function already existed in GDB and was
in use by GDB's x86_linux_prepare_to_resume.  An equivalent was
written for gdbserver and gdbserver's x86_linux_prepare_to_resume
was modified to use it.

gdb/ChangeLog:

	* x86-nat.h (x86_debug_reg_state): Move declaration to...
	* nat/x86-dregs.h (x86_debug_reg_state): New declaration.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_debug_reg_state): New function.
	(x86_linux_prepare_to_resume): Use the above.
2015-03-24 14:05:43 +00:00
Gary Benson 7b6690874f Introduce current_lwp_ptid
This commit introduces a new function, current_lwp_ptid, that
shared Linux code can use to obtain the ptid of the current
lightweight process.

gdb/ChangeLog:

	* nat/linux-nat.h (current_lwp_ptid): New declaration.
	* linux-nat.c (current_lwp_ptid): New function.
	* x86-linux-nat.c: Include nat/linux-nat.h.
	(x86_linux_dr_get_addr): Use current_lwp_ptid.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.
	(x86_linux_dr_set_control): Likewise.
	(x86_linux_dr_set_addr): Likewise.

gdb/gdbserver/ChangeLog:

	* linux-low.c (current_lwp_ptid): New function.
	* linux-x86-low.c: Include nat/linux-nat.h.
	(x86_dr_low_get_addr): Use current_lwp_ptid.
	(x86_dr_low_get_control): Likewise.
	(x86_dr_low_get_status): Likewise.
2015-03-24 14:05:43 +00:00
Antoine Tremblay 1563054901 Fix breakpoint thread condition missing with mi and a pending breakpoint.
When setting a pending breakpoint with a thread condition while using
the mi interface, the thread condition would be lost by gdb when the breakpoint
was resolved.

This patch fixes this behavior by setting the thread condition properly in the
mi case.

Also, this patch modifies the mi-pending test case to test for this issue and
removes some unneeded code in the testcase and dependency on stdio.

gdb/Changelog:
	PR breakpoints/16466
	* breakpoint.c (create_breakpoint): Set thread on breakpoint struct.

gdb/testsuite/ChangeLog:
	PR breakpoints/16466
	* gdb.mi/Makefile.in: Add mi-pendshr2.sl to cleanup.
	* gdb.mi/mi-pending.c (thread_func): New function.
	(int main): Add threading support required.
	* gdb.mi/mi-pending.exp: Add tests for this issue.
	* gdb.mi/mi-pendshr.c (pendfunc1): Remove stdio dependency.
	(pendfunc2): Remove stdio dependency.
	* gdb.mi/mi-pendshr2.c: New file.
2015-03-24 08:38:49 -04:00
Joel Brobecker 8a4506c032 Fix indentation in ser_windows_setparity and hardwire_setparity.
gdb/ChangeLog:

        * ser-mingw.c (ser_windows_setparity): Fix indentation.
        * ser-unix.c (hardwire_setparity): Likewise.
2015-03-23 15:45:16 -07:00
Yury Grechishchev 236af5e336 GDB: Add set/show serial parity command.
The "set serial parity" command allows the user to control which
parity to use when communicating over a serial connection, rather
than having the parity hardcoded to none.

gdb/ChangeLog:

        * NEWS: Mention set/show serial parity command.
        * monitor.c (monitor_open): Call serial_setparity.
        * remote.c (remote_open_1): Likewise.
        * ser-base.c (ser_base_serparity): New function.
        * ser-base.h (ser_base_setparity): Add  declaration.
        * ser-go32.c (dos_ops): Set "setparity" field.
        * ser-mingw.c (ser_windows_raw): Do not set state.fParity and
        state.Parity.
        (ser_windows_setparity): New function.
        (hardwire_ops): Add ser_windows_setparity.
        (tty_ops): Add NULL for setparity field.
        (pipe_ops): Add ser_base_setparity.
        (tcp_ops): Likewise.
        * ser-pipe.c (pipe_ops): Likewise.
        * ser-tcp.c (tcp_ops): Likewise.
        * ser-unix.c (hardwire_setparity): Add declaration.
        (hardwire_raw): Don't reset PARENB flag.
        (hardwire_setparity): New function.
        (hardwire_ops): Add hardwire_setparity.
        * serial.c (serial_setparity): New function.
        (serial_parity): New global.
        (parity_none, parity_odd, parity_even, parity_enums, parity):
        New static globals.
        (set_parity): New function.
        (_initialize_serial): Add set/show serial parity commands.
        * serial.h (GDBPARITY_NONE): Define.
        (GDBPARITY_ODD): Define.
        (GDBPARITY_EVEN): Define.
        (serial_setparity) Add declaration.
        (struct serial_ops): Add setparity field.
        * target.h (serial_parity): Add declaration.

gdb/doc/ChangeLog:

        * gdb.texinfo (Remote configuration): Document "set/show
        serial parity" command.
2015-03-23 15:34:42 -07:00
Keith Seitz 32b40af94e Update comment of linespec_lexer_lex_keyword.
gdb/ChangeLog

       * linespec.c (linespec_lexer_lex_keyword): Update comment.
2015-03-23 13:32:01 -07:00
Keith Seitz 693dca065a Add missing changelog entries of last commit 2015-03-23 13:29:19 -07:00
Keith Seitz 0578b14e99 Expand keyword lexing intelligence in the linespec parser.
This patch changes the heuristic the linespec lexer uses to
    detect a keyword in the input stream.

    Currently, the heuristic is: a word is a keyword if it
    1) points to a string that is a keyword
    2) is followed by a non-identifier character

    This is strictly more correct than using whitespace. For example,
    it allows constructs such as "break foo if(i == 1)". However,
    find_condition_and_thread in breakpoint.c does not support this expanded
    usage. It requires whitespace to follow the keyword.

    The proposed new heuristic is: a word is a keyword if it
    1) points to a string that is a keyword
    2) is followed by whitespace
    3) is not followed by another keyword string followed by whitespace

    This additional complexity allows constructs such as
    "break thread thread 3" and "break thread 3".  In the former case,
    the actual location is a symbol named "thread" to be set on thread #3.
    In the later case, the location is NULL, i.e., the default location,
    to be set on thread #3.

    In order to pass all the new tests added here, I've also had to add a
    new feature to parse_breakpoint_sals, which expands recognition of the
    default location to keywords other than "if", which is the only keyword
    currently permitted with the default (NULL) location, but there is no
    reason to exclude other keywords.

    Consequently, it will be possible to use "break thread 1" or
    "break task 1".

    In addition to all of this, it is now possible to remove the keyword_ok
    state from the linespec parser.

    gdb/ChangeLog

    	* breakpoint.c (parse_breakpoint_sals): Use
    	linespec_lexer_lex_keyword to ascertain if the user specified
    	a NULL location.
    	* linespec.c [IF_KEYWORD_INDEX]: Define.
    	(linespec_lexer_lex_keyword): Export.
    	(struct ls_parser) <keyword_ok>: Remove.
    	A keyword is only a keyword if not followed by another keyword.
    	(linespec_lexer_lex_one): Remove keyword_ok handling.
    	Add comment explaining why the parsing stream is not advanced
    	when a keyword is seen.
    	(parse_linespec): Remove parser->keyword_ok.
    	* linespec.h (linespec_lexer_lex_keyword): Add declaration.

    gdb/testsuite/ChangeLog

    	* gdb.linespec/keywords.c: New file.
    	* gdb.linespec/keywords.exp: New file.
2015-03-23 13:16:39 -07:00
Keith Seitz 7e993ebf23 PR gdb/18021 - defend against "static virtual" methods
This bug appears to be caused by bad debuginfo. The method
causing the sefault in the reporter's test case is marked both static
and virtual.

This patch simply safegaurds against this case in dwarf2_add_member_fn,
where the code assumes that there is a `this' pointer when a virtual method
is seen (more specifically, when DW_AT_vtable_elem is seen).

It previously dereferenced the first formal parameter
(`this' pointer), which in this case doesn't exist. GDB consequently
segfaulted dereferencing a NULL pointer.

gdb/ChangeLog
	PR gdb/18021
	* dwarf2read.c (dwarf2_add_member_fn): Issue a complaint
	if we find a static method with DW_AT_vtable_elem_location.

gdb/testsuite/ChangeLog
	PR gdb/18021
	* gdb.dwarf2/staticvirtual.exp: New test.
2015-03-23 12:50:28 -07:00
Eli Zaretskii b1a0f70495 Fix undefined behavior in TUI's TAB expansion
gdb/ChangeLog:

	* tui/tui-io.c (tui_expand_tabs): Reinitialize the column counter
	before the second loop, to avoid undefined behavior.  Reported by
	Anton Blanchard <anton@samba.org>.
2015-03-21 10:48:34 +02:00
Keven Boell d9823cbb39 [gdb/DWARF] Introduce linked list for dynamic attributes
This patch introduces a linked list for dynamic attributes of a type.
This is a pre-work for the Fortran dynamic array support. The Fortran
dynamic array support will add more dynamic attributes to a type.
As only a few types will have such dynamic attributes set, a linked
list is more efficient in terms of memory consumption than adding
multiple attributes to main_type.

gdb/ChangeLog:

        * gdbtypes.c (resolve_dynamic_type_internal): Adapt
        data_location usage to linked list.
        (resolve_dynamic_type_internal): Adapt data_location to
        linked list.
        (get_dyn_prop, add_dyn_prop, copy_dynamic_prop_list): New function.
        (copy_type_recursive, copy_type): Add copy of linked list.
        * gdbtypes.h (enum dynamic_prop_node_kind): New enum.
        (struct dynamic_prop_list): New struct.
        * dwarf2read.c (set_die_type): Set data_location data.
2015-03-20 17:52:03 -04:00
Pedro Alves 2e7bf1d721 constify i386-sol2-tdep.c and machoread.c
/home/pedro/gdb/mygit/src/gdb/i386-sol2-tdep.c: In function ‘const char* i386_sol2_static_transform_name(const char*)’:
/home/pedro/gdb/mygit/src/gdb/i386-sol2-tdep.c:93:29: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
       p = strrchr (name, '.');
                             ^
gdb:

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

	* i386-sol2-tdep.c (i386_sol2_static_transform_name): Move "p" to
	inner block and make it const.
	* machoread.c (get_archive_prefix_len): Make "lparen" const.
2015-03-20 17:39:29 +00:00
Pedro Alves 7a26bd4d83 constify set_breakpoint_condition
gdb:

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

	* breakpoint.c (set_breakpoint_condition): Make argument "exp" const.
	* breakpoint.h (set_breakpoint_condition): Update declaration.
2015-03-20 17:39:24 +00:00
Pedro Alves cd46431bbd constify tui/tui-io.c
gdb:

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

	* tui/tui-io.c (tui_expand_tabs): Make "s1" const.
2015-03-20 17:39:18 +00:00
Pedro Alves e28566f7d0 constify xcoffread.c
/home/pedro/gdb/mygit/src/gdb/xcoffread.c: In function ‘void scan_xcoff_symtab(objfile*)’:
/home/pedro/gdb/mygit/src/gdb/xcoffread.c:2644:33: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
      p = strchr (namestring, ':');
                                 ^
gdb:

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

	* xcoffread.c (scan_xcoff_symtab): Make "p" and "q" const.
2015-03-20 17:39:13 +00:00
Pedro Alves f6fc92f671 constify remote-m32r-sdi.c
gdb:

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

	* remote-m32r-sdi.c (m32r_open): Make "port_str" const.
2015-03-20 17:39:08 +00:00
Pedro Alves c32ed3ef80 constify nto-tdep.c
/home/pedro/gdb/mygit/src/gdb/nto-tdep.c: In function ‘int nto_find_and_open_solib(char*, unsigned int, char**)’:
/home/pedro/gdb/mygit/src/gdb/nto-tdep.c:111:14: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
       endian = gdbarch_byte_order (target_gdbarch ())
              ^
/home/pedro/gdb/mygit/src/gdb/nto-tdep.c: In function ‘void nto_init_solib_absolute_prefix()’:
/home/pedro/gdb/mygit/src/gdb/nto-tdep.c:170:14: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
       endian = gdbarch_byte_order (target_gdbarch ())
              ^

gdb

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

	* nto-tdep.c (nto_find_and_open_solib): Make "endian" const.
	(nto_init_solib_absolute_prefix): Likewise.
2015-03-20 17:39:03 +00:00
Pedro Alves eef49a3d1a constify gdbserver/tracepoint.c
gdb/gdbserver/tracepoint.c:3647:7: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
gdb/gdbserver/tracepoint.c:3652:7: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
gdb/gdbserver/tracepoint.c:3657:7: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

gdb/gdbserver

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

	* tracepoint.c (cmd_qtstatus): Make "str" const.
2015-03-20 17:38:59 +00:00
Pedro Alves b2333d22e0 constify gdbserver/server.c
gdb/gdbserver/

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

	* server.c (handle_general_set): Make "req_str" const.
2015-03-20 17:38:54 +00:00
Pedro Alves 53e7808581 constify sparc-sol2-tdep.c and spu-tdep.c
/home/pedro/gdb/mygit/src/gdb/sparc-sol2-tdep.c: In function ‘const char* sparc_sol2_static_transform_name(const char*)’:
/home/pedro/gdb/mygit/src/gdb/sparc-sol2-tdep.c:247:35: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
       char *p = strrchr (name, '.');
                                   ^
gdb:

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

	* sparc-sol2-tdep.c (sparc_sol2_static_transform_name): Make "p" const.
	* spu-tdep.c (spu_gdbarch_init): Make "name" const.
2015-03-20 17:38:50 +00:00
Jan Kratochvil bc23328cc1 Remove gdb.hp
gdb/ChangeLog
2015-03-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* config/djgpp/README: Remove gdb.hp.

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

	* Makefile.in (ALL_SUBDIRS): Remove gdb.hp.
	* README: Remove HP-UX and gdb.hp.
	(configuration):
	* configure: Regenerate.
	* configure.ac (AC_OUTPUT): Remove gdb.hp/Makefile,
	gdb.hp/gdb.objdbg/Makefile, gdb.hp/gdb.base-hp/Makefile,
	gdb.hp/gdb.aCC/Makefile, gdb.hp/gdb.compat/Makefile,
	gdb.hp/gdb.defects/Makefile.
	* gdb.hp/Makefile.in: File deleted.
	* gdb.hp/gdb.aCC/Makefile.in: File deleted.
	* gdb.hp/gdb.aCC/optimize.c: File deleted.
	* gdb.hp/gdb.aCC/optimize.exp: File deleted.
	* gdb.hp/gdb.aCC/run.c: File deleted.
	* gdb.hp/gdb.aCC/watch-cmd.exp: File deleted.
	* gdb.hp/gdb.base-hp/Makefile.in: File deleted.
	* gdb.hp/gdb.base-hp/callfwmall.c: File deleted.
	* gdb.hp/gdb.base-hp/callfwmall.exp: File deleted.
	* gdb.hp/gdb.base-hp/dollar.c: File deleted.
	* gdb.hp/gdb.base-hp/dollar.exp: File deleted.
	* gdb.hp/gdb.base-hp/genso-thresh.c: File deleted.
	* gdb.hp/gdb.base-hp/hwwatchbus.c: File deleted.
	* gdb.hp/gdb.base-hp/hwwatchbus.exp: File deleted.
	* gdb.hp/gdb.base-hp/pxdb.c: File deleted.
	* gdb.hp/gdb.base-hp/pxdb.exp: File deleted.
	* gdb.hp/gdb.base-hp/reg-pa64.exp: File deleted.
	* gdb.hp/gdb.base-hp/reg-pa64.s: File deleted.
	* gdb.hp/gdb.base-hp/reg.exp: File deleted.
	* gdb.hp/gdb.base-hp/reg.s: File deleted.
	* gdb.hp/gdb.base-hp/sized-enum.c: File deleted.
	* gdb.hp/gdb.base-hp/sized-enum.exp: File deleted.
	* gdb.hp/gdb.base-hp/so-thresh.exp: File deleted.
	* gdb.hp/gdb.base-hp/so-thresh.mk: File deleted.
	* gdb.hp/gdb.base-hp/so-thresh.sh: File deleted.
	* gdb.hp/gdb.compat/Makefile.in: File deleted.
	* gdb.hp/gdb.compat/average.c: File deleted.
	* gdb.hp/gdb.compat/sum.c: File deleted.
	* gdb.hp/gdb.compat/xdb.c: File deleted.
	* gdb.hp/gdb.compat/xdb0.c: File deleted.
	* gdb.hp/gdb.compat/xdb0.h: File deleted.
	* gdb.hp/gdb.compat/xdb1.c: File deleted.
	* gdb.hp/gdb.compat/xdb1.exp: File deleted.
	* gdb.hp/gdb.compat/xdb2.exp: File deleted.
	* gdb.hp/gdb.compat/xdb3.exp: File deleted.
	* gdb.hp/gdb.defects/Makefile.in: File deleted.
	* gdb.hp/gdb.defects/bs14602.c: File deleted.
	* gdb.hp/gdb.defects/bs14602.exp: File deleted.
	* gdb.hp/gdb.defects/solib-d.c: File deleted.
	* gdb.hp/gdb.defects/solib-d.exp: File deleted.
	* gdb.hp/gdb.defects/solib-d1.c: File deleted.
	* gdb.hp/gdb.defects/solib-d2.c: File deleted.
	* gdb.hp/gdb.objdbg/Makefile.in: File deleted.
	* gdb.hp/gdb.objdbg/objdbg01.exp: File deleted.
	* gdb.hp/gdb.objdbg/objdbg01/x1.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg01/x2.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg01/x3.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg01/x3.h: File deleted.
	* gdb.hp/gdb.objdbg/objdbg02.exp: File deleted.
	* gdb.hp/gdb.objdbg/objdbg02/x1.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg02/x2.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg02/x3.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg03.exp: File deleted.
	* gdb.hp/gdb.objdbg/objdbg03/x1.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg03/x2.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg03/x3.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg04.exp: File deleted.
	* gdb.hp/gdb.objdbg/objdbg04/x.h: File deleted.
	* gdb.hp/gdb.objdbg/objdbg04/x1.cc: File deleted.
	* gdb.hp/gdb.objdbg/objdbg04/x2.cc: File deleted.
	* gdb.hp/gdb.objdbg/tools/symaddr: File deleted.
	* gdb.hp/gdb.objdbg/tools/symaddr.pa64: File deleted.
	* gdb.hp/gdb.objdbg/tools/test-objdbg.cc: File deleted.
	* gdb.hp/tools/odump: File deleted.
2015-03-20 17:15:15 +01:00
Yao Qi e8ffc436d9 Don't call set_gdbarch_cannot_step_breakpoint in aarch64_gdbarch_init
Hi,
I am looking at the following fails in aarch64-linux,

stepi^M
47        NOP; /* after permanent bp */^M
(gdb) FAIL: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: stepi signal with handler: single-step to handler

the test expects GDB single step into signal handler, but GDB doesn't.
The code in infrun.c:resume

      /* Most targets can step a breakpoint instruction, thus
	 executing it normally.  But if this one cannot, just
	 continue and we will hit it anyway.  */
      if (gdbarch_cannot_step_breakpoint (gdbarch))
	step = 0;

change the intended action from "step" to "continue".  The gdbarch method
cannot_step_breakpoint isn't documented well, and I don't get much clue
after explore the history.  However, from the comments above,
aarch64-linux can step a breakpoint instruction, so don't need to call
set_gdbarch_cannot_step_breakpoint.

gdb:

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

	* aarch64-tdep.c (aarch64_gdbarch_init): Don't call
	set_gdbarch_cannot_step_breakpoint.
2015-03-20 10:15:21 +00:00
Pedro Alves 23f238d345 Fix race exposed by gdb.threads/killed.exp
On GNU/Linux, this test sometimes FAILs like this:

 (gdb) run
 Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library "/lib64/libthread_db.so.1".
 ptrace: No such process.
 (gdb)
 Program terminated with signal SIGKILL, Killed.
 The program no longer exists.
 FAIL: gdb.threads/killed.exp: run program to completion (timeout)

Note the suspicious "No such process" line (that's errno==ESRCH).
Adding debug output we see:

  linux_nat_wait: [process -1], [TARGET_WNOHANG]
  LLW: enter
  LNW: waitpid(-1, ...) returned 18465, ERRNO-OK
  LLW: waitpid 18465 received Stopped (signal) (stopped)
  LNW: waitpid(-1, ...) returned 18461, ERRNO-OK
  LLW: waitpid 18461 received Trace/breakpoint trap (stopped)
  LLW: Handling extended status 0x03057f
  LHEW: Got clone event from LWP 18461, new child is LWP 18465
  LNW: waitpid(-1, ...) returned 0, ERRNO-OK
  RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0
  RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0
  sigchld
  ptrace: No such process.
  (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG]
  LLW: enter
  LNW: waitpid(-1, ...) returned 18465, ERRNO-OK
  LLW: waitpid 18465 received Killed (terminated)
  LLW: LWP 18465 exited.
  LNW: waitpid(-1, ...) returned 18461, No child processes
  LLW: waitpid 18461 received Killed (terminated)
  Process 18461 exited
  LNW: waitpid(-1, ...) returned -1, No child processes
  LLW: exit
  sigchld
  infrun: target_wait (-1, status) =
  infrun:   18461 [process 18461],
  infrun:   status->kind = signalled, signal = GDB_SIGNAL_KILL
  infrun: TARGET_WAITKIND_SIGNALLED

  Program terminated with signal SIGKILL, Killed.
  The program no longer exists.
  infrun: stop_waiting
  FAIL: gdb.threads/killed.exp: run program to completion (timeout)

The issue is that here:

  RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0
  RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0

The first line shows we had just resumed LWP 18465, which does:

 void *
 child_func (void *dummy)
 {
   kill (pid, SIGKILL);
   exit (1);
 }

So if the kernel manages to schedule that thread fast enough, the
process may be killed before GDB has a chance to resume LWP 18461.

GDBserver has code at the tail end of linux_resume_one_lwp to cope
with this:

~~~
    ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread),
	    (PTRACE_TYPE_ARG3) 0,
	    /* Coerce to a uintptr_t first to avoid potential gcc warning
	       of coercing an 8 byte integer to a 4 byte pointer.  */
	    (PTRACE_TYPE_ARG4) (uintptr_t) signal);

    current_thread = saved_thread;
    if (errno)
      {
	/* ESRCH from ptrace either means that the thread was already
	   running (an error) or that it is gone (a race condition).  If
	   it's gone, we will get a notification the next time we wait,
	   so we can ignore the error.  We could differentiate these
	   two, but it's tricky without waiting; the thread still exists
	   as a zombie, so sending it signal 0 would succeed.  So just
	   ignore ESRCH.  */
	if (errno == ESRCH)
	  return;

	perror_with_name ("ptrace");
      }
~~~

However, that's not a complete fix, because between starting to handle
the resume request and getting that PTRACE_CONTINUE, we run other
ptrace calls that can also fail with ESRCH, and that end up throwing
an error (with perror_with_name).

In the case above, I indeed sometimes see resume_stopped_resumed_lwps
fail in the registers read:

resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
{
...
      CORE_ADDR pc = regcache_read_pc (regcache);

Or e.g., in 32-bit mode, i386_linux_resume has several calls that can
throw too.

Whether to ignore ptrace errors or not depends on context that is only
available somewhere up the call chain.  So the fix is to let ptrace
errors throw as they do today, and wrap the resume request in a
TRY/CATCH that swallows it iff the lwp that we were trying to resume
is no longer ptrace-stopped.

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

	* linux-low.c (linux_resume_one_lwp): Rename to ...
	(linux_resume_one_lwp_throw): ... this.  Don't handle ESRCH here,
	instead call perror_with_name.
	(check_ptrace_stopped_lwp_gone): New function.
	(linux_resume_one_lwp): Reimplement as wrapper around
	linux_resume_one_lwp_throw that swallows errors if the LWP is
	gone.

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

	* linux-nat.c (linux_resume_one_lwp): Rename to ...
	(linux_resume_one_lwp_throw): ... this.  Don't handle ESRCH here,
	instead call perror_with_name.
	(check_ptrace_stopped_lwp_gone): New function.
	(linux_resume_one_lwp): Reimplement as wrapper around
	linux_resume_one_lwp_throw that swallows errors if the LWP is
	gone.
	(resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and
	swallows errors if the LWP is gone.  Use
	linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 17:07:38 +00:00
Pedro Alves 7d1551f618 Remove spurious gdb/ChangeLog entry
My last change added the same entry to both gdbserver's and gdb's
ChangeLogs by mistake...  Should have gone to gdbserver's only.
2015-03-19 17:00:55 +00:00
Pedro Alves 91baf43fa7 gdbserver/Linux: unbreak non-stop
The previous change added an assertion that is catching yet another
bug in count_events_callback/select_event_lwp_callback:

  (gdb)
  PASS: gdb.mi/mi-nonstop.exp: interrupted
  mi_expect_interrupt: expecting: \*stopped,(reason="signal-received",signal-name="0",signal-meaning="Signal 0"|reason="signal-received",signal-name="SIGINT",signal-meaning="Interrupt")[^
  ]*

  /home/pedro/gdb/mygit/src/gdb/gdbserver/linux-low.c:2329: A problem internal to GDBserver has been detected.
  select_event_lwp: Assertion `num_events > 0' failed.
  =thread-group-exited,id="i1"

Certainly select_event_lwp_callback should always at least find one
event, as it's only called because an event triggered (though we may
have more than one: the point of the function is randomly picking
one).

An LWP that GDB previously asked to continue/step (thus is resumed)
and gets a vCont;t request ends up with last_resume_kind ==
resume_stop.  These functions in gdbserver used to filter out events
that weren't going to be reported to GDB; I think the last_resume_kind
kind check used to make sense at that point, but it no longer does.

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

	* linux-low.c (count_events_callback, select_event_lwp_callback):
	No longer check whether the thread has resume_stop as last resume
	kind.
2015-03-19 16:51:09 +00:00
Pedro Alves 8bf3b159e5 gdbserver/Linux: unbreak thread event randomization
Wanting to make sure the new continue-pending-status.exp test tests
both cases of threads 2 and 3 reporting an event, I added counters to
the test, to make it FAIL if events for both threads aren't seen.
Assuming a well behaved backend, and given a reasonable number of
iterations, it should PASS.

However, running that against GNU/Linux gdbserver, I found that
surprisingly, that FAILed.  GDBserver always reported the breakpoint
hit for the same thread.

Turns out that I broke gdbserver's thread event randomization
recently, with git commit 582511be ([gdbserver] linux-low.c: better
starvation avoidance, handle non-stop mode too).  In that commit I
missed that the thread structure also has a status_pending_p field...
The end result was that count_events_callback always returns 0, and
then if no thread is stepping, select_event_lwp always returns the
event thread.  IOW, no randomization is happening at all.  Quite
curious how all the other changes in that patch were sufficient to fix
non-stop-fair-events.exp anyway even with that broken.

Tested on x86_64 Fedora 20, native and gdbserver.

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

	* linux-low.c (count_events_callback, select_event_lwp_callback):
	Use the lwp's status_pending_p field, not the thread's.

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

	* gdb.threads/continue-pending-status.exp (saw_thread_2)
	(saw_thread_3): New globals.
	(top level): Increment them when an event for the corresponding
	thread is seen.
	(no thread starvation): New test.
2015-03-19 12:38:05 +00:00
Pedro Alves eb54c8bf08 native/Linux: internal error if resume is short-circuited
If the linux_nat_resume's short-circuits the resume because the
current thread has a pending status, and, a thread with a higher
number was previously stopped for a breakpoint, GDB internal errors,
like:

 /home/pedro/gdb/mygit/src/gdb/linux-nat.c:2590: internal-error: status_callback: Assertion `lp->status != 0' failed.

Fix this by make status_callback bail out earlier.  GDBserver is
already doing the same.

New test added that exercises this.

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

	* linux-nat.c (status_callback): Return early if the LWP has no
	status pending.

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

	* gdb.threads/continue-pending-status.c: New file.
	* gdb.threads/continue-pending-status.exp: New file.
2015-03-19 12:26:49 +00:00
Pedro Alves b90fc18880 select_event_lwp_callback: update comments
This function (in both GDB and GDBserver) used to consider only
SIGTRAP/breakpoint events, but that's no longer the case nowadays.

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

	* linux-low.c (select_event_lwp_callback): Update comments to
	no longer mention SIGTRAP.

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

	* linux-nat.c (select_event_lwp_callback): Update comment to no
	longer mention SIGTRAP.
2015-03-19 12:24:06 +00:00
Pedro Alves 32d2e5d640 Tighten gdb.base/disp-step-syscall.exp
This fixes several problems with this test.

E.g,. with --target_board=native-extended-gdbserver on x86_64 Fedora
20, I get:

 Running /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/disp-step-syscall.exp ...
 FAIL: gdb.base/disp-step-syscall.exp: vfork: get hexadecimal valueof "$pc" (timeout)
 FAIL: gdb.base/disp-step-syscall.exp: vfork: single step over vfork final pc
 FAIL: gdb.base/disp-step-syscall.exp: vfork: delete break vfork insn
 FAIL: gdb.base/disp-step-syscall.exp: vfork: continue to marker (vfork) (the program is no longer running)

And with --target=native-gdbserver, I get:

 Running /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/disp-step-syscall.exp ...
 KPASS: gdb.base/disp-step-syscall.exp: vfork: single step over vfork (PRMS server/13796)
 FAIL: gdb.base/disp-step-syscall.exp: vfork: get hexadecimal valueof "$pc" (timeout)
 FAIL: gdb.base/disp-step-syscall.exp: vfork: single step over vfork final pc
 FAIL: gdb.base/disp-step-syscall.exp: vfork: delete break vfork insn
 FAIL: gdb.base/disp-step-syscall.exp: vfork: continue to marker (vfork) (the program is no longer running)

First, the lack of fork support on remote targets is supposed to be
kfailed, so the KPASS is obviously bogus.  The extended-remote board
should have KFAILed too.

The problem is that the test is using "is_remote" instead of
gdb_is_target_remote.

And then, I get:

 (gdb) PASS: gdb.base/disp-step-syscall.exp: vfork: set displaced-stepping on
 stepi

 Program terminated with signal SIGSEGV, Segmentation fault.
 The program no longer exists.
 (gdb) PASS: gdb.base/disp-step-syscall.exp: vfork: single step over vfork

Obviously, that should be a FAIL.  The problem is that the test only
expects SIGILL, not SIGSEGV.  It also doesn't bail correctly if an
internal error or some other pattern caught by gdb_test_multiple
matches.  The test doesn't really need to match specific exits/crashes
patterns, if the PASS regex is improved, like in ...

... this and the other "stepi" tests are a bit too lax, passing on
".*".  This tightens those up to expect "x/i" and the "=>" current PC
indicator, like in:

 1: x/i $pc
 => 0x3b36abc9e2 <vfork+34>:     syscall

On x86_64 Fedora 20, I now get a quick KFAIL instead of timeouts with
both the native-extended-gdbserver and native-gdbserver boards:

 PASS: gdb.base/disp-step-syscall.exp: vfork: delete break vfork
 PASS: gdb.base/disp-step-syscall.exp: vfork: continue to syscall insn vfork
 PASS: gdb.base/disp-step-syscall.exp: vfork: set displaced-stepping on
 KFAIL: gdb.base/disp-step-syscall.exp: vfork: single step over vfork (PRMS: server/13796)

and a full pass with native testing.

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

	* gdb.base/disp-step-syscall.exp (disp_step_cross_syscall):
	Use gdb_is_target_remote instead of is_remote.  Use
	gdb_test_multiple instead of gdb_expect.  Exit early if
	gdb_test_multiple hits its internal matches.  Tighten stepi tests
	expected output.  Fail on exit with any signal, instead of just
	SIGILL.
2015-03-18 19:28:08 +00:00
Tristan Gingold 670f82d437 Fix amd64 windows unwinding issues within MS dlls.
Unwind info in system dlls uses almost all possible codes, contrary to unwind
info generated by gcc.  A few issues have been discovered: incorrect handling
of SAVE_NONVOL opcodes and incorrect in prologue range checks.  Furthermore I
added comments not to forget what has been investigated.

gdb/ChangeLog:
	* amd64-windows-tdep.c (amd64_windows_find_unwind_info): Move
	redirection code to ...
	(amd64_windows_frame_decode_insns): ... Here.  Fix in prologue
	checks.  Fix SAVE_NONVOL operations.  Add debug code and comments.
2015-03-18 15:55:10 +01:00
Gary Benson 464b0089f0 Reimplement "vFile:fstat" without qSupported
This commit makes support for the "vFile:fstat" packet be detected
by probing rather than using qSupported, for consistency with the
other vFile: packets.

gdb/ChangeLog:

	(remote_protocol_features): Remove the "vFile:fstat" feature.
	(remote_hostio_fstat): Probe for "vFile:fstat" support.

gdb/doc/ChangeLog:

	* gdb.texinfo (General Query Packets): Remove documentation
	for now-removed vFile:fstat qSupported features.

gdb/gdbserver/ChangeLog:

	* server.c (handle_query): Do not report vFile:fstat as supported.
2015-03-18 11:19:02 +00:00
Yao Qi f68f11b76d Support catch syscall on aarch64 linux
Hi,
This patch is to support catch syscall on aarch64 linux.  We
implement gdbarch method get_syscall_number for aarch64-linux,
and add aarch64-linux.xml file, which looks straightforward, however
the changes to test case doesn't.

First of all, we enable catch-syscall.exp on aarch64-linux target,
but skip the multi_arch testing on current stage.  I plan to touch
multi arch debugging on aarch64-linux later.

Then, when I run catch-syscall.exp on aarch64-linux, gcc errors that
SYS_pipe isn't defined.  We find that aarch64 kernel only has pipe2
syscall and libc already convert pipe to pipe2.  As a result, I change
catch-syscall.c to use SYS_pipe if it is defined, otherwise use
SYS_pipe2 instead.  The vector all_syscalls in catch-syscall.exp can't
be pre-determined, so I add a new proc setup_all_syscalls to fill it,
according to the availability of SYS_pipe.

Regression tested on {x86_64, aarch64}-linux x {native, gdbserver}.

gdb:

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

	PR tdep/18107
	* aarch64-linux-tdep.c: Include xml-syscall.h
	(aarch64_linux_get_syscall_number): New function.
	(aarch64_linux_init_abi): Call
	set_gdbarch_get_syscall_number.
	* syscalls/aarch64-linux.xml: New file.

gdb/testsuite:

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

	PR tdep/18107
	* gdb.base/catch-syscall.c [!SYS_pipe] (pipe2_syscall): New
	variable.
	* gdb.base/catch-syscall.exp: Don't skip it on
	aarch64*-*-linux* target.  Remove elements in all_syscalls.
	(test_catch_syscall_multi_arch): Skip it on aarch64*-linux*
	target.
	(setup_all_syscalls): New proc.
2015-03-18 10:47:45 +00:00
Yurij Grechishhev 393bd0c06b Fix name of ser_base_setstopbits's second argument.
Small copy/paste error, most likely...

gdb/ChangeLog:

	* ser-base.h (ser_base_setstopbits): Change second argument name
	from "rate" to "num".
2015-03-17 10:12:56 -04:00
Gary Benson 7f3647e2ba Remove forward declaration of struct stat
Forward declarations of struct stat break the Windows build.
This commit removes a forward declaration of struct stat and
includes sys/stat.h directly instead.

gdb/ChangeLog:

	PR gdb/18131
	* common/common-remote-fileio.h (sys/stat.h): New include.
	(stuct stat): Remove forward declaration.
2015-03-17 11:26:09 +00:00
Yao Qi ca5fd19bfb watchpoint-reuse-slot.exp: skip setting HW breakpoints on some address
We see some fails in watchpoint-reuse-slot.exp on aarch64-linux, because
it sets some HW breakpoint on some address doesn't meet the alignment
requirements by kernel, kernel will reject the
ptrace (PTRACE_SETHBPREGS) call, and some fails are caused, for example:

(gdb) PASS: gdb.base/watchpoint-reuse-slot.exp: always-inserted off: watch x hbreak: : width 1, iter 0: base + 0: delete $bpnum
hbreak *(buf.byte + 0 + 1)^M
Hardware assisted breakpoint 80 at 0x410a61^M
(gdb) PASS: gdb.base/watchpoint-reuse-slot.exp: always-inserted off: watch x hbreak: : width 1, iter 0: base + 1: hbreak *(buf.byte + 0 + 1)
stepi^M
Warning:^M
Cannot insert hardware breakpoint 80.^M
Could not insert hardware breakpoints:^M
You may have requested too many hardware breakpoints/watchpoints.^M
^M
(gdb) FAIL: gdb.base/watchpoint-reuse-slot.exp: always-inserted off: watch x hbreak: : width 1, iter 0: base + 1: stepi advanced

hbreak *(buf.byte + 0 + 1)^M
Hardware assisted breakpoint 440 at 0x410a61^M
Warning:^M
Cannot insert hardware breakpoint 440.^M
Could not insert hardware breakpoints:^M
You may have requested too many hardware breakpoints/watchpoints.^M
^M
(gdb) FAIL: gdb.base/watchpoint-reuse-slot.exp: always-inserted on: watch x hbreak: : width 1, iter 0: base + 1: hbreak *(buf.byte + 0 + 1)

This patch is to skip some tests by checking proc valid_addr_p.
We can handle other targets in valid_addr_p too.

gdb/testsuite:

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

	* gdb.base/watchpoint-reuse-slot.exp (valid_addr_p): New proc.
	(top level): Skip tests if valid_addr_p returns false for
	$cmd1 or $cmd2.
2015-03-16 17:27:02 +00:00
John Baldwin 3ce5b6e25c Fetch all registers before writing the core register notes.
Without this, not all registers were present in the core generated by
gcore.  For example, running 'gcore' on a program without examining
the vector registers (SSE or AVX) would store all the vector registers
as zeros because they were not pulled into the regcache.  Running
'info vector' before 'gcore' would store the correct values in the
core since it populated the regcache.  For Linux processes, a similar
operation is achieved by having the thread iterator callback invoke
target_fetch_registers on each thread before its corresponding
register notes are dumped.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_make_corefile_notes): Fetch all target registers
	before writing core register notes.
2015-03-16 09:48:51 -04:00
Yuanhui Zhang d053f6be55 stub termcap, add extern "C"
Fixes linking an --enable-build-with-cxx build on mingw:

 ../readline/terminal.c:278: undefined reference to `tgetnum'
 ../readline/terminal.c:297: undefined reference to `tgetnum'
 ../readline/libreadline.a(terminal.o): In function `get_term_capabilities':
 ../readline/terminal.c:427: undefined reference to `tgetstr'
 ../readline/libreadline.a(terminal.o): In function `_rl_init_terminal_io':
 [etc.]

gdb/ChangeLog:
2015-03-16  Yuanhui Zhang  <asmwarrior@gmail.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb_curses.h (tgetnum): Mark with EXTERN_C.
	* stub-termcap.c (tgetent, tgetnum, tgetflag, tgetstr, tputs)
	(tgoto): Wrap with extern "C".
2015-03-16 11:36:00 +00:00
Pedro Alves b1a921c8c6 stub-termcap.c: prototype tputs's parameter's parameter, for C++ mode
src/gdb/stub-termcap.c: In function 'int tputs(char*, int, int (*)())':
 src/gdb/stub-termcap.c:67:22: error: too many arguments to function
      outfun (*string++);
		       ^

gdb/ChangeLog:
2015-03-16  Pedro Alves  <palves@redhat.com>
	    Yuanhui Zhang  <asmwarrior@gmail.com>

	* stub-termcap.c (tputs): Change prototype.
2015-03-16 11:36:00 +00:00
Yuanhui Zhang 876d1cd7b5 windows-nat.c: conflicting declaration of struct thread_info in C++ mode
Building mingw GDB with --enable-build-with-cxx shows:

 ../../binutils-gdb/gdb/windows-nat.c: At global scope:
 ../../binutils-gdb/gdb/windows-nat.c:192:1: error: conflicting declaration 'typedef struct thread_info_struct thread_info'
  thread_info;
  ^
 In file included from ../../binutils-gdb/gdb/windows-nat.c:52:0:
 ../../binutils-gdb/gdb/gdbthread.h:160:8: error: 'struct thread_info' has a previous declaration as 'struct thread_info'
  struct thread_info
	 ^

Simply rename the structure to avoid the conflict.

gdb/ChangeLog:
2015-03-16  Yuanhui Zhang  <asmwarrior@gmail.com>
	    Pedro Alves  <palves@redhat.com>

	* windows-nat.c (struct thread_info_struct): Rename to ...
	(struct windows_thread_info_struct): ... this.
	(thread_info): Rename to ...
	(windows_thread_info): ... this.
	All users updated.
2015-03-16 11:31:31 +00:00
Jan Kratochvil 0800b440df NEWS: Remove HPUX
gdb/ChangeLog
2015-03-14  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* NEWS: New Removed targets and native configurations.
2015-03-14 11:01:17 +01:00
Jan Kratochvil 61a12cfa7b Remove HPUX
IIUC it is a pre-requisite for IPv6 support, some UNICes do not support
getaddrinfo required for IPv6.  But coincidentally such UNICes are no longer
really supported by GDB.  Therefore it was concluded we can remove all such
UNICes and then we can implement IPv6 easily with getaddrinfo.

In mail
        Re: getaddrinfo available on all GDB hosts? [Re: [PATCH v2] Add IPv6 support for remote TCP connections]
        Message-ID: <20140211034157.GG5485@adacore.com>
        https://sourceware.org/ml/gdb-patches/2014-02/msg00333.html
Joel said:

So I chose HP-UX first for this patch.

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

	Remove HPUX.
	* Makefile.in (ALL_64_TARGET_OBS): Remove ia64-hpux-tdep.o.
	(ALL_TARGET_OBS): Remove hppa-hpux-tdep.o, solib-som.o and solib-pa64.o.
	(HFILES_NO_SRCDIR): Remove solib-som.h, inf-ttrace.h, solib-pa64.h and
	ia64-hpux-tdep.h, solib-ia64-hpux.h.
	(ALLDEPFILES): Remove hppa-hpux-tdep.c, hppa-hpux-nat.c,
	ia64-hpux-nat.c, ia64-hpux-tdep.c, somread.c and solib-som.c.
	* config/djgpp/fnchange.lst: Remove hppa-hpux-nat.c and
	hppa-hpux-tdep.c.
	* config/ia64/hpux.mh: Remove file.
	* config/pa/hpux.mh: Remove file.
	* configure: Rebuilt.
	* configure.ac (dlgetmodinfo, somread.o): Remove.
	* configure.host (hppa*-*-hpux*, ia64-*-hpux*): Make them obsolete.
	(ia64-*-hpux*): Remove its float format exception.
	* configure.tgt (hppa*-*-hpux*, ia64-*-hpux*): Make them obsolete.
	* hppa-hpux-nat.c: Remove file.
	* hppa-hpux-tdep.c: Remove file.
	* hppa-tdep.c (struct hppa_unwind_info, struct hppa_objfile_private):
	Move them here from hppa-tdep.h
	(hppa_objfile_priv_data, hppa_init_objfile_priv_data): Make it static.
	(hppa_frame_prev_register_helper): Remove HPPA_FLAGS_REGNUM exception.
	* hppa-tdep.h (struct hppa_unwind_info, struct hppa_objfile_private):
	Move them to hppa-tdep.c.
	(hppa_objfile_priv_data, hppa_init_objfile_priv_data): Remove
	declarations.
	* ia64-hpux-nat.c: Remove file.
	* ia64-hpux-tdep.c: Remove file.
	* ia64-hpux-tdep.h: Remove file.
	* inf-ttrace.c: Remove file.
	* inf-ttrace.h: Remove file.
	* solib-ia64-hpux.c: Remove file.
	* solib-ia64-hpux.h: Remove file.
	* solib-pa64.c: Remove file.
	* solib-pa64.h: Remove file.
	* solib-som.c: Remove file.
	* solib-som.h: Remove file.
	* somread.c: Remove file.
2015-03-13 20:24:22 +01:00
John Baldwin 25268153a1 Use kinfo_getvmmap on FreeBSD to enumerate memory regions.
Use kinfo_getvmmap from libutil on FreeBSD to enumerate memory
regions in a running process instead of /proc/<pid>/map.  FreeBSD systems
do not mount procfs by default, but kinfo_getvmmap uses a sysctl that
is always available.

Skip memory regions for devices as well as regions an application has
requested to not be dumped via the MAP_NOCORE flag to mmap or
MADV_NOCORE advice to madvise.

gdb/ChangeLog:

	* configure.ac: AC_CHECK_LIB(util, kinfo_getvmmap).
	* configure: Regenerate.
	* config.in: Regenerate.
	* fbsd-nat.c [!HAVE_KINFO_GETVMMAP] (fbsd_read_mapping): Don't
        define.
	(fbsd_find_memory_regions): Use kinfo_getvmmap to
	enumerate memory regions if present.
2015-03-13 14:08:15 -04:00
John Baldwin 773eacf5b0 Style fixes.
- Do not leave operators at end-of-line.
- Fix block indentation in if-else chain.

gdb/ChangeLog:

	* amd64fbsd-tdep.c (amd64fbsd_sigtramp_p): Style fixes.
	* i386fbsd-tdep.c: Fix style in various gdb_static_assert
	expressions.
	(i386fbsd_sigtramp_p): Likewise.
2015-03-13 14:01:38 -04:00
John Baldwin 01b6bdb03c Add myself as a write-after-approval GDB maintainer
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add John Baldwin.
2015-03-12 14:55:44 -04:00
Gary Benson 811a659a77 Allow "set sysroot" with no argument to restore sysroot to empty
This commit creates the "set/show sysroot" commands using
add_setshow_optional_filename_cmd to allow the sysroot to
be restored to empty after being set.

gdb/ChangeLog:

	* solib.c (_initialize_solib): Make "set/show sysroot" use
	add_setshow_optional_filename_cmd so it can be restored to
	empty after being set.
2015-03-12 11:44:16 +00:00
Sergio Durigan Junior 10304ef3e8 Create gdb/break-catch-syscall.c
This commits cleans up the gdb/breakpoint.c file and moves everything
that is related to the 'catch syscall' command to the new file
gdb/break-catch-syscall.c.  This is just code movement, and the only
new part is the adjustment needed on 'catching_syscall_number' to use
the new 'breakpoint_find_if' function insted of relying on the
ALL_BREAKPOINTS macro.

Tested by running the 'gdb.base/catch-syscall.exp' testcase.

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

	* Makefile.in (SFILES): New source break-catch-syscall.c.
	(COMMON_OBS): New object break-catch-syscall.o.
	* break-catch-syscall.c: New file.
	* breakpoint.c: Remove inclusion of "xml-syscall.h".
	(syscall_catchpoint_p): Move declaration to break-catch-syscall.c
	(struct syscall_catchpoint): Likewise.
	(dtor_catch_syscall): Likewise.
	(catch_syscall_inferior_data): Likewise.
	(struct catch_syscall_inferior_data): Likewise.
	(get_catch_syscall_inferior_data): Likewise.
	(catch_syscall_inferior_data_cleanup): Likewise.
	(insert_catch_syscall): Likewise.
	(remove_catch_syscall): Likewise.
	(breakpoint_hit_catch_syscall): Likewise.
	(print_it_catch_syscall): Likewise.
	(print_one_catch_syscall): Likewise.
	(print_mention_catch_syscall): Likewise.
	(print_recreate_catch_syscall): Likewise.
	(catch_syscall_breakpoint_ops): Likewise.
	(syscall_catchpoint_p): Likewise.
	(create_syscall_event_catchpoint): Likewise.
	(catch_syscall_split_args): Likewise.
	(catch_syscall_command_1): Likewise.
	(is_syscall_catchpoint_enabled): Likewise.
	(catch_syscall_enabled): Likewise.
	(catching_syscall_number): Likewise.
	(catch_syscall_completer): Likewise.
	(clear_syscall_counts): Likewise.
	(initialize_breakpoint_ops): Move initialization of syscall
	catchpoints to break-catch-syscall.c.
	(_initialize_breakpoint): Move code related to syscall catchpoints
	to break-catch-syscall.c.
2015-03-11 14:13:49 -04:00
Sergio Durigan Junior badd37cec8 Implement breakpoint_find_if
This commit implements the 'breakpoint_find_if' function, which allows
code external to gdb/breakpoint.c to iterate through the list of
'struct breakpoint *'.  This is needed in order to create the
'gdb/break-catch-syscall.c' file, because one of its functions
(catching_syscall_number) needs to do this iteration.

My first thought was to share the ALL_BREAKPOINTS* macros on
gdb/breakpoint.h, but they use a global variable local to
gdb/breakpoint.c, and I did not want to share that variable.  So, in
order to keep the minimal separation, I decided to implement this
way of iterating through the existing 'struct breakpoint *'.

This function was based on BFD's bfd_sections_find_if.  If the
user-provided function returns 0, the iteration proceeds.  Otherwise,
the iteration stops and the function returns the 'struct breakpoint *'
that is being processed.  This means that the return value of this
function can be either NULL or a pointer to a 'struct breakpoint'.

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

	* breakpoint.c (breakpoint_find_if): New function.
	* breakpoint.h (breakpoint_find_if): New prototype.
2015-03-11 14:13:49 -04:00
Gary Benson aa9e327f1e Implement vFile:fstat: in gdbserver
This commit implements the "vFile:fstat:" packet in gdbserver.

gdb/gdbserver/ChangeLog:

	* hostio.c (sys/types.h): New include.
	(sys/stat.h): Likewise.
	(common-remote-fileio.h): Likewise.
	(handle_fstat): New function.
	(handle_vFile): Handle vFile:fstat packets.
	* server.c (handle_query): Report vFile:fstat as supported.
2015-03-11 17:53:57 +00:00
Gary Benson 0a93529c56 Implement remote_bfd_iovec_stat
This commit adds a new packet "vFile:fstat:" to the remote protocol
that can be used by to retrieve information about files that have
been previously opened using vFile:open.  vFile:fstat: support is
added to GDB, and remote_bfd_iovec_stat is implemented using it.  If
vFile:fstat: is not supported by the remote GDB creates a dummy result
by zeroing the supplied stat structure and setting its st_size field
to INT_MAX.  This mimics GDB's previous behaviour, with the exception
that GDB did not previously zero the structure so all other fields
would have been returned unchanged, which is to say very likely
populated with random values from the stack.

gdb/ChangeLog:

	* remote-fileio.h (remote_fileio_to_host_stat): New declaration.
	* remote-fileio.c (remote_fileio_to_host_uint): New function.
	(remote_fileio_to_host_ulong): Likewise.
	(remote_fileio_to_host_mode): Likewise.
	(remote_fileio_to_host_time): Likewise.
	(remote_fileio_to_host_stat): Likewise.
	* remote.c (PACKET_vFile_fstat): New enum value.
	(remote_protocol_features): Register the "vFile:fstat" feature.
	(remote_hostio_fstat): New function.
	(remote_bfd_iovec_stat): Use the above.
	(_initialize_remote): Register new "set/show remote
	hostio-fstat-packet" command.
	* symfile.c (separate_debug_file_exists): Update comment.
	* NEWS: Announce new vFile:fstat packet.

gdb/doc/ChangeLog:

	* gdb.texinfo (Remote Configuration): Document the
	"set/show remote hostio-fstat-packet" command.
	(General Query Packets): Document the vFile:fstat
	qSupported features.
	(Host I/O Packets): Document the vFile:fstat packet.
2015-03-11 17:53:57 +00:00
Gary Benson 791c00567a Move remote_fileio_to_fio_stat to gdb/common
This commit moves remote_fileio_to_fio_stat and its supporting
functions into new files common/common-remote-fileio.[ch].

gdb/ChangeLog:

	* common/common-remote-fileio.h: New file.
	* common/common-remote-fileio.c: Likewise.
	* Makefile.in (SFILES): Add common/common-remote-fileio.c.
	(HFILES_NO_SRCDIR): Add common/common-remote-fileio.h.
	(COMMON_OBS): Add common-remote-fileio.o.
	(common-remote-fileio.o): New rule.
	* remote-fileio.h (common-remote-fileio.h): New include.
	* remote-fileio.c (gdb/fileio.h): Do not include.
	(remote_fileio_to_be): Moved to common-remote-fileio.h.
	(remote_fileio_to_fio_uint): Likewise.
	(remote_fileio_to_fio_time): Likewise.
	(remote_fileio_mode_to_target): Moved to common-remote-fileio.c.
	(remote_fileio_to_fio_mode): Likewise.
	(remote_fileio_to_fio_ulong): Likewise.
	(remote_fileio_to_fio_stat): Likewise.

gdb/gdbserver/ChangeLog:

	* configure.ac (AC_CHECK_MEMBERS): Add checks for
	struct stat.st_blocks and struct stat.st_blksize.
	* configure: Regenerate.
	* config.in: Likewise.
	* Makefile.in (SFILES): Add common/common-remote-fileio.c.
	(OBS): Add common-remote-fileio.o.
	(common-remote-fileio.o): New rule.
2015-03-11 17:53:57 +00:00
Andy Wingo 1390d0efa6 Fix typo in value-dynamic-type
gdb/ChangeLog:

	* guile/scm-value.c (gdbscm_value_dynamic_type): Fix typo in which
	we were checking the cached type, not the cached dynamic type.
2015-03-11 14:32:56 +01:00
Andy Wingo 84a4591a7b Fix memory corruption in Guile command interface
Re-registering a command will delete previous commands of the same name,
running the destroyer for the command object.  The Guile destroyer
incorrectly tried to xfree the name and other strings, which is invalid
as they are on the GC heap.

gdb/ChangeLog:

	* guile/scm-cmd.c (cmdscm_destroyer): Don't xfree the name and
	other strings, as these are on the GC'd heap, and will be
	collected along with the smob.
2015-03-11 14:25:29 +01:00
Andy Wingo 85642ba08c Add objfile-progspace to Guile interface
This commit adds an objfile-progspace accessor to the (gdb) Guile
module.

gdb/testsuite/ChangeLog:

	* gdb.guile/scm-objfile.exp: Add objfile-progspace test.

gdb/doc/ChangeLog:

	* guile.texi (Objfiles In Guile): Document objfile-progspace.

gdb/ChangeLog:

	* guile/scm-objfile.c (gdbscm_objfile_progspace): New function.
	(objfile_functions): Bind gdbscm_objfile_progspace to
	objfile-progspace.
	* guile/lib/gdb.scm: Add objfile-progspace to exports.
2015-03-11 14:20:06 +01:00
Andy Wingo 92fab5a617 [guile] Run finalizers from GDB thread
gdb/ChangeLog:

	* guile/guile.c (_initialize_guile): Disable automatic
	finalization, if Guile offers us that possibility.
	* guile/guile.c (call_initialize_gdb_module):
	* guile/scm-safe-call.c (gdbscm_with_catch): Arrange to run
	finalizers in appropriate places.
	* config.in (HAVE_GUILE_MANUAL_FINALIZATION): New definition.
	* configure.ac (AC_TRY_LIBGUILE): Add a check for
	scm_set_automatic_finalization_enabled.
	* configure: Regenerated.
2015-03-11 13:07:53 +01:00
Yao Qi e03f96456f Typo fix
Fix typo "inferiorr".

gdb/testsuite:

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

	* gdb.base/catch-syscall.exp: Fix typo in comments.
2015-03-11 11:50:12 +00:00
Yao Qi 5d0962b2e9 Skip catch-syscall.exp on HP-UX target
"catch syscall" doesn't work on HP-UX.

gdb/testsuite:

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

	* gdb.base/catch-syscall.exp: Skip it on HP-UX target.
2015-03-11 11:43:07 +00:00
Andreas Arnez f054145ed2 S390: Skip prologue using SAL information, if possible
Instead of analyzing the prologue and possibly coming to a wrong
conclusion, this change tries to skip the prologue with the use of
skip_prologue_using_sal.  Only if that fails, the prologue analyzer is
invoked as before.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_skip_prologue): Skip the prologue using
	SAL, if possible.
2015-03-11 11:11:45 +01:00
Andreas Arnez 183961935e S390: Defer PER info update until resume
For multi-threaded inferiors on S390 GNU/Linux targets, GDB tried to
update the PER info via ptrace() in a newly attached thread before
assuring that the thread is stopped.  Depending on the timing, this
could lead to a GDB internal error.  The patch defers the PER info
update until just before resuming the thread.

gdb/ChangeLog:

	* s390-linux-nat.c (struct arch_lwp_info): New.
	(s390_fix_watch_points): Rename to...
	(s390_prepare_to_resume): ...this.  Skip the PER info update
	unless the watch points have changed.
	(s390_refresh_per_info, s390_new_thread): New functions.
	(s390_insert_watchpoint): Call s390_refresh_per_info instead of
	s390_fix_watch_points.
	(s390_remove_watchpoint): Likewise.
	(_initialize_s390_nat): Reflect renaming of s390_fix_watch_points.
	Register s390_prepare_to_resume.
2015-03-11 11:11:44 +01:00
Pedro Alves b2df3cefb1 Delete gdb/testsuite/dg-extract-results.py
Unfortunately, the Python version of the dg-extract-results.sh script
doesn't produce stable-enough results for GDB.  The test messages
appear to end up alpha sorted (losing the original sequence) and also
sorting changes between runs for some reason.  That may be tolerable
for GCC, but for GDB, it often renders test results diffing between
different revisions unworkable.

Until that is fixed upstream, delete the script from the GDB tree.

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

	* dg-extract-results.py: Delete.
2015-03-09 17:47:18 +00:00
Pedro Alves ef878e5310 Make dg-extract-results.sh explicitly treat .{sum,log} files as text
This merges Sergio's fix from GCC:
  https://gcc.gnu.org/ml/gcc-patches/2014-12/msg01293.html

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

	Merge dg-extract-results.sh from GCC upstream (r218843).

	2014-12-17  Sergio Durigan Junior  <sergiodj@redhat.com>
		* dg-extract-results.sh: Use --text with grep to avoid issues with
		binary files.  Fall back to cat -v, if that doesn't work.
2015-03-09 17:47:17 +00:00
Pedro Alves 9a9df97001 gdbserver/tracepoint: Add 'struct sockaddr_un *' -> 'struct sockaddr *' cast
Fixes this in C++ mode:

  gdb/gdbserver/tracepoint.c: In function ‘void* gdb_agent_helper_thread(void*)’:
  gdb/gdbserver/tracepoint.c:7190:47: error: cannot convert ‘sockaddr_un*’ to ‘sockaddr*’ for argument ‘2’ to ‘int accept(int, sockaddr*, socklen_t*)’
	  fd = accept (listen_fd, &sockaddr, &tmp);

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

	* tracepoint.c (gdb_agent_helper_thread): Cast '&sockaddr' to
	'struct sockaddr' pointer in 'accept' call.
2015-03-09 11:29:57 +00:00
Pedro Alves 9eb1356e38 Revert union gdb_sockaddr_u
This reverts 366c75fc.

We don't actually need to access the object through
"struct sockaddr *", so we don't need the union:
   https://sourceware.org/ml/gdb-patches/2015-03/msg00213.html

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

	Revert:
	2015-03-07  Pedro Alves  <palves@redhat.com>
	* common/gdb_socket.h: New file.
	* ser-tcp.c: Include gdb_socket.h.  Don't include netinet/in.h nor
	sys/socket.h.
	(net_open): Use union gdb_sockaddr_u.

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

	Revert:
	2015-03-07  Pedro Alves  <palves@redhat.com>
	* gdbreplay.c: No longer include <netinet/in.h>, <sys/socket.h>,
	or <winsock2.h> here.  Instead include "gdb_socket.h".
	(remote_open): Use union gdb_sockaddr_u.
	* remote-utils.c: No longer include <netinet/in.h>, <sys/socket.h>
	or <winsock2.h> here.  Instead include "gdb_socket.h".
	(handle_accept_event, remote_prepare): Use union gdb_sockaddr_u.
	* tracepoint.c: Include "gdb_socket.h" instead of <sys/socket.h>
	or <sys/un.h>.
	(init_named_socket, gdb_agent_helper_thread): Use union
	gdb_sockaddr_u.
2015-03-09 11:27:05 +00:00
Pedro Alves aac331e484 Remove C-specific warnings from common warning set
Whoops, these are C specific, but I somehow missed the warnings before:

  cc1plus: warning: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
  cc1plus: warning: command line option ‘-Wdeclaration-after-statement’ is valid for C/ObjC but not for C++ [enabled by default]
  cc1plus: warning: command line option ‘-Wmissing-parameter-type’ is valid for C/ObjC but not for C++ [enabled by default]
  cc1plus: warning: command line option ‘-Wold-style-declaration’ is valid for C/ObjC but not for C++ [enabled by default]
  cc1plus: warning: command line option ‘-Wold-style-definition’ is valid for C/ObjC but not for C++ [enabled by default]

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

	* configure.ac (build_warnings): Move -Wmissing-prototypes
	-Wdeclaration-after-statement -Wmissing-parameter-type
	-Wold-style-declaration -Wold-style-definition to the C-specific
	set.
	* configure: Regenerate.

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

	* configure.ac (build_warnings): Move
	-Wdeclaration-after-statement to the C-specific set.
	* configure: Regenerate.
2015-03-07 18:00:15 +00:00
Pedro Alves 366c75fc91 Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations
Building gdbserver in C++ mode shows:

  gdb/gdbserver/tracepoint.c: In function ‘void* gdb_agent_helper_thread(void*)’:
  gdb/gdbserver/tracepoint.c:7190:47: error: cannot convert ‘sockaddr_un*’ to ‘sockaddr*’ for argument ‘2’ to ‘int accept(int, sockaddr*, socklen_t*)’
	  fd = accept (listen_fd, &sockaddr, &tmp);

A few places in the tree already have an explicit cast to struct
sockaddr *, but that's a strict aliasing violation.  Instead of
propagating invalid code, fix this by using a union instead.

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

	* common/gdb_socket.h: New file.
	* ser-tcp.c: Include gdb_socket.h.  Don't include netinet/in.h nor
	sys/socket.h.
	(net_open): Use union gdb_sockaddr_u.

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

	* gdbreplay.c: No longer include <netinet/in.h>, <sys/socket.h>,
	or <winsock2.h> here.  Instead include "gdb_socket.h".
	(remote_open): Use union gdb_sockaddr_u.
	* remote-utils.c: No longer include <netinet/in.h>, <sys/socket.h>
	or <winsock2.h> here.  Instead include "gdb_socket.h".
	(handle_accept_event, remote_prepare): Use union gdb_sockaddr_u.
	* tracepoint.c: Include "gdb_socket.h" instead of <sys/socket.h>
	or <sys/un.h>.
	(init_named_socket, gdb_agent_helper_thread): Use union
	gdb_sockaddr_u.
2015-03-07 17:30:46 +00:00
Pedro Alves 72df25b28d Make TRY/CATCH use real C++ try/catch in C++ mode
Although the current TRY/CATCH implementation works in C++ mode too,
it relies on setjmp/longjmp, and longjmp bypasses calling the
destructors of objects on the stack, which is obviously bad for C++.

This patch fixes this by makes TRY/CATCH use real try/catch in C++
mode behind the scenes.  The way this is done allows RAII and cleanups
to coexist while we phase out cleanups, instead of requiring a flag
day.

This patch is not strictly necessary until we require a C++ compiler
and start actually using RAII, though I'm all for baby steps, and it
shows my proposed way forward.  Putting it in now, allows for easier
experimentation and exposure of potential problems with real C++
exceptions.

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

	* common/common-exceptions.c [!__cplusplus] (enum catcher_state)
	(exceptions_state_mc_action_iter)
	(exceptions_state_mc_action_iter_1, exceptions_state_mc_catch):
	Don't define.
	[__cplusplus] (try_scope_depth): New global.
	[__cplusplus] (exception_try_scope_entry)
	(exception_try_scope_exit, gdb_exception_sliced_copy)
	(exception_rethrow): New functions.
	(throw_exception): In C++ mode, throw
	gdb_exception_RETURN_MASK_QUIT for RETURN_QUIT and
	gdb_exception_RETURN_MASK_ERROR for RETURN_ERROR.
	(throw_it): In C++ mode, use try_scope_depth.
	* common/common-exceptions.h [!__cplusplus]
	(exceptions_state_mc_action_iter)
	(exceptions_state_mc_action_iter_1, exceptions_state_mc_catch):
	Don't declare.
	[__cplusplus] (exception_try_scope_entry)
	(exception_try_scope_exit, exception_rethrow): Declare.
	[__cplusplus] (struct exception_try_scope): New struct.
	[__cplusplus] (TRY, CATCH, END_CATCH): Reimplement on top of real
	C++ exceptions.
	(struct gdb_exception_RETURN_MASK_ALL)
	(struct gdb_exception_RETURN_MASK_ERROR)
	(struct gdb_exception_RETURN_MASK_QUIT): New types.
2015-03-07 15:26:27 +00:00
Pedro Alves 284e6217cf kill volatile struct gdb_exception
After the previous patch, this is the last remaining use of a volatile
struct gdb_exception.  Kill it, as it's troublesome for C++: we can't
assign volatile <-> non-volatile without copy constructors /
assignment operators that do that, which I'd rather avoid.

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

	* main.c (handle_command_errors): Remove volatile qualifier from
	parameter.
2015-03-07 15:25:09 +00:00
Pedro Alves 6c63c96a22 more making TRY/CATCH callers look more like real C++ try/catch blocks
All these were caught by actually making TRY/CATCH use try/catch
behind the scenes, which then resulted in the build failing (on x86_64
Fedora 20) because there was code between the try and catch blocks.

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

	* breakpoint.c (save_breakpoints): Adjust to avoid code between
	TRY and CATCH.
	* gdbtypes.c (safe_parse_type): Remove empty line.
	(types_deeply_equal):
	* guile/scm-frame.c (gdbscm_frame_name):
	* linux-thread-db.c (find_new_threads_once):
	* python/py-breakpoint.c (bppy_get_commands):
	* record-btrace.c (record_btrace_insert_breakpoint)
	(record_btrace_remove_breakpoint, record_btrace_start_replaying)
	(record_btrace_start_replaying): Adjust to avoid code between TRY
	and CATCH.
2015-03-07 15:19:57 +00:00
Pedro Alves 492d29ea1c Split TRY_CATCH into TRY + CATCH
This patch splits the TRY_CATCH macro into three, so that we go from
this:

~~~
  volatile gdb_exception ex;

  TRY_CATCH (ex, RETURN_MASK_ERROR)
    {
    }
  if (ex.reason < 0)
    {
    }
~~~

to this:

~~~
  TRY
    {
    }
  CATCH (ex, RETURN_MASK_ERROR)
    {
    }
  END_CATCH
~~~

Thus, we'll be getting rid of the local volatile exception object, and
declaring the caught exception in the catch block.

This allows reimplementing TRY/CATCH in terms of C++ exceptions when
building in C++ mode, while still allowing to build GDB in C mode
(using setjmp/longjmp), as a transition step.

TBC, after this patch, is it _not_ valid to have code between the TRY
and the CATCH blocks, like:

  TRY
    {
    }

  // some code here.

  CATCH (ex, RETURN_MASK_ERROR)
    {
    }
  END_CATCH

Just like it isn't valid to do that with C++'s native try/catch.

By switching to creating the exception object inside the CATCH block
scope, we can get rid of all the explicitly allocated volatile
exception objects all over the tree, and map the CATCH block more
directly to C++'s catch blocks.

The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was
done with a script, rerun from scratch at every rebase, no manual
editing involved.  After the mechanical conversion, a few places
needed manual intervention, to fix preexisting cases where we were
using the exception object outside of the TRY_CATCH block, and cases
where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH
after this patch].  The result was folded into this patch so that GDB
still builds at each incremental step.

END_CATCH is necessary for two reasons:

First, because we name the exception object in the CATCH block, which
requires creating a scope, which in turn must be closed somewhere.
Declaring the exception variable in the initializer field of a for
block, like:

  #define CATCH(EXCEPTION, mask) \
    for (struct gdb_exception EXCEPTION; \
         exceptions_state_mc_catch (&EXCEPTION, MASK); \
	 EXCEPTION = exception_none)

would avoid needing END_CATCH, but alas, in C mode, we build with C90,
which doesn't allow mixed declarations and code.

Second, because when TRY/CATCH are wired to real C++ try/catch, as
long as we need to handle cleanup chains, even if there's no CATCH
block that wants to catch the exception, we need for stop at every
frame in the unwind chain and run cleanups, then rethrow.  That will
be done in END_CATCH.

After we require C++, we'll still need TRY/CATCH/END_CATCH until
cleanups are completely phased out -- TRY/CATCH in C++ mode will
save/restore the current cleanup chain, like in C mode, and END_CATCH
catches otherwise uncaugh exceptions, runs cleanups and rethrows, so
that C++ cleanups and exceptions can coexist.

IMO, this still makes the TRY/CATCH code look a bit more like a
newcomer would expect, so IMO worth it even if we weren't considering
C++.

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

	* common/common-exceptions.c (struct catcher) <exception>: No
	longer a pointer to volatile exception.  Now an exception value.
	<mask>: Delete field.
	(exceptions_state_mc_init): Remove all parameters.  Adjust.
	(exceptions_state_mc): No longer pop the catcher here.
	(exceptions_state_mc_catch): New function.
	(throw_exception): Adjust.
	* common/common-exceptions.h (exceptions_state_mc_init): Remove
	all parameters.
	(exceptions_state_mc_catch): Declare.
	(TRY_CATCH): Rename to ...
	(TRY): ... this.  Remove EXCEPTION and MASK parameters.
	(CATCH, END_CATCH): New.
	All callers adjusted.

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

	Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH
	instead.
2015-03-07 15:14:14 +00:00
Tom Tromey ece957c859 quit_force: Replace TRY_CATCH wrapper macros
More preparation for running the TRY_CATCH->TRY/CATCH conversion
script.

gdb/ChangeLog:
2015-03-07  Tom Tromey  <tromey@redhat.com>

	* top.c (quit_force): Inline and delete DO_TRY, DO_PRINT_EX.
2015-03-07 14:56:47 +00:00
Pedro Alves 7556d4a4f6 Normalize TRY_CATCH exception handling block
This normalizes some exception catch blocks that check for ex.reason
to look like this:

~~~
  volatile gdb_exception ex;

  TRY_CATCH (ex, RETURN_MASK_ALL)
    {
      ...
    }
  if (ex.reason < 0)
    {
      ...
    }
~~~

This is a preparation step for running a script that converts all
TRY_CATCH uses to look like this instead:

~~~
  TRY
    {
      ...
    }
  CATCH (ex, RETURN_MASK_ALL)
    {
      ...
    }
  END_CATCH
~~~

The motivation for that change is being able to reimplent TRY/CATCH in
terms of C++ try/catch.

This commit makes it so that:

 - no condition other than ex.reason < 0 is checked in the if
   predicate

 - there's no "else" block to check whether no exception was caught

 - there's no code between the TRY_CATCH (TRY) block and the
   'if (ex.reason < 0)' block (CATCH).

 - the exception object is no longer referred to outside the if/catch
   block.  Note the local volatile exception objects that are
   currently defined inside functions that use TRY_CATCH will
   disappear.  In cases it's more convenient to still refer to the
   exception outside the catch block, a new non-volatile local is
   added and copy to that object is made within the catch block.

The following patches should make this all clearer.

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

	* amd64-tdep.c (amd64_frame_cache, amd64_sigtramp_frame_cache)
	(amd64_epilogue_frame_cache): Normal exception handling code.
	* break-catch-throw.c (check_status_exception_catchpoint)
	(re_set_exception_catchpoint): Ditto.
	* cli/cli-interp.c (safe_execute_command):
	* cli/cli-script.c (script_from_file): Ditto.
	* compile/compile-c-symbols.c (generate_c_for_for_one_variable):
	Ditto.
	* compile/compile-object-run.c (compile_object_run): Ditto.
	* cp-abi.c (baseclass_offset): Ditto.
	* cp-valprint.c (cp_print_value): Ditto.
	* exceptions.c (catch_exceptions_with_msg):
	* frame-unwind.c (frame_unwind_try_unwinder): Ditto.
	* frame.c (get_frame_address_in_block_if_available): Ditto.
	* i386-tdep.c (i386_frame_cache, i386_epilogue_frame_cache)
	(i386_sigtramp_frame_cache): Ditto.
	* infcmd.c (post_create_inferior): Ditto.
	* linespec.c (parse_linespec, find_linespec_symbols):
	* p-valprint.c (pascal_object_print_value): Ditto.
	* parse.c (parse_expression_for_completion): Ditto.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Ditto.
	* remote.c (remote_get_noisy_reply): Ditto.
	* s390-linux-tdep.c (s390_frame_unwind_cache): Ditto.
	* solib-svr4.c (solib_svr4_r_map): Ditto.
2015-03-07 14:56:43 +00:00
Pedro Alves f873665f44 Fix mail address format of a couple recent ChangeLog entries 2015-03-07 14:52:22 +00:00
Yao Qi 60a191edda Use show_debug_regs as a boolean
I happen to see that show_debug_regs is used as an arithmetic type,
but it should be a boolean,

  if (show_debug_regs > 1)

On the other hand, GDB RSP only allows setting it to either 0 or 1,
so it makes no sense to check whether it is greater than 1.  This
patch fixes it.

gdb/gdbserver:

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

	* linux-aarch64-low.c (aarch64_insert_point): Use
	show_debug_regs as a boolean.
	(aarch64_remove_point): Likewise.
2015-03-06 14:14:27 +00:00
Gary Benson 61012eef84 New common function "startswith"
This commit introduces a new inline common function "startswith"
which takes two string arguments and returns nonzero if the first
string starts with the second.  It also updates the 295 places
where this logic was written out longhand to use the new function.

gdb/ChangeLog:

	* common/common-utils.h (startswith): New inline function.
	All places where this logic was used updated to use the above.
2015-03-06 09:42:06 +00:00
Pedro Alves 9494d2199f gdb.base/bp-permanent.exp: Tighten regex
Trying to fix a permanent breakpoints bug, I broke "next" over a
regular breakpoint.  "next" would immediately hit the breakpoint the
program was already stopped at.  But, the "next over setup" test
failed to notice this and still issued a pass.  That's because the
regex matches "testsuite" in:

  Breakpoint 2 at 0x400687: file src/gdb/testsuite/gdb.base/bp-permanent.c, line 46.

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

	* gdb.base/bp-permanent.exp: Tighten "next over setup" regex.
2015-03-05 23:40:39 +00:00
Pedro Alves 68901c4d43 PR gdb/18002: Fix reinsert of a permanent breakpoints
When we find out that a breakpoint is set on top of a program
breakpoint, we mark it as "permanent".  E.g.,:

...
  if (bp_loc_is_permanent (loc))
    {
      loc->inserted = 1;
      loc->permanent = 1;
    }
...

Note we didn't fill in the breakpoint's shadow (shadow_len remains 0).

In case the target claims support for evaluating breakpoint
conditions, GDB sometimes reinserts breakpoints that are already
inserted (to update the conditions on the target side).  Since GDB
doesn't know whether the target supports evaluating conditions _of_
software breakpoints (vs hardware breakpoints, etc.) until it actually
tries it, if the target doesn't actually support z0 breakpoints, GDB
ends up reinserting a GDB-managed software/memory breakpoint
(mem-break.c).

And that is the case that is buggy: breakpoints that are marked
inserted contribute their shadows (if any) to the memory returned by
target_read_memory, to mask out breakpoints.  Permanent breakpoints
are always marked as inserted.  So if the permanent breakpoint doesn't
have a shadow yet in its shadow buffer, but we set shadow_len before
calling target_read_memory, then the still clear shadow_contents
buffer will be used by the breakpoint masking code...  And then from
there on, the permanent breakpoint has a broken shadow buffer, and
thus any memory read out of that address will read bogus code, and
many random bad things fall out from that.

The fix is just to set shadow_len at the same time shadow_contents is
set, not one before and another after...

Fixes all gdb.base/bp-permanent.exp FAILs on PPC64 GNU/Linux gdbserver
and probably any other gdbserver port that doesn't do z0 breakpoints.

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

	PR gdb/18002
	* mem-break.c (default_memory_insert_breakpoint): Set shadow_len
	after reading the breakpoint's shadow memory.
2015-03-05 23:39:45 +00:00
Mark Kettenis 2dcb2b1a45 Enable rthreads support on OpenBSD/hppa
gdb/
2015-03-05  Mark Kettenis  <kettenis@gnu.org>

        * hppabsd-nat.c: Remove file.
        * hppaobsd-nat.c: New file.
        * Makefile.in (ALLDEPFILES): Remove hppabsd-nat.c.  Add
        hppaobsd-nat.c.
        * config/pa/obsd.mh (NATDEPFILES): Replace hppabsd-nat.o with
        hppaobsd-nat.o.
2015-03-05 17:21:03 +01:00
Pedro Alves f5771b1d96 Fix Windows/SPU/NTO/Lynx gdbserver builds
I forgot to update these target_ops instances when I added these new
hooks.

I confirmed mingw32-w64 builds again at least.

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

	* lynx-low.c (lynx_target_ops): Install NULL hooks for
	stopped_by_sw_breakpoint, supports_stopped_by_sw_breakpoint,
	stopped_by_hw_breakpoint, supports_stopped_by_hw_breakpoint.
	* nto-low.c (nto_target_ops): Likewise.
	* spu-low.c (spu_target_ops): Likewise.
	* win32-low.c (win32_target_ops): Likewise.
2015-03-05 10:24:58 +00:00
Simon Marchi a8d9763abd Accept all-stop alternative in mi_expect_interrupt
When interrupting a thread in non-stop vs all-stop, the signal given in
the MI *stopped event is not the same. Currently, mi_expect_interrupt only
accepts the case for non-stop, so this adds the alternative for all-stop.

gdb/testsuite/ChangeLog:

	* lib/mi-support.exp (mi_expect_interrupt): Accept
	alternative event for when in all-stop mode.
2015-03-04 17:56:58 -05:00
Pedro Alves 527a273ac1 garbage collect target_decr_pc_after_break
record-btrace was the only target making use of this, and it no longer
uses it.

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

	* target.h (struct target_ops) <to_decr_pc_after_break>: Delete.
	(target_decr_pc_after_break): Delete declaration.
	* target.c (default_target_decr_pc_after_break)
	(target_decr_pc_after_break): Delete.
	* linux-nat.c (check_stopped_by_breakpoint, linux_nat_wait_1): Use
	gdbarch_decr_pc_after_break instead of target_decr_pc_after_break.
	* linux-thread-db.c (check_event): Likewise.
	* infrun.c (adjust_pc_after_break): Likewise.
	* darwin-nat.c (cancel_breakpoint): Likewise.
	* aix-thread.c (aix_thread_wait): Likewise.
	* target-delegates.c: Regenerate.
2015-03-04 20:41:17 +00:00
Pedro Alves 3e572f7104 gdbserver/Linux: Use TRAP_BRKPT/TRAP_HWBPT
This patch adjusts gdbserver's Linux backend to tell gdbserver core
(and ultimately GDB) whether a trap was caused by a breakpoint.

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

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

        * linux-low.c (check_stopped_by_breakpoint) [USE_SIGTRAP_SIGINFO]:
	Decide whether a breakpoint triggered based on the SIGTRAP's
	siginfo.si_code.
        (thread_still_has_status_pending_p) [USE_SIGTRAP_SIGINFO]: Don't check whether a
        breakpoint is inserted if relying on SIGTRAP's siginfo.si_code.
	(linux_low_filter_event): Check for breakpoints before checking
	watchpoints.
	(linux_wait_1): Don't re-increment the PC if relying on SIGTRAP's
	siginfo.si_code.
        (linux_stopped_by_sw_breakpoint)
        (linux_supports_stopped_by_sw_breakpoint)
        (linux_stopped_by_hw_breakpoint)
        (linux_supports_stopped_by_hw_breakpoint): New functions.
        (linux_target_ops): Install new target methods.
2015-03-04 20:41:17 +00:00
Pedro Alves 1ec68e26c9 gdbserver: Support the "swbreak"/"hwbreak" stop reasons
This patch teaches the core of gdbserver about the new "swbreak" and
"hwbreak" stop reasons, and adds the necessary hooks a backend needs
to implement to support the feature.

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

	* remote-utils.c (prepare_resume_reply): Report swbreak/hbreak.
	* server.c (swbreak_feature, hwbreak_feature): New globals.
	(handle_query) <qSupported>: Handle "swbreak+" and "hwbreak+".
	(captured_main): Clear swbreak_feature and hwbreak_feature.
	* server.h (swbreak_feature, hwbreak_feature): Declare.
	* target.h (struct target_ops) <stopped_by_sw_breakpoint,
	supports_stopped_by_sw_breakpoint, stopped_by_hw_breakpoint,
	supports_stopped_by_hw_breakpoint>: New fields.
	(target_supports_stopped_by_sw_breakpoint)
	(target_stopped_by_sw_breakpoint)
	(target_supports_stopped_by_hw_breakpoint)
	(target_stopped_by_hw_breakpoint): Declare.
2015-03-04 20:41:16 +00:00
Pedro Alves faf09f0119 Linux native: Use TRAP_BRKPT/TRAP_HWBPT
This patch adjusts the native Linux target backend to tell the core
whether a trap was caused by a breakpoint.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 - The kernel doesn't schedule thread A yet.

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

 - Kernel finally schedules thread A.

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

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

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

Other problems with moribund locations are:

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

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

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

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

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

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

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

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

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

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

Tested on x86-64 Fedora 20.

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

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

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

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

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

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

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

       inferior_ptid = ptid_build (child_pid, child_pid, 0);

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

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

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

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

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

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

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

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

gdb/ChangeLog:

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

gdb/testsuite/ChangeLog:

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

gdb/testsuite/ChangeLog:

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

gdb/ChangeLog:

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

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

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

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

the logs there show:

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

Tested on x86_64 Fedora 20.

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

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

gdb/ChangeLog:

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

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

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

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

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

The record-btrace target can hit an assertion here:

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

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

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

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

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

Tested on x86-64 Fedora 20, -m32.

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

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

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

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

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

Thanks to Jan Kratochvil for reporting the issue.

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

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

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

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

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

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

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

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

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

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

Tested on x86_64 Fedora 20.

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

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

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

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

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

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

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

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

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

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

gdb/ChangeLog:

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

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

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

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

On AiX:

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

You can reproduce the same problem by trying to compile:

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

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

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

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

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

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

gdb/ChangeLog:

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

gdb/testsuite/ChangeLog:

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

gdb/gdbserver/ChangeLog:

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

gdb/ChangeLog:

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

gdb/ChangeLog:

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

gdb/doc/ChangeLog:

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

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

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

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

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

gdb/ChangeLog:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fix this by adding a helper function.

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

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

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

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

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

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

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

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

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

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

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

  src/gdb/target.h:753:10: error: use of enum ‘exec_direction_kind’ without previous declaration

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

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

	* target.h: Include "infrun.h".
2015-02-27 17:28:49 +00:00
Pedro Alves 749bab0110 proc-service, extern "C"
libthread_db.so calls symbols in the client (GDB), through the
proc-service interface.  These routines must have extern "C" linkage
so their symbol names are not mangled when GDB is built as a C++
program.  On the GDBserver side, we were missing fallback declarations for
all these symbols.

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

	* gdb_proc_service.h: Wrap with EXTERN_C_PUSH/EXTERN_C_POP.

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

	* gdb_proc_service.h: Wrap with EXTERN_C_PUSH/EXTERN_C_POP.
	[!HAVE_PROC_SERVICE_H] (struct ps_prochandle): Forward declare.
	[!HAVE_PROC_SERVICE_H] (ps_pdread, ps_pdwrite, ps_ptread)
	ps_ptwrite, ps_lgetregs, ps_lsetregs, ps_lgetfpregs)
	(ps_lsetfpregs, ps_getpid)
	(ps_get_thread_area, ps_pglobal_lookup, ps_pstop, ps_pcontinue)
	(ps_lstop, ps_lcontinue, ps_lgetxregsize, ps_lgetxregs)
	(ps_lsetxregs, ps_plog): Declare.
2015-02-27 17:28:11 +00:00
Pedro Alves 3c14e5a39b Make functions and variables exported by the IPA be extern "C"
Functions and variables that are exported by the IPA DSO (that
GDBserver needs to look up) should have "C" mangling, thus be declared
with extern "C".

Function and variable declarations need the extern "C" marker, but
variable definitions can't be marked extern, so the patch splits
IP_AGENT_EXPORT into three.

Building in C++ mode revealed that a few variables were missing
IP_AGENT_EXPORT, thus the IPA has been broken when stripped, even in C
mode...  So this ends being a bug fix as well.

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

	* common/agent.h (IPA_SYM_EXPORTED_NAME): New.
	(IPA_SYM): Use it.
	* common/common-defs.h (EXTERN_C_PUSH, EXTERN_C_POP): New macros.

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

	* linux-amd64-ipa.c (gdb_agent_get_raw_reg): Use
	IP_AGENT_EXPORT_FUNC.
	* linux-i386-ipa.c (gdb_agent_get_raw_reg): Use
	IP_AGENT_EXPORT_FUNC.
	* tracepoint.c (ATTR_USED, ATTR_NOINLINE, ATTR_CONSTRUCTOR)
	(IP_AGENT_EXPORT): Delete.
	(gdb_tp_heap_buffer, gdb_jump_pad_buffer, gdb_jump_pad_buffer_end)
	(gdb_trampoline_buffer, gdb_trampoline_buffer_end)
	(gdb_trampoline_buffer_error, collecting, gdb_collect)
	(stop_tracing, flush_trace_buffer, about_to_request_buffer_space)
	(trace_buffer_is_full, stopping_tracepoint, expr_eval_result)
	(error_tracepoint, tracepoints, tracing, trace_buffer_ctrl)
	(trace_buffer_ctrl_curr, trace_buffer_lo, trace_buffer_hi)
	(traceframe_read_count, traceframe_write_count)
	(traceframes_created, trace_state_variables, get_raw_reg)
	(get_trace_state_variable_value, set_trace_state_variable_value)
	(ust_loaded, helper_thread_id, cmd_buf): Use
	IPA_SYM_EXPORTED_NAME.
	(stop_tracing, flush_trace_buffer): Use IP_AGENT_EXPORT_FUNC.
	(tracepoints) Use IP_AGENT_EXPORT_VAR.
	(stopping_tracepoint, trace_buffer_is_full, expr_eval_result): Use
	IP_AGENT_EXPORT_VAR and wrap in EXTERN_C_PUSH/EXTERN_C_POP.
	(last_tracepoint): Move into !IN_PROCESS_AGENT block.
	(error_tracepoint): Use IP_AGENT_EXPORT_VAR and wrap in
	EXTERN_C_PUSH/EXTERN_C_POP.
	(trace_state_variables): Use IP_AGENT_EXPORT_VAR.
	(trace_buffer_lo, trace_buffer_hi): Use IP_AGENT_EXPORT_VAR and
	wrap in EXTERN_C_PUSH/EXTERN_C_POP.
	(trace_buffer_ctrl, trace_buffer_ctrl_curr)
	(traceframe_write_count, traceframe_read_count)
	(traceframes_created, tracing): Use IP_AGENT_EXPORT_VAR.
	(about_to_request_buffer_space, get_trace_state_variable_value)
	(set_trace_state_variable_value): Use IP_AGENT_EXPORT_FUNC.
	(collecting): Use IP_AGENT_EXPORT_VAR and wrap in
	EXTERN_C_PUSH/EXTERN_C_POP.
	(gdb_collect): Use IP_AGENT_EXPORT_FUNC.
	(ust_loaded, cmd_buf): Use IP_AGENT_EXPORT_VAR.
	(helper_thread_id, gdb_agent_capability): Use IP_AGENT_EXPORT_VAR
	and wrap in EXTERN_C_PUSH/EXTERN_C_POP.
	(gdb_tp_heap_buffer, gdb_jump_pad_buffer, gdb_jump_pad_buffer_end)
	(gdb_trampoline_buffer, gdb_trampoline_buffer_end)
	(gdb_trampoline_buffer_error): Use IP_AGENT_EXPORT_VAR.
	* tracepoint.h (ATTR_USED, ATTR_NOINLINE, EXPORTED_SYMBOL):
	Define.
	(IP_AGENT_EXPORT_FUNC, IP_AGENT_EXPORT_VAR)
	(IP_AGENT_EXPORT_VAR_DECL): Define.
	(tracing): Declare.
	(gdb_agent_get_raw_reg): Declare.
2015-02-27 17:27:29 +00:00
Pedro Alves 56000a9801 Add extern "C" to declarations of C symbols
These symbols are defined in C code, so in C++ mode we need to use
extern "C" to declare them.  As extern "C" can't be used inside a
function's scope, we move the declarations to the global scope at the
same time.

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

	* cli-out.c (_rl_erase_entire_line): Move declaration out of
	cli_mld_erase_entire_line, and make it extern "C".
	* common/common-defs.h (EXTERN_C): New.
	* completer.c (_rl_completion_prefix_display_length)
	(_rl_print_completions_horizontally, QSFUNC): Move declarations
	out of gdb_display_match_list_1.
	(_rl_qsort_string_compare): Move declaration out of
	gdb_display_match_list_1, and make it extern "C".
	* defs.h (re_comp): Use EXTERN_C.
	* maint.c (_mcleanup): Move declaration out of mcleanup_wrapper,
	and make it extern "C".
	(monstartup): Move declaration out of maintenance_set_profile_cmd,
	and make it extern "C".
	(main): Move declaration out of maintenance_set_profile_cmd.
	* nat/linux-ptrace.c (linux_ptrace_attach_fail_reason_string): Use
	EXTERN_C.
2015-02-27 17:26:16 +00:00
Pedro Alves bcabf4207e Make array object extern
Compiling python.c in C++ mode, we get:

  ...src/gdb/python/python.c: At global scope:
  ...src/gdb/python/python.c:106:31: error: storage size of ‘GdbMethods’ isn’t known
   static PyMethodDef GdbMethods[];
				 ^

Fix it by making the affected array objects extern.

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

	* python/python.c (GdbMethods): Rename to ...
	(python_GdbMethods): ... this and make extern.
	(GdbModuleDef): Rename to ...
	(python_GdbModuleDef): ... this and make extern.
2015-02-27 17:25:45 +00:00
Pedro Alves 928dbe0756 record-btrace.c: Remove redefinitions
The set_record_btrace_cmdlist and show_record_btrace_cmdlist objects
are declared twice in the file, seemingly a simply copy/paste
oversight.  In C, the first time counts as forward declaration, but in
C++, they are all definitions.  That results in:

 src/gdb/record-btrace.c:80:33: error: redefinition of ‘cmd_list_element* set_record_btrace_cmdlist’
 src/gdb/record-btrace.c:61:33: error: ‘cmd_list_element* set_record_btrace_cmdlist’ previously declared here
 src/gdb/record-btrace.c:81:33: error: redefinition of ‘cmd_list_element* show_record_btrace_cmdlist’
 src/gdb/record-btrace.c:62:33: error: ‘cmd_list_element* show_record_btrace_cmdlist’ previously declared here

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

	* record-btrace.c (set_record_btrace_cmdlist)
	(show_record_btrace_cmdlist): Remove redefinitions.
 ---

 gdb/record-btrace.c |    4 ----
 1 file changed, 4 deletions(-)
2015-02-27 17:25:23 +00:00
Tom Tromey 52059ffd69 Fix struct, union, and enum nesting in C++
In C, an enum or structure defined inside other structure has global
scope just like it had been defined outside the struct in the first
place.  However, in C++, such a nested structure is given a name that
is nested inside the structure.  This patch moves such affected
structures/enums out to global scope, so that code using them works
the same in C++ as it works today in C.

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

	* dwarf2-frame.c (enum cfa_how_kind, struct
	dwarf2_frame_state_reg_info): Move out of struct
	dwarf2_frame_state.
	* dwarf2read.c (struct tu_stats): Move out of struct
	dwarf2_per_objfile.
	(struct file_entry): Move out of struct line_header.
	(struct nextfield, struct nextfnfield, struct fnfieldlist, struct
	typedef_field_list): Move out of struct field_info.
	* gdbtypes.h (enum dynamic_prop_kind, union dynamic_prop_data):
	Move out of struct dynamic_prop.
	(union type_owner, union field_location, struct field, struct
	range_bounds, union type_specific): Move out of struct main_type.
	(struct fn_fieldlist, struct fn_field, struct typedef_field)
	(VOFFSET_STATIC): Move out of struct cplus_struct_type.
	(struct call_site_target, union call_site_parameter_u, struct
	call_site_parameter): Move out of struct call_site.
	* m32c-tdep.c (enum m32c_prologue_kind): Move out of struct
	m32c_prologue.
	(enum srcdest_kind): Move out of struct srcdest.
	* main.c (enum cmdarg_kind): Move out of struct cmdarg.
	* prologue-value.h (enum prologue_value_kind): Move out of struct
	prologue_value.
	* s390-linux-tdep.c (enum s390_abi_kind): Move out of struct
	gdbarch_tdep.
	* stabsread.c (struct nextfield, struct next_fnfieldlist): Move
	out of struct field_info.
	* symfile.h (struct other_sections): Move out of struct
	section_addr_info.
	* symtab.c (struct symbol_cache_slot): Move out struct
	block_symbol_cache.
	* target-descriptions.c (enum tdesc_type_kind): Move out of
	typedef struct tdesc_type.
	* tui/tui-data.h (enum tui_line_or_address_kind): Move out of
	struct tui_line_or_address.
	* value.c (enum internalvar_kind, union internalvar_data): Move
	out of struct internalvar.
	* xtensa-tdep.h (struct ctype_cache): Move out of struct
	gdbarch_tdep.
2015-02-27 17:19:15 +00:00
Pedro Alves fe978cb071 C++ keyword cleanliness, mostly auto-generated
This patch renames symbols that happen to have names which are
reserved keywords in C++.

Most of this was generated with Tromey's cxx-conversion.el script.
Some places where later hand massaged a bit, to fix formatting, etc.
And this was rebased several times meanwhile, along with re-running
the script, so re-running the script from scratch probably does not
result in the exact same output.  I don't think that matters anyway.

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

	Rename symbols whose names are reserved C++ keywords throughout.

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

	Rename symbols whose names are reserved C++ keywords throughout.
2015-02-27 16:33:07 +00:00
Pedro Alves 3bc3d82a00 Add --enable-build-with-cxx configure switch
This new option, disabled by default for now, allows specifying
whether to build GDB, GDBserver, and friends with a C++ (98/03)
compiler.

The name of the switch should be familiar to those who followed GCC's
own C++ conversion process.

. Adding -fpermissive to COMPILER in C++ mode (see the new
build-with-cxx.m4 file) makes errors like these be warnings instead:

  gdb/infrun.c:6597:1: error:   initializing argument 1 of ‘void sig_print_info(gdb_signal)’ [-fpermissive]
   sig_print_info (enum gdb_signal oursig)
   ^
  gdb/infrun.c: In function ‘void do_restore_infcall_suspend_state_cleanup(void*)’:
  gdb/infrun.c:7164:39: error: invalid conversion from ‘void*’ to ‘infcall_suspend_state*’ [-fpermissive]
     restore_infcall_suspend_state (state);
				 ^

so that the compiler carries on compiling the file.  -Werror still
catches the warnings, so nothing is lost, only our lifes are made
easier by concentrating on getting other more important things out of
the way first.

There's no way to quiet those warnings.  Until they're all fixed, when
building in C++ mode, -Werror is disabled by default.

. Adding -Wno-narrowing suppresses thousands of instances of this warning:

  gdb/arm-linux-tdep.c:439:1: error: narrowing conversion of ‘-1’ from ‘int’ to ‘ULONGEST {aka long unsigned int}’ inside { } is ill-formed in C++11 [-Werror=narrowing]
  gdb/arm-linux-tdep.c:439:1: error: narrowing conversion of ‘-1l’ from ‘LONGEST {aka long int}’ to ‘ULONGEST {aka long unsigned int}’ inside { } is ill-formed in C++11 [-Werror=narrowing]
  gdb/arm-linux-tdep.c:450:1: error: narrowing conversion of ‘-1’ from ‘int’ to ‘ULONGEST {aka long unsigned int}’ inside { } is ill-formed in C++11 [-Werror=narrowing]

We can defer handling those until we target C++11.


. Adding -Wno-sign-compare suppresses thousands of instances of this warning:

  gdb/linux-record.c:1763:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
	 if (tmpulongest == tdep->fcntl_F_GETLK64)
				  ^


. Adding -Wno-write-strings suppresses thousands of instances of this warning:

  gdb/mi/mi-cmd-var.c: In function ‘void mi_cmd_var_show_attributes(char*, char**, int)’:
  gdb/mi/mi-cmd-var.c:514:12: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
       attstr = "editable";
	      ^
  gdb/mi/mi-cmd-var.c:516:12: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
       attstr = "noneditable";
	      ^

For now, it's best to hide these warnings from view until we're
'-fpermissive'-clean, and can thus start building with -Werror.
The C compiler has always managed to build working GDBs with these
issues in the code, so a C++ compiler should too.

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

	* Makefile.in (COMPILER): New, get it from autoconf.
	(COMPILE.pre, CC_LD): Use COMPILER.
	(CXX): Get from autoconf instead.
	(CXX_FOR_TARGET): Default to g++ instead of gcc.
	* acinclude.m4: Include build-with-cxx.m4.
	* build-with-cxx.m4: New file.
	* configure.ac: Call AC_PROG_CXX and GDB_AC_BUILD_WITH_CXX.
	Disable -Werror by default if building in C++ mode.
	(build_warnings): Add -Wno-sign-compare, -Wno-write-strings and
	-Wno-narrowing in C++ mode.  Only enable -Wpointer-sign in C mode.
	Run supported-warning-flags tests with the C++ compiler.
	Save/restore CXXFLAGS too.
	* configure: Regenerate.

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

	* Makefile.in (COMPILER): New, get it from autoconf.
	(CXX): Get from autoconf instead.
	(COMPILE.pre): Use COMPILER.
	(CC-LD): Rename to ...
	(CC_LD): ... this.  Use COMPILER.
	(gdbserver$(EXEEXT), gdbreplay$(EXEEXT), $(IPA_LIB)): Adjust.
	(CXX_FOR_TARGET): Default to g++ instead of gcc.
	* acinclude.m4: Include build-with-cxx.m4.
	* configure.ac: Call AC_PROG_CXX and GDB_AC_BUILD_WITH_CXX.
	Disable -Werror by default if building in C++ mode.
	(build_warnings): Add -Wno-sign-compare, -Wno-write-strings and
	-Wno-narrowing in C++ mode. Run supported-warning-flags tests with
	the C++ compiler.  Save/restore CXXFLAGS too.
	* configure: Regenerate.
2015-02-27 16:24:02 +00:00
Pedro Alves 07697489f4 Create libiberty.m4, have GDB and GDBserver use it
Converting GDB to be a C++ program, I stumbled on 'basename' issues,
like:

 src/gdb/../include/ansidecl.h:169:64: error: new declaration ‘char* basename(const char*)’
 /usr/include/string.h:597:26: error: ambiguates old declaration ‘const char* basename(const char*)’

which I believe led to this bit in gold's configure.ac:

 dnl We have to check these in C, not C++, because autoconf generates
 dnl tests which have no type information, and current glibc provides
 dnl multiple declarations of functions like basename when compiling
 dnl with C++.
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp])

These checks IIUC intend to generate all the HAVE_DECL_FOO symbols
that libiberty.h and ansidecl.h check.

GDB is missing these checks currently, which results in the conflict
shown above.

This adds an m4 file that both GDB and GDBserver's configury use to
pull in the autoconf checks that libiberty clients needs done in order
to use these libiberty.h/ansidecl.h.

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

	* libiberty.m4: New file.
	* acinclude.m4: Include libiberty.m4.
	* configure.ac: Call libiberty_INIT.
	* config.in, configure: Regenerate.

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

	* acinclude.m4: Include libiberty.m4.
	* configure.ac: Call libiberty_INIT.
	* config.in, configure: Regenerate.
2015-02-27 15:52:02 +00:00
Pedro Alves 6f98576f29 Add "../lib/unbuffer_output.c" and use it in gdb.base/interrupt.c
In some scenarios, GDB or GDBserver can be spawned with input _not_
connected to a tty, and then tests that rely on stdio fail with
timeouts, because the inferior's stdout and stderr streams end up
fully buffered.

See discussion here:
  https://sourceware.org/ml/gdb-patches/2015-02/msg00809.html

We have a hack in place that works around this for Windows testing,
that forces every test program to link with an .o file that does
(lib/set_unbuffered_mode.c):

 static int __gdb_set_unbuffered_output (void) __attribute__ ((constructor));
 static int
 __gdb_set_unbuffered_output (void)
 {
   setvbuf (stdout, NULL, _IONBF, BUFSIZ);
   setvbuf (stderr, NULL, _IONBF, BUFSIZ);
 }

That's a bit hacky; it ends up done for _all_ tests.

This patch adds a way to do this unbuffering explicitly from the test
code itself, so it is done only when necessary, and for all
targets/hosts.  For starters, it adjusts gdb.base/interrupt.c to use
it.

Tested on x86_64 Fedora 20, native, and against a remote gdbserver
board file that connects to the target with ssh, with and without -t
(create pty).

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

	* lib/unbuffer_output.c: New file.
	* gdb.base/interrupt.c: Include "../lib/unbuffer_output.c".
	(main): Call gdb_unbuffer_output.
2015-02-27 13:54:22 +00:00
Yao Qi eba5ab56cf Don't skip catch-syscall.exp on hppa*-hp-hpux* target
As far as I know, "catch syscall" is supported on hppa*-hp-hpux*, but
the test catch-syscall.exp is skipped on this target by mistake.  This
patch is to fix it.  However, I don't have a hpux machine to test.

gdb/testsuite:

2015-02-27  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/catch-syscall.exp: Don't skip it on hppa*-hp-hpux*
	target.
2015-02-27 13:45:06 +00:00
Andreas Arnez 60abeae4f2 S390: Fix compiler invocation with "compile" command
On 64-bit S390 platforms the "compile" command always failed because
gcc was not invoked correctly.  This patch fixes the compiler
invocation.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_gcc_target_options): Not just handle
	31-bit targets, but 64-bit targets as well.
	(s390_gnu_triplet_regexp): New function.
	(s390_gdbarch_init): Set the gcc_target_options gdbarch method for
	64-bit targets as well.  Set the gnu_triplet_regexp gdbarch
	method.
2015-02-27 10:47:54 +01:00
Joel Brobecker f44466fb65 Mark latest entry in gdb/ChangeLog as "(tiny patch)". 2015-02-27 09:49:59 +01:00
Jon TURNEY f0666312fd Retrieve segment registers on Windows amd64
For amd64, CONTEXT_FULL does not contain CONTEXT_SEGMENTS, which seems
to be needed to retrieve all the segment registers.  Add it explicitly,
with a little de-cruftification.

The value of the segment registers isn't terribly useful on amd64, but
at least this makes the output of 'info registers' correct.

Before:

    (gdb)  i r cs ss ds es fs gs
    cs             0x33     51
    ss             0x2b     43
    ds             0x0      0
    es             0x0      0
    fs             0x0      0
    gs             0x0      0

After:

    (gdb) i r cs ss ds es fs gs
    cs             0x33     51
    ss             0x2b     43
    ds             0x2b     43
    es             0x2b     43
    fs             0x53     83
    gs             0x2b     43

gdb/ChangeLog

2015-02-27  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* windows-nat.c (CONTEXT_DEBUGGER): Remove.
	(CONTEXT_DEBUGGER_DR): Add CONTEXT_SEGMENTS.  Incorporate flags
	from CONTEXT_DEBUGGER.
2015-02-27 09:46:05 +01:00
Doug Evans 0def5aaad6 Add missing CHECK_TYPEDEF calls to recent vptr_{fieldno,basetype} cleanup.
gdb/ChangeLog:

	* gdbtypes.c (internal_type_vptr_fieldno): Add missing call to
	CHECK_TYPEDEF.
	(set_type_vptr_fieldno): Ditto.
	(internal_type_vptr_basetype, set_type_vptr_basetype): Ditto.
	* gnu-v3-abi.c (gnuv3_dynamic_class): Ditto.

gdb/testsuite/ChangeLog:

	* gdb.cp/class2.cc (Dbase, D): New classes.
	(main): New local delta.
	* gdb.cp/class2.exp: Test printing delta.
	* gdb.cp/classes.cc (DynamicBase2, DynamicBar): New classes.
	(dynbar): New global.
	* gdb.cp/classes.exp (test_ptype_class_objects): Test ptype DynamicBar.
2015-02-26 17:31:29 -08:00
Pedro Alves 9beb7c4e1d gdbserver/Linux: Simplify stepping past program breakpoint a little
.decr_pc_after_break is never higher than .breakpoint_len, so use
.breakpoint_len directly.  Based on idea from Yao here:
https://sourceware.org/ml/gdb-patches/2015-02/msg00689.html

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

	* linux-low.c (linux_wait_1): When incrementing the PC past a
	program breakpoint always use the_low_target.breakpoint_len as
	increment, rather than the maximum between that and
	the_low_target.decr_pc_after_break.
2015-02-26 18:48:46 +00:00
Pedro Alves 77b64a49e2 Add ATTRIBUTE_PRINTF attributes, and fix fallout
Fixes building gdb on x86_64-apple-darwin14 with clang, which produces
a number of warnings from -Wformat-nonliteral.

Ref: https://sourceware.org/ml/gdb/2015-02/msg00047.html

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

	* auto-load.h (file_is_auto_load_safe): Add ATTRIBUTE_PRINTF.
	* complaints.c (vcomplaint): Pass argument FMT directly to
	printf-like functions instead of complaint->fmt.
	* ctf.c (ctf_save_write_metadata): Add ATTRIBUTE_PRINTF.
	* darwin-nat.c (inferior_debug): Add ATTRIBUTE_PRINTF.
	* compile/compile-loc2c.c (pushf, unary, binary): Add
	ATTRIBUTE_PRINTF.
	(do_compile_dwarf_expr_to_c): Pass string literal as format string
	to pushf.
	(BINARY): Pass string literal as format string to 'binary'.
	* compile/compile-object-load.c (link_callbacks_einfo): Add
	ATTRIBUTE_PRINTF.
	* guile/guile-internal.h (gdbscm_printf): Add ATTRIBUTE_PRINTF.
2015-02-26 18:29:12 +00:00
Pedro Alves 532f44ed67 Rename windows-termcap.c -> stub-termcap.c
Preparation for using this on all hosts.

Confirmed that --host=x86_64-w64-mingw32 still builds the stub
termcap.

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

	* windows-termcap.c: Rename to ...
	* stub-termcap.c: ... this.  Adjust header line.
	* Makefile.in (SFILES): Refer to stub-termcap.c instead of
	windows-termcap.c.
	* configure: Regenerate.
	* configure.ac: Refer to stub-termcap.o instead of
	windows-termcap.o.
	* gdb_curses.h: Mention stub-termcap.c instead of
	windows-termcap.c.
2015-02-26 17:13:58 +00:00
Jan Kratochvil 081a1c2ced compile: Fix GNU-IFUNC funcs called from injected code
One could not call IFUNCs (=indirect functions) from the compiled injected
code.  Either it errored with:
	gdb command line:1:1: error: function return type cannot be function

or it just called the IFUNC dispatcher in normal way, returning real function
implementation address instead of the function return value (and thus no
function was called).

gdb/ChangeLog
2015-02-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* compile/compile-c-symbols.c (convert_one_symbol, convert_symbol_bmsym)
	(gcc_symbol_address): Call gnu_ifunc_resolve_addr.

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

	* gdb.compile/compile-ifunc.c: New file.
	* gdb.compile/compile-ifunc.exp: New file.
2015-02-26 17:40:57 +01:00
Antoine Tremblay 2f41223f62 Fix print of value type in a corner case of finish
When doing finish in a function, if gdb fails to return a value, gdb
also fails at printing the value type if this type is a struct.

For example :

(gdb) fin
....
Value returned has type: . Cannot determine contents

This patch fixes this by calling type_to_string to print the type
so that we can support these types.

This patch returns the following example output :

(gdb) fin
....
Value returned has type: struct test. Cannot determine contents

Also, this patch modifies structs.exp to check that we return the
correct type.

gdb/ChangeLog:
	* gdb/infcmd.c (print_return_value): use type_to_string to print type.

gdb/testsuite/ChangeLog:
	* gdb.base/structs.exp: Check for correct struct on finish.
2015-02-26 10:58:00 -05:00
Yao Qi 03eddd80d7 Dwarf assembler: handle one instruction function
On aarch64, we got the following fail:

(gdb) disassemble func
Dump of assembler code for function func:
   0x0000000000400730 <+0>:     ret
End of assembler dump.^M
(gdb) x/2i func+0^M
   0x400730 <func>:     ret^M
   0x400734 <main>:     stp     x29, x30, [sp,#-16]!^M
(gdb) FAIL: gdb.dwarf2/dw2-ifort-parameter.exp: x/2i func+0

the pattern in proc function_range expects to match <func+0>, however,
GDB doesn't display the offset when it is zero.  This patch is to
adjust the pattern when $func_length is zero.

gdb/testsuite:

2015-02-26  Yao Qi  <yao.qi@linaro.org>

	* lib/dwarf.exp (function_range): Adjust pattern when $func_length
	is zero.
2015-02-26 14:21:19 +00:00
Jan Kratochvil 80c570537e SEGV in ppc64_elf_get_synthetic_symtab reading a separate debug file
The attached patch fixes the SEGV and lets GDB successfully
load all kernel modules installed by default on RHEL 7.

Valgrind on F-21 x86_64 host has shown me more clear what is the problem:

Reading symbols from /home/jkratoch/t/cordic.ko...Reading symbols from
/home/jkratoch/t/cordic.ko.debug...=================================================================
==22763==ERROR: AddressSanitizer: heap-use-after-free on address 0x6120000461c8 at pc 0x150cdbd bp 0x7fffffffc7e0 sp 0x7fffffffc7d0
READ of size 8 at 0x6120000461c8 thread T0
    #0 0x150cdbc in ppc64_elf_get_synthetic_symtab /home/jkratoch/redhat/gdb-test-asan/bfd/elf64-ppc.c:3282
    #1 0x8c5274 in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1205
    #2 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
[...]
0x6120000461c8 is located 264 bytes inside of 288-byte region [0x6120000460c0,0x6120000461e0)
freed by thread T0 here:
    #0 0x7ffff715454f in __interceptor_free (/lib64/libasan.so.1+0x5754f)
    #1 0xde9cde in xfree common/common-utils.c:98
    #2 0x9a04f7 in do_my_cleanups common/cleanups.c:155
    #3 0x9a05d3 in do_cleanups common/cleanups.c:177
    #4 0x8c538a in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1229
    #5 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
[...]
previously allocated by thread T0 here:
    #0 0x7ffff71547c7 in malloc (/lib64/libasan.so.1+0x577c7)
    #1 0xde9b95 in xmalloc common/common-utils.c:41
    #2 0x8c4da2 in elf_read_minimal_symbols /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1147
    #3 0x8c55e7 in elf_symfile_read /home/jkratoch/redhat/gdb-test-asan/gdb/elfread.c:1268
[...]
SUMMARY: AddressSanitizer: heap-use-after-free /home/jkratoch/redhat/gdb-test-asan/bfd/elf64-ppc.c:3282 ppc64_elf_get_synthetic_symtab
[...]
==22763==ABORTING

A similar case a few lines later I have fixed in 2010 by:
        https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=3f1eff0a2c7f0e7078f011f55b8e7f710aae0cc2

My testcase does not always reproduce it but at least a bit:
 * GDB without ppc64 target (even as a secondary one) is reported as "untested"
 * ASAN-built GDB with ppc64 target always crashes (and PASSes with this fix)
 * unpatched non-ASAN-built GDB with ppc64 target crashes from commandline
 * unpatched non-ASAN-built GDB with ppc64 target PASSes from runtest (?)

gdb/ChangeLog
2015-02-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* elfread.c (elf_read_minimal_symbols): Use bfd_alloc for
	bfd_canonicalize_symtab.

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

	* gdb.arch/cordic.ko.bz2: New file.
	* gdb.arch/cordic.ko.debug.bz2: New file.
	* gdb.arch/ppc64-symtab-cordic.exp: New file.
2015-02-26 14:08:01 +01:00
John Baldwin cf424aef0a Rework signal frame probing for FreeBSD/x86
- Use signal frame sniffers that look for the signal trampoline
  instruction sequence to detect most signal frames.

- FreeBSD kernels between 9.2 and 10.1 inclusive do not include the
  signal trampoline code in process core dumps.  To detect signal
  frames for core dumps under these kernels, use the
  kern.proc.sigtramp.<pid> sysctl to fetch the location of the signal
  trampoline in the gdb process and assume that PC values within this
  location are signal frames.  This depends on that location being
  identical for all binaries.

gdb/ChangeLog:
2015-02-25  John Baldwin  <jhb@FreeBSD.org>

	* amd64fbsd-nat.c: Include sys/user.h.
	(_initialize_amd64fbsd_nat): Use the KERN_PROC_SIGTRAMP sysctl
	instead of KERN_PS_STRINGS to locate the signal trampoline.
	* i386fbsd-nat.c: Include sys/user.h.
	(_initialize_i386fbsd_nat): Use the KERN_PROC_SIGTRAMP sysctl
	instead of KERN_PS_STRINGS to locate the signal trampoline.
	* amd64fbsd-tdep.c (amd64fbsd_sigtramp_code): New.
	(amd64fbsd_sigtramp_p): New.
	(amd64fbsd_sigtramp_start_addr, amd64fbsd_sigtramp_end_addr): No
	longer set default values.
	(amd64fbsd_init_abi): Set "sigtramp_p" to "amd64fbsd_sigtramp_p".
	* i386fbsd-tdep.c (i386fbsd_sigtramp_start)
	(i386fbsd_sigtramp_middle, i386fbsd_sigtramp_end)
	(i386fbsd_freebsd4_sigtramp_start)
	(i386fbsd_freebsd4_sigtramp_middle)
	(i386fbsd_freebsd4_sigtramp_end, i386fbsd_osigtramp_start)
	(i386fbsd_osigtramp_middle, i386fbsd_osigtramp_end): New.
	(i386fbsd_sigtramp_p): New.
	(i386fbsd_sigtramp_start_addr, i386fbsd_sigtramp_end_addr): No
	longer set default values.
	(i386fbsd_init_abi): Set "sigtramp_p" to "i386fbsd_sigtramp_p".
2015-02-26 11:10:25 +00:00
John Baldwin c5cb74eeb3 Fix infinite recursion in amd64fbsd_sigcontext_addr
amd64fbsd_sigcontext_addr is using frame_unwind_register_unsigned to
fetch the stack pointer which results in infinite recursion.  This
patch changes it to use get_frame_register to match the
sigcontext_addr methods in the i386-bsd and amd64-linux targets
instead.

gdb/ChangeLog:
2015-02-25  John Baldwin  <jhb@freebsd.org>

	* amd64fbsd-tdep.c (amd64fbsd_sigcontext_addr): Use
	get_frame_register instead of frame_unwind_register_unsigned.
2015-02-26 11:07:57 +00:00
Jan Kratochvil 17487d857c Change // comment in gdb/compile/
Missing ChangeLog in the previous commit:
	bb2b33b939

gdb/ChangeLog
2015-02-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR build/18033
	* compile/compile-c-support.c (c_compute_program): Change // comment.
	* compile/compile-object-load.c (setup_sections): Change // comment.
2015-02-26 11:50:08 +01:00
Jan Kratochvil bb2b33b939 Change // comment in gdb/compile/ 2015-02-26 11:48:18 +01:00
Joel Brobecker 9357a9e66e Remove // comment in gdb/iq2000-tdep.c
gdb/ChangeLog:

	PR build/18033:
	* iq2000-tdep.c (iq2000_frame_cache): Delete C++-style comment.
2015-02-26 10:42:04 +01:00
Yao Qi 21613c12d1 [aarch64] Fix one fail in gdb.xml/tdesc-regs.exp
Hi,
I see the following fail in aarch64-linux-gnu testing...

(gdb) set tdesc file /XXX/gdb/testsuite/gdb.xml/single-reg.xml^M
warning: Architecture rejected target-supplied description^M
(gdb) FAIL: gdb.xml/tdesc-regs.exp: set tdesc file single-reg.xml

core-regs isn't set for aarch64 target, and looks it is an oversight
when aarch64 port was added.

gdb/testsuite:

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

	* gdb.xml/tdesc-regs.exp: Set core-regs to aarch64-core.xml for
	aarch64*-*-* target.
2015-02-25 10:39:59 +00:00
Doug Evans b615dd209f Fix typo in earlier entry. 2015-02-23 13:39:45 -08:00
Sergio Durigan Junior 7ee67ee442 PR gdb/18008: Fix typo in documentation
This obvious patch fixes a typo in our documentation
(s/problam/problem).

gdb/doc/ChangeLog:
2015-02-23  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/18008
	* gdb.texinfo (maint internal-error, maint internal-warning, maint
	demangler-warning): Fix typo ("problam").
2015-02-23 16:15:29 -05:00
Pedro Alves 8090aef2bf gdbserver: redo stepping over breakpoint that was on top of a permanent breakpoint
I'm going to add an alternate mechanism of breakpoint trap
identification to 'check_stopped_by_breakpoint' that does not rely on
checking the instruction at PC.  The mechanism currently used to tell
whether we're stepping over a permanent breakpoint doesn't fit in that
new method.  This patch redoes the whole logic in a different way that
works with both old and new methods, in essence moving the "stepped
permanent breakpoint" detection "one level up".  It makes lower level
check_stopped_by_breakpoint always the adjust the PC, and then has
linux_wait_1 advance the PC past the breakpoint if necessary.  This
ends up being better also because this now handles
non-decr_pc_after_break targets too.  Before, such targets would get
stuck forever reexecuting the breakpoint instruction.

Tested on x86_64 Fedora 20.

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

	* linux-low.c (check_stopped_by_breakpoint): Don't check if the
	thread was doing a step-over; always adjust the PC if
	we stepped over a permanent breakpoint.
	(linux_wait_1): If we stepped over breakpoint that was on top of a
	permanent breakpoint, manually advance the PC past it.
2015-02-23 18:59:38 +00:00
Pedro Alves d8b901edd1 delete_breakpoints: Rewrite using gdb_test_multiple
Because delete_breakpoints uses gdb_expect directly, an internal error
results in slow timeouts instead of quickly bailing out.  This patch
rewrites the procedure to use gdb_test_multiple instead, while
preserving the existing general logic ("delete breakpoints" + "info
breakpoints").

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

	* lib/gdb.exp (delete_breakpoints): Rewrite using
	gdb_test_multiple.
2015-02-23 17:35:09 +00:00
Pedro Alves 1f10ba14bc remote.c: simplify parsing stop reasons in T stop replies
We need to be careful with parsing optional stop reasons that start
with an hex character ("awatch", "core"), as GDBs that aren't aware of
them parse them as real numbers.  That's silly of course, given that
there should be a colon after those magic "numbers".  So if strtol on
"abbz:" doesn't return "first invalid char" pointing to the colon, we
know that "abbz" isn't really a register number.  It must be optional
stop info we don't know about.  This adjusts GDB to work that way,
removing the need for the special casing done upfront:

	  /* If this packet is an awatch packet, don't parse the 'a'
	     as a register number.  */
	  if (strncmp (p, "awatch", strlen("awatch")) != 0
	      && strncmp (p, "core", strlen ("core") != 0))

For as long as we care about compatibility with GDB 7.9, we'll need to
continue to be careful about this, so I added a comment.

Tested on x86_64 Fedora 20, native gdbserver.

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

	* remote.c (skip_to_semicolon): New function.
	(remote_parse_stop_reply) <T stop reply>: Use it.  Don't
	special case the stop reasons that look like hex numbers
	upfront.  Instead handle real register numbers after matching
	all the known stop reasons.
2015-02-23 16:45:39 +00:00
Pedro Alves e5b85ead63 gdb.base/info-os.c: Include stdlib.h
Fixes:

 > gdb compile failed, /gdb/testsuite/gdb.base/info-os.c: In function 'main':
 > /gdb/testsuite/gdb.base/info-os.c:65:3: warning: implicit declaration of function 'atexit' [-Wimplicit-function-declaration]
 >    atexit (ipc_cleanup);
 >    ^
 > FAIL: gdb.base/info-os.exp: cannot compile test program

with recent GCCs.

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

	* gdb.base/info-os.c: Include stdlib.h.
2015-02-23 14:03:48 +00:00
Pedro Alves bc9540e842 gdbserver: 64-bit kernel / 32-inferior, syscall restarting
$ make check RUNTESTFLAGS="--target_board=native-gdbserver/-m32 clone-thread_db.exp"

gdb.log shows:

  Running target native-gdbserver/-m32
  ...
  clone-thread_db: src/gdb/testsuite/gdb.threads/clone-thread_db.c:57: thread_fn: Assertion `res != -1' failed.
  ...
  (gdb) FAIL: gdb.threads/clone-thread_db.exp: continue to end

That was waitpid returning -1 / EINTR.  We don't see that when testing
with unix/-m32 (native debugging).  Turns out to be that when
debugging a 32-bit inferior, a 64-bit GDBserver is reading/writing
$orig_eax from/to the wrong ptrace register buffer offset.  When
gdbserver is 64-bit, the ptrace register buffer is in 64-bit layout,
so the register is found at "ORIG_EAX * 8", not at "ORIG_EAX * 4".

Fixes these with --target_board=native-gdbserver/-m32 on x86_64 Fedora 20:

    -FAIL: gdb.threads/clone-thread_db.exp: continue to end
    +PASS: gdb.threads/clone-thread_db.exp: continue to end

    -FAIL: gdb.threads/hand-call-in-threads.exp: all dummies popped
    +PASS: gdb.threads/hand-call-in-threads.exp: all dummies popped
     PASS: gdb.threads/hand-call-in-threads.exp: breakpoint on all_threads_running
     PASS: gdb.threads/hand-call-in-threads.exp: breakpoint on hand_call
     PASS: gdb.threads/hand-call-in-threads.exp: disable scheduler locking
    @@ -29339,15 +29331,15 @@ PASS: gdb.threads/hand-call-in-threads.e
     PASS: gdb.threads/hand-call-in-threads.exp: discard hand call, thread 4
     PASS: gdb.threads/hand-call-in-threads.exp: discard hand call, thread 5
     PASS: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 1
    -FAIL: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 2
    -FAIL: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 3
    -FAIL: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 4
    +PASS: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 2
    +PASS: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 3
    +PASS: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 4
     PASS: gdb.threads/hand-call-in-threads.exp: dummy stack frame number, thread 5
     PASS: gdb.threads/hand-call-in-threads.exp: enable scheduler locking
     PASS: gdb.threads/hand-call-in-threads.exp: hand call, thread 1
    -FAIL: gdb.threads/hand-call-in-threads.exp: hand call, thread 2
    -FAIL: gdb.threads/hand-call-in-threads.exp: hand call, thread 3
    -FAIL: gdb.threads/hand-call-in-threads.exp: hand call, thread 4
    +PASS: gdb.threads/hand-call-in-threads.exp: hand call, thread 2
    +PASS: gdb.threads/hand-call-in-threads.exp: hand call, thread 3
    +PASS: gdb.threads/hand-call-in-threads.exp: hand call, thread 4
     PASS: gdb.threads/hand-call-in-threads.exp: hand call, thread 5
     PASS: gdb.threads/hand-call-in-threads.exp: prepare to discard hand call, thread 1
     PASS: gdb.threads/hand-call-in-threads.exp: prepare to discard hand call, thread 2

gdb/gdbserver/ChangeLog
2015-02-23  Pedro Alves  <palves@redhat.com>

	* linux-x86-low.c (REGSIZE): Define in both 32-bit and 64-bit
	modes.
	(x86_fill_gregset, x86_store_gregset): Use it when handling
	$orig_eax.
2015-02-23 13:03:10 +00:00
Doug Evans 85c3a371b3 testcase for PR symtab/17855
gdb/testsuite/ChangeLog:

	PR symtab/17855
	* gdb.ada/exec_changed.exp: Add second test where symbol lookup cache
	is read after symbols have been re-read.
	* gdb.ada/exec_changed/first.adb (First): New procedure Break_Me.
	* gdb.ada/exec_changed/second.adb (Second): Ditto.
2015-02-22 09:11:55 -08:00
Doug Evans 96553a0cff PR c++/17976, symtab/17821
This patch addresses two issues.

The basic problem is that "(anonymous namespace)" doesn't get entered
into the symbol table because when dwarf2read.c:new_symbol_full is called
the DIE has no name (dwarf2_name returns NULL).

PR 17976: ptype '(anonymous namespace)' should work like any namespace

PR 17821: perf issue looking up (anonymous namespace)

bash$ gdb monster-program
(gdb) mt set per on
(gdb) mt set symbol-cache-size 0
(gdb) break (anonymous namespace)::foo

Before:

Command execution time: 3.266289 (cpu), 6.169030 (wall)
Space used: 811429888 (+12910592 for this command)

After:

Command execution time: 1.264076 (cpu), 4.057408 (wall)
Space used: 798781440 (+0 for this command)

gdb/ChangeLog:

	PR c++/17976, symtab/17821
	* cp-namespace.c (cp_search_static_and_baseclasses): New parameter
	is_in_anonymous.  All callers updated.
	(find_symbol_in_baseclass): Ditto.
	(cp_lookup_nested_symbol_1): Ditto.  Don't search all static blocks
	for symbols in an anonymous namespace.
	* dwarf2read.c (namespace_name): Don't call dwarf2_name, fetch
	DW_AT_name directly.
	(dwarf2_name): Convert missing namespace name to
	CP_ANONYMOUS_NAMESPACE_STR.

gdeb/testsuite/ChangeLog:

	* gdb.cp/anon-ns.exp: Add test for ptype '(anonymous namespace)'.
2015-02-21 21:58:31 -08:00
Jan Kratochvil 97a0c6972e Testsuite patch for: i386: Fix internal error when prstatus in core file is too big
gdb/testsuite/ChangeLog
2015-02-21  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR corefiles/17808
	* gdb.arch/i386-biarch-core.core.bz2: New file.
	* gdb.arch/i386-biarch-core.exp: New file.
2015-02-21 15:24:20 +01:00
Pedro Alves a47cd6e95a gdb.threads/multi-create-ns-info-thr.exp and native-extended-remote board
The buildbot shows that the new
gdb.threads/multi-create-ns-info-thr.exp test is timing out when
tested with --target=native-extended-remote.  The reason is:

 No breakpoints or watchpoints.
 (gdb) break main
 Breakpoint 1 at 0x10000b00: file ../../../binutils-gdb/gdb/testsuite/gdb.threads/multi-create.c, line 72.
 (gdb) run
 Starting program: /home/gdb-buildbot/fedora-21-ppc64be-1/fedora-ppc64be-native-extended-gdbserver/build/gdb/testsuite/outputs/gdb.threads/multi-create-ns-info-thr/multi-cre
 ate-ns-info-thr
 Process /home/gdb-buildbot/fedora-21-ppc64be-1/fedora-ppc64be-native-extended-gdbserver/build/gdb/testsuite/outputs/gdb.threads/multi-create-ns-info-thr/multi-create-ns-inf
 o-thr created; pid = 16266
 Unexpected vCont reply in non-stop mode: T0501:00003fffffffd190;40:00000080560fe290;thread:p3f8a.3f8a;core:0;
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 (gdb) break multi-create.c:45
 Breakpoint 2 at 0x10000994: file ../../../binutils-gdb/gdb/testsuite/gdb.threads/multi-create.c, line 45.
 (gdb) commands
 Type commands for breakpoint(s) 2, one per line.

Non-stop tests don't really work with the
--target_board=native-extended-remote board, because tests toggle
non-stop on after GDB is already connected to gdbserver, while
Currently, non-stop must be enabled before connecting.

This adjusts the test to bail if running to main fails, like all other
non-stop tests.

Note non-stop tests do work with --target_board=native-gdbserver.

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

	* gdb.threads/multi-create-ns-info-thr.exp: Return early if
	runto_main fails.
2015-02-21 12:03:23 +00:00
Pedro Alves c5facdc449 Fix gdb.base/solib-corrupted.exp after dtrace probes changes
Commit 6f9b8491 (Adapt `info probes' to support printing probes of
different types.) added a new type column to "info probes".  That
caused a solib-corrupted.exp regression:

 ~~~~~~~~~~~~~~~~~~~~~
 Running /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/solib-corrupted.exp ...
 FAIL: gdb.base/solib-corrupted.exp: corrupted list

		 === gdb Summary ===

 # of expected passes            2
 # of unexpected failures        1
 ~~~~~~~~~~~~~~~~~~~~~

Tested on x86_64 Fedora 20.

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

	* gdb.base/solib-corrupted.exp: Expect "stap" as first column of
	info probes.
2015-02-20 23:10:53 +00:00
Pedro Alves 2db9a4275c GNU/Linux: Stop using libthread_db/td_ta_thr_iter
TL;DR - GDB can hang if something refreshes the thread list out of the
target while the target is running.  GDB hangs inside td_ta_thr_iter.
The fix is to not use that libthread_db function anymore.

Long version:

Running the testsuite against my all-stop-on-top-of-non-stop series is
still exposing latent non-stop bugs.

I was originally seeing this with the multi-create.exp test, back when
we were still using libthread_db thread event breakpoints.  The
all-stop-on-top-of-non-stop series forces a thread list refresh each
time GDB needs to start stepping over a breakpoint (to pause all
threads).  That test hits the thread event breakpoint often, resulting
in a bunch of step-over operations, thus a bunch of thread list
refreshes while some threads in the target are running.

The commit adds a real non-stop mode test that triggers the issue,
based on multi-create.exp, that does an explicit "info threads" when a
breakpoint is hit.  IOW, it does the same things the as-ns series was
doing when testing multi-create.exp.

The bug is a race, so it unfortunately takes several runs for the test
to trigger it.  In fact, even when setting the test running in a loop,
it sometimes takes several minutes for it to trigger for me.

The race is related to libthread_db's td_ta_thr_iter.  This is
libthread_db's entry point for walking the thread list of the
inferior.

Sometimes, when GDB refreshes the thread list from the target,
libthread_db's td_ta_thr_iter can somehow see glibc's thread list as a
cycle, and get stuck in an infinite loop.

The issue is that when a thread exits, its thread control structure in
glibc is moved from a "used" list to a "cache" list.  These lists are
simply circular linked lists where the "next/prev" pointers are
embedded in the thread control structure itself.  The "next" pointer
of the last element of the list points back to the list's sentinel
"head".  There's only one set of "next/prev" pointers for both lists;
thus a thread can only be in one of the lists at a time, not in both
simultaneously.

So when thread C exits, simplifying, the following happens.  A-C are
threads.  stack_used and stack_cache are the list's heads.

Before:

  stack_used -> A -> B -> C -> (&stack_used)
  stack_cache -> (&stack_cache)

After:

  stack_used -> A -> B -> (&stack_used)
  stack_cache -> C -> (&stack_cache)

td_ta_thr_iter starts by iterating at the list's head's next, and
iterates until it sees a thread whose next pointer points to the
list's head again.  Thus in the before case above, C's next points to
stack_used, indicating end of list.  In the same case, the stack_cache
list is empty.

For each thread being iterated, td_ta_thr_iter reads the whole thread
object out of the inferior.  This includes the thread's "next"
pointer.

In the scenario above, it may happen that td_ta_thr_iter is iterating
thread B and has already read B's thread structure just before thread
C exits and its control structure moves to the cached list.

Now, recall that td_ta_thr_iter is running in the context of GDB, and
there's no locking between GDB and the inferior.  From it's local copy
of B, td_ta_thr_iter believes that the next thread after B is thread
C, so it happilly continues iterating to C, a thread that has already
exited, and is now in the stack cache list.

After iterating C, td_ta_thr_iter finds the stack_cache head, which
because it is not stack_used, td_ta_thr_iter assumes it's just another
thread.  After this, unless the reverse race triggers, GDB gets stuck
in td_ta_thr_iter forever walking the stack_cache list, as no thread
in thatlist has a next pointer that points back to stack_used (the
terminating condition).

Before fully understanding the issue, I tried adding cycle detection
to GDB's td_ta_thr_iter callback.  However, td_ta_thr_iter skips
calling the callback in some cases, which means that it's possible
that the callback isn't called at all, making it impossible for GDB to
break the loop.  I did manage to get GDB stuck in that state more than
once.

Fortunately, we can avoid the issue altogether.  We don't really need
td_ta_thr_iter for live debugging nowadays, given PTRACE_EVENT_CLONE.
We already know how to map and lwp id to a thread id without iterating
(thread_from_lwp), so use that more.

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

	* linux-nat.c (linux_handle_extended_wait): Call
	thread_db_notice_clone whenever a new clone LWP is detected.
	(linux_stop_and_wait_all_lwps, linux_unstop_all_lwps): New
	functions.
	* linux-nat.h (thread_db_attach_lwp): Delete declaration.
	(thread_db_notice_clone, linux_stop_and_wait_all_lwps)
	(linux_unstop_all_lwps): Declare.
	* linux-thread-db.c (struct thread_get_info_inout): Delete.
	(thread_get_info_callback): Delete.
	(thread_from_lwp): Use td_thr_get_info and record_thread.
	(thread_db_attach_lwp): Delete.
	(thread_db_notice_clone): New function.
	(try_thread_db_load_1): If /proc is mounted and shows the
	process'es task list, walk over all LWPs and call thread_from_lwp
	instead of relying on td_ta_thr_iter.
	(attach_thread): Don't call check_thread_signals here.  Split the
	tail part of the function (which adds the thread to the core GDB
	thread list) to ...
	(record_thread): ... this function.  Call check_thread_signals
	here.
	(thread_db_wait): Don't call thread_db_find_new_threads_1.  Always
	call thread_from_lwp.
	(thread_db_update_thread_list): Rename to ...
	(thread_db_update_thread_list_org): ... this.
	(thread_db_update_thread_list): New function.
	(thread_db_find_thread_from_tid): Delete.
	(thread_db_get_ada_task_ptid): Simplify.
	* nat/linux-procfs.c: Include <sys/stat.h>.
	(linux_proc_task_list_dir_exists): New function.
	* nat/linux-procfs.h (linux_proc_task_list_dir_exists): Declare.

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

	* thread-db.c: Include "nat/linux-procfs.h".
	(thread_db_init): Skip listing new threads if the kernel supports
	PTRACE_EVENT_CLONE and /proc/PID/task/ is accessible.

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

	* gdb.threads/multi-create-ns-info-thr.exp: New file.
2015-02-20 21:40:31 +00:00
Pedro Alves 3b27ef472d linux-nat.c: fix a few lin_lwp_attach_lwp issues
This function has a few latent bugs that are triggered by a non-stop
mode test that will be added in a subsequent patch.

First, as described in the function's intro comment, the function is
supposed to return 1 if we're already auto attached to the thread, but
haven't processed the PTRACE_EVENT_CLONE event of its parent thread
yet.

Then, we may find that we're trying to attach to a clone child that
hasn't yet stopped for its initial stop, and therefore 'waitpid(...,
WNOHANG)' returns 0.  In that case, we're currently adding the LWP to
the stopped_pids list, which results in linux_handle_extended_wait
skipping the waitpid call on the child, and thus confusing things
later on when the child eventually reports the stop.

Then, the tail end of lin_lwp_attach_lwp always sets the
last_resume_kind of the LWP to resume_stop, which is wrong given that
the user may be doing "info threads" while some threads are running.

And then, the else branch of lin_lwp_attach_lwp always sets the
stopped flag of the LWP.  This branch is reached if the LWP is the
main LWP, which may well be running at this point (to it's wrong to
set its 'stopped' flag).

AFAICS, there's no reason anymore for special-casing the main/leader
LWP here:

- For the "attach" case, linux_nat_attach already adds the main LWP to
the lwp list, and sets its 'stopped' flag.

- For the "run" case, after linux_nat_create_inferior, end up in
linux_nat_wait_1 here:

  /* The first time we get here after starting a new inferior, we may
     not have added it to the LWP list yet - this is the earliest
     moment at which we know its PID.  */
  if (ptid_is_pid (inferior_ptid))
    {
      /* Upgrade the main thread's ptid.  */
      thread_change_ptid (inferior_ptid,
			  ptid_build (ptid_get_pid (inferior_ptid),
				      ptid_get_pid (inferior_ptid), 0));

      lp = add_initial_lwp (inferior_ptid);
      lp->resumed = 1;
    }

... which adds the LWP to the LWP list already, before
lin_lwp_attach_lwp can ever be reached.

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

	* linux-nat.c (lin_lwp_attach_lwp): No longer special case the
	main LWP.  Handle the case of waitpid returning 0 if we're already
	attached to the LWP.  Don't set the LWP's last_resume_kind to
	resume_stop if we already knew about the LWP.
	(linux_nat_filter_event): Add debug logs.
2015-02-20 20:21:59 +00:00
Pedro Alves 1cc28231d2 Garbage collect forward_target_decr_pc_after_break
The definition was removed a year ago, but the declaration managed to
stay behind.

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

	* target.h (forward_target_decr_pc_after_break): Delete
	declaration.
2015-02-20 20:11:02 +00:00
Pedro Alves afa8d396f6 fix gdbserver/linux-low'c's pending status handling
Another fix I'm working made schedlock.exp fail with gdbserver
frequently.  Looking deeper, it turns out to be a pre-existing bug.

status_pending_p_callback is filtering out LWPs incorrectly.  The
result is that that sometimes status_pending_p_callback returns a
pending event for an LWP that isn't expected, and then GDBserver gets
very confused.

E.g,. when doing a step-over, linux_wait_for_event is called with a
particular LWP's ptid, meaning events for all other LWPs should be
left pending, but here we see it retuning an event for some other LWP:

 linux_wait_1: [<all threads>]
 step_over_bkpt set [LWP 29577.29577], doing a blocking wait      <--------
 my_waitpid (-1, 0x40000001)
 my_waitpid (-1, 0x80000001): status(57f), 0
 LWFE: waitpid(-1, ...) returned 0, ERRNO-OK
 pc is 0x4007a0
 src/gdb/gdbserver/linux-low.c:2587: A problem internal to GDBserver has been detected.
 linux_wait_1: got event for 29581                                <--------

 Remote connection closed
 (gdb) FAIL: gdb.threads/schedlock.exp: continue to breakpoint: return to loop (initial)
 delete breakpoints

Tested on x86_64 Fedora 20.

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

	* linux-low.c (status_pending_p_callback): Use ptid_match.
2015-02-20 19:52:51 +00:00
Pedro Alves 60fb7e9efa Fix no-attach-trace.exp with "target remote" / gdbserver
$ make check RUNTESTFLAGS="--target_board=native-gdbserver no-attach-trace.exp"
 ...
 (gdb) trace main
 Tracepoint 1 at 0x400594: file /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.trace/no-attach-trace.c, line 25.
 (gdb) PASS: gdb.trace/no-attach-trace.exp: set tracepoint on main
 tstart
 You can't do that when your target is `exec'
 (gdb) FAIL: gdb.trace/no-attach-trace.exp: tstart

Even though this target supports tracing, the test restarts GDB and
doesn't do gdb_run_cmd so does not reconnect to the remote target.  So
at that point, GDB only has the "exec" target, which obviously doesn't
do tracing.

The test is about doing "tstart" before running a program, so the fix
is to do gdb_target_supports_trace with whatever target GDB ends up
connected after clean_restart.

Tested on x86_64 Fedora 20, native, native-gdbserver and
native-extended-gdbserver boards.  The test passes with the latter,
and is skipped with the first two.

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

	* gdb.trace/no-attach-trace.exp: Don't run to main.  Do
	clean_restart before gdb_target_supports_trace.
2015-02-20 19:50:36 +00:00
Pedro Alves 5c5019c27c PR18006: internal error if threaded program calls clone(CLONE_VM)
On GNU/Linux, if a pthreaded program has a thread call clone(CLONE_VM)
directly, and then that clone LWP hits a debug event (breakpoint,
etc.) GDB internal errors.  Threaded programs shouldn't really be
calling clone directly, but GDB shouldn't crash either.

The crash looks like this:

 (gdb) break clone_fn
 Breakpoint 2 at 0x4007d8: file clone-thread_db.c, line 35.
 (gdb) r
 ...
 [Thread debugging using libthread_db enabled]
 ...
 src/gdb/linux-nat.c:1030: internal-error: lin_lwp_attach_lwp: Assertion `lwpid > 0' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.

The problem is that 'clone' ends up clearing the parent thread's tid
field in glibc's thread data structure.  For x86_64, the glibc code in
question is here:

  sysdeps/unix/sysv/linux/x86_64/clone.S:

   ...
          testq   $CLONE_THREAD, %rdi
          jne     1f
          testq   $CLONE_VM, %rdi
          movl    $-1, %eax            <----
          jne     2f
          movl    $SYS_ify(getpid), %eax
          syscall
  2:      movl    %eax, %fs:PID
          movl    %eax, %fs:TID        <----
  1:

When GDB refreshes the thread list out of libthread_db, it finds a
thread with LWP with pid -1 (the clone's parent), which naturally
isn't yet on the thread list.  GDB then tries to attach to that bogus
LWP id, which is caught by that assertion.

The fix is to detect the bad PID early.

Tested on x86-64 Fedora 20.  GDBserver doesn't need any fix.

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

	PR threads/18006
	* linux-thread-db.c (thread_get_info_callback): Return early if
	the thread's lwp id is -1.

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

	PR threads/18006
	* gdb.threads/clone-thread_db.c: New file.
	* gdb.threads/clone-thread_db.exp: New file.
2015-02-20 19:00:21 +00:00
Joel Brobecker f3978e9100 Document the GDB 7.9 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 7.9 released.
2015-02-20 21:20:23 +04:00
Steve Ellcey ffdf88ecd7 2015-02-19 Steve Ellcey <sellcey@imgtec.com>
* dtrace-probe.c (dtrace_process_dof_probe): Initialize arg.expr.
	(dtrace_get_probes) Change type of variable 'dof'.
2015-02-19 14:42:37 -08:00
Antoine Tremblay c9587f8823 Fix non executable stack handling when calling functions in the inferior.
When gdb creates a dummy frame to execute a function in the inferior,
the process may generate a SIGSEGV, SIGTRAP or SIGILL because the stack
is non executable. If the signal handler set in gdb has option print
or stop enabled for these signals gdb handles this correctly.

However, in the case of noprint and nostop the signal is short-circuited
and the inferior process is sent the signal directly. This causes the
inferior to crash because of gdb.

This patch adds a check for SIGSEGV, SIGTRAP or SIGILL so that these
signals are sent to gdb rather than short-circuited in the inferior.
gdb then handles them properly and the inferior process does not
crash.

This patch also fixes the same behavior in gdbserver.

Also added a small testcase to test the issue called catch-gdb-caused-signals.

This applies to Linux only, tested on Linux.

gdb/ChangeLog:
	PR breakpoints/16812
	* linux-nat.c (linux_nat_filter_event): Report SIGTRAP,SIGILL,SIGSEGV.
	* nat/linux-ptrace.c (linux_wstatus_maybe_breakpoint): Add.
	* nat/linux-ptrace.h: Add linux_wstatus_maybe_breakpoint.

gdb/gdbserver/ChangeLog:
	PR breakpoints/16812
	* linux-low.c (wstatus_maybe_breakpoint): Remove.
	(linux_low_filter_event): Update wstatus_maybe_breakpoint name.
	(linux_wait_1): Report SIGTRAP,SIGILL,SIGSEGV.

gdb/testsuite/ChangeLog:
	PR breakpoints/16812
	* gdb.base/catch-gdb-caused-signals.c: New file.
	* gdb.base/catch-gdb-caused-signals.exp: New file.
2015-02-19 11:04:21 -05:00
David Taylor 53cf2ee0d9 [gdb/ax] small "setv" fix and documentation's adjustment.
gdb/doc/agentexpr.texi documents the "setv" opcode as follow:

    @item @code{setv} (0x2d) @var{n}: @result{} @var{v}
    Set trace state variable number @var{n} to the value found on the top
    of the stack.  The stack is unchanged, so that the value is readily
    available if the assignment is part of a larger expression.  The
    handling of @var{n} is as described for @code{getv}.

The @item line is incorrect (and does not match with its
description), so this patch fixes it.

Additionally, in gdb/common/ax.def we find the line:

    DEFOP (setv, 2, 0, 0, 1, 0x2d)

From the comment earlier in the file:

       Each line is of the form:

       DEFOP (name, size, data_size, consumed, produced, opcode)
[...]
       CONSUMED is the number of stack elements consumed.
       PRODUCED is the number of stack elements produced.

which is saying that nothing is consumed and one item is produced.
Both should be 0 or both should be 1.

This patch sets them both to 1, which seems better since if nothing
is on the stack an error will occur.

gdb/ChangeLog:

        * common/ax.def (setv): Fix consumed entry in setv DEFOP.

gdb/doc/ChangeLog:

        * agentexpr.texi (Bytecode Descriptions): Fix summary line for setv.

Tested on x86_64-linux.
2015-02-19 19:04:16 +04:00
Patrick Palka acfe0940a8 Add missing gdb/ChangeLog entry for previous change. 2015-02-18 18:51:14 -05:00