Commit Graph

5529 Commits

Author SHA1 Message Date
Doug Evans 82c7be3106 PR c++/18141, c++/18417.
gdb/ChangeLog:

	* cp-support.c (cp_lookup_rtti_type): Handle the case of NAME being
	a typedef.

gdb/testsuite/ChangeLog:

	* gdb.cp/iostream.cc: New file.
	* gdb.cp/iostream.exp: New file.
2015-05-26 17:20:49 -07:00
Doug Evans b4f5498457 Rename dwarf2 to dwarf in "set debug" and maintenance commands.
gdb/ChangeLog:

	* NEWS: Add entries for command renamings.
	* dwarf2read.c (dwarf_read_debug): Renamed from dwarf2_read_debug.
	All uses updated.
	(dwarf_die_debug): Renamed from dwarf2_die_debug.  All uses updated.
	(dwarf_max_cache_age): Renamed from dwarf2_max_cache_age.
	All uses updated.
	(show_dwarf_max_cache_age): Renamed from show_dwarf2_max_cache_age.
	All callers updated.  Fix spelling of DWARF in help text.
	(set_dwarf_cmdlist): Renamed from set_dwarf2_cmdlist.
	All uses updated.
	(show_dwarf_cmdlist): Renamed from show_dwarf2_cmdlist.
	All uses updated.
	(set_dwarf_cmd): Renamed from set_dwarf2_cmd.  All callers updated.
	(show_dwarf_cmd): Renamed from show_dwarf2_cmd.  All callers updated.
	(dwarf_always_disassemble): Renamed from dwarf_always_disassemble.
	All uses updated.
	(show_dwarf_always_disassemble): Renamed from
	show_dwarf2_always_disassemble.  All callers updated.
	(_initialize_dwarf2_read): Rename "set/show dwarf2" prefix to
	"set/show dwarf".  Rename "set/show dwarf2 max-cache-age" to
	"set/show dwarf max-cache-age".  Rename
	"set/show dwarf2 always-disassemble" to
	"set/show dwarf always-disassemble".  Rename
	"set/show debug dwarf2-read" to "set/show debug dwarf-read".  Rename
	"set/show debug dwarf2-die" to "set/show debug dwarf-die".

gdb/doc/ChangeLog:

	* gdb.texinfo (Debugging Output): Update for DWARF "set debug"
	command renamings.
	(Maintenance Commands): Update for DWARF "set debug" command renamings.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-op-call.exp: Update.
	* gdb.dwarf2/dw4-sig-types.exp: Update.
	* gdb.dwarf2/implptr.exp: Update.
	* gdb.mi/mi-cmd-param-changed.exp: Update.
2015-05-26 16:50:57 -07:00
Doug Evans 4ea6efe936 PR python/18438
gdb/ChangeLog:

	* python/py-lazy-string.c (stpy_convert_to_value): Use
	gdbpy_gdb_memory_error not PyExc_MemoryError.
	(gdbpy_create_lazy_string_object): Ditto.

gdb/testsuite/ChangeLog:

	* gdb.python/py-lazy-string.c: New file.
	* gdb.python/py-lazy-string.exp: New file.
	* gdb.python/py-prettyprint.c (lazystring) <len>: New member.
	(main): Update.  Add estring3.
	* gdb.python/py-prettyprint.exp: Add tests for strings at address 0.
	* gdb.python/py-prettyprint.py (pp_ls): Handle length.
2015-05-26 16:13:04 -07:00
Yao Qi f6bb7db35d New gdb.reverse test case for aarch64 instructions
This patch adds a test case to test the process record for some of
aarch64 instructions.

In each function, GDB turns on process record, and single step until
program goes to the end of the function.  Then, single step backward.
In each of forward single step and backward single step, the contents
of registers are saved, and test compares them.  If there is any
differences, a FAIL is emitted.

The test is flexible, and we can test other instructions easily in the
future.

gdb/testsuite:

2015-05-26  Omair Javaid  <omair.javaid@linaro.org>
	    Yao Qi  <yao.qi@linaro.org>

	* gdb.reverse/aarch64.c: New.
	* gdb.reverse/aarch64.exp: New.
2015-05-26 12:42:21 +01:00
Omair Javaid a81bfbd06b Enables gdb.reverse testsuite for aarch64*-linux targets
This patch enable gdb.reverse tests for aarch64*-linux targets.

With this patch, there are 7 FAILs in gdb.reverse/ tests.

 FAIL: gdb.reverse/finish-reverse-bkpt.exp: reverse-finish from void_func trips breakpoint at entry
 FAIL: gdb.reverse/finish-reverse-bkpt.exp: no spurious proceed after breakpoint stop
 FAIL: gdb.reverse/next-reverse-bkpt-over-sr.exp: reverse-next over call trips user breakpoint at function entry
 FAIL: gdb.reverse/step-precsave.exp: reverse step into fn call
 FAIL: gdb.reverse/step-precsave.exp: reverse step out of called fn
 FAIL: gdb.reverse/step-reverse.exp: reverse step into fn call
 FAIL: gdb.reverse/step-reverse.exp: reverse step out of called fn

gdb/testsuite:

2015-05-26  Omair Javaid  <omair.javaid@linaro.org>

	* lib/gdb.exp (supports_process_record): Return true for aarch64*-linux*.
	(supports_reverse): Likewise.
2015-05-26 12:42:12 +01:00
Patrick Palka 158bf1b4aa Make sure test names are unique in gdb.base/gdbinit-history.exp
Use with_test_prefix to avoid duplicating test names when calling
the procedure test_gdbinit_history_setting multiple times.

gdb/testsuite/ChangeLog:

	* gdb.base/gdbinit-history.exp (test_gdbinit_history_setting):
	Use with_test_prefix.
2015-05-21 21:05:00 -04:00
Andrew Burgess a014503004 gdb: Add completer for layout command.
Add layout name completion for the layout command.

gdb/ChangeLog:

	* tui/tui-layout.c (layout_completer): New function.
	(_initialize_tui_layout): Set completer on layout command.

gdb/testsuite/ChangeLog:

	* gdb.base/completion.exp: Add test for completion of layout
	names.
2015-05-21 20:48:10 +02:00
Andrew Burgess ebe3b57852 gdb/testsuite: New skip_tui_tests predicate.
Add a new predicate procedure to the gdb.exp library 'skip_tui_tests',
which returns true if the tui is not compiled into gdb.

Make use of this predicate in the gdb.base/tui-layout.exp test as an
example.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (skip_tui_tests): New proc.
	* gdb.base/tui-layout.exp: Check skip_tui_tests.
2015-05-20 21:57:20 +02:00
Pedro Alves 84204ed7c0 Fix gdb.base/gdbinit-history.exp when HISTSIZE is set in the environment
Some buildslaves are showing that this test is failing.  E.g.,:

 https://sourceware.org/ml/gdb-testers/2015-q2/msg04164.html

The issue is that HISTSIZE is set to 1000 in the environment that runs
the tests (that's the default in Fedora, set in /etc/profile).

We can trivially reproduce it with:

 $ HISTSIZE=1000 make check RUNTESTFLAGS="gdbinit-history.exp"
 (...)
 Running /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/gdbinit-history.exp ...
 FAIL: gdb.base/gdbinit-history.exp: show history size
 FAIL: gdb.base/gdbinit-history.exp: show history size
 FAIL: gdb.base/gdbinit-history.exp: show commands

gdb.log shows:
 ...
 (gdb) set height 0
 (gdb) set width 0
 (gdb) show history size
 The size of the command history is 1000.
 (gdb) FAIL: gdb.base/gdbinit-history.exp: show history size

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

	* gdb.base/gdbinit-history.exp (test_gdbinit_history_setting):
	Save the whole env array instead of just HOME.  Unset HISTSIZE in
	the environment while testing.  Restore whole environment
	afterwards.
2015-05-19 10:47:27 +01:00
Doug Evans 37442ce10a Add support for unbuffered and zero sized Guile ports.
gdb/ChangeLog

	* NEWS: Mention support for unbuffered Guile memory ports.
	* scm-ports.c (ioscm_memory_port): Update comments on end, size.
	(ioscm_lseek_address): Improve overflow calculation.
	(gdbscm_memory_port_fill_input): Add assert.
	(gdbscm_memory_port_write): Handle unbuffered ports.
	Handle large writes identical to Guile's fport_write.
	(gdbscm_memory_port_seek): Fix seeking past end check.
	(gdbscm_memory_port_close): Handle closing unbuffered port.
	(ioscm_parse_mode_bits): Recognize "0" for unbuffered ports.
	(ioscm_init_memory_port): Handle unbuffered ports.
	(ioscm_reinit_memory_port): Ditto.
	(ioscm_init_memory_port): Update size calculation.
	(gdbscm_open_memory): Support zero sized ports.

gdb/testsuite/ChangeLog

	* gdb.guile/scm-ports.c: New file.
	* gdb.guile/scm-ports.exp: Add memory port tests.

gdb/doc/ChangeLog

	* guile.texi (Memory Ports in Guile): Document support for unbuffered
	memory ports.
2015-05-16 12:14:26 -07:00
Jan Kratochvil 36de76f9cc compile: New 'compile print'
It is planned the existing GDB command 'print' will be able to evaluate its
expressions using the compiler.  There will be some option to choose between
the existing GDB evaluation and the compiler evaluation.  But as an
intermediate step this patch provides the expression printing feature as a new
command.

I can imagine it could be also called 'maintenance compile print' as in the
future one should be able to use its functionality by the normal 'print'
command.

There was a discussion with Eli about the command name:
	https://sourceware.org/ml/gdb-patches/2015-03/msg00880.html
As there were no other comments yet I haven't renamed it yet, before there is
some confirmation about settlement on the final name.

Support for the GDB '@' operator to create arrays has been submitted for GCC:
	[gcc patch] libcc1: '@' GDB array operator
	https://gcc.gnu.org/ml/gcc-patches/2015-03/msg01451.html


gdb/ChangeLog
2015-05-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Phil Muldoon  <pmuldoon@redhat.com>

	* NEWS (Changes since GDB 7.9): Add compile print.
	* compile/compile-c-support.c (add_code_header, add_code_footer)
	(c_compute_program): Add COMPILE_I_PRINT_ADDRESS_SCOPE and
	COMPILE_I_PRINT_VALUE_SCOPE.
	* compile/compile-internal.h (COMPILE_I_PRINT_OUT_ARG_TYPE)
	(COMPILE_I_PRINT_OUT_ARG, COMPILE_I_EXPR_VAL, COMPILE_I_EXPR_PTR_TYPE):
	New.
	* compile/compile-object-load.c: Include block.h.
	(get_out_value_type): New function.
	(compile_object_load): Handle COMPILE_I_PRINT_ADDRESS_SCOPE and
	COMPILE_I_PRINT_VALUE_SCOPE.  Set compile_module's OUT_VALUE_ADDR and
	OUT_VALUE_TYPE.
	* compile/compile-object-load.h (struct compile_module): Add fields
	out_value_addr and out_value_type.
	* compile/compile-object-run.c: Include valprint.h and compile.h.
	(struct do_module_cleanup): Add fields out_value_addr and
	out_value_type.
	(do_module_cleanup): Handle COMPILE_I_PRINT_ADDRESS_SCOPE and
	COMPILE_I_PRINT_VALUE_SCOPE.
	(compile_object_run): Propagate out_value_addr and out_value_type.
	Pass OUT_VALUE_ADDR.
	* compile/compile.c: Include valprint.h.
	(compile_print_value, compile_print_command): New functions.
	(eval_compile_command): Handle failed COMPILE_I_PRINT_ADDRESS_SCOPE.
	(_initialize_compile): Update compile code help text.  Install
	compile_print_command.
	* compile/compile.h (compile_print_value): New prototype.
	* defs.h (enum compile_i_scope_types): Add
	COMPILE_I_PRINT_ADDRESS_SCOPE and COMPILE_I_PRINT_VALUE_SCOPE.

gdb/doc/ChangeLog
2015-05-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Compiling and Injecting Code): Add compile print.

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

	* gdb.compile/compile-print.c: New file.
	* gdb.compile/compile-print.exp: New file.
2015-05-16 14:45:06 +02:00
Jan Kratochvil 3a9558c494 compile: Use -Wall, not -w
For a reason unknown to me GDB was using -w instead of -Wall for 'compile code'.
The problem is later patch for 'compile printf' really needs some warnings to
be able to catch for example missing format string parameters:
	(gdb) compile printf "%d\n"
GCC does not seem to be able to cancel -w (there is nothing like -no-w).

Besides that I think even 'compile code' can benefit from -Wall.

That #ifndef change in print_one_macro() is needed otherwise we get
macro-redefinition warnings for the GCC built-in macros (as -w is no
longer in effect).  For example, without the #ifndef/#endif one gets:

	compile -r -- void _gdb_expr(){int i = 5;}^M
	/tmp/gdbobj-xpU1yB/out4.c:4:0: warning: "__FILE__" redefined [-Wbuiltin-macro-redefined]^M
	/tmp/gdbobj-xpU1yB/out4.c:5:0: warning: "__LINE__" redefined^M
	...

It makes more sense to pick the inferior's version of the macros, hence
#ifndef instead of #undef.

That new testsuite XFAIL is there as if one changes the struct definition to be
compliant with cv-qualifiers (to prevent the warnings):
struct struct_type {
-  struct struct_type *selffield;
+  volatile struct struct_type *selffield;
only then GCC/GDB will hit the crash, described in that GDB PR 18202.


gdb/ChangeLog
2015-05-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* compile/compile-c-support.c (print_one_macro): Use #ifndef.
	(generate_register_struct): Use __gdb_uintptr for TYPE_CODE_PTR.
	(c_compute_program): Call generate_register_struct after typedefs.
	* compile/compile-loc2c.c (push, pushf_register_address)
	(pushf_register): Cast to GCC_UINTPTR.
	(do_compile_dwarf_expr_to_c): Use unused attribute.  Add space after
	type.  Use GCC_UINTPTR instead of void *.  Remove excessive cast.
	(compile_dwarf_expr_to_c): Use GCC_UINTPTR instead of void *.
	* compile/compile.c (_initialize_compile): Enable warnings for
	COMPILE_ARGS.

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

	* gdb.compile/compile-ops.exp: Cast param to void.
	* gdb.compile/compile.exp: Complete type for _gdb_expr.
	(compile code struct_object.selffield = &struct_object): Add xfail.
2015-05-16 14:39:59 +02:00
Jerome Guitton aa7151351e Array indexed by non-contiguous enumeration types
In Ada, index types of arrays can be enumeration types, and enumeration
types can be non-contiguous. In which case the address of elements is
not given by the value of the index, but by its position in the enumeration
type.

In other words, in this example:

 type Color is (Blue, Red);
 for Color use (Blue => 8, Red => 12, Green => 16);

 type A is array (Color) of Integer;
 type B is array (1 .. 3) of Integer;

Arrays of type A and B will have the same layout in memory, even if
the enumeration Color has a hole in its set of integer value.

Since recently support for such a feature was in ada-lang.c, where the
array was casted to a regular continuous index range. We were losing
the information of index type. And this was not quite working for
subranges in variable-length fields; their bounds are expressed using
the integer value of the bounds, not its position in the enumeration,
and there was some confusion all over ada-lang.c as to whether we had
the position or the integer value was used for indexes.

The idea behind this patch is to clean this up by keeping the real
representation of these array index types and bounds when representing
the value, and only use the position when accessing the elements or
computing the length. This first patch fixes the printing of such
an array.

To the best of my knowledge, this feature only exists in Ada so it
should only affect this language.

gdb/ChangeLog:

        Jerome Guitton  <guitton@adacore.com>:
        * ada-lang.c (ada_value_ptr_subscript): Use enum position of
        index to get element instead of enum value.
        (ada_value_slice_from_ptr, ada_value_slice): Use enum position
        of index to compute length, but enum values to compute bounds.
        (ada_array_length): Use enum position of index instead of enum value.
        (pos_atr): Move position computation to...
        (ada_evaluate_subexp): Use enum values to compute bounds.
        * gdbtypes.c (discrete_position): ...this new function.
        * gdbtypes.h (discrete_position): New function declaration.
        * valprint.c (val_print_array_elements): Call discrete_position
        to handle array indexed by non-contiguous enumeration types.

gdb/testsuite/ChangeLog:

        * gdb.ada/arr_enum_with_gap: New testcase.
2015-05-15 14:03:46 -07:00
Jerome Guitton 931e5bc3e1 Non bit-packed packed arrays as variable-length fields
In the case of non bit-packed arrays, GNAT does not generate its
traditional XP encoding; it is not needed. However, it still generates
the so-called "implementation type" with a P suffix. This
implementation type shall be skipped when looking for other
descriptive types such as XA encodings for variable-length
fields.

Note also that there may be an intermediate typedef between the
implementation type and its XA description. It shall be skipped
as well.

gdb/ChangeLog:

        Jerome Guitton  <guitton@adacore.com>
	* ada-lang.c (find_parallel_type_by_descriptive_type):
	Go through typedefs during lookup.
	(to_fixed_array_type): Add support for non-bit packed arrays
	as variable-length fields.

gdb/testsuite/ChangeLog:

        * gdb.ada/byte_packed_arr: New testcase.
2015-05-15 14:00:57 -07:00
Joel Brobecker 9cd4d857bb [Ada] problem printing negative integer values in packed arrays.
Consider the following declarations:

   type Signed_Small is new Integer range - (2 ** 5) .. (2 ** 5 - 1);
   type Signed_Simple_Array is array (1 .. 4) of Signed_Small;
   pragma Pack (Signed_Simple_Array);
   SSA : Signed_Simple_Array := (-1, 2, -3, 4);

GDB currently print its value incorrectly for the elements that
are negative:

    (gdb) print ssa
    $1 = (65535, 2, 1048573, 4)
    (gdb) print ssa(1)
    $2 = 65535
    (gdb) print ssa(2)
    $3 = 2
    (gdb) print ssa(3)
    $4 = 1048573
    (gdb) print ssa(4)
    $5 = 4

What happens is that the sign-extension is not working because
we're trying to do left shift with a negative count. In
ada_value_primitive_packed_val, we have a loop which populates
the extra bits of the target (unpacked) value, after extraction
of the data from the original (packed) value:

        while (ntarg > 0)
          {
            accum |= sign << accumSize;
            unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
!!! ->      accumSize -= HOST_CHAR_BIT;
            accum >>= HOST_CHAR_BIT;
            ntarg -= 1;
            targ += delta;
          }

At each iteration, accumSize gets decremented by HOST_CHAR_BIT,
which can easily cause it to become negative, particularly on
little endian targets, where accumSize is at most HOST_CHAR_BIT - 1.
This causes us to perform a left-shift operation with a negative
accumSize at the next loop iteration, which is undefined, and
acutally does not produce the effect we wanted (value left untouched)
when the code is compiled with GCC.

This patch fixes the issue by simply setting accumSize to zero
if negative.

gdb/ChangeLog:

        * ada-lang.c (ada_value_primitive_packed_val): Make sure
        accumSize is never negative.

gdb/testsuite/ChangeLog:

        * gdb.ada/pckd_neg: New testcase.
2015-05-15 07:37:15 -07:00
Patrick Palka ebfd00d210 Fix PR gdb/17820
This patch is a comprehensive fix for PR 17820 which reports that
using "set history size unlimited" inside one's gdbinit file doesn't
really work.

There are three small changes in this patch.  The most important change
this patch makes is to decode the argument of the "size" subcommand
using add_setshow_zuinteger_unlimited_cmd() instead of using
add_setshow_uinteger_cmd().  The new decoder takes an int * and maps
unlimited to -1 whereas the old decoder takes an unsigned int * and maps
unlimited to UINT_MAX.  Using the new decoder simplifies our handling of
unlimited and makes it easier to interface with readline which itself
expects a signed-int history size.

The second change is the factoring of the [stifle|unstifle]_history logic
into a common function which is now used by both init_history() and
set_history_size_command().  This is technically the change that fixes
the PR itself.

Thirdly, this patch initializes history_size_setshow_var to -2 to mean
that the variable has not been set yet.  Now init_history() tests for -2
instead of 0 to determine whether to give the variable a default value.
This means that having "set history size 0" in one's gdbinit file will
actually keep the history size at 0 and not reset it to 256.

gdb/ChangeLog:

	PR gdb/17820
	* top.c (history_size_setshow_var): Change type to signed.
	Initialize to -2.  Update documentation.
	(set_readline_history_size): Define.
	(set_history_size_command): Use it.  Remove logic for handling
	out-of-range sizes.
	(init_history): Use set_readline_history_size().  Test for a
	value of -2 instead of 0 when determining whether to set a
	default history size.
	(init_main): Decode the argument of the "size" command as a
	zuinteger_unlimited.

gdb/testsuite/ChangeLog:

	PR gdb/17820
	* gdb.base/gdbinit-history.exp: New test.
	* gdb.base/gdbinit-history/unlimited/.gdbinit: New file.
	* gdb.base/gdbinit-history/zero/.gdbinit: New file.
2015-05-13 09:26:54 -04:00
Siva Chandra 4c082a81df [Python] Add methods reference_value and const_value to gdb.Value.
gdb/ChangeLog:

	* NEWS (Python Scripting): Mention the new gdb.Value methods.
	* python/py-value.c (valpy_reference_value): New function.
	(valpy_const_value): Likewise.
	(value_object_methods): Add new methods.
	* value.c (make_cv_value): New function.
	* value.h (make_cv_value): Declare.

gdb/doc/ChangeLog:

	* python.texi (Values From Inferior): Add descriptions of new
	methods gdb.Value.reference_value and gdb.Value.const_value.

gdb/testsuite/ChangeLog:

	* gdb.python/py-xmethods.cc: Enhance test case.
	* gdb.python/py-xmethods.exp: New tests.
	* gdb.python/py-xmethods.py (A_indexoper): New xmethod worker
	function.
	(B_indexoper): Likewise.
	(global_dm_list) : Add new xmethod worker functions.
2015-05-09 17:30:35 -07:00
Sergio Durigan Junior f7797074a5 Fix coredump-filter.exp by correctly unsetting array
In my last commit to make gdb.base/coredump-filter.exp be more robust
regarding using arrays in the global namespace, I cleared the
"coredump_var_addr" array like this:

  set coredump_var_addr ""
  # use coredump_var_addr as an array...

This causes DejaGNU to complain because the variable is first set as
non-array, and the used as an array.  The correct way to do this is to
unset the variable using:

  unset -nocomplain coredump_var_addr
  # use coredump_var_addr as an array...

The "-nocomplain" part is necessary because if the variable doesn't
exist "unset" will not error.

Tested on Fedora 20 x86_64.

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

	* gdb.base/coredump-filter.exp: Correctly unset
	"coredump_var_addr" array.
2015-05-08 13:19:19 -04:00
Pedro Alves a4674e4efc Fix sequential gdb test runs
Sequential test runs are stopping prematurely like this:

 $ make check RUNTESTFLAGS="non-existing-program.exp server-exec-info.exp"

 Running /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.server/non-existing-program.exp ...
 Running /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.server/server-exec-info.exp ...
 can not find channel named "exp6"
     while executing
 "match_max [match_max -d]"
     (procedure "default_gdb_init" line 26)
     invoked from within
 "default_gdb_init $test_file_name"
     (procedure "gdb_init" line 83)
     invoked from within
 "${tool}_init $test_file_name"
     (procedure "runtest" line 18)
     invoked from within
 "runtest $test_name"
     ("foreach" body line 42)
     invoked from within
 ...
 make[2]: *** [check-single] Error 1
 make[2]: Leaving directory `/home/pedro/gdb/mygit/build/gdb/testsuite'
 make[1]: *** [check] Error 2
 make[1]: Leaving directory `/home/pedro/gdb/mygit/build/gdb/testsuite'
 make: *** [check] Error 2

default_gdb_init has this:

    # Unlike most tests, we have a small number of tests that generate
    # a very large amount of output.  We therefore increase the expect
    # buffer size to be able to contain the entire test output.  This
    # is especially needed by gdb.base/info-macros.exp.
    match_max -d 65536
    # Also set this value for the currently running GDB.
    match_max [match_max -d]

It's the second match_max that is erroring.  As that call does not
specify an explicit channel name with -i, expect defaults to
$spawn_id, which is pointing at a channel that is already gone.  (If
the spawn_id variable is not set, match_max defaults to
$user_spawn_id / stdin/out).

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

	* gdb.server/non-existing-program.exp: Unset spawn_id.
2015-05-08 18:06:46 +01:00
Siva Chandra df2eb078c0 [PR python/18291] Fix printing of "disabled" status of xmethod matchers.
gdb/ChangeLog:

	PR python/18291
	* python/lib/gdb/command/xmethods.py (print_xm_info): Fix typo.
	Print xmethod matcher status.

gdb/testsuite/ChangeLog:

	PR python/18291
	* gdb.python/py-xmethods.exp: Add tests.
2015-05-08 07:20:04 -07:00
Yao Qi 422349a385 Fix PR 18208: update /proc/pid/coredump_filter by c code
Hi,
We see some fails in gdb.base/coredump-filter.exp when we do remote
gdbserver testing, like what I did for arm/aarch64 linux testing or
run it with board file remote-gdbserver-on-localhost

 $ make check RUNTESTFLAGS='--target_board=remote-gdbserver-on-localhost coredump-filter.exp'

we find that this line in the test doesn't work as expected,

 remote_exec target "sh -c \"echo $filter_flag > /proc/$ipid/coredump_filter\""

although such pattern has been used in gdb testsuite somewhere else,
but the special thing here is that we redirect the output to
/proc/$ipid/coredump_filter on the remote target.  DejaGNU will
redirect the output from the remote target to local, and looks tcl
gets confused by these two redirection.

After trying pass different parameters to remote_exec and hacking
remote_exec/rsh_exec/local_exec, I got no success, I decide
to give up, and try to update /proc/$ipid/coredump_filter by the c
code directly.

This patch adds a c function set_coredump_filter to update
coredump_filter, and GDB calls it.

gdb/testsuite:

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

	PR gdb/18208
	* gdb.base/coredump-filter.c (set_coredump_filter): New function.
	* gdb.base/coredump-filter.exp (do_save_core): Call inferior
	function set_coredump_filter, and remove remote_exec call.
	Remove argument ipid.  Callers update.
	(top level): Don't get inferior's PID.
2015-05-08 12:37:48 +01:00
Andreas Arnez 63fc80ce17 Skip watch_thread_num.exp on targets without access watchpoints
Since watch_thread_num.exp was changed to use access watchpoints, the
test case fails on s390 and s390x, since those targets do not support
access watchpoints.  This patch skips the test case on such targets.

gdb/testsuite/ChangeLog:

	* gdb.base/watch_thread_num.exp: Skip test on targets without
	access watchpoints.
2015-05-08 12:50:47 +02:00
Pedro Alves 80ad801e90 PR server/18081: gdbserver crashes when providing an unexisting binary
$ ./gdbserver :1234 blah
 Process blah created; pid = 16471
 Cannot exec blah: No such file or directory.

 Child exited with status 127
 Killing process(es): 16471
 ../../../../src/binutils-gdb/gdb/gdbserver/linux-low.c:920: A problem internal to GDBserver has been detected.
 kill_wait_lwp: Assertion `res > 0' failed.

GDBserver shouldn't even be trying to kill that process.  GDBserver
kills or detaches from all processes on exit, and due to a missing
mourn_inferior call, GDBserver tries to kill the process that it had
already seen exit.

Tested on x86_64 Fedora 20.  New test included.  I emulated what
Windows outputs by hacking an error call in linux_create_inferior.

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

	PR server/18081
	* server.c (start_inferior): If the process exits, mourn it.

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

	PR server/18081
	* gdb.server/non-existing-program.exp: New file.
2015-05-06 18:50:03 +01:00
Joel Brobecker 0fa7fe506c out of line functions nested inside inline functions.
This patch improves the handling of out-of-line functions nested
inside functions that have been inlined.

Consider for instance a situation where function Foo_O224_021
has a function Child1 declared in it, which itself has a function
Child2 nested inside Child1. After compiling the program with
optimization on, Child1 gets inlined, but not Child2.

After inserting a breakpoint on Child2, and running the program
until reaching that breakpoint, we get the following backtrace:

    % gdb foo_o224_021
    (gdb) break foo_o224_021.child1.child2
    (gdb) run
    [...]
    Breakpoint 1, foo_o224_021 () at foo_o224_021.adb:28
    28          Child1;
    (gdb) bt
    #0  0x0000000000402400 in foo_o224_021 () at foo_o224_021.adb:28
    #1  0x00000000004027a4 in foo_o224_021.child1 () at foo_o224_021.adb:23
    #2  0x00000000004027a4 in foo_o224_021 () at foo_o224_021.adb:28

GDB reports the wrong function name for frame #0. We also get the same
kind of error in the "Breakpoint 1, foo_o224_021 () [...]" message.
In both cases, the function name should be foo_o224_021.child1.child2,
and the parameters should be "s=...".

What happens is that the inlined frame handling does not handle well
the case where an inlined function is calling an out-of-line function
which was declared inside the inlined function's scope.

In particular, looking first at the inlined-frame sniffer when applying
to frame #0:

        /* Calculate DEPTH, the number of inlined functions at this
           location.  */
        depth = 0;
        cur_block = frame_block;
        while (BLOCK_SUPERBLOCK (cur_block))
          {
            if (block_inlined_p (cur_block))
              depth++;
            cur_block = BLOCK_SUPERBLOCK (cur_block);
          }

What happens is that cur_block starts as the block associated
to child2, which is not inlined. We shoud be stopping here, but
instead, we keep walking the superblock chain, which takes us
all the way to Foo_O224_021's block, via Child2's block. And
since Child1 was inlined, we end up with a depth count of 1,
wrongly making GDB think that frame #0 is an inlined frame.

Same kind of issue inside skip_inline_frames.

The fix is to stop checking for inlined frames as soon as we see
a block corresponding to a function which is not inlined.  This is
the behavior we now obtain:

    (gdb) run
    [...]
    Breakpoint 1, foo_o224_021.child1.child2 (s=...) at foo_o224_021.adb:9
    9               function Child2 (S : String) return Boolean is
    (gdb) bt
    #0  0x0000000000402400 in foo_o224_021.child1.child2 (s=...)
        at foo_o224_021.adb:9
    #1  0x00000000004027a4 in foo_o224_021.child1 () at foo_o224_021.adb:23
    #2  0x00000000004027a4 in foo_o224_021 () at foo_o224_021.adb:28

gdb/ChangeLog:

        * inline-frame.c (inline_frame_sniffer, skip_inline_frames):
        Stop counting inlined frames as soon as an out-of-line function
        is found.

gdb/testsuite/ChangeLog:

        * gdb.ada/out_of_line_in_inlined.exp: Add run and "bt" tests.
2015-05-05 11:08:14 -07:00
Pierre-Marie de Rodat 3ea89b92fb DWARF: cannot break on out-of-line function nested inside inlined function.
Consider the following code, which defines a function, Child2,
which is itself nested inside Child1:

    procedure Foo_O224_021 is
        O1 : constant Object_Type := Get_Str ("Foo");
        procedure Child1 is
            O2 : constant Object_Type := Get_Str ("Foo");
            function Child2 (S : String) return Boolean is -- STOP
            begin
                for C of S loop
                    Do_Nothing (C);
                    if C = 'o' then
                        return True;
                    end if;
                end loop;
                return False;
            end Child2;
            R : Boolean;
        begin
            R := Child2 ("Foo");
            R := Child2 ("Bar");
            R := Child2 ("Foobar");
        end Child1;
    begin
        Child1;
    end Foo_O224_021;

On x86_64-linux, when compiled at -O2, GDB is unable to insert
a breakpoint on Child2:

    % gnatmake -g -O2 foo_o224_021
    % gdb foo_o224_021
    (gdb) b child2
    Function "child2" not defined.
    (gdb) b foo_o224_021.child1.child2
    Function "foo_o224_021.child1.child2" not defined.

The problem is caused by the fact that GDB did not create a symbol
for Child2, and this, in turn, is caused by the fact that the compiler
decided to inline Child1, but not Child2. The DWARF debugging info
first provides an abstract instance tree for Child1...

 <3><1b7b>: Abbrev Number: 29 (DW_TAG_subprogram)
    <1b7c>   DW_AT_name        : (indirect string, offset: 0x23f8): foo_o224_021__child1
    <1b82>   DW_AT_inline      : 1      (inlined)
    <1b83>   DW_AT_sibling     : <0x1c01>

... where that subprogram is given the DW_AT_inline attribute.
Inside that function there is a lexical block which has no PC
range (corresponding to the fact that this is the abstract tree):

 <4><1b87>: Abbrev Number: 30 (DW_TAG_lexical_block)

... inside which our subprogram Child2 is described:

 <5><1b92>: Abbrev Number: 32 (DW_TAG_subprogram)
    <1b93>   DW_AT_name        : (indirect string, offset: 0x2452): foo_o224_021__child1__child2
    <1b99>   DW_AT_type        : <0x1ab1>
    <1b9d>   DW_AT_low_pc      : 0x402300
    <1ba5>   DW_AT_high_pc     : 0x57
    [...]

Then, later on, we get the concrete instance tree, starting at:

 <3><1c5e>: Abbrev Number: 41 (DW_TAG_inlined_subroutine)
    <1c5f>   DW_AT_abstract_origin: <0x1b7b>
    <1c63>   DW_AT_entry_pc    : 0x4025fd
    <1c6b>   DW_AT_ranges      : 0x150

... which refers to Child1. One of that inlined subroutine children
is the concrete instance of the empty lexical block we saw above
(in the abstract instance tree), which gives the actual address
range for this inlined instance:

 <5><1c7a>: Abbrev Number: 43 (DW_TAG_lexical_block)
    <1c7b>   DW_AT_abstract_origin: <0x1b87>
    <1c7f>   DW_AT_ranges      : 0x180

This is the DIE which provides the context inside which we can
record Child2. But unfortunately, GDB does not take the abstract
origin into account when handling lexical blocks, causing it
to miss the fact that this block contains some symbols described
in the abstract instance tree. This is the first half of this patch:
modifying GDB to follow DW_AT_abstract_origin attributes for
lexical blocks.

But this not enough to fix the issue, as we're still unable to
break on Child2 with just that change. The second issue can be
traced to the way inherit_abstract_dies determines the list of
DIEs to inherit from. For that, it iterates over all the DIEs in
the concrete instance tree, and finds the list of DIEs from the
abstract instance tree that are not referenced from the concrete
instance tree. As it happens, there is one type of DIE in the
concrete instance tree which does reference Child2's DIE, but
in fact does otherwise define a concrete instance of the reference
DIE; that's (where <0x1b92> is Child2's DIE):

 <6><1d3c>: Abbrev Number: 35 (DW_TAG_GNU_call_site)
    <1d3d>   DW_AT_low_pc      : 0x4026a4
    <1d45>   DW_AT_abstract_origin: <0x1b92>

So, the second part of the patch is to modify inherit_abstract_dies
to ignore DW_TAG_GNU_call_site DIEs when iterating over the concrete
instance tree.

This patch also includes a testcase which can be used to reproduce
the issue. Unfortunately, for it to actually pass, a smal patch in
GCC is also necessary to make sure that GCC provides lexical blocks'
DW_AT_abstract_origin attributes from the concrete tree back to
the abstract tree. We hope to be able to submit and integrate that
patch in the GCC tree soon. Meanwhile, a setup_xfail has been added.

gdb/ChangeLog:

	2014-05-05  Pierre-Marie de Rodat  <derodat@adacore.com>
	* dwarf2read.c (inherit_abstract_dies): Skip
	DW_TAG_GNU_call_site dies while inheriting children of an
	abstract DIE into a scope.
	(read_lexical_block_scope): Inherit abstract DIE's for
	lexical scopes.

gdb/testsuite/ChangeLog:

        * gdb.ada/out_of_line_in_inlined: New testcase.
2015-05-05 11:06:09 -07:00
Joel Brobecker 87b8eff03f testsuite/gdb.ada/var_rec_arr: New testcase.
gdb/testsuite/ChangeLog:

        * gdb.ada/var_rec_arr: New testcase.
2015-05-05 10:48:21 -07:00
Yao Qi 5fccc63539 Skip setting HW watchpoint if skip_hw_watchpoint_multi_tests in gdb.base/break-idempotent.exp
Hi,
I see this fails below on arm linux native testing and remote testing
with "set remote hardware-watchpoint-limit 1",

 rwatch global^M
 There are not enough available hardware resources for this watchpoint.^M
 (gdb) FAIL: gdb.base/break-idempotent.exp: always-inserted off: rwatch: twice: rwatch global

gdb.base/break-idempotent.exp sets two breakpoints/watchpoints on the
same address.  GDB isn't smart enough calculate these two HW
watchpoints can fit in one HW debug register, so the error message
above isn't necessary (there is one HW watchpoint register on arm).
Because target_ops interface can_use_hardware_watchpoint doesn't
pass enough information to the target backend.

Note that if I don't "set remote hardware-watchpoint-limit 1" in
remote testing, this test passes without fails.  However without
"set remote hardware-watchpoint-limit 1", many other watchpoint
tests fail.

This patch is to add a check to skip_hw_watchpoint_multi_tests
for rwatch and awatch.  We can add such check for watch as well,
but GDB is able to switch to software watchpoint if HW resource
isn't available, it doesn't cause any fail, I decide not to skip.

gdb/testsuite:

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

	* gdb.base/break-idempotent.exp: If
	skip_hw_watchpoint_multi_tests returns true, skip the tests
	on "rwatch" and "awatch".
2015-04-30 10:08:10 +01:00
Yao Qi 42d38f42dc Skip gdb.base/relativedebug.exp if libc doesn't have debug info
Hi,
I see the fail in gdb.base/relativedebug.exp on aarch64 box on which
glibc doesn't have debug info,

 bt^M
 #0 0x0000002000061a88 in raise () from /lib/aarch64-linux-gnu/libc.so.6^M
 #1 0x0000002000064efc in abort () from /lib/aarch64-linux-gnu/libc.so.6^M
 #2 0x0000000000400640 in handler (signo=14) at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:25^M
 #3 <signal handler called>^M
 #4 0x00000020000cc478 in ?? () from /lib/aarch64-linux-gnu/libc.so.6^M
 #5 0x0000000000400664 in main () at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:32^M
 (gdb) FAIL: gdb.base/relativedebug.exp: pause found in backtrace

if glibc has debug info, this test doesn't fail.

In sysdeps/unix/sysv/linux/generic/pause.c, __libc_pause calls
__syscall_pause,

  static int
  __syscall_pause (void)
  {
    sigset_t set;

    int rc =
      INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, _NSIG / 8);
    if (rc == 0)
      rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8);

    return rc;
  }

  int
  __libc_pause (void)
  {
    if (SINGLE_THREAD_P)
      return __syscall_pause ();     <--- tail call

    int oldtype = LIBC_CANCEL_ASYNC ();

    int result = __syscall_pause ();

    LIBC_CANCEL_RESET (oldtype);

    return result;
  }

and GDB unwinder is confused by the GCC optimized code,

(gdb) disassemble pause
Dump of assembler code for function pause:
   0x0000007fb7f274c4 <+0>:     stp     x29, x30, [sp,#-32]!
   0x0000007fb7f274c8 <+4>:     mov     x29, sp
   0x0000007fb7f274cc <+8>:     adrp    x0, 0x7fb7fd2000
   0x0000007fb7f274d0 <+12>:    ldr     w0, [x0,#364]
   0x0000007fb7f274d4 <+16>:    stp     x19, x20, [sp,#16]
   0x0000007fb7f274d8 <+20>:    cbnz    w0, 0x7fb7f274e8 <pause+36>

   0x0000007fb7f274dc <+24>:    ldp     x19, x20, [sp,#16]
   0x0000007fb7f274e0 <+28>:    ldp     x29, x30, [sp],#32
   0x0000007fb7f274e4 <+32>:    b       0x7fb7f27434    <---- __syscall_pause

   0x0000007fb7f274e8 <+36>:    bl      0x7fb7f5e080

Note that the program stops in __syscall_pause, but its symbol is
stripped in glibc, so GDB doesn't know where the program stops.
__syscall_pause is a tail call in __libc_pause, so it returns to main
instead of __libc_pause.  As a result, the backtrace is like,

 #0  0x0000007fb7ebca88 in raise () from /lib/aarch64-linux-gnu/libc.so.6
 #1  0x0000007fb7ebfefc in abort () from /lib/aarch64-linux-gnu/libc.so.6
 #2  0x0000000000400640 in handler (signo=14) at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:25
 #3  <signal handler called>
 #4  0x0000007fb7f27478 in ?? () from /lib/aarch64-linux-gnu/libc.so.6   <-- [in __syscall_pause]
 #5  0x0000000000400664 in main () at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:32

looks GDB does nothing wrong here.  I looked back at the test case
gdb.base/relativedebug.exp, which was added
https://sourceware.org/ml/gdb-patches/2006-10/msg00305.html
This test was indented to test the problem that "backtraces no longer
display some libc functions" after separate debug info is installed.
IOW, it makes few sense to test against libc which doesn't have debug
info at all, such as my case.

This patch is to tweak the test case to catch the output of
"info shared", if "(*)" is found for libc.so, which means libc doesn't
have debug info, then skip the test.

gdb/testsuite:

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

	* gdb.base/relativedebug.exp: Invoke gdb command
	"info sharedlibrary", and if libc.so doesn't have debug info,
	skip the test.
2015-04-30 09:55:06 +01:00
Doug Evans 2ce1cdbf84 PR python/18285
gdb/ChangeLog:

	PR python/18285
	* NEWS: Document new gdb.XMethodWorker.get_result_type method.
	* eval.c (evaluate_subexp_standard) <OP_FUNCALL>: Handle
	EVAL_AVOID_SIDE_EFFECTS for xmethods.
	* extension-priv.h (struct extension_language_ops)
	<get_xmethod_result_type>: New member.
	* extension.c (get_xmethod_result_type): New function.
	* extension.h (get_xmethod_result_type): Declare.
	* python/py-xmethods.c (get_result_type_method_name): New static
	global.
	(py_get_result_type_method_name): Ditto.
	(gdbpy_get_xmethod_result_type): New function.
	(gdbpy_initialize_xmethods): Initialize py_get_result_type_method_name.
	* python/python-internal.h (gdbpy_get_xmethod_result_type): Declare.
	* python/python.c (python_extension_ops): Add
	gdbpy_get_xmethod_result_type.
	* python/lib/gdb/xmethod.py (XMethodWorker): Add get_result_type.
	* valarith.c (value_x_binop): Handle EVAL_AVOID_SIDE_EFFECTS for
	xmethods.
	(value_x_unop): Ditto.
	* value.c (result_type_of_xmethod): New function.
	* value.h (result_type_of_xmethod): Declare.

gdb/testsuite/ChangeLog:

	* gdb.python/py-xmethods.exp: Add ptype tests.
	* gdb.python/py-xmethods.py (E_method_char_worker): Add
	get_result_type method.

gdb/doc/ChangeLog:

	* python.texi (Xmethod API) <gdb.XMethodWorker.get_result_type>:
	Document.
	(Writing an Xmethod): Add get_result_type to example.
2015-04-29 13:24:21 -07:00
Luis Machado f24a38c514 Use software watchpoints if hardware watchpoints are not available when testing gdb.base/watch-bitfields.exp
There are targets GDB thinks support hardware watchpoints, but in reality they
don't.  Though it may seem that hardware watchpoint creation was successful,
the actual insertion of such watchpoint will fail when GDB moves the inferior.

(gdb) watch -location q.a^M
Hardware watchpoint 2: -location q.a^M
(gdb) PASS: gdb.base/watch-bitfields.exp: -location watch against bitfields: watch -location q.a
watch -location q.e^M
Hardware watchpoint 3: -location q.e^M
(gdb) PASS: gdb.base/watch-bitfields.exp: -location watch against bitfields: watch -location q.e
print q.a^M
$1 = 0^M
(gdb) PASS: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: print expression before
continue^M
Continuing.^M
Warning:^M
Could not insert hardware watchpoint 2.^M
Could not insert hardware watchpoint 3.^M
Could not insert hardware breakpoints:^M
You may have requested too many hardware breakpoints/watchpoints.^M
^M
(gdb) FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: continue

This leads to a number of FAILs:

FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: print expression after
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 0->5: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 0->5: print expression after
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 1->0: print expression before
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 1->0: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 5->4: print expression before
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 5->4: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 5->4: print expression after
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: continue until exit
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 0->4: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 0->4: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 4->10: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 4->10: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 4->10: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 10->3: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 10->3: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 10->3: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 3->2: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 3->2: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 3->2: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 2->1: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 2->1: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 2->1: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 1->0: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 1->0: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: continue until exit

We can avoid these errors/FAILs by checking the board data and switching to
software watchpoints if the board does not support hardware watchpoints.

gdb/testsuite/ChangeLog:

2015-04-29  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/watch-bitfields.exp: Switch to software watchpoints if
	the target does not support hardware watchpoints.
2015-04-29 12:22:24 -03:00
Luis Machado ecbf2b3c4f Handle memory write errors on gdb.base/break-always.exp
This is another case of the testcase not handling memory write errors that
happen on some targets (QEMU) when GDB attempts to modify an address that
should contain a breakpoint, for example.

The following patch handles this and prevents spurious failures from
happening. It also adds a foreach loop to avoid duplication of code
and hardcoded patterns.

gdb/testsuite/ChangeLog:

2015-04-29  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/break-always.exp: Abort testing if writing to memory
	causes an error.
2015-04-29 12:09:40 -03:00
Doug Evans 34f5f757b3 PR python/18299
gdb/ChangeLog:

	PR python/18299
	* python/lib/gdb/printing.py (register_pretty_printer): Handle
	name or __name__ attributes.  Handle gdb module as first argument.

gdb/testsuite/ChangeLog:

	* gdb.python/py-pp-maint.py: Move "replace" testing to ...
	* gdb.python/py-pp-registration.exp: ... here.  New file.
	* gdb.python/py-pp-registration.c: New file.
	* gdb.python/py-pp-registration.py: New file.
2015-04-28 22:14:23 -07:00
Doug Evans 69b4374a87 PR python/18089
gdb/ChangeLog:

	PR python/18089
	* python/py-prettyprint.c (print_children): Verify result of children
	iterator.  Provide better error message.
	* python/python-internal..h (gdbpy_print_python_errors_p): Declare.
	* python/python.c (gdbpy_print_python_errors_p): New function.

gdb/testsuite/ChangeLog:

	* gdb.python/py-bad-printers.c: New file.
	* gdb.python/py-bad-printers.py: New file.
	* gdb.python/py-bad-printers.exp: New file.
2015-04-28 21:53:54 -07:00
Sasha Smundak 59fb7612dd Add gdb.Type.optimized_out method.
gdb/ChangeLog:

	* NEWS: Mention gdb.Type.optimized_out method.
	* python/py-type.c (typy_optimized_out):  New function.

gdb/doc/ChangeLog:

	* python.texi: New method documented.

gdb/testsuite/ChangeLog:

	* gdb.python/py-type.exp: New test.
2015-04-28 17:41:09 -07:00
Andy Wingo 2631b16a57 Fix py-parameter.exp and scm-parameter.exp path matching
gdb/testsuite/ChangeLog:

	* gdb.python/py-parameter.exp:
	* gdb.guile/scm-parameter.exp: Escape the path that we are
	matching against, as it might contain characters that are special
	to regular expressions.
2015-04-28 11:15:47 +02:00
Joel Brobecker 460efde16c [Ada] Preserve typedef layer when getting struct element
Consider the following declarations:

   type Int_Access is access Integer;
   type Record_Type is record
      IA : Int_Access;
   end record;

   R : Record_Type;

Printing the type name of "R.IA" yields:

    (gdb) whatis r.ia
    type = access integer

It should be:

    (gdb) whatis r.ia
    type = bar.int_access

Looking at the debugging info, field "r.ia" is defined as
a typedef which has the name of the field type:

        .uleb128 0x3    # (DIE (0x4e) DW_TAG_typedef)
        .long   .LASF4  # DW_AT_name: "bar__int_access"
        .long   0x8b    # DW_AT_type

... with the typedef's target type being an anonymous pointer
type:

        .uleb128 0x7    # (DIE (0x8b) DW_TAG_pointer_type)
        .byte   0x8     # DW_AT_byte_size
        .long   0x91    # DW_AT_type

What happens here is that a couple of function in ada-lang.c
always start by stripping all typedef layers when handling
struct fields, with the effect of making us lose the type name
in this case.

We did not understand this at the time the code was written,
but typedefs should be stripped only when we know we do not
need them. So this patch, adjust the code to avoid the stripping
while handling the fields, and adds it back in the lone place
which handles the result of processing and didn't know how to
handle typedefs struct fields yet.

gdb/ChangeLog:

        * ada-lang.c (ada_is_tagged_type): Add call to ada_check_typedef.
        (ada_lookup_struct_elt_type): Remove calls to ada_check_typedef.
        (template_to_static_fixed_type): Call ada_check_typedef only
        when necessary.

gdb/testsuite/ChangeLog:

        * gdb.ada/rec_comp: New testcase.
2015-04-27 11:04:47 +02:00
Sergio Durigan Junior 2d369d8e97 Clear variable "coredump_var_addr" before using it on gdb.base/coredump-filter.exp
This commit is a continuation of the fix committed on:

  commit 8cd8f2f8ac
  Author: Sergio Durigan Junior <sergiodj@redhat.com>
  Date:   Mon Apr 13 02:40:08 2015 -0400

      Rename variable "addr" to "coredump_var_addr" in gdb.base/coredump-filter.exp

Pedro pointed out that this fix was not complete, because the
testsuite could be run several times in a row (for example), which
means that it is not enough to just make the variable name unique: it
also needs to be cleared out if it is global.

This commit does that.  It is actually just a commit made to make
things totally correct; this specific test does not fail if you run it
several times in a row.

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

	* gdb.base/coredump-filter.exp: Clear variable "coredump_var_addr"
	before using it.
2015-04-26 15:34:29 -04:00
Andrew Burgess cf75d6c37e gdb: Add support for dumping to verilog hex format.
Extend the gdb 'dump' command to allow creating output in verilog hex
format.  Add some tests to cover new functionality.  As bfd does not
currently support reading in verilog hex formats the tests only cover
the 'dump' command, not the 'restore' command.

gdb/ChangeLog:

	* cli/cli-dump.c (verilog_cmdlist): New variable.
	(dump_verilog_memory): New function.
	(dump_verilog_value): New function.
	(verilog_dump_command): New function.
	(_initialize_cli_dump): Add new commands to support verilog dump
	format.
	* NEWS: Add entry for "dump verilog".

gdb/doc/ChangeLog:

	* gdb.texinfo (Dump/Restore Files): Add detail about verilog dump
	format.

gdb/testsuite/ChangeLog:

	* gdb.base/dump.exp: Add *.verilog files to all_files list.  Add
	new tests for verilog output.
2015-04-24 22:49:59 +01:00
Yao Qi 8dbe7ca5a5 A new board file remote-gdbserver-on-localhost.exp
This patch is to add a new board file that does real remote gdbserver
testing on localhost.  This board file can be used to reproduce PR 18208.

gdb/testsuite

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

	* boards/remote-gdbserver-on-localhost.exp: New file.
2015-04-24 11:00:14 +01:00
Pedro Alves 4ef9fb2f07 Fix gdb.base/interrupt.exp racy fail against gdbserver
Currently, against gdbserver, interrupt.exp occasionaly fails like
this:

 ERROR: Process no longer exists
 UNRESOLVED: gdb.base/interrupt.exp: send end of file

The problem is that we see gdbserver exiting before we match gdb's
output:

 expect: does "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n" (spawn_id exp8) match regular expression "end of file"? Gate "end of file"? gate=no
 expect: read eof
 expect: set expect_out(spawn_id) "exp8"
 expect: set expect_out(buffer) "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n"

Fix this by removing $inferior_spawn_id from the set of spawn ids
expect is watching as soon as we see the "end of file" string out of
the inferior spawn id, using an indirect spawn id list.

Tested on x86-64 Fedora 20, native and gdbserver (both target remote
and extended-remote).

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

	* gdb.base/interrupt.exp: Use an indirect spawn id list holding
	$inferior_spawn_id instead of $inferior_spawn_id directly.  On
	"end of file", remove $inferior_spawn_id from the indirect list.
2015-04-23 15:48:27 +01:00
Pedro Alves 0a8031692e gdb.base/interrupt.exp: Rename saw_eof to saw_end_of_file
To avoid confusion between "end of file" string matching and eof
matching, as in process exit.

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

	* gdb.base/interrupt.exp: Rename saw_eof to saw_end_of_file.
2015-04-23 15:48:27 +01:00
Pedro Alves 749ef8f891 gdb_test_multiple match eof of any spawn_id
Since silent handling of eof is usually the wrong thing to do, this
patch makes gdb_test_multiple handle it for all $any_spawn_id.

Currently, against gdbserver, interrupt.exp occasionaly fails like
this:

 FAIL: gdb.base/interrupt.exp: send end of file

gdb.log with expect debug output enabled shows:

 expect: does "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n" (spawn_id exp8) match regular expression "end of file"? Gate "end of file"? gate=no
 expect: read eof
 expect: set expect_out(spawn_id) "exp8"
 expect: set expect_out(buffer) "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n"
 FAIL: gdb.base/interrupt.exp: send end of file

Note "expect: read eof" for spawn_id=exp8.  exp8 is
inferior_spawn_id/gdbserver_spawn_id.  That means
expect/gdb_test_multiple saw gdbserver exit before we got the expected
gdb output.  Since there's no explicit pattern for "eof", expect (and
thus gdb_test_multiple) just returns.

After this commit, we get instead:

 ERROR: Process no longer exists
 UNRESOLVED: gdb.base/interrupt.exp: send end of file

Note that before we still got an FAIL because $saw_inferior_exit is 0
when we get to:

	gdb_assert { $saw_eof && $saw_inferior_exit } $msg

Fixing the fail (now unresolved) will be the subject of a separate
patch.

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

	* lib/gdb.exp (gdb_test_multiple): Match eof/full_buffer/timeout
	on $any_spawn_id instead of only on $gdb_spawn_id.
2015-04-23 15:48:26 +01:00
Pierre Muller 8aae434443 Fix pascal behavior for class fields with testcase
Problem reported as PR pascal/17815

Part 1/3: Remember the case pattern that allowed finding a field of this.
File gdb/p-exp.y modified

  This is the fix in the pascal parser (p-exp.y),
to avoid the error that GDB does find normal variables
case insensitively, but not fields of this,
inside a class or object method.

Part 2/3: Add "class" option for pascal compiler
File gdb/testsuite/lib/pascal.exp

This part of the patch series is unchanged.
It adds class option to pascal compiler
which adds the required command line option to
accept pascal class types.

Part 3/3:
New file: gdb/testsuite/gdb.pascal/case-insensitive-symbols.exp
New file: gdb/testsuite/gdb.pascal/case-insensitive-symbols.pas

  Here is an updated version of this test, using Pedro's suggestions.
Test to check that PR 17815 is fixed.
2015-04-21 22:10:08 +02:00
Gary Benson 1586c8fbaf Fix three test failures with extended remote targets
This commit fixes three gdb.base/attach.exp failures when using
extended remote targets.  The failures occurred because GDB now
locates and loads files when attaching on remote targets if the
remote target supports qXfer:exec-file:read; the filenames were
shown but with "target:" prefixes which the test has been updated
to handle.

gdb/testsuite/ChangeLog:

	* gdb.base/attach.exp: Fix three extended remote failures.
2015-04-20 11:36:02 +01:00
Gary Benson 1b6e6f5c7f Access executable from remote system when first inferior appears
This commit modifies remote_add_inferior to take an extra argument
try_open_exec.  If this is nonzero, remote_add_inferior will attempt
to open this inferior's executable as the main executable if no main
executable is open already.  Callers are updated appropriately.

With this commit, remote debugging can now be initiated using only a
"target remote" or "target extended-remote" command; no "set sysroot"
or "file" commands are required, e.g.

  bash$ gdb -q
  (gdb) target remote | gdbserver - /bin/sh
  Remote debugging using | gdbserver - /bin/sh
  Process /bin/sh created; pid = 32166
  stdin/stdout redirected
  Remote debugging using stdio
  Reading symbols from target:/bin/bash...

One testcase required updating as a result of this commit.  The test
checked that GDB's "info files" command does not crash if no main
executable is open, and relied on GDB's inability to access the main
executable over the remote protocol.  The test was updated to inhibit
this new behavior.

gdb/ChangeLog:

	* remote.c (remote_add_inferior): New argument try_open_exec.
	If nonzero, attempt to open the inferior's executable file as
	the main executable if no main executable is open already.
	All callers updated.
	* NEWS: Mention that GDB now supports automatic location and
	retrieval of executable + files from remote targets.

gdb/doc/ChangeLog:

	* gdb.texinfo (Connecting to a Remote Target): Mention that
	GDB can access program files from remote targets that support
	qXfer:exec-file:read and Host I/O packets.

gdb/testsuite/ChangeLog:

	* gdb.server/server-exec-info.exp: Inhibit GDB from accessing
	the main executable over the remote protocol.
2015-04-17 09:47:30 +01:00
Pedro Alves e797481d53 Fix {mi-tracepoint-changed, mi-tsv-changed}.exp with native-extended-gdbserver
Fixes:

 -FAIL: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint created
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint on marker is installed
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1


 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created

These tests do something like this:

 #0 - start gdb/gdbserver normally
 #1 - setup some things in the debug session
 #2 - disconnect from gdbserver
 #3 - restart gdb
 #4 - reconnect to gdbserver

The problem is that the native-extended-gdbserver board always spawns
a new gdbserver instance in #3 (and has gdb connect to that).  So when
the test gets to #4, it connects to that new instance instead of the
old one:

 (gdb) spawn ../gdbserver/gdbserver --multi :2354
 Listening on port 2354
 target extended-remote localhost:2354
 Remote debugging using localhost:2354
 ...
 spawn ../gdbserver/gdbserver --multi :2355
 Listening on port 2355
 47-target-select extended-remote localhost:2355
 =tsv-created,name="trace_timestamp",initial="0"\n
 47^connected
 (gdb)
 ...
 47-target-select extended-remote localhost:2355
 47^connected
 (gdb)
 FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created

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

	* boards/native-extended-gdbserver.exp (mi_gdb_start): Don't start
	a new gdbserver if gdbserver_reconnect_p is set.
2015-04-16 14:36:52 +01:00
Pedro Alves 1ca99c4299 Fix gdbserver_reconnect_p handling
Commit 6423214f (testsuite: Don't use expect_background to reap
gdbserver) broke a couple tests that set gdbserver_reconnect_p and
restart gdb before reconnecting, because a gdb_exit (e.g., through
clean_restart) exits gdbserver unconditionally.

Fixes, with --target_board=native-gdbserver:

 -FAIL: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint created
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint on marker is installed
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1

 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created

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

	* lib/gdbserver-support.exp (gdb_exit): If gdbserver_reconnect_p
	is set, don't exit gdbserver.
2015-04-16 14:26:59 +01:00
Andreas Arnez af9fd6f863 s390-vregs.exp: Avoid compile errors with older GCCs and on 31-bit targets
The test case s390-vregs.exp yields compile errors on 31-bit targets
as well as when using a GCC that defaults to an older "-march=".  This
patch fixes these issues.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-vregs.S (change_vrs): Replace exrl by an
	appropriate .insn, such that an older assembler can be used.
	* gdb.arch/s390-vregs.exp: Add the compile flag -mzarch, to enable
	the z/Architecture instruction set on 31-bit targets as well.
2015-04-16 13:03:48 +02:00
Andreas Arnez 04ff1e612e GDB tests for Go language support: remove unnecessary first breakpoint
On s390x targets some of the Go test cases fail because the first
breakpoint happens to be at the same spot as the breakpoint at
main.main.  When such a test case tries to continue to the first
breakpoint, the program runs until the end instead, and the test fails
like this:

FAIL: gdb.go/handcall.exp: Going to first breakpoint (the program exited)

This patch removes all the handling related to the first breakpoint in
those cases.  After applying the patch, the tests run successfully on
s390x.

gdb/testsuite/ChangeLog:

	* gdb.go/handcall.exp: Remove all logic related to the first
	breakpoint and rely on go_runto_main instead.
	* gdb.go/strings.exp: Likewise.
	* gdb.go/unsafe.exp: Likewise.
	* gdb.go/hello.exp: Likewise.  Also rename the remaining
	breakpoint marker to "breakpoint 1".
	* gdb.go/handcall.go: Remove comment "set breakpoint 1 here".
	* gdb.go/strings.go: Likewise.
	* gdb.go/unsafe.go: Likewise.
	* gdb.go/hello.go: Likewise.  Also remove the second occurrence of
	"set breakpoint 2 here" and rename the remaining breakpoint marker
	to "breakpoint 1".
2015-04-16 13:03:47 +02:00
Simon Marchi 40d2f8d62e Some Python 3 fixes
Some missing parentheses and one itertools.imap (Py2) vs map (Py3) issue.

gdb/ChangeLog:

	* python/lib/gdb/command/unwinders.py: Add parentheses.

gdb/testsuite/ChangeLog:

	* gdb.python/py-framefilter.py (ErrorFilter.filter): Use map function
	if itertools.imap is not present.
	* gdb.python/py-objfile.exp: Add parentheses.
	* gdb.python/py-type.exp: Same.
	* gdb.python/py-unwind-maint.py: Same.
2015-04-15 11:54:33 -04:00
Yao Qi 8cbc97c629 Fix fails in gdb.dwarf2/dynarr-ptr.exp
I see many fails in gdb.dwarf2/dynarr-ptr.exp on arm-linux target,
started from this

print foo.three_ptr.all^M
Cannot access memory at address 0x107c8^M
(gdb) FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.three_ptr.all
print foo.three_ptr.all(1)^M
Cannot access memory at address 0x107c8

It turns out that ":$ptr_size" is used incorrectly.

             array_ptr_label: DW_TAG_pointer_type {
                 {DW_AT_byte_size :$ptr_size }
                                  ^^^^^^^^^^
                 {DW_AT_type :$array_label}
             }

Since the FORM isn't given, and it starts with the ":", it is regarded
as a label reference by dwarf assembler.  The generated asm file on
x86_64 is

        .uleb128        6               /* Abbrev (DW_TAG_pointer_type) */
        .4byte        8 - .Lcu1_begin   <----- WRONG
        .4byte        .Llabel2 - .Lcu1_begin

Looks .Lcu1_begin is 0 on x86_64 and that is why this test passes on
x86_64.  On arm, .Lcu1_begin is an address somewhere, and the value
of DW_AT_byte_size is a very large number, so memory read request
of such large length failed.

This patch is to remove ":" and set the form explicitly.  The generated
asm file on x86_64 becomes

        .uleb128        6               /* Abbrev (DW_TAG_pointer_type) */
        .byte        8
        .4byte        .Llabel2 - .Lcu1_begin

gdb/testsuite:

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

	* gdb.dwarf2/dynarr-ptr.exp (assemble): Use $ptr_size instead
	of ":$ptr_size" and set its form explicitly.
2015-04-15 14:05:07 +01:00
Yao Qi 45fd756caf Increase timeout in watch-bitfields.exp for software watchpoint
I see the following two timeout fails on pandaboard (arm-linux target),

 FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: continue until exit (timeout)
 FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: continue until exit (timeout)

In this test, more than one watchpoint is used, so the following
watchpoint requests fall back to software watchpoint, so that GDB
will single step all the way and it is very slow.

This patch is to copy the fix from

  [PATCH] GDB/testsuite: Correct gdb.base/watchpoint-solib.exp timeout tweak
  https://sourceware.org/ml/gdb-patches/2014-07/msg00716.html

I find the left-over of this patch review is to factor out code into
a procedure, so I do that in this patch.

Re-run tests watch-bitfields.exp, watchpoint-solib.exp, sigall-reverse.exp,
and until-precsave.exp on pandaboard, no regression.

gdb/testsuite:

2015-04-15  Pedro Alves  <palves@redhat.com>
	    Yao Qi  <yao.qi@linaro.org>

	* gdb.base/watch-bitfields.exp (test_watch_location): Increase
	timeout by factor of 4.
	(test_regular_watch): Likewise.
	* gdb.base/watchpoint-solib.exp: Use with_timeout_factor.
	* gdb.reverse/sigall-reverse.exp: Likewise.
	* gdb.reverse/until-precsave.exp: Likewise.
	* lib/gdb.exp (with_timeout_factor): New proc.
	(gdb_expect): Move some code to ...
	(get_largest_timeout): ... here.  New procedure.
2015-04-15 12:46:58 +01:00
Luis Machado 9e811bc379 Harden gdb.base/bp-permanent.exp
Reinstate test message and replace hardcoded test command with a variable.

gdb/testsuite/ChangeLog:
2015-04-14  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/bp-permanent.exp (test): Reinstate correct test message.
2015-04-14 09:25:27 -03:00
Luis Machado 0ff6fcb2f0 Harden gdb.base/bp-permanent.exp
This testcase does not work as expected in QEMU (aarch64 QEMU in my case). It
fails when trying to manually write the breakpoint instruction to a certain
PC address.

(gdb) p /x addr_bp[0] = buffer[0]^M
Cannot access memory at address 0x400834^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[0] = buffer[0]
p /x addr_bp[1] = buffer[1]^M
Cannot access memory at address 0x400835^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[1] = buffer[1]
p /x addr_bp[2] = buffer[2]^M
Cannot access memory at address 0x400836^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[2] = buffer[2]
p /x addr_bp[3] = buffer[3]^M
Cannot access memory at address 0x400837^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[3] = buffer[3]

The following patch prevents a number of failures by detecting this and bailing out in case the target has such a restriction. Writing to .text from within the program isn't any better. It just leads to a SIGSEGV.

Before the patch:

                === gdb Summary ===

After the patch:

                === gdb Summary ===

gdb/testsuite/ChangeLog:
2015-04-13  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/bp-permanent.exp (test): Handle the case of being unable
	to write to the .text section.
2015-04-13 14:45:56 -03:00
Luis Machado 7578d5f72c Harden gdb.base/coredump-filter.exp
This testcase seems to assume the target is running Linux, so bare metal,
simulators and other debugging stubs running different OS' will have a
hard time executing some of the commands the testcase issues.

Even restricting the testcase to Linux systems (which the patch below does),
there are still problems with, say, QEMU not providing PID information when
"info inferior" is issued. As a consequence, the subsequent tests will either
fail or will not make much sense.

The attached patch checks if PID information is available. If not, it just
bails out and avoids running into a number of failures.

gdb/testsuite/ChangeLog:
2015-04-13  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/coredump-filter.exp: Restrict test to Linux systems only.
	Handle the case of targets that do not provide PID information.
2015-04-13 14:42:48 -03:00
Yao Qi 2efe15c428 Catch exception in lib/gdbserver-support.exp:gdb_exit
I see the error when I run gdb-sigterm.exp with native-gdbserver
on x86_64-linux.

infrun: prepare_to_wait^M
Cannot execute this command while the target is running.^M
Use the "interrupt" command to stop the target^M
and then try again.^M
gdb.base/gdb-sigterm.exp: expect eof #0: got eof
gdb.base/gdb-sigterm.exp: expect eof #0: stepped 12 times
ERROR OCCURED: : spawn id exp8 not open
    while executing
"expect {
-i exp8 -timeout 10
            -re "$gdb_prompt $" {
                exp_continue
            }
            -i "$server_spawn_id" eof {
                wait -i $expect_out(spawn_id)
                unse..."
    ("uplevel" body line 1)
    invoked from within

In gdb-sigterm.exp, SIGTERM is sent to GDB and it exits.  However,
Dejagnu or tcl doesn't know this.

This patch is to catch the exception, but error messages are still
shown in the console and gdb.log.  In order to avoid this, we also
replace gdb_expect with expect.

gdb/testsuite:

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

	* lib/gdbserver-support.exp (gdb_exit): Catch exception
	and use expect instead of gdb_expect.
2015-04-13 15:46:11 +01:00
Sergio Durigan Junior 8cd8f2f8ac Rename variable "addr" to "coredump_var_addr" in gdb.base/coredump-filter.exp
This commit renames the global array variable "addr" to an unique name
"coredump_var_addr" in the test gdb.base/coredump-filter.exp.  This is
needed because global arrays can have name conflicts between tests.
For example, this specific test was conflicting with dmsym.exp,
causing errors like:

  ERROR: tcl error sourcing ../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp.
  ERROR: can't set "addr": variable is array
      while executing
  "set addr "0x\[0-9a-zA-Z\]+""
      (file "../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp" line 45)
      invoked from within
  "source ../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp"
      ("uplevel" body line 1)
      invoked from within
  "uplevel #0 source ../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp"
      invoked from within
  "catch "uplevel #0 source $test_file_name""

This problem was reported by Yao Qi at:

  <https://sourceware.org/ml/gdb-patches/2015-04/msg00373.html>
  Message-Id: <1428666671-12926-1-git-send-email-qiyaoltc@gmail.com>

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

	* gdb.base/coredump-filter.exp: Rename variable "addr" to
	"coredump_var_addr" to avoid naming conflict with other testcases.
2015-04-13 02:45:16 -04:00
Pedro Alves 9ee417720b Cleanup signal-while-stepping-over-bp-other-thread.exp
gdb/testsuite/ChangeLog:
2015-04-10  Pedro Alves  <palves@redhat.com>

	* gdb.threads/signal-while-stepping-over-bp-other-thread.exp: Use
	gdb_test_sequence and gdb_assert.
2015-04-10 19:49:00 +01:00
Pedro Alves 07473109e1 step-over-trips-on-watchpoint.exp: Don't put addresses in test messages
Diffing test results, I noticed:

 -PASS: gdb.threads/step-over-trips-on-watchpoint.exp: displaced=on: with thread-specific bp: next: b *0x0000000000400811 thread 1
 +PASS: gdb.threads/step-over-trips-on-watchpoint.exp: displaced=on: with thread-specific bp: next: b *0x00000000004007d1 thread 1

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

	* gdb.threads/step-over-trips-on-watchpoint.exp (do_test): Use
	test messages that don't include the breakpoint address.
2015-04-10 19:23:24 +01:00
Yao Qi de3db44c87 [arm] watchpoint-reuse-slot.exp: skip setting HW points on some address
Hi,
ARM linux kernel has some requirements on the address/length setting
for HW breakpoints/watchpoints, but watchpoint-reuse-slot.exp doesn't
consider them and sets HW points on various addresses.  Many fails
are causes as a result:

stepi^M
Warning:^M
Could not insert hardware watchpoint 20.^M
Could not insert hardware breakpoints:^M
You may have requested too many hardware breakpoints/watchpoints.^M
^M
(gdb) FAIL: gdb.base/watchpoint-reuse-slot.exp: always-inserted off: watch x watch: : width 2, iter 2: base + 1: stepi advanced

watch *(buf.byte + 2 + 1)@2^M
Hardware watchpoint 388: *(buf.byte + 2 + 1)@2^M
Warning:^M
Could not insert hardware watchpoint 388.^M
Could not insert hardware breakpoints:^M
You may have requested too many hardware breakpoints/watchpoints.^M
^M
(gdb) FAIL: gdb.base/watchpoint-reuse-slot.exp: always-inserted on: watch x watch: : width 2, iter 2: base + 1: watch *(buf.byte + 2 + 1)@2

This patch is to reflect kernel requirements in watchpoint-reuse-slot.exp
in order to skip some tests.

gdb/testsuite:

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

	* gdb.base/watchpoint-reuse-slot.exp (valid_addr_p): Return
	false for some offset and width combinations which aren't
	supported by linux kernel.
2015-04-10 16:23:13 +01:00
Pedro Alves c79d856c88 Test step-over-{lands-on-breakpoint|trips-on-watchpoint}.exp with displaced stepping
These tests exercise the infrun.c:proceed code that needs to know to
start new step overs (along with switch_back_to_stepped_thread, etc.).
That code is tricky to get right in the multitude of possible
combinations (at least):

 (native | remote)
  X (all-stop | all-stop-but-target-always-in-non-stop)
  X (displaced-stepping | in-line step-over).

The first two above are properties of the target, but the different
step-over-breakpoint methods should work with any target that supports
them.  This patch makes sure we always test both methods on all
targets.

Tested on x86-64 Fedora 20.

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

	* gdb.threads/step-over-lands-on-breakpoint.exp (do_test): New
	procedure, factored out from ...
	(top level): ... here.  Add "set displaced-stepping" testing axis.
	* gdb.threads/step-over-trips-on-watchpoint.exp (do_test): New
	parameter "displaced".  Use it.
	(top level): Use foreach and add "set displaced-stepping" testing
	axis.
2015-04-10 13:31:59 +01:00
Pedro Alves ebc90b50ce Make gdb.threads/step-over-trips-on-watchpoint.exp effective on !x86
This test is currently failing like this on (at least) PPC64 and s390x:

 FAIL: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: step: step
 FAIL: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: next: next
 FAIL: gdb.threads/step-over-trips-on-watchpoint.exp: with thread-specific bp: step: step
 FAIL: gdb.threads/step-over-trips-on-watchpoint.exp: with thread-specific bp: next: next

gdb.log:

 (gdb) PASS: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: step: set scheduler-locking off
 step
 wait_threads () at ../../../src/gdb/testsuite/gdb.threads/step-over-trips-on-watchpoint.c:49
 49        return 1; /* in wait_threads */
 (gdb) FAIL: gdb.threads/step-over-trips-on-watchpoint.exp: no thread-specific bp: step: step

The problem is that the test assumes that both the "watch_me = 1;" and
the "other = 1;" lines compile to a single instruction each, which
happens to be true on x86, but no necessarily true everywhere else.
The result is that the test doesn't really test what it wants to test.

Fix it by looking for the instruction that triggers the watchpoint.

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

	* gdb.threads/step-over-trips-on-watchpoint.c (child_function):
	Remove comment.
	* gdb.threads/step-over-trips-on-watchpoint.exp (do_test): Find
	both the address of the instruction that triggers the watchpoint
	and the address of the instruction immediately after, and use
	those addresses for the test.  Fix comment.
2015-04-10 13:11:32 +01:00
Pedro Alves 8f572e5c0f Fix gdb.base/sigstep.exp with displaced stepping on software single-step targets
TL;DR:

When stepping over a breakpoint with displaced stepping, the core must
be notified of all signals, otherwise the displaced step fixup code
confuses a breakpoint trap in the signal handler for the expected trap
indicating the displaced instruction was single-stepped
normally/successfully.

Detailed version:

Running sigstep.exp with displaced stepping on, against my x86
software single-step branch, I got:

 FAIL: gdb.base/sigstep.exp: step on breakpoint, to handler: performing step
 FAIL: gdb.base/sigstep.exp: next on breakpoint, to handler: performing next
 FAIL: gdb.base/sigstep.exp: continue on breakpoint, to handler: performing continue

Turning on debug logs, we see:

 (gdb) step
 infrun: clear_proceed_status_thread (process 32147)
 infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
 infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=1, current thread [process 32147] at 0x400842
 displaced: stepping process 32147 now
 displaced: saved 0x400622: 49 89 d1 5e 48 89 e2 48 83 e4 f0 50 54 49 c7 c0
 displaced: %rip-relative addressing used.
 displaced: using temp reg 2, old value 0x3615eafd37, new value 0x40084c
 displaced: copy 0x400842->0x400622: c7 81 1c 08 20 00 00 00 00 00
 displaced: displaced pc to 0x400622
 displaced: run 0x400622: c7 81 1c 08
 LLR: Preparing to resume process 32147, 0, inferior_ptid process 32147
 LLR: PTRACE_CONT process 32147, 0 (resume event thread)
 linux_nat_wait: [process -1], [TARGET_WNOHANG]
 LLW: enter
 LNW: waitpid(-1, ...) returned 32147, No child processes
 LLW: waitpid 32147 received Alarm clock (stopped)
 LLW: PTRACE_CONT process 32147, Alarm clock (preempt 'handle')
 LNW: waitpid(-1, ...) returned 0, No child processes
 LLW: exit (ignore)
 sigchld
 infrun: target_wait (-1.0.0, status) =
 infrun:   -1.0.0 [process -1],
 infrun:   status->kind = ignore
 infrun: TARGET_WAITKIND_IGNORE
 infrun: prepare_to_wait
 linux_nat_wait: [process -1], [TARGET_WNOHANG]
 LLW: enter
 LNW: waitpid(-1, ...) returned 32147, No child processes
 LLW: waitpid 32147 received Trace/breakpoint trap (stopped)
 CSBB: process 32147 stopped by software breakpoint
 LNW: waitpid(-1, ...) returned 0, No child processes
 LLW: trap ptid is process 32147.
 LLW: exit
 infrun: target_wait (-1.0.0, status) =
 infrun:   32147.32147.0 [process 32147],
 infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
 infrun: TARGET_WAITKIND_STOPPED
 displaced: restored process 32147 0x400622
 displaced: fixup (0x400842, 0x400622), insn = 0xc7 0x81 ...
 displaced: restoring reg 2 to 0x3615eafd37
 displaced: relocated %rip from 0x400717 to 0x400937
 infrun: stop_pc = 0x400937
 infrun: delayed software breakpoint trap, ignoring
 infrun: no line number info
 infrun: stop_waiting
 0x0000000000400937 in __dso_handle ()
 1: x/i $pc
 => 0x400937:    and    %ah,0xa0d64(%rip)        # 0x4a16a1
 (gdb) FAIL: gdb.base/sigstep.exp: displaced=on: step on breakpoint, to handler: performing step


What should have happened is that the breakpoint hit in the signal
handler should have been presented to the user.  But note that
"preempt 'handle'" -- what happened instead is that
displaced_step_fixup confused the breakpoint in the signal handler for
the expected SIGTRAP indicating the displaced instruction was
single-stepped normally/successfully.

This should be affecting all software single-step targets in the same
way.

The fix is to make sure the core sees all signals when displaced
stepping, just like we already must see all signals when doing an
stepping over a breakpoint in-line.  We now get:

 infrun: target_wait (-1.0.0, status) =
 infrun:   570.570.0 [process 570],
 infrun:   status->kind = stopped, signal = GDB_SIGNAL_ALRM
 infrun: TARGET_WAITKIND_STOPPED
 displaced: restored process 570 0x400622
 infrun: stop_pc = 0x400842
 infrun: random signal (GDB_SIGNAL_ALRM)
 infrun: signal arrived while stepping over breakpoint
 infrun: inserting step-resume breakpoint at 0x400842
 infrun: resume (step=0, signal=GDB_SIGNAL_ALRM), trap_expected=0, current thread [process 570] at 0x400842
 LLR: Preparing to resume process 570, Alarm clock, inferior_ptid process 570
 LLR: PTRACE_CONT process 570, Alarm clock (resume event thread)
 infrun: prepare_to_wait
 linux_nat_wait: [process -1], [TARGET_WNOHANG]
 LLW: enter
 LNW: waitpid(-1, ...) returned 0, No child processes
 LLW: exit (ignore)
 infrun: target_wait (-1.0.0, status) =
 infrun:   -1.0.0 [process -1],
 infrun:   status->kind = ignore
 sigchld
 infrun: TARGET_WAITKIND_IGNORE
 infrun: prepare_to_wait
 linux_nat_wait: [process -1], [TARGET_WNOHANG]
 LLW: enter
 LNW: waitpid(-1, ...) returned 570, No child processes
 LLW: waitpid 570 received Trace/breakpoint trap (stopped)
 CSBB: process 570 stopped by software breakpoint
 LNW: waitpid(-1, ...) returned 0, No child processes
 LLW: trap ptid is process 570.
 LLW: exit
 infrun: target_wait (-1.0.0, status) =
 infrun:   570.570.0 [process 570],
 infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
 infrun: TARGET_WAITKIND_STOPPED
 infrun: stop_pc = 0x400717
 infrun: BPSTAT_WHAT_STOP_NOISY
 infrun: stop_waiting

 Breakpoint 3, handler (sig=14) at /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/sigstep.c:35
 35        done = 1;

Hardware single-step targets already behave this way, because the
Linux backends (both native and gdbserver) always report signals to
the core if the thread was single-stepping.

As mentioned in the new comment in do_target_resume, we can't fix this
by instead making the displaced_step_fixup phase skip fixing up the PC
if the single step stopped somewhere we didn't expect.  Here's what
the backtrace would look like if we did that:

 Breakpoint 3, handler (sig=14) at /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/sigstep.c:35
 35        done = 1;
 1: x/i $pc
 => 0x400717 <handler+7>:        movl   $0x1,0x200943(%rip)        # 0x601064 <done>
 (gdb) bt
 #0  handler (sig=14) at /home/pedro/gdb/mygit/src/gdb/testsuite/gdb.base/sigstep.c:35
 #1  <signal handler called>
 #2  0x0000000000400622 in _start ()
 (gdb) FAIL: gdb.base/sigstep.exp: displaced=on: step on breakpoint, to handler: backtrace

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

	* infrun.c (displaced_step_in_progress): New function.
	(do_target_resume): Advise target to report all signals if
	displaced stepping.

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

	* gdb.base/sigstep.exp (breakpoint_to_handler)
	(breakpoint_to_handler_entry): New parameter 'displaced'.  Use it.
	Test "backtrace" in handler.
	(breakpoint_over_handler): New parameter 'displaced'.  Use it.
	(top level): Add new "displaced" test axis to
	breakpoint_to_handler, breakpoint_to_handler_entry and
	breakpoint_over_handler.
2015-04-10 10:55:09 +01:00
Pedro Alves 8d707a12ef gdb/18216: displaced step+deliver signal, a thread needs step-over, crash
The problem is that with hardware step targets and displaced stepping,
"signal FOO" when stopped at a breakpoint steps the breakpoint
instruction at the same time it delivers a signal.  This results in
tp->stepped_breakpoint set, but no step-resume breakpoint set.  When
the next stop event arrives, GDB crashes.  Irrespective of whether we
should do something more/different to step past the breakpoint in this
scenario (e.g., PR 18225), it's just wrong to assume there'll be a
step-resume breakpoint set (and was not the original intention).

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

	PR gdb/18216
	* infrun.c (process_event_stop_test): Don't assume a step-resume
	is set if tp->stepped_breakpoint is true.

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

	PR gdb/18216
	* gdb.threads/multiple-step-overs.exp: Remove expected eof.
2015-04-10 10:36:23 +01:00
Yao Qi ef713951c5 [arm] Fix displaced stepping for thumb alu reg instruction
Recent patch series "V2 All-stop on top of non-stop" causes a SIGSEGV
in the test case,

> -PASS: gdb.base/info-shared.exp: continue to breakpoint: library function #4
> +FAIL: gdb.base/info-shared.exp: continue to breakpoint: library function #4
>
> continue^M
> Continuing.^M
> ^M
> Program received signal SIGSEGV, Segmentation fault.^M
> 0x40021564 in ?? () gdb/testsuite/gdb.base/info-shared-solib1.so^M
> (gdb) FAIL: gdb.base/info-shared.exp: continue to breakpoint: library function #4

and an ARM displaced stepping bug is exposed.  It can be reproduced by
the modified gdb.arch/arm-disp-step.exp as below,

continue^M
Continuing.^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
0xa713cfcc in ?? ()^M
(gdb) FAIL: gdb.arch/arm-disp-step.exp: continue to breakpoint: continue to test_add_rn_pc_end

This patch is to fix it.

gdb:

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

	* arm-tdep.c (install_alu_reg): Update comment.
	(thumb_copy_alu_reg): Remove local variable rn.  Update
	debugging message.  Use r2 instead of r1 in the modified
	instruction.

gdb/testsuite:

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

	* gdb.arch/arm-disp-step.S (main): Call test_add_rn_pc.
	(test_add_rn_pc): New function.
	* gdb.arch/arm-disp-step.exp (test_add_rn_pc): New proc.
	(top level): Invoke test_add_rn_pc.
2015-04-10 10:33:01 +01:00
Pedro Alves 906d60cf46 PR13858 - Can't do displaced stepping with no symbols
Running break-interp.exp with the target always in non-stop mode trips
on PR13858, as enabling non-stop also enables displaced stepping.

The problem is that when GDB doesn't know where the entry point is, it
doesn't know where to put the displaced stepping scratch pad.  The
test added by this commit exercises this.  Without the fix, we get:

 (gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=on: break *$pc
 set displaced-stepping on
 (gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=on: set displaced-stepping on
 stepi
 0x00000000004005be in ?? ()
 Entry point address is not known.
 (gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=on: stepi
 p /x $pc
 $2 = 0x4005be
 (gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=on: get after PC
 FAIL: gdb.base/step-over-no-symbols.exp: displaced=on: advanced

The fix switches all GNU/Linux ports to get the entry point from
AT_ENTRY in the target auxiliary vector instead of from symbols.  This
is currently only done by PPC when Cell debugging is enabled, but I
think all archs should be able to do the same.  Note that
ppc_linux_displaced_step_location cached the result, I'm guessing to
avoid constantly re-fetching the auxv out of remote targets, but
that's no longer necessary nowadays, as the auxv blob is itself cached
in the inferior object.  The ppc_linux_entry_point_addr global is
obviously bad for multi-process too nowadays.

Tested on x86-64 (-m64/-m32), PPC64 (-m64/-m32) and S/390 GNU/Linux.
Yao tested the new test on ARM as well.

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

	PR gdb/13858
	* amd64-linux-tdep.c (amd64_linux_init_abi_common): Install
	linux_displaced_step_location as gdbarch_displaced_step_location
	hook.
	* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
	* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
	* linux-tdep.c (linux_displaced_step_location): New function,
	based on ppc_linux_displaced_step_location.
	* linux-tdep.h (linux_displaced_step_location): New declaration.
	* ppc-linux-tdep.c (ppc_linux_entry_point_addr): Delete.
	(ppc_linux_inferior_created, ppc_linux_displaced_step_location):
	Delete.
	(ppc_linux_init_abi): Install linux_displaced_step_location as
	gdbarch_displaced_step_location hook, even without Cell/B.E..
	(_initialize_ppc_linux_tdep): Don't install
	ppc_linux_inferior_created as inferior_created observer.
	* s390-linux-tdep.c (s390_gdbarch_init): Install
	linux_displaced_step_location as gdbarch_displaced_step_location
	hook.

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

	PR gdb/13858
	* gdb.base/step-over-no-symbols.exp: New file.
2015-04-10 10:07:02 +01:00
Andy Wingo f2983cc34e Add Guile frame-read-register command
gdb/ChangeLog:

	* guile/scm-frame.c (gdbscm_frame_read_register): New function.
	(frame_functions): Bind gdbscm_frame_read_register to
	frame-read-register.
	* guile/lib/gdb.scm (frame-read-register): Export.

gdb/doc/ChangeLog:

	* guile.texi (Frames In Guile): Describe frame-read-register.

gdb/testsuite/ChangeLog:

	* gdb.guile/scm-frame.exp: Add frame-read-register tests, modelled
	after the Python tests.
2015-04-09 14:39:00 +02:00
Sergio Durigan Junior 6d62641c83 Fix Python completion when using the "complete" command
This patch is related to PR python/16699, and is an improvement over the
patch posted here:

  <https://sourceware.org/ml/gdb-patches/2014-03/msg00301.html>

Keith noticed that, when using the "complete" command on GDB to complete
a Python command, some strange things could happen.  In order to
understand what can go wrong, I need to explain how the Python
completion mechanism works.

When the user requests a completion of a Python command by using TAB,
GDB will first try to determine the right set of "brkchars" that will be
used when doing the completion.  This is done by actually calling the
"complete" method of the Python class.  Then, when we already know the
"brkchars" that will be used, we call the "complete" method again, for
the same values.

If you read the thread mentioned above, you will see that one of the
design decisions was to make the "cmdpy_completer_helper" (which is the
function the does the actual calling of the "complete" method) cache the
first result of the completion, since this result will be used in the
second call, to do the actual completion.

The problem is that the "complete" command does not process the
brkchars, and the current Python completion mechanism (improved by the
patch mentioned above) relies on GDB trying to determine the brkchars,
and then doing the completion itself.  Therefore, when we use the
"complete" command instead of doing a TAB-completion on GDB, there is a
scenario where we can use the invalid cache of a previous Python command
that was completed before.  For example:

  (gdb) A <TAB>
  (gdb) complete B
  B value1
  B value10
  B value2
  B value3
  B value4
  B value5
  B value6
  B value7
  B value8
  B value9
  (gdb) B <TAB>
  comp1   comp2   comp4   comp6   comp8
  comp10  comp3   comp5   comp7   comp9

Here, we see that "complete B " gave a different result than "B <TAB>".
The reason for that is because "A <TAB>" was called before, and its
completion results were "value*", so when GDB tried to "complete B " it
wrongly answered with the results for A.  The problem here is using a
wrong cache (A's cache) for completing B.

We tried to come up with a solution that would preserve the caching
mechanism, but it wasn't really possible.  So I decided to completely
remove the cache, and doing the method calling twice for every
completion.  This is not optimal, but I do not think it will impact
users noticeably.

It is worth mentioning another small issue that I found.  The code was
doing:

  wordobj = PyUnicode_Decode (word, sizeof (word), host_charset (), NULL);

which is totally wrong, because using "sizeof" here will lead to always
the same result.  So I changed this to use "strlen".  The testcase also
catches this problem.

Keith kindly expanded the existing testcase to cover the problem
described above, and everything is passing.

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

	PR python/16699
	* python/py-cmd.c (cmdpy_completer_helper): Adjust function to not
	use a caching mechanism.  Adjust comments and code to reflect
	that.  Replace 'sizeof' by 'strlen' when fetching 'wordobj'.
	(cmdpy_completer_handle_brkchars): Adjust call to
	cmdpy_completer_helper.  Call Py_XDECREF for 'resultobj'.
	(cmdpy_completer): Likewise.

gdb/testsuite/ChangeLog:
2015-04-08  Keith Seitz  <keiths@redhat.com>

	PR python/16699
	* gdb.python/py-completion.exp: New tests for completion.
	* gdb.python/py-completion.py (CompleteLimit1): New class.
	(CompleteLimit2): Likewise.
	(CompleteLimit3): Likewise.
	(CompleteLimit4): Likewise.
	(CompleteLimit5): Likewise.
	(CompleteLimit6): Likewise.
	(CompleteLimit7): Likewise.
2015-04-08 18:27:10 -04:00
Pedro Alves f3770638ca Add test for PR18214 and PR18216 - multiple step-overs with queued signals
Both PRs are triggered by the same use case.

PR18214 is about software single-step targets.  On those, the 'resume'
code that detects that we're stepping over a breakpoint and delivering
a signal at the same time:

  /* Currently, our software single-step implementation leads to different
     results than hardware single-stepping in one situation: when stepping
     into delivering a signal which has an associated signal handler,
     hardware single-step will stop at the first instruction of the handler,
     while software single-step will simply skip execution of the handler.
...
     Fortunately, we can at least fix this particular issue.  We detect
     here the case where we are about to deliver a signal while software
     single-stepping with breakpoints removed.  In this situation, we
     revert the decisions to remove all breakpoints and insert single-
     step breakpoints, and instead we install a step-resume breakpoint
     at the current address, deliver the signal without stepping, and
     once we arrive back at the step-resume breakpoint, actually step
     over the breakpoint we originally wanted to step over.  */

doesn't handle the case of _another_ thread also needing to step over
a breakpoint.  Because the other thread is just resumed at the PC
where it had stopped and a breakpoint is still inserted there, the
thread immediately re-traps the same breakpoint.  This test exercises
that.  On software single-step targets, it fails like this:

 KFAIL: gdb.threads/multiple-step-overs.exp: displaced=off: signal thr3: continue to sigusr1_handler
 KFAIL: gdb.threads/multiple-step-overs.exp: displaced=off: signal thr2: continue to sigusr1_handler

gdb.log (simplified):

 (gdb) continue
 Continuing.

 Breakpoint 4, child_function_2 (arg=0x0) at src/gdb/testsuite/gdb.threads/multiple-step-overs.c:66
 66            callme (); /* set breakpoint thread 2 here */
 (gdb) thread 3
 (gdb) queue-signal SIGUSR1
 (gdb) thread 1
 [Switching to thread 1 (Thread 0x7ffff7fc1740 (LWP 24824))]
 #0  main () at src/gdb/testsuite/gdb.threads/multiple-step-overs.c:106
 106       wait_threads (); /* set wait-threads breakpoint here */
 (gdb) break sigusr1_handler
 Breakpoint 5 at 0x400837: file src/gdb/testsuite/gdb.threads/multiple-step-overs.c, line 31.
 (gdb) continue
 Continuing.
 [Switching to Thread 0x7ffff7fc0700 (LWP 24828)]

 Breakpoint 4, child_function_2 (arg=0x0) at src/gdb/testsuite/gdb.threads/multiple-step-overs.c:66
 66            callme (); /* set breakpoint thread 2 here */
 (gdb) KFAIL: gdb.threads/multiple-step-overs.exp: displaced=off: signal thr3: continue to sigusr1_handler


For good measure, I made the test try displaced stepping too.  And
then I found it crashes GDB on x86-64 (a hardware step target), but
only when displaced stepping... :

 KFAIL: gdb.threads/multiple-step-overs.exp: displaced=on: signal thr1: continue to sigusr1_handler (PRMS: gdb/18216)
 KFAIL: gdb.threads/multiple-step-overs.exp: displaced=on: signal thr2: continue to sigusr1_handler (PRMS: gdb/18216)
 KFAIL: gdb.threads/multiple-step-overs.exp: displaced=on: signal thr3: continue to sigusr1_handler (PRMS: gdb/18216)

 Program terminated with signal SIGSEGV, Segmentation fault.
 #0  0x000000000062a83a in process_event_stop_test (ecs=0x7fff847eeee0) at src/gdb/infrun.c:4964
 4964          if (sr_bp->loc->permanent
 Setting up the environment for debugging gdb.
 Breakpoint 1 at 0x79fcfc: file src/gdb/common/errors.c, line 54.
 Breakpoint 2 at 0x50a26c: file src/gdb/cli/cli-cmds.c, line 217.
 (top-gdb) p sr_bp
 $1 = (struct breakpoint *) 0x0
 (top-gdb) bt
 #0  0x000000000062a83a in process_event_stop_test (ecs=0x7fff847eeee0) at src/gdb/infrun.c:4964
 #1  0x000000000062a1af in handle_signal_stop (ecs=0x7fff847eeee0) at src/gdb/infrun.c:4715
 #2  0x0000000000629097 in handle_inferior_event (ecs=0x7fff847eeee0) at src/gdb/infrun.c:4165
 #3  0x0000000000627482 in fetch_inferior_event (client_data=0x0) at src/gdb/infrun.c:3298
 #4  0x000000000064ad7b in inferior_event_handler (event_type=INF_REG_EVENT, client_data=0x0) at src/gdb/inf-loop.c:56
 #5  0x00000000004c375f in handle_target_event (error=0, client_data=0x0) at src/gdb/linux-nat.c:4658
 #6  0x0000000000648c47 in handle_file_event (file_ptr=0x2e0eaa0, ready_mask=1) at src/gdb/event-loop.c:658

The all-stop-non-stop series fixes this, but meanwhile, this augments
the multiple-step-overs.exp test to cover this, KFAILed.

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

	PR gdb/18214
	PR gdb/18216
	* gdb.threads/multiple-step-overs.c (sigusr1_handler): New
	function.
	(main): Install it as SIGUSR1 handler.
	* gdb.threads/multiple-step-overs.exp (setup): Remove 'prefix'
	parameter.  Always use "setup" as prefix.  Toggle "set
	displaced-stepping" off/on depending on global.  Don't switch to
	thread 1 here.
	(top level): Add displaced stepping "off/on" test axis.  Update
	"setup" calls.  Wrap each subtest with with_test_prefix.  Test
	continuing with a queued signal in each thread.
2015-04-08 19:59:03 +01:00
Pedro Alves 4496bed7f3 Fix gdb.trace/{actions,infotrace,while-stepping}.exp with extended-remote
The recent actions.exp change to check gdb_run_cmd succeeded caught
further problems.  The test now fails like this
with --target_board=native-extended-gdbserver:

 FAIL: gdb.trace/actions.exp: Can't run to main

gdb.log shows:

 (gdb) run
 Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.trace/actions
 Running the default executable on the remote target failed; try "set remote exec-file"?
 (gdb) FAIL: gdb.trace/actions.exp: Can't run to main

The problem is that a gdb_load call is missing.

Grepping around for similar problems in other tests, I found that
infotrace.exp and while-stepping.exp should be likewise affected.  And
indeed this is what we get today:

 FAIL: gdb.trace/infotrace.exp: tstart
 FAIL: gdb.trace/infotrace.exp: continue to end (the program is no longer running)
 FAIL: gdb.trace/infotrace.exp: tstop
 FAIL: gdb.trace/infotrace.exp: 2.6: info tracepoints (trace buffer usage)
 FAIL: gdb.trace/while-stepping.exp: tstart
 FAIL: gdb.trace/while-stepping.exp: tstop
 FAIL: gdb.trace/while-stepping.exp: tfile: info tracepoints
 FAIL: gdb.trace/while-stepping.exp: ctf: info tracepoints

while-stepping.exp even has the same race bug actions.exp had.

After this, {actions,infotrace,while-stepping}.exp all pass cleanly
with the native-extended-gdbserver board.

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

	* gdb.trace/actions.exp: Use gdb_load before gdb_run_cmd.
	* gdb.trace/infotrace.exp: Use gdb_load before gdb_run_cmd.  Use
	gdb_breakpoint instead of gdb_test that doesn't expect anything.
	Return early if running to main fails.
	* gdb.trace/while-stepping.exp: Likewise.
2015-04-08 10:39:43 +01:00
Pedro Alves b97fde9213 gdb.base/interrupt.exp: Use send_inferior/$inferior_spawn_id
The gdb.base/interrupt.exp test is important for testing system call
restarting, but because it depends on inferior I/O, it ends up skipped
against gdbserver.  This patch adjusts the test to use send_inferior
and $inferior_spawn_id so it works against GDBserver.

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

	* gdb.base/interrupt.exp: Don't skip if $inferior_spawn_id !=
	$gdb_spawn_id.  Use send_inferior and $inferior_spawn_id to
	interact with inferior program.
2015-04-07 18:29:12 +01:00
Pedro Alves f71c18e755 testsuite: Introduce $inferior_spawn_id
Some important tests, like gdb.base/interrupt.exp end up skipped
against gdbserver, because they depend on inferior I/O, which
gdbserver doesn't do.

This patch adds a mechanism that makes it possible to make them work.
It adds a new "inferior_spawn_id" global that is the spawn ID used for
I/O interaction with the inferior.  By default, for native targets, or
remote targets that can do I/O through GDB (semi-hosting) this will be
the same as the gdb/host spawn ID.  Otherwise, the board may set this
to some other spawn ID.  When debugging with GDBserver, this will be
set to GDBserver's spawn ID.

Then tests can use send_inferior instead of send_gdb to send input to
the inferior, and use expect's "-i" switch to select which spawn ID to
use for matching input/output.  That is, something like this will now
work:

  send_inferior "echo me\n"
  gdb_test_multiple "continue" "test msg" {
    -i "$inferior_spawn_id" -re "echo me\r\necho\r\n" {
      ...
    }
  }

Or even:

  gdb_test_multiple "continue" "test msg" {
    -i "$inferior_spawn_id" -re "hello world" {
      ...
    }
    -i "$gdb_spawn_id" -re "error.*$gdb_prompt $" {
      ...
    }
  }

Of course, by default, gdb_test_multiple still matches with
$gdb_spawn_id.

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

	* lib/gdb.exp (inferior_spawn_id): New global.
	(gdb_test_multiple): Handle "-i".  Reset the spawn id to GDB's
	spawn id after processing the user code.
	(default_gdb_start): Set inferior_spawn_id.
	(send_inferior): New procedure.
	* lib/gdbserver-support.exp (gdbserver_start): Set
	inferior_spawn_id.
	(close_gdbserver, gdb_exit): Unset inferior_spawn_id.
2015-04-07 18:28:38 +01:00
Pedro Alves 6423214fcb testsuite: Don't use expect_background to reap gdbserver
I adjusted a test to do 'expect -i $server_spawn_id -re ...', and saw
really strange behavior.  Whether that expect would work, depended on
whether GDB would also send output and the same expect matched it too
(on $gdb_spawn_id).  I was perplexed until I noticed that
gdbserver_spawn spawns gdbserver and then uses expect_background to
reap gdbserver.  That expect_background conflicts/races with any
"expect -i $server_spawn_id" done anywhere else in parallel...

In order to make it possible for tests to read inferior I/O out of
$server_spawn_id, we to get rid of that expect_background.  This patch
makes us instead reap gdbserver's spawn id when GDB exits.  If GDB is
still around, this gives a chance for gdbserver to exit cleanly.  The
current code in gdb_finish uses "kill", but that doesn't work with
extended-remote (gdbserver doesn't exit).  We now use "monitor exit"
instead which works in both remote and extended-remote modes.

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

	* lib/gdb.exp (gdb_finish): Delete persistent gdbserver handling.
	* lib/gdbserver-support.exp (gdbserver_start): Make
	$server_spawn_id global.
	(gdbserver_start): Don't wait for gdbserver's spawn id with
	expect_background.
	(close_gdbserver): New procedure.
	(gdb_exit): Rename the default version and reimplement.
2015-04-07 18:27:55 +01:00
Pedro Alves 71c0ee8cb9 gdb_test_multiple: Fix user code argument processing
While teaching gdb_test_multiple to forward "-i" to gdb_expect, I
found that with:

      gdb_test_multiple (...) {
        -i $some_variable -re "..." {}
      }

$some_variable was not getting expanded in the gdb_test_multiple
caller's scope.  This is a bug inside gdb_test_multiple.  When
processing an argument in passed in user code, it was appending the
original argument literally, instead of appending the uplist'ed
argument.

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

        * lib/gdb.exp (gdb_test_multiple): When processing an argument,
	append the substituted item, not the original item.
2015-04-07 18:27:24 +01:00
Pedro Alves 203bc29be2 gdb.base/interrupt.exp: Use gdb_test_multiple instead of gdb_expect
gdb/testsuite/ChangeLog:
2015-04-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/interrupt.exp: Use gdb_test_multiple instead of
	gdb_expect.
2015-04-07 18:27:22 +01:00
Pedro Alves 508a3ddf63 gdb.base/interrupt.exp: Fix race
Working on splitting gdb and inferior output handling in this test, I
noticed a race that happens to be masked out today.

The test sends "a\n" to the inferior, and then inferior echoes back
"a\n".

If expect manages to read only the first "a\r\n" into its buffer, then
this matches:

    -re "^a\r\n(|a\r\n)$" {

and leaves the second "a\r\n" in output.

Then the next test that processes inferior I/O sends "data\n", and expects:

    -re "^(\r\n|)data\r\n(|data\r\n)$"

which fails given the anchor and given "a\r\n" is still in the buffer.

This is masked today because the test relies on inferior I/O being
done on GDB's terminal, and there are tested GDB commands in between,
which consume the "a\r\n" that was left in the output.

We don't support SunOS4 anymore, so just remove the workaround.

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

	* gdb.base/interrupt.exp: Don't handle the case of the inferior
	output appearing once only.
2015-04-07 18:19:29 +01:00
Pedro Alves 9f6dbe2bbb Fix gdb.trace/actions.exp race
I saw this on PPC64 once:

  not installed on target
  (gdb) PASS: gdb.trace/actions.exp: 5.10a: verify teval actions set for two tracepoints
  break main
  Breakpoint 4 at 0x10000c6c: file ../../../src/gdb/testsuite/gdb.trace/actions.c, line 139.
  (gdb) PASS: gdb.trace/actions.exp: break main
  run
  Starting program: /home/palves/gdb/build/gdb/testsuite/outputs/gdb.trace/actions/actions
  tstatus

  Breakpoint 4, main (argc=1, argv=0x3fffffffebb8, envp=0x3fffffffebc8) at ../../../src/gdb/testsuite/gdb.trace/actions.c:139
  139       begin ();
  (gdb) tstatus
  Trace can not be run on this target.
  (gdb) actions 1
  Enter actions for tracepoint 1, one per line.
  End with a line saying just "end".
  >collect $regs
  >end
  (gdb) PASS: gdb.trace/actions.exp: set actions for first tracepoint
  tstart
  You can't do that when your target is `native'
  (gdb) FAIL: gdb.trace/actions.exp: tstart
  info tracepoints 1
  Num     Type           Disp Enb Address            What
  1       tracepoint     keep y   0x00000000100007c8 in gdb_c_test at ../../../src/gdb/testsuite/gdb.trace/actions.c:74
	  collect $regs
	  not installed on target
  ...

followed by a cascade of FAILs.  The "tstatus" was supposed to detect
that this target (native) can't do tracepoints, but, alas, it didn't.

That detection failed because 'gdb_test "break main"' doesn't expect
anything, and then the output was slow enough that 'gdb_test ""
"Breakpoint .*"' matched the output of "break main"...

The fix is to use gdb_breakpoint instead.  Also check the result of
gdb_test while at it.

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

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

	* gdb.trace/actions.exp: Use gdb_breakpoint instead of gdb_test
	that doesn't expect anything.  Return early if running to main
	fails.
2015-04-07 17:04:18 +01:00
Yao Qi 337532fab1 Properly set alarm value in gdb.threads/non-stop-fair-events.exp
Nowadays, the alarm value is 60, and alarm is generated on some slow
boards.  This patch is to pass DejaGNU timeout value to the program,
and move the alarm call before going to infinite loop.  If any thread
has activities, the alarm is reset.

gdb/testsuite:

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

	* gdb.threads/non-stop-fair-events.c (SECONDS): New macro.
	(child_function): Call alarm.
	(main): Move call to alarm into the loop.
	* gdb.threads/non-stop-fair-events.exp: Build program with
	-DTIMEOUT=$timeout.
2015-04-07 11:30:07 +01:00
Doug Evans 01b622d4c7 * lib/pascal.exp (gpc_compile): Rename dest arg to destfile.
The "dest" parameter to fpc_compile/gpc_compile is the name of
compilation destination file, not a board name.

This patch fixes this by using names consistent with
lib/future.exp:gdb_default_target_compile.

gdb/testsuite/ChangeLog:

	* lib/pascal.exp (gpc_compile): Rename dest arg to destfile.
	Fix dest parameter to board_info.
	(fpc_compile): Ditto.
	(gdb_compile_pascal): Rename dest arg to destfile.
2015-04-06 08:45:06 -07:00
Pierre-Marie de Rodat 961f416025 Do not consider reference types as dynamic
Even when referenced types are dynamic, the corresponding referencing
type should not be considered as dynamic: it's only a pointer.  This
prevents reference type for values not in memory to be resolved.

gdb/ChangeLog:

	* gdbtypes.c (is_dynamic_type_internal): Remove special handling
	of TYPE_CODE_REF types so that they are not considered as
	dynamic depending on the referenced type.
	(resolve_dynamic_type_internal): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.ada/funcall_ref.exp: New file.
	* gdb.ada/funcall_ref/foo.adb: New file.
2015-04-03 15:23:49 +02:00
Yao Qi cafda5977a kfail two tests in no-unwaited-for-left.exp for remote target
I see these two fails in no-unwaited-for-left.exp in remote testing
for aarch64-linux target.

...
continue
Continuing.
warning: Remote failure reply: E.No unwaited-for children left.

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

....
continue
Continuing.
warning: Remote failure reply: E.No unwaited-for children left.

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

I checked the gdb.log on buildbot, and find that these two fails also
appear on Debian-i686-native-extended-gdbserver and Fedora-ppc64be-native-gdbserver-m64.
I recall that they are about local/remote parity, and related RSP is missing.
There has been already a PR 14618 about it.  This patch is to kfail them
on remote target.

gdb/testsuite:

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

	* gdb.threads/no-unwaited-for-left.exp: Set up kfail if target
	is remote.
2015-04-02 13:51:31 +01:00
Gary Benson fed040c6a5 Make the default sysroot be "target:"
This commit makes GDB default to a sysroot of "target:".
One testcase needed updating as a result of this change.

gdb/ChangeLog:

	* main.c (captured_main): Set gdb_sysroot to "target:"
	if not otherwise set.

gdb/testsuite/ChangeLog:

	* gdb.base/break-probes.exp: Cope with "target:" sysroot.
2015-04-02 13:38:29 +01:00
Sasha Smundak d11916aa89 Add support for writing unwinders in Python.
gdb/ChangeLog:

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

gdb/doc/ChangeLog:

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

gdb/testsuite/ChangeLog:

	* gdb.python/py-unwind-maint.c: New file.
	* gdb.python/py-unwind-maint.exp: New test.
	* gdb.python/py-unwind-maint.py: New file.
	* gdb.python/py-unwind.c: New file.
	* gdb.python/py-unwind.exp: New test.
	* gdb.python/py-unwind.py: New test.
2015-04-01 11:49:12 -07:00
Pedro Alves a14711808e gdb.threads/manythreads.exp: can't read "test": no such variable
If interrupt_and_wait manages to trigger the FAIL path, we get:

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

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

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

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

fails with (line breaks added for clarity):

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

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

	* lib/gdb.exp (gdb_spawn_with_cmdline_opts): Append space to
	GDBFLAGS if not empty.
2015-04-01 15:25:21 +01:00
Pierre-Marie de Rodat 3c724c8ca9 Share the "multi_line" helper among all testcases
gdb/testsuite/ChangeLog:

	* gdb.ada/complete.exp: Remove "multi_line".
	* gdb.ada/info_exc.exp: Remove "multi_line".
	* gdb.ada/packed_tagged.exp: Remove "multi_line".
	* gdb.ada/ptype_field.exp: Remove "multi_line".
	* gdb.ada/sym_print_name.exp: Remove "multi_line".
	* gdb.ada/tagged.exp: Remove "multi_line".
	* gdb.btrace/buffer-size.exp: Replace [join [list ...]] with
	[multi_line ...]
	* gdb.btrace/delta.exp: Likewise.
	* gdb.btrace/exception.exp: Likewise.
	* gdb.btrace/function_call_history.exp: Likewise.
	* gdb.btrace/instruction_history.exp: Likewise.
	* gdb.btrace/nohist.exp: Likewise.
	* gdb.btrace/record_goto.exp: Likewise.
	* gdb.btrace/segv.exp: Likewise.
	* gdb.btrace/stepi.exp: Likewise.
	* gdb.btrace/tailcall.exp: Likewise.
	* gdb.btrace/unknown_functions.exp: Likewise.
	* gdb.dwarf2/dw2-undefined-ret-addr.exp: Likewise.
	* lib/gdb.exp: Add the "multi_line" helper.
2015-04-01 15:06:39 +02:00
Pedro Alves 4eec2deb06 Crash on thread id wrap around
On GNU/Linux, if the target reuses the TID of a thread that GDB still
has in its list marked as THREAD_EXITED, GDB crashes, like:

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

Here:

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

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

Tested on x86_64 Fedora 20.

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

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

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

	* gdb.threads/tid-reuse.c: New file.
	* gdb.threads/tid-reuse.exp: New file.
2015-04-01 13:38:06 +01:00
Sergio Durigan Junior df8411da08 Implement support for checking /proc/PID/coredump_filter
This patch, as the subject says, extends GDB so that it is able to use
the contents of the file /proc/PID/coredump_filter when generating a
corefile.  This file contains a bit mask that is a representation of
the different types of memory mappings in the Linux kernel; the user
can choose to dump or not dump a certain type of memory mapping by
enabling/disabling the respective bit in the bit mask.  Currently,
here is what is supported:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	PR corefiles/16092
	* gdb.base/coredump-filter.c: New file.
	* gdb.base/coredump-filter.exp: Likewise.
2015-03-31 19:32:34 -04:00
Petr Machata 6ef37366be dwarf.exp: Allow generating a stub .debug_line section
Example of use:

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

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

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

Signed-off-by: Petr Machata <pmachata@redhat.com>
2015-03-31 16:25:07 +02:00
Jon Turney 7ec911b0fb testsuite: Don't set SYMBOL_PREFIX for x86_64_*_cygwin
Exactly like x86_64-*-mingw, SYMBOL_PREFIX should not be set to "_" for
x86_64_*_cygwin

gdb/testuite/ChangeLog:

	* lib/gdb.exp (gdb_target_symbol_prefix_flags): Don't set
	SYMBOL_PREFIX for x86_64-*-cygwin.
2015-03-26 22:37:24 +00:00
Andy Wingo ff908ebf86 Properly intern constants into psymtab
Variables with a DW_AT_const_value but without a DW_AT_location were not
getting added to the partial symbol table.  They are added to the full
symbol table, however, when the compilation unit's psymtabs are
expanded.

Before:

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

After:

   (gdb) p one
   $1 = 1

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

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

gdb/testsuite/ChangeLog:

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

gdb/ChangeLog:

	PR symtab/18148
	* dwarf2read.c (struct partial_die_info): Add has_const_value
	member.
	(add_partial_symbol): Don't punt on symbols that have const_value
	attributes.
	(read_partial_die): Detect DW_AT_const_value.
2015-03-26 19:41:54 +01:00
Yao Qi 6d5f0679fe Handle the effect of skipping prologue
break-asm-file.exp has some manually written dwarf to create some line
number entries like this,

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

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

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

in the following test,

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

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

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

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

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

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

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

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

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

then the line table becomes:

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

gdb/testsuite:

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

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

gdb/testsuite:

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

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

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

I get the following error:

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

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

gdb/testsuite:

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

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

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

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

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

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

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

gdb/testsuite:

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

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

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

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

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

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

testsuite/
	* gdb.btrace/exception.exp: Increase BTS buffer size.
2015-03-25 14:15:07 +01:00
Pedro Alves a25d8bf9c5 Fix "thread apply all" with exited threads
I noticed that "thread apply all" sometimes crashes.

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

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

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

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

Tested on x86_64 Fedora 20.

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

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

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

	* gdb.threads/no-unwaited-for-left.exp: Test "thread apply all".
2015-03-24 21:01:29 +00:00
Pedro Alves 856e7dd698 Make "set scheduler-locking step" depend on user intention, only
Currently, "set scheduler-locking step" is a bit odd.  The manual
documents it as being optimized for stepping, so that focus of
debugging does not change unexpectedly, but then it says that
sometimes other threads may run, and thus focus may indeed change
unexpectedly...  A user can then be excused to get confused and wonder
why does GDB behave like this.

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

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

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

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

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

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

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

Tested on x86_64 Fedora 20, native and gdbserver.

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

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

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

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

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

	* gdb.texinfo (test_step) <set scheduler-locking step>: No longer
	mention that threads may sometimes run unlocked.
2015-03-24 17:50:31 +00:00
Antoine Tremblay ad235a410a Fix mi-pending.exp test output to allow stable test diffing
gdb/testsuite/ChangeLog:

	* gdb.mi/mi-pending.exp: Fix output of breakpoint test.
2015-03-24 13:38:19 -04:00