Commit Graph

106034 Commits

Author SHA1 Message Date
Tom Tromey
91eea9cc48 Remove dwarf2_per_bfd::all_type_units
I don't think there is any deep reason to separate CUs and TUs in
dwarf2_per_bfd.  This patch removes all_type_units and unifies these
two containers.  Some minor tweaks are needed to the index writers,
because both forms of index keep CUs and TUs separate;

Regression tested on x86-63 Fedora 32.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct tu_stats) <nr_tus>: New member.
	(struct dwarf2_per_bfd) <get_cutu, get_tu>: Remove
	<get_cu>: Now inline.
	<all_type_units>: Remove.
	* dwarf2/read.c (dwarf2_per_bfd::~dwarf2_per_bfd): Update.
	(dwarf2_per_bfd::get_cutu, dwarf2_per_bfd::get_cu)
	(dwarf2_per_bfd::get_tu): Remove.
	(dwarf2_per_bfd::allocate_signatured_type): Update nr_tus.
	(create_signatured_type_table_from_index)
	(create_signatured_type_table_from_debug_names)
	(dw2_symtab_iter_next, dwarf2_base_index_functions::print_stats)
	(dwarf2_base_index_functions::expand_all_symtabs)
	(dw2_expand_marked_cus, dw_expand_symtabs_matching_file_matcher)
	(dwarf2_base_index_functions::map_symbol_filenames)
	(dw2_debug_names_iterator::next, dwarf2_initialize_objfile)
	(add_signatured_type_cu_to_table, create_all_type_units)
	(add_type_unit, build_type_psymtabs_1, print_tu_stats)
	(create_all_comp_units): Update.
	* dwarf2/index-write.c (check_dwarf64_offsets, write_gdbindex)
	(write_debug_names): Update.
2021-04-30 14:07:58 -06:00
Tom Tromey
0d305d5c67 Allocate dwarf2_per_cu_data with 'new'
In a patch series I am working on, I'd like to have a non-POD member
in dwarf2_per_cu_data.  This currently can't be done because
dwarf2_per_cu_data is allocated on an obstack and initialized with
memset.

This patch changes the DWARF reader to allocate objects of this type
with 'new'.  The various "subclasses" of this type (signatured_type in
particular) are now changed to derive from dwarf2_per_cu_data, and
also use 'new' for allocation.

Regression tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_per_bfd) <allocate_per_cu,
	allocate_signatured_type>: Change return type.
	<all_comp_units, all_type_units>: Hold unique pointers.
	(struct dwarf2_per_cu_data): Add constructor and initializers.
	(struct signatured_type): Derive from dwarf2_per_cu_data.
	* dwarf2/read.c (type_unit_group): Derive from
	dwarf2_per_cu_data.
	(dwarf2_per_bfd::get_cutu, dwarf2_per_bfd::get_cu)
	(dwarf2_per_bfd::get_tu)
	(dwarf2_per_bfd::allocate_signatured_type)
	(dwarf2_per_bfd::allocate_signatured_type)
	(create_cu_from_index_list, create_cus_from_index_list)
	(create_signatured_type_table_from_index)
	(create_signatured_type_table_from_debug_names)
	(create_addrmap_from_aranges)
	(dwarf2_base_index_functions::find_last_source_symtab)
	(dw_expand_symtabs_matching_file_matcher)
	(dwarf2_gdb_index::expand_symtabs_matching)
	(dwarf2_base_index_functions::map_symbol_filenames)
	(create_cus_from_debug_names_list)
	(dw2_debug_names_iterator::next)
	(dwarf2_debug_names_index::expand_symtabs_matching)
	(create_debug_type_hash_table, add_type_unit)
	(fill_in_sig_entry_from_dwo_entry, lookup_dwo_signatured_type):
	Update.
	(allocate_type_unit_groups_table): Use delete.
	(create_type_unit_group): Change return type.  Use new.
	(get_type_unit_group, build_type_psymtabs_1)
	(build_type_psymtab_dependencies)
	(process_skeletonless_type_unit, set_partial_user)
	(dwarf2_build_psymtabs_hard, read_comp_units_from_section)
	(create_cus_hash_table, queue_and_load_dwo_tu, follow_die_sig_1)
	(read_signatured_type): Update.
	(dwarf2_find_containing_comp_unit): Change type of
	'all_comp_units'.
	(run_test): Update.
	(dwarf2_per_bfd::allocate_per_cu)
	(dwarf2_per_bfd::allocate_signatured_type): Change return type.
	Use new.
	(add_signatured_type_cu_to_table): Update.
	* dwarf2/index-write.c (write_one_signatured_type)
	(check_dwarf64_offsets, psyms_seen_size, write_gdbindex)
	(write_debug_names): Update.
2021-04-30 14:07:58 -06:00
Tom Tromey
1bee48c7ad Make get_image_name static
The only callers of get_image_name are nat/windows-nat.c, so make it
static.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* nat/windows-nat.h (get_image_name): Don't declare.
	* nat/windows-nat.c (get_image_name): Now static.
2021-04-30 10:22:24 -06:00
Tom Tromey
e228ef975e Share DLL code between gdb and gdbserver
This moves the new DLL-loading code into nat/windows-nat.c, and
changes both gdb and gdbserver to use the shared code.  One
client-provided callback, handle_load_dll, is changed to allow the
code to be shared.  This callback was actually never called from
nat/windows-nat.c; maybe I had planned to share more here and then
didn't finish... I'm not sure.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_nat::handle_load_dll): Update.
	(windows_nat_target::get_windows_debug_event): Call
	dll_loaded_event.
	(windows_add_all_dlls, windows_add_dll): Move to
	nat/windows-nat.c.
	* nat/windows-nat.h (handle_load_dll): Change parameters.
	(dll_loaded_event, windows_add_all_dlls): Declare.
	* nat/windows-nat.c (windows_add_dll, windows_add_all_dlls): Move
	from windows-nat.c.
	(dll_loaded_event): New function.

gdbserver/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* win32-low.cc (do_initial_child_stuff): Update.
	(windows_nat::handle_load_dll): Rename from win32_add_one_solib.
	Change parameter type.
	(win32_add_dll, win32_add_all_dlls)
	(windows_nat::handle_load_dll): Remove.
	(get_child_debug_event): Call dll_loaded_event.
2021-04-30 10:22:24 -06:00
Tom Tromey
de07187290 Use nat/windows-nat function indirection code
This changes gdbserver to use the function indirection code that was
just moved into nat/windows-nat.[ch].  One additional function is used
by gdbserver that was not used by gdb.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* nat/windows-nat.h (GenerateConsoleCtrlEvent): New define.
	(GenerateConsoleCtrlEvent_ftype, GenerateConsoleCtrlEvent):
	Declare.
	* nat/windows-nat.c (GenerateConsoleCtrlEvent): Define.
	(initialize_loadable): Initialize GenerateConsoleCtrlEvent.

gdbserver/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* win32-low.cc (GETPROCADDRESS): Remove.
	(winapi_DebugActiveProcessStop, winapi_DebugSetProcessKillOnExit)
	(winapi_DebugBreakProcess, winapi_GenerateConsoleCtrlEvent)
	(winapi_Wow64SetThreadContext, win32_Wow64GetThreadContext)
	(win32_Wow64SetThreadContext): Remove.
	(win32_set_thread_context, do_initial_child_stuff)
	(win32_process_target::attach, win32_process_target::detach):
	Update.
	(winapi_EnumProcessModules, winapi_EnumProcessModulesEx)
	(winapi_GetModuleInformation, winapi_GetModuleInformationA):
	Remove.
	(win32_EnumProcessModules, win32_EnumProcessModulesEx)
	(win32_GetModuleInformation, win32_GetModuleInformationA):
	Remove.
	(load_psapi): Remove.
	(win32_add_dll, win32_process_target::request_interrupt): Update.
	(initialize_low): Call initialize_loadable.
2021-04-30 10:22:24 -06:00
Tom Tromey
9e439f0098 Move function indirection code to nat/windows-nat
gdb and gdbserver both look for functions in some Windows DLLs at
runtime.  This patch moves this code out of gdb and into
nat/windows-nat, so it can be shared by both programs.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c: Move code to nat/windows-nat.[ch].
	(_initialize_windows_nat): Call initialize_loadable.
	* nat/windows-nat.h (AdjustTokenPrivileges)
	(DebugActiveProcessStop, DebugBreakProcess)
	(DebugSetProcessKillOnExit, EnumProcessModules)
	(EnumProcessModulesEx, GetModuleInformation)
	(GetModuleFileNameExA, GetModuleFileNameExW)
	(LookupPrivilegeValueA, OpenProcessToken, GetConsoleFontSize)
	(GetCurrentConsoleFont, Wow64SuspendThread)
	(Wow64GetThreadContext, Wow64SetThreadContext)
	(Wow64GetThreadSelectorEntry): Move from windows-nat.c.
	(AdjustTokenPrivileges_ftype)
	(DebugActiveProcessStop_ftype, DebugBreakProcess_ftype)
	(DebugSetProcessKillOnExit_ftype, EnumProcessModules_ftype)
	(EnumProcessModulesEx_ftype, GetModuleInformation_ftype)
	(GetModuleFileNameExA_ftype, GetModuleFileNameExW_ftype)
	(LookupPrivilegeValueA_ftype, OpenProcessToken_ftype)
	(GetConsoleFontSize_ftype)
	(GetCurrentConsoleFont_ftype, Wow64SuspendThread_ftype)
	(Wow64GetThreadContext_ftype, Wow64SetThreadContext_ftype)
	(Wow64GetThreadSelectorEntry_ftype): Likewise.
	(initialize_loadable): Declare.
	* nat/windows-nat.c (AdjustTokenPrivileges)
	(DebugActiveProcessStop, DebugBreakProcess)
	(DebugSetProcessKillOnExit, EnumProcessModules)
	(EnumProcessModulesEx, GetModuleInformation, GetModuleFileNameExA)
	(GetModuleFileNameExW, LookupPrivilegeValueA, OpenProcessToken)
	(GetCurrentConsoleFont, GetConsoleFontSize, Wow64SuspendThread)
	(Wow64GetThreadContext, Wow64SetThreadContext)
	(Wow64GetThreadSelectorEntry): Define.
	(bad, bad_GetCurrentConsoleFont, bad_GetConsoleFontSize): Move
	from windows-nat.c.
	(initialize_loadable): Likewise, and rename.
2021-04-30 10:22:24 -06:00
Tom Tromey
1053c6389a Use template functions in windows-nat.c
windows-nat.c defines a number of replacement functions that simply
return zero.  This patch removes these in favor of a couple of
template functions.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (bad_GetModuleFileNameEx): Remove define.
	(bad_DebugActiveProcessStop, bad_DebugBreakProcess)
	(bad_DebugSetProcessKillOnExit, bad_EnumProcessModules)
	(bad_GetModuleFileNameExW, bad_GetModuleFileNameExA)
	(bad_GetModuleInformation, bad_OpenProcessToken): Remove.
	(bad): New template functions.
	(_initialize_loadable): Update.
2021-04-30 10:22:23 -06:00
Tom Tromey
698facb837 Use rvalue reference in thread_pool::post_task
Tankut's recent patches made me realize that thread_pool::post_task
should have used an rvalue reference for its parameter.  This patch
makes this change.

gdbsupport/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* thread-pool.cc (thread_pool::post_task): Update.
	* thread-pool.h (class thread_pool) <post_task>: Take rvalue
	reference to function.
2021-04-30 10:04:56 -06:00
Tom Tromey
2869ac4b59 Fix crash with GNAT minimal encodings
Running the AdaCore internal test suite with -fgnat-encodings=minimal
found a gdb crash.  The bug is that GDB ends up with a typedef in
ada_index_type, resulting in a NULL dereference.

This crash can be reproduced using GCC 11 with the included test case.

Tested on x86-64 Fedora 32.  Because this is Ada-specific, and was
already reviewed by Joel, I am going to check it in.

2021-04-30  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_index_type): Use ada_check_typedef.

gdb/testsuite/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/enum_idx_packed/pck.ads (My_Enum, My_Array_Type)
	(Confused_Array): New types.
	* gdb.ada/enum_idx_packed/foo.adb (Confused_Array): New variable.
	* gdb.ada/enum_idx_packed.exp: Add new tests.
2021-04-30 07:33:01 -06:00
Nick Clifton
d1fbc3ba09 Fix illegal memory access parsing a corrupt MACH-O format file.
PR 27801
	* mach-o.c (bfd_mach_o_core_fetch_environment): Use bfd_get_32 to
	read 32-bit value.
2021-04-30 14:31:03 +01:00
Nick Clifton
9f84cb380e Fix an illegal memory access when parsing a corrupt core note.
PR 27799
	* elf32-xtensa.c (elf_xtensa_grok_prstatus): Check for core notes
	that are too small.
2021-04-30 14:19:24 +01:00
Nick Clifton
6cb40a679b Fix a double free when re-allocating a buffer to size 0.
PR 27797
	* libbfd.c (bfd_realloc_or_free): Do not free a pointer than has
	been realloc'ed to size 0.
2021-04-30 14:04:08 +01:00
Nick Clifton
bfbfa6e7f4 Fix attempt to free non-allocated pointer when parsing .debug_sup sections.
PR 27796
	* dwarf.c (load_debug_sup_file): Allocate memory for filename in
	.debug_sup section.
2021-04-30 12:28:39 +01:00
Nick Clifton
bceb87ef4d Fix illegal memory access when parsing a corrupt PE format file.
PR 27795
	* coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Check for invalid name
	lengths.
2021-04-30 12:11:35 +01:00
Tom de Vries
5536f0cc62 [gdb/testsuite] Make gdb.mi/mi-sym-info.exp more robust against timeouts
Once in a while, I run into this timeout:
...
FAIL: gdb.mi/mi-sym-info.exp: List all variables from debug information \
  only (timeout)
...

I can make the timeout reproducible by setting timeout to 8s (instead of the
default 10s) for the duration of that test.

Make the test-case more stable by fixing all timeouts caused by setting
timeout to 5, either by adding with_timeout_factor, or increasing its factor.

Tested on x86_64-linux.  Also tested in parallel with stress -c 5, to simulate
a busy system in another way.

gdb/testsuite/ChangeLog:

2021-04-30  Tom de Vries  <tdevries@suse.de>

	* gdb.mi/mi-sym-info.exp: Add with_timeout_factor, and increase
	existing timeout factors.
2021-04-30 11:25:47 +02:00
Tom de Vries
7f7f284dfe [gdb/testsuite] Fix duplicate test name in gdb.mi/mi-sym-info.exp
Since commit 2d61316c32 "[gdb/testsuite] Fix buffer full errors in
gdb.mi/mi-sym-info.exp", we have a duplicate test name:
...
Running src/gdb/testsuite/gdb.mi/mi-sym-info.exp ...
DUPLICATE: gdb.mi/mi-sym-info.exp: List all variables
...

This is caused by a copy-paste accident: the idea was to copy the test, edit
it, and then remove the old test, but I forgot to remove the old one.
Remove it now.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-04-30  Tom de Vries  <tdevries@suse.de>

	* gdb.mi/mi-sym-info.exp: Remove duplicate test.
2021-04-30 11:25:47 +02:00
GDB Administrator
7a8238b072 Automatic date update in version.in 2021-04-30 00:00:29 +00:00
Tom de Vries
3f33407487 [gdb/testsuite] Fix timeout in gdb.base/valgrind-infcall-2.exp
Since commit 6d5702a5eb "Fix test case gdb.base/valgrind-bt.exp" I run into:
...
FAIL: gdb.base/valgrind-infcall-2.exp: target remote for vgdb (timeout)
FAIL: gdb.base/valgrind-infcall-2.exp: monitor v.set gdb_output (timeout)
...

The commit adds this line in proc vgdb_start:
...
    set vgdbcmd "set remotetimeout 3"
...
which has no effect given that the value of var vgdbcmd is not used before
it's overwritten.  We can fix this by doing instead:
...
    set_remotetimeout 3
...

The FAIL I'm observing is fixed by increasing the remotetimeout value to 4.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-04-29  Tom de Vries  <tdevries@suse.de>

	PR testsuite/27786
	* lib/valgrind.exp (vgdb_start): Use set_remotetimeout.  Increase
	remotetimeout to 4.
2021-04-29 23:32:20 +02:00
Simon Marchi
e197dfae62 gdb: don't use C++17 namespace declaration style
In a review, I suggested to use "namespace gdb::observers" instead of
two separate namespace declarations.  I didn't realize that this was a
C++17 feature, which breaks compilers that default to an earlier version
of the language, like g++ 4.8.  Change it back to two separate
declarations.

gdb/ChangeLog:

	* auto-load.h: Split namespace declaration.

Change-Id: I701537161967fbd9fcc298ff600bd072aab1251d
2021-04-29 16:24:49 -04:00
Nick Clifton
09e40e44ad Fix an access through a null pointer when parsing a corrupt SOM format fle.
PR 27793
	* som.c (som_slurp_symbol_table): Assign symbols without any scope
	to the undefined section.
	(som_decode_symclass): Check for a missing symbol section.
	* syms.c (bfd_decode_symclass): Likewise.
2021-04-29 17:55:43 +01:00
Nick Clifton
063e75c9e4 Fix illegal memory accesses when parsing a corrupt SOM format file.
PR 27792
	* som.c (som_slurp_string_table): Place a terminating NUL byte at
	the end of the table.
	(som_slurp_symbol_table): Check for an over-large offset into the
	string string table.
2021-04-29 17:41:43 +01:00
Simon Marchi
89ba430c6b gdb: move some variables to an inner scope in save_waitstatus
These two variables:

      struct regcache *regcache = get_thread_regcache (tp);
      const address_space *aspace = regcache->aspace ();

are only needed inside the "if".  Getting a thread's regcache is a
somewhat expensive operation, so it's good to avoid it if not necessary.
Move the variable declarations and their initialization to the "if"
scope.

gdb/ChangeLog:

	* infrun.c (save_waitstatus): Move variables to inner scope.

Change-Id: Ief1463728755b4dcc142c0a0a76896e9d594ae84
2021-04-29 10:16:28 -04:00
Jan Beulich
a2443c8988 x86-64: adjust recently added tests
Five of them fail for Cygwin and MingW. Adjust four and move one to the
ELF-only section.
2021-04-29 15:02:25 +02:00
Nick Clifton
5edb8e3f5a Correct the text describing windres's --processor option.
PR 27594
 * doc/binutils.texi (windres): Correct the description of the
 default value of the --preprocessor argument.
2021-04-29 13:11:29 +01:00
Jan Beulich
3abbafc2aa x86: relax when/how @size can be used
Allow a few more expression forms when the entire expression can be
resolved at assembly time. For this, i386_validate_fix() needs to
arrange for all processing of the relocation to be deferred to
tc_gen_reloc().
2021-04-29 11:45:10 +02:00
Jan Beulich
44f871628c x86: allow @size to also (sensibly) apply to sections
So far this (counter-intuitively) produced the size as recorded in the
(section) symbol. Obtain the section's size instead for section symbols.
(I wonder whether STT_SECTION symbols couldn't properly hold the
section's size in their st_size field, which in turn would likely mean
the internal symbol would also have its size properly updated.)

Note that this is not the same as the .sizeof.() pseudo-operator: @size
yields the local file's contribution to a section, while .sizeof.() gets
resolved by the linker to produce the final full section's size.

As to the 3rd each of the expected output lines in the changed testcase:
I can't find justification for zzz to come after yyy despite them being
defined in the opposite order in source. Therefore I think it's better
to permit both possible outcomes.
2021-04-29 11:43:53 +02:00
Andrew Burgess
8eb82ba1fd gdb/NEWS: Fix typo and stray full stop
Some errors introduced in commit:

  commit edeaceda7b
  Date:   Thu Aug 27 16:53:13 2020 +0100

      gdb: startup commands to control Python extension language

gdb/ChangeLog:

	* NEWS: Fix typo and stray full stop.
2021-04-29 10:31:16 +01:00
GDB Administrator
ae95c78d26 Automatic date update in version.in 2021-04-29 00:00:33 +00:00
Tom Tromey
db2534b704 Fix Ada overloading with 'null'
Currently, the Ada expression parser treats 'null' as an integer 0.
However, this causes overloading to fail in certain cases.

This patch changes the Ada expression parser to use a special type for
'null'.  I chose pointer-to-int0, because I think that's not likely to
be needed for any other Ada expression.  Note this works because a
"mod 1" type has an underlying non-zero byte size; the test includes a
check for this.

The output is changed so that "print null", by default, shows "null".
And, ada_type_match is changed both to recognize the special null type
and to remove a bit of weird code related to how pointers are treated
for overload type matching.

Tested on x86-64 Fedora 32.  Because this only touches Ada, and Joel
already approved it internally at AdaCore, I am checking it in.

gdb/ChangeLog
2021-04-28  Tom Tromey  <tromey@adacore.com>

	* ada-exp.y (primary): Use new type for null pointer.
	* ada-lang.c (ada_type_match): Remove "may_deref"
	parameter.  Handle null pointer.
	(ada_args_match): Update.
	* ada-valprint.c (ada_value_print_ptr, ada_value_print):
	Handle null pointer.

gdb/testsuite/ChangeLog
2021-04-28  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/null_overload.exp: New file.
	* gdb.ada/null_overload/foo.adb: New file.
2021-04-28 10:19:57 -06:00
Andrew Burgess
e43c3e2a74 gdb/doc: use @env to reference environment variables
Clean up a few places where we are not using @env{...} to reference
environment variables.

gdb/doc/ChangeLog:

	* gdb.texinfo (Initialization Files): Use @env when referencing
	environment variables.
	(Shell Commands): Likewise.
	(Starting): Likewise.
	(Arguments): Likewise.
	(Environment): Likewise.
	(Edit): Likewise.
	(Compiling and Injecting Code): Likewise.
	(Files): Likewise.
	(Command History): Likewise.
	(Screen Size): Likewise.
	(Emacs): Likewise.
2021-04-28 13:29:52 +01:00
Nick Clifton
24aebc79b1 Stop the BFD library from treating annobin symbols as potential function symbols.
bfd	* elf.c (_bfd_elf_maybe_function_sym): Do not accept annobin
	symbols as potential function symbols.
	* elfnn-aarch64.c (elfNN_aarch64_maybe_function_sym): Likewise.
	* elf64-ppc.c (ppc64_elf_maybe_function_sym): Likewise.
	* elf32-arm.c (elf32_arm_maybe_function_sym): Likewise.

ld	* testsuite/ld-elf/anno-sym.s: New test source file.
	* testsuite/ld-elf/anno-sym.d: New test driver.
	* testsuite/ld-elf/anno-sym.l: New test error output.
2021-04-28 11:49:09 +01:00
Andrew Burgess
edeaceda7b gdb: startup commands to control Python extension language
Add two new commands to GDB that can be placed into the early
initialization to control how Python starts up.  The new options are:

  set python ignore-environment on|off
  set python dont-write-bytecode auto|on|off

  show python ignore-environment
  show python dont-write-bytecode

These can be used from GDB's startup file to control how the Python
extension language behaves.  These options are equivalent to the -E
and -B flags to python respectively, their descriptions from the
Python man page:

  -E     Ignore environment variables like PYTHONPATH and PYTHONHOME
         that modify the  behavior  of  the  interpreter.

  -B     Don't write .pyc files on import.

gdb/ChangeLog:

	* NEWS: Mention new commands.
	* python/python.c (python_ignore_environment): New static global.
	(show_python_ignore_environment): New function.
	(set_python_ignore_environment): New function.
	(python_dont_write_bytecode): New static global.
	(show_python_dont_write_bytecode): New function.
	(set_python_dont_write_bytecode): New function.
	(_initialize_python): Register new commands.

gdb/doc/ChangeLog:

	* python.texinfo (Python Commands): Mention new commands.

gdb/testsuite/ChangeLog:

	* gdb.python/py-startup-opt.exp: New file.
2021-04-28 09:56:22 +01:00
Andrew Burgess
041ca48e97 gdb: extension languages finish_initialization to initialize
Now that both Python and Guile are fully initialized from their
respective finish_initialization methods, the "finish" in the method
name doesn't really make sense; initialization starts _and_ finishes
with that method.

As such, this commit renames finish_initialization to just initialize.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* extension-priv.h (struct extension_language_ops): Rename
	'finish_initialization' to 'initialize'.
	* extension.c (finish_ext_lang_initialization): Renamed to...
	(ext_lang_initialization): ...this, update comment, and updated
	the calls to reflect the change in struct extension_language_ops.
	* extension.h (finish_ext_lang_initialization): Renamed to...
	(ext_lang_initialization): ...this.
	* guile/guile.c (gdbscm_finish_initialization): Renamed to...
	(gdbscm_initialize): ...this, update comment at definition.
	(guile_extension_ops): Update.
	* main.c (captured_main_1): Update call to
	finish_ext_lang_initialization.
	* python/python.c (gdbpy_finish_initialization): Rename to...
	(gdbpy_initialize): ...this, update comment at definition, and
	update call to do_finish_initialization.
	(python_extension_ops): Update.
	(do_finish_initialization): Rename to...
	(do_initialize): ...this, and update comment.
2021-04-28 09:56:21 +01:00
Andrew Burgess
1178f01adf gdb: initialise extension languages after processing early startup files
Now (thanks to the last few commits) all extension languages are
fully initialised in their finish_initialization method, this commit
delays the call to this method until after the early initialization
files have been processed.

Right now there's no benefit from doing this, but in a later commit I
plan to add new options for Python that will control how Python is
initialized.

With this commit in place, my next commits will allow the user to add
options to their early initialization file and alter how Python starts
up.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* main.c (captured_main_1): Add a call to
	finish_ext_lang_initialization.
	* top.c (gdb_init): Remove call to finish_ext_lang_initialization.
2021-04-28 09:56:20 +01:00
Andrew Burgess
880ae75a2b gdb delay guile initialization until gdbscm_finish_initialization
Like with the previous commit, this commit delays the initialisation
of the guile extension language until gdbscm_finish_initialization.

This is mostly about splitting the existing gdbscm_initialize_*
functions in two, all the calls to register_objfile_data_with_cleanup,
gdbarch_data_register_post_init, etc are moved into new _initialize_*
functions, but everything else is left in the gdbscm_initialize_*
functions.

Then the call to code previously in _initialize_guile is moved into
gdbscm_finish_initialization.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* guile/guile.c (gdbscm_set_backtrace): Add declaration.
	(gdbscm_finish_initialization): Add code moved from
	_initialize_guile.
	(_initialize_guile): Move code to gdbscm_finish_initialization.
	* guile/scm-arch.c (gdbscm_initialize_arches): Move some code into
	_initialize_scm_arch.
	(_initialize_scm_arch): New function.
	* guile/scm-block.c (gdbscm_initialize_blocks): Move some code
	into _initialize_scm_block.
	(_initialize_scm_block): New function.
	* guile/scm-frame.c (gdbscm_initialize_frames): Move some code
	into _initialize_scm_frame.
	(_initialize_scm_frame): New function.
	* guile/scm-objfile.c (gdbscm_initialize_objfiles): Move some code
	into _initialize_scm_objfile.
	(_initialize_scm_objfile): New function.
	* guile/scm-progspace.c (gdbscm_initialize_pspaces): Move some
	code into _initialize_scm_progspace.
	(_initialize_scm_progspace): New function.
	* guile/scm-symbol.c (gdbscm_initialize_symbols): Move some code
	into _initialize_scm_symbol.
	(_initialize_scm_symbol): New function.
	* guile/scm-symtab.c (gdbscm_initialize_symtabs): Move some code
	into _initialize_scm_symtab.
	(_initialize_scm_symtab): New function.
	* guile/scm-type.c (gdbscm_initialize_types): Move some code into
	_initialize_scm_type.
	(_initialize_scm_type): New function.
2021-04-28 09:56:20 +01:00
Andrew Burgess
8e3685bf25 gdb: delay python initialisation until gdbpy_finish_initialization
Delay Python initialisation until gdbpy_finish_initialization.

This is mostly about splitting the existing gdbpy_initialize_*
functions in two, all the calls to register_objfile_data_with_cleanup,
gdbarch_data_register_post_init, etc are moved into new _initialize_*
functions, but everything else is left in the gdbpy_initialize_*
functions.

Then the call to do_start_initialization (in python/python.c) is moved
from the _initialize_python function into gdbpy_finish_initialization.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* python/py-arch.c (_initialize_py_arch): New function.
	(gdbpy_initialize_arch): Move code to _initialize_py_arch.
	* python/py-block.c (_initialize_py_block): New function.
	(gdbpy_initialize_blocks): Move code to _initialize_py_block.
	* python/py-inferior.c (_initialize_py_inferior): New function.
	(gdbpy_initialize_inferior): Move code to _initialize_py_inferior.
	* python/py-objfile.c (_initialize_py_objfile): New function.
	(gdbpy_initialize_objfile): Move code to _initialize_py_objfile.
	* python/py-progspace.c (_initialize_py_progspace): New function.
	(gdbpy_initialize_pspace): Move code to _initialize_py_progspace.
	* python/py-registers.c (_initialize_py_registers): New function.
	(gdbpy_initialize_registers): Move code to
	_initialize_py_registers.
	* python/py-symbol.c (_initialize_py_symbol): New function.
	(gdbpy_initialize_symbols): Move code to _initialize_py_symbol.
	* python/py-symtab.c (_initialize_py_symtab): New function.
	(gdbpy_initialize_symtabs): Move code to _initialize_py_symtab.
	* python/py-type.c (_initialize_py_type): New function.
	(gdbpy_initialize_types): Move code to _initialize_py_type.
	* python/py-unwind.c (_initialize_py_unwind): New function.
	(gdbpy_initialize_unwind): Move code to _initialize_py_unwind.
	* python/python.c (_initialize_python): Move call to
	do_start_initialization to gdbpy_finish_initialization.
	(gdbpy_finish_initialization): Add call to
	do_start_initialization.
2021-04-28 09:56:20 +01:00
Andrew Burgess
913832e99c gdb: ensure SIGINT is set to SIG_DFL during initialisation
In order for our SIGINT handling to work correctly with Python we
require that SIGINT be set to SIG_DFL during Python's initialisation.

Currently this is the case, but, in a later commit I plan to delay the
initialisation of Python until after the point where GDB's own SIGINT
handler has been installed.

The consequence of this is that our SIGINT handling would become
broken.

In this commit I propose adding an RAII class that will ensure SIGINT
is set to SIG_DFL during the call to each extension languages
finish_initialization method.

At this point this change should have not effect.

gdb/ChangeLog:

	* extension.c (struct scoped_default_signal): New struct.
	(scoped_default_sigint): New typedef.
	(finish_ext_lang_initialization): Make use of
	scoped_default_sigint.
2021-04-28 09:56:19 +01:00
Andrew Burgess
a3b5ef3e45 gdb: remove unused argument from gdb_init
The argument to gdb_init is not used, remove it.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* main.c (captured_main_1): Don't pass argument to gdb_init.
	* top.c (gdb_init): Remove unused argument, and add header
	comment.
	* top.h (gdb_init): Remove argument.
2021-04-28 09:56:19 +01:00
Jan Beulich
eb19308f2d x86: honor signedness of PC-relative relocations
PR gas/27763

While the comment in output_jump() was basically correct prior to the
introduction of 64-bit mode, both that and the not-JMP-like behavior of
XBEGIN require adjustments: Branches with 32-bit displacement do not
wrap at 4G in 64-bit mode, and XBEGIN with 16-bit operand size doesn't
wrap at 64k. Similarly %rip-relative addressing doesn't wrap at 4G.

The new testcase points out that for PE/COFF object_64bit didn't get
set so far, preventing in particular the check at the end of
md_convert_frag() to take effect.

For Mach-O the new testcase fails (bogusly), in that only the first two
of the expected errors get raised. Since for Mach-O many testcases
already fail, and since an x86_64-darwin target can't even be configured
for, I didn't think I need to bother.

Note that there are further issues in this area, in particular for
branches with operand size overrides. Such branches, which truncate
%rip / %eip, can't be correctly expressed with ordinary PC-relative
relocations. It's not really clear what to do with them - perhaps the
best we can do is to carry through all associated relocations, leaving
it to the linker (or even loader) to decide (once the final address
layout is known). Same perhaps goes for relocations associated with
32-bit addressing in 64-bit mode.
2021-04-28 10:53:00 +02:00
GDB Administrator
6c356992b4 Automatic date update in version.in 2021-04-28 00:00:32 +00:00
Luis Machado
b9f90c72ee Fix timeout with maint print objfiles
I'm seeing timeouts from gdb.rust/traits.exp when we attempt to print
things with "maint print objfiles".

This happens for two reasons:

1 - GDB does not explicitly split each entry into its own line, but rather
    relies on the terminal's width to insert line breaks.

2 - When running the GDB testsuite, such width may be unlimited, which will
    prevent GDB from inserting any line breaks.

As a result, the output may be too lengthy and will come in big lines.  Tweak
the support library to match the patterns line-by-line, which gives us more
time to match things. Also fix GDB's output to print one entry per line,
regardless of the terminal width.

A similar approach was used in another testcase using the same command (commit
eaeaf44cfd). With the new line breaks, we don't
need a particular pattern, so clean up that test as well.

gdb/ChangeLog:

2021-04-27  Luis Machado  <luis.machado@linaro.org>

	* psymtab.c (psymbol_functions::dump): Output newline.
	* symmisc.c (dump_objfile): Likewise.

gdb/testsuite/ChangeLog:

2021-04-27  Luis Machado  <luis.machado@linaro.org>

	* gdb.base/maint.exp: Drop a pattern that is not needed.
	* lib/gdb.exp (readnow): Match line-by-line.
2021-04-27 20:42:07 -03:00
Luis Machado
4b62a30d5b Fix timeout for gdb.xml/tdesc-reload.exp
For aarch64, the "info all-registers" output is very verbose.  If you run
this test using read1, it will timeout before the command output is done being
read.

Read line-by-line so we don't run into timeouts.

gdb/testsuite/ChangeLog:

2021-04-27  Luis Machado  <luis.machado@linaro.org>

	* gdb.xml/tdesc-reload.exp: Pass -lbl.
2021-04-27 20:40:44 -03:00
Michael Weghorn
2c473def12 gdb: do autoload before notifying Python side in new_objfile event
Without any explicit dependencies specified, the observers attached
to the 'gdb::observers::new_objfile' observable are always notified
in the order in which they have been attached.

The new_objfile observer callback to auto-load scripts is attached in
'_initialize_auto_load'.
The new_objfile observer callback that propagates the new_objfile event
to the Python side is attached in 'gdbpy_initialize_inferior', which is
called via '_initialize_python'.
With '_initialize_python' happening before '_initialize_auto_load',
the consequence was that the new_objfile event was emitted on the Python
side before autoloaded scripts had been executed when a new objfile was
loaded.
As a result, trying to access the objfile's pretty printers (defined in
the autoloaded script) from a handler for the Python-side
'new_objfile' event would fail. Those would only be initialized later on
(when the 'auto_load_new_objfile' callback was called).

To make sure that the objfile passed to the Python event handler
is properly initialized (including its 'pretty_printers' member),
make sure that the 'auto_load_new_objfile' observer is notified
before the 'python_new_objfile' one that propagates the event
to the Python side.

To do this, make use of the mechanism to explicitly specify
dependencies between observers (introduced in a preparatory commit).

Add a corresponding testcase that involves a test library with an autoloaded
Python script and a handler for the Python 'new_objfile' event.

(The real world use case where I came across this issue was in an attempt
to extend handling for GDB pretty printers for dynamically loaded
objfiles in the Qt Creator IDE, s. [1] and [2] for more background.)

[1] https://bugreports.qt.io/browse/QTCREATORBUG-25339
[2] https://codereview.qt-project.org/c/qt-creator/qt-creator/+/333857/1

Tested on x86_64-linux (Debian testing).

gdb/ChangeLog:

	* gdb/auto-load.c (_initialize_auto_load): 'Specify token
	when attaching the 'auto_load_new_objfile' observer, so
	other observers can specify it as a dependency.
	* gdb/auto-load.h (struct token): Declare
	'auto_load_new_objfile_observer_token' as token to be used
	for the 'auto_load_new_objfile' observer.
	* gdb/python/py-inferior.c (gdbpy_initialize_inferior): Make
	'python_new_objfile' observer depend on 'auto_load_new_objfile'
	observer, so it gets notified after the latter.

gdb/testsuite/ChangeLog:

	* gdb.python/libpy-autoloaded-pretty-printers-in-newobjfile-event.so-gdb.py: New test.
	* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.cc: New test.
	* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.h: New test.
	* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-main.cc: New test.
	* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.exp: New test.
	* gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py: New test.

Change-Id: I8275b3f4c3bec32e56dd7892f9a59d89544edf89
2021-04-27 11:22:32 -04:00
Michael Weghorn
9a6e099f43 gdbsupport: allow to specify dependencies between observers
Previously, the observers attached to an observable were always notified
in the order in which they had been attached.  That order is not easily
controlled, because observers are typically attached in _initialize_*
functions, which are called in an undefined order.

However, an observer may require that another observer attached only
later is called before itself is.

Therefore, extend the 'observable' class to allow explicitly specifying
dependencies when attaching observers, by adding the possibility to
specify tokens for observers that it depends on.

To make sure dependencies are notified before observers depending on
them, the vector holding the observers is sorted in a way that
dependencies come before observers depending on them.  The current
implementation for sorting uses the depth-first search algorithm for
topological sorting as described at [1].

Extend the observable unit tests to cover this case as well.  Check that
this works for a few different orders in which the observers are
attached.

This newly introduced mechanism to explicitly specify dependencies will
be used in a follow-up commit.

[1] https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search

Tested on x86_64-linux (Debian testing).

gdb/ChangeLog:

	* unittests/observable-selftests.c (dependency_test_counters):
	New.
	(observer_token0, observer_token1, observer_token2,
	observer_token3, observer_token4, observer_token5): New.
	(struct dependency_observer_data): New struct.
	(observer_dependency_test_callback): New function.
	(test_observers): New.
	(run_dependency_test): New function.
	(test_dependency): New.
	(_initialize_observer_selftest): Register dependency test.

gdbsupport/ChangeLog:

	* observable.h (class observable): Extend to allow specifying
	dependencies between observers, keep vector holding observers
	sorted so that dependencies are notified before observers
	depending on them.

Change-Id: I5399def1eeb69ca99e28c9f1fdf321d78b530bdb
2021-04-27 11:22:32 -04:00
H.J. Lu
60cfa10c36 x86: Add () to silence GCC 5
Add () to !i.prefix[ADDR_PREFIX] to silence GCC 5:

gas/config/tc-i386.c:4152:31: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
     && !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))
                               ^

	* config/tc-i386.c (optimize_encoding): Add () to silence GCC 5.
2021-04-27 08:16:55 -07:00
Nick Clifton
3d64c987c7 Reject debuglink sections with no associated filename.
PR 27779
	* dwarf.c (parse_gnu_debuglink): Reject empty names.
	(parse_gnu_debugaltlink): Likewise.
2021-04-27 15:19:41 +01:00
Mike Frysinger
2045d9d17f sim: riscv: switch MIN/MAX to common min/max
The common sim-basics.h defines min/max already, so use them.
2021-04-26 23:29:01 -04:00
Mike Frysinger
bd0918c910 sim: nltvals: unify common syscall tables
Since libgloss provides a default syscall table for arches, use that
to provide the default syscall table for ports.  Only the exceptions
need to be enumerated now with the common logic as the default.
2021-04-26 22:39:55 -04:00
Mike Frysinger
66d055c754 sim: enable hardware support by default
Force this on for all ports.  We have a few common models that can
be used, so make them generally available.  If the port doesn't use
any hardware (the default), then behavior is unchanged.
2021-04-26 22:30:55 -04:00
Mike Frysinger
3955e34670 bfd: add stdlib.h when using abort
Since this file calls abort() now, we need to include stdlib.h for
its prototype.
2021-04-26 21:02:38 -04:00