Commit Graph

107510 Commits

Author SHA1 Message Date
Tom de Vries
0086a91cee [gdb/testsuite] Support -fPIE/-fno-PIE/-pie/-no-pie in gdb_compile_rust
When running gdb.rust/*.exp test-cases with target board unix/-fPIE/-pie, I
run into:
...
builtin_spawn -ignore SIGHUP rustc --color never gdb.rust/watch.rs \
  -g -lm -fPIE -pie -o outputs/gdb.rust/watch/watch^M
error: Unrecognized option: 'f'^M
^M
compiler exited with status 1
...

The problem is that -fPIE and -fpie are gcc options, but for rust we use
rustc, which has different compilation options.

Fix this by translating the gcc options to rustc options in gdb_compile_rust,
similar to how that is done for ada in target_compile_ada_from_dir.

Likewise for unix/-fno-PIE/-no-pie.

Tested on x86_64-linux, with:
- native
- unix/-fPIE/-pie
- unix/-fno-PIE/-no-pie
specifically, on openSUSE Leap 15.2 both with package gcc-PIE:
- installed (making gcc default to PIE)
- uninstalled (making gcc default to non-PIE).
and rustc 1.52.1.
2021-09-23 22:52:51 +02:00
Tom de Vries
6ef69a3ff3 [gdb/testsuite] Use pie instead of -fPIE -pie
Replace {additional_flags=-fPIE ldflags=-pie} with {pie}.

This makes sure that the test-cases properly error out when using target board
unix/-fno-PIE/-no-pie.

Tested on x86_64-linux.
2021-09-23 22:42:10 +02:00
Tom de Vries
508109612f [gdb/testsuite] Fix probe test in gdb.base/break-interp.exp
When running test-case gdb.base/break-interp.exp on ubuntu 18.04.5, we have:
...
 (gdb) bt^M
 #0  0x00007eff7ad5ae12 in ?? () from break-interp-LDprelinkNOdebugNO^M
 #1  0x00007eff7ad71f50 in ?? () from break-interp-LDprelinkNOdebugNO^M
 #2  0x00007eff7ad59128 in ?? () from break-interp-LDprelinkNOdebugNO^M
 #3  0x00007eff7ad58098 in ?? () from break-interp-LDprelinkNOdebugNO^M
 #4  0x0000000000000002 in ?? ()^M
 #5  0x00007fff505d7a32 in ?? ()^M
 #6  0x00007fff505d7a94 in ?? ()^M
 #7  0x0000000000000000 in ?? ()^M
 (gdb) FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: \
         first backtrace: dl bt
...

Using the backtrace, the test-case tries to establish that we're stopped in
dl_main.

However, the backtrace only shows an address, because:
- the dynamic linker contains no minimal symbols and no debug info, and
- gdb is build without --with-separate-debug-dir so it can't find the
  corresponding .debug file, which does contain the mimimal symbols and
  debug info.

As in "[gdb/testsuite] Improve probe detection in gdb.base/break-probes.exp",
fix this by doing info probes and grepping for the address.

Tested on x86_64-linux.
2021-09-23 22:42:10 +02:00
Tom de Vries
d264c39e8b [gdb/testsuite] Improve probe detection in gdb.base/break-probes.exp
When running test-case gdb.base/break-probes.exp on ubuntu 18.04.5, we have:
...
 (gdb) run^M
 Starting program: break-probes^M
 Stopped due to shared library event (no libraries added or removed)^M
 (gdb) bt^M
 #0  0x00007ffff7dd6e12 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #1  0x00007ffff7dedf50 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #2  0x00007ffff7dd5128 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #3  0x00007ffff7dd4098 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #4  0x0000000000000001 in ?? ()^M
 #5  0x00007fffffffdaac in ?? ()^M
 #6  0x0000000000000000 in ?? ()^M
 (gdb) UNSUPPORTED: gdb.base/break-probes.exp: probes not present on this system
...

Using the backtrace, the test-case tries to establish that we're stopped in
dl_main, which is used as proof that we're using probes.

However, the backtrace only shows an address, because:
- the dynamic linker contains no minimal symbols and no debug info, and
- gdb is build without --with-separate-debug-dir so it can't find the
  corresponding .debug file, which does contain the mimimal symbols and
  debug info.

Fix this by instead printing the pc and grepping for the value in the
info probes output:
...
(gdb) p /x $pc^M
$1 = 0x7ffff7dd6e12^M
(gdb) info probes^M
Type Provider Name           Where              Object                      ^M
  ...
stap rtld     init_start     0x00007ffff7dd6e12 /lib64/ld-linux-x86-64.so.2 ^M
  ...
(gdb)
...

Tested on x86_64-linux.
2021-09-23 22:42:10 +02:00
Tom de Vries
108e60844c [gdb/testsuite] Handle failing probe detection in gdb.base/break-probes.exp
When running test-case gdb.base/break-probes.exp on ubuntu 18.04.5, we have:
...
 (gdb) bt^M
 #0  0x00007ffff7dd6e12 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #1  0x00007ffff7dedf50 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #2  0x00007ffff7dd5128 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #3  0x00007ffff7dd4098 in ?? () from /lib64/ld-linux-x86-64.so.2^M
 #4  0x0000000000000001 in ?? ()^M
 #5  0x00007fffffffdaac in ?? ()^M
 #6  0x0000000000000000 in ?? ()^M
 (gdb) FAIL: gdb.base/break-probes.exp: ensure using probes
...

The test-case intends to emit an UNTESTED in this case, but fails to do so
because it tries to do it in a regexp clause in a gdb_test_multiple, which
doesn't trigger.  Instead, a default clause triggers which produces the FAIL.

Also the use of UNTESTED is not appropriate, and we should use UNSUPPORTED
instead.

Fix this by silencing the FAIL, and emitting an UNSUPPORTED after the
gdb_test_multiple:
...
 if { ! $using_probes } {
+    unsupported "probes not present on this system"
     return -1
 }
...

Tested on x86_64-linux.
2021-09-23 22:42:10 +02:00
Tom de Vries
04739cc7ce [gdb/testsuite] Use early-out style in gdb.base/break-probes.exp
Reduce indentation and improve readability in test-case
gdb.base/break-probes.exp by replacing:
...
if { <cond> } {
  <lots-of-code>
}
...
with:
...
if { ! <cond> } {
  return -1
}
<lots-of-code>
...

Tested on x86_64-linux.
2021-09-23 22:42:10 +02:00
Pedro Alves
9b8efa2cd1 Test that frame info/IDs are stable/consistent
This adds a testcase that tests that the unwinder produces consistent
frame info and frame IDs by making sure that "info frame" shows the
same result when stopped at a function (level == 0), compared to when
we find the same frame in the stack at a level > 0.

E.g., on x86-64, right after running to main, we see:

  (gdb) info frame
  Stack level 0, frame at 0x7fffffffd340:
   rip = 0x555555555168 in main (gdb.base/backtrace.c:41); saved rip = 0x7ffff7dd90b3
   source language c.
   Arglist at 0x7fffffffd330, args:
   Locals at 0x7fffffffd330, Previous frame's sp is 0x7fffffffd340
   Saved registers:
    rbp at 0x7fffffffd330, rip at 0x7fffffffd338
  (gdb)

and then after continuing to a function called by main, and selecting
the "main" frame again, we see:

  (gdb) info frame
  Stack level 3, frame at 0x7fffffffd340:
   rip = 0x555555555172 in main (gdb.base/backtrace.c:41); saved rip = 0x7ffff7dd90b3
   caller of frame at 0x7fffffffd330
   source language c.
   Arglist at 0x7fffffffd330, args:
   Locals at 0x7fffffffd330, Previous frame's sp is 0x7fffffffd340
   Saved registers:
    rbp at 0x7fffffffd330, rip at 0x7fffffffd338
  (gdb)

The only differences should be in the stack level, the 'rip = '
address, and the presence of the "caller of frame at" info.  All the
rest should be the same.  If it isn't, it probably means that the
frame base, the frame ID, etc. aren't stable & consistent.

The testcase exercises both the DWARF and the heuristic unwinders,
using "maint set dwarf unwinder on/off".

Tested on {x86-64 -m64, x86-64 -m32, Aarch64, Power8} GNU/Linux.

Change-Id: I795001c82cc70d543d197415e3f80ce5dc7f3452
2021-09-23 18:58:51 +01:00
Tom Tromey
c80e29dba9 Change get_ada_task_ptid parameter type
get_ada_task_ptid currently takes a 'long' as its 'thread' parameter
type.  However, on some platforms this is actually a pointer, and
using 'long' can sometimes end up with the value being sign-extended.
This sign extension can cause problems later, if the tid is then later
used as an address again.

This patch changes the parameter type to ULONGEST and updates all the
uses.  This approach preserves sign extension on the targets where it
is apparently intended, while avoiding it on others.

Co-Authored-By: John Baldwin <jhb@FreeBSD.org>
2021-09-23 09:30:54 -06:00
Tom Tromey
96bbe3ef96 Change ptid_t::tid to ULONGEST
The ptid_t 'tid' member is normally used as an address in gdb -- both
bsd-uthread and ravenscar-thread use it this way.  However, because
the type is 'long', this can cause problems with sign extension.

This patch changes the type to ULONGEST to ensure that sign extension
does not occur.
2021-09-23 09:30:54 -06:00
Tom Tromey
184ea2f731 Remove defaulted 'tid' parameter to ptid_t constructor
I wanted to find, and potentially modify, all the spots where the
'tid' parameter to the ptid_t constructor was used.  So, I temporarily
removed this parameter and then rebuilt.

In order to make it simpler to search through the "real" (nonzero)
uses of this parameter, something I knew I'd have to do multiple
times, I removed any ", 0" from constructor calls.

Co-Authored-By: John Baldwin <jhb@FreeBSD.org>
2021-09-23 09:30:54 -06:00
Tom Tromey
334381ea46 Style the "XXX" text in ptype/o
This patch changes gdb to use the 'highlight' style on the "XXX" text
in the output of ptype/o.
2021-09-23 09:19:56 -06:00
GDB Administrator
ae9150ce9e Automatic date update in version.in 2021-09-23 00:00:07 +00:00
Tom de Vries
378f6478ce [gdb/testsuite] Fix gdb.python/py-events.exp
With test-case gdb.python/py-events.exp on ubuntu 18.04.5 we run into:
...
(gdb) info threads^M
  Id   Target Id                                     Frame ^M
* 1    Thread 0x7ffff7fc3740 (LWP 31467) "py-events" do_nothing () at \
         src/gdb/testsuite/gdb.python/py-events-shlib.c:19^M
(gdb) FAIL: gdb.python/py-events.exp: get current thread
...

The info thread commands uses "Thread" instead of "process" because
libpthread is already loaded:
...
new objfile name: /lib/x86_64-linux-gnu/libdl.so.2^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".^M
event type: new_objfile^M
new objfile name: /lib/x86_64-linux-gnu/libpthread.so.0^M
...
and consequently thread_db_target::pid_to_str is used.

Fix this by parsing the "Thread" expression.

Tested on x86_64-linux.
2021-09-22 14:11:09 +02:00
Tom de Vries
479209dd4f [gdb] Add maint selftest -verbose option
The print_one_insn selftest in gdb/disasm-selftests.c contains:
...
  /* If you want to see the disassembled instruction printed to gdb_stdout,
     set verbose to true.  */
  static const bool verbose = false;
...

Make this parameter available in the maint selftest command using a new option
-verbose, such that we can do:
...
(gdb) maint selftest -verbose print_one_insn
...

Tested on x86_64-linux.
2021-09-22 11:47:50 +02:00
Alan Modra
cf11ebea12 dwarf2 sub-section test
This is a testcase for the bug fixed by commit 5b4846283c.  When
running the testcase on ia64 targets I found timeouts along with lots
of memory being consumed, due to ia64 gas not tracking text
sub-sections.  Trying to add nops for ".nop 16" in ".text 1" resulting
in them being added to subsegment 0, with no increase to subsegment 1
size.  This patch also fixes that problem.

Note that the testcase fails on ft32-elf, mn10200-elf, score-elf,
tic5x-elf, and xtensa-elf.  The first two are relocation errors, the
last three appear to be the .nop directive failing to emit the right
number of nops.  I didn't XFAIL any of them.

	* config/tc-ia64.c (md): Add last_text_subseg.
	(ia64_flush_insns, dot_endp): Use last_text_subseg.
	(ia64_frob_label, md_assemble): Set last_text_subseg.
	* testsuite/gas/elf/dwarf2-21.d,
	* testsuite/gas/elf/dwarf2-21.s: New test.
	* testsuite/gas/elf/elf.exp: Run it.
2021-09-22 10:24:05 +09:30
Alan Modra
ed41b9cdb2 Fix x86 "FAIL: TLS -fno-pic -shared"
Fix a typo in commit 5d0869d987

	* testsuite/ld-i386/tlsnopic.rd: Typo fix.
2021-09-22 10:24:05 +09:30
GDB Administrator
5d0869d987 Automatic date update in version.in 2021-09-22 00:00:07 +00:00
Nick Clifton
5226a6a892 Change the linker's heuristic for computing the entry point for binaries so that shared libraries default to an entry point of 0.
* ldlang.c (lang_end): When computing the entry point, only
	try the start address of the entry section when creating an
	executable.
	* ld.texi (Entry point): Update description of heuristic used to
	choose the entry point.
	testsuite/ld-alpha/tlspic.rd: Update expected entry point address.
	testsuite/ld-arm/tls-gdesc-got.d: Likewise.
	testsuite/ld-i386/tlsnopic.rd: Likewise.
	testsuite/ld-ia64/tlspic.rd: Likewise.
	testsuite/ld-sparc/gotop32.rd: Likewise.
	testsuite/ld-sparc/gotop64.rd: Likewise.
	testsuite/ld-sparc/tlssunnopic32.rd: Likewise.
	testsuite/ld-sparc/tlssunnopic64.rd: Likewise.
	testsuite/ld-sparc/tlssunpic32.rd: Likewise.
	testsuite/ld-sparc/tlssunpic64.rd: Likewise.
	testsuite/ld-tic6x/shlib-1.rd: Likewise.
	testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	testsuite/ld-x86-64/pr14207.d: Likewise.
	testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	testsuite/ld-x86-64/tlspic.rd: Likewise.
	testsuite/ld-x86-64/tlspic2.rd: Likewise.
2021-09-21 13:21:41 +01:00
Tom de Vries
5335ab6872 [gdb/testsuite] Handle supports_memtag in gdb.base/gdb-caching-proc.exp
In test-case gdb.base/gdb-caching-proc.exp, we run all procs declared with
gdb_caching_proc.  Some of these require a gdb instance, some not.

We could just do a clean_restart every time, but that would amount to 44 gdb
restarts.  We try to minimize this by doing this only for the few procs that
need it, and hardcoding those in the test-case.

For those procs, we do a clean_restart, execute the proc, and then do a
gdb_exit, to make sure the gdb instance doesn't linger such that we detect
procs that need a gdb instance but are not listed in the test-case.

However, that doesn't work in the case of gnat_runtime_has_debug_info.  This
proc doesn't require a gdb instance because it starts its own.  But it doesn't
clean up the gdb instance, and since it's not listed, the test-case
doesn't clean up the gdb instance eiter.  Consequently, the proc
supports_memtag (which should be listed, but isn't) uses the gdb instance
started by gnat_runtime_has_debug_info rather than throwing an error.  Well,
unless gnat_runtime_has_debug_info fails before starting a gdb instance, in
which case we do run into the error.

Fix this by:
- doing gdb_exit unconditionally
- fixing the resulting error by adding supports_memtag in the test-case to
  the "needing gdb instance" list

Tested on x86_64-linux.
2021-09-21 12:06:35 +02:00
Felix Willgerodt
be24dba6f1 gdb, doc: Add ieee_half and bfloat16 to list of predefined target types.
For some reason these two weren't added to the list when they were orginally
added to GDB.

gdb/doc/ChangeLog:
2021-09-21  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.texinfo (Predefined Target Types): Mention ieee_half and bfloat16.
2021-09-21 10:14:36 +02:00
GDB Administrator
01723a3503 Automatic date update in version.in 2021-09-21 00:00:08 +00:00
Tom de Vries
5936ac73ed [gdb/testsuite] Fix gdb.ada/interface.exp with gcc-9
When running test-case gdb.ada/interface.exp with gcc-9, we run into:
...
(gdb) info locals^M
s = (x => 1, y => 2, w => 3, h => 4)^M
r = (x => 1, y => 2, w => 3, h => 4)^M
(gdb) FAIL: gdb.ada/interface.exp: info locals
...

The failure is caused by the regexp expecting variable r followed by
variable s.

Fix this by allowing variable s followed by variable r as well.

Tested on x86_64-linux.
2021-09-21 00:54:08 +02:00
Tom de Vries
acb7bdf0d2 [gdb/testsuite] Fix gdb.ada/mi_prot.exp
When running test-case gdb.ada/mi_prot.exp with gcc 8.5.0, we run into:
...
(gdb) ^M
Expecting: ^(-stack-list-arguments --no-frame-filters 1[^M
]+)?(\^done,stack=.*[^M
]+[(]gdb[)] ^M
[ ]*)
-stack-list-arguments --no-frame-filters 1^M
^done,stack-args=[frame={level="0",args=[{name="<_object>",value="(ceiling_priority =\
> 97, local => 0)"},{name="v",value="5"},{name="<_objectO>",value="true"}]},frame={le\
vel="1",args=[{name="v",value="5"},{name="<_objectO>",value="true"}]},frame={level="2\
",args=[]}]^M
(gdb) ^M
FAIL: gdb.ada/mi_prot.exp: -stack-list-arguments --no-frame-filters 1 (unexpected out\
put)
...

Fix this by updating the regexp to expect "^done,stack-args=" instead of
"^done,stack=".

Tested on x86_64-linux.
2021-09-21 00:41:26 +02:00
Tom de Vries
ff1c1bb9be [gdb/testsuite] Register test for each arch separately in register_test_foreach_arch
In gdb/disasm-selftests.c we have:
...
  selftests::register_test_foreach_arch ("print_one_insn",
                                         selftests::print_one_insn_test);
...
and we get:
...
$ gdb -q -batch -ex "maint selftest print_one_insn" 2>&1 \
  | grep ^Running
Running selftest print_one_insn.
$
...

Change the semantics register_test_foreach_arch such that a version of
print_one_insn is registered for each architecture, such that we have:
...
$ gdb -q -batch -ex "maint selftest print_one_insn" 2>&1 \
  | grep ^Running
Running selftest print_one_insn::A6.
Running selftest print_one_insn::A7.
Running selftest print_one_insn::ARC600.
  ...
$
...

This makes it f.i. possible to do:
...
$ gdb -q -batch a.out -ex "maint selftest print_one_insn::armv8.1-m.main"
Running selftest print_one_insn::armv8.1-m.main.
Self test failed: self-test failed at src/gdb/disasm-selftests.c:165
Ran 1 unit tests, 1 failed
...

Tested on x86_64-linux with an --enable-targets=all build.
2021-09-21 00:41:26 +02:00
Tom de Vries
c45a683f8f [gdb] Change register_test to use std::function arg
Change register_test to use std::function arg, such that we can do:
...
  register_test (test_name, [=] () { SELF_CHECK (...); });
...

Tested on x86_64-linux.
2021-09-21 00:41:26 +02:00
Tom de Vries
6f265beb28 [gdb/testsuite] Fix gdb.ada/big_packed_array.exp xfail for -m32
With test-case gdb.ada/big_packed_array.exp and target board unix/-m32 I run
into:
...
(gdb) print bad^M
$2 = (0 => 0 <repeats 24 times>, 160)^M
(gdb) FAIL: gdb.ada/big_packed_array.exp: scenario=minimal: print bad
...

The problem is that while the variable is an array of 196 bits (== 24.5 bytes),
the debug information describes it as 25 unsigned char.  This is PR
gcc/101643, and the test-case contains an xfail for this, which catches only:
...
(gdb) print bad^M
$2 = (0 => 0 <repeats 25 times>)^M
...

Fix this by updating the xfail pattern.

Tested on x86_64-linux.
2021-09-20 15:07:57 +02:00
Simon Marchi
56d9e3c562 gdbsupport/gdb_proc_service.h: use decltype instead of typeof
Bug 28341 shows that GDB fails to compile when built with -std=c++11.
I don't know much about the use case, but according to the author of the
bug:

    I encountered the scenario where CXX is set to "g++ -std=c++11" when
    I try to compile binutils under GCC as part of the GCC 3-stage
    compilation, which is common for building a cross-compiler.

The author of the bug suggests using __typeof__ instead of typeof.  But
since we're using C++, we might as well use decltype, which is standard.
This is what this patch does.

The failure (and fix) can be observed by configuring GDB with CXX="g++
-std=c++11":

      CXX    linux-low.o
    In file included from /home/simark/src/binutils-gdb/gdbserver/gdb_proc_service.h:22,
		     from /home/simark/src/binutils-gdb/gdbserver/linux-low.h:27,
		     from /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:20:
    /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:177:50: error: expected constructor, destructor, or type conversion before (token
      177 |   __attribute__((visibility ("default"))) typeof (SYM) SYM
	  |                                                  ^
    /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:179:1: note: in expansion of macro PS_EXPORT
      179 | PS_EXPORT (ps_get_thread_area);
	  | ^~~~~~~~~

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28341
Change-Id: I84fbaae938209d8d935ca08dec9b7e6a0dd1bda0
2021-09-20 07:59:53 -04:00
Andrew Burgess
6a7f57668a riscv: print .2byte or .4byte before an unknown instruction encoding
When the RISC-V disassembler encounters an unknown instruction, it
currently just prints the value of the bytes, like this:

  Dump of assembler code for function custom_insn:
     0x00010132 <+0>:	addi	sp,sp,-16
     0x00010134 <+2>:	sw	s0,12(sp)
     0x00010136 <+4>:	addi	s0,sp,16
     0x00010138 <+6>:	0x52018b
     0x0001013c <+10>:	0x9c45

My proposal, in this patch, is to change the behaviour to this:

  Dump of assembler code for function custom_insn:
     0x00010132 <+0>:	addi	sp,sp,-16
     0x00010134 <+2>:	sw	s0,12(sp)
     0x00010136 <+4>:	addi	s0,sp,16
     0x00010138 <+6>:	.4byte	0x52018b
     0x0001013c <+10>:	.2byte	0x9c45

Adding the .4byte and .2byte opcodes.  The benefit that I see here is
that in the patched version of the tools, the disassembler output can
be fed back into the assembler and it should assemble to the same
binary format.  Before the patch, the disassembler output is invalid
assembly.

I've started a RISC-V specific test file under binutils so that I can
add a test for this change.

binutils/ChangeLog:

	* testsuite/binutils-all/riscv/riscv.exp: New file.
	* testsuite/binutils-all/riscv/unknown.d: New file.
	* testsuite/binutils-all/riscv/unknown.s: New file.

opcodes/ChangeLog:

	* riscv-dis.c (riscv_disassemble_insn): Print a .%dbyte opcode
	before an unknown instruction, '%d' is replaced with the
	instruction length.
2021-09-20 09:45:34 +01:00
Alan Modra
d467335403 Fix allocate_filenum last dir/file checks
* dwarf2dbg.c (allocate_filenum) Correct use of last_used_dir_len.
2021-09-20 14:01:11 +09:30
Alan Modra
5b4846283c Re: PR28149, debug info with wrong file association
Fixes segfaults when building aarch64-linux kernel, due to only doing
part of the work necessary when allocating file numbers late.  I'd
missed looping over subsegments, which resulted in some u.filename
entries left around and later interpreted as u.view.

	PR 28149
	* dwarf2dbg.c (purge_generated_debug): Iterate over subsegs too.
	(dwarf2_finish): Call do_allocate_filenum for all subsegs too,
	in a separate loop before subsegs are chained.
2021-09-20 11:38:55 +09:30
Alan Modra
8ac439689f Move eelf_mipsel_haiki.c to ALL_64_EMULATION_SOURCES
--enable-targets=all on a 32-bit host results in a link failure with
undefined references due to elfxx-mips.c not being compiled.  This
patch fixes that by putting eelf_mipsel_haiki.c in the correct
EMULATION_SOURCES Makefile variable.  I've also added a bunch of
missing file dependencies and sorted a few things so that it's easier
to verify dependencies are present.

	* Makfile.am: Add missing haiku dependencies, sort.
	(ALL_EMULATION_SOURCES): Sort.  Move eelf_mipsel_haiku.c to..
	(ALL_64_EMULATION_SOURCES): ..here.  Sort.
	* Makfile.in: Regenerate.
2021-09-20 11:38:55 +09:30
GDB Administrator
1e071750a2 Automatic date update in version.in 2021-09-20 00:00:06 +00:00
H.J. Lu
e4675a5810 elf: Don't set version info on unversioned symbols
Don't set version info on unversioned symbols when seeing a hidden
versioned symbol after an unversioned definition and the default
versioned symbol.

bfd/

	PR ld/28348
	* elflink.c (elf_link_add_object_symbols): Don't set version info
	on unversioned symbols.

ld/

	PR ld/28348
	* testsuite/ld-elf/pr28348.rd: New file.
	* testsuite/ld-elf/pr28348.t: Likewise.
	* testsuite/ld-elf/pr28348a.c: Likewise.
	* testsuite/ld-elf/pr28348b.c: Likewise.
	* testsuite/ld-elf/pr28348c.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run PR ld/28348 tests.
2021-09-19 07:19:39 -07:00
Mike Frysinger
034ce7b42a gdb: manual: update @inforef to @xref
The @inforef command is deprecated, and @xref does the samething.
Also had to update the text capitalization to match current manual.
Verified that info & HTML links work.
2021-09-19 02:20:34 -04:00
Weimin Pan
ffb3f58793 CTF: multi-CU and archive support
Now gdb is capable of debugging executable, which consists of multiple
compilation units (CUs) with the CTF debug info. An executable could
potentially have one or more archives, which, in CTF context, contain
conflicting types.

all changes were made in ctfread.c in which elfctf_build_psymtabs was
modified to handle archives, via the ctf archive iterator and its callback
build_ctf_archive_member and scan_partial_symbols was modified to scan
archives, which are treated as subfiles, to build the psymtabs.

Also changes were made to handle CTF's data object section and function
info section which now share the same format of their contents - an array
of type IDs. New functions ctf_psymtab_add_stt_entries, which is called by
ctf_psymtab_add_stt_obj and ctf_psymtab_add_stt_func, and add_stt_entries,
which is called by add_stt_obj and add_stt_func when setting up psymtabs
and full symtab, respectively.
2021-09-18 20:41:29 -04:00
GDB Administrator
3733650765 Automatic date update in version.in 2021-09-19 00:00:07 +00:00
Tom de Vries
acedf59370 [gdb/testsuite] Fix gdb.server/server-kill.exp with -m32
When running test-case gdb.server/server-kill.exp with target board unix/-m32,
I run into:
...
0xf7fd6b20 in _start () from /lib/ld-linux.so.2^M
(gdb) Executing on target: kill -9 13082    (timeout = 300)
builtin_spawn -ignore SIGHUP kill -9 13082^M
bt^M
(gdb) FAIL: gdb.server/server-kill.exp: kill_pid_of=server: test_unwind_syms: bt
...

The test-case expects the backtrace command to trigger remote communication,
which then should result in a "Remote connection closed" or similar.

However, no remote communication is triggered, because we hit the "Check that
this frame is unwindable" case in get_prev_frame_always_1.

We don't hit this problem in the kill_pid_of=inferior case, because there we
run to main before doing the backtrace.

Fix this by doing the same in the kill_pid_of=server case.

Tested on x86_64-linux.
2021-09-18 17:19:06 +02:00
Tom de Vries
2c71f639a0 [gdb/ada] Handle artificial local symbols
With current master and gcc 7.5.0/8.5.0, we have this timeout:
...
(gdb) print s^M
Multiple matches for s^M
[0] cancel^M
[1] s at src/gdb/testsuite/gdb.ada/interface/foo.adb:20^M
[2] s at src/gdb/testsuite/gdb.ada/interface/foo.adb:?^M
> FAIL: gdb.ada/interface.exp: print s (timeout)
...

[ The FAIL doesn't reproduce with gcc 9.3.1.  This difference in
behaviour bisects to gcc commit d70ba0c10de.

The FAIL with earlier gcc bisects to gdb commit ba8694b650. ]

The FAIL is caused by gcc generating this debug info describing a named
artificial variable:
...
 <2><1204>: Abbrev Number: 31 (DW_TAG_variable)
    <1205>   DW_AT_name        : s.14
    <1209>   DW_AT_type        : <0x1213>
    <120d>   DW_AT_artificial  : 1
    <120d>   DW_AT_location    : 5 byte block: 91 e0 7d 23 18   \
      (DW_OP_fbreg: -288; DW_OP_plus_uconst: 24)
...

An easy way to fix this would be to simply not put named artificial variables
into the symbol table.  However, that causes regressions for Ada.  It relies
on being able to get the value from such variables, using a named reference.

Fix this instead by marking the symbol as artificial, and:
- ignoring such symbols in ada_resolve_variable, which fixes the FAIL
- ignoring such ada symbols in do_print_variable_and_value, which prevents
  them from showing up in "info locals"

Note that a fix for the latter was submitted here (
https://sourceware.org/pipermail/gdb-patches/2008-January/054994.html ), and
this patch borrows from it.

Tested on x86_64-linux.

Co-Authored-By: Joel Brobecker  <brobecker@adacore.com>

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28180
2021-09-18 09:25:49 +02:00
GDB Administrator
10c21d953d Automatic date update in version.in 2021-09-18 00:00:08 +00:00
Alan Modra
ef9768e37e PR28149 part 2, purge generated line info
Mixing compiler generated line info with gas generated line info is
generally just confusing.  Also .loc directives with non-zero view
fields might reference a previous .loc.  It becomes a little more
tricky to locate that previous .loc if there might be gas generated
line info present too.  Mind you, we turn off gas generation of line
info on seeing compiler generated line info, so any reference back
won't hit gas generated line info.  At least, if the view info is
sane.  Unfortunately, gas needs to handle mangled source.

	PR 28149
	* dwarf2dbg.c (purge_generated_debug): New function.
	(dwarf2_directive_filename): Call the above.
	(out_debug_line): Don't segfault after purging.
	* testsuite/gas/i386/dwarf2-line-4.d: Update expected output.
	* testsuite/gas/i386/dwarf4-line-1.d: Likewise.
	* testsuite/gas/i386/dwarf5-line-1.d: Likewise.
	* testsuite/gas/i386/dwarf5-line-2.d: Likewise.
2021-09-18 08:20:11 +09:30
Alan Modra
51298b3303 PR28149, debug info with wrong file association
gcc-11 and gcc-12 pass -gdwarf-5 to gas, in order to prime gas for
DWARF 5 level debug info.  Unfortunately it seems there are cases
where the compiler does not emit a .file or .loc dwarf debug directive
before any machine instructions.  (Note that the .file directive
typically emitted as the first line of assembly output doesn't count as
a dwarf debug directive.  The dwarf .file has a file number before the
file name string.)

This patch delays allocation of file numbers for gas generated line
debug info until the end of assembly, thus avoiding any clashes with
compiler generated file numbers.  Two fixes for test case source are
necessary;  A .loc can't use a file number that hasn't already been
specified with .file.

A followup patch will remove all the gas generated line info on
seeing a .file directive.

	PR 28149
	* dwarf2dbg.c (num_of_auto_assigned): Delete.
	(current): Update initialisation.
	(set_or_check_view): Replace all accesses to view with u.view.
	(dwarf2_consume_line_info): Likewise.
	(dwarf2_directive_loc): Likewise.  Assert that we aren't generating
	line info.
	(dwarf2_gen_line_info_1): Don't call set_or_check_view on
	gas generated line entries.
	(dwarf2_gen_line_info): Set and track filenames for gas generated
	line entries.  Simplify generation of labels.
	(get_directory_table_entry): Use filename_cmp when comparing dirs.
	(do_allocate_filenum): New function.
	(dwarf2_where): Set u.filename and filenum to -1 for gas generated
	line entries.
	(dwarf2_directive_filename): Remove num_of_auto_assigned handling.
	(process_entries): Update view field access.  Call
	do_allocate_filenum.
	* dwarf2dbg.h (struct dwarf2_line_info): Add filename field in
	union aliasing view.
	* testsuite/gas/i386/dwarf2-line-3.s: Add .file directive.
	* testsuite/gas/i386/dwarf2-line-4.s: Likewise.
	* testsuite/gas/i386/dwarf2-line-4.d: Update expected output.
	* testsuite/gas/i386/dwarf4-line-1.d: Likewise.
	* testsuite/gas/i386/dwarf5-line-1.d: Likewise.
	* testsuite/gas/i386/dwarf5-line-2.d: Likewise.
2021-09-18 08:20:11 +09:30
Alan Modra
5cdb4f1442 [GOLD] PowerPC64 support for sym+addend GOT entries
Pass addends to all the GOT handling functions, plus remove some
extraneous asserts.

	PR 28192
	* powerpc.cc (Output_data_got_powerpc): Add addend parameter to
	all methods creating got entries.
	(Target_powerpc::Scan::local): Pass reloc addend to got handling
	functions, and when creating dynamic got relocations.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Likewise.  Remove extraneous
	assertions.
2021-09-18 08:20:11 +09:30
Alan Modra
e4d49a0f90 [GOLD] Got_entry::write addends
This takes care of writing out GOT entries with addends.  The local
symbol case was already largely handled, except for passing the addend
to tls_offset_for_local which might need the addend in a
local_got_offset call.  That's needed also in tls_offset_for_global.

I'm assuming here that GOT entries for function symbols won't ever
have addends, and in particular that a GOT entry referencing PLT call
stub code won't want an offset into the code.

	PR 28192
	* output.cc (Output_data_got::Got_entry::write): Include addend
	in global symbol value.  Pass addend to tls_offset_for_*.
	* powerpc.cc (Target_powerpc::do_tls_offset_for_local): Handle addend.
	(Target_powerpc::do_tls_offset_for_global): Likewise.
	* s390.cc (Target_s390::do_tls_offset_for_local): Likewise.
	(Target_s390::do_tls_offset_for_global): Likewise.
	* target.h (Target::tls_offset_for_local): Add addend param.
	(Target::tls_offset_for_global): Likewise.
	(Target::do_tls_offset_for_local): Likewise.
	(Target::do_tls_offset_for_global): Likewise.
2021-09-18 08:20:11 +09:30
Alan Modra
2cc9ed14fa [GOLD] Output_data_got create entry method addends
This patch makes all the Output_data_got methods that create new
entries accept an optional addend.

	PR 28192
	* output.h (Output_data_got::add_global): Add optional addend
	parameter.  Update comment.  Delete overload without addend.
	(Output_data_got::add_global_plt): Likewise.
	(Output_data_got::add_global_tls): Likewise.
	(Output_data_got::add_global_with_rel): Likewise.
	(Output_data_got::add_global_pair_with_rel): Likewise.
	(Output_data_got::add_local_plt): Likewise.
	(Output_data_got::add_local_tls): Likewise.
	(Output_data_got::add_local_tls_pair): Likewise.
	(Output_data_got::reserve_local): Likewise.
	(Output_data_got::reserve_global): Likewise.
	(Output_data_got::Got_entry): Include addend in global sym
	constructor.  Delete local sym constructor without addend.
	* output.cc (Output_data_got::add_global): Add addend param,
	pass to got handling methods.
	(Output_data_got::add_global_plt): Likewise.
	(Output_data_got::add_global_with_rel): Likewise.
	(Output_data_got::add_global_pair_with_rel): Likewise.
	(Output_data_got::add_local_plt): Likewise.
	(Output_data_got::add_local_tls_pair): Likewise.
	(Output_data_got::reserve_local): Likewise.
	(Output_data_got::reserve_global): Likewise.
2021-09-18 08:20:11 +09:30
Alan Modra
54721a930e [GOLD] Output_data_got tidy
Some Output_data_got methods already have support for addends, but
were implemented as separate methods.  This removes unnecessary code
duplication.

Relobj::local_has_got_offset and others there get a similar treatment.
Comments are removed since it should be obvious without a comment, and
the existing comments are not precisely what the code does.  For
example, a local_has_got_offset call without an addend does not return
whether the local symbol has *a* GOT offset of type GOT_TYPE, it
returns whether there is a GOT entry of type GOT_TYPE for the symbol
with addend of zero.

	PR 28192
	* output.h (Output_data_got::add_local): Make addend optional.
	(Output_data_got::add_local_with_rel): Likewise.
	(Output_data_got::add_local_pair_with_rel): Likewise.
	* output.cc (Output_data_got::add_local): Delete overload
	without addend.
	(Output_data_got::add_local_with_rel): Likewise.
	(Output_data_got::add_local_pair_with_rel): Likewise.
	* object.h (Relobj::local_has_got_offset): Make addend optional.
	Delete overload without addend later.  Update comment.
	(Relobj::local_got_offset): Likewise.
	(Relobj::set_local_got_offset): Likewise.
2021-09-18 08:20:11 +09:30
Alan Modra
973b2b402e [GOLD] Remove addend from Local_got_entry_key
This patch removes the addend from Local_got_entry_key, which is
unnecessary now that Got_offset_list has an addend.  Note that it
might be advantageous to keep the addend in Local_got_entry_key when
linking objects containing a large number of section_sym+addend@got
relocations.  I opted to save some memory by removing the field but
left the class there in case we might need to restore {sym,addend}
lookup.  That's also why this change is split out from the
Got_offset_list change.

	PR 28192
	* object.h (Local_got_entry_key): Delete addend_ field.
	Adjust constructor and methods to suit.
	* object.cc (Sized_relobj::do_for_all_local_got_entries):
	Update key.
2021-09-18 08:20:11 +09:30
Alan Modra
912697efc1 [GOLD] Got_offset_list: addend field
This is the first in a series of patches aimed at supporting GOT
entries against symbol plus addend generally for PowerPC64 rather than
just section symbol plus addend as gold has currently.

This patch adds an addend field to Got_offset_list, so that both local
and global symbols can have GOT entries with addend.

	PR 28192
	* object.h (Got_offset_list): Add addend_ field, init in both
	constructors.  Adjust all accessors to suit.
	(Sized_relobj::do_local_has_got_offset): Adjust to suit.
	(Sized_relobj::do_local_got_offset): Likewise.
	(Sized_relobj::do_set_local_got_offset): Likewise.
	* symtab.h (Symbol::has_got_offset): Add optional addend param.
	(Symbol::got_offset, Symbol::set_got_offset): Likewise.
	* incremental.cc (Local_got_offset_visitor::visit): Add unused
	uint64_t parameter with FIXME.
	(Global_got_offset_visitor::visit): Add unused uint64_t parameter.
2021-09-18 08:20:11 +09:30
Henry Castro
6bc2c6ee80 Fix segfault when running ia16-elf-gdb
"A problem internal to GDB has been detected,
further debugging may prove unreliable."

Segmentation fault
2021-09-17 13:36:51 -06:00
Nelson Chu
c9f2799101 RISC-V: Merged extension string tables and their version tables into one.
There are two main reasons for this patch,

* In the past we had two extension tables, one is used to record all
supported extensions in bfd/elfxx-riscv.c, another is used to get the
default extension versions in gas/config/tc-riscv.c.  It is hard to
maintain lots of tables in different files, but in fact we can merge
them into just one table.  Therefore, we now define many riscv_supported_std*
tables, which record names and versions for all supported extensions.
We not only use these tables to initialize the riscv_ext_order, but
also use them to get the default versions of extensions, and decide if
the extensions should be enbaled by default.

* We add a new filed `default_enable' for the riscv_supported_std* tables,
to decide if the extension should be enabled by default.  For now if the
`default_enable' field of the extension is set to EXT_DEFAULT, then we
should enable the extension when the -march and elf architecture attributes
are not set.  In the future, I suppose the `default_enable' can be set
to lots of EXT_<VENDOR>, each vendor can decide to open which extensions,
when the target triple of vendor is chosen.

The elf/linux regression tests of riscv-gnu-toolchain are passed.

bfd/
	* elfnn-riscv.c (cpu-riscv.h): Removed sine it is included in
	bfd/elfxx-riscv.h.
	(riscv_merge_std_ext): Updated since the field of rpe is changed.
	* elfxx-riscv.c (cpu-riscv.h): Removed.
	(riscv_implicit_subsets): Added implicit extensions for g.
	(struct riscv_supported_ext): Used to be riscv_ext_version.  Moved
	from gas/config/tc-riscv.c, and added new field `default_enable' to
	decide if the extension should be enabled by default.
	(EXT_DEFAULT): Defined for `default_enable' field.
	(riscv_supported_std_ext): It used to return the supported standard
	architecture string, but now we move ext_version_table from
	gas/config/tc-riscv.c to here, and rename it to riscv_supported_std_ext.
	Currently we not only use the table to initialize riscv_ext_order, but
	also get the default versions of extensions, and decide if the extensions
	should be enbaled by default.
	(riscv_supported_std_z_ext): Likewise, but is used for z* extensions.
	(riscv_supported_std_s_ext): Likewise, but is used for s* extensions.
	(riscv_supported_std_h_ext): Likewise, but is used for h* extensions.
	(riscv_supported_std_zxm_ext): Likewise, but is used for zxm* extensions.
	(riscv_all_supported_ext): Includes all supported extension tables.
	(riscv_known_prefixed_ext): Updated.
	(riscv_valid_prefixed_ext): Updated.
	(riscv_init_ext_order): Init the riscv_ext_order table according to
	riscv_supported_std_ext.
	(riscv_get_default_ext_version): Moved from gas/config/tc-riscv.c.
	Get the versions of extensions from riscv_supported_std* tables.
	(riscv_parse_add_subset): Updated.
	(riscv_parse_std_ext): Updated.
	(riscv_set_default_arch): Set the default subset list according to
	the default_enable field of riscv_supported_*ext tables.
	(riscv_parse_subset): If the input ARCH is NULL, then we call
	riscv_set_default_arch to set the default subset list.
	* elfxx-riscv.h (cpu-riscv.h): Included.
	(riscv_parse_subset_t): Removed get_default_version field, and added
	isa_spec field to replace it.
	(extern riscv_supported_std_ext): Removed.
gas/
	* (bfd/cpu-riscv.h): Removed.
	(struct riscv_ext_version): Renamed and moved to bfd/elfxx-riscv.c.
	(ext_version_table): Likewise.
	(riscv_get_default_ext_version): Likewise.
	(ext_version_hash): Removed.
	(init_ext_version_hash): Removed.
	(riscv_set_arch): Updated since the field of rps is changed.  Besides,
	report error when the architecture string is empty.
	(riscv_after_parse_args): Updated.
2021-09-17 16:33:54 +08:00
GDB Administrator
648d5dc4e6 Automatic date update in version.in 2021-09-17 00:00:08 +00:00