Commit Graph

7921 Commits

Author SHA1 Message Date
Tom de Vries d7445728b1 [gdb/testsuite] Handle missing gccgo
Without gccgo installed I see in stdout/stderr:
...
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/print.exp ...
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/handcall.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/max-depth.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/integers.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/unsafe.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/package.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/types.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/chan.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/strings.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/basic-types.exp ...
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/hello.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
Running /data/gdb_versions/devel/src/gdb/testsuite/gdb.go/methods.exp ...
gdb compile failed, default_target_compile: Can't find gccgo.
...

Fix this by introducing a gdb_caching_proc support_go_compile, and using it in
the complaining test-cases.

Tested on x86_64-linux, with and without gccgo installed.

gdb/testsuite/ChangeLog:

2020-02-20  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (support_go_compile): New gdb_caching_proc.
	(gdb_simple_compile): Handle compile_flags go by using .go extension
	for source file.
	* gdb.go/chan.exp: Use support_go_compile.
	* gdb.go/handcall.exp: Same.
	* gdb.go/hello.exp: Same.
	* gdb.go/integers.exp: Same.
	* gdb.go/max-depth.exp: Same.
	* gdb.go/methods.exp: Same.
	* gdb.go/package.exp: Same.
	* gdb.go/strings.exp: Same.
	* gdb.go/types.exp: Same.
	* gdb.go/unsafe.exp: Same.
2020-02-20 06:31:24 +01:00
Tom de Vries c9c41e6d73 [gdb/testsuite] Fix xpass in gdb.python/lib-types.exp
When running gdb.python/lib-types.exp, we have an xpass:
...
(gdb) python print (str (typedef_const_typedef_class1_ref_obj.type))^M
typedef_const_typedef_class1_ref^M
(gdb) XPASS: gdb.python/lib-types.exp: \
  python print (str (typedef_const_typedef_class1_ref_obj.type)) \
  (PRMS gcc/55641)
...

When running the same with gcc 4.8, we have an xfail instead:
...
(gdb) python print (str (typedef_const_typedef_class1_ref_obj.type))^M
const typedef_const_typedef_class1_ref^M
(gdb) XFAIL: gdb.python/lib-types.exp: \
  python print (str (typedef_const_typedef_class1_ref_obj.type)) \
  (PRMS gcc/55641)
...

Fix the xpass by xfailing only for the gcc 4.8 pattern.

Tested on x86_64-linux, with:
- gcc 7.5.0
- gcc 4.8.5
- clang 5.0.2

gdb/testsuite/ChangeLog:

2020-02-19  Tom de Vries  <tdevries@suse.de>

	* gdb.python/lib-types.exp: Make xfail more strict.
2020-02-19 22:57:19 +01:00
Tom de Vries f20ff83737 [gdb/testsuite] Fix funcall_ref.exp xpass
When running gdb.ada/funcall_ref.exp I run into two XPASSes:
...
(gdb) p get ("Hello world!")^M
$1 = (n => 12, s => "Hello world!")^M
(gdb) XPASS: gdb.ada/funcall_ref.exp: p get ("Hello world!")
ptype get ("Hello world!")^M
type = <ref> record^M
    n: natural;^M
    s: access array (1 .. n) of character;^M
end record^M
(gdb) XPASS: gdb.ada/funcall_ref.exp: ptype get ("Hello world!")
...

The xfails are documented in funcall_ref.exp:
...
 # Currently, GCC describes such functions as returning pointers (instead of
 # references).
 setup_xfail *-*-*
...

Using gnatmake 4.8, we can reproduce the XFAILs:
...
(gdb) p get ("Hello world!")^M
$1 = (access foo.bar) 0x6147b0 <system.secondary_stack.chunk+48>^M
(gdb) XFAIL: gdb.ada/funcall_ref.exp: p get ("Hello world!")
ptype get ("Hello world!")^M
type = access record^M
    n: natural;^M
    s: access array (1 .. n) of character;^M
end record^M
(gdb) XFAIL: gdb.ada/funcall_ref.exp: ptype get ("Hello world!")
...

Fix the XPASSes by:
- removing the xfail setup
- switching the order of the two tests
- detecting the "access record" type and declaring the first test unsupported,
  and skipping the second test

Tested on x86_64-linux, both with gnatmake 4.8.5 and gnatmake 7.5.0.

gdb/testsuite/ChangeLog:

2020-02-19  Tom de Vries  <tdevries@suse.de>

	* gdb.ada/funcall_ref.exp: Replace xfail setup by unsupported check.
2020-02-19 22:33:42 +01:00
Doug Evans 084104828c rust/25535 Apply embedded offset to enum variant calculation
Hopefully straightforward (and I didn't miss anything ...).

gdb/ChangeLog
2020-02-19  Doug Evans  <dje@google.com>

	PR rust/25535
	* rust-lang.c (rust_print_enum): Apply embedded_offset to
	rust_enum_variant calculation.

gdb/testsuite/ChangeLog
2020-02-19  Doug Evans  <dje@google.com>

	PR rust/25535
	* gdb.rust/simple.exp: Add test.
	* gdb.rust/simple.rs: Add test.
2020-02-19 13:59:31 -07:00
Tom de Vries 623563f79d [gdb/testsuite] Fix corefile-buildid.exp with check-read1
When running gdb.base/corefile-buildid.exp using check-read1, I run into:
...
FAIL: gdb.base/corefile-buildid.exp: shared: info files (timeout)
FAIL: gdb.base/corefile-buildid.exp: symlink shared: info files (timeout)
FAIL: gdb.base/corefile-buildid.exp: shared sepdebug: info files (timeout)
FAIL: gdb.base/corefile-buildid.exp: symlink shared sepdebug: info files \
  (timeout)
...

This is caused by attempting to match the output of an "info files" command
using a single gdb_test in check_exec_file.

Fix this by doing line-by-line matching in check_exec_file.

Tested on x86_64-linux, using make targets check and check-read1.

gdb/testsuite/ChangeLog:

2020-02-19  Tom de Vries  <tdevries@suse.de>

	* gdb.base/corefile-buildid.exp (check_exec_file): Match info files
	output line-by-line.
2020-02-19 21:33:39 +01:00
Tom de Vries d3308cfdec [gdb/testsuite] Fix c++/14186 kpass in cpexprs.exp
With gdb.cp/cpexprs.exp, we see:
...
KPASS: gdb.cp/cpexprs.exp: p CV::m(int) const (PRMS c++/14186)
KPASS: gdb.cp/cpexprs.exp: p CV::m(int) volatile (PRMS c++/14186)
KPASS: gdb.cp/cpexprs.exp: p CV::m(int) const volatile (PRMS c++/14186)
...

The tests have been KPASSing since Sept 4 2017, due to commit 3693fdb3c8
'Make "p S::method() const::static_var" work too'.

Fix this by removing the corresponding kfail.

gdb/testsuite/ChangeLog:

2020-02-19  Tom de Vries  <tdevries@suse.de>

	* gdb.cp/cpexprs.exp: Remove c++/14186 kfail.
2020-02-19 13:41:10 +01:00
Tom de Vries 86cbc5dc16 [gdb/testsuite] Be quiet about missing prelink in solib-overlap.exp
When running gdb.base/solib-overlap.exp, I get:
...
Running src/gdb/testsuite/gdb.base/solib-overlap.exp ...
sh: prelink: command not found

                === gdb Summary ===

nr of untested testcases         1
...

The verbose output on stdout/stderr is due to using system to execute
prelink, which also means that the output is not captured in gdb.log and
gdb.sum.

Fix this by using exec instead of system.

Tested on x86_64-linux, with:
- no prelink installed, and
- a fake prelink installed, using "cp /usr/bin/echo ~/bin/prelink".

gdb/testsuite/ChangeLog:

2020-02-19  Tom de Vries  <tdevries@suse.de>

	* gdb.base/solib-overlap.exp: Use exec instead of system to execute
	prelink.
2020-02-19 08:24:44 +01:00
Tom de Vries 9db2b96b07 [gdb/testsuite] Ignore pass in gdb_caching_proc
Before commit d4295de4f3 "[gdb/testsuite] Handle missing gnatmake in
gnat_runtime_has_debug_info", calling the gdb_caching_proc
gnat_runtime_has_debug_info could generate a pass because of using
gdb_compile_ada.

This has been fixed in that commit by using a factored out variant
gdb_compile_ada_1, which does not call pass.

Additionally, fix cases like this in more generic way: by ignoring pass calls
during execution of a gdb_caching_proc.

Build and reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-19  Tom de Vries  <tdevries@suse.de>

	* lib/cache.exp (ignore_pass, gdb_do_cache_wrap): New proc.
	(gdb_do_cache): Use gdb_do_cache_wrap.
	* gdb.base/gdb-caching-proc.exp (test_proc): Use gdb_do_cache_wrap.
2020-02-19 07:05:13 +01:00
Tom de Vries 89e2fdc56a [gdb/testsuite] Be quiet about untested dtrace-prob.exp
When running gdb.base/dtrace-probe.exp, I get this on stdout/stderr:
...
Running src/gdb/testsuite/gdb.base/dtrace-probe.exp ...
gdb compile failed, ld: error in \
  build/gdb/testsuite/outputs/gdb.base/dtrace-probe/dtrace-probe.o\
  (.eh_frame); no .eh_frame_hdr table will be created
ld: crt1.o: in function `_start':
start.S:110: undefined reference to `main'
ld: build/gdb/testsuite/outputs/gdb.base/dtrace-probe/dtrace-probe-p.o:\
  (.SUNW_dof+0x88): undefined reference to `main'
ld: build/gdb/testsuite/outputs/gdb.base/dtrace-probe/dtrace-probe-p.o:\
  (.SUNW_dof+0xb8): undefined reference to `main'
collect2: error: ld returned 1 exit status

                === gdb Summary ===

nr of untested testcases         1
...

There is no reason to be this verbose about the failure to compile.

Fix this by using quiet as additional option to gdb_compile in
dtrace_build_usdt_test_program.  Note that the error message still occurs in
gdb.log.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-19  Tom de Vries  <tdevries@suse.de>

	* lib/dtrace.exp (dtrace_build_usdt_test_program): Use quiet as
	gdb_compile option.
2020-02-19 00:05:40 +01:00
Simon Marchi 373d7ac0f1 gdb: change print format of flag enums with value 0
If a flag enum has value 0 and the enumeration type does not have an
enumerator with value 0, we currently print:

  $1 = (unknown: 0x0)

I don't like the display of "unknown" here, since for flags, 0 is a
an expected value.  It just means that no flags are set.  This patch
makes it so that we print it as a simple 0 in this situation:

  $1 = 0

If there is an enumerator with value 0, it is still printed using that
enumerator, for example (from the test):

  $1 = FE_NONE

gdb/ChangeLog:

	* valprint.c (generic_val_print_enum_1): When printing a flag
	enum with value 0 and there is no enumerator with value 0, print
	just "0" instead of "(unknown: 0x0)".

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.exp (test_print_enums): Update expected
	output.
2020-02-18 17:33:04 -05:00
Simon Marchi b29a2df000 gdb: print unknown part of flag enum in hex
When we print the "unknown" part of a flag enum, it is printed in
decimal.  I think it would be more useful if it was printed in hex, as
it helps to determine which bits are set more than a decimal value.

gdb/ChangeLog:

	* valprint.c (generic_val_print_enum_1): Print unknown part of
	flag enum in hex.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.exp (test_print_enums): Expect hex values
	for "unknown".
2020-02-18 17:33:04 -05:00
Simon Marchi 6740f0cc3b gdb: allow duplicate enumerators in flag enums
I have come across some uses cases where it would be desirable to treat
an enum that has duplicate values as a "flag enum".  For example, this
one here [1]:

    enum membarrier_cmd {
            MEMBARRIER_CMD_QUERY                                = 0,
            MEMBARRIER_CMD_GLOBAL                               = (1 << 0),
            MEMBARRIER_CMD_GLOBAL_EXPEDITED                     = (1 << 1),
            MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED            = (1 << 2),
            MEMBARRIER_CMD_PRIVATE_EXPEDITED                    = (1 << 3),
            MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED           = (1 << 4),
            MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE          = (1 << 5),
            MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 6),

            /* Alias for header backward compatibility. */
            MEMBARRIER_CMD_SHARED = MEMBARRIER_CMD_GLOBAL,
    };

The last enumerator is kept for backwards compatibility.  Without this
patch, this enumeration wouldn't be considered a flag enum, because two
enumerators collide.   With this patch, it would be considered a flag
enum, and the value 3 would be printed as:

  MEMBARRIER_CMD_GLOBAL | MEMBARRIER_CMD_GLOBAL_EXPEDITED

Although if people prefer, we could display both MEMBARRIER_CMD_GLOBAL
and MEMBARRIER_CMD_SHARED in the result.  It wouldn't be wrong, and
could perhaps be useful in case a bit may have multiple meanings
(depending on some other bit value).

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/membarrier.h?id=0bf999f9c5e74c7ecf9dafb527146601e5c848b9#n125

gdb/ChangeLog:

	* dwarf2/read.c (update_enumeration_type_from_children): Allow
	flag enums to contain duplicate enumerators.
	* valprint.c (generic_val_print_enum_1): Update comment.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.c (enum flag_enum): Add FE_TWO_LEGACY
	enumerator.
2020-02-18 17:32:57 -05:00
Simon Marchi edd45eb06b gdb: fix printing of flag enums with multi-bit enumerators
GDB has this feature where if an enum looks like it is meant to
represent binary flags, it will present the values of that type as a
bitwise OR of the flags that are set in the value.

The original motivation for this patch is to fix this behavior:

  enum hello { AAA = 0x1, BBB = 0xf0 };

  (gdb) p (enum hello) 0x11
  $1 = (AAA | BBB)

This is wrong because the bits set in BBB (0xf0) are not all set in the
value 0x11, but GDB presents it as if they all were.

I think that enumerations with enumerators that have more than one bit
set should simply not qualify as "flag enum", as far as this
heuristic is concerned.  I'm not sure what it means to have flags of
more than one bit.  So this is what this patch implements.

I have added an assert in generic_val_print_enum_1 to make sure the flag
enum types respect that, in case they are used by other debug info
readers, in the future.

I've enhanced the gdb.base/printcmds.exp test to cover this case.  I've
also added tests for printing flag enums with value 0, both when the
enumeration has and doesn't have an enumerator for value 0.

gdb/ChangeLog:

	* dwarf2/read.c: Include "count-one-bits.h".
	(update_enumeration_type_from_children): If an enumerator has
	multiple bits set, don't treat the enumeration as a "flag enum".
	* valprint.c (generic_val_print_enum_1): Assert that enumerators
	of flag enums have 0 or 1 bit set.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.c (enum flag_enum): Prefix enumerators with
	FE_, add FE_NONE.
	(three): Update.
	(enum flag_enum_without_zero): New enum.
	(flag_enum_without_zero): New variable.
	(enum not_flag_enum): New enum.
	(three_not_flag): New variable.
	* gdb.base/printcmds.exp (test_artificial_arrays): Update.
	(test_print_enums): Add more tests for printing flag enums.
2020-02-18 17:28:23 -05:00
Tom de Vries d4295de4f3 [gdb/testsuite] Handle missing gnatmake in gnat_runtime_has_debug_info
After de-installing gnatmake, I get on stdout/stderr:
...
Running src/gdb/testsuite/gdb.base/gdb-caching-proc.exp ...
FAIL: gdb-caching-proc.exp: failed to compile gnat-debug-info test binary
  ...
FAIL: gdb-caching-proc.exp: failed to compile gnat-debug-info test binary
...

In gdb.sum, we see these FAILs (each paired with an UNSUPPORTED as well)
followed by:
...
PASS: gdb-caching-proc.exp: gnat_runtime_has_debug_info consistency
...

Likewise, after re-installing gnatmake, I get a PASS for each of the
UNSUPPORTEDs, and the FAILs disappear.

The FAIL comes from gnat_runtime_has_debug_info, the PASS/UNSUPPORTED comes
from gdb_compile_ada.

Fix this by removing the corresponding fail call in
gnat_runtime_has_debug_info, as well as using a new variant gdb_compile_ada_1
that doesn't call pass/unsupported.

Tested on x86_64-linux, with gnatmake installed and de-installed.

gdb/testsuite/ChangeLog:

2020-02-18  Tom de Vries  <tdevries@suse.de>

	* lib/ada.exp (gdb_compile_ada_1): Factor out of ...
	(gdb_compile_ada): ... here.
	(gnat_runtime_has_debug_info): Remove fail call for gdb_compile_ada
	failure.  Use gdb_compile_ada_1 instead of gdb_compile_ada.
2020-02-18 10:18:36 +01:00
Tom Tromey f251f50533 Have testsuite find gdbserver in new location
This updates the gdb testsuite to look for gdbserver in its new
location.  The old location is also checked for, on the theory that
perhaps someone sets GDB to a full path for install testing.

gdb/testsuite/ChangeLog
2020-02-14  Tom Tromey  <tom@tromey.com>

	* lib/gdbserver-support.exp (find_gdbserver): Find gdbserver in
	build directory.
	* boards/gdbserver-base.exp: Update path to gdbserver.

Change-Id: If03db762ba53882ddfaf2d2d516de14c3fa03938
2020-02-14 14:14:38 -07:00
Tom de Vries 8f432634a5 [gdb/testsuite] Remove stale exec in gdb_compile_ada
When running test-case gdb.ada/ptype_tagged_param.exp, I get:
...
PASS: gdb.ada/ptype_tagged_param.exp: compilation foo.adb
...

However, when I then de-install gnatmake and run again, I get the same result.
This is due to a stale exec. After removing the stale exec, I get:
...
UNSUPPORTED: gdb.ada/ptype_tagged_param.exp: compilation foo.adb
...

Fix this removing the stale exec in gdb_compile_ada before compilation.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-13  Tom de Vries  <tdevries@suse.de>

	* lib/ada.exp (gdb_compile_ada): Delete stale exec before compilation.
2020-02-13 15:42:07 +01:00
Tom de Vries 92b6eaf759 [gdb/testsuite] Add unsupported tests in catch_ex_std.exp
If I de-install gnatbind, I run into:
...
FAIL: gdb.ada/catch_ex_std.exp: gnatbind foo
...

Fix this by marking the test unsupported instead:
...
UNSUPPORTED: gdb.ada/catch_ex_std.exp: gnatbind foo
...

Likewise for gnatlink.

Tested on x86_64-linux, with and without gnatbind/gnatlink installed.

gdb/testsuite/ChangeLog:

2020-02-13  Tom de Vries  <tdevries@suse.de>

	* gdb.ada/catch_ex_std.exp: Indicate unsupported if gnatbind/gnatlink
	are missing.
2020-02-13 15:34:06 +01:00
Tom de Vries f3b0f7fe42 [gdb/testsuite] Fix gnatmake_version_at_least
After de-installing gnatmake, I get:
...
Running src/gdb/testsuite/gdb.ada/rename_subscript_param.exp ...
ERROR: tcl error sourcing src/gdb/testsuite/gdb.ada/rename_subscript_param.exp.
ERROR: couldn't execute "gnatmake": no such file or directory
    while executing
"exec $gnatmake --version"
    (procedure "gnatmake_version_at_least" line 4)
...

Fix this by wrapping the exec call in a catch call.

Tested with and withouth gnatmake installed on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-13  Tom de Vries  <tdevries@suse.de>

	* lib/ada.exp (gnatmake_version_at_least): Wrap exec call in a catch
	call.
2020-02-13 08:37:34 +01:00
Sergio Durigan Junior f6be87130b New testcase for PR tui/25126 (staled source cache)
I'm dealing with a Fedora GDB bug that is related to PR tui/25126, and
I thought I'd write a specific testcase for it because I couldn't find
one.

The idea is to get the simple reproducer from the bug and tweak the
testcase around it.  This one was a bit hard because, since we need to
modify the source file and recompile it, it involved a bit of TCL-foo
to do things.  Also for this reason, I'm only enabling the test for
native boards.

I tested this with an upstream GDB and made sure everything is
passing.  I also tested with a faulty GDB and made sure the test
failed.

gdb/testsuite/ChangeLog:
2020-02-11  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR tui/25126
	https://bugzilla.redhat.com/show_bug.cgi?id=1784210
	* gdb.base/cached-source-file.c: New file.
	* gdb.base/cached-source-file.exp: New file.

Change-Id: Ib1b074342ebe8613c6d1dfde631691ebdf6d81c6
2020-02-11 11:36:17 -05:00
Tom de Vries b2770d5e77 [gdb/testsuite] Fix UNRESOLVED in gdb.server/server-kill-python.exp
The test-case gdb.server/server-kill-python.exp runs fine by itself:
...
Running src/gdb/testsuite/gdb.server/server-kill-python.exp ...

                === gdb Summary ===

nr of expected passes            3
...

But if we run f.i. gdb.server/file-transfer.exp before it, we get instead:
...
Running src/gdb/testsuite/gdb.server/server-kill-python.exp ...
ERROR: GDB process no longer exists

                === gdb Summary ===

nr of expected passes            13
nr of unresolved testcases       1
...

We can see the origin of the problem here:
...
spawn gdbserver --once localhost:2347 \
  build/gdb/testsuite/outputs/gdb.server/file-transfer/file-transfer \
  build/gdb/testsuite/outputs/gdb.server/server-kill-python/server-kill-python^M
Process build/gdb/testsuite/outputs/gdb.server/file-transfer/file-transfer
  \ created; pid = 9464^M
Listening on port 2347^M
...

The spawn of the gdbserver for the server-kill-python test-case gets as
executable argument the file-transfer binary.

This is caused by proc gdbserver_spawn attempting to load the exec file in
$file_last_loaded.  This is something that is meant to load the same exec in
the gdbserver that was earlier loaded into gdb.

In this test-case however, nothing has been loaded into gdb by the test-case,
and consequently we load the file that was loaded into gdb in the previous
test-case.

Fix this by unsetting $file_last_loaded in gdb_init.

Build and reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-11  Tom de Vries  <tdevries@suse.de>

	PR testsuite/25488
	* lib/gdb.exp (gdb_init): Unset $file_last_loaded.

Change-Id: Ic385e08cbd34cbf85518720cf5695b4ff6619f4b
2020-02-11 07:08:33 +01:00
Tom de Vries 44f6938ead [gdb/testsuite] Skip multi-target.exp without gdbserver
Pre-commit 919adfe840 "Move gdbserver to top level", if we build gdb with
--disable-gdbserver, and run test-case gdb.multi/multi-target.exp, we run
into:
...
(gdb) PASS: gdb.multi/multi-target.exp: continue: non-stop=off: set remote-exec file in inferior 2
spawn of  --once --multi localhost:2346 failed
ERROR: tcl error sourcing /data/gdb_versions/devel/src/gdb/testsuite/gdb.multi/multi-target.exp.
ERROR: Timeout waiting for gdbserver response.
...

Fix this by using skip_gdbserver_tests in multi-target.exp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* gdb.multi/multi-target.exp: Skip if skip_gdbserver_tests.
2020-02-10 13:22:09 +01:00
Maciej W. Rozycki 5f0e2eb79e GDB/testsuite: Fix a catastrophic step-over-no-symbols.exp failure
Fix a catastrophic failure in gdb.base/step-over-no-symbols.exp where
remote target communication issues cause the value of the PC retrieved
to be empty:

(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: stepi
p /x $pc
Remote 'g' packet reply is too long (expected 264 bytes, got 532 bytes): 00000000000000002a6f61551500000080faffff3f0000000028010000000000b03857551500000060ad5f5515000000906e615515000000802401000000000090faffff3f00000000000000000000000100000000000000e8fbffff3f000000f8fbffff3f0000000000000000000000b8faffff3f0000008a05010000000000589c6f551500000056424d40435c2f7c1809575515000000f0e0baaa2a0000000000000000000000f0ffbaaa2a000000f0e0baaa2a0000006804baaa2a000000000000000000000000000000000000007053baaa2a0000008252b2aa2a00000090fe01000000000048e056551500000004000000000000004000000000000000920501000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000xxxxxxxxxxxxxxxx00000000
(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: get after PC
ERROR: tcl error sourcing .../gdb/testsuite/gdb.base/step-over-no-symbols.exp.
ERROR: missing operand at _@_
in expression " _@_!= "
    (parsing expression " != ")
    invoked from within
"expr $before_addr != $after_addr"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 expr $condition"
    (procedure "gdb_assert" line 6)
    invoked from within
"gdb_assert {$before_addr != $after_addr} "advanced""
    (procedure "test_step_over" line 36)
    invoked from within
"test_step_over $displaced"
    ("uplevel" body line 2)
    invoked from within
"uplevel 1 $body"
    invoked from within
"with_test_prefix "displaced=$displaced" {
	test_step_over $displaced
    }"
    ("foreach" body line 6)
    invoked from within
"foreach displaced { "off" "on" "auto" } {
    if { $displaced != "off" && ![support_displaced_stepping] } {
	continue
    }

    with_test_prefix "dis..."
    (file ".../gdb/testsuite/gdb.base/step-over-no-symbols.exp" line 84)
    invoked from within
"source .../gdb/testsuite/gdb.base/step-over-no-symbols.exp"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 source .../gdb/testsuite/gdb.base/step-over-no-symbols.exp"
    invoked from within
"catch "uplevel #0 source $test_file_name""
Remote debugging from host xxx.xxx.xxx.xxx, port 47130
monitor exit
Killing process(es): 1092
Remote communication error.  Target disconnected.: Connection reset by peer.
(gdb)

To do so verify first, before making an arithmetic comparison, that the
values to compare are actually integers (using a string comparison would
result in a false PASS if both operands were empty, as in this case),
making the test script proceed normally:

(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: stepi
p /x $pc
Remote 'g' packet reply is too long (expected 264 bytes, got 532 bytes): 00000000000000002a6f61551500000080faffff3f0000000028010000000000b03857551500000060ad5f5515000000906e615515000000802401000000000090faffff3f00000000000000000000000100000000000000e8fbffff3f000000f8fbffff3f0000000000000000000000b8faffff3f0000008a05010000000000589c6f5515000000424d40435c2f7c7c1809575515000000f0e0baaa2a0000000000000000000000f0ffbaaa2a000000f0e0baaa2a0000006804baaa2a000000000000000000000000000000000000007053baaa2a0000008252b2aa2a00000090fe01000000000048e056551500000004000000000000004000000000000000920501000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000xxxxxxxxxxxxxxxx00000000
(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: get after PC
FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: advanced
Remote debugging from host xxx.xxx.xxx.xxx, port 48404
monitor exit
Killing process(es): 1795
Remote communication error.  Target disconnected.: Connection reset by peer.
(gdb)

Note the double curly braces, to take advantage of `&&' operator's lazy
evaluation.

	gdb/testsuite/
	* gdb.base/step-over-no-symbols.exp: Verify that $before_addr
	and $after_addr are both integers before making a comparison.
2020-02-10 08:59:04 +00:00
Tom de Vries 46ce2b6f4c [gdb/testsuite] Capture many-headers.exp progress and output in gdb.log
When running test-case gdb.base/many-headers.exp, we have test output on
stdout/stderr:
...
Running src/gdb/testsuite/gdb.base/many-headers.exp ...
[New LWP 759]
Core was generated by `outputs/gdb.base/many-headers/many'.
Program terminated with signal SIGSEGV, Segmentation fault.
\#0  0x0000000000400688 in ?? ()

                === gdb Summary ===

nr of expected passes            1
...

Furthermore, the only trace in gdb.log that we have of the gdb command issued
is:
...
PASS: gdb.base/many-headers.exp: read core file
...

Fix this by echoing the gdb command in gdb.log, and capturing the
command output and pasting it into gdb.log:
...
( ulimit -s 4096; \
  gdb -nw -nx -data-directory data-directory -batch -core=many-headers.core )
[New LWP 1542]
Core was generated by `many'.
Program terminated with signal SIGSEGV, Segmentation fault.
\#0  0x0000000000400688 in ?? ()
PASS: gdb.base/many-headers.exp: read core file
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-09  Tom de Vries  <tdevries@suse.de>

	* gdb.base/many-headers.exp: Echo gdb command to gdb.log.  Capture gdb
	command output and paste it into gdb.log.  If any, paste catch message
	to gdb.log.
2020-02-09 13:30:03 +01:00
Tom Tromey 5abbbe1d13 Revert basenames_may_differ patch
Commit a0c1ffedc regressed certain cases coming from Eclipse.
See PR breakpoints/24915.

gdb/ChangeLog
2020-02-07  Tom Tromey  <tromey@adacore.com>

	PR breakpoints/24915:
	* source.c (find_and_open_source): Do not check basenames_may_differ.

gdb/testsuite/ChangeLog
2020-02-07  Tom Tromey  <tromey@adacore.com>

	PR breakpoints/24915:
	* gdb.base/annotate-symlink.exp: Use setup_xfail.

Change-Id: Iadbf42f35eb40c95ad32b2108ae25d8f199998bd
2020-02-07 14:05:56 -07:00
Shahab Vahedi 1d5d29e73f gdb: Catch exceptions if the source file is not found
The source_cache::ensure method may throw an exception through
the invocation of source_cache::get_plain_source_lines. This
happens when the source file is not found. The expected behaviour
of "ensure" is only returning "true" or "false" according to the
documentation in the header file.

So far, if gdb is in source layout and a file is missing, you see
some outputs like below:

 ,---------------------------------------------.
 | test.c file is loaded in the source window. |
 |                                             |
 | int main()                                  |
 | ...                                         |
 |---------------------------------------------|
 | Remote debugging using :1234                |
 | __start () at /path/to/crt0.S:141           |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) p/x $pc                               |
 | $1 = 0x124                                  |
 | (gdb) n                                     |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) p/x $pc                               |
 | $2 = 0x128                                  |
 | (gdb) [pressing arrow-down key]             |
 | (gdb) terminate called after throwing an    |
 |       instance of 'gdb_exception_error'     |
 `---------------------------------------------'
Other issues have been encountered as well [1].

The patch from Pedro [2] which is about preventing exceptions
from crossing the "readline" mitigates the situation by not
causing gdb crash, but still there are lots of errors printed:

 ,---------------------------------------------.
 | test.c file is loaded in the source window. |
 |                                             |
 | int main()                                  |
 | ...                                         |
 |---------------------------------------------|
 | Remote debugging using :1234                |
 | __start () at /path/to/crt0.S:141           |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) [pressing arrow-down key]             |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) [pressing arrow-down key]             |
 | /path/to/crt0.S: No such file or directory. |
 | (gdb) [pressing arrow-up key]               |
 | /path/to/crt0.S: No such file or directory. |
 `---------------------------------------------'

With the changes of this patch, the behavior is like:
 ,---------------------------------------------.
 | initially, source window is empty because   |
 | crt0.S is not found and according to the    |
 | program counter that is the piece of code   |
 | being executed.                             |
 |                                             |
 | later, when we break at main (see commands  |
 | below), this window will be filled with the |
 | the contents of test.c file.                |
 |---------------------------------------------|
 | Remote debugging using :1234                |
 | __start () at /path/to/crt0.S:141           |
 | (gdb) p/x $pc                               |
 | $1 = 0x124                                  |
 | (gdb) n                                     |
 | (gdb) p/x $pc                               |
 | $2 = 0x128                                  |
 | (gdb) b main                                |
 | Breakpoint 1 at 0x334: file test.c, line 8. |
 | (gdb) cont                                  |
 | Continuing.                                 |
 | Breakpoint 1, main () at hello.c:8          |
 | (gdb) n                                     |
 | (gdb)                                       |
 `---------------------------------------------'

There is no crash and the error message is completely
gone. Maybe it is good practice that the error is
shown inside the source window.

I tested this change against gdb.base/list-missing-source.exp
and there was no regression.

[1]
It has also been observed in the past that the register
values are not transferred from qemu's gdb stub, see:
https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/226

[2]
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=2f267673f0fdee9287e6d404ecd4f2d29da0d2f2

gdb/ChangeLog:

	* source-cache.c (source_cache::ensure): Surround
	get_plain_source_lines with a try/catch.
	(source_cache::get_line_charpos): Get rid of try/catch
	and only check for the return value of "ensure".
	* tui/tui-source.c (tui_source_window::set_contents):
	Simplify "nlines" calculation.

gdb/testsuite/ChangeLog:

	* gdb.tui/tui-missing-src.exp: Add the "missing source
	file" test for the TUI.
2020-02-06 17:54:59 +01:00
Andrew Burgess b0999b9b45 gdb/testsuite: Avoid leaking a port number into results summary
Give a test a real name in order to avoid including a port number in
the results summary file - which makes comparing test results between
runs hard.

gdb/testsuiteChangeLog:

	* gdb.server/multi-ui-errors.exp: Give a test a real name to avoid
	including a port number in the output.

Change-Id: I19334e176ac15aee2a9732a6060c58153d9fb793
2020-02-06 16:39:20 +00:00
Alok Kumar Sharma c3b149eb76 gdb/fortran: Allow for using Flang in Fortran testing
In lib/fortran.exp, in the helper function fortran_int4, there is
currently no support for the LLVM Fortran compiler, Flang.  As a
result we return the default pattern 'unknown' to match against all
4-byte integer types, which causes many tests to fail.

The same is true for all of the other helper functions related to
finding a suitable type pattern.

This commit adds support for Flang.  There should be no change when
testing with gfortran.

gdb/testsuite/ChangeLog:

	* lib/fortran.exp (fortran_int4): Handle clang.
	(fortran_int8): Likewise.
	(fortran_real4): Likewise.
	(fortran_real8): Likewise.
	(fortran_complex4): Likewise.
	(fortran_logical4): Likewise.
	(fortran_character1): Likewise.

Change-Id: Ife0d9828f78361fbd992bf21af746042b017dafc
2020-02-04 17:17:20 +00:00
Tom de Vries f8dcc90b60 [gdb/testsuite] Add note to 'Race detection' entry in README
Add note to 'Race detection' entry in README about the possibility that
check-read1 makes failing tests pass.

gdb/testsuite/ChangeLog:

2020-02-04  Tom de Vries  <tdevries@suse.de>

	* README (Race detection): Add note.

Change-Id: I12ef2f0ec35abc5a0221585bf30e5f4f0616aa7c
2020-02-04 17:36:17 +01:00
Tom de Vries f90ac7c2bb [gdb/testsuite] Make inferior_exited_re match a single line
The current inferior_exited_re regexp contains a '.*':
...
set inferior_exited_re "(?:\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
...

This means that while matching a single line:
...
$ tclsh
% set re "(?:\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
(?:\[Inferior [0-9]+ \(.*\) exited)
% set line "\[Inferior 1 (process 33) exited\]\n"
[Inferior 1 (process 33) exited]

% regexp $re $line
1
...
it also matches more than one line:
...
$ tclsh
% set re "(?:\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
(?:\[Inferior [0-9]+ \(.*\) exited)
% set line "\[Inferior 1 (process 33) exited\]\n\[Inferior 2 (process 44) exited\]\n"
[Inferior 1 (process 33) exited]
[Inferior 2 (process 44) exited]

% regexp $re $line
1
...

Fix this by using "\[^\n\r\]*" instead of ".*".

Build and reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-04  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (inferior_exited_re): Use "\[^\n\r\]*" instead of ".*".

Change-Id: Id7b1dcecd8c7fda3d1ab34b4fa1364d301748333
2020-02-04 17:30:05 +01:00
Tom de Vries 780636aec0 [gdb/testsuite] Use non-capturing parentheses for inferior_exited_re
The inferior_exited_re regexp uses capturing parentheses by default:
...
set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
...

The parentheses are there to be able to use the expression as an atom, f.i.,
to have '+' apply to the whole regexp in "${inferior_exited_re}+".

But the capturing is not necessary, and it can be confusing because it's not
obvious in a regexp using "$inferior_exited_re (bla|bli)" that the first
captured expression is in $inferior_exited_re.

Replace by non-capturing parentheses.  If we still want to capture the
expression, we can simply (and more clearly) use "($inferior_exited_re)".

Build and reg-tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-02-04  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (inferior_exited_re): Use non-capturing parentheses.

Change-Id: I7640c6129b1ada617424d6a63730d4b119c58ef3
2020-02-04 09:53:50 +01:00
Rogerio Alves 5d2e119328 gdb: fix powerpc disassembly tests
This patch fixes test failures power8 and power9 caused by changes on
opcodes:

The dissasembler does not emit whitespace for instructions
anymore (c2b1c27545)

The dissasembler generates extended mnemonics for some instructions
instead (aae9718e4d)

The ldmx instruction was removed. This instruction was never
implemented (6fbc939cfd)

gdb/testsuite/ChangeLog:
2020-02-03  Rogerio A. Cardoso  <rcardoso@linux.ibm.com>

	* gdb.arch/powerpc-power8.exp: Delete trailing whitespace of
	tbegin., tend. instructions. Replace bctar-, bctar+, bctarl-,
	bctarl+ extended mnemonics when avaliable by bgttar, bnstarl,
	blttar, bnetarl.
	* gdb.arch/powerpc-power8.s: Fix comments. Fix instructions
	binary for blttar, bnetarl.
	* gdb.arch/powerpc-power9.exp: Delete trailing whitespace of
	wait instruction. Delete ldmx test.
	* gdb.arch/powerpc-power9.s: Delete ldmx instruction.
2020-02-03 22:35:49 -05:00
Alok Kumar Sharma e409c542cc Fixed gdb to print arrays with very high indexes
In the function f77_print_array_1, the variable 'i' which holds the
index is of datatype 'int', while bounds are of datatype LONGEST. Due to
size of int being smaller than LONGEST, the variable 'i' stores
incorrect values for high indexes (higher than max limit of int).  Due
to this issue in sources, two abnormal behaviors are seen while printing
arrays with high indexes (please check array-bounds-high.f90) For high
indexes with negative sign, gdb prints empty array even if the array has
elements.

    (gdb) p arr
    $1 = ()

For high indexes with positive sign, gdb crashes.  We have now changed
the datatype of 'i' to LONGEST which is same as datatype of bounds.

gdb/ChangeLog:

	* f-valprint.c (f77_print_array_1): Changed datatype of index
	variable to LONGEST from int to enable it to contain bound
	values correctly.

gdb/testsuite/ChangeLog:

	* gdb.fortran/array-bounds-high.exp: New file.
	* gdb.fortran/array-bounds-high.f90: New file.

Change-Id: Ie2dce9380a249e634e2684b9c90f225e104369b7
2020-02-03 20:24:34 -05:00
Lukas Durfina b0029748ca Fix compilation error with musl in gdb/testsuite/gdb.base/fileio.c
Musl is giving warnings about these includes in this way:
warning: #warning redirecting incorrect #include <sys/errno.h> to <errno.h>
warning: #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h>

gdb/testsuite/Changelog:

	* gdb.base/fileio.c: Remove #include of <sys/errno.h>.
	Replace #include of <sys/fcntl.h> by <fcntl.h>.
2020-02-03 14:36:17 +04:00
Tom de Vries 195a8287c1 [gdb/testsuite] Fix typo in gdb.server/server-kill-python.exp
Fix typo '$gdb_tst_name' -> '$gdb_test_name'.

gdb/testsuite/ChangeLog:

2020-02-01  Tom de Vries  <tdevries@suse.de>

	* gdb.server/server-kill-python.exp: Fix $gdb_tst_name typo.

Change-Id: Iad050dab0e8aad2f2692e54e398021558250f1ac
2020-02-01 00:05:42 +01:00
Andrew Burgess 42330a681a gdb/tui: Disassembler scrolling of very small programs
In TUI mode, if the disassembly output for the program is less than
one screen long, then currently if the user scrolls down until on the
last assembly instruction is displayed and then tries to scroll up
using Page-Up, the display doesn't update - they are stuck viewing the
last line.

If the user tries to scroll up using the Up-Arrow, then the display
scrolls normally.

What is happening is on the Page-Up we ask GDB to scroll backward the
same number of lines as the height of the TUI ASM window.  The back
scanner, which looks for a good place to start disassembling, fails to
find a starting address which will provide the requested number of new
lines before we get back to the original starting address (which is
not surprising, our whole program contains less than a screen height
of instructions), as a result the back scanner gives up and returns
the original starting address.

When we scroll with Up-Arrow we only ask the back scanner to find 1
new instruction, which it manages to do, so this scroll works.

The solution here is, when we fail to find enough instructions, to
return the lowest address we did manage to find.  This will ensure we
jump to the lowest possible address in the disassembly output.

gdb/ChangeLog:

	PR tui/9765
	* tui/tui-disasm.c (tui_find_disassembly_address): If we don't
	have enough lines to fill the screen, still return the lowest
	address we found.

gdb/testsuite/ChangeLog:

	PR tui/9765
	* gdb.tui/tui-layout-asm-short-prog.S: New file.
	* gdb.tui/tui-layout-asm-short-prog.exp: New file.

Change-Id: I6a6a7972c68a0559e9717fd8d82870b669a40af3
2020-01-31 00:41:06 +00:00
Luis Machado b62a802857 Test handling of additional brk instruction patterns
New in v5:

- Use gdb_test_name for gdb_test_multiple.
- Use gdb_assert.
- Verify count matches the expected sigtraps exactly.

New in v4:

- Fix formatting nit in gdb/testsuite/gdb.arch/aarch64-brk-patterns.c.

New in v3:

- Minor formatting and code cleanups.
- Added count check to validate number of brk SIGTRAP's.
- Moved count to SIGTRAP check conditional block.

This test exercises the previous patch's code and makes sure GDB can
properly get a SIGTRAP from various brk instruction patterns.

GDB needs to be able to see the program exiting normally. If GDB doesn't
support the additional brk instructions, we will see timeouts.

We bail out with the first timeout since we won't be able to step through
the program breakpoint anyway, so it is no use carrying on.

gdb/testsuite/ChangeLog:

2020-01-29  Luis Machado  <luis.machado@linaro.org>

	* gdb.arch/aarch64-brk-patterns.c: New source file.
	* gdb.arch/aarch64-brk-patterns.exp: New test.
2020-01-29 11:26:07 -03:00
Tankut Baris Aktemur 5f440116e8 testsuite, cp: add expected failures to pass-by-ref tests for certain compilers
There exist expected failures in the pass-by-ref.exp and
pass-by-ref-2.exp tests based on the GCC and Clang version.

* GCC version <= 6 and Clang do not emit DW_AT_deleted and
  DW_AT_defaulted.

* Clang version >= 7 emits DW_AT_calling_convention, which helps the
  debugger make the right calling convention decision in some cases
  despite lacking the 'defaulted' and 'deleted' attributes.

Mark the related tests as XFAIL based on the compiler version.

Tested on X86_64 using GCC 5.5.0, 6.5.0, 7.4.0, 8.3.0, 9.2.1;
and Clang 5.0.1, 6.0.0, 7.0.0, 8.0.0, 9.0.1, 10.0.0.

gdb/testsuite/ChangeLog:
2020-01-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.cp/pass-by-ref-2.exp: Mark some tests as XFAIL based on the
	GCC/Clang version.
	* gdb.cp/pass-by-ref.exp: Ditto.

Change-Id: I1d8440aa438049f7c4da7f4f76f201c48550f1e4
2020-01-29 09:10:56 +01:00
Tom de Vries ee2a6fc604 [gdb/testsuite] Fix gdb.threads/watchpoint-fork.exp race
I ran into:
...
Thread 3.1 "watchpoint-fork" hit Breakpoint 3, marker () at \
  watchpoint-fork-mt.c:42^M
42      }^M
(gdb) parent2: 1945^M

FAIL: gdb.threads/watchpoint-fork.exp: child: multithreaded: breakpoint (A) \
  after the second fork (timeout)
...
The problem is that the FAILing gdb_test expects '(gdb) ' to be the last thing
printed, but the inferior prints something after that.

A similar FAIL is described in the sources in watchpoint-fork-parent.c:
...
      printf ("child%d: %d\n", nr, (int) getpid ());
      /* Delay to get both the "child%d" and "parent%d" message printed
      	 without a race breaking expect by its endless wait on `$gdb_prompt$':
         Breakpoint 3, marker () at watchpoint-fork.c:33
         33      }
         (gdb) parent2: 14223  */
      i = sleep (1);
...

I noticed that while the executables print output, the output is not verified in
the test-case, so it's merely debug output.

Fix this by:
- guarding the prints in the executables (as well as related
  sleep and setbuf calls) with #if DEBUG, and
- compiling by default with DEBUG=0.

gdb/testsuite/ChangeLog:

2020-01-29  Tom de Vries  <tdevries@suse.de>

	* gdb.threads/watchpoint-fork-child.c: Guard prints with #if DEBUG.
	* gdb.threads/watchpoint-fork-mt.c: Same.
	* gdb.threads/watchpoint-fork-parent.c: Same.
	* gdb.threads/watchpoint-fork-st.c: Same.
	* gdb.threads/watchpoint-fork.exp: Compile with DEBUG=0.

Change-Id: I63efd4c7771f96b5f5cd87ef2ab36795484ae2be
2020-01-29 08:48:53 +01:00
Luis Machado 16b10d6e61 Harden gdb.base/step-over-syscall.exp
New in v3:
- Verify if the syscall number matches what is expected for the target.
- Used gdb_assert for one more check.

New in v2:

- Set initial values to -1 instead of 0.
- Rewrote RE to prevent unexpected matching when parsing one character at a
  time.
- Used gdb_assert for an additional check.
- Validated with check-read1

There are a couple problems with this test.

First
--

gdb.base/step-over-syscall.exp records the address of a syscall instruction
within fork/vfork/clone functions and also the address of the instruction
after that syscall instruction.

It uses these couples addresses to make sure we stepped over a syscall
instruction (fork/vfork/clone events) correctly.

The way the test fetches the addresses of the instructions is by stepi-ing
its way through the fork/vfork/clone functions until it finds a match for
a syscall. Then it stepi's once again to get the address of the next
instruction.

This assumes that stepi-ing over a syscall is working correctly and landing
in the right PC. This is not the case for AArch64/Linux, where we're
landing a couple instructions after the syscall in some cases.

The following patch lets the test execute as before, but adds a new instruction
address check using the x command as opposed to stepi.

I didn't want to change how the test works since we may also be
interested in checking if stepi-ing over the syscall under different
conditions (displaced stepping on/off) yields the same results. I don't
feel strongly about this, so i'm OK with changing how we compare PC's for
the entire test if folks decide it is reasonable.

Second
--

FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: continue to vfork (3rd time) (the program exited)
FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: continue to syscall insn vfork (the program is no longer running)
FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: single step over vfork (the program is no longer running)

Depending on the glibc version we may have different code generated for the
fork/vfork/clone functions.

I ran into the situation where vfork for newer glibc's on AArch64/Linux is
very short, so "break vfork" will put a breakpoint right at the syscall
instruction, which is something the testcase isn't expecting (a off-by-1
of sorts).

The patch adds extra code to handle this case. If the test detects we're
already sitting at a syscall instruction, it records the address and moves
on to record the address after that particular instruction.

Another measure is to "break *$syscall" instead of "break $syscall". That
guarantees we're stopping at the first instruction of the syscall function,
if it ever happens that the syscall instruction is the first instruction of
those functions.

With these changes i can fix some failures for aarch64-linux-gnu and also
expose the problems i've reported here:

https://sourceware.org/ml/gdb-patches/2019-12/msg01071.html

These tests now fail for aarch64-linux-gnu (patch for this is going through
reviews):

FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: pc after stepi matches insn addr after syscall
FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=on: pc after stepi matches insn addr after syscall

gdb/testsuite/ChangeLog:

2020-01-27  Luis Machado  <luis.machado@linaro.org>

	* gdb.base/step-over-syscall.exp (setup): Check if we're already
	sitting at a syscall instruction when we hit the syscall function's
	breakpoint.
	Check PC against one obtained with the x command.
	Validate syscall number.
	(step_over_syscall): Don't continue to the syscall instruction if
	we're already there.
2020-01-27 17:28:06 -03:00
Philippe Waroquiers b1468492c6 Test 'set exec-file-mismatch ask|warn|off'.
Modify gdb.base/attach.exp to test the behaviour of the option
exec-file-mismatch.  Note that this test can also be run using/
  make check RUNTESTFLAGS="--target_board=native-extended-gdbserver" TESTS=gdb.base/attach.exp

to test the behaviour of attaching to running program using a gdb server.

Note: when running the test with a gdbserver, the tests in
test_command_line_attach_run fail because the command "run" is not supported.
I tried to extend the condition
    if ![isnative] then {
	unsupported "commandline attach run test"
	return 0
    }
but unclear to me how to best do that.  The below trials all failed
to work properly:
    if { ![isnative] || [target_is_gdbserver] } then {
    if { ![isnative] || [use_gdb_stub] } then {
    if { ![isnative] || [is_remote target] } then {
  => could never obtain a condition that was true with gdbserver.

2020-01-25  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/attach.exp: Test 'set exec-file-mismatch'.
2020-01-25 11:08:24 +01:00
Andrew Burgess 7ffa82e122 gdb: Better frame tracking for inline frames
This commit improves GDB's handling of inline functions when there are
more than one inline function in a stack, so for example if we have a
stack like:

   main -> aaa -> bbb -> ccc -> ddd

And aaa, bbb, and ccc are all inline within main GDB should (when
given sufficient debug information) be able to step from main through
aaa, bbb, and ccc.  Unfortunately, this currently doesn't work, here's
an example session:

  (gdb) start
  Temporary breakpoint 1 at 0x4003b0: file test.c, line 38.
  Starting program: /project/gdb/tests/inline/test

  Temporary breakpoint 1, main () at test.c:38
  38	  global_var = 0;
  (gdb) step
  39	  return aaa () + 1;
  (gdb) step
  aaa () at test.c:39
  39	  return aaa () + 1;
  (gdb) step
  bbb () at test.c:39
  39	  return aaa () + 1;
  (gdb) step
  ccc () at test.c:39
  39	  return aaa () + 1;
  (gdb) step
  ddd () at test.c:32
  32	  return global_var;
  (gdb) bt
  #0  ddd () at test.c:32
  #1  0x00000000004003c1 in ccc () at test.c:39
  #2  bbb () at test.c:26
  #3  aaa () at test.c:14
  #4  main () at test.c:39

Notice that once we get to line 39 in main, GDB keeps reporting line
39 in main as the location despite understanding that the inferior is
stepping through the nested inline functions with each use of step.

The problem is that as soon as the inferior stops we call
skip_inline_frames (from inline-frame.c) which calculates the
inferiors current state in relation to inline functions - it figures
out if we're in an inline function, and if we are counts how many
inline frames there are at the current location.

So, in our example above, when we step from line 38 in main to line 39
we stop at a location that is simultaneously in all of main, aaa, bbb,
and ccc.  The block structure reflects the order in which the
functions would be called, with ccc being the most inner block and
main being the most outer block.  When we stop GDB naturally finds the
block for ccc, however within skip_inline_frames we spot that bbb,
aaa, and main are super-blocks of the current location and that each
layer represents an inline function.  The skip_inline_frames then
records the depth of inline functions (3 in this case for aaa, bbb,
and ccc) and also the symbol of the outermost inline function (in this
case 'aaa' as main isn't an inline function, it just has things inline
within it).

Now GDB understands the stack to be main -> aaa -> bbb -> ccc,
however, the state initialised in skip_inline_frames starts off
indicating that we should hide 3 frames from the user, so we report
that we're in main at line 39.  The location of main, line 39 is
derived by asking the inline function state for the last symbol in the
stack (aaa in this case), and then asking for it's location - the
location of an inlined function symbol is its call site, so main, line
39 in this case.

If the user then asks GDB to step we don't actually move the inferior
at all, instead we spot that we are in an inline function stack,
lookup the inline state data, and reduce the skip depth by 1.  We then
report to the user that GDB has stopped.  GDB now understands that we
are in 'aaa'.  In order to get the precise location we again ask GDB
for the last symbol from the inline data structure, and we are again
told 'aaa', we then get the location from 'aaa', and report that we
are in main, line 39.

Hopefully it's clear what the mistake here is, once we've reduced the
inline skip depth we should not be using 'aaa' to compute the precise
location, instead we should be using 'bbb'.  That is what this patch
does.

Now, when we call skip_inline_frames instead of just recording the
last skipped symbol we now record all symbols in the inline frame
stack.  When we ask GDB for the last skipped symbol we return a symbol
based on how many frames we are skipping, not just the last know
symbol.

With this fix in place, the same session as above now looks much
better:

  (gdb) start
  Temporary breakpoint 1 at 0x4003b0: file test.c, line 38.
  Starting program: /project/gdb/tests/inline/test

  Temporary breakpoint 1, main () at test.c:38
  38	  global_var = 0;
  (gdb) s
  39	  return aaa () + 1;
  (gdb) s
  aaa () at test.c:14
  14	  return bbb () + 1;
  (gdb) s
  bbb () at test.c:26
  26	  return ccc () + 1;
  (gdb) s
  ccc () at test.c:20
  20	  return ddd () + 1;
  (gdb) s
  ddd () at test.c:32
  32	  return global_var;
  (gdb) bt
  #0  ddd () at test.c:32
  #1  0x00000000004003c1 in ccc () at test.c:20
  #2  bbb () at test.c:26
  #3  aaa () at test.c:14
  #4  main () at test.c:39

gdb/ChangeLog:

	* frame.c (find_frame_sal): Move call to get_next_frame into more
	inner scope.
	* inline-frame.c (inilne_state) <inline_state>: Update argument
	types.
	(inilne_state) <skipped_symbol>: Rename to...
	(inilne_state) <skipped_symbols>: ...this, and change to a vector.
	(skip_inline_frames): Build vector of skipped symbols and use this
	to reate the inline_state.
	(inline_skipped_symbol): Add a comment and some assertions, fetch
	skipped symbol from the list.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-inline-many-frames.c: New file.
	* gdb.dwarf2/dw2-inline-many-frames.exp: New file.

Change-Id: I99def5ffb44eb9e58cda4b449bf3d91ab0386c62
2020-01-24 23:44:16 +00:00
Andrew Burgess 3d92a3e313 gdb: Don't reorder line table entries too much when sorting.
Don't reorder line table entries for the same address when sorting the
line table, maintain the compiler given line order.  Usually this will
reflect the order in which lines are conceptually encountered at a
given address.

Consider this example:

/* 1  */    volatile int global_var;
/* 2  */    int  __attribute__ ((noinline))
/* 3  */    bar ()
/* 4  */    {
/* 5  */      return global_var;
/* 6  */    }
/* 7  */    static inline int __attribute__ ((always_inline))
/* 8  */    foo ()
/* 9  */    {
/* 10 */      return bar ();
/* 11 */    }
/* 12 */    int
/* 13 */    main ()
/* 14 */    {
/* 15 */      global_var = 0;
/* 16 */      return foo ();
/* 17 */    }

GCC 10 currently generates a line table like this (as shown by
objdump):

  CU: ./test.c:
  File name          Line number    Starting address
  test.c                       4            0x4004b0
  test.c                       5            0x4004b0
  test.c                       6            0x4004b6
  test.c                       6            0x4004b7

  test.c                      14            0x4003b0
  test.c                      15            0x4003b0
  test.c                      16            0x4003ba
  test.c                      10            0x4003ba
  test.c                      10            0x4003c1

The interesting entries are those for lines 16 and 10 at address
0x4003ba, these represent the call to foo and the inlined body of
foo.

With the current line table sorting GDB builds the line table like
this (as shown by 'maintenance info line-table'):

  INDEX    LINE ADDRESS
  0          14 0x00000000004003b0
  1          15 0x00000000004003b0
  2          10 0x00000000004003ba
  3          16 0x00000000004003ba
  4         END 0x00000000004003c1
  5           4 0x00000000004004b0
  6           5 0x00000000004004b0
  7         END 0x00000000004004b7

Notice that entries 2 and 3 for lines 10 and 16 are now in a different
order to the line table as given by the compiler.  With this patch
applied the order is now:

  INDEX    LINE ADDRESS
  0          14 0x00000000004003b0
  1          15 0x00000000004003b0
  2          16 0x00000000004003ba
  3          10 0x00000000004003ba
  4         END 0x00000000004003c1
  5           4 0x00000000004004b0
  6           5 0x00000000004004b0
  7         END 0x00000000004004b7

Notice that entries 2 and 3 are now in their original order again.

The consequence of the incorrect ordering is that when stepping
through inlined functions GDB will display the wrong line for the
inner most frame.  Here's a GDB session before this patch is applied:

  Starting program: /home/andrew/tmp/inline/test

  Temporary breakpoint 1, main () at test.c:15
  15	/* 15 */      global_var = 0;
  (gdb) step
  16	/* 16 */      return foo ();
  (gdb) step
  foo () at test.c:16
  16	/* 16 */      return foo ();
  (gdb) step
  bar () at test.c:5
  5	/* 5  */      return global_var;

The step from line 15 to 16 was fine, but the next step should have
taken us to line 10, instead we are left at line 16.  The final step
to line 5 is as expected.

With this patch applied the session goes better:

  Starting program: /home/andrew/tmp/inline/test

  Temporary breakpoint 1, main () at test.c:15
  15	/* 15 */      global_var = 0;
  (gdb) step
  16	/* 16 */      return foo ();
  (gdb) step
  foo () at test.c:10
  10	/* 10 */      return bar ();
  (gdb) step
  bar () at test.c:5
  5	/* 5  */      return global_var;

We now visit the lines as 15, 16, 10, 5 as we would like.

The reason for this issue is that the inline frame unwinder is
detecting that foo is inlined in main.  When we stop at the shared
address 0x4003ba the inline frame unwinder first shows us the outer
frame, this information is extracted from the DWARF's
DW_TAG_inlined_subroutine entries and passed via GDB's block data.

When we step again the inlined frame unwinder moves us up the call
stack to the inner most frame at which point the frame is displayed as
normal, with the location for the address being looked up in the line
table.

As GDB uses the last line table entry for an address as "the" line to
report for that address it is critical that GDB maintain the order of
the line table entries.  In the first case, by reordering the line
table we report the wrong location.

I had to make a small adjustment in find_pc_sect_line in order to
correctly find the previous line in the line table.  In some line
tables I was seeing an actual line entry and an end of sequence marker
at the same address, before this commit these would reorder to move
the end of sequence marker before the line entry (end of sequence has
line number 0).  Now the end of sequence marker remains in its correct
location, and in order to find a previous line we should step backward
over any end of sequence markers.

As an example, the binary:
  gdb/testsuite/outputs/gdb.dwarf2/dw2-ranges-func/dw2-ranges-func-lo-cold

Has this line table before the patch:

  INDEX    LINE ADDRESS
  0          48 0x0000000000400487
  1         END 0x000000000040048e
  2          52 0x000000000040048e
  3          54 0x0000000000400492
  4          56 0x0000000000400497
  5         END 0x000000000040049a
  6          62 0x000000000040049a
  7         END 0x00000000004004a1
  8          66 0x00000000004004a1
  9          68 0x00000000004004a5
  10         70 0x00000000004004aa
  11         72 0x00000000004004b9
  12        END 0x00000000004004bc
  13         76 0x00000000004004bc
  14         78 0x00000000004004c0
  15         80 0x00000000004004c5
  16        END 0x00000000004004cc

And after this patch:

  INDEX    LINE ADDRESS
  0          48 0x0000000000400487
  1          52 0x000000000040048e
  2         END 0x000000000040048e
  3          54 0x0000000000400492
  4          56 0x0000000000400497
  5         END 0x000000000040049a
  6          62 0x000000000040049a
  7          66 0x00000000004004a1
  8         END 0x00000000004004a1
  9          68 0x00000000004004a5
  10         70 0x00000000004004aa
  11         72 0x00000000004004b9
  12        END 0x00000000004004bc
  13         76 0x00000000004004bc
  14         78 0x00000000004004c0
  15         80 0x00000000004004c5
  16        END 0x00000000004004cc

When calling find_pc_sect_line with the address 0x000000000040048e, in
both cases we find entry #3, we then try to find the previous entry,
which originally found this entry '2         52 0x000000000040048e',
after the patch it finds '2         END 0x000000000040048e', which
cases the lookup to fail.

By skipping the END marker after this patch we get back to the correct
entry, which is now #1: '1          52 0x000000000040048e', and
everything works again.

gdb/ChangeLog:

	* buildsym.c (lte_is_less_than): Delete.
	(buildsym_compunit::end_symtab_with_blockvector): Create local
	lambda function to sort line table entries, and use
	std::stable_sort instead of std::sort.
	* symtab.c (find_pc_sect_line): Skip backward over end of sequence
	markers when looking for a previous line.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-inline-stepping.c: New file.
	* gdb.dwarf2/dw2-inline-stepping.exp: New file.

Change-Id: Ia0309494be4cfd9dcc554f30209477f5f040b21b
2020-01-24 23:43:16 +00:00
Andrew Burgess 94a72be708 gdb: Include end of sequence markers in the line table
In this commit:

  commit d9b3de22f3
  Date:   Wed May 27 14:44:29 2015 -0700

      Add struct to record dwarf line number state machine.

I believe an unintended change was made to how we store the DWARF line
table, the end of sequence markers between sequences of lines were
lost from the line table.

This commit fixes this small oversight and restores the end of
sequence markers.

Given that we've survived this long without noticing is clearly an
indication that this isn't that serious, however, a later patch that I
am developing would benefit from having the markers in place, so I'd
like to restore them.

Having the markers also means that the output of 'maintenance info
line-table' now more closely reflects the DWARF line table.

I've taken this opportunity to improve how 'maintenance info
line-table' displays the end of sequence markers - it now uses the END
keyword, rather than just printing an entry with line number 0.  So we
see this:

  INDEX    LINE ADDRESS
  0          12 0x00000000004003b0
  1          17 0x00000000004003b0
  2          18 0x00000000004003b0
  3         END 0x00000000004003b7
  4           5 0x00000000004004a0
  5           6 0x00000000004004a0
  6         END 0x00000000004004a7

Instead of what we would have seen, which was this:

  INDEX    LINE ADDRESS
  0          12 0x00000000004003b0
  1          17 0x00000000004003b0
  2          18 0x00000000004003b0
  3           0 0x00000000004003b7
  4           5 0x00000000004004a0
  5           6 0x00000000004004a0
  6           0 0x00000000004004a7

I've added a small test that uses 'maintenance info line-table' to
ensure that we don't regress this again.

gdb/ChangeLog:

	* dwarf2read.c (lnp_state_machine::record_line): Include
	end_sequence parameter in debug print out.  Record the line if we
	are at an end_sequence marker even if it's not the start of a
	statement.
	* symmisc.c (maintenance_print_one_line_table): Print end of
	sequence markers with 'END' not '0'.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Update line table parsing test.
	* gdb.dwarf2/dw2-ranges-base.exp: Add new line table parsing test.

Change-Id: I002f872248db82a1d4fefdc6b51ff5dbf932d8a8
2020-01-24 23:39:31 +00:00
Pedro Alves 53af73bf5e Fix re-runs of a second inferior (PR gdb/25410)
This fixes a latent bug exposed by the multi-target patch (5b6d1e4fa
"Multi-target support), and then fixes two other latent bugs exposed
by fixing that first latent bug.

The symptom described in the bug report is that starting a first
inferior, then trying to run a second (multi-threaded) inferior twice,
causes libthread_db to fail to load, along with other erratic
behavior:

 (gdb) run
 Starting program: /tmp/foo
 warning: td_ta_new failed: generic error

Going a bit deeply, I found that if the two inferiors have different
symbols, we can see that just after inferior 2 exits, we are left with
inferior 2 selected, which is correct, but the symbols in scope belong
to inferior 1, which is obviously incorrect...

This problem is that there's a path in
scoped_restore_current_thread::restore() that switches to no thread
selected, and switches the current inferior, but leaves the current
program space as is, resulting in leaving the program space pointing
to the wrong program space (the one of the other inferior).  This was
happening after handling TARGET_WAITKIND_NO_RESUMED, which is an event
that triggers after TARGET_WAITKIND_EXITED for the previous inferior
exit.  Subsequent symbol lookups find the symbols of the wrong
inferior.

The fix is to use switch_to_inferior_no_thread in that problem spot.
This function was recently added along with the multi-target work
exactly for these situations.

As for testing, this patch adds a new testcase that tests symbol
printing just after inferior exit, which exercises the root cause of
the problem more directly.  And then, to cover the use case described
in the bug too, it also exercises the lithread_db.so mis-loading, by
using TLS printing as a proxy for being sure that threaded debugging
was activated sucessfully.  The testcase fails without the fix like
this, for the "print symbol just after exit" bits:

 ...
 [Inferior 1 (process 8719) exited normally]
 (gdb) PASS: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=1: continue until exit
 print re_run_var_1
 No symbol "re_run_var_1" in current context.
 (gdb) FAIL: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=1: print re_run_var_1
 ...

And like this for the "libthread_db.so loading" bits:

 (gdb) run
 Starting program: /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run
 warning: td_ta_new failed: generic error
 [New LWP 27001]

 Thread 1.1 "multi-re-run" hit Breakpoint 3, all_started () at /home/pedro/gdb/binutils-gdb/build/../src/gdb/testsuite/gdb.multi/multi-re-run.c:44
 44      }
 (gdb) PASS: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=2: running to all_started in runto
 print tls_var
 Cannot find thread-local storage for LWP 27000, executable file /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run:
 Cannot find thread-local variables on this target
 (gdb) FAIL: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=2: print tls_var


As mentioned, that fix above goes on to expose a couple other latent
bugs.  This commit fixes those as well.

The first latent bug exposed is in
infrun.c:handle_vfork_child_exec_or_exit.  The current code is leaving
inf->pspace == NULL while calling clone_program_space.  The idea was
to make it so that the breakpoints module doesn't use this inferior's
pspace to set breakpoints.  With that, any
scoped_restore_current_thread use from within clone_program_space
tries to restore a NULL program space, which hits an assertion:

 Attaching after Thread 0x7ffff74b8700 (LWP 27276) vfork to child process 27277]
 [New inferior 2 (process 27277)]
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library "/lib64/libthread_db.so.1".
 /home/pedro/gdb/binutils-gdb/build/../src/gdb/progspace.c:243: internal-error: void set_current_program_space(program_space*): Assertion `pspace != NULL' faile
 d.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/vfork-follow-child-exit.exp: detach-on-fork=off: continue (GDB internal error)

That NULL pspace idea was legitimate, but it's no longer necessary,
since commit b2e586e850 ("Defer breakpoint reset when cloning
progspace for fork child").  So the fix is to just set the inferior's
program space earlier.


The other latent bug exposed is in exec.c.  When exec_close is called
from the program_space destructor, it is purposedly called with a
current program space that is not the current inferior's program
space.  The problem is that the multi-target work added some code to
remove_target_sections that loops over all inferiors, and uses
scoped_restore_current_thread to save/restore the previous
thread/inferior/frame state.  This makes it so that exec_close returns
with the current program space set to the current inferior's program
space, which is exactly what we did not want.  Then the program_space
destructor continues into free_all_objfiles, but it is now running
that method on the wrong program space, resulting in:

 Reading symbols from /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads...
 Reading symbols from /usr/lib/debug/usr/lib64/libpthread-2.26.so.debug...
 Reading symbols from /usr/lib/debug/usr/lib64/libm-2.26.so.debug...
 Reading symbols from /usr/lib/debug/usr/lib64/libc-2.26.so.debug...
 Reading symbols from /usr/lib/debug/usr/lib64/ld-2.26.so.debug...
 [Inferior 3 (process 9583) exited normally]
 /home/pedro/gdb/binutils-gdb/build/../src/gdb/progspace.c:170: internal-error: void program_space::free_all_objfiles(): Assertion `so->objfile == NULL' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: inferior 1 exited (GDB internal error)

The fix is to use scoped_restore_current_pspace_and_thread instead of
scoped_restore_current_thread.

gdb/ChangeLog:
2020-01-24  Pedro Alves  <palves@redhat.com>

	PR gdb/25410
	* thread.c (scoped_restore_current_thread::restore): Use
	switch_to_inferior_no_thread.
	* exec.c: Include "progspace-and-thread.h".
	(add_target_sections, remove_target_sections):
	scoped_restore_current_pspace_and_thread instead of
	scoped_restore_current_thread.
	* infrun.c (handle_vfork_child_exec_or_exit): Assign the pspace
	and aspace to the inferior before calling clone_program_space.
	Remove stale comment.

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

	PR gdb/25410
	* gdb.multi/multi-re-run-1.c: New.
	* gdb.multi/multi-re-run-2.c: New.
	* gdb.multi/multi-re-run.exp: New.
2020-01-24 18:46:20 +00:00
Andrew Burgess 1ba1ac8801 gdb: Enable stdin on exception in execute_gdb_command
This is an update of this patch:

  https://sourceware.org/ml/gdb-patches/2018-09/msg00884.html

This patch attempts to address PR gdb/23718 by re-enabling stdin
whenever an exception is caught during gdb.execute().

When Python gdb.execute() is called, an exception could occur (e.g. the
target disappearing), which is then converted into a Python exception.  If
stdin was disabled before the exception is caught, it is not re-enabled,
because the exception doesn't propagate to the top level of the event loop,
whose catch block would otherwise enable it.

The result is that when execution of a Python script completes, GDB does
not prompt or accept input, and is effectively hung.

This change rectifies the issue by re-enabling stdin in the catch block of
execute_gdb_command, prior to converting the exception to a Python
exception.

Since this patch was originally posted I've added a test, and also I
converted the code to re-enable stdin from this:

  SWITCH_THRU_ALL_UIS ()
    {
      async_enable_stdin ();
    }

to simply this:

  async_enable_stdin ();

My reasoning is that we only need the SWITCH_THRU_ALL_UIS if, at the time
the exception is caught, the current_ui might be different than at the time
we called async_disable_stdin.  Within python's execute_gdb_command I think
it should be impossible to switch current_ui, so the SWITCH_THRU_ALL_UIS
isn't needed.

gdb/ChangeLog:

	PR gdb/23718
	* gdb/python/python.c (execute_gdb_command): Call
	async_enable_stdin in catch block.

gdb/testsuite/ChangeLog:

        PR gdb/23718
	* gdb.server/server-kill-python.exp: New file.

Change-Id: I1cfc36ee9f8484cc1ed82be9be338353db6bc080
2020-01-24 00:11:53 +00:00
Andrew Burgess f3364a6d0f gdb: Re-enable stdin for all UIs from start_event_loop
If we catch an exception in start_event_loop's call to
gdb_do_one_event, then it is possible that the current_ui has changed
since we called async_disable_stdin.  If that's the case then calling
async_enable_stdin will be called on the wrong UI.

To solve this problem we wrap the call to async_enable_stdin with
SWITCH_THRU_ALL_UIS, this causes us to try and re-enable stdin for all
UIs, which will catch any for which we called async_disable_stdin.

gdb/ChangeLog:

	* event-loop.c (start_event_loop): Wrap async_enable_stdin with
	SWITCH_THRU_ALL_UIS.

gdb/testsuite/ChangeLog:

	* gdb.server/multi-ui-errors.c: New file.
	* gdb.server/multi-ui-errors.exp: New file.

Change-Id: I1e18deff2e6f4e17f7a13adce3553eb001cad93b
2020-01-24 00:11:52 +00:00
Andrew Burgess 733d0a6795 gdb/tui: asm window handles invalid memory and scrolls better
This started as a patch to enable the asm window to handle attempts to
disassemble invalid memory, but it ended up expanding into a
significant rewrite of how the asm window handles scrolling.  These
two things ended up being tied together as it was impossible to
correctly test scrolling into invalid memory when the asm window would
randomly behave weirdly while scrolling.

Things that should work nicely now; scrolling to the bottom or top of
the listing with PageUp, PageDown, Up Arrow, Down Arrow and we should
be able to scroll past small areas of memory that don't have symbols
associated with them.  It should also be possible to scroll to the
start of a section even if there's no symbol at the start of the
section.

Adding tests for this scrolling was a little bit of a problem.  First
I would have liked to add tests for PageUp / PageDown, but the tuiterm
library we use doesn't support these commands right now due to only
emulating a basic ascii terminal.  Changing this to emulate a more
complex terminal would require adding support for more escape sequence
control codes, so I've not tried to tackle that in this patch.

Next, I would have liked to test scrolling to the start or end of the
assembler listing and then trying to scroll even more, however, this
is a problem because in a well behaving GDB a scroll at the start/end
has no effect.  What we need to do is:

  - Move to start of assembler listing,
  - Send scroll up command,
  - Wait for all curses output,
  - Ensure the assembler listing is unchanged, we're still at the
    start of the listing.

The problem is that there is no curses output, so how long do we wait
at step 3?  The same problem exists for scrolling to the bottom of the
assembler listing.  However, when scrolling down you can at least see
the end coming, so I added a test for this case, however, this feels
like an area of code that is massively under tested.

gdb/ChangeLog:

	PR tui/9765
	* minsyms.c (lookup_minimal_symbol_by_pc_section): Update header
	comment, add extra parameter, and update to store previous symbol
	when appropriate.
	* minsyms.h (lookup_minimal_symbol_by_pc_section): Update comment,
	add extra parameter.
	* tui/tui-disasm.c (tui_disassemble): Update header comment,
	remove unneeded parameter, add try/catch around gdb_print_insn,
	rewrite to add items to asm_lines vector.
	(tui_find_backward_disassembly_start_address): New function.
	(tui_find_disassembly_address): Updated throughout.
	(tui_disasm_window::set_contents): Update for changes to
	tui_disassemble.
	(tui_disasm_window::do_scroll_vertical): No need to adjust the
	number of lines to scroll.

gdb/testsuite/ChangeLog:

	PR tui/9765
	* gdb.tui/tui-layout-asm.exp: Add scrolling test for asm window.

Change-Id: I323987c8fd316962c937e73c17d952ccd3cfa66c
2020-01-24 00:10:33 +00:00
Tom Tromey 4f13c1c00b Make "file" clear TUI source window
I noticed that a plain "file" will leave the current source file in
the TUI source window.  Instead, I think, it should clear the source
window.  This patch implements this.

gdb/ChangeLog
2020-01-19  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_update_source_windows_with_line):
	Handle case where symtab is null.

gdb/testsuite/ChangeLog
2020-01-19  Tom Tromey  <tom@tromey.com>

	* gdb.tui/main.exp: Add check for plain "file".

Change-Id: I8424acf837f1a47f75bc6a833d1e917d4c10b51e
2020-01-19 13:08:48 -07:00
Christian Biesinger 40c9409927 Fix some spelling errors.
I noticed those from a lintian run:
https://salsa.debian.org/cbiesinger-guest/gdb/-/jobs/514119

gdb/ChangeLog:

2020-01-16  Christian Biesinger  <cbiesinger@google.com>

        * btrace.c (btrace_compute_ftrace_1): Fix spelling error (Unkown).
        (btrace_stitch_trace): Likewise.
        * charset.c (intermediate_encoding): Likewise (vaild).
        * nat/linux-btrace.c (linux_read_pt): Likewise (Unkown).
        * python/py-record-btrace.c (struct PyMethodDef): Likewise (occurences).
        * record-btrace.c (record_btrace_print_conf): Likewise (unkown).

gdb/testsuite/ChangeLog:

2020-01-16  Christian Biesinger  <cbiesinger@google.com>

        * lib/gdb.exp: Fix spelling error (seperatelly).

Change-Id: I2a44936bac295020f217fb6c78b99b0a8d09cf9a
2020-01-16 16:46:25 -06:00
Pedro Alves 701adfb009 [gdb] Move ChangeLog entries to their right files
I spotted a few misplaced entries in the ChangeLog-2019 entries, and
went on to fix them.

Looking around I saw a good number of other entries in other years.
Then OCD got the best of me and I fixed them all.

Also fixes cases of wrong paths in entries, like "* gdb/foo.c" instead
of "* foo.c".
2020-01-16 18:11:06 +00:00