Commit Graph

118236 Commits

Author SHA1 Message Date
Alan Modra
0ab0435fe6 Re: USE_MMAP fuzzed object file attacks
I committed a broken patch.

	* aoutx.h (aout_get_external_symbols): Remove wrong #else and
	unneeded casts.
	* pdp11.c (aout_get_external_symbols): Likewise.
2024-04-04 13:19:42 +10:30
Alan Modra
9fd82d9142 Fix uninitialised variable errors
Commit c6291d749a introduced a number of errors, found by clang.

elf.c:456:7: error: variable 'alloc_ext_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elf.c:464:7: error: variable 'alloc_extshndx_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
  if (bfd_seek (ibfd, pos, SEEK_SET) != 0
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elflink.c:2837:11: error: variable 'alloc1_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
      if (internal_relocs == NULL)
          ^~~~~~~~~~~~~~~~~~~~~~~
elflink.c:12595:16: error: variable 'ext_size' set but not used [-Werror,-Wunused-but-set-variable]
                      size_t ext_size = 0;

	* elf.c (bfd_elf_get_elf_syms): Fix use of uninitialised variables.
	* elflink.c (_bfd_elf_link_info_read_relocs): Likewise.
	(bfd_elf_final_link): Fix set but not used warning.
2024-04-04 11:33:13 +10:30
Alan Modra
b86d3af60f USE_MMAP fuzzed object file attacks
If mmap is used without sanity checking, then we'll get a SIGBUS if
an access is done to the mmap'd memory corresponding to a page past
end of file.

	* aoutx.h (aout_get_external_symbols): Check that mmap regions
	are within file contents.  Catch stringsize overflow.
	(some_aout_object_p): Don't clear already zeroed fields.  Tidy.
	* pdp11.c: As for aoutx.h.  Copy some fixes too.
2024-04-04 10:30:47 +10:30
GDB Administrator
7e217ee2c0 Automatic date update in version.in 2024-04-04 00:00:08 +00:00
H.J. Lu
a9505c7420 elf: Add _bfd_elf_link_m[un]map_section_contents
To copy input section contents, add _bfd_elf_link_mmap_section_contents
and _bfd_elf_link_munmap_section_contents to mmap in the input sections.

	* elf-bfd.h (_bfd_elf_link_mmap_section_contents): New.
	(_bfd_elf_link_munmap_section_contents): Likewise.
	* elf.c (elf_mmap_section_contents): New.
	(_bfd_elf_mmap_section_contents): Use it.
	(_bfd_elf_link_mmap_section_contents): New.
	(_bfd_elf_link_munmap_section_contents): Likewise.
	* elflink.c (elf_link_input_bfd): Call
	_bfd_elf_link_mmap_section_contents instead of
	bfd_get_full_section_contents.  Call
	_bfd_elf_link_munmap_section_contents to munmap the section
	contents.
	(bfd_elf_final_link): When mmap is used, initialize
	max_contents_size to _bfd_minimum_mmap_size and increase it
	for compressed or linker created sections or sections whose
	rawsize != size.
2024-04-03 09:11:03 -07:00
H.J. Lu
3428c771ae elf: Always keep symbol table and relocation info for eh_frame
When --no-keep-memory is used, the symbol table and relocation info for
eh_frame are freed after they are retrieved for each text section in the
input object.  If an input object has many text sections, the same data
is retrieved and freed many times which can take a very long time.
Update _bfd_elf_gc_mark to keep the symbol table and relocation info for
eh_frame to avoid it.  Data to link the 3.5GB clang executable in LLVM
17 debug build on Linux/x86-64 with 32GB RAM is:

		before		after		improvement
user		86.31		86.44		-0.2%
system		8.77		8.63		1.6%
total		95.58		96.81		-1.3%
maximum set(GB)	13.1		13.1		0%
page faults	3024752		3028699		-1.3%

and data to link the 275M cc1plus executable in GCC 14 stage 1 build is:

user		5.49		5.46		-0.5%
system		0.73		0.73		0%
total		6.26		6.25		0.3%
maximum set(MB)	964		964		0%
page faults	235173		235796		-0.3%

The memory usage impact is minimum and the link time of the Rust binary
in

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

is reduced from 500+ seconds to 1.44 seconds, a 300x speedup.

	PR ld/31466
	* elflink.c (init_reloc_cookie): Add a bool argument, keep_memory,
	for keeping memory.  Always keep memory if keep_memory is true.
	(init_reloc_cookie_rels): Likewise
	(init_reloc_cookie_for_section): Add a bool argument for keeping
	memory and pass it to init_reloc_cookie and
	init_reloc_cookie_rels.
	(_bfd_elf_gc_mark_reloc): Pass false to _bfd_elf_gc_mark.
	(_bfd_elf_gc_mark): Pass true to init_reloc_cookie_for_section
	for the eh_frame section.  Pass false to
	init_reloc_cookie_for_section for other sections.
	(_bfd_elf_gc_mark_extra_sections): Add Add a bool argument for
	keeping memory and pass it to _bfd_elf_gc_mark.
	(bfd_elf_parse_eh_frame_entries): Pass false to init_reloc_cookie
	and init_reloc_cookie_rels.
	(bfd_elf_gc_sections): Pass false to init_reloc_cookie_for_section
	and _bfd_elf_gc_mark.
	(bfd_elf_discard_info): Pass false to
	init_reloc_cookie_for_section and init_reloc_cookie.
2024-04-03 09:11:03 -07:00
H.J. Lu
d41b764855 elf: Don't cache symbol nor relocation tables with mmap
During a "-j 8" LLVM 17 debug build on a machine with 32GB RAM and 16GB
swap, ld was killed by kernel because of out of memory:

[79437.949336] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/session-9.scope,task=ld,pid=797431,uid=1000
[79437.949349] Out of memory: Killed process 797431 (ld) total-vm:9219600kB, anon-rss:6558156kB, file-rss:1792kB, shmem-rss:0kB, UID:1000 pgtables:17552kB oom_score_adj:0

Don't cache symbol nor relocation tables if they are mapped in.  Data to
link the 3.5GB clang executable in LLVM 17 debug build on Linux/x86-64
with 32GB RAM is:

		stdio		mmap		improvement
user		86.73		87.02		-0.3%
system		9.55		9.21		3.6%
total		100.40		97.66		0.7%
maximum set(GB)	17.34		13.14		24%
page faults	4047667		3042877		25%

and data to link the 275M cc1plus executable in GCC 14 stage 1 build is:

user		5.41		5.44		-0.5%
system		0.80		0.76		5%
total		6.25		6.26		-0.2%
maximum set(MB)	1323		968		27%
page faults	323451		236371		27%

These improve the overall system performance for parallel build by
reducing memory usage and page faults.

Also rename _bfd_link_keep_memory to _bfd_elf_link_keep_memory.  Since
the --no-keep-memory linker option causes:

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

this is opt-in by each backend.

bfd/

	* elf32-i386.c (elf_i386_scan_relocs): Remove
	_bfd_link_keep_memory.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
	* elflink.c (_bfd_elf_link_keep_memory): New.
	(_bfd_elf_link_iterate_on_relocs): Replace _bfd_link_keep_memory
	with _bfd_elf_link_keep_memory.
	(elf_link_add_object_symbols): Likewise.
	(init_reloc_cookie): Likewise.
	(init_reloc_cookie_rels): Likewise.
	* libbfd-in.h (_bfd_link_keep_memory): Removed.
	* linker.c (_bfd_link_keep_memory): Likewise.
	* libbfd.h: Regenerated.
2024-04-03 09:11:03 -07:00
H.J. Lu
c6291d749a elf: Use mmap to map in symbol and relocation tables
Add _bfd_mmap_read_temporary to mmap in symbol tables and relocations
whose sizes >= 4 * page size.  For the final link, allocate an external
relocation buffer of 4 * page size to avoid using mmap and munmap on
smaller relocation sections.  Since _bfd_mmap_read_temporary allocates
buffer as needed, its callers don't need to.

When mmap is used to map in all ELF sections, data to link the 3.5GB
clang executable in LLVM 17 debug build on Linux/x86-64 with 32GB RAM
is:

		stdio		mmap		improvement
user		84.79		85.27		-0.5%
system		10.95		9.09		17%
total		97.91		94.90		3%
page faults	4837944		4033778		17%

and data to link the 275M cc1plus executable in GCC 14 stage 1 build
is:

user		5.31		5.33		-0.4%
system		0.86		0.76		12%
total		6.19		6.13		1%
page faults	361273		322491		11%

	* elf.c (bfd_elf_get_elf_syms): Don't allocate buffer for external
	symbol table.  Replace bfd_read with _bfd_mmap_read_temporary.
	* elflink.c (elf_link_read_relocs_from_section): Add 2 arguments
	to return mmap memory address and size.
	(_bfd_elf_link_info_read_relocs): Don't allocate buffer for
	external relocation information.  Replace bfd_read with
	_bfd_mmap_read_temporary.
	(bfd_elf_final_link): Cache external relocations up to
	_bfd_minimum_mmap_size bytes when mmap is used.
	* libbfd.c (_bfd_mmap_read_temporary): New.
	* libbfd-in.h (_bfd_mmap_read_temporary): Likewise.
	* libbfd.h: Regenerated.
2024-04-03 09:11:03 -07:00
H.J. Lu
584b30e4b3 elf: Add _bfd_elf_m[un]map_section_contents
Add _bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents.
A backend must opt-in to use mmap.  It should replace

bfd_malloc_and_get_section -> _bfd_elf_mmap_section_contents
free			   -> _bfd_elf_munmap_section_contents

on section contents.

	* compress.c (bfd_get_full_section_contents): Don't allocate
	buffer if mmapped_p is true.
	* elf-bfd.h (elf_backend_data): Add use_mmap.
	(bfd_elf_section_data): Add contents_addr and contents_size.
	(_bfd_elf_mmap_section_contents): New.
	(_bfd_elf_munmap_section_contents): Likewise.
	* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Replace
	bfd_malloc_and_get_section and free with
	_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
	on section contents.
	* elf-sframe.c (_bfd_elf_parse_sframe): Likewise.
	* elf.c (_bfd_elf_make_section_from_shdr): Replace
	bfd_malloc_and_get_section and free with
	_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
	on section contents.
	(_bfd_elf_print_private_bfd_data): Likewise.
	(_bfd_elf_mmap_section_contents): New.
	(_bfd_elf_munmap_section_contents): Likewise.
	* elf32-i386.c (elf_i386_scan_relocs): Replace
	bfd_malloc_and_get_section and free with
	_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
	on section contents.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
	(elf_x86_64_get_synthetic_symtab): Likewise.
	* elfcode.h (elf_checksum_contents): Likewise.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	(bfd_elf_get_bfd_needed_list): Likewise.
	* elfxx-target.h (elf_backend_use_mmap): New.
	(elfNN_bed): Add elf_backend_use_mmap.
	* elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Replace
	bfd_malloc_and_get_section and free with
	_bfd_elf_mmap_section_contents and _bfd_elf_munmap_section_contents
	on section contents.
	(_bfd_x86_elf_get_synthetic_symtab): Replace free with
	_bfd_elf_munmap_section_contents.
	* elfxx-x86.h (elf_backend_use_mmap): New.
	* libbfd.c: Include "elf-bfd.h".
	(_bfd_generic_get_section_contents): Call bfd_mmap_local for
	mmapped_p.
	* opncls.c (_bfd_delete_bfd): Also munmap ELF section contents.
	* section.c (asection): Add mmapped_p.
	(BFD_FAKE_SECTION): Updated.
	(bfd_malloc_and_get_section): Add a sanity check for not
	mmapped_p.
	* bfd-in2.h: Regenerated.
2024-04-03 09:11:03 -07:00
H.J. Lu
9ba56acee5 elf: Use mmap to map in read-only sections
There are many linker input files in LLVM debug build with huge string
sections.  All these string sections can be treated as read-only.  But
linker copies all of them into memory which consumes huge amount of
memory and slows down linker significantly.

Add _bfd_mmap_readonly_persistent and _bfd_mmap_readonly_temporary to
mmap in reado-only sections with size >= 4 * page size.

NB: All string sections in valid ELF inputs must be null terminated.
There is no need to terminate it again and string sections are mmapped
as read-only.

	* bfd.c (bfd_mmapped_entry): New.
	(bfd_mmapped): Likewise.
	(bfd): Add mmapped.
	* bfdwin.c (bfd_get_file_window): Use _bfd_pagesize.
	* cache.c (cache_bmmap): Remove pagesize_m1 and use pagesize_m1
	instead.
	* elf.c (bfd_elf_get_str_section): Call
	_bfd_mmap_readonly_persistent instead of _bfd_alloc_and_read.
	Don't terminate the string section again.
	(get_hash_table_data): Call _bfd_mmap_readonly_temporary and
	_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
	and free.
	(_bfd_elf_get_dynamic_symbols): Call _bfd_mmap_readonly_persistent
	instead of _bfd_alloc_and_read.  Don't terminate the string
	section again.  Call _bfd_mmap_readonly_temporary and
	_bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
	and free.
	(_bfd_elf_slurp_version_tables): Call _bfd_mmap_readonly_temporary
	and _bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
	and free.
	* elflink.c (bfd_elf_link_record_dynamic_symbol): Use bfd_malloc
	to get the unversioned symbol.
	* libbfd-in.h (_bfd_pagesize): New.
	(_bfd_pagesize_m1): Likewise.
	(_bfd_minimum_mmap_size): Likewise.
	(_bfd_mmap_readonly_persistent): Likewise.
	(_bfd_mmap_readonly_temporary): Likewise.
	(_bfd_munmap_readonly_temporary): Likewise.
	* libbfd.c
	(bfd_allocate_mmapped_page): New.
	(_bfd_mmap_readonly_temporary): Likewise.
	(_bfd_munmap_readonly_temporary): Likewise.
	(_bfd_mmap_readonly_persistent): Likewise.
	(_bfd_pagesize): Likewise.
	(_bfd_pagesize_m1): Likewise.
	(_bfd_minimum_mmap_size): Likewise.
	(bfd_init_pagesize): Likewise.
	* lynx-core.c (lynx_core_file_p): Use _bfd_pagesize.
	* opncls.c (_bfd_delete_bfd): Munmap tracked mmapped memories.
	* sysdep.h (MAP_ANONYMOUS): New. Define if undefined.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.
2024-04-03 09:11:00 -07:00
Lancelot SIX
f89ae595dd Revert "gdb/compile: Use std::filesystem::remove_all in cleanup"
This reverts commit 7bba0ad085.

Tom de Vries reported that 7bba0ad085 (gdb/compile: Use
std::filesystem::remove_all in cleanup) broke builds with gcc-7.5.0
which mostly supports c++17, but not std::filesystem[1].  As this change
is not critical, revert it to maintain compatibility.

[1] https://inbox.sourceware.org/gdb-patches/a06e6483-aa2e-4b8a-854f-e369a1e961ea@suse.de/

Change-Id: I58150bd27600c95052bdf1bbbd6b44718a5a0bbf
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31420
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-03 16:30:48 +01:00
Tankut Baris Aktemur
3d7d77d747 doc: add the missing 'handle' attribute in xml
The XML response to the "qXfer:threads:read" packet may include
a "handle" attribute.  The attribute is mentioned in the document
but not shown in the sample XML structure.  Add it.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-04-03 16:44:43 +02:00
Lancelot SIX
7bba0ad085 gdb/compile: Use std::filesystem::remove_all in cleanup
In a previous review, I noticed that some code in gdb/compile/compile.c
could use c++17's `std::filesystem::remove_all` instead of using some
`system ("rm -rf ...");`.

This patch implements this.

Note that I use the noexcept overload of std::filesystem::remove_all and
explicitly check for an error code.  This means that this code called
during the cleanup procedure cannot throw, and does not risk preventing
other cleanup functions to be called.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31420
Change-Id: If5668bf3e15e66c020e5c3b4fa999f861690e4cf
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-03 13:53:32 +01:00
Lancelot SIX
e73b04d265 gdb: ensure has dwarf info before reading DWZ file
I recent change (e9b738dfbd "Avoid race when reading dwz file") moved
the call to dwarf2_read_dwz_file from dwarf2_initialize_objfile to
dwarf2_has_info.

Before that patch, dwarf2_initialize_objfile was only called when
dwarf2_has_info returned true, and since that patch it is always called.

When reading a file that has no debug info (.debug_info/.debug_abbrev
sections), but has a .gnu_debugaltlink section, GDB’s behavior is
different.  I can observe this when loading
/lib/x86_64-linux-gnu/libtinfo.so on Ubuntu 22.04 (or while debugging
any program dynamically loading this library).

Before e9b738dfbd, we had:

    $ ./gdb/gdb -data-directory ./gdb/data-directory -q  /lib/x86_64-linux-gnu/libtinfo.so
    Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so...
    (No debugging symbols found in /lib/x86_64-linux-gnu/libtinfo.so)
    (gdb)

while after we have:

    $ ./gdb/gdb -data-directory ./gdb/data-directory -q  /lib/x86_64-linux-gnu/libtinfo.so
    Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so...

    warning: could not find '.gnu_debugaltlink' file for /usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
    (No debugging symbols found in /lib/x86_64-linux-gnu/libtinfo.so)
    (gdb)

This patch restores the previous behavior of only trying to load the
DWZ file for objfiles when the main part of the debuginfo is present
(i.e. when dwarf2_has_info returns true).  We still make sure that
dwarf2_read_dwz_file is called at most once per objfile.

A consequence of this change is that the per_bfd->dwz_file optional
object can now remain empty (instead of containing a nullptr), so also
this patch also adjusts dwarf2_get_dwz_file to account for this
possibility.  This effectively reverts the changes to
dwarf2_get_dwz_file done by e9b738dfbd.

Regression tested on x86_64-linux-gnu Ubuntu 22.04.

Approved-By: Tom Tromey <tom@tromey.com>
2024-04-03 13:47:03 +01:00
Nick Clifton
301bfc45ab Fix null pointer dereference in process_debug_info() 2024-04-03 11:19:33 +01:00
Nick Clifton
28b24770bb Extend objdump's --show-all-symbols option so that it also shows the extra symbols referenced by an instruction. 2024-04-03 11:17:19 +01:00
Jan Beulich
b1c4af2086 Arm64: check tied operand specifier in aarch64-gen
Make sure that field actually matches the specified operands. Don't
follow existing F_PSEUDO checking in using assertions, though. Print
meaningful error messages, thus - while not having a line number
available - at least providing some indication of where things are
wrong.

Fix SVE2.1's extq accordingly, but don't extend the testsuite there:
There are further issues with its operands (SVE_Zm_imm4 doesn't look to
be correct to use there, as that describes an indexed vector register,
while here a separate vector register and immediate operand are to be
specified).
2024-04-03 10:42:44 +02:00
Jan Beulich
ef9a6314d8 x86: add missing No_qSuf to non-64-bit PTWRITE
While largely benign, it still should have been put there when the
original single template was split (commit a04973848d).
2024-04-03 10:41:30 +02:00
Jan Beulich
0006623c18 x86: drop stray Size64 from WRSSQ
Like for WRUSSQ it's not needed here. The legacy insn had gained it in
the course of zapping Rex64, but that attribute wasn't needed here
either. The APX insn then simply gained it by copy-and-paste, I suppose.
2024-04-03 10:40:57 +02:00
Cui, Lili
8963a60d7b x86/APX: Remove KEYLOCKER and SHA promotions from EVEX MAP4
APX spec removed KEYLOCKER and SHA promotions from EVEX MAP4.
https://www.intel.com/content/www/us/en/developer/articles/technical/advanced-performance-extensions-apx.html

gas/ChangeLog:

        * NEWS: Mention that remove KEYLOCKER and SHA promotions from EVEX
	* MAP4.
        * config/tc-i386.c (process_operands): Removed special handling of
	* KEYLOCKER and SHA.
        * testsuite/gas/i386/x86-64-apx-egpr-promote-inval.l: Removed KEYLOCKER
        * and SHA instructions.
        * testsuite/gas/i386/x86-64-apx-egpr-promote-inval.s: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-bad.s: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-intel.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted-wig.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.d: Ditto.
        * testsuite/gas/i386/x86-64-apx-evex-promoted.s: Ditto.

opcodes/ChangeLog:

        * i386-dis-evex-prefix.h: Removed KEYLOCKER and SHA instructions.
        * i386-dis-evex.h: Ditto.
        * i386-opc.tbl: Ditto.
        * i386-dis.c (print_vector_reg): Removed special handling of KEYLOCKER
	*  and SHA.
2024-04-03 09:50:00 +08:00
GDB Administrator
a0635511a8 Automatic date update in version.in 2024-04-03 00:00:14 +00:00
Tom Tromey
b1741ab0da libiberty: Invoke D demangler when --format=auto
Investigating GDB PR d/31580 showed that the libiberty demangler
doesn't automatically demangle D mangled names.  However, I think it
should -- like C++ and Rust (new-style), D mangled names are readily
distinguished by the leading "_D", and so the likelihood of confusion
is low.  The other non-"auto" cases in this code are Ada (where the
encoded form could more easily be confused by ordinary programs) and
Java (which is long gone, but which also shared the C++ mangling and
thus was just an output style preference).

This patch also fixed another GDB bug, though of course that part
won't apply to the GCC repository.

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

libiberty
	* cplus-dem.c (cplus_demangle): Try the D demangler with
	"auto" format.
	* testsuite/d-demangle-expected: Add --format=auto test.
2024-04-02 13:53:13 -06:00
Tom Tromey
251cedaeb5 Print type name when printing Rust slice
The recent change to how unsized Rust values are printed included a
small regression from past behavior.  Previously, a slice's type would
be printed, like:

    (gdb) print slice
    $80 = &[i32] [3]

The patch changed this to just

    (gdb) print slice
    $80 = [3]

This patch restores the previous behavior.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30330
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31517
2024-04-02 11:37:32 -06:00
Tom Tromey
051889c810 Constify ada-lex.l:attributes
While examining the Ada parser globals with 'nm', I noticed that the
lexer's "attributes" array should be const.  This change moves it into
read-only storage.
2024-04-02 11:24:27 -06:00
Tom Tromey
0298128e07 Remove "numbuf" global
The lexer has a "numbuf" global that is only used for temporary
storage.  This patch removes the global and redeclares it at the
points of use.
2024-04-02 11:24:27 -06:00
Tom Tromey
33a03c1213 Move "returned_complete" into ada_parse_state
This moves the "returned_complete" global into ada_parse_state.
2024-04-02 11:24:27 -06:00
Tom Tromey
d9346cbfcb Move "paren_depth" into ada_parse_state
This moves the "paren_depth" global into ada_parse_state.
2024-04-02 11:24:27 -06:00
Tom Tromey
65586abcf3 Move "temp_parse_space" into ada_parse_state
This patch moves the "temp_parse_space" global into ada_parse_state.
It is also renamed to remove the redundant "parse".  Finally, it is
changed to an auto_obstack to avoid the need for any manual
management.
2024-04-02 11:24:27 -06:00
Tom Tromey
ed08e2b371 Move "iterated_associations" into ada_parse_state
This patch moves the "iterated_associations" global into
ada_parse_state.
2024-04-02 11:24:27 -06:00
Tom Tromey
06c3813858 Move "assignments" global into ada_parse_state
This patch moves the "assignments" global into ada_parse_state.
2024-04-02 11:24:27 -06:00
Tom Tromey
68d7f5b02f Move "components" and "associations" into ada_parse_state
This patch moves the "components" and "associations" globals into
ada_parse_state.
2024-04-02 11:24:27 -06:00
Tom Tromey
48497d85e3 Move "int_storage" global into ada_parse_state
This patch moves the "int_storage" global into ada_parse_state.
2024-04-02 11:24:27 -06:00
Tom Tromey
b64e3e1c36 Introduce ada_parse_state
This patch introduces the ada_parse_state class and the ada_parser
global.  It also changes find_completion_bounds to be a method of this
new type.

Note that find_completion_bounds never used its parameter; and because
it is generally fine to use the 'pstate' global throughout the parser,
this patch removes the parameter entirely.
2024-04-02 11:24:27 -06:00
Tom Tromey
542ea7fe46 Implement Ada 2022 iterated assignment
Ada 2022 includes iterated assignment for array initialization.  This
patch implements a subset of this for gdb.  In particular, only arrays
with integer index types really work -- currently there's no decent
way to get the index type in EVAL_AVOID_SIDE_EFFECTS mode during
parsing.  Fixing this probably requires the Ada parser to take a
somewhat more sophisticated approach to type resolution; and while
this would help fix another bug in this area, this patch is already
useful without it.
2024-04-02 11:24:27 -06:00
Tom Tromey
d9d782dd8b Introduce and use aggregate_assigner type
This patch is a refactoring to add a new aggregate_assigner type.
This type is passed to Ada aggregate assignment operations in place of
passing a number of separate arguments.  This new approach makes it
simpler to change some aspects of aggregate assignment behavior.
2024-04-02 11:24:26 -06:00
Tom Tromey
c2cf30e760 Run isort
This patch is the result of running 'isort .' in the gdb directory.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 11:21:39 -06:00
Tom Tromey
68982f618b Prepare gdb for isort
This patch prepares gdb for isort: it adds a couple of isort marker
comments where needed, and it adds an isort clause to setup.cfg.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 11:21:31 -06:00
Tom Tromey
e2238b2e20 Do not use bare "except"
flake8 warns about a bare "except".  The docs point out that this will
also catch KeyboardInterrupt and SystemExit exceptions, which is
normally undesirable.  Using "except Exception" catches everything
reasonable, so this patch makes this change.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:37 -06:00
Tom Tromey
34b0776fd7 Suppress some "undefined" warnings from flake8
flake8 warns about some identifiers in __init__.py, because it does
not realize these come from the star-imported _gdb module.  This patch
suppresses these warnings.
2024-04-02 10:58:37 -06:00
Tom Tromey
99364b187f Specify ImportError in styling.py
styling.py has a long try/except surrounding most of the body.  flake8
warns about the final bare "except".  However, this except is really
only there to catch the situation where the host doesn't have Pygments
installed.  This patch changes this to only catch ImportError.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:37 -06:00
Tom Tromey
788050bf18 Suppress star import errors
flake8 warns about the "from _gdb.disassembler import *" line in
disassembler.py, and a similar line from __init__.py.  These line are
needed to re-export names from the corresponding C++ module, so this
patch applies the appropriate "noqa" flags.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:37 -06:00
Tom Tromey
80c69af864 Remove bare "except" from disassembler.py
flake8 complains about a bare "except" in disassembler.py.  In this
case, the code purports to guard against some kind of user error
involving data structure corruption.  I think it's better here to just
let the error occur -- py-disasm.c will show a stack trace in this
case.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:37 -06:00
Tom Tromey
5ac754cf46 Remove unused import from gdb/__init__.py
flake8 points out that the import of _gdb in gdb/__init__.py is
unused.  Remove it.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:37 -06:00
Tom Tromey
a311bd9e2b Ignore unsed import in dap/__init__.py
flake8 warns about dap/__init__.py because it has a number of unused
imports.  Most of these are intentional: the import is done to ensure
that the a DAP request is registered with the server object.

This patch applies a "noqa" comment to these imports, and also removes
one import that is truly unnecessary.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:37 -06:00
Tom Tromey
2fde5149d7 Fix flake8 errors in dap/server.py
Commit 032d23a6 ("Fix stray KeyboardInterrupt after cancel")
introduced some errors into dap/server.py.  A function is called but
not imported, and the wrong variable name is used.  This patch
corrects both errors.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:37 -06:00
Tom Tromey
8a99b2b817 Remove .flake8
I re-ran flake8 today and was puzzled to see W503 warnings.
Eventually I found out that the setup.cfg config overrides .flake8.
This patch merges the two and removes .flake8, to avoid future
confusion.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-04-02 10:58:36 -06:00
Tom de Vries
374c1cbbf0 [gdb/testsuite] Add missing include in gdb.base/ctf-ptype.c
On fedora rawhide, when running test-case gdb.base/ctf-ptype.exp, I get:
...
gdb compile failed, ctf-ptype.c: In function 'main':
ctf-ptype.c:242:29: error: implicit declaration of function 'malloc' \
  [-Wimplicit-function-declaration]
  242 |   v_char_pointer = (char *) malloc (1);
      |                             ^~~~~~
ctf-ptype.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
  +++ |+#include <stdlib.h>
    1 | /* This test program is part of GDB, the GNU debugger.
...

Fix this by adding the missing include.

Tested on aarch64-linux.
2024-04-02 16:22:46 +02:00
Tom de Vries
d16a53152c [gdb/testsuite] Fix gdb.ada/verylong.exp on 32-bit target
In an aarch32-linux chroot on an aarch64-linux system, I run into:
...
(gdb) print x^M
$1 = 9223372036854775807^M
(gdb) FAIL: gdb.ada/verylong.exp: print x
...

A passing version on aarch64-linux looks like:
...
(gdb) print x^M
$1 = 170141183460469231731687303715884105727^M
(gdb) PASS: gdb.ada/verylong.exp: print x
...

The difference is caused by the size of the type Long_Long_Long_Integer, which
is:
- a 128-bit signed on 64-bit targets, and
- a 64-bit signed on 32-bit target.

Fix this by detecting the size of the Long_Long_Long_Integer type, and
handling it.

Tested on aarch64-linux and aarch32-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR testsuite/31574
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31574

[1] https://gcc.gnu.org/onlinedocs/gnat_rm/Implementation-Defined-Characteristics.html
2024-04-02 16:14:39 +02:00
Nick Clifton
121a3f4b4f Update objcopy's --section-alignment option so that it sets the alignment flag on PE sections. Add a check for aligned sections not matching their VMAs. 2024-04-02 15:09:16 +01:00
Tom de Vries
b35013e29f [gdb/tui] Fix centering and highlighting of current line
After starting TUI like this with a hello world a.out:
...
$ gdb -q a.out -ex start -ex "tui enable"
...
we get:
...
┌─hello.c──────────────────────────────┐
│        5 {                           │
│        6   printf ("hello\n");       │
│        7                             │
│        8   return 0;                 │
│        9 }                           │
│                                      │
└──────────────────────────────────────┘
...

This is a regression since commit ee1e9bbb51 ("[gdb/tui] Fix displaying main
after resizing"), before which we had instead:
...
┌─hello.c──────────────────────────────┐
│        4 main (void)                 │
│        5 {                           │
│  >     6   printf ("hello\n");       │
│        7                             │
│        8   return 0;                 │
│        9 }                           │
└──────────────────────────────────────┘
...

In other words, the problems are:
- the active line (source line 6) is no longer highlighted, and
- the active line is not vertically centered (screen line 2 out 6 instead of
  screen line 3 out of 6).

Fix these problems respectively by:
- in tui_enable, instead of "tui_show_frame_info (0)" using
  'tui_show_frame_info (deprecated_safe_get_selected_frame ())", and
- in tui_source_window_base::rerender, adding centering functionality.

Tested on aarch64-linux.

Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>

PR tui/31522
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31522
2024-04-02 16:09:10 +02:00