binutils-gdb.git
2 years agold: Keep indirect symbol from IR if referenced from shared object
H.J. Lu [Fri, 11 Feb 2022 23:13:19 +0000 (15:13 -0800)]
ld: Keep indirect symbol from IR if referenced from shared object

Don't change indirect symbol defined in IR to undefined if it is
referenced from shared object.

bfd/

PR ld/28879
* elflink.c (_bfd_elf_merge_symbol): Don't change indirect
symbol defined in IR to undefined if it is referenced from
shared object.

ld/

PR ld/28879
* testsuite/ld-plugin/lto.exp: Run PR ld/28879 tests.
* testsuite/ld-plugin/pr28879a.cc: New file.
* testsuite/ld-plugin/pr28879b.cc: Likewise.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 14 Feb 2022 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoPR28882, build failure with gcc-4.2 due to use of 0b literals
Alan Modra [Sat, 12 Feb 2022 23:26:51 +0000 (09:56 +1030)]
PR28882, build failure with gcc-4.2 due to use of 0b literals

PR 28882
* elf/loongarch.h: Replace binary literals with hex.

2 years agoDon't pass around expld.dataseg pointer
Alan Modra [Tue, 8 Feb 2022 00:10:35 +0000 (10:40 +1030)]
Don't pass around expld.dataseg pointer

The better to see any code that accesses expld.dataseg.

* ldexp.c (fold_segment_end): Remove seg parameter.  Adjust calls.
(fold_segment_align, fold_segment_relro_end): Likewise.
* ldlang.c (lang_size_segment): Likewise.
(lang_size_relro_segment_1, lang_find_relro_sections_1): Likewise.

2 years agoRemove bfd ELF_RELROPAGESIZE
Alan Modra [Tue, 8 Feb 2022 00:03:17 +0000 (10:33 +1030)]
Remove bfd ELF_RELROPAGESIZE

Now that ld properly aligns the end of the relro segment, the hack to
make relro work on powerpc can disappear.

bfd/
* bfd.c (bfd_emul_get_commonpagesize): Remove relro param.
Don't return bed->relropagesize.
* elf-bfd.h (struct elf_backend_data): Remove relropagesize.
* elfxx-target.h (ELF_RELROPAGESIZE): Remove.
* elf32-ppc.c (ELF_RELROPAGESIZE): Don't define.
* elf64-ppc.c: Likewise.
* bfd-in2.h: Regenerate.
ld/
* ldemul.c (after_parse_default): Adjust
bfd_emul_get_commonpagesize call.

2 years agoPR28824, relro security issues, x86 keep COMMONPAGESIZE relro
Alan Modra [Wed, 2 Feb 2022 22:27:47 +0000 (08:57 +1030)]
PR28824, relro security issues, x86 keep COMMONPAGESIZE relro

x86 treats MAXPAGESIZE as a memory optimisation parameter, actual
hardware paging is always COMMPAGESIZE of 4k.  Use COMMONPAGESIZE for
the end of the relro segment alignment.

The previous patch regresses pr18176, increasing the testcase file
size from 322208 to 2099872 bytes.  Fixing this on x86 will require
introducing a gap after the end of the relro segment (of up to
relropagesize-1 bytes).

PR 28824
PR 18176
* ld.h (ld_config_type): Add relro_use_commonpagesize field.
* ldexp.c (fold_segment_align): Set relropagesize depending on
relro_use_commonpagesize.
* emultempl/elf-x86.em (elf_x86_create_output_section_statements):
Set relro_use_commonpagesize.
* testsuite/ld-x86-64/pr18176.d: xfail.

2 years agoPR28824, relro security issues
Alan Modra [Thu, 27 Jan 2022 04:47:16 +0000 (15:17 +1030)]
PR28824, relro security issues

Background
==========
There are constraints on layout of binaries to meet demand paging and
memory protection requirements.  Demand paged binaries must have file
offset mod pagesize equal to vma mod pagesize.  Memory protection
(executable, read, write status) can only change at page boundaries.
The linker's MAXPAGESIZE variable gives the page size for these layout
constraints.

In a typical basic executable with two memory segments, text (RE) and
data (RW), the data segment must start on a different page to the
last text segment page.  For example, with 64k pages and a small
executable of 48k text and 1k data, the text segment might start at
address 0x10000 and data at 0x20000 for a total of two 64k memory
pages.  Demand paging would require the image on disk to be 64k+1k
in size.  We can do better than that.  If the data segment instead
starts at 0x2c000 (the end of the text segment plus one 64k page) then
there are still only two memory pages, but the disk image is now
smaller, 48k+1k in size.  This is why the linker normally starts the
data segment at the end of the text segment plus one page.  That
simple heuristic isn't ideal in all cases.  Changing our simple
example to one with 64k-1 text size, following that heuristic would
result in data starting at 0x2ffff.  Now we have two 64k memory data
pages for a data segment of 1k!  If the data segment instead started
at 0x30000 we'd get a single data segment page at the cost of 1 byte
extra in the disk image, which is likely a good trade-off.  So the
linker does adjust the simple heuristic.  Just how much disk image
size increase is allowed is controlled by the linker's COMMONPAGESIZE
variable.

A PT_GNU_RELRO segment overlays the initial part of the data segment,
saying that those pages should be made read-only after relocation by
the dynamic loader.  Page granularity for memory protection means that
the end of the relro segment must be at a page boundary.

The problem
===========
Unfortunately most targets currently only align the end of the relro
segment to COMMONPAGESIZE.  That results in only partial relro
protection if an executable is running with MAXPAGESIZE pages, since
any part of the relro segment past the last MAXPAGESIZE boundary can't
be made read-only without also affecting sections past the end of the
relro segment.  I believe this problem arose because x86 always runs
with 4k (COMMPAGESIZE) memory pages, and therefore using a larger
MAXPAGESIZE on x86 is for reasons other than the demand paging and
memory page protection boundary requirements.

The solution
============
Always end the relro segment on a MAXPAGESIZE boundary, except for
x86.  Note that the relro segment, comprising of sections at the start
of the data segment, is sized according to how those sections are laid
out.  That means the start of the relro segment is fixed relative to
its end.  Which also means the start of the data segment must be at a
fixed address mod MAXPAGESIZE.  So for relro the linker can't play
games with the start of the data segment to save disk space.  At
least, not without introducing gaps between the relro sections.  In
fact, because the linker was starting layout using its simple
heuristic of starting the data segment at the end of the text segment
plus one page, it was sometimes introducing page gaps for no reason.
See pr28743.

PR 28824
PR 28734
* ldexp.c (fold_segment_align): When relro, don't adjust up by
offset within page.  Set relropagesize.
(fold_segment_relro_end): Align to relropagesize.
* ldexp.h (seg_align_type): Rename pagesize to commonpagesize.
Add relropagesize.  Comment.
* ldlang.c (lang_size_segment): Adjust to suit field renaming.
(lang_size_relro_segment_1): Align relro_end using relropagesize.

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 13 Feb 2022 00:00:14 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 12 Feb 2022 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agox86: Disallow invalid relocation against protected symbol
H.J. Lu [Wed, 9 Feb 2022 23:51:22 +0000 (15:51 -0800)]
x86: Disallow invalid relocation against protected symbol

I am checking this into master and will backport it to 2.38 branch.

H.J
----
On x86, GCC 12 supports -mno-direct-extern-access to enable canonical
reference to protected function and disable copy relocation.  With
-mno-direct-extern-access, the canonical protected function symbols must
be accessed via canonical reference and the protected data symbols in
shared libraries are non-copyable. Under glibc 2.35, non-canonical
reference to the canonical protected function will get the run-time error:

./y: internal_f: ./libfoo.so: non-canonical reference to canonical protected function

and copy relocations against the non-copyable protected symbols will get
the run-time error:

./x: internal_i: ./libfoo.so: copy relocation against non-copyable protected symbol

Update x86 linker to disallow non-canonical reference to the canonical
protected function:

ld: plt.o: non-canonical reference to canonical protected function `internal_f' in libfoo.so
ld: failed to set dynamic section sizes: bad value

and copy relocation against the non-copyable protected symbol:

ld: main.o: copy relocation against non-copyable protected symbol `internal_i' in libfoo.so

at link-time.

bfd/

PR ld/28875
* elf-properties.c (_bfd_elf_parse_gnu_properties): Don't skip
shared libraries for GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.
* elf32-i386.c (elf_i386_scan_relocs): Disallow non-canonical
reference to canonical protected function.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
* elfxx-x86.c (elf_x86_allocate_dynrelocs): Don't allow copy
relocation against non-copyable protected symbol.

ld/

PR ld/28875
* testsuite/ld-i386/i386.exp: Check non-canonical reference to
canonical protected function and check copy relocation against
non-copyable protected symbol.
* testsuite/ld-i386/pr21997-1.err: New file.
* testsuite/ld-i386/pr28875.err: Likewise.
* testsuite/ld-i386/pr28875a.c: Likewise.
* testsuite/ld-i386/pr28875b.c: Likewise.
* testsuite/ld-x86-64/pr21997-1a.err: Updated.
* testsuite/ld-x86-64/pr21997-1b.err: Likewise.
* testsuite/ld-x86-64/pr28875-data.err: New file.
* testsuite/ld-x86-64/pr28875-func.err: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Check non-canonical reference
to canonical protected function and check copy relocation against
non-copyable protected symbol.

2 years agoAdd initializers to bound_minimal_symbol
Tom Tromey [Tue, 8 Feb 2022 20:41:53 +0000 (13:41 -0700)]
Add initializers to bound_minimal_symbol

This adds initializers to bound_minimal_symbol, allowing for the
removal of some calls to memset.

2 years agogdb/fortran: support ptype and print commands for namelist variables
Bhuvanendra Kumar N [Wed, 2 Feb 2022 17:52:27 +0000 (17:52 +0000)]
gdb/fortran: support ptype and print commands for namelist variables

Gfortran supports namelists (a Fortran feature); it emits
DW_TAG_namelist and DW_TAG_namelist_item dies. But gdb does not
process these dies and does not support 'print' or 'ptype' commands on
namelist variables.

An attempt to print namelist variables results in gdb bailing out with
the error message as shown below.

  (gdb) print nml
  No symbol "nml" in current context.

This commit is to make the print and ptype commands work for namelist
variables and its items. Sample output of these commands is shared
below, with fixed gdb.

  (gdb) ptype nml
  type = Type nml
      integer(kind=4) :: a
      integer(kind=4) :: b
  End Type nml
  (gdb) print nml
  $1 = ( a = 10, b = 20 )

2 years agogdb: fix until behavior with trailing !is_stmt lines
Bruno Larsen [Wed, 26 Jan 2022 13:08:13 +0000 (10:08 -0300)]
gdb: fix until behavior with trailing !is_stmt lines

When using the command "until", it is expected that GDB will exit a
loop if the current instruction is the last one related to that loop.
However, if there were trailing non-statement instructions, "until"
would just behave as "next".  This was noticeable in clang-compiled
code, but might happen with gcc-compiled as well.  PR gdb/17315 relates
to this problem, as running gdb.base/watchpoint.exp with clang
would fail for this reason.

To better understand this issue, consider the following source code,
with line numbers marked on the left:

  10: for (i = 0; i < 10; ++i)
  11:     loop_body ();
  12:   other_stuff ();

If we transform this to pseudo-assembler, and generate a line table,
we could end up with something like this:

  Address | Pseudo-Assembler | Line | Is-Statement?

  0x100   | i = 0            | 10   | Yes
  0x104   | loop_body ()     | 11   | Yes
  0x108   | i = i + 1        | 10   | Yes
  0x10c   | if (i < 10):     | 10   | No
  0x110   |     goto 0x104   | 10   | No
  0x114   | other_stuff ()   | 12   | Yes

Notice the two non-statement instructions at the end of the loop.

The problem is that when we reach address 0x108 and use 'until',
hoping to leave the loop, GDB sets up a stepping range that runs from
the start of the function (0x100 in our example) to the end of the
current line table entry, that is 0x10c in our example.  GDB then
starts stepping forward.

When 0x10c is reached GDB spots that we have left the stepping range,
that the new location is not a statement, and that the new location is
associated with the same source line number as the previous stepping
range.  GDB then sets up a new stepping range that runs from 0x10c to
0x114, and continues stepping forward.

Within that stepping range the inferior hits the goto (at 0x110) and
loops back to address 0x104.

At 0x104 GDB spots that we have left the previous stepping range, that
the new address is marked as a statement, and that the new address is
for a different source line.  As a result, GDB stops and returns
control to the user.  This is not what the user was expecting, they
expected GDB to exit the loop.

The fix proposed in this patch, is that, when the user issues the
'until' command, and GDB sets up the initial stepping range, GDB will
check subsequent SALs (symtab_and_lines) to see if they are
non-statements associated with the same line number.  If they are then
the end of the initial stepping range is extended to the end of the
non-statement SALs.

In our example above, the user is at 0x108 and uses 'until', GDB now
sets up a stepping range from the start of the function 0x100 to
0x114, the first address associated with a different line.

Now as GDB steps around the loop it never leaves the initial stepping
range.  It is only when GDB exits the loop that we leave the stepping
range, and the stepping finishes at address 0x114.

This patch also adds a test case that can be run with gcc to test that
this functionality is not broken in the future.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17315

2 years agogas/doc: Fix "a true results" typo
Richard Sandiford [Fri, 11 Feb 2022 15:03:47 +0000 (15:03 +0000)]
gas/doc: Fix "a true results" typo

2 years agogdb: extend the information printed by 'maint info jit'
Jan Vrany [Mon, 7 Feb 2022 11:39:22 +0000 (11:39 +0000)]
gdb: extend the information printed by 'maint info jit'

This commit updates the output of 'maint info jit' to print not just
the jit_code_entry address, but also the symfile address, and the
symfile size.

The new information could be obtained by looking into target memory at
the contents of the jit_code_entry, but, by storing this information
within gdb at the time the jit object is loaded, it is now possible to
check if the jit_code_entry has been modified in target memory behind
gdb's back.

Additionally, the symfile address is the same address that is now used
in the objfile names after commit 4a620b7e.

One test that relies on the output of 'maint info jit' was updated to
allow for the new output format.

2 years agobfd: Remove return with expression in void function
Michael Forney [Fri, 11 Feb 2022 12:45:40 +0000 (12:45 +0000)]
bfd: Remove return with expression in void function

      * bfd.c (bfd_set_gp_value): Remove return with expression
        in void function.

2 years agogdb: LoongArch: Add Makefile, configure and NEWS
Tiezhu Yang [Fri, 11 Feb 2022 12:17:56 +0000 (20:17 +0800)]
gdb: LoongArch: Add Makefile, configure and NEWS

This commit adds Makefile, configure and NEWS for LoongArch.

Signed-off-by: Zhensong Liu <liuzhensong@loongson.cn>
Signed-off-by: Qing zhang <zhangqing@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: LoongArch: Add initial native Linux support
Tiezhu Yang [Fri, 11 Feb 2022 12:16:20 +0000 (20:16 +0800)]
gdb: LoongArch: Add initial native Linux support

This commit adds initial native Linux support for LoongArch.

Signed-off-by: Zhensong Liu <liuzhensong@loongson.cn>
Signed-off-by: Qing zhang <zhangqing@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: LoongArch: Add initial Linux target support
Tiezhu Yang [Fri, 11 Feb 2022 12:15:06 +0000 (20:15 +0800)]
gdb: LoongArch: Add initial Linux target support

This commit adds initial Linux target support for LoongArch.

Signed-off-by: Zhensong Liu <liuzhensong@loongson.cn>
Signed-off-by: Qing zhang <zhangqing@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: LoongArch: Add initial baremetal support
Tiezhu Yang [Fri, 11 Feb 2022 12:13:21 +0000 (20:13 +0800)]
gdb: LoongArch: Add initial baremetal support

This commit adds initial baremetal support for LoongArch.

Signed-off-by: Zhensong Liu <liuzhensong@loongson.cn>
Signed-off-by: Qing zhang <zhangqing@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: LoongArch: Add initial target description support
Tiezhu Yang [Fri, 11 Feb 2022 12:12:30 +0000 (20:12 +0800)]
gdb: LoongArch: Add initial target description support

This commit adds initial target description support for LoongArch.

Signed-off-by: Zhensong Liu <liuzhensong@loongson.cn>
Signed-off-by: Qing zhang <zhangqing@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agolibctf: delete unused libctf_TEXINFOS
Mike Frysinger [Thu, 2 Dec 2021 04:43:29 +0000 (23:43 -0500)]
libctf: delete unused libctf_TEXINFOS

It's not clear what this was meant for, but it's not used by anything,
and the info pages still generate fine without it.

2 years agogdb/linux: remove ptrace support check for exec, fork, vfork, vforkdone, clone, sysgood
Simon Marchi [Sun, 16 Jan 2022 04:25:59 +0000 (23:25 -0500)]
gdb/linux: remove ptrace support check for exec, fork, vfork, vforkdone, clone, sysgood

I think it's safe to remove checking support for these ptrace features,
they have all been added in what is now ancient times (around the
beginning of Linux 2.6).  This allows removing a bit of complexity in
linux-nat.c and nat/linux-ptrace.c.

It also allows saving one extra fork every time we start debugging on
Linux: linux_check_ptrace_features forks a child process to test if some
ptrace features are supported.  That child process forks a grand-child,
to test whether ptrace reports an event for the fork by the child.  This
is no longer needed, if we assume the kernel supports reporting forks.

PTRACE_O_TRACEVFORKDONE was introduced in Linux in this change, in 2003:

  https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=45c1a159b85b3b30afd26a77b4be312226bba416

PTRACE_O_TRACESYSGOOD was supported at least as of this change, in 2002:

  https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=acc7088569c8eef04eeed0eff51d23bb5bcff964

PTRACE_O_TRACEFORK, PTRACE_O_TRACEVFORK, PTRACE_O_TRACEEXEC and
PTRACE_O_TRACECLONE were introduced in this change, in 2002:

  https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=a0691b116f6a4473f0fa264210ab9b95771a2b46

Change-Id: Iffb906549a89cc6b619427f976ec044706ab1e8d

2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 11 Feb 2022 00:00:15 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb/infrun: some extra infrun debug print statements
Andrew Burgess [Thu, 10 Feb 2022 09:59:23 +0000 (09:59 +0000)]
gdb/infrun: some extra infrun debug print statements

While reviewing a different patch I wanted to know more about what was
going on during GDB's stepping.  I added some extra infrun debug print
calls, and I thought these might be useful to others.

2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 10 Feb 2022 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoUpdate the obsolete list and how-to-make-a-release documentation now that the 2.38...
Nick Clifton [Wed, 9 Feb 2022 13:44:14 +0000 (13:44 +0000)]
Update the obsolete list and how-to-make-a-release documentation now that the 2.38 release is out.

2 years agoPR28763, SIGSEGV during processing of program headers via readelf
Alan Modra [Wed, 9 Feb 2022 11:54:44 +0000 (22:24 +1030)]
PR28763, SIGSEGV during processing of program headers via readelf

PR 28763
* readelf.c (process_file_header): Discard any cached program
headers if there is an extension field for e_phnum in first
section header.

2 years agoWork around gcc-4 warnings in elf64-ppc.c
Alan Modra [Wed, 9 Feb 2022 05:51:02 +0000 (16:21 +1030)]
Work around gcc-4 warnings in elf64-ppc.c

elf64-ppc.c: In function 'ppc64_elf_size_dynamic_sections':
elf64-ppc.c:10309:45: error: value computed is not used [-Werror=unused-value]
     ++lgot_ents, ++lgot_masks, isym != NULL && isym++)

It is of course a silly warning, fixed in later versions of gcc.  I
wrote "isym != NULL && isym++" rather than the simpler "isym++" to
stop sanitisers complaining about incrementing a NULL pointer.  isym
is of course unused in any code path where it might start off as
NULL.  Sometimes you can't win.  So don't try to be clever in reading
local symbols only when needed.  99 times out of 100 they will be
cached anyway.

* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Avoid annoying
warnings by always reading local syms.
(ppc64_elf_layout_multitoc): Likewise.

2 years agoTest --only-keep-debug on ELF relocatables
Peilin Ye [Thu, 3 Feb 2022 06:33:22 +0000 (22:33 -0800)]
Test --only-keep-debug on ELF relocatables

Add a test for commit 7c4643efe7be, which fixed --only-keep-debug for ELF
relocatables.

* testsuite/binutils-all/objcopy.exp
(keep_debug_symbols_for_elf_relocatable): New test.

2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 9 Feb 2022 00:00:16 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoRISC-V: Stop reporting warnings for mismatched extension versions
Palmer Dabbelt [Mon, 7 Feb 2022 20:14:30 +0000 (12:14 -0800)]
RISC-V: Stop reporting warnings for mismatched extension versions

The extension version checking logic is really just too complicated to
encode into the linker, trying to do so causes more harm than good.
This removes the checks and the associated tests, leaving the logic to
keep the largest version of each extension linked into the target.

bfd/

* elfnn-riscv.c (riscv_version_mismatch): Rename to
riscv_update_subset_version, and stop reporting warnings on
version mismatches.
(riscv_merge_std_ext): Adjust calls to riscv_version_mismatch.
(riscv_merge_multi_letter_ext): Likewise.

ld/
* testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Remove
* testsuite/ld-riscv-elf/attr-merge-arch-failed-01a.s: Likewise
* testsuite/ld-riscv-elf/attr-merge-arch-failed-01b.s: Likewise
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: Likewise
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s: Likewise
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s: Likewise
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s: Likewise
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s: Likewise
* testsuite/ld-riscv-elf/attr-merge-user-ext-01.d: New test.
* testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i21_m2p0.s:
Likewise.
* testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i21_m2p1.s:
Likewise.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Remove obselete
attr-merge-arch-failed-{01,02}, replace with
attr-merge-user-ext-01.

Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 years agoPR28862, heap-buffer-overflow in parse_stab_string
Alan Modra [Tue, 8 Feb 2022 09:51:01 +0000 (20:21 +1030)]
PR28862, heap-buffer-overflow in parse_stab_string

I have no info on the format of a "SUNPRO C++ Namespace" stab, so am
relying on the previous code being correct in parsing these stabs.
Just don't allow NULs anywhere in the stab.

PR 28862
* stabs.c (parse_stab_string): Don't overrun buffer when parsing
'Y' stab.

2 years agoRe: elf: Check symbol version without any symbols
Alan Modra [Tue, 8 Feb 2022 01:14:27 +0000 (11:44 +1030)]
Re: elf: Check symbol version without any symbols

* testsuite/ld-elf/pr24718-1.d: Don't xfail for hppa64.

2 years agogdb: remove tailing newlines from index_cache_debug calls
Andrew Burgess [Mon, 7 Feb 2022 17:13:34 +0000 (17:13 +0000)]
gdb: remove tailing newlines from index_cache_debug calls

I noticed that most of the calls to index_cache_debug include a
trailing newline.  As the new debug mechanism already adds a newline,
that means all of these debug calls result in a blank line being
printed, which I think is a mistake.

Remove all the trailing newlines.

I also reformatted one of the index_cache_debug where a string will
now fit onto a single line.

Unless 'set debug index-cache on' is used, there should be no visible
change in output after this commit.

2 years agoi386: Allow GOT32 relocations against ABS symbols
H.J. Lu [Mon, 7 Feb 2022 23:22:19 +0000 (15:22 -0800)]
i386: Allow GOT32 relocations against ABS symbols

GOT32 relocations are allowed since absolute value + addend is stored in
the GOT slot.

Tested on glibc 2.35 build with GCC 11.2 and -Os.

bfd/

PR ld/28870
* elfxx-x86.c (_bfd_elf_x86_valid_reloc_p): Also allow GOT32
relocations.

ld/

PR ld/28870
* testsuite/ld-i386/i386.exp: Run pr28870.
* testsuite/ld-i386/pr28870.d: New file.
* testsuite/ld-i386/pr28870.s: Likewise.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 8 Feb 2022 00:00:21 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb/python: allow Value.format_string to return styled output
Andrew Burgess [Mon, 24 Jan 2022 15:29:49 +0000 (15:29 +0000)]
gdb/python: allow Value.format_string to return styled output

Add a new argument to the gdb.Value.format_string method, 'styling'.
This argument is False by default.

When this argument is True, then the returned string can contain output
styling escape sequences.

When this argument is False, then the returned string will not contain
any styling escape sequences.

If the returned string is going to be printed to the user, then it is
often nice to retain the GDB styling.

For the testing, we need to adjust the TERM environment variable, as
we do for all the styling tests.  I'm now running all of the C tests
in gdb.python/py-format-string.exp in an environment where styling
could be generated, but only my new test should actually produce
styled output, hopefully this will catch the case where a bug might
cause format_string to always produce styled output.

2 years agogdb: make thread_info::m_thread_fsm a std::unique_ptr
Lancelot SIX [Tue, 11 Jan 2022 15:10:11 +0000 (10:10 -0500)]
gdb: make thread_info::m_thread_fsm a std::unique_ptr

While working on function calls, I realized that the thread_fsm member
of struct thread_info is a raw pointer to a resource it owns.  This
commit changes the type of the thread_fsm member to a std::unique_ptr in
order to signify this ownership relationship and slightly ease resource
management (no need to manually call delete).

To ensure consistent use, the field is made a private member
(m_thread_fsm).  The setter method (set_thread_fsm) can then check
that it is incorrect to associate a FSM to a thread_info object if
another one is already in place.  This is ensured by an assertion.

The function run_inferior_call takes an argument as a pointer to a
call_thread_fsm and installs it in it in a thread_info instance.  Also
change this function's signature to accept a unique_ptr in order to
signify that the ownership of the call_thread_fsm is transferred during
the call.

No user visible change expected after this commit.

Tested on x86_64-linux with no regression observed.

Change-Id: Ia1224f72a4afa247801ce6650ce82f90224a9ae8

2 years agogdb: unbuffer all input streams when not using readline
Andrew Burgess [Wed, 22 Dec 2021 12:57:44 +0000 (12:57 +0000)]
gdb: unbuffer all input streams when not using readline

This commit should fix PR gdb/28711.  What's actually going on is
pretty involved, and there's still a bit of the story that I don't
understand completely, however, from my observed results, I think that
the change I propose making here (or something very similar) is going
to be needed.

The original bug report involves using eclipse to drive gdb using mi
commands.  A separate tty is spun off in which to send gdb the mi
commands, this tty is created using the new-ui command.

The behaviour observed is that, given a particular set of mi commands
being sent to gdb, we sometimes see an ESPIPE error from a lseek
call, which ultimately results in gdb terminating.

The problems all originate from gdb_readline_no_editing_callback in
gdb/event-top.c, where we can (sometimes) perform calls to fgetc, and
allow glibc to perform buffering on the FILE object being used.

I say sometime, because, gdb_readline_no_editing_callback already
includes a call to disable the glibc buffering, but this is only done
if the input stream is not a tty.  In our case the input stream is a
tty, so the buffering is left in place.

The first step to understanding why this problem occurs is to
understand that eclipse sends multiple commands to gdb very quickly
without waiting for and answer to each command, eclipse plans to
collect all of the command results after sending all the commands to
gdb.  In fact, eclipse sends the commands to gdb that they appear to
arrive in the gdb process as a single block of data.  When reproducing
this issue within the testsuite I find it necessary to send multiple
commands using a single write call.

The next bit of the story gets a little involved, and this is where my
understanding is not complete.  I can describe the behaviour that I
observe, and (for me at least) I'm happy that what I'm seeing, if a
little strange, is consistent.  In order to fully understand what's
going on I think I would likely need to dive into kernel code, which
currently seems unnecessary given that I'm happy with the solution I'm
proposing.

The following description all relates to input from a tty in which I'm
not using readline.  I see the same problems either when using a
new-ui tty, or with gdb's standard, non-readline, mi tty.

Here's what I observe happening when I send multiple commands to gdb
using a single write, if I send gdb this:

  command_1\ncommand_2\ncommand_3

then gdb's event loop will wake up (from its select) as it sees there
is input available.  We call into gdb_readline_no_editing_callback,
where we call fgetc, glibc will do a single big read, and get back
just:

  command_1\n

that is, despite there being multiple lines of input available, I
consistently get just a single line.  From glibc a single character is
returned from the fgetc call, and within gdb we accumulate characters,
one at a time, into our own buffer.  Eventually gdb sees the '\n'
character, and dispatches the whole 'command_1' into gdb's command
handler, which processes the command and prints the result.  We then
return to gdb_readline_no_editing_callback, which in turn returns to
gdb's event loop where we re-enter the select.

Inside the select we immediately see that there is more input waiting
on the input stream, drop out of the select, and call back into
gdb_readline_no_editing_callback.  In this function we again call
fgetc where glibc performs another big read.  This time glibc gets:

  command_2\n

that is, we once again get just a single line, despite there being a
third line available.  Just like the first command we copy the whole
string, character by character into gdb's buffer, then handle the
command.  After handling the command we go to the event loop, enter,
and then exit the select, and call back to the function
gdb_readline_no_editing_callback.

In gdb_readline_no_editing_callback we again call fgetc, this time
glibc gets the string:

  command_3\n

like before, we copy this to gdb's buffer and handle the command, then
we return to the event loop.  At this point the select blocks while we
wait for more input to arrive.

The important bit of this is that someone, somewhere is, it appears,
taking care to split the incoming write into lines.

My next experiment is to try something like:

  this_is_a_very_long_command\nshort_command\n

However, I actually make 'this_is_a_very_long_command' very long, as
in many hundreds of characters long.  One way to do this is:

  echo xxxxxx.....xxxxx

and just adding more and more 'x' characters as needed.  What I'm
aiming for is to have the first command be longer than glibc's
internal read buffer, which, on my machine, is 1024 characters.

However, for this discussion, lets imagine that glibc's buffer is just
8 characters (we can create just this situation by adding a suitable
setbuf call into gdb_readline_no_editing_callback).

Now, if I send gdb this data:

  abcdefghij\nkl\n

The first read from glibc will get 'abcdefgh', that is a full 8
character buffer.  Once gdb has copied these to its buffer we call
fgetc again, and now glibc will get 'ij\n', that is, just like before,
multiple lines are split at the '\n' character.  The full command,
which is now in gdb's buffer can be handled 'abcdefghij', after which
we go (via the event loop) back to gdb_readline_no_editing_callback.
Now we call fgetc, and glibc will get 'kl\n', which is then handled in
the normal way.

So far, so good.  However, there is, apparently, one edge case where
the above rules don't apply.

If the '\n' character is the first character read from the kernel,
then the incoming lines are not split up.  So, given glibc's 8
character buffer, if I send gdb this:

  abcdefgh\nkl\n

that is the first command is 8 characters plus a newline, then, on the
first read (from within glibc) we get 'abcdefgh' in a single buffer.
As there's no newline gdb calls fgetc again, and glibc does another
large read, now we get:

  \nkl\n

which doesn't follow the above pattern - the lines are not split into
separate buffers!

So, gdb reads the first character from glibc using fgetc, this is the
newline.  Now gdb has a complete command, and so the command is
handled.  We then return to the event loop and enter the select.

The problem is that, as far as the kernel is concerned, there is no
more input pending, it's all been read into glibc's buffer, and so the
select doesn't return.  The second command is basically stuck in
glibc's buffer.

If I send another command to gdb, or even just send an empty
command (a lone newline) then the select returns, we call into
gdb_readline_no_editing_callback, and now gdb sees the second
command.

OK, so the above is interesting, but it doesn't explain the ESPIPE
error.

Well, that's a slightly different, but related issue.  The ESPIPE
case will _only_ show up when using new-ui to create the separate tty
for mi commands, and is a consequence of this commit:

  commit afe09f0b6311a4dd1a7e2dc6491550bb228734f8
  Date:   Thu Jul 18 17:20:04 2019 +0100

      Fix for using named pipes on Windows

Prior to this commit, the new-ui command would open the tty three
times, once each for stdin, stderr, and stdout.  After this commit we
open the tty just once and reuse the FILE object for all three roles.

Consider the problem case, where glibc has (unexpectedly) read the
second command into its internal buffer.  When we handle the first
command we usually end up having to write something to the mi output
stream.

After the above commit the same FILE object represents both the input
and output streams, so, when gdb tries to write to the FILE object,
glibc spots that there is input pending within the input buffer, and
so assumes that we have read ahead of where we should be in the input
file.  To correct for this glibc tries to do an lseek call to
reposition the file offset of the output stream prior to writing to
it.  However, as the output stream is a tty, and seeking is not
supported on a tty, this lseek call fails, this results in the ESPIPE,
which ultimately causes gdb to terminate.

So, now we understand why the ESPIPE triggers (which was what caused
the gdb crash in the original bug report), and we also understand that
sometime gdb will not handle the second command in a timely
fashion (if the first command is just the wrong length). So, what to
do about all this?

We could revert the commit mentioned above (and implement its
functionality another way).  This would certainly resolve the ESPIPE
issue, the buffered input would now only be on the input stream, the
output stream would have no buffered input, and so glibc would never
try to lseek, and so we'd never get the ESPIPE error.

However, this only solves one of the two problems.  We would still
suffer from the problem where, if the first command is just the wrong
length, the second command will not (immediately) get handled.

The only solution I can see to this problem is to unbuffer the input
stream.  If glibc is not buffering the input, but instead, we read
incoming data character by character from the kernel, then everything
will be fine.  As soon as we see the newline at the end of the first
command we will handle the first command.  As glibc will have no
buffered input it will not be tempted to lseek, so no ESPIPE error.
When we go have to the event loop there will be more data pending in
the kernel, so the select will immediately return, and the second
command will be processed.

I'm tempted to suggest that we should move the unbuffering of the
input stream out of gdb_readline_no_editing_callback and do it
somewhere earlier, more like when we create the input streams.
However, I've not done that in this commit for a couple of reasons:

  1. By keeping the unbuffering in gdb_readline_no_editing_callback
  I'm making the smallest possible change that fixes the bug.  Moving
  the unbuffering somewhere better can be done as a refactor later, if
  that 's felt to be important,

  2. I don't think making repeated calls to unbuffer the input will
  have that much performance impact.  We only make the unbuffer call
  once per call to gdb_readline_no_editing_callback, and, if the input
  stream is already unbuffered we'll return pretty quickly, so I don't
  see this as being massively costly,

  3. Tom is currently doing lots of gdb stream management changes and
  I want to minimise the chances we'll conflict.

So, this commit just changes gdb_readline_no_editing_callback to
always unbuffer the input stream.

The test for this issue sends two commands in a loop, with the first
command growing bigger each time around the loop.  I actually make the
first command bigger by just adding whitespace to the front, as gdb
still has to read the complete command (including whitespace) via
glibc, so this is enough to trigger the bug.

The original bug was reported when using a virtual machine, and in
this situation we see this in the strace output:

  read(9, "70-var-info-path-expression var1.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1024) = 64
  read(9, "\n71-var-info-path-expression var1.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", 1024) = 67

I'm not completely sure what's going on here, but it appears that the
kernel on the virtual machine is delivering the input to glibc slower
than I see on my real hardware; glibc asks for 1024 bytes, but only
gets 64 bytes the first time.  In the second read we see the problem
case, the first character is the newline, but then the entire second
command is included.

If I run this exact example on my real hardware then the first command
would not be truncated at 64 bytes, instead, I'd expect to see the
newline included in the first read, with the second command split into
a second read.

So, for testing, I check cases where the first command is just a few
characters (starting at 8 character), all the way up to 2048
characters.  Hopefully, this should mean we hit the problem case for
most machine setups.

The only last question relates to commit afe09f0b6311a4d that I
mentioned earlier.  That commit was intended to provide support for
Microsoft named pipes:

  https://docs.microsoft.com/en-us/windows/win32/ipc/named-pipes

I know next to nothing about this topic beyond a brief scan of the
above link, but I think these windows named pipe are closer in
behaviour to unix sockets than to unix named fifos.

I am a little nervous that, after the above commit, we now use the
same FILE for in, err, and out streams.  In contrast, in a vanilla C
program, I would expect different FILE objects for each stream.

Still, I'm reluctant to revert the above commit (and provide the same
functionality a different way) without a specific bug to point at,
and, now that the streams are unbuffered, I expect a lot of the read
and write calls are going straight to the kernel with minimal glibc
involvement, so maybe it doesn't really matter.  Anyway, I haven't
touched the above patch, but it is something to keep in mind when
working in this area.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28711

2 years agogdb/disasm: combine the no printing disassembler setup code
Andrew Burgess [Fri, 4 Feb 2022 16:51:45 +0000 (16:51 +0000)]
gdb/disasm: combine the no printing disassembler setup code

We have three places in gdb where we initialise a disassembler that
will not print anything (used for figuring out the length of
instructions, or collecting other information from the disassembler).

Each of these places has its own stub function to act as a print like
callback, the stub function is identical in each case, and just does
nothing.

In this commit I create a new function to initialise a disassembler
that doesn't print anything, and have all three locations use this new
function.  There's now only one non-printing stub function.

There should be no user visible changes after this commit.

2 years agogdb: add the 'set/show suppress-cli-notifications' command
Tankut Baris Aktemur [Mon, 7 Feb 2022 07:26:56 +0000 (08:26 +0100)]
gdb: add the 'set/show suppress-cli-notifications' command

GDB already has a flag to suppress printing notification events, such
as thread and inferior context switches, on the CLI.  This is used
internally when executing commands.  Make the flag available to the
user via a new command.  This is expected to be useful in scripts.

For instance, suppose that when Inferior 1 gets to a certain state,
you want to add and set up a new inferior using the commands below,
but you also want to have a reduced/clean output.

  define do-setup
    printf "Setting up Inferior 2...\n"
    add-inferior -exec a.out
    inferior 2
    break file.c:3
    run
    inferior 1
    printf "Done\n"
  end

Currently, GDB prints

  (gdb) do-setup
  Setting up Inferior 2...
  [New inferior 2]
  Added inferior 2 on connection 1 (native)
  [Switching to inferior 2 [<null>] (/tmp/a.out)]
  Breakpoint 2 at 0x1155: file file.c, line 3.

  Thread 2.1 "a.out" hit Breakpoint 2, main () at file.c:3
  3         return 0;
  [Switching to inferior 1 [process 7670] (/tmp/test)]
  [Switching to thread 1.1 (process 7670)]
  #0  main () at test.c:2
  2         int a = 1;
  Done

GDB's Python API make it possible to capture and return GDB's output,
but this does not work for all the streams.  In particular, CLI
notification events are not captured:

  (gdb) python gdb.execute("do-setup", False, True)
  [Switching to inferior 2 [<null>] (/tmp/a.out)]

  Thread 2.1 "a.out" hit Breakpoint 2, main () at file.c:3
  3         return 0;
  [Switching to inferior 1 [process 8263] (/tmp/test)]
  [Switching to thread 1.1 (process 8263)]
  #0  main () at test.c:2
  2         int a = 1;

You can use the new "set suppress-cli-notifications" command to
suppress the output:

  (gdb) set suppress-cli-notifications on
  (gdb) do-setup
  Setting up Inferior 2...
  [New inferior 2]
  Added inferior 2 on connection 1 (native)
  Breakpoint 2 at 0x1155: file file.c, line 3.
  Done

2 years agogdb/cli: add a 'normal_stop' option to 'cli_suppress_notification'
Tankut Baris Aktemur [Mon, 7 Feb 2022 07:26:56 +0000 (08:26 +0100)]
gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification'

Extend the 'cli_suppress_notification' struct with a new field,
'normal_stop', that can be used for checking if printing normal stop
events on the CLI should be suppressed.

This patch only introduces the flag.  The subsequent patch adds a user
command to turn the flag off/on.

2 years agogdb/cli: convert cli_suppress_notification from int to bool
Tankut Baris Aktemur [Mon, 7 Feb 2022 07:26:55 +0000 (08:26 +0100)]
gdb/cli: convert cli_suppress_notification from int to bool

Convert the suppress_notification flag for the CLI from int to bool.

2 years agoRevert "elf: Remove the 1-page gap before the RELRO segment"
Alan Modra [Sat, 5 Feb 2022 09:36:52 +0000 (20:06 +1030)]
Revert "elf: Remove the 1-page gap before the RELRO segment"

This reverts commit 2f83249c13d86065b4c7cdb198ea871017b4bba1.

PR ld/28743
* ldlang.c (lang_size_relro_segment_1): Revert 2022-01-10 changes.
* testsuite/ld-i386/pr20830.d: Likewise.
* testsuite/ld-s390/gotreloc_64-relro-1.dd: Likewise.
* testsuite/ld-x86-64/pr14207.d: Likewise.
* testsuite/ld-x86-64/pr18176.d: Likewise.
* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
* testsuite/ld-x86-64/pr20830a.d: Likewise.
* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
* testsuite/ld-x86-64/pr20830b.d: Likewise.
* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
* testsuite/ld-x86-64/pr21038a.d: Likewise.
* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
* testsuite/ld-x86-64/pr21038c.d: Likewise.

2 years agoRevert "ld: Rewrite lang_size_relro_segment_1"
Alan Modra [Sat, 5 Feb 2022 09:31:40 +0000 (20:01 +1030)]
Revert "ld: Rewrite lang_size_relro_segment_1"

This reverts commit c804c6f98d342c3d46f73d7a7ec6229d5ab1c9f3.

PR ld/28743
PR ld/28819
* ldlang.c (lang_size_relro_segment_1): Revert 2022-01-14 change.
* testsuite/ld-x86-64/pr28743-1.d: Likewise.
* testsuite/ld-x86-64/pr28743-1.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Likewise.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 7 Feb 2022 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoA more elegant pr28827-1 testcase
Alan Modra [Sat, 5 Feb 2022 10:30:41 +0000 (21:00 +1030)]
A more elegant pr28827-1 testcase

Use .irpc macros in pr28827-1.s

* testsuite/ld-powerpc/pr28827-1.s: Make the testcase more
elegant.  Comment.

2 years agoMerge do_val_print and common_val_print
Tom Tromey [Thu, 27 Jan 2022 00:57:33 +0000 (17:57 -0700)]
Merge do_val_print and common_val_print

The only caller of do_val_print just does a small bit of work before
the call.  This patch merges the two functions, and removes an
unnecessary local variable, making gdb a bit simpler.

2 years agogdb: remove SYMBOL_LINE macro
Simon Marchi [Fri, 28 Jan 2022 03:39:50 +0000 (22:39 -0500)]
gdb: remove SYMBOL_LINE macro

Add a getter and a setter for a symbol's line.  Remove the corresponding macro
and adjust all callers.

Change-Id: I229f2b8fcf938c07975f641361313a8761fad9a5

2 years agogdb: remove SYMBOL_TYPE macro
Simon Marchi [Fri, 28 Jan 2022 03:16:41 +0000 (22:16 -0500)]
gdb: remove SYMBOL_TYPE macro

Add a getter and a setter for a symbol's type.  Remove the corresponding
macro and adjust all callers.

Change-Id: Ie1a137744c5bfe1df4d4f9ae5541c5299577c8de

2 years agogdb: remote SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION macro
Simon Marchi [Fri, 28 Jan 2022 03:13:40 +0000 (22:13 -0500)]
gdb: remote SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION macro

Add a getter for a whether a symbol is a C++ template function.  Remove
the corresponding macro and adjust all callers.

Change-Id: I89abc2802a952b77b0e0eb73a25c2306cb8e8bcc

2 years agogdb: remove SYMBOL_INLINED macro
Simon Marchi [Fri, 28 Jan 2022 03:08:54 +0000 (22:08 -0500)]
gdb: remove SYMBOL_INLINED macro

Add a getter and a setter for whether a symbol is inlined.  Remove the
corresponding macro and adjust all callers.

Change-Id: I934468da3b5a32dd6b161a6f252a6b1b94737279

2 years agogdb: remove SYMBOL_IS_ARGUMENT macro
Simon Marchi [Fri, 28 Jan 2022 03:06:47 +0000 (22:06 -0500)]
gdb: remove SYMBOL_IS_ARGUMENT macro

Add a getter and a setter for whether a symbol is an argument.  Remove
the corresponding macro and adjust all callers.

Change-Id: I71b4f0465f3dfd2ed8b9e140bd3f7d5eb8d9ee81

2 years agogdb: remove SYMBOL_OBJFILE_OWNED macro
Simon Marchi [Fri, 28 Jan 2022 03:01:10 +0000 (22:01 -0500)]
gdb: remove SYMBOL_OBJFILE_OWNED macro

Add a getter and a setter for whether a symbol is objfile owned.  Remove
the corresponding macro and adjust all callers.

Change-Id: Ib7ef3718d65553ae924ca04c3fd478b0f4f3147c

2 years agogdb: remove SYMBOL_DOMAIN macro
Simon Marchi [Fri, 28 Jan 2022 02:50:32 +0000 (21:50 -0500)]
gdb: remove SYMBOL_DOMAIN macro

Add a getter and a setter for a symbol's domain.  Remove the
corresponding macro and adjust all callers.

Change-Id: I54465b50ac89739c663859a726aef8cdc6e4b8f3

2 years agogdb: remove SYMBOL_CLASS macro, add getter
Simon Marchi [Mon, 22 Nov 2021 03:26:24 +0000 (22:26 -0500)]
gdb: remove SYMBOL_CLASS macro, add getter

Change-Id: I83211d5a47efc0564386e5b5ea4a29c00b1fd46a

2 years agogdb: remove SYMBOL_IMPL macro, add method
Simon Marchi [Mon, 22 Nov 2021 03:10:47 +0000 (22:10 -0500)]
gdb: remove SYMBOL_IMPL macro, add method

Add a getter for a symbol's "impl".  Remove the corresponding macro and
adjust all callers.

Change-Id: Ibe26ed442f0f99a0f5cddafca30bd96ec7fb9fa8

2 years agogdb: remove SYMBOL_ACLASS_INDEX macro, add getter/setter
Simon Marchi [Mon, 22 Nov 2021 03:03:07 +0000 (22:03 -0500)]
gdb: remove SYMBOL_ACLASS_INDEX macro, add getter/setter

Add a getter and a setter for a symbol's aclass index.  Remove the
corresponding macro and adjust all callers.

Change-Id: Ie8c8d732624cfadb714aba5ddafa3d29409b3d39

2 years agogdb: remove SYMBOL_MATCHES_SEARCH_NAME
Simon Marchi [Sun, 21 Nov 2021 18:50:39 +0000 (13:50 -0500)]
gdb: remove SYMBOL_MATCHES_SEARCH_NAME

It seems like this macro is not needed at all anymore, it just wraps the
function of the same name with the same arguments.

Change-Id: I3c342ac8d89c27af5aee1a819dc32cc6396fd41b

2 years agogdb: remove SYMTAB_DIRNAME macro
Simon Marchi [Sun, 21 Nov 2021 03:24:54 +0000 (22:24 -0500)]
gdb: remove SYMTAB_DIRNAME macro

Remove the macro, replace with an equivalent method.

Change-Id: I46ec36b91bb734331138eb9cd086b2db01635aed

2 years agogdb: remove SYMTAB_PSPACE macro
Simon Marchi [Sun, 21 Nov 2021 03:23:01 +0000 (22:23 -0500)]
gdb: remove SYMTAB_PSPACE macro

Remove the macro, replace with an equivalent method.

Change-Id: Icccc20e7e8ae03ac4dac1c7514c25a12a9a0ac69

2 years agogdb: remove SYMTAB_OBJFILE macro
Simon Marchi [Sun, 21 Nov 2021 02:54:11 +0000 (21:54 -0500)]
gdb: remove SYMTAB_OBJFILE macro

Remove the macro, replace with an equivalent method.

Change-Id: I8f9ecd290ad28502e53c1ceca5006ba78bf042eb

2 years agogdb: remove SYMTAB_BLOCKVECTOR macro
Simon Marchi [Sun, 21 Nov 2021 02:32:41 +0000 (21:32 -0500)]
gdb: remove SYMTAB_BLOCKVECTOR macro

Remove the macro, replace with an equivalent method.

Change-Id: Id6fe2a79c04bcd6c69ccaefb7a69bc06a476288c

2 years agogdb: remove SYMTAB_LANGUAGE macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 13:47:30 +0000 (08:47 -0500)]
gdb: remove SYMTAB_LANGUAGE macro, add getter/setter

Add a getter and a setter for a symtab's language.  Remove the
corresponding macro and adjust all callers.

Change-Id: I9f4d840b11c19f80f39bac1bce020fdd1739e11f

2 years agogdb: remove SYMTAB_LINETABLE macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 13:40:12 +0000 (08:40 -0500)]
gdb: remove SYMTAB_LINETABLE macro, add getter/setter

Add a getter and a setter for a symtab's linetable.  Remove the
corresponding macro and adjust all callers.

Change-Id: I159183fc0ccd8e18ab937b3c2f09ef2244ec6e9c

2 years agogdb: remove SYMTAB_COMPUNIT macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:49:01 +0000 (22:49 -0500)]
gdb: remove SYMTAB_COMPUNIT macro, add getter/setter

Add a getter and a setter for a symtab's compunit_symtab.  Remove the
corresponding macro and adjust all callers.

For brevity, I chose the name "compunit" instead of "compunit_symtab"
the the field, getter and setter names.  Since we are already in symtab
context, the _symtab suffix seems redundant.

Change-Id: I4b9b731c96e3594f7733e75af1e3d01bc0e4fe92

2 years agogdb: remove COMPUNIT_MACRO_TABLE macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:43:56 +0000 (22:43 -0500)]
gdb: remove COMPUNIT_MACRO_TABLE macro, add getter/setter

Add a getter and a setter for a compunit_symtab's macro table.  Remove the
corresponding macro and adjust all callers.

Change-Id: I00615ea72d5ac43d9a865e941cb2de0a979c173a

2 years agogdb: remove COMPUNIT_EPILOGUE_UNWIND_VALID macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:41:10 +0000 (22:41 -0500)]
gdb: remove COMPUNIT_EPILOGUE_UNWIND_VALID macro, add getter/setter

Add a getter and a setter for a compunit_symtab's epilogue unwind valid flag.
Remove the corresponding macro and adjust all callers.

Change-Id: If3b68629d987767da9be7041a95d96dc34367a9a

2 years agogdb: remove COMPUNIT_LOCATIONS_VALID macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:35:40 +0000 (22:35 -0500)]
gdb: remove COMPUNIT_LOCATIONS_VALID macro, add getter/setter

Add a getter and a setter for a compunit_symtab's locations valid flag.
Remove the corresponding macro and adjust all callers.

Change-Id: I3e3cfba926ce62993d5b61814331bb3244afad01

2 years agogdb: remove COMPUNIT_BLOCK_LINE_SECTION macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:31:55 +0000 (22:31 -0500)]
gdb: remove COMPUNIT_BLOCK_LINE_SECTION macro, add getter/setter

Add a getter and a setter for a compunit_symtab's block line section.  Remove
the corresponding macro and adjust all callers.

Change-Id: I3eb1a323388ad55eae8bfa45f5bc4a08dc3df455

2 years agogdb: remove COMPUNIT_BLOCKVECTOR macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:25:23 +0000 (22:25 -0500)]
gdb: remove COMPUNIT_BLOCKVECTOR macro, add getter/setter

Add a getter and a setter for a compunit_symtab's blockvector.  Remove
the corresponding macro and adjust all callers.

Change-Id: I99484c6619dcbbea7c5d89c72aa660316ca62f64

2 years agogdb: remove COMPUNIT_DIRNAME macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:15:30 +0000 (22:15 -0500)]
gdb: remove COMPUNIT_DIRNAME macro, add getter/setter

Add a getter and a setter for a compunit_symtab's dirname.  Remove the
corresponding macro and adjust all callers.

Change-Id: If2f39b295fd26822586485e04a8b8b5aa5cc9b2e

2 years agogdb: remove COMPUNIT_PRODUCER macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 03:09:25 +0000 (22:09 -0500)]
gdb: remove COMPUNIT_PRODUCER macro, add getter/setter

Add a getter and a setter for a compunit_symtab's producer.  Remove the
corresponding macro and adjust all callers.

Change-Id: Ia1d6d8a0e247a08a21af23819d71e49b37d8931b

2 years agogdb: remove COMPUNIT_DEBUGFORMAT macro, add getter/setter
Simon Marchi [Sat, 20 Nov 2021 02:49:53 +0000 (21:49 -0500)]
gdb: remove COMPUNIT_DEBUGFORMAT macro, add getter/setter

Add a getter and a setter for a compunit_symtab's debugformat.  Remove
the corresponding macro and adjust all callers.

Change-Id: I1667b02d5322346f8e23abd9f8a584afbcd75975

2 years agogdb: remove COMPUNIT_FILETABS macro
Simon Marchi [Sat, 20 Nov 2021 02:35:17 +0000 (21:35 -0500)]
gdb: remove COMPUNIT_FILETABS macro

I think that most remaining uses of COMPUNIT_FILETABS intend to get the
primary filetab of the compunit_symtab specifically (and not to iterate
over all filetabs, for example, those cases would use compunit_filetabs,
which has been converted to compunit_symtab::filetabs), so replace mosts
uses with compunit_symtab::primary_filetab.

In jit.c, function finalize_symtab, we can save the symtab object
returned by allocate_symtab and use it, it makes things simpler.

Change-Id: I4e51d6d4b40759de8768b61292e5e13c8eae2e38

2 years agogdb: move compunit_filetabs to compunit_symtab::filetabs
Simon Marchi [Sat, 20 Nov 2021 02:18:05 +0000 (21:18 -0500)]
gdb: move compunit_filetabs to compunit_symtab::filetabs

Make compunit_filetabs, used to iterate a compunit_symtab's filetabs, a
method of compunit_symtab.  The name filetabs conflicts with the current
name of the field.  Rename the field to m_filetabs, since at this point
nothing outside of compunit_symtab uses it, so we should treat it as
private (even though it's not actually private).  Rename the
last_filetab field to m_last_filetab as well (it's only used on
compunit_symtab::add_filetab).

Adjust the COMPUNIT_FILETABS macro to keep its current behavior of
returning the first filetab.

Change-Id: I537b553a44451c52d24b18ee1bfa47e23747cfc3

2 years agogdb: add compunit_symtab::set_primary_filetab method
Simon Marchi [Sat, 20 Nov 2021 02:14:36 +0000 (21:14 -0500)]
gdb: add compunit_symtab::set_primary_filetab method

Add a method to set the primary filetab of the CU.  This is currently
done in buildsym_compunit::end_symtab_with_blockvector.

Change-Id: I16c51a6b90a4cb4c0c5f183b0f2e12bc64b6fd74

2 years agogdb: add compunit_symtab::add_filetab method
Simon Marchi [Sat, 20 Nov 2021 01:59:59 +0000 (20:59 -0500)]
gdb: add compunit_symtab::add_filetab method

Add a method to append a filetab/symtab to a compunit_symtab.  There is
a single place where this is done currently, in allocate_symtab.

Change-Id: Ie86c6e34d175728173d1cffdce44acd6cff6c31d

2 years agogdb: rename compunit_primary_filetab to compunit_symtab::primary_filetab
Simon Marchi [Sat, 20 Nov 2021 01:50:59 +0000 (20:50 -0500)]
gdb: rename compunit_primary_filetab to compunit_symtab::primary_filetab

Make compunit_primary_filetab a method of compunit_symtab.

Change-Id: Iee3c4f7e36d579bf763c5bba146e5e10d6766768

2 years agogdb: remove COMPUNIT_OBJFILE macro
Simon Marchi [Fri, 19 Nov 2021 18:15:24 +0000 (13:15 -0500)]
gdb: remove COMPUNIT_OBJFILE macro

Remove the macro, update all users to use the getter directly.

Change-Id: I3f0fd6f4455d1c4ebd5da73b561eb18a979ef1f6

2 years agogdb: add getter/setter for compunit_symtab::objfile
Simon Marchi [Fri, 19 Nov 2021 18:11:24 +0000 (13:11 -0500)]
gdb: add getter/setter for compunit_symtab::objfile

Rename the field to m_objfile, and add a getter and a setter.  Update
all users.

Change-Id: If7e2f763ee3e70570140d9af9261b1b056253317

2 years agoAllow non-ASCII characters in Rust identifiers
Tom Tromey [Wed, 26 Jan 2022 22:39:03 +0000 (15:39 -0700)]
Allow non-ASCII characters in Rust identifiers

Rust 1.53 (quite a while ago now) ungated the support for non-ASCII
identifiers.  This didn't work in gdb.  This is PR rust/20166.

This patch fixes the problem by allowing non-ASCII characters to be
considered as identifier components.  It seemed simplest to just pass
them through -- doing any extra checking didn't seem worthwhile.

The new test also verifies that such characters are allowed in strings
and character literals as well.  The latter also required a bit of
work in the lexer.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20166

2 years agoFix Rust parser bug with function fields
Tom Tromey [Tue, 25 Jan 2022 01:02:38 +0000 (18:02 -0700)]
Fix Rust parser bug with function fields

In Rust, 'obj.f()' is a method call -- but '(obj.f)()' is a call of a
function-valued field 'f' in 'obj'.  The Rust parser in gdb currently
gets this wrong.  This is PR rust/24082.

The expression and Rust parser rewrites made this simple to fix --
simply wrapping a parenthesized expression in a new operation handles
it.  This patch has a slight hack because I didn't want to introduce a
new exp_opcode enumeration constant just for this.  IMO this doesn't
matter, since we should work toward removing dependencies on these
opcodes anyway; but let me know what you think of this.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24082

2 years agold: Add emultempl/emulation.em
H.J. Lu [Fri, 4 Feb 2022 19:04:15 +0000 (11:04 -0800)]
ld: Add emultempl/emulation.em

Add emultempl/emulation.em to define ld_${EMULATION_NAME}_emulation so
that new emulation hooks can be added easily.

* emultempl/aix.em (LDEMUL_AFTER_OPEN): New.
(LDEMUL_SET_OUTPUT_ARCH): Likewise.
(LDEMUL_CHOOSE_TARGET): Likewise.
(LDEMUL_BEFORE_ALLOCATION): Likewise.
(LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS): Likewise.
(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
(LDEMUL_PARSE_ARGS): Likewise.
(LDEMUL_ADD_OPTIONS): Likewise.
(LDEMUL_HANDLE_OPTION): Likewise.
(LDEMUL_UNRECOGNIZED_FILE): Likewise.
(LDEMUL_PRINT_SYMBOL): Likewise.
(ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/beos.em (gld_${EMULATION_NAME}_before_parse):
Renamed to ...
(gld${EMULATION_NAME}_before_parse): This.
(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
(gld${EMULATION_NAME}_set_symbols): This.
(gld_${EMULATION_NAME}_after_open): Renamed to ...
(gld${EMULATION_NAME}_after_open): This.
(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
(gld${EMULATION_NAME}_before_allocation): This.
(gld_${EMULATION_NAME}_get_script): Renamed to ...
(gld${EMULATION_NAME}_get_script): This.
(LDEMUL_AFTER_OPEN): New.
(LDEMUL_BEFORE_ALLOCATION): Likewise.
(LDEMUL_PLACE_ORPHAN): Likewise.
(LDEMUL_SET_SYMBOLS): Likewise.
(LDEMUL_ADD_OPTIONS): Likewise.
(LDEMUL_HANDLE_OPTION): Likewise.
(ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/elf.em (LDEMUL_AFTER_PARSE): New.
(LDEMUL_AFTER_OPEN): Likewise.
(LDEMUL_BEFORE_PLACE_ORPHANS): Likewise.
(LDEMUL_AFTER_ALLOCATION): Likewise.
(LDEMUL_SET_OUTPUT_ARCH): Likewise.
(LDEMUL_BEFORE_ALLOCATION): Likewise.
(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
(LDEMUL_PLACE_ORPHAN): Likewise.
(LDEMUL_ADD_OPTIONS): Likewise.
(LDEMUL_HANDLE_OPTION): Likewise.
(LDEMUL_LIST_OPTIONS): Likewise.
(LDEMUL_UNRECOGNIZED_FILE): Likewise.
(ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/emulation.em: New file.
* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/msp430.em (LDEMUL_AFTER_OPEN): New.
(LDEMUL_AFTER_ALLOCATION): Likewise.
(LDEMUL_PLACE_ORPHAN): Likewise.
(LDEMUL_FINISH): Likewise.
(LDEMUL_ADD_OPTIONS): Likewise.
(LDEMUL_HANDLE_OPTION): Likewise.
(LDEMUL_LIST_OPTIONS): Likewise.
(ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/pe.em (gld_${EMULATION_NAME}_before_parse): Renamed
to ...
(gld${EMULATION_NAME}_before_parse): This.
(gld_${EMULATION_NAME}_list_options): Renamed to ...
(gld${EMULATION_NAME}_list_options): This.
(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
(gld${EMULATION_NAME}_set_symbols): This.
(gld_${EMULATION_NAME}_after_parse): Renamed to ...
(gld${EMULATION_NAME}_after_parse): This.
(gld_${EMULATION_NAME}_after_open): Renamed to ...
(gld${EMULATION_NAME}_after_open): This.
(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
(gld${EMULATION_NAME}_before_allocation): This.
(gld_${EMULATION_NAME}_unrecognized_file): Renamed to ...
(gld${EMULATION_NAME}_unrecognized_file): This.
(gld_${EMULATION_NAME}_recognized_file): Renamed to ...
(gld${EMULATION_NAME}_recognized_file): This.
(gld_${EMULATION_NAME}_finish): Renamed to ...
(gld${EMULATION_NAME}_finish): This.
(gld_${EMULATION_NAME}_place_orphan): Renamed to ...
(gld${EMULATION_NAME}_place_orphan): This.
(gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ...
(gld${EMULATION_NAME}_open_dynamic_archive): This.
(gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ...
(gld${EMULATION_NAME}_find_potential_libraries): This.
(gld_${EMULATION_NAME}_get_script): Renamed to ...
(gld${EMULATION_NAME}_get_script): This.
(LDEMUL_AFTER_PARSE): New.
(LDEMUL_AFTER_OPEN): Likewise.
(LDEMUL_BEFORE_ALLOCATION): Likewise.
(LDEMUL_FINISH=): Likewise.
(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
(LDEMUL_PLACE_ORPHAN): Likewise.
(LDEMUL_SET_SYMBOLS): Likewise.
(LDEMUL_ADD_OPTIONS): Likewise.
(LDEMUL_HANDLE_OPTION): Likewise.
(LDEMUL_UNRECOGNIZED_FILE): Likewise.
(LDEMUL_LIST_OPTIONS): Likewise.
(LDEMUL_RECOGNIZED_FILE): Likewise.
(LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise.
(ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/pep.em (gld_${EMULATION_NAME}_before_parse): Renamed
to ...
(gld${EMULATION_NAME}_before_parse): This.
(gld_${EMULATION_NAME}_list_options): Renamed to ...
(gld${EMULATION_NAME}_list_options): This.
(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
(gld${EMULATION_NAME}_set_symbols): This.
(gld_${EMULATION_NAME}_after_parse): Renamed to ...
(gld${EMULATION_NAME}_after_parse): This.
(gld_${EMULATION_NAME}_after_open): Renamed to ...
(gld${EMULATION_NAME}_after_open): This.
(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
(gld${EMULATION_NAME}_before_allocation): This.
(gld_${EMULATION_NAME}_unrecognized_file): Renamed to ...
(gld${EMULATION_NAME}_unrecognized_file): This.
(gld_${EMULATION_NAME}_recognized_file): Renamed to ...
(gld${EMULATION_NAME}_recognized_file): This.
(gld_${EMULATION_NAME}_finish): Renamed to ...
(gld${EMULATION_NAME}_finish): This.
(gld_${EMULATION_NAME}_place_orphan): Renamed to ...
(gld${EMULATION_NAME}_place_orphan): This.
(gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ...
(gld${EMULATION_NAME}_open_dynamic_archive): This.
(gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ...
(gld${EMULATION_NAME}_find_potential_libraries): This.
(gld_${EMULATION_NAME}_get_script): Renamed to ...
(gld${EMULATION_NAME}_get_script): This.
(LDEMUL_AFTER_PARSE): New.
(LDEMUL_AFTER_OPEN): Likewise.
(LDEMUL_BEFORE_ALLOCATION): Likewise.
(LDEMUL_FINISH=): Likewise.
(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
(LDEMUL_PLACE_ORPHAN): Likewise.
(LDEMUL_SET_SYMBOLS): Likewise.
(LDEMUL_ADD_OPTIONS): Likewise.
(LDEMUL_HANDLE_OPTION): Likewise.
(LDEMUL_UNRECOGNIZED_FILE): Likewise.
(LDEMUL_LIST_OPTIONS): Likewise.
(LDEMUL_RECOGNIZED_FILE): Likewise.
(LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise.
(ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/ticoff.em (gld_${EMULATION_NAME}_list_options):
Renamed to ...
(gld${EMULATION_NAME}_list_options): This.
(gld_${EMULATION_NAME}_before_parse): Renamed to ...
(gld_${EMULATION_NAME}_get_script): Renamed to ...
(gld${EMULATION_NAME}_get_script): This.
(LDEMUL_ADD_OPTIONS): New.
(LDEMUL_HANDLE_OPTION): Likewise.
(LDEMUL_LIST_OPTIONS): Likewise.
(ld_${EMULATION_NAME}_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.
* emultempl/vanilla.em (LDEMUL_BEFORE_PARSE): New.
(LDEMUL_SET_OUTPUT_ARCH): Likewise.
(LDEMUL_GET_SCRIPT): Likewise.
(EMULATION_NAME): Likewise.
(OUTPUT_FORMAT): Likewise.
(ld_vanilla_emulation): Removed.
Source ${srcdir}/emultempl/emulation.em.

2 years agogdb/doc: update docs for 'info win' and 'winheight' commands
Andrew Burgess [Fri, 28 Jan 2022 11:49:54 +0000 (11:49 +0000)]
gdb/doc: update docs for 'info win' and 'winheight' commands

This started by noticing that the docs for 'winheight' are out of
date, the docs currently give a specific list of possible window
names.  However, now that windows can be implemented in Python, it is
not possible to list all possible names.

I now link the user to a mechanism by which they can discover the
valid names for themselves at run time (by using 'info win').  That,
and the fact that gdb provides tab-completion of the name at the
command line, feels good enough.

Finally, I noticed that the docs for 'win info' don't explicitly say
that the name of the window is given in the output.  This could
probably have been inferred, but given I'm now linking to this as a
mechanism to find the window name, I'd prefer to mention that the name
can be found in the output.

2 years agogdb/tui: add window width information to 'info win' output
Andrew Burgess [Mon, 24 Jan 2022 21:25:38 +0000 (21:25 +0000)]
gdb/tui: add window width information to 'info win' output

Now that we support horizontal window placement in the tui, it makes
sense to have 'info win' include the width, as well as the height, of
the currently visible windows.

That's what this commit does.  Example output is now:

  (gdb) info win
  Name       Lines Columns Focus
  src           12      40 (has focus)
  asm           12      41
  status         1      80
  cmd           11      80

I've added a NEWS entry, but the documentation was already suitably
vague, it just says that 'info win' displays the size of the visible
windows, so I don't think anything needs to be added there.

I've also added some tests, as far as I could find, the 'info win'
command was previously untested.

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 6 Feb 2022 00:00:16 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agox86: Skip undefined symbol when finishing DT_RELR
H.J. Lu [Sat, 5 Feb 2022 15:26:31 +0000 (07:26 -0800)]
x86: Skip undefined symbol when finishing DT_RELR

Don't abort for undefined symbol when finishing DT_RELR.  Instead, skip
undefined symbol.  Undefined symbol will be reported by relocate_section.

* elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Skip
undefined symbol in finishing phase.

2 years agoTweak assembler invocation for pr28827-1 test
Alan Modra [Sat, 5 Feb 2022 07:49:21 +0000 (18:19 +1030)]
Tweak assembler invocation for pr28827-1 test

PR 28827
* testsuite/ld-powerpc/pr28827-1.d: Pass -a64 to gas.

2 years agoPR28827 testcase
Alan Modra [Sat, 5 Feb 2022 05:06:58 +0000 (15:36 +1030)]
PR28827 testcase

This testcase triggers a stub sizing error with the patches applied
for PR28743 (commit 2f83249c13d8 and c804c6f98d34).

PR 28827
* testsuite/ld-powerpc/pr28827-1.s,
* testsuite/ld-powerpc/pr28827-1.d: New test.
* testsuite/ld-powerpc/powerpc.exp: Run it.

2 years agoEnable "size" as a dumpprog in ld
Alan Modra [Sat, 5 Feb 2022 07:05:09 +0000 (17:35 +1030)]
Enable "size" as a dumpprog in ld

binutils/
* testsuite/lib/binutils-common.exp (run_dump_test): Reference
global SIZE and SIZEFLAGS.
ld/
* testsuite/config/default.exp: Define SIZE and SIZEFLAGS.

2 years agoDetect .eh_frame_hdr earlier for SIZEOF_HEADERS
Alan Modra [Fri, 4 Feb 2022 09:00:47 +0000 (19:30 +1030)]
Detect .eh_frame_hdr earlier for SIZEOF_HEADERS

Current code detects the need for PT_GNU_EH_FRAME using a field set by
_bfd_elf_discard_section_eh_frame_hdr, which is called fairly late in
the linking process.  Use the elf hash table eh_info instead, which is
set up earlier by size_dynamic_sections.

* elf-bfd.h (struct output_elf_obj_tdata): Delete eh_frame_hdr.
(elf_eh_frame_hdr): Don't define.
(_bfd_elf_discard_section_eh_frame_hdr): Update prototype.
* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame_hdr): Delete
abfd parameter.  Don't set elf_eh_frame_hdr.
* elf.c (elf_eh_frame_hdr): New function.
(get_program_header_size): Adjust elf_eh_frame_hdr call.
(_bfd_elf_map_sections_to_segments): Likewise.

2 years agosim: mips: Add simulator support for mips32r6/mips64r6
Faraz Shahbazker [Wed, 2 Feb 2022 10:17:25 +0000 (11:17 +0100)]
sim: mips: Add simulator support for mips32r6/mips64r6

2022-02-01  Ali Lown  <ali.lown@imgtec.com>
    Andrew Bennett  <andrew.bennett@imgtec.com>
    Dragan Mladjenovic  <dragan.mladjenovic@rt-rk.com>
    Faraz Shahbazker  <fshahbazker@wavecomp.com>

sim/common/ChangeLog:
* sim-bits.h (EXTEND9, EXTEND18 ,EXTEND19, EXTEND21,
EXTEND26): New macros.

sim/mips/ChangeLog:
* Makefile.in (IGEN_INCLUDE): Add mips3264r6.igen.
* configure: Regenerate.
* configure.ac: Support mipsisa32r6 and mipsisa64r6.
(sim_engine_run): Pick simulator model from processor specified
in e_flags.
* cp1.c (value_fpr): Handle fmt_dc32.
(fp_unary, fp_binary): Zero initialize locals.
(update_fcsr, fp_classify, fp_rint, fp_r6_cmp, inner_fmac,
fp_fmac, fp_min, fp_max, fp_mina, fp_maxa, fp_fmadd, fp_fmsub):
New functions.
(sim_fpu_class_mips_mapping): New.
* cp1.h (fcsr_ABS2008_mask, fcsr_ABS2008_shift): New define.
* interp.c (MIPSR6_P): New.
(load_word): Allow unaligned memory access for MIPSR6.
* micromips.igen (sc, scd): Adapt to new do_sc* helper signature.
* mips.igen: Add *r6 models.
(signal_if_cti, forbiddenslot32): New helpers.
(delayslot32): Use signal_if_cti.
(do_sc, do_scd); Add store_ll_bit parameter.
(sc, scd): Adapt to previous change.
(nal, beq, bal): New definitions for *r6.
(sll): Split nop and ssnop cases into ...
(nop, ssnop): New definitions.
(loadstore_ea): Use the 32-bit compatibility adressing.
(cache): Split logic into ...
(do_cache): New helper.
(check_fpu): Select IEEE 754-2008 mode for R6.
(not_word_value, unpredictable, check_mt_hilo, check_mf_hilo,
check_multi_hilo, check_div_hilo, check_u64, do_dmfc1b, add,
li, addu, and, andi, bgez, bgtz, blez, bltz, bne, break, dadd,
daddiu, daddu, dror, dror32, drorv, dsll, dsll32, dsllv, dsra,
dsra32, dsrav, dsrl, dsrl32, dsub, dsubu, j, jal, jalr,
jalr.hb, lb, lbu, ld, lh, lhu, lui, lw, lwu, nor, or, ori, ror,
rorv, sb, sd, sh, sll, sllv, slt, slti, sltiu, sltu, sra, srav,
srl, srlv, sub, subu, sw, sync, syscall, teq, tge, tgeu, tlt,
tltu, tne, xor, xori, check_fmt_p, do_load_double,
do_store_double, abs.FMT, add.FMT, ceil.l.FMT, ceil.w.FMT,
cfc1, ctc1, cvt.d.FMT, cvt.l.FMT, cvt.w.FMT, div.FMT, dfmc1,
dmtc1, floor.l.FMT, floor.w.FMT, ldc1, lwc1, mfc1, mov.FMT,
mtc1, mul.FMT, recip.FMT, round.l.FMT, round.w.FMT, rsqrt.FMT,
sdc1, sqrt.FMT, sub.FMT, swc1, trunc.l.FMT, trunc.w.FMT, bc0f,
bc0fl, bc0t, bc0tl, dmfc0, dmtc0, eret, mfc0, mtc0, cop, tlbp,
tlbr, tlbwi, tlbwr): Enable on *r6 models.
* mips3264r2.igen (dext, dextm, dextu, di, dins, dinsm, dinsu,
dsbh, dshd, ei, ext, mfhc1, mthc1, ins, seb, seh, synci, rdhwr,
wsbh): Likewise.
* mips3264r6.igen: New file.
* sim-main.h (FP_formats): Add fmt_dc32.
(FORBIDDEN_SLOT): New macros.
(simFORBIDDENSLOT, FP_R6CMP_*, FP_R6CLASS_*): New defines.
(fp_r6_cmp, fp_classify, fp_rint, fp_min, fp_max, fp_mina,
fp_maxa, fp_fmadd, fp_fmsub): New declarations.
(R6Compare, Classify, RoundToIntegralExact, Min, Max, MinA,
MaxA, FusedMultiplyAdd, FusedMultiplySub): New macros. Wrapping
previous declarations.

sim/testsuite/mips/ChangeLog:
* basic.exp: Add r6-*.s tests.
(run_r6_removed_test): New function.
(run_endian_tests): New function.
* hilo-hazard-3.s: Skip for mips*r6.
* r2-fpu.s: New test.
* r6-64.s: New test.
* r6-branch.s: New test.
* r6-forbidden.s: New test.
* r6-fpu.s: New test.
* r6-llsc-dp.s: New test.
* r6-llsc-wp.s: New test.
* r6-removed.csv: New test.
* r6-removed.s: New test.
* r6.s: New test.
* utils-r6.inc: New inc.

2 years agosim: Add partial support for IEEE 754-2008
Faraz Shahbazker [Wed, 2 Feb 2022 10:17:24 +0000 (11:17 +0100)]
sim: Add partial support for IEEE 754-2008

2022-02-01  Faraz Shahbazker  <fshahbazker@wavecomp.com>

sim/common/ChangeLog:
* sim-fpu.c (sim_fpu_minmax_nan): New.
(sim_fpu_max): Add variant behaviour for IEEE 754-2008.
(sim_fpu_min): Likewise.
(sim_fpu_is_un, sim_fpu_is_or): New.
(sim_fpu_un, sim_fpu_or): New.
(sim_fpu_is_ieee754_2008, sim_fpu_is_ieee754_1985): New.
(sim_fpu_set_mode): New.
(sim_fpu_classify): New.
* sim-fpu.h (sim_fpu_minmax_nan): New declaration.
(sim_fpu_un, sim_fpu_or): New declarations.
(sim_fpu_is_un, sim_fpu_is_or): New declarations.
(sim_fpu_mode): New enum.
[sim_fpu_state](current_mode): New field.
(sim_fpu_current_mode): New define.
(sim_fpu_is_ieee754_2008): New declaration.
(sim_fpu_is_ieee754_1985): New declaration.
(sim_fpu_set_mode): New declaration.
(sim_fpu_classify): New declaration.

2 years agosim: Factor out NaN handling in floating point operations
Faraz Shahbazker [Wed, 2 Feb 2022 10:17:23 +0000 (11:17 +0100)]
sim: Factor out NaN handling in floating point operations

2022-02-01  Faraz Shahbazker  <fshahbazker@wavecomp.com>

sim/common/ChangeLog:
* sim-fpu.c (sim_fpu_op_nan): New.
(sim_fpu_add): Factor out NaN operand handling with
a call to sim_fpu_op_nan.
(sim_fpu_sub, sim_fpu_mul, sim_fpu_div): Likewise.
(sim_fpu_rem, sim_fpu_max, sim_fpu_min): Likewise.
* sim-fpu.h (sim_fpu_op_nan): New declaration.

2 years agosim: Allow toggling of quiet NaN-bit semantics
Faraz Shahbazker [Wed, 2 Feb 2022 10:17:22 +0000 (11:17 +0100)]
sim: Allow toggling of quiet NaN-bit semantics

IEEE754-1985 specifies the top bit of the mantissa as an indicator
of signalling vs. quiet NaN, but does not define the precise semantics.
Most architectures treat this bit as indicating quiet NaN, but legacy
(pre-R6) MIPS goes the other way and treats it as signalling NaN.

This used to be controlled by a macro that was only defined for MIPS.
This patch replaces the macro with a variable to track the current
semantics of the NaN bit and allows differentiation between older
(pre-R6) and and newer MIPS cores.

2022-02-01  Faraz Shahbazker  <fshahbazker@wavecomp.com>

sim/common/ChangeLog:
* sim-fpu.c (_sim_fpu): New.
(pack_fpu, unpack_fpu): Allow reversal of quiet NaN semantics.
* sim-fpu.h (sim_fpu_state): New struct.
(_sim_fpu): New extern.
(sim_fpu_quiet_nan_inverted): New define.

sim/mips/ChangeLog:
* cp1.h (fcsr_NAN2008_mask, fcsr_NAN2008_shift): New.
* mips.igen (check_fpu): Select default quiet NaN mode
for legacy MIPS.
* sim-main.h (SIM_QUIET_NAN_NEGATED): Remove.

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 5 Feb 2022 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agold: Remove emultempl/armcoff.em
H.J. Lu [Fri, 4 Feb 2022 19:33:05 +0000 (11:33 -0800)]
ld: Remove emultempl/armcoff.em

Remove emultempl/armcoff.em which has been unused after

commit 2ac93be706418f3b2aebeb22159a328023faed52
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Apr 16 20:33:36 2018 +0930

    Remove arm-aout and arm-coff support

    This also removes arm-netbsd (not arm-netbsdelf!), arm-openbsd, and
    arm-riscix.  Those targets weren't on the obsolete list but they are
    all aout, and it doesn't make all that much sense to remove arm-aout
    without removing them too.

* emultempl/armcoff.em: Removed.

2 years agogdb: include jit_code_entry::symfile_addr value in names of objfiles created by jit...
Simon Marchi [Wed, 2 Feb 2022 15:54:03 +0000 (10:54 -0500)]
gdb: include jit_code_entry::symfile_addr value in names of objfiles created by jit reader API

This commit includes the JIT object's symfile address in the names of
objfiles created by JIT reader API (e.g., << JIT compiled code at
0x7ffd8a0c77a0 >>).  This allows one to at least differentiate one from
another.

The address is the one that the debugged program has put in
jit_code_entry::symfile_addr, and that the JIT reader's read function
receives.  As we can see in gdb.base/jit-reader-host.c and
gdb.base/jit-reader.c, that may not be the actual value of where the
JIT-ed code is.  But it is a value chosen by the author of the JIT
engine and the JIT reader, so including this value in the objfile name
may help them correlate the JIT objfiles created by with their logs /
data structures.

To access this field, we need to pass down a reference to the
jit_code_entry.  So make jit_dbg_reader_data a structure (instead of an
alias for a CORE_ADDR) that includes the address of the code entry in
the inferior's address space (the previous meaning of
jit_dbg_reader_data) plus a reference to the jit_code_entry as read into
GDB's address space.  And while at it, pass down the gdbarch, so that we
don't have to call target_gdbarch.

Co-Authored-By: Jan Vrany <jan.vrany@labware.com>
Change-Id: Ib26c4d1bd8de503d651aff89ad2e500cb312afa5