Commit Graph

37597 Commits

Author SHA1 Message Date
Markus Metzger a038fa3e14 stack: check frame_unwind_caller_id
Callers of frame_unwind_caller_* functions are supposed to check
frame_unwind_caller_id.

Add such a check to frame_info and treat an invalid caller ID as if the caller
PC were not available.

gdb/
	* stack.c (frame_info): Check frame_unwind_caller_id.
2016-02-12 09:46:31 +01:00
Markus Metzger 2f3ef606b9 frame: add skip_tailcall_frames
Add a new function skip_tailcall_frames to skip TAILCALL_FRAME frames.

gdb/
	* frame.h (skip_tailcall_frames): New.
	* frame.c (skip_tailcall_frames): New.
	(frame_pop): Call skip_tailcall_frames.
	* infcmd.c (finish_command): Call skip_tailcall_frames.
2016-02-12 09:44:42 +01:00
Wei-cheng Wang 7cae9051ed gdbserver: Remove tracepoint_action ops.
This patch removes 'ops' in tracepoint, and uses helper functions to
call action handler instead.

The object layout of tracepoint_action may differ in gdbserver and
inferior depend on the alignment rule of target ABI, so gdbserver cannot
simply copy the object from its memory to inferior memory.

For example,

  struct collect_memory_action
  {
    struct tracepoint_action base;
    {
      #ifndef IN_PROCESS_AGENT
      const struct tracepoint_action_ops *ops;
      #if
  -   char type;
  | }
  | ULONGEST addr;
  | ULONGEST len;
  - int32_t basereg;
  };

and on PowerPC,

     Wihtout ops           with ops
      0   1   2   3         0   1   2   3
   0 |type| PADDING...    0 |ops-------------|
   4 .................    4 |type|PADDING....|
   8 |addr------------    8 |addr-------------
   c ----------------|    c -----------------|
  10 |len-------------   10 |len--------------
  14 ----------------|   14 -----------------|
  18 |basereg--------|   18 |basereg---------|

so we cannot directly copy the object.

In this patch, 'ops' is removed in order to make the objects identical.

gdb/gdbserver/ChangeLog:

2016-02-11  Wei-cheng Wang  <cole945@gmail.com>
	    Marcin Kościelnicki  <koriakin@0x04.net>

	* tracepoint.c (struct tracepoint_action_ops): Remove.
	(struct tracepoint_action): Remove ops.
	(m_tracepoint_action_download, r_tracepoint_action_download)
	(x_tracepoint_action_download, l_tracepoint_action_download): Adjust
	size and offset accordingly.
	(m_tracepoint_action_ops, r_tracepoint_action_ops)
	(x_tracepoint_action_ops, l_tracepoint_action_ops): Remove.
	(tracepoint_action_send, tracepoint_action_download): New functions.
	Helpers for trace action handlers.
	(add_tracepoint_action): Remove setup actions ops.
	(download_tracepoint_1, tracepoint_send_agent): Call helper functions.
2016-02-11 23:21:48 +01:00
Pedro Alves acc23c113a Add missing quotes to gdb/testsuite/README
gdb/testsuite/ChangeLog:
2016-02-11  Pedro Alves  <palves@redhat.com>

	* README (Parallel testing): Add missing double quotes.
2016-02-11 19:55:46 +00:00
Pedro Alves e352bf0a3c Support 'make check-parallel' in gdb's build dir
Currently, you can cd to the gdb/testsuite/ dir and use
make check-parallel, instead of using FORCE_PARALLEL:

 $ make -j8 check-parallel RUNTESTFLAGS="--target_board=native-gdbserver"
 $ make -j8 check RUNTESTFLAGS="--target_board=native-gdbserver" FORCE_PARALLEL=1

But you can't do that in the build/gdb/ dir:

 $ make check-parallel RUNTESTFLAGS="--target_board=native-gdbserver"
 make: *** No rule to make target `check-parallel'.  Stop.

I find check-parallel a bit more convenient, and more typo-proof, so
this patch makes it work from the gdb build dir too.

While documenting this in testsuite/README, I found that the parallel
testing mode would better be pulled out to its own section and
extended.

gdb/ChangeLog:
2016-02-11  Pedro Alves  <palves@redhat.com>

	* Makefile.in (check-parallel): New rule.

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

	* README (Parallel testing): New section.
	(GDB_PARALLEL): Rewrite.
	(FORCE_PARALLEL): Document.
2016-02-11 19:36:39 +00:00
Simon Marchi bec2ab5a15 arm-tdep.c: Remove unused variables
Just a little bit of cleanup.

gdb/ChangeLog:

	* arm-tdep.c (arm_skip_prologue): Remove unused variables.
	(arm_analyze_prologue): Likewise.
	(arm_scan_prologue): Likewise.
	(arm_m_exception_prev_register): Likewise.
	(arm_copy_block_xfer): Likewise.
	(thumb2_copy_block_xfer): Likewise.
	(arm_decode_miscellaneous): Likewise.
	(arm_decode_ld_st_word_ubyte): Likewise.
	(arm_decode_svc_copro): Likewise.
	(thumb2_decode_svc_copro): Likewise.
	(thumb_copy_16bit_ldr_literal): Likewise.
	(thumb_copy_pop_pc_16bit): Likewise.
	(decode_thumb_32bit_ld_mem_hints): Likewise.
	(arm_show_force_mode): Likewise.
	(_initialize_arm_tdep): Likewise.
	(arm_record_strx): Likewise.
	(arm_record_extension_space): Likewise.
	(arm_record_data_proc_misc_ld_str): Likewise.
	(arm_record_exreg_ld_st_insn): Likewise.
	(arm_record_vfp_data_proc_insn): Likewise.
	(arm_record_coproc_data_proc): Likewise.
	(thumb_record_misc): Likewise.
	(thumb_record_ldm_stm_swi): Likewise.
	(thumb2_record_ld_st_dual_ex_tbb): Likewise.
	(thumb2_record_ld_mem_hints): Likewise.
	(thumb2_record_lmul_lmla_div): Likewise.
	(thumb2_record_asimd_struct_ld_st): Likewise.
	(arm_process_record): Likewise.
2016-02-11 14:09:25 -05:00
Simon Marchi 2ba163c8d1 arm-tdep.c: Remove unused arm_displaced_step_copy_insn
This function is never used, since it is superseded by
arm_linux_displaced_step_copy_insn.

gdb/ChangeLog:

	* arm-tdep.c (arm_displaced_step_copy_insn): Remove.
	(ARM displaced stepping support): Remove reference to
	arm_displaced_step_copy_insn in comment.
	* arm-tdep.h (arm_displaced_step_copy_insn): Remove.
	* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Remove
	reference to arm_displaced_step_copy_insn in comment.
2016-02-11 14:08:53 -05:00
Simon Marchi 615234c107 arm-tdep.c: Change type of insn parameters
Almost obvious... change the type of some insn parameters, so that it
matches the rest of the code.

gdb/ChangeLog:

	* arm-tdep.c (thumb_copy_unmodified_16bit): Change type of insn.
	(thumb_copy_b): Likewise.
	(arm_decode_b_bl_ldmstm): Likewise.
	(thumb_copy_16bit_ldr_literal): Likewise.
	(thumb_copy_pop_pc_16bit): Likewise.
2016-02-11 13:21:32 -05:00
Marcin Kościelnicki 9f5fed7852 gdb.trace: Add a testcase for tdesc in tfile.
This tests whether $ymm15 can be correctly collected and printed from
tfile.  It covers:

- storing tdesc in tfile (without that, $ymm15 doesn't exist)
- ax_pseudo_register_collect for x86 (without that, $ymm15 cannot be
  collected)
- register order in tfile_fetch_registers (without that, $ymm15h is
  fetched from wrong position)
- off-by-one in tfile_fetch_registers (without that, $ymm15h is
  incorrectly considered to be out of bounds)
- using proper tdesc in encoding tracepoint actions (without that,
  internal error happens due to $ymm15h being considered unavailable)

gdb/testsuite/ChangeLog:

	* gdb.trace/tfile-avx.c: New test.
	* gdb.trace/tfile-avx.exp: New test.
2016-02-11 15:16:31 +01:00
Antoine Tremblay 82e9becd8a Use the target architecture when encoding tracepoint actions
This patch uses the target architecture rather then the objfile
architecture when encoding tracepoint actions.

The target architecture may contain additional registers. E.g. ARM VFP
registers. This information is needed to allow their collection. Since we
can never know whether the registers numbers in the target match the
binary's we have to use tdesc here.

One note about combined debuggers / multi-inferior from Pedro Alves:

In the combined debugger case taking Cell as the practical example that
gdb supports currently:

In that case, the main target_gdbarch() will be powerpc, but you may have set a
tracepoint on _spu_ code, which has a different gdbarch.  so for that case,
target_gdbarch would be wrong.  I think that in that case, we'd need to
find __the_ target/tdesc gdbarch that is (bfd) compatible with the
objfile's gdbarch.

I think cell/spu gdbserver doesn't support tracepoints, so we can ignore
this for now.

The multi-inferior/process case is somewhat related, but its simpler.
each inferior has its own gdbarch.

That is, target_gdbarch depends on the current inferior selected.
In fact, that just returns inferior->gdbarch nowaways.

No regressions, tested on ubuntu 14.04 ARMv7 and x86.
With gdbserver-{native,extended} / { -marm -mthumb }

gdb/ChangeLog:

	* tracepoint.c (encode_actions_1): Use target_gdbarch () rather
	than loc->gdbarch.
2016-02-11 08:14:35 -05:00
Marcin Kościelnicki 5ac87a997f gdb.trace: Read XML target description from tfile.
gdb/ChangeLog:

	* tracefile-tfile.c (trace_tdesc): New static variable.
	(tfile_open): Clear trace_tdesc, call target_find_description.
	(tfile_interp_line): Recognize tdesc lines.
	(tfile_close): Clear trace_tdesc.
	(tfile_xfer_partial_features): New function.
	(tfile_xfer_partial): Call tfile_xfer_partial_features.
	(tfile_append_tdesc_line): New function.
2016-02-10 23:31:13 +01:00
Marcin Kościelnicki 18d3cec54e gdb.trace: Save XML target description in tfile.
gdb/ChangeLog:

	* ctf.c (ctf_write_tdesc): New function.
	(ctf_write_ops): Wire in ctf_write_tdesc.
	* tracefile-tfile.c (tfile_write_tdesc): New function.
	(tfile_write_ops): Wire in tfile_write_tdesc.
	* tracefile.c (trace_save): Call write_tdesc method.
	* tracefile.h (struct trace_file_write_ops): Add write_tdesc method.
	* xml-tdesc.c (target_fetch_description_xml): New function.
	* xml-tdesc.h: Add target_fetch_description_xml prototype.
2016-02-10 23:31:11 +01:00
Yao Qi 9f6a71b4bf Clear *VAL in regcache_raw_read_unsigned
We have function regcache_raw_read_unsigned defined in both GDB and
GDBserver, so that it is used in common like this,

  ULONGEST value;
  status = regcache_raw_read_unsigned (regcache, regnum, &value);

'value' is correctly set in GDB side, but may not be correctly set
in GDBserver, because &value is passed in regcache_raw_read_unsigned
but collect_register may only set part of the whole variable.  In my
test, I see the top half of 'value' is garbage.  This patch fixes this
problem by clearing *VAL before calling collect_register.

gdb/gdbserver:

2016-02-10  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache_raw_read_unsigned): Clear *VAL.
2016-02-10 16:40:52 +00:00
Simon Marchi 550dc4e266 arm-tdep.c: Fix typo
unpriveleged -> unprivileged

gdb/ChangeLog:

	* arm-tdep.c (arm_copy_extra_ld_st): Fix "unpriveleged" typo.
	(arm_decode_dp_misc): Likewise.
2016-02-10 10:10:18 -05:00
Marcin Kościelnicki 62e5fd57bc gdb/x86: Implement ax_pseudo_register_collect hook.
Makes "collect $ymm15" action work.

gdb/ChangeLog:

	* amd64-tdep.c (amd64_ax_pseudo_register_collect): New function.
	(amd64_init_abi): Fill ax_pseudo_register_collect hook.
	* gdb/i386-tdep.c (i386_pseudo_register_read_into_value): Remove
	misleading comment.
	(i386_pseudo_register_write): Ditto.
	(i386_ax_pseudo_register_collect): New function.
	(i386_gdbarch_init): Fill ax_pseudo_register_collect hook.
	* i386-tdep.h: Add i386_ax_pseudo_register_collect prototype.
2016-02-10 15:30:31 +01:00
Marcin Kościelnicki e909d859f5 gdb.trace: Use g packet order in tfile_fetch_registers.
tfile_fetch_registers currently wrongly fetches registers using
gdb order instead of g packet order.  On x86_64 with AVX, this causes
problems with ymm*h and orig_rax registers: gdb has ymm*h first, while
g packet has orig_rax first.

gdb/ChangeLog:

	* tracefile-tfile.c (tfile_fetch_registers): Use g packet order
	instead of gdb order.

gdb/doc/ChangeLog:

	* gdb.texinfo (Trace File Format): Remove misleading information
	about register block ordering.
2016-02-10 15:30:13 +01:00
Marcin Kościelnicki 473b99e572 gdb.trace: Fix off-by-one in tfile_fetch_registers.
This resulted in the last register being considered unavailable.
On plain x86_64 (without AVX), this happened to be orig_rax.

gdb/ChangeLog:

	* tracefile-tfile.c (tfile_fetch_registers): Fix off-by-one in bounds
	check.
2016-02-10 14:50:22 +01:00
Joel Brobecker 1233c0bae6 Update NEWS post GDB 7.11 branch creation.
gdb/ChangeLog:

	* NEWS: Create a new section for the next release branch.
	Rename the section of the current branch, now that it has
	been cut.
2016-02-10 07:28:01 +04:00
Joel Brobecker d1dc094269 Bump version to 7.11.50.DATE-git.
Now that the GDB 7.11 branch has been created, we can
bump the version number.

gdb/ChangeLog:

	GDB 7.11 branch created (9ef9e6a6a0):
	* version.in: Bump version to 7.11.50.DATE-git.
2016-02-10 07:20:26 +04:00
Keith Seitz 9ef9e6a6a0 breakpoints/19546: Fix crash after updating breakpoints
One of the last checks update_breakpoints_after_exec does while looping
over the list of breakpoints is check that the breakpoint has a valid
location spec. It uses event_location_empty_p to check if the location spec
is "empty", and if it is, the breakpoint is deleted.

momentary_breakpoint types rely on setting the breakpoint structure's
location spec to NULL, thereby causing an update to delete the breakpoint.
However, event_location_empty_p assumed that locations were never NULL.
As a result, GDB would crash dereferencing a NULL pointer whenever
update_breakpoints_after_exec would encounter a momentary_breakpoint.

This patch creates a new wrapper/helper function which tests that the given
breakpoint's location spec is non-NULL and if it is not "empty"
or "unspecified."

gdb/ChangeLog

	PR breakpoints/19546
	* breakpoint.c (breakpoint_event_location_empty_p): New function.
	(update_breakpoints_after_exec, bkpt_re_set): Use this new function
	instead of event_location_empty_p.

gdb/testsuite/ChangeLog

	PR breakpoints/19546
	* gdb.base/infcall-exec.c: New file.
	* gdb.base/infcall-exec2.c: New file.
	* gdb.base/infcall-exec.exp: New file.
2016-02-09 16:04:45 -08:00
Keith Seitz 39a67dc4f7 Enable/update legacy linespecs in MI.
MI is currently using string_to_event_location to enable the use of legacy
linespecs, but using this function (until this patchset) had the (as yet
unnoticed) side effect of allowing both MI and CLI representation for
explicit locations.

This patch simply changes MI to use the same legacy linespec functions
that the python and guile interpreters use.  This eliminates the CLI syntax
for explicit locations (in MI).

gdb/ChangeLog

	* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Use
	string_to_event_location_basic instead of string_to_event_location.
2016-02-09 14:31:04 -08:00
Keith Seitz a96e36da2f Use string_to_event_location_basic in guile.
This patch, analogous to the previous python patch, implements proper
legacy linespec support in guile code using the newly introduced
string_to_event_location_basic.

gdb/ChangeLog

	* guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Skip
	leading whitespace and use string_to_event_location_basic instead
	of new_linespec_location.

gdb/testsuite/ChangeLog

	* gdb.guile/scm-breakpoint.exp (test_bkpt_address): New procedure.
	(toplevel): Call test_bkpt_address.
2016-02-09 14:29:21 -08:00
Keith Seitz 9f61929fd8 python/19506 -- gdb.Breakpoint address location regression
Now that "legacy" linespecs benefit from consolidated support in
string_to_event_location_basic, python's Breakpoint command should use this
function to turn strings into event locations.

As a result, this patch fixes python/19506. Before:

(gdb) python gdb.Breakpoint("*main")
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: Function "*main" not defined.
Error while executing Python code.

After:

(gdb) python gdb.Breakpoint("*main")
Breakpoint 1 at 0x4005fb: file ../../../src/gdb/testsuite/gdb.python/py-breakpoint.c, line 32.

gdb/ChangeLog

	PR python/19506
	* python/py-breakpoint.c (bppy_init): Use
	string_to_event_location_basic instead of new_linespec_location.

gdb/testsuite/ChangeLog

	PR python/19506
	* gdb.python/py-breakpoint.exp (test_bkpt_address): New procedure.
	(toplevel): Call test_bkpt_address.
2016-02-09 14:27:50 -08:00
Keith Seitz eeb1af437c Refactor string_to_event_location for legacy linespec support.
This patch refactors string_to_event_location, breaking it into two
separate functions:

1) string_to_event_location_basic
A "basic" string parser that implements support for "legacy" linespecs
(linespec, address, and probe locations).  This function is intended to
be used by any UI wishing/needing to support this legacy behavior.

2) string_to_event_location
This is now intended as a CLI-only function which adds explicit location
parsing in a CLI-appropriate manner (in the form of traditional option/value
pairs).

Together these patches serve to simplify string-to-event location parsing
for all existing non-CLI interfaces (MI, guile, and python).

gdb/ChangeLog

	* location.c (string_to_explicit_location): Note that "-p" is
	reserved for probe locations and return NULL for any input
	that starts with that.
	(string_to_event_location): Move "legacy" linespec code to ...
	(string_to_event_location_basic): ... here.
	* location.h (string_to_event_location): Update comment.
	(string_to_event_location_basic): New function.
2016-02-09 10:02:53 -08:00
Simon Marchi 1e94266c4d Modernize configure.ac's
Using AC_OUTPUT with arguments has been deprecated for some time in
autoconf, even in version 2.64, which we are using.  This change should
not affect functionality.

I also removed the "exit 0"'s, they shouldn't be necessary.

gdb/ChangeLog:

	* configure.ac: Use AC_CONFIG_FILES instead of passing arguments
	to AC_OUTPUT.  Remove "exit 0" at the end.
	* configure: Regenerate.

gdb/testsuite/ChangeLog:

	* configure.ac: Use AC_CONFIG_FILES instead of passing arguments
	to AC_OUTPUT.
	* configure: Regenerate.

gdb/gdbserver/ChangeLog:

	* configure.ac: Use AC_CONFIG_FILES instead of passing arguments
	to AC_OUTPUT.
	* configure: Regenerate.
2016-02-09 09:01:58 -05:00
Pedro Alves 2a7f3dffce Fix PR19548: Breakpoint re-set inserts breakpoints when it shouldn't
PR19548 shows that we still have problems related to 13fd3ff34329:

 [PR17431: following execs with "breakpoint always-inserted on"]
 https://sourceware.org/ml/gdb-patches/2014-09/msg00733.html

The problem this time is that we currently update the global location
list and try to insert breakpoint locations after re-setting _each_
breakpoint in turn.

Say:

 - We have _more_ than one breakpoint set.  Let's assume 2.

 - There's a breakpoint with a pre-exec address that ends up being an
   unmapped address after the exec.

 - That breakpoint is NOT the first in the breakpoint list.

Then when handling an exec, and we re-set the first breakpoint in the
breakpoint list, we mistakently try to install the old pre-exec /
un-re-set locations of the other breakpoint, which fails:

 (gdb) continue
 Continuing.
 process 28295 is executing new program: (...)/execl-update-breakpoints2
 Error in re-setting breakpoint 1: Warning:
 Cannot insert breakpoint 2.
 Cannot access memory at address 0x1000764

 Breakpoint 1, main (argc=1, argv=0x7fffffffd368) at /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/execl-update-breakpoints.c:34
 34        len = strlen (argv[0]);
 (gdb)

Fix this by deferring the global location list update till after all
breakpoints are re-set.

Tested on x86_64 Fedora 20, native and gdbserver.

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

	PR breakpoints/19548
	* breakpoint.c (create_overlay_event_breakpoint): Don't update
	global location list here.
	(create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint, create_jit_event_breakpoint)
	(update_breakpoint_locations):
	(breakpoint_re_set): Update global location list after all
	breakpoints are re-set.

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

	PR breakpoints/19548
	* gdb.base/execl-update-breakpoints.c (some_function): New
	function.
	(main): Call it.
	* gdb.base/execl-update-breakpoints.exp: Add a second breakpoint.
	Tighten expected GDB output.
2016-02-09 12:12:17 +00:00
Simon Marchi 8adce0342f Fix siginfo C++ build error
Change the signature of gdbserver's siginfo_fixup functions so that it's
in line with gdb's.  This gets rid of the following build error in C++:

  /home/emaisin/src/binutils-gdb/gdb/gdbserver/linux-x86-low.c: In function ‘int x86_siginfo_fixup(siginfo_t*, void*, int)’:
  /home/emaisin/src/binutils-gdb/gdb/gdbserver/linux-x86-low.c:694:21: error: invalid conversion from ‘void*’ to ‘gdb_byte* {aka unsigned char*}’ [-fpermissive]
               FIXUP_32);
                       ^
  In file included from /home/emaisin/src/binutils-gdb/gdb/gdbserver/linux-x86-low.c:31:0:
  /home/emaisin/src/binutils-gdb/gdb/gdbserver/../nat/amd64-linux-siginfo.h:52:5: error:   initializing argument 2 of ‘int amd64_linux_siginfo_fixup_common(siginfo_t*, gdb_byte*, int, amd64_siginfo_fixup_mode)’ [-fpermissive]
   int amd64_linux_siginfo_fixup_common (siginfo_t *native, gdb_byte *inf,
       ^
  /home/emaisin/src/binutils-gdb/gdb/gdbserver/linux-x86-low.c:698:20: error: invalid conversion from ‘void*’ to ‘gdb_byte* {aka unsigned char*}’ [-fpermissive]
             FIXUP_X32);
                      ^
  In file included from /home/emaisin/src/binutils-gdb/gdb/gdbserver/linux-x86-low.c:31:0:
  /home/emaisin/src/binutils-gdb/gdb/gdbserver/../nat/amd64-linux-siginfo.h:52:5: error:   initializing argument 2 of ‘int amd64_linux_siginfo_fixup_common(siginfo_t*, gdb_byte*, int, amd64_siginfo_fixup_mode)’ [-fpermissive]
   int amd64_linux_siginfo_fixup_common (siginfo_t *native, gdb_byte *inf,
       ^

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (aarch64_linux_siginfo_fixup): Change
	void * to gdb_byte *.
	* linux-low.c (siginfo_fixup): Likewise.
	(linux_xfer_siginfo): Likewise.
	* linux-low.h (struct linux_target_ops) <siginfo_fixup>:
	Likewise.
	* linux-x86-low.c (x86_siginfo_fixup): Likewise.
2016-02-09 11:18:15 +00:00
Walfred Tedeschi c23bbc1cda Revert "Fix build breakage"
This reverts commit 222cab58b7.
2016-02-09 11:36:54 +01:00
Walfred Tedeschi 222cab58b7 Fix build breakage
Add a cast to reinterpret a void* as a gdb_byte*.

2016-02-09  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/gdbserver/ChangeLog:

        * linux-x86-low.c (x86_siginfo_fixup): Add cast to gdb_byte*.
2016-02-09 11:26:13 +01:00
Simon Marchi 2151ccc56c Always organize test artifacts in a directory hierarchy
When running tests in parallel, each test puts its generated files in a
different directory, under "outputs".  I think it would be nice if it
was always the case, as it would isolate the test cases a bit more.  An
artifact created by a test wouldn't get overwritten by another test.

Also, it makes it easier to clean up.  A lot of executables are left all
over the place because their names do not appear in gdb.*/Makefile.  If
everything is in "outputs", then we just have to delete that directory
(which we already do).

At the same time it makes the gdb.foo directories and their Makefiles
useless in the build directory, since they are pretty much only used for
cleaning.

What do you think?

gdb/testsuite/ChangeLog:

	* Makefile.in (ALL_SUBDIRS): Remove.
	(clean mostlyclean): Do not recurse in ALL_SUBDIRS.
	(distclean maintainer-clean realclean): Likewise.
	* configure.ac (AC_OUTPUT): Remove gdb.*/Makefile.
	* configure: Regenerate.
	* gdb.ada/Makefile.in: Delete.
	* gdb.arch/Makefile.in: Likewise.
	* gdb.asm/Makefile.in: Likewise.
	* gdb.base/Makefile.in: Likewise.
	* gdb.btrace/Makefile.in: Likewise.
	* gdb.cell/Makefile.in: Likewise.
	* gdb.compile/Makefile.in: Likewise.
	* gdb.cp/Makefile.in: Likewise.
	* gdb.disasm/Makefile.in: Likewise.
	* gdb.dlang/Makefile.in: Likewise.
	* gdb.dwarf2/Makefile.in: Likewise.
	* gdb.fortran/Makefile.in: Likewise.
	* gdb.gdb/Makefile.in: Likewise.
	* gdb.go/Makefile.in: Likewise.
	* gdb.guile/Makefile.in: Likewise.
	* gdb.java/Makefile.in: Likewise.
	* gdb.linespec/Makefile.in: Likewise.
	* gdb.mi/Makefile.in: Likewise.
	* gdb.modula2/Makefile.in: Likewise.
	* gdb.multi/Makefile.in: Likewise.
	* gdb.objc/Makefile.in: Likewise.
	* gdb.opencl/Makefile.in: Likewise.
	* gdb.opt/Makefile.in: Likewise.
	* gdb.pascal/Makefile.in: Likewise.
	* gdb.perf/Makefile.in: Likewise.
	* gdb.python/Makefile.in: Likewise.
	* gdb.reverse/Makefile.in: Likewise.
	* gdb.server/Makefile.in: Likewise.
	* gdb.stabs/Makefile.in: Likewise.
	* gdb.threads/Makefile.in: Likewise.
	* gdb.trace/Makefile.in: Likewise.
	* gdb.xml/Makefile.in: Likewise.
	* lib/gdb.exp (make_gdb_parallel_path): Add check for
	GDB_PARALLEL.
	(standard_output_file): Remove check for GDB_PARALLEL, always
	return path in outputs/$subdir/$testname.
2016-02-08 14:02:36 -05:00
Simon Marchi 437277d47a Fix in-tree, parallel running of Ada tests
While testing the following patch,

  [PATCH] Always organize test artifacts in a directory hierarchy
  https://sourceware.org/ml/gdb-patches/2016-01/msg00133.html

I noticed that it broke Ada testing.  This lead me to think that
parallel testing when building in-tree didn't work previously in Ada.
It is confirmed by this test:

$ make check TESTS="gdb.ada/fun_addr.exp" -j 2
...
Running ./gdb.ada/fun_addr.exp ...
FAIL: gdb.ada/fun_addr.exp: compilation foo.adb
...

This patch fixes in-tree parallel testing for Ada, and consequently
serial and parallel testing when the aforementioned patch is applied.

The problem originates from the fact that Ada support code cd's to the
builddir before compiling.  In itself it's not a problem, it allows to
place intermediate auto-generated files in that directory.  The Ada
compilation refers to the source file, which is in another directory,
only by its base name (e.g. foo.adb).  In serial mode, that worked
because builddir was the same as the source directory (e.g.
gdb.ada/fun_addr/).  In an out-of-tree build, it works because the
source directory is added as an include directory (note: this is not the
same $srcdir as autoconf's):

  set srcdir [file dirname $source]
  additional_flags=-I$srcdir

which becomes:

  additional_flags=-I/home/emaisin/build/binutils-gdb/gdb/testsuite/gdb.ada/fun_addr

However, when building in-tree, srcdir is relative: ./gdb.ada/fun_addr.
When using parallel or always-in-outputs-directory mode, we are cd'ed in
the outputs directory.  So -I$srcdir is relative to the current
directory, which is wrong.

To fix it, I made the TCL variable srcdir (set in site.exp, from which
everything else is derived) always absolute.  It is done by assigning
autoconf's abs_srcdir instead of autoconf's srcdir.  This way -I$srcdir
will always be good, regardless of where we cd'ed to.  A small apparent
change is that when running tests, DejaGnu will say:

  Running /tmp/binutils-gdb/gdb/testsuite/gdb.ada/fun_addr.exp ...

instead of

  Running ./gdb.ada/fun_addr.exp ...

I hope it's not too much of an annoyance.  I think that it should make
the testsuite a tiny bit more robust against other bugs of the same
class.

Regtested in & out of tree, only with native target.

gdb/testsuite/ChangeLog:

	* Makefile.in (abs_srcdir): Assign @abs_srcdir@.
	(site.exp): Assign abs_srcdir to tcl's srcdir.
2016-02-08 14:00:49 -05:00
Simon Marchi 5488790363 remote.c: Cleanup unused variables
I built remote.c with -Wunused, to check a function I was working on,
turns out there is a bunch of unused variables.

gdb/ChangeLog:

	* remote.c (remote_register_number_and_offset): Remove unused
	variable(s).
	(remote_thread_always_alive): Likewise.
	(remote_update_thread_list): Likewise.
	(process_initial_stop_replies): Likewise.
	(remote_start_remote): Likewise.
	(remote_check_symbols): Likewise.
	(discard_pending_stop_replies): Likewise.
	(process_stop_reply): Likewise.
	(putpkt_binary): Likewise.
	(getpkt): Likewise.
	(remote_add_target_side_condition): Likewise.
	(remote_insert_breakpoint): Likewise.
	(remote_supports_stopped_by_sw_breakpoint): Likewise.
	(remote_supports_stopped_by_hw_breakpoint): Likewise.
	(remote_xfer_partial): Likewise.
	(remote_read_btrace): Likewise.
	(remote_async_serial_handler): Likewise.
	(remote_thread_events): Likewise.
	(_initialize_remote): Likewise.
2016-02-08 12:57:08 -05:00
Simon Marchi 30914ca8c0 varobj: Cleanup dead code
This patch removes some dead code.

I noticed that varobj_delete was always called with dellist == NULL, so
I started removing that parameter.  That allows removing a good chunk of
the code in varobj_delete, making it almost trivial.  We can also remove
the resultp parameters in that whole trail.  In turn, this shows that
struct cpstack, cppush and cppop were only used fo that mechanism, so
they can be removed as well.

I also moved the function comment to the header file to comply with
today's guideline, even though the rest of the file does not respect it
(yet).

gdb/ChangeLog:

	* varobj.h (varobj_delete): Remove dellist parameter, update and
	move documentation here.
	* varobj.c (struct cpstack, cppush, cppop): Remove.
	(delete_variable): Remove resultp (first) parameter.
	(delete_variable_1): Likewise.
	(varobj_delete): Remove dellist parameter and unused code.
	(update_dynamic_varobj_children): Adjust varobj_delete call.
	(update_type_if_necessary): Likewise.
	(varobj_set_visualizer): Likewise.
	(varobj_update): Likewise.
	(value_of_root): Likewise.
	(varobj_invalidate_iter): Likewise.
	* mi/mi-cmd-var.c (mi_cmd_var_delete): Likewise.
2016-02-07 09:45:02 -05:00
Yao Qi 31d913c7e4 [testsuite] Remove BASEDIR
BASEDIR was added by https://sourceware.org/ml/gdb-patches/2013-10/msg00587.html
in order to handle the different directory layout in serial testing
and parallel testing.  BASEDIR is "gdb.base" in serial testing and is
"outputs/gdb.base/TESTNAME" in parallel testing.  However, it doesn't
work if the GDBserver is in remote target, like this,

$ make check RUNTESTFLAGS='--target_board=remote-gdbserver-on-localhost foll-vfork.exp foll-exec.exp'
FAIL: gdb.base/foll-exec.exp: continue to first exec catchpoint (the program exited)
FAIL: gdb.base/foll-vfork.exp: exec: vfork and exec child follow, to main bp: continue to bp (the program exited)
FAIL: gdb.base/foll-vfork.exp: exec: vfork child follow, finish after tcatch vfork: finish (the program exited)
FAIL: gdb.base/foll-vfork.exp: exec: vfork relations in info inferiors: continue to bp (the program exited)

these tests fail because the executable can't be found.  With target
board native-gdbserver, the program is spawned this way,

 spawn ../gdbserver/gdbserver --once :2347 /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/gdb.base/foll-vfork

so BASEDIR is correct.  However, with target board
remote-gdbserver-on-localhost, the program is spawned

  spawn /usr/bin/ssh -l yao localhost /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/../gdbserver/gdbserver --once :2346 /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/gdb.base/foll-vfork

so BASEDIR (either "gdb.base" or "outputs/gdb.base/TESTNAME") makes no
sense.

I had a fix that pass absolute directory to BASEDIR, but it assumes
that directory structure is the same on build and target, and it
doesn't work in remote host case.  The current fix in this patch is
to get the directory from argv[0].  In any case, the program to be
exec'ed is at the same directory with the main program.

Note that these tests do "next N" to let program stop at the desired
line, but it is fragile, because GDB for different targets may skip
function prologue slightly differently, so I replace some of them by
"tbreak on LINE NUMBER and continue".

gdb/testsuite:

2016-02-04  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/foll-exec-mode.c: Include limits.h.
	(main): Add parameters argc and argv.  Get directory from
	argv[0].
	* gdb.base/foll-exec-mode.exp: Don't pass -DBASEDIR in
	compilation.
	* gdb.base/foll-exec.c: Include limits.h.
	(main): Add parameters argc and argv.
	Get directory from argv[0].
	* gdb.base/foll-exec.exp: Don't pass -DBASEDIR in compilation.
	Adjust tests on the number of lines as source code changed.
	* gdb.base/foll-vfork-exit.c: Include limits.h.
	(main): Add one line of statement before vfork.
	* gdb.base/foll-vfork.c: Include limits.h and string.h.
	(main): Add parameters argc and argv.  Get directory from
	argv[0].
	* gdb.base/foll-vfork.exp: Don't pass -DBASEDIR in compilation.
	(setup_gdb): Set tbreak to skip some source lines.
	* gdb.multi/bkpt-multi-exec.c: Include limits.h.
	(main): Add parameters argc and argv.  Get directory from
	argv[0].
	* gdb.multi/bkpt-multi-exec.exp: Don't pass -DBASEDIR in
	compilation.
	* gdb.multi/multi-arch-exec.c: Include limits.h and string.h.
	(main): Add parameters argc and argv.  Get directory from
	argv[0].
	* gdb.multi/multi-arch-exec.exp: Don't pass -DBASEDIR in
	compilation.
2016-02-04 15:46:37 +00:00
Yao Qi e42e5352d1 waiting_for_stop_reply around remote_fileio_request
Hi,
I see this error when GDB connects with qemu,

(gdb) n
....
Sending packet: $vCont;c#a8...Ack
Packet received: Ffstat,00000001,f6fff038
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.

looks we don't set rs->waiting_for_stop_reply to zero
before handle fileio request,

 #10 0x00000000005edb64 in target_write (len=64, offset=4143968312, buf=0x7fffffffd570 "\375\377\377\377", annex=0x0, object=TARGET_OBJECT_MEMORY,
    ops=<optimised out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/target.c:1922
 #11 target_write_memory (memaddr=memaddr@entry=4143968312, myaddr=myaddr@entry=0x7fffffffd6a0 "", len=len@entry=64)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/target.c:1500
 #12 0x00000000004b2b41 in remote_fileio_func_fstat (buf=0x127b258 "") at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1037
 #13 0x00000000004b1878 in do_remote_fileio_request (uiout=<optimised out>, buf_arg=buf_arg@entry=0x127b240)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1204
 #14 0x00000000005b8c7c in catch_exceptions_with_msg (func_uiout=<optimised out>, func=func@entry=0x4b1800 <do_remote_fileio_request>,
    func_args=func_args@entry=0x127b240, gdberrmsg=gdberrmsg@entry=0x0, mask=mask@entry=RETURN_MASK_ALL)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:187
 #15 0x00000000005b8dea in catch_exceptions (uiout=<optimised out>, func=func@entry=0x4b1800 <do_remote_fileio_request>, func_args=func_args@entry=0x127b240,
    mask=mask@entry=RETURN_MASK_ALL) at /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:167
 #16 0x00000000004b2fff in remote_fileio_request (buf=0x127b240 "Xf6fff038,0:", ctrlc_pending_p=0) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1255
 #17 0x0000000000496f12 in remote_wait_as (ptid=..., status=0x7fffffffdb20, options=1) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote.c:6997

however, we did set rs->waiting_for_stop_reply to zero before Luis's
patch https://sourceware.org/ml/gdb-patches/2015-10/msg00336.html

In fact, Luis's patch v1
https://sourceware.org/ml/gdb-patches/2015-08/msg00809.html is about
setting rs->waiting_for_stop_reply back to one after
remote_fileio_request, which is correct.  However during the review, the
patch is changed and ends up with "not setting rs->waiting_for_stop_reply
to zero".

I manually test GDB, but I don't have a way to run regression tests.

gdb:

2016-02-04  Yao Qi  <yao.qi@linaro.org>

	* remote.c (remote_wait_as): Set rs->waiting_for_stop_reply to
	0 before handling 'F' and set it back afterwards.
2016-02-04 15:09:09 +00:00
Simon Marchi 6456a18b71 ui-out.c: Remove unused enum
This is unused since 54eb231c4b, where
static arrays of ui_out_levels were replaced with vectors.

gdb/ChangeLog:

	* ui-out.c (MAX_UI_OUT_LEVELS): Remove.
2016-02-02 16:40:38 -05:00
Walfred Tedeschi 3f2f6cb5e8 Adaptation of siginfo fixup for the new bnd fields
New bnds fields will be always present for x86 architecture.
Fixup for compatibility layer 32bits has to be fixed.

It was added the nat_siginfo to serving as intermediate step
between kernel provided siginfo and the fix up routine.

When executing compat_siginfo_from_siginfo or
compat_x32_siginfo_from_siginfo first the buffer read from the kernel are
converted into the nat_signfo for homogenization, then the fields of
nat_siginfo are use to set the compat and compat_x32 siginfo fields.

In other to make this conversion independent of the system where gdb
is compiled the most complete version of the siginfo, named as native
siginfo, is used internally as an intermediate step.

Conversion using nat_siginfo is exemplified below:

compat_siginfo_from_siginfo or compat_x32_siginfo_from_siginfo:

buffer (from the kernel) -> nat_siginfo -> 32 / X32 siginfo
                      (memcpy)       (field by field)

siginfo_from_compat_x32_siginfo or siginfo_from_compat_siginfo:

32 / X32 siginfo -> nat_siginfo -> buffer (to the kernel)
          (field by field)    (memcpy)

Caveat: No support for MPX on x32.

2016-02-02  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* amd64-linux-siginfo.c (nat_siginfo_t, nat_sigval_t, nat_timeval):
	New types.
	(compat_siginfo): New bound fields added.
	(compat_x32_siginfo): New field added.
	(cpt_si_addr_lsb): New define.
	(compat_siginfo_from_siginfo): Use nat_siginfo.
	(siginfo_from_compat_siginfo): Use nat_siginfo.
	(compat_x32_siginfo_from_siginfo): Likewise.
	(siginfo_from_compat_x32_siginfo): Likewise.
2016-02-02 12:02:16 +01:00
Walfred Tedeschi 96b5c49fb1 Add bound related fields to the siginfo structure
Both Linux and glibc have introduced bound related fields in the
segmentation fault fields of the siginfo_t type. Add the new fields
to our x86's siginfo_t type too.

Kernel patch:
http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?id=ee1b58d36aa1b5a79eaba11f5c3633c88231da83

Glibc patch:
d4358b51c2

2016-02-02  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* linux-tdep.c (linux_get_siginfo_type): Add the _addr_bnd
	structure to the siginfo if extra_fields contains
	LINUX_SIGINFO_FIELD_ADDR_BND.
2016-02-02 11:58:36 +01:00
Walfred Tedeschi 190b495d47 Use linux_get_siginfo_type_with_fields for x86
Use linux_get_siginfo_type_with_fields for adding bound fields on
segmentation fault for i386/amd64 siginfo.

2016-02-02  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* linux-tdep.h (linux_get_siginfo_type_with_fields): Make extern.
	* linux-tdep.c (linux_get_siginfo_type_with_fields): Make extern.
	* i386-linux-tdep.h (x86_linux_get_siginfo_type): New
	function.
	* amd64-linux-tdep.c (amd64_linux_init_abi_common): Add
	x86_linux_get_siginfo_type for the amd64 abi.
	* i386-linux-tdep.c (x86_linux_get_siginfo_type): New
	function.
	(i386_linux_init_abi): Add new function at the i386 ABI
	initialization.
2016-02-02 11:50:17 +01:00
Walfred Tedeschi 43564574f1 Preparation for new siginfo on Linux
First add new structure and function to allow architecture customization
for the siginfo structure.

2016-01-15  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* linux-tdep.h (linux_siginfo_extra_field_values): New enum values.
	(linux_siginfo_extra_fields): New enum type.
	* linux-tdep.c (linux_get_siginfo_type_with_fields): New function.
	(linux_get_siginfo_type): Use new function.
2016-02-02 11:46:28 +01:00
Walfred Tedeschi 93813b37c8 Merge gdb and gdbserver implementations for siginfo
Extract the compatible siginfo handling from amd64-linux-nat.c and
gdbserver/linux-x86-low to a new file nat/amd64-linux-siginfo.c.

2016-02-02  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* nat/amd64-linux-siginfo.c: New file.
	* nat/amd64-linux-siginfo.h: New file.
	* Makefile.in (HFILES_NO_SRCDIR): Add nat/amd64-linux-siginfo.h.
	(amd64-linux-siginfo.o): New rule.
	* config/i386/linux64.mh (NATDEPFILES): Add amd64-linux-siginfo.o.
	* amd64-linux-nat.c (nat/amd64-linux-siginfo.h): New include.
	(compat_siginfo_from_siginfo, siginfo_from_compat_siginfo)
	(compat_x32_siginfo_from_siginfo, siginfo_from_compat_x32_siginfo)
	(compat_timeval, compat_sigval, compat_x32_clock, cpt_si_pid)
	(cpt_si_uid, cpt_si_timerid, cpt_si_overrun, cpt_si_status)
	(cpt_si_utime, cpt_si_stime, cpt_si_ptr, cpt_si_addr, cpt_si_band)
	(cpt_si_fd, si_timerid, si_overrun): Move to nat/amd64-linux-siginfo.c.

gdb/gdbserver/ChangeLog:

	* configure.srv (x86_64-*-linux*): Add amd64-linux-siginfo.o
	to srv_tgtobj.
	(i[34567]86-*-linux*): Add amd64-linux-siginfo.o
	to srv_tgtobj.
	* linux-x86-low.c [__x86_64__]: Include
	"nat/amd64-linux-siginfo.h".
	(compat_siginfo_from_siginfo, siginfo_from_compat_siginfo)
	(compat_x32_siginfo_from_siginfo, siginfo_from_compat_x32_siginfo)
	(compat_timeval, compat_sigval, compat_x32_clock, cpt_si_pid)
	(cpt_si_uid, cpt_si_timerid, cpt_si_overrun, cpt_si_status)
	(cpt_si_utime, cpt_si_stime, cpt_si_ptr, cpt_si_addr, cpt_si_band)
	(cpt_si_fd, si_timerid, si_overrun): Move from
	nat/amd64-linux-siginfo.c.
	* Makefile.in (amd64-linux-siginfo.o:): New rule.
2016-02-02 11:42:56 +01:00
Doug Evans 713cdcbf65 gdb.texinfo (Value Sizes): Fix typo. 2016-02-01 15:48:56 -08:00
Doug Evans 8244c20d7c gdb.texinfo (Skipping Over Functions and Files): Fix typo. 2016-02-01 15:39:23 -08:00
Doug Evans 9482b9fbb6 gdb.base/skip.exp: Clean up multiple references to same test name. 2016-02-01 15:22:05 -08:00
Pedro Alves ccb6afd6e3 Mention PR remote/19496 in gdb/testsuite/ChangeLog entry 2016-02-01 19:22:26 +00:00
Pedro Alves 6b2e4f10ae Test gdb.threads/forking-threads-plus-breakpoint.exp with displaced stepping off
This exposes the internal error Don mentioned in PR19496:

  (1) internal error --  gdb/target.c:2713: internal-error: Can't determine the current address space of thread

More analysis here:

  https://sourceware.org/ml/gdb-patches/2016-01/msg00685.html

The (now kfailed) internal error looks like:

 continue &
 Continuing.
 (gdb) PASS: gdb.threads/forking-threads-plus-breakpoint.exp: cond_bp_target=1: detach_on_fork=on: displaced=off: continue &
 [New Thread 2846.2847]
 (...)
 [New Thread 2867.2867]
 /home/pedro/gdb/mygit/src/gdb/target.c:2723: internal-error: Can't determine the current address space of thread Thread 2846.2846

 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) KFAIL: gdb.threads/forking-threads-plus-breakpoint.exp: cond_bp_target=1: detach_on_fork=on: displaced=off: inferior 1 exited (GDB internal error) (PRMS: remote/19496)
 Resyncing due to internal error.

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

	PR remote/19496
	* gdb.threads/forking-threads-plus-breakpoint.exp
	(displaced_stepping_supported): New global.
	(probe_displaced_stepping_support): New procedure.
	(do_test): Add 'displaced' parameter, and use it.
	(top level): Check for displaced stepping support.  Add displaced
	stepping on/off testing axis.
2016-02-01 18:48:04 +00:00
Andrew Burgess 37a8db1a33 gdb: Guard against undefined behaviour in mi-vla-fortran.exp
The test gdb.mi/mi-vla-fortran.exp reveals an issue with the DWARF
generated by gfortran.

In the test a pointer variable 'pvla2' is created:
    real, pointer :: pvla2 (:, :)

Initially this variable will be unassociated, so something like this:
    l = associated(pvla2)

should return false.

In the test gdb stops at a point _before_ pvla2 is associated with
anything, and we then try to print pvla2, the expectation is that gdb
should reply <not associated>.

The problem is that the data the DWARF directs gdb to read (to identify
if the variable is associated or not) is not initialised until the first
time pvla2 is accessed.

As a result gdb ends up reading uninitialised memory, sometimes this
uninitialised memory indicates the variable is associated (when it's
not).  This first mistake can lead to a cascade of errors, reading
uninitialised memory, with the result that gdb builds an invalid type to
associate with the variable pvla2.

In some cases, this invalid type can be very large, which when we try to
print pvla2 causes gdb to allocate a large amount of memory.

A recent commit added a new gdb variable 'max-value-size', which
prevents gdb from allocating values of extreme size.  As a result
directly trying to print pvla2 will now now error rather than allocate a
large amount of memory.

However, some of the later tests create a varobj for pvla2, and then
ask for the children of that varobj to be displayed.  In the case where
an invalid type has been computed for pvla2 then the number of children
can be wrong, and very big, in which case trying to display all of these
children can cause gdb to consume an excessive amount of memory.

This commit first detects if printing pvla2 triggers the max-value-size
error, if it does then we avoid all the follow on tests relating to the
unassociated pvla2, which avoids the second error printing the varobj
children.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-vla-fortran.exp: Add XFAIL for accessing unassociated
	pointer.  Don't perform further tests on the unassociated pointer
	if the first test fails.
2016-02-01 18:05:35 +00:00
Andrew Burgess 5fdf6324fa gdb: New set/show max-value-size command.
For languages with dynamic types, an incorrect program, or uninitialised
variables within a program, could result in an incorrect, overly large
type being associated with a value.  Currently, attempting to print such
a variable will result in gdb trying to allocate an overly large buffer.

If this large memory allocation fails then the result can be gdb either
terminating, or (due to memory contention) becoming unresponsive for the
user.

A new user visible variable in gdb helps guard against such problems,
two new commands are available:

   set max-value-size
   show max-value-size

The 'max-value-size' is the maximum size of memory in bytes that gdb
will allocate for the contents of a value.  Any attempt to allocate a
value with a size greater than this will result in an error.  The
initial default for this limit is set at 64k, this is based on a similar
limit that exists within the ada specific code.

It is possible for the user to set max-value-size to unlimited, in which
case the old behaviour is restored.

gdb/ChangeLog:

	* value.c (max_value_size): New variable.
	(MIN_VALUE_FOR_MAX_VALUE_SIZE): New define.
	(show_max_value_size): New function.
	(check_type_length_before_alloc): New function.
	(allocate_value_contents): Call check_type_length_before_alloc.
	(set_value_enclosing_type): Likewise.
	(_initialize_values): Add set/show handler for max-value-size.
	* NEWS: Mention new set/show command.

gdb/doc/ChangeLog:

	* gdb.texinfo (Value Sizes): New section.
	(Data): Add the 'Value Sizes' node to the menu.

gdb/testsuite/ChangeLog:

	* gdb.base/max-value-size.c: New file.
	* gdb.base/max-value-size.exp: New file.
	* gdb.base/huge.exp: Disable max-value-size for this test.
2016-02-01 18:05:35 +00:00
Simon Marchi 5fa1307022 Fix some comments in varobj.{c,h}
A few typos.  The comment about varobj_create has been misplaced since
the dawn of time.

gdb/ChangeLog:

	* varobj.h (struct varobj): Fix typos in comments.
	(struct lang_varobj_ops): Likewise.
	* varobj.c (VAROBJ_TABLE_SIZE): Likewise.
	(varobj_create): Move misplaced comment.
2016-01-31 22:24:17 -05:00
Simon Marchi a2e3e93f44 Fix two misleading indentation warnings
Two small changes so everything builds with latest GCC and its
-Wmisleading-indentation.

In the aarch64-tdep.c case, the two misindented lines should actually be
part of the for loop.  It looks like the indentation is all done using
spaces in that file though...  I fixed it (changed for tabs + spaces) for
the lines I touched.

In the xcoffread.c case, we can simply remove the braces and fix the
indentation.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_record_asimd_load_store): Add braces
	to for include additional lines.
	* xcoffread.c (scan_xcoff_symtab): Remove unnecessary braces.
2016-01-29 15:32:29 -05:00
Iain Buclaw 935c61442b Add ChangeLog entry for update to gdb.dlang demangle tests. 2016-01-28 21:53:51 +01:00
Iain Buclaw 4324c94dd7 Align dlang demangle tests with libiberty.
gdb/testsuite/ChangeLog:
	* gdb.dlang/demangle.exp: Sync tests from libiberty testsuite.
2016-01-28 21:47:44 +01:00
Simon Marchi 56e374a6bc Add rawmemchr to imported gnulib modules
rawmemchr is a dependency of strchrnul, so it should be explicitly
listed.

gdb/ChangeLog:

	* gnulib/import/Makefile.am: Regenerate.
	* gnulib/import/Makefile.in: Regenerate.
	* gnulib/import/m4/gnulib-cache.m4: Regenerate.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add rawmemchr.
2016-01-28 13:49:46 -05:00
Simon Marchi 8424cc978c Import strchrnul from gnulib and use it
For a forthcoming patch, I need a "skip_to_colon" function.  I noticed
there are two skip_to_semicolon (one in gdb and one in gdbserver). I
thought we could put it in common/, and generalize it for any character.
It turns out that the strchrnul function does exactly that.  I imported
the corresponding module from gnulib, for those systems that do not have
it.

There are probably more places where this function can be used instead
of doing the work by hand (I am looking at
remote-utils.c::look_up_one_symbol).

gdb/ChangeLog:

	* remote.c (skip_to_semicolon): Remove.
	(remote_parse_stop_reply): Use strchrnul instead of
	skip_to_semicolon.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	strchrnul.
	* gnulib/aclocal.m4: Regenerate.
	* gnulib/config.in: Regenerate.
	* gnulib/configure: Regenerate.
	* gnulib/import/Makefile.am: Regenerate.
	* gnulib/import/Makefile.in: Regenerate.
	* gnulib/import/m4/gnulib-cache.m4: Regenerate.
	* gnulib/import/m4/gnulib-comp.m4: Regenerate.
	* gnulib/import/m4/rawmemchr.m4: New file.
	* gnulib/import/m4/strchrnul.m4: New file.
	* gnulib/import/rawmemchr.c: New file.
	* gnulib/import/rawmemchr.valgrind: New file.
	* gnulib/import/strchrnul.c: New file.
	* gnulib/import/strchrnul.valgrind: New file.

gdb/gdbserver/ChangeLog:

	* server.c (skip_to_semicolon):  Remove.
	(process_point_options): Use strchrnul instead of
	skip_to_semicolon.
2016-01-28 10:28:56 -05:00
Yao Qi 7fe8399de9 [testsuite] Fix tiemout fail in gdb.fortran/vla-value.exp
In vla.f90, this single line of source is compiled to many instructions,

  vla2(:, :, :) = 1311                ! vla2-allocated

it is quite slow (about several minutes in my testing) to step over this
source line without range stepping.  This patch is to increase the timeout
value by 15 times, which is a magic number to make sure timeout disappears
in my testing with a slow arm-linux board.

gdb/testsuite:

2016-01-28  Yao Qi  <yao.qi@linaro.org>

	* gdb.fortran/vla-value.exp: Wrap test with with_timeout_factor.
2016-01-28 14:27:48 +00:00
Yao Qi 4a6a1ed4a1 Fix GDB crash in dprintf.exp
I see GDB crashes in dprintf.exp on aarch64-linux testing,

(gdb) PASS: gdb.base/dprintf.exp: agent: break 29
set dprintf-style agent^M
(gdb) PASS: gdb.base/dprintf.exp: agent: set dprintf style to agent
continue^M
Continuing.
ASAN:SIGSEGV
=================================================================
==22475==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x000000494820 sp 0x7fff389b83a0 bp 0x62d000082417 T0)
    #0 0x49481f in remote_add_target_side_commands /home/yao/SourceCode/gnu/gdb/git/gdb/remote.c:9190^M
    #1 0x49e576 in remote_add_target_side_commands /home/yao/SourceCode/gnu/gdb/git/gdb/remote.c:9174^M
    #2 0x49e576 in remote_insert_breakpoint /home/yao/SourceCode/gnu/gdb/git/gdb/remote.c:9240^M
    #3 0x5278b7 in insert_bp_location /home/yao/SourceCode/gnu/gdb/git/gdb/breakpoint.c:2734^M
    #4 0x52ac09 in insert_breakpoint_locations /home/yao/SourceCode/gnu/gdb/git/gdb/breakpoint.c:3159^M
    #5 0x52ac09 in update_global_location_list /home/yao/SourceCode/gnu/gdb/git/gdb/breakpoint.c:12686

the root cause of this problem in this case is about linespec and
symtab which produces additional incorrect location and a NULL is added to
bp_tgt->tcommands.  I posted a patch
https://sourceware.org/ml/gdb-patches/2015-12/msg00321.html to fix it
in linespec (the fix causes regression), but GDB still shouldn't add
NULL into bp_tgt->tcommands.  The logic of build_target_command_list
looks odd to me.  If we get something wrong in parse_cmd_to_aexpr (it
returns NULL), we shouldn't continue, instead we should set flag
null_command_or_parse_error.  This is what this patch does.  In the
meantime, we find build_target_condition_list has the same problem, so
fix it too.

gdb:

2016-01-28  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (build_target_command_list): Don't call continue
	if aexpr is NULL.
	(build_target_condition_list): Likewise.
2016-01-28 14:16:42 +00:00
Kevin Buettner 94715c1790 rx: Treat scalars larger than 8 bytes as aggregates in rx_push_dummy_call.
This patch fixes the following failures (which are also GDB internal errors)
for the -m64bit-doubles multilib:

FAIL: gdb.base/callfuncs.exp: p t_double_complex_values(dc1, dc2) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: p t_double_complex_values(dc3, dc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: p t_double_complex_many_args(dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: p t_double_complex_many_args(dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: p t_long_double_complex_values(ldc1, ldc2) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: p t_long_double_complex_values(ldc3, ldc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: p t_long_double_complex_many_args(ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: p t_long_double_complex_many_args(ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1,ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_double_complex_values(dc1, dc2) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_double_complex_values(dc3, dc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_double_complex_many_args(dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_double_complex_many_args(dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_long_double_complex_values(ldc1, ldc2) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_long_double_complex_values(ldc3, ldc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_long_double_complex_many_args(ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4) (GDB internal error)
FAIL: gdb.base/callfuncs.exp: noproto: p t_long_double_complex_many_args(ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1,ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1) (GDB internal error)
FAIL: gdb.base/varargs.exp: print find_max_double_real(4, dc1, dc2, dc3, dc4) (GDB internal error)
FAIL: gdb.base/varargs.exp: print find_max_long_double_real(4, ldc1, ldc2, ldc3, ldc4) (GDB internal error)

The assertion failure which is tripped is:

		  gdb_assert (arg_size <= 4);

While it may seem that the patch ought to disallow scalars larger than
4, scalars of size 8 are explicitly handled by the code elsewhere.

This came up because gcc has a complex type that is 16 bytes in length
when 64-bit doubles are used.

gdb/ChangeLog:

	* rx-tdep.c (rx_push_dummy_call): Treat scalars larger than 8
	bytes as aggregates.
2016-01-27 12:34:29 -07:00
Joel Brobecker c07af0ab29 Add Keith Seitz as Linespec Maintainer
gdb/ChangeLog:

        * MAINTAINERS (Responsible Maintainers): Add Keith Seitz as
        Linespec Maintainers.
2016-01-27 13:54:37 +04:00
Simon Marchi 41548caa9b Fix function comments
Two obvious fixes.

gdb/ChangeLog:

	* common/common-utils.c (skip_spaces): Fix comment.
	(skip_to_space_const): Likewise.
2016-01-26 16:30:03 -05:00
John Baldwin 67ebd9cbb1 Fix subject verb agreement in the description of several debug settings.
gdb/doc/ChangeLog:

	* gdb.texinfo (Debugging Output): Fix subject verb disagreements.
2016-01-26 10:48:53 -08:00
Yao Qi 4d18591be9 Remove argument pc in get_next_pcs
Nowadays, get_next_pcs in linux_target_ops has two parameters PC
and REGCACHE.  Parameter PC looks redundant because it can be go
from REGCACHE.  The patch is to remove PC from the arguments for
various functions.

gdb:

2016-01-26  Yao Qi  <yao.qi@linaro.org>

	* arch/arm-get-next-pcs.c (thumb_deal_with_atomic_sequence_raw):
	Remove argument pc.  Get pc by regcache_read_pc.  Callers updated.
	(arm_deal_with_atomic_sequence_raw): Likewise.
	(thumb_get_next_pcs_raw): Likewise.
	(arm_get_next_pcs_raw): Likewise.
	(arm_get_next_pcs): Remove argument pc.  Callers updated.
	* arch/arm-get-next-pcs.h (arm_get_next_pcs): Update declaration.

gdb/gdbserver:

2016-01-26  Yao Qi  <yao.qi@linaro.org>

	* linux-arm-low.c (arm_gdbserver_get_next_pcs): Remove argument pc.
	* linux-low.c (install_software_single_step_breakpoints): Don't
	call regcache_read_pc.
	* linux-low.h (struct linux_target_ops) <get_next_pcs>: Remove
	argument pc.
2016-01-26 14:08:26 +00:00
Yao Qi d80209703e [GDBserver] Use regcache_read_pc in install_software_single_step_breakpoints
In install_software_single_step_breakpoints, we've got the regcache
of current_thread, so we don't have to bother get_pc to get pc,
instead we can get pc from regcache directly.  Note that the callers
of install_software_single_step_breakpoints have already switched
current_thread to LWP.

Since the pc is got from regcache_read_pc, in the next patch, we can
get pc inside the implementation of *the_low_target.get_next_pcs and
stop passing pc to *the_low_target.get_next_pcs.

gdb/gdbserver:

2016-01-26  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (install_software_single_step_breakpoints): Call
	regcache_read_pc instead of get_pc.
2016-01-26 14:08:26 +00:00
Yao Qi 8b20733984 [GDBserver] Block and unblock SIGIO
Nowadays, GDBserver disables async io (by ignoring SIGIO) when process
a serial event, and enables async io (by installing signal handler) when
resume the inferior and wait.  GDBserver may miss SIGIO (by interrupt)
and doesn't process SIGIO in time, which is shown by
gdb.base/interrupt-noterm.exp.  In the test, GDB sends "continue &" and
then "interrupt".  if '\003' arrives at a period between GDBserver
receives vCont;c and enables async io, SIGIO is ignored because signal
handler isn't installed.  GDBserver waits for the inferior and can not
notice '\003' until it returns from wait.

This patch changes the code to install SIGIO handler early, but block
and unblock SIGIO as needed.  In this way, we don't remove SIGIO
handler, so SIGIO can't be ignored.  However, GDBserver needs to
remove the signal handler when connection is closed.

gdb/gdbserver:

2016-01-26  Yao Qi  <yao.qi@linaro.org>

	* remote-utils.c (remote_close) [!USE_WIN32API]: Ignore SIGIO.
	(unblock_async_io): Rename to ...
	(block_unblock_async_io): ... it.  New function.
	(enable_async_io): Don't install SIGIO handler.  Unblock it
	instead.
	(disable_async_io): Don't ignore SIGIO.  Block it instead.
	(initialize_async_io): Install SIGIO handler.  Don't call
	unblock_async_io.
2016-01-26 13:50:22 +00:00
Yao Qi 18879fef17 [GDBserver] Check input interrupt after reading in a packet
GDBserver may read some packet together with '\003' in one go.  We've
already checked '\003' first when reading packet by my patch,

  Check input interrupt first when reading packet
  https://sourceware.org/ml/gdb-patches/2016-01/msg00057.html

but if we don't check '\003' *after* each packet, the interrupt will
be processed next time GDBserver reads from the buffer, so that the
interrupt isn't processed in time.  For example, GDB sends vCont;c and
interrupt (see gdb.base/interrupt-noterm.exp), we'll resume the
inferior and wait once packet vCont;c is seen.  If we don't check the
interrupt character after vCont;c packet, interrupt character will stay
in the buffer unattended until GDBserver returns from the wait, which
may take a while.  Note that since we've read '\003' from file
descriptor, SIGIO signal handler input_interrupt doesn't help either.

This issue can be exposed by hacking the end of getpkt like
@@ -1041,6 +1050,9 @@ getpkt (char *buf)
        }
     }

+  if (readchar_bufcnt > 0)
+    gdb_assert (*readchar_bufp != '\003');
+
   return bp - buf;
 }

and this can trigger internal error,
(gdb) PASS: gdb.base/interrupt-noterm.exp: interrupt
Remote connection closed^M
(gdb) FAIL: gdb.base/interrupt-noterm.exp: inferior received SIGINT
Remote debugging from host 10.2.206.40^M
/home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/remote-utils.c:1054: A problem internal to GDBserver has been detected.^M
getpkt: Assertion `*readchar_bufp != '\003'' failed.^M

This patch is to peek the buffer, if it is '\003', consume it and call
*the_target->request_interrupt.

gdb/gdbserver:

2016-01-26  Yao Qi  <yao.qi@linaro.org>

	* remote-utils.c (getpkt): If the buffer isn't empty, and the
	first character is '\003', call *the_target->request_interrupt.
2016-01-26 13:50:22 +00:00
Mark Wielaard a579cd9aa8 Fix GCC6 -Wmisleading-indentation issues.
GCC6 will warn about misleading indentation issues like:

gdb/ada-lang.c: In function ‘ada_evaluate_subexp’:
ada-lang.c:11423:9: error: statement is indented as if it were guarded by...
         arg1 = unwrap_value (arg1);
         ^~~~

gdb/ada-lang.c:11421:7: note: ...this ‘else’ clause, but it is not
       else
       ^~~~

In this case it would be a bug except for the fact the if clause already
returned early. So this misindented statement really only got executed
for the else case. But it could easily mislead a reader, so adding a
proper else block is the correct solution.

In case of c-typeprint.c (c_type_print_base) the if statement is indeed
misleadingly indented, but not a bug. Just indent correctly. The inflow.c
(terminal_ours_1) misindented block comes from the removal of an if clause
in commit d9d2d8b which looks correct. Just introduce an else to fixup the
indentation of the block. The linux-record.c misleadingly indented return
statements are just that. Misleading to the reader, but not actual bugs.
Just unindent them so they don't look like they fall under the wrong if
clause.
2016-01-26 00:04:55 +01:00
Yao Qi a0f8e08a3c Remove new_thread_notify and dead_thread_notify
They were added by

  PATCH: Multithreaded debugging for gdbserver
  https://sourceware.org/ml/gdb-patches/2002-06/msg00157.html

but as a no-op, and the last usage of them was removed by

  [gdbserver/RFC/RFA] Implement multiprocess extensions, add linux multiproces support.
  https://sourceware.org/ml/gdb-patches/2009-03/msg00667.html

This patch is to remove them.

gdb/gdbserver:

2016-01-25  Yao Qi  <yao.qi@linaro.org>

	* remote-utils.c (new_thread_notify): Remove.
	(dead_thread_notify): Likewise.
	* remote-utils.h (new_thread_notify): Remove declaration.
	(dead_thread_notify): Likewise.
2016-01-25 16:11:43 +00:00
Pedro Alves a2077e2540 Fix PR 19461: strange "info thread" behavior in non-stop
If you have "set follow-fork child" set, then if you do "info threads"
right after a fork, and before the child reports any other event to
GDB core, you'll see:

(gdb) info threads
  Id   Target Id         Frame
* 1.1  Thread 0x7ffff7fc1740 (LWP 31875) "fork-plus-threa" (running)
  2.1  process 31879 "fork-plus-threa" Selected thread is running.
(gdb)

The "Selected thread is running." bit is a bogus error.  That was GDB
trying to fetch the current frame of thread 2.1, because the external
runnning state is "stopped", and then throwing an error because the
thread is actually running.

This actually affects all-stop + schedule-multiple as well.

The problem here is that on a fork event, GDB doesn't update the
external parent/child running states.

New comprehensive test included.  The "kill inferior 1" / "kill
inferior 2" bits also trip on PR gdb/19494 (hang killing unfollowed
fork children), which was fixed by the previous patch.

gdb/ChangeLog:
2016-01-25  Pedro Alves  <palves@redhat.com>

	PR threads/19461
	* infrun.c (handle_inferior_event_1) <fork/vfork>: Update
	parent/child running states.

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

	PR threads/19461
	* gdb.base/fork-running-state.c: New file.
	* gdb.base/fork-running-state.exp: New file.
2016-01-25 13:17:34 +00:00
Pedro Alves 1d2736d43b Fix PR 19494: hang when killing unfollowed fork children
linux_nat_kill relies on get_last_target_status to determine whether
the current inferior is stopped at a unfollowed fork/vfork event.
This is bad because many things can happen ever since we caught the
fork/vfork event...  This commit rewrites that code to instead walk
the thread list looking for unfollowed fork events, similarly to what
was done for remote.c.

New test included.  The main idea of the test is make sure that when
the program stops for a fork catchpoint, and the user kills the
parent, gdb also kills the unfollowed fork child.  Since the child
hasn't been added as an inferior at that point, we need some other
portable way to detect that the child is gone.  The test uses a pipe
for that.  The program forks twice, so you have grandparent, child and
grandchild.  The grandchild inherits the write side of the pipe.  The
grandparent hangs reading from the pipe, since nothing ever writes to
it.  If, when GDB kills the child, it also kills the grandchild, then
the grandparent's pipe read returns 0/EOF and the test passes.
Otherwise, if GDB doesn't kill the grandchild, then the pipe read
never returns and the test times out, like:

 FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout)
 FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout)

No regressions on x86_64 Fedora 20.  New test passes with gdbserver as
well.

gdb/ChangeLog:
2016-01-25  Pedro Alves  <palves@redhat.com>

	PR gdb/19494
	* linux-nat.c (kill_one_lwp): New, factored out from ...
	(kill_callback): ... this.
	(kill_wait_callback): New, factored out from ...
	(kill_wait_one_lwp): ... this.
	(kill_unfollowed_fork_children): New function.
	(linux_nat_kill): Use it.

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

	PR gdb/19494
	* gdb.base/catch-fork-kill.c: New file.
	* gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:16:43 +00:00
Pedro Alves f1da4b11ee Move foreach_with_prefix to lib/gdb.exp
gdb/testsuite/ChangeLog:
2016-01-25  Pedro Alves  <palves@redhat.com>

	* gdb.base/step-sw-breakpoint-adjust-pc.exp (foreach_with_prefix):
	Delete, moved to lib/gdb.exp.
	* gdb.threads/forking-threads-plus-breakpoint.exp
	(foreach_with_prefix): Likewise.
	* gdb.threads/process-dies-while-handling-bp.exp
	(foreach_with_prefix): Likewise.
	* lib/gdb.exp (foreach_with_prefix): New procedure.
2016-01-25 13:15:11 +00:00
Pedro Alves 018a260a3b Delete ChangeLog entry from the wrong place
Missed actually removing this in 37e42b4fe92c...
2016-01-25 12:54:48 +00:00
Marcin Kościelnicki 45f3854667 gdb.trace/testsuite: Bump stack collection fudge factor.
These two tests collect 64 words from $sp onwards, hoping that's enough
to capture a few whole stack frames.  Unfortunately, that's not enough
for s390, which tends to have large frame sizes - minimum 24 words on
s390, 20 on s390x (which just barely passes).  Bump it to 128 words,
let's hope no machine needs more.

Tested on x86_64, s390, s390x.

gdb/testsuite/ChangeLog:

	* gdb.trace/backtrace.exp: Bump stack collection fudge factor.
	* gdb.trace/entry-values.exp: Bump stack collection fudge factor.
2016-01-25 13:19:22 +01:00
Marcin Kościelnicki dc29a1ce6a gdb.trace: Fix unavailable-dwarf-piece.exp on big endian targets
The test constructs fake DWARF info for a C structure involving bitfields.
DWARF bitfields are always counted from LSB, while the order in which
bitfields are allocated in a C struct depends on the target endianness -
thus the generated DWARF marks different bitfields as unavailable when
target is big endian.  Accordingly, we need different expected outputs.

Tested on s390 and s390x, no regression on x86_64.

gdb/testsuite/ChangeLog:

	* gdb.trace/unavailable-dwarf-piece.exp: Fix bitfield handling on big
	endian targets.
2016-01-23 14:54:59 +01:00
Marcin Kościelnicki cc5fd9abe4 gdb.trace: Fix another expected message on continue.
Missed one message in bd0a71fa16, since it
didn't trigger on s390x or amd64 (fast tracepoint out of range due to
shared library usage), noticed on s390.

Pushed as obvious.

gdb/testsuite/ChangeLog:

	* gdb.trace/pending.exp: Fix expected message on continue.
2016-01-23 12:16:19 +01:00
Jan Kratochvil 092127d743 testsuite: gdb.gdb/selftest.exp: Drop expected Thread number
Pedro Alves:
Looks like you forgot to amend before pushing though -- the version
checked in still had "Thread 1".

gdb/testsuite/ChangeLog
2016-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	Fix testsuite compatibility with Guile.
	* gdb.gdb/selftest.exp (send ^C to child process): Drop expected Thread
	number.
2016-01-22 21:49:38 +01:00
Jan Kratochvil 31d765d380 testsuite: Fix PR threads/19422 regression + Guile regression
The PR threads/19422 patchset added a new regression.

Additionally below it there was already a regression if --with-guile (which is
default if Guile is found) was used.

racy case #1:

(xgdb) PASS: gdb.gdb/selftest.exp: Set xgdb_prompt
^M
Thread 1 "xgdb" received signal SIGINT, Interrupt.^M
0x00007ffff583bfdd in poll () from /lib64/libc.so.6^M
(gdb) FAIL: gdb.gdb/selftest.exp: send ^C to child process
signal SIGINT^M
Continuing with signal SIGINT.^M
^C^M
Thread 1 "xgdb" received signal SIGINT, Interrupt.^M
0x00007ffff5779da0 in sigprocmask () from /lib64/libc.so.6^M
(gdb) PASS: gdb.gdb/selftest.exp: send SIGINT signal to child process
backtrace^M
errstring=errstring@entry=0x7e0e6c "", mask=mask@entry=RETURN_MASK_ALL) at exceptions.c:240^M
errstring=errstring@entry=0x7e0e6c "", mask=mask@entry=RETURN_MASK_ALL) at exceptions.c:240^M
(gdb) PASS: gdb.gdb/selftest.exp: backtrace through signal handler

racy case #2:

(xgdb) PASS: gdb.gdb/selftest.exp: Set xgdb_prompt
^M
Thread 1 "xgdb" received signal SIGINT, Interrupt.^M
0x00007ffff583bfdd in poll () from /lib64/libc.so.6^M
(gdb) FAIL: gdb.gdb/selftest.exp: send ^C to child process
signal SIGINT^M
Continuing with signal SIGINT.^M
^C^M
Thread 2 "xgdb" received signal SIGINT, Interrupt.^M
[Switching to Thread 0x7ffff3b7f700 (LWP 13227)]^M
0x00007ffff6b88b10 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0^M
(gdb) PASS: gdb.gdb/selftest.exp: send SIGINT signal to child process
backtrace^M
(gdb) FAIL: gdb.gdb/selftest.exp: backtrace through signal handler

Pedro Alves:
Not all targets support thread names, and even those that do, not all
use the program name as default thread name -- I think that's only true
for GNU/Linux, actually.  So I think it's best to not expect that, like:
            -re "(Thread .*|Program) received signal SIGINT.*$gdb_prompt $" {

gdb/testsuite/ChangeLog
2016-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix testsuite compatibility with Guile.
	* gdb.gdb/selftest.exp (send ^C to child process): Accept also Thread.
	(thread 1): New test for backtrace through signal handler.
2016-01-22 21:21:45 +01:00
John Baldwin b2bae2f79b Reword the string description of native FreeBSD ptids.
The prior format led to confusing messages when threads were created
or added such as "[New process 14757, LWP 100537]".  The new format
reports this as "[New LWP 100434 of process 15652]".

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_pid_to_str): Adjust string format.
2016-01-22 08:47:15 -08:00
Marcin Kościelnicki 99e8eb11cf gdb.trace: Fix write_inferior_data_ptr on 32-bit big-endian machines.
Noticed and tested on 31-bit s390.  This bug caused completely broken
fast tracepoints.

gdb/gdbserver/ChangeLog:

	* tracepoint.c (write_inferior_data_ptr): Cast to uintptr_t, so that
	it works properly on big-endian machines where sizeof (CORE_ADDR)
	!= sizeof (void *).
2016-01-22 15:03:47 +01:00
Yao Qi 1ac78c0444 [testsuite] Unbuffer the output in gdb.base/multi-forks.c
This patch unbuffer the output of the program so that the test harness
can count the number of "done" from output correctly.

gdb/testsuite:

2016-01-22  Yao Qi  <yao.qi@linaro.org>

	PR testsuite/19491
	* gdb.base/multi-forks.c: Include
	../lib/unbuffer_output.c
	(main): Call gdb_unbuffer_output.
2016-01-22 09:02:11 +00:00
Yao Qi d86feca31b [ARM] perror_with_name when failed to fetch/store registers
I see the following test fail on native arm-linux gdb testing...

(gdb) PASS: gdb.base/killed-outside.exp: registers: get pid of inferior
Executing on target: kill -9 2346    (timeout = 300)
spawn kill -9 2346^M
flushregs^M
Register cache flushed.^M
warning: Unable to fetch general registers.^M
PC not available^M
(gdb) PASS: gdb.base/killed-outside.exp: registers: flushregs
info threads^M
  Id   Target Id         Frame ^M
* 1    process 2346 "killed-outside" (gdb) FAIL: gdb.base/killed-outside.exp: registers: info threads (timeout)

since the inferior disappeared, ptrace will fail.  In that case, the
exception should be thrown, so that the caller can handle that.

gdb:

2016-01-22  Yao Qi  <yao.qi@linaro.org>

	* arm-linux-nat.c (fetch_fpregs): Call perror_with_name
	instead of warning.
	(store_fpregs, fetch_regs, store_regs): Likewise.
	(fetch_wmmx_regs, store_wmmx_regs): Likewise.
	(fetch_vfp_regs, store_vfp_regs): Likewise.
2016-01-22 09:01:09 +00:00
Doug Evans b35a8b2f1f * breakpoint.c (init_breakpoint_sal): Add comment. 2016-01-21 17:03:10 -08:00
Doug Evans 4f5946a863 * lib/ada.exp (gdb_compile_ada): Fix typo. 2016-01-21 16:20:02 -08:00
Marcin Kościelnicki f906b85701 gdb.trace: Fix string collection for 64-bit platforms.
String collection always used ref32 to fetch the string pointer.  Make it
use gen_fetch instead.

As a side effect, this patch changes dup+const+trace+pop sequence used
for collecting the string's address to a trace_quick opcode.  This
results in a shorter agent expression.

This appeared to work on x86_64 since it's a little-endian platform, and
malloc (used in gdb.trace/collection.exp) returns addresses in low 4GB.
Noticed and tested on s390x-ibm-linux-gnu, also tested on
i686-unknown-linux-gnu and x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* ax-gdb.c (gen_traced_pop): Use gen_fetch for string collection.
2016-01-21 17:36:27 +01:00
Andrew Burgess 4a099de2e7 gdb: Small cleanup to disasm.c:maybe_add_dis_line_entry
Give the function a better name (drop "maybe_") and update the header
comment.

gdb/ChangeLog:

	* disasm.c (maybe_add_dis_line_entry): Rename to...
	(add_dis_line_entry): ...this, and update header comment.
	(do_mixed_source_and_assembly): Now use add_dis_line_entry.
2016-01-21 12:56:25 +01:00
Pedro Alves a994041db3 gdb: Respect CXXFLAGS when building with C++ compiler
Currently, even when built with --enable-build-with-cxx, gdb uses
CFLAGS instead of CXXFLAGS.  This commit fixes it.

CXXFLAGS set in the environment when configure was run is now honored
in the generated gdb/Makefile, and you can also override CXXFLAGS in
the command like at make time, with the usual 'make CXXFLAGS="..."'

Objects built with a C compiler (e.g., gnulib) still honor CFLAGS
instead.

gdb/ChangeLog:
2016-01-21  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMPILER_CFLAGS): New.
	(CXXFLAGS): Get it from configure.
	(INTERNAL_CFLAGS_BASE, INTERNAL_LDFLAGS): Use COMPILER_CFLAGS
	instead of CFLAGS.
	* build-with-cxx.m4 (GDB_AC_BUILD_WITH_CXX): Set and AC_SUBST
	COMPILER_CFLAGS.
	* configure: Regenerate.

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

	* Makefile.in (COMPILER_CFLAGS, CXXFLAGS): New.
	(INTERNAL_CFLAGS_BASE): Use COMPILER_CFLAGS instead of CFLAGS.
	* configure: Regenerate.
2016-01-21 11:18:45 +00:00
Joel Brobecker 305e13e67f Fix regression introduced in "break *<EXPR>" by explicit location patches.
A relatively recent patch support for explicit locations, and part
of that patch cleaned up the way we parse breakpoint locations.
Unfortunatly, a small regression crept in for "*<EXPR>" breakpoint
locations. In particular, on PIE programs, one can see the issue by
doing the following, with any program:

    (gdb) b *main
    Breakpoint 1 at 0x51a: file hello.c, line 3.
    (gdb) run
    Starting program: /[...]/hello
    Error in re-setting breakpoint 1: Warning:
    Cannot insert breakpoint 1.
    Cannot access memory at address 0x51a

    Warning:
    Cannot insert breakpoint 1.
    Cannot access memory at address 0x51a

Just for the record, this regression was introduced by:

    commit a06efdd6ef
    Date:   Tue Aug 11 17:09:35 2015 -0700
    Subject: Explicit locations: introduce address locations

What happens is that the patch makes the implicit assumption that
the address computed the first time is static, as if it was designed
to only support litteral expressions (Eg. "*0x1234"). This allows
the shortcut of not re-computing the breakpoint location's address
when re-setting breakpoints.

However, this does not work in general, as demonstrated in the example
above.

This patch plugs that hole simply by saving the original expression
used to compute the address as part of the address location, so as
to then re-evaluate that expression during breakpoint re-set.

gdb/ChangeLog:

        * location.h (new_address_location): Add new parameters
        "addr_string" and "addr_string_len".
        (get_address_string_location): Add declaration.
        * location.c (new_address_location): Add new parameters
        "addr_string" and "addr_string_len".  If not NULL, store
        a copy of the addr_string in the new location as well.
        (get_address_string_location): New function.
        (string_to_event_location): Update call to new_address_location.
        * linespec.c (event_location_to_sals) <ADDRESS_LOCATION>:
        Save the event location in the parser's state before
        passing it to convert_address_location_to_sals.
        * breakpoint.c (create_thread_event_breakpoint): Update call
        to new_address_location.
        (init_breakpoint_sal): Get the event location's string, if any,
        and use it to update call to new_address_location.
        * python/py-finishbreakpoint.c (bpfinishpy_init):
        Update call to new_address_location.
        * spu-tdep.c (spu_catch_start): Likewise.

        * config/djgpp/fnchange.lst: Add entries for
        gdb/testsuite/gdb.base/break-fun-addr1.c and
        gdb/testsuite/gdb.base/break-fun-addr2.c.

gdb/testsuite/ChangeLog:

        * gdb.base/break-fun-addr.exp: New file.
        * gdb.base/break-fun-addr1.c: New file.
        * gdb.base/break-fun-addr2.c: New file.
2016-01-21 14:23:15 +04:00
Yao Qi f7a6a40dbc Detect the arm/thumb mode of code SIGRETURN or RT_SIGRETURN returns to
This patch fixes the following regression introduced by commit d0e59a68

step^M
39      } /* handler */^M
1: x/i $pc^M
=> 0x8740 <handler+80>: sub     sp, r11, #0^M
(gdb) step^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
setitimer () at ../sysdeps/unix/syscall-template.S:81^M
81      ../sysdeps/unix/syscall-template.S: No such file or directory.^M
1: x/i $pc^M
=> 0xb6eff9c0 <setitimer>:      push    {r7}^M
(gdb) FAIL: gdb.base/sigstep.exp: continue to handler, si+advance in handler, step from handler: leave handler

in my test setting, program is compiled in arm mode, but the glibc
is built in thumb mode, so when we do 'step' to step over syscall
instruction svc for SIGRETURN, GDB should set breakpoint for arm mode
in the program, even though the current program in glibc is in thumb
mode.  Current GDB doesn't consider the case that the mode of program
SIGRETURN goes to can be different from current program mode.

In fact, GDB has taken care of this arm/thumb mode changes already,
see

/* Copy the value of next pc of sigreturn and rt_sigrturn into PC,
   return 1.  In addition, set IS_THUMB depending on whether we
   will return to ARM or Thumb code.  Return 0 if it is not a
   rt_sigreturn/sigreturn syscall.  */
static int
arm_linux_sigreturn_return_addr (struct frame_info *frame,
				 unsigned long svc_number,
				 CORE_ADDR *pc, int *is_thumb)

but in the commit d0e59a68

> -  arm_linux_sigreturn_return_addr (frame, svc_number, &return_addr, &is_thumb);
> +  if (svc_number == ARM_SIGRETURN || svc_number == ARM_RT_SIGRETURN)
> +    next_pc = arm_linux_sigreturn_next_pc (regcache, svc_number);

the IS_THUMB setting is lost, so it is a regression.

gdb:

2016-01-21  Yao Qi  <yao.qi@linaro.org>

	* arm-linux-tdep.c (arm_linux_sigreturn_next_pc): Add parameter
	is_thumb and set it according to CPSR saved on the stack.
	(arm_linux_get_next_pcs_syscall_next_pc): Pass is_thumb to
	arm_linux_sigreturn_next_pc.

gdb/gdbserver:

2016-01-21  Yao Qi  <yao.qi@linaro.org>

	* linux-arm-low.c (arm_sigreturn_next_pc): Add parameter
	is_thumb and set it according to CPSR saved on the stack.
	(get_next_pcs_syscall_next_pc): Pass is_thumb to
	arm_sigreturn_next_pc.
2016-01-21 07:48:50 +00:00
Simon Marchi 5f5dfff63f Fix sorting of enum values in FlagEnumerationPrinter
The lambda function used to sort the enumerator list does not work
properly.  This list consists of tuples, (enum label, enum value).  The
key function returns x.enumval.  enumval not being defined for a tuple,
we see this exception in the test log:

  Python Exception <class 'AttributeError'> 'tuple' object has no attribute 'enumval'

The function should return the second item of the tuple, which is the
enumval.

The pretty-printer still worked mostly correctly, except that the
enumeration values were not sorted.  The test still passed because the
enumeration values are already sorted where they are defined.  The test
also passed despite the exception being printed, because the right output
was printed after the exception:

  print (enum flag_enum) (FLAG_1)
  Python Exception <type 'exceptions.AttributeError'> 'tuple' objecthas no attribute 'enumval':M
  $7 = 0x1 [FLAG_1]
  (gdb) PASS: gdb.python/py-pp-maint.exp: print FLAG_1

New in v2:

- Improved test case, I stole Pedro's example directly.  It verifies
  that the sorting of enumerators by value works, by checking that
  printing FOO_MASK appears as FOO_1 | FOO_2 | FOO_3.

  I noticed that I could change the regexps to almost anything and the
  tests would still pass.  I think it was because of the | in there.  I
  made them more robust by using string_to_regexp.  I used curly braces
  { } instead of quoting marks " " for strings, so that I could use
  square brackets [ ] in them without having to escape them all.  I also
  removed the "message" part of the tests, since they are redundant with
  the command, and it's just more maintenance to have to update them.

  Tested with Python 2.7 and 3.5.

gdb/ChangeLog:

	* python/lib/gdb/printing.py (FlagEnumerationPrinter.__call__):
	Fix enumerators sort key function.

gdb/testsuite/ChangeLog:

	* gdb.python/py-pp-maint.exp: Change/add enum flag tests.
	* gdb.python/py-pp-maint.c (enum flag_enum): Use more complex
	enum flag values.
2016-01-20 13:44:33 -05:00
Andreas Arnez fd356fa288 gnu_vector.exp: Respect `should_kfail' for PR 8549
The gnu_vector test case yields a new FAIL on s390x:

  FAIL: gdb.base/gnu_vector.exp: verify vector return value

It was introduced by commit 77ae9c1933 "gdb.base/gnu_vector.exp:
Don't test output from the inferior".  That commit dropped the special
handling for GDB's inability (on some targets) to set the return value.

This change re-establishes the logic from before, converting the above
FAIL to a KFAIL (PRMS gdb/8549).

gdb/testsuite/ChangeLog:

	* gdb.base/gnu_vector.exp: Re-establish handling for should_kfail
	when GDB can not set the vector return value.  Add more comments
	for clarification.
2016-01-20 19:41:45 +01:00
Antoine Tremblay 9df22175e1 Fix missing IPA lib in tspeed.exp in some configurations.
On Ubuntu 14.04 the following failure would be seen when running the
tspeed.exp test on a target that supports fast tracepoints like x86_64:

Target returns error code '.In-process agent library not loaded in
process.  Fast and static tracepoints unavailable.'.
(gdb) FAIL: gdb.trace/tspeed.exp: start trace experiment

This is because the default is to link with --as-needed and the
gdb_compile for the test is using the libs argument instead of shlib which
corrects this issue since 6ebea266fd by
adding -Wl,--no-as-needed.

This patch fixes the issue by passing the lib as the shlib argument to
gdb_compile.

Tested on Ubuntu 14.04 x86_64.

gdb/testsuite/ChangeLog:

	* gdb.trace/tspeed.exp:  Use shlib instead of libs in gdb_compile
	command.
2016-01-20 12:30:53 -05:00
Pedro Alves b12e5614fb Fix gdb/ChangeLog typo 2016-01-20 13:10:41 +00:00
Pedro Alves 37e42b4fe9 Move ChangeLog entry to proper place (gdb/testsuite/ -> gdb/) 2016-01-20 13:03:40 +00:00
Joel Brobecker be56871ee8 minor reformatting in printcmd.c::print_scalar_formatted
(GNU Coding Standard...)

gdb/ChangeLog:

        * printcmd.c (print_scalar_formatted): move binary operator from
        end of line to beginning of next line.  Adjust formatting
        accordingly.
2016-01-20 08:03:44 +04:00
John Baldwin f2feec9809 Use a separate variable for the size passed to sysctl.
This fixes a sign mismatch warning.

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_pid_to_exec_file): Use new "buflen" instead of
	"len" with sysctl.
2016-01-19 11:35:19 -08:00
John Baldwin 20a0aab3ed Dump register notes for each thread when generating a FreeBSD core.
gdb/ChangeLog:

	* fbsd-tdep.c (find_stop_signal): Remove.
	(struct fbsd_collect_regset_section_cb) <lwp>: New field.
	<stop_signal>: New field.
	<abort_iteration>: New field.
	(fbsd_collect_regset_section_cb): Use new fields.
	(fbsd_collect_thread_registers): New function.
	(struct fbsd_corefile_thread_data): New structure.
	(fbsd_corefile_thread): New function.
	(fbsd_make_corefile_notes): Use new function to dump notes for each
	non-exited thread in a process.
2016-01-19 08:19:40 -08:00
John Baldwin 6e9567fe2a Add support for LWP-based threads on FreeBSD.
Older versions of FreeBSD supported userland threading via a pure
user-space threading library (N threads scheduled on 1 process) and
a N:M model (N threads scheduled on M LWPs).  However, modern FreeBSD
versions only support a M:M threading model where each user thread is
backed by a dedicated LWP.  This thread target only supports this
threading model.  It also uses ptrace to query and alter LWP state
directly rather than using libthread_db to simplify the implementation.

FreeBSD recently gained support for reporting LWP events (birth and death
of LWPs).  GDB will use LWP events when present.  For older systems it
fetches the list of LWPs in the to_update_thread_list target op to update
the list of threads on each stop.

This target supports scheduler locking by using ptrace to suspend
individual LWPs as necessary before resuming a process.

gdb/ChangeLog:

	* configure.ac: Check for support for LWP names on FreeBSD.
	* fbsd-nat.c [PT_LWPINFO] New variable debug_fbsd_lwp.
	[TDP_RFPPWAIT || HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME]
	(fbsd_fetch_kinfo_proc): Move function earlier.
	[PT_LWPINFO] (fbsd_thread_alive): New function.
	[PT_LWPINFO] (fbsd_pid_to_str): New function.
	[HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME] (fbsd_thread_name): New function.
	[PT_LWP_EVENTS] (fbsd_enable_lwp_events): New function.
	[PT_LWPINFO] (fbsd_add_threads): New function.
	[PT_LWPINFO] (fbsd_update_thread_list): New function.
	[PT_LWPINFO] New variable super_resume.
	[PT_LWPINFO] (resume_one_thread_cb): New function.
	[PT_LWPINFO] (resume_all_threads_cb): New function.
	[PT_LWPINFO] (fbsd_resume): New function.
	(fbsd_remember_child): Save full ptid instead of plain pid.
	(fbsd_is_child_pending): Return ptid of saved child process.
	(fbsd_wait): Include lwp in returned ptid and switch to LWP ptid on
	first stop.
	[PT_LWP_EVENTS] Handle LWP events.
	[TDP_RFPPWAIT] Include LWP in child ptid.
	(fbsd_post_startup_inferior) [PT_LWP_EVENTS]: Enable LWP events.
	(fbsd_post_attach) [PT_LWP_EVENTS]: Enable LWP events.
	Add threads for existing processes.
	(fbsd_nat_add_target) [PT_LWPINFO]: Set "to_thread_alive" to
	"fbsd_thread_alive".
	Set "to_pid_to_str" to "fbsd_pid_to_str".
	[HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME]: Set "to_thread_name" to
	"fbsd_thread_name".
	[PT_LWPINFO]: Set "to_update_thread_list" to "fbsd_update_thread_list".
	Set "to_has_thread_control" to "tc_schedlock".
	Set "to_resume" to "fbsd_resume".
	(_initialize_fbsd_nat): New function.
	* configure: Regenerate.
	* config.in: Regenerate.

gdb/doc/ChangeLog:

	* gdb.texinfo (Debugging Output): Document "set/show debug fbsd-lwp".
2016-01-19 08:19:00 -08:00
John Baldwin 94309df7aa Use LWP IDs with ptrace register requests on FreeBSD.
This allows gdb to fetch per-thread registers for multi-threaded FreeBSD
processes.

Export get_ptrace_pid() from inf-ptrace.c and use it to determine the PID
to pass to ptrace in pan-BSD native targets.  NetBSD and OpenBSD also accept
LWP IDs for ptrace requests to fetch per-thread state.

gdb/ChangeLog:

	* amd64bsd-nat.c (amd64bsd_fetch_inferior_registers): Use
	get_ptrace_pid.
	(amd64bsd_store_inferior_registers): Use get_ptrace_pid.
	(amd64bsd_dr_get): Use get_ptrace_pid.
	(amd64bsd_dr_set): Use get_ptrace_pid.
	* i386bsd-nat.c (i386bsd_fetch_inferior_registers): Use get_ptrace_pid.
	(i386bsd_store_inferior_registers): Use get_ptrace_pid.
	(i386bsd_dr_get): Use get_ptrace_pid.
	(i386bsd_dr_set): Use get_ptrace_pid.
	* inf-ptrace.c (get_ptrace_pid): Export.
	* inf-ptrace.h (get_ptrace_pid): Declare.
	* ppcfbsd-nat.c (ppcfbsd_fetch_inferior_registers): Use lwp id.
	(ppcfbsd_store_inferior_registers): Use lwp id.
2016-01-19 08:18:49 -08:00
John Baldwin 791174281c Display per-thread information for threads in FreeBSD cores.
Display the LWP ID of each thread in a FreeBSD core.  Extract thread
names from the per-thread THRMISC note.

gdb/ChangeLog:

	* fbsd_tdep.c (fbsd_core_pid_to_str): New function.
	(fbsd_core_thread_name): New function.
	(fbsd_init_abi): Add "core_pid_to_str" gdbarch method.
	Add "core_thread_name" gdbarch method.
2016-01-19 08:18:30 -08:00
John Baldwin 4dfc5dbc4e Add support for extracting thread names from cores.
Add a new gdbarch method to extract a thread name from a core for a
given thread.  Use this new method in core_thread_name to implement the
to_thread_name target op.

gdb/ChangeLog:

	* corelow.c (core_thread_name): New function.
	(init_core_ops): Use "core_thread_name" for the "to_thread_name"
	target op.
	* gdbarch.sh (core_thread_name): New gdbarch callback.
	* gdbarch.h: Re-generate.
	* gdbarch.c: Re-generate.
2016-01-19 08:18:20 -08:00
Simon Marchi 10e3ed9029 Fix enum flag with Python 3
Using Python 3.5 (I assume it's the same with 3.4 and lower, but I didn't
test), I see this:

  print (enum flag_enum) (FLAG_1)^M
  Python Exception <class 'TypeError'> %x format: an integer is required, not gdb.Value: ^M
  $7 = ^M
  (gdb) FAIL: gdb.python/py-pp-maint.exp: print FLAG_1

Apparently, this idiom, where v is a gdb.Value, was possible with Python 2,
but not with Python 3:

  '%x' % v

In Python 2, it would automatically get converted to an integer.  To solve
it, I simply added wrapped v in a call to int().

  '%x' % int(v)

In Python 2, the int type is implemented with a "long" in C, so on x86-32 it's
32-bits.  I was worried that doing int(v) would truncate the value and give
wrong results for enum values > 32-bits.  However, the int type != the int
function.  The int function does the right thing, selecting the right integer
type for the given value.  I tested with large enum values on x86-32 and
Python 2, and everything works as expected.

gdb/ChangeLog:

	* python/lib/gdb/printing.py (_EnumInstance.to_string): Explicitly
	convert gdb.Value to integer type using int().
2016-01-19 11:07:07 -05:00
Simon Marchi 41d1845eda testsuite: Factor out --status in DO_RUNTEST
gdb/testsuite/ChangeLog:

	* Makefile.in (DO_RUNTEST): Add --status and update usages.
2016-01-19 11:06:11 -05:00