Commit Graph

107159 Commits

Author SHA1 Message Date
Alan Modra
5570ab7f44 Re: elf: Treat undefined version as hidden
Fix fallout in cris testsuite

	PR binutils/28158
	* ld-cris/libdso-1c.d: Update for version display change.
	* ld-cris/libdso-15b.d: Likewise.
2021-08-05 20:47:09 +09:30
Andrew Burgess
99ba4b64d3 gdb/testsuite: update test gdb.base/step-over-syscall.exp
I was looking at PR gdb/19675 and the related test
gdb.base/step-over-syscall.exp.  This test includes a call to kfail
when we are testing a displaced step over a clone syscall.

While looking at the test I removed the call to kfail and ran the
test, and was surprised that the test passed.

I ran the test a few times and it does sometimes fail, but mostly it
passed fine.

PR gdb/19675 describes how, when we displaced step over a clone, the
new thread is created with a $pc in the displaced step buffer.  GDB
then fails to "fix" this $pc (for the new thread), and the thread will
be set running with its current $pc value.  This means that the new
thread will just start executing from whatever happens to be after the
displaced stepping buffer.

In the original PR gdb/19675 bug report Yao Qi was seeing the new
thread cause a segfault, the problem is, what actually happens is
totally undefined.

On my machine, I'm seeing the new thread reenter main, it then starts
trying to run the test again (in the new thread).  This just happens
to be safe enough (in this simple test) that most of the time the
inferior doesn't crash.

In this commit I try to make the test slightly more likely to fail by
doing a couple of things.

First, I added a static variable to main, this is set true when the
first thread enters main, if a second thread ever enters main then I
force an abort.

Second, when the test is finishing I want to ensure that the new
threads have had a chance to do "something bad" if they are going to.
So I added a global counter, as each thread starts successfully it
decrements the counter.  The main thread does not proceed to the final
marker function (where GDB has placed a breakpoint) until all threads
have started successfully.  This means that if the newly created
thread doesn't successfully enter clone_fn then the counter will never
reach zero and the test will timeout.

With these two changes my hope is that the test should fail more
reliably, and so, I have also changed the test to call setup_kfail
before the specific steps that we expect to misbehave instead of just
calling kfail and skipping parts of the test completely.  The benefit
of this is that if/when we fix GDB this test will start to KPASS and
we'll know to update this test to remove the setup_kfail call.
2021-08-05 10:44:16 +01:00
GDB Administrator
12488b1767 Automatic date update in version.in 2021-08-05 00:00:29 +00:00
Lancelot SIX
8085fa01a5 gdb: Use unwinder name in frame_info::to_string
While working on a stack unwinding issue using 'set debug frame on', I
noticed the frame_info::to_string method could be slightly improved.

Unwinders have been given a name in
a154d838a7.  Before this patch, frame_info
debug output prints the host address of the used unwinder, which is not
easy to interpret.  This patch proposes to use the unwinder name
instead since we now have it.

Before the patch:

    {level=1,type=NORMAL_FRAME,unwind=0x2ac1763ec0,pc=0x3ff7fc3460,id={stack=0x3ff7ea79b0,code=0x0000003ff7fc33ac,!special},func=0x3ff7fc33ac}

With the patch:

    {level=1,type=NORMAL_FRAME,unwinder="riscv prologue",pc=0x3ff7fc3460,id={stack=0x3ff7ea79b0,code=0x0000003ff7fc33ac,!special},func=0x3ff7fc33ac}

Tested on riscv64-linux-gnu.
2021-08-04 23:12:06 +00:00
Simon Marchi
06b80590fb gdb/testsuite: fix gdb.base/info-macros.exp with clang
The test gdb.base/info-macros.exp says that it doesn't pass the "debug"
option to prepare_for_testing because that would cause -g to appear
after -g3 on the command line, and that would cause some gcc versions to
not include macro info.  I don't know what gcc versions this refers to.
I tested with gcc 4.8, and that works fine with -g after -g3.

The current state is problematic when testing with CC_FOR_TARGET=clang,
because then only -fdebug-macro is included.  No -g switch if included,
meaning we get a binary without any debug info, and the test fails.

One way to fix it would be to add "debug" to the options when the
compiler is clang.

However, the solution I chose was to specify "debug" in any case, even
for gcc.  Other macro tests such as gdb.base/macscp.exp do perfectly
fine with it.  Also, this lets the test use the debug flag specified by
the board file.  For example, we can test with GCC and DWARF 5, with:

    $ make check RUNTESTFLAGS="--target_board unix/gdb:debug_flags=-gdwarf-5" TESTS="gdb.base/info-macros.exp"

With the hard-coded -g3, this wouldn't actually test with DWARF 5.

Change-Id: I33fa92ee545007d3ae9c52c4bb2d5be6b5b698f1
2021-08-04 15:26:36 -04:00
Simon Marchi
f6c4a82abd gdb: avoid dereferencing empty str_offsets_base optional in dwarf_decode_macros
Since 4d7188abfd ("gdbsupport: add debug assertions in
gdb::optional::get"), some macro-related tests fail on Ubuntu 20.04 with
the system gcc 9.3.0 compiler when building with _GLIBCXX_DEBUG.  For
example, gdb.base/info-macros.exp results in:

   (gdb) break -qualified main
   /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb_optional.h:206: internal-error: T& gdb::optional<T>::get() [with T = long unsigned int]: Assertion `this->has_value ()' failed.

The binary contains DWARF 4 debug info and includes a pre-standard
(pre-DWARF 5) .debug_macro section.  The CU doesn't have a
DW_AT_str_offsets_base attribute (which doesn't exist in DWARF 4).  The
field dwarf2_cu::str_offsets_base is therefore empty.  At
dwarf2/read.c:24138, we unconditionally read the value in the optional,
which triggers the assertion shown above.

The same thing happens when building the test program with DWARF 5 with
the same gcc compiler, as that version of gcc doesn't use indirect
string forms, even with DWARF 5.  So it still doesn't add a
DW_AT_str_offsets_base attribute on the CU.

Fix that by propagating down a gdb::optional<ULONGEST> for the str
offsets base instead of ULONGEST.  That value is only used in
dwarf_decode_macro_bytes, when encountering an "strx" macro operation
(DW_MACRO_define_strx or DW_MACRO_undef_strx).  Add a check there that
we indeed have a value in the optional before reading it.  This is
unlikely to happen, but could happen in theory with an erroneous file
that uses DW_MACRO_define_strx but does not provide a
DW_AT_str_offsets_base (in practice, some things would probably have
failed before and stopped processing of debug info).  I tested the
complaint by inverting the condition and using a clang-compiled binary,
which uses the strx operators.  This is the result:

    During symbol reading: use of DW_MACRO_define_strx with unknown string offsets base [in module /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/info-macros/info-macros]

The test now passes cleanly with the setup mentioned above, and the
testsuite looks on par with how it was before 4d7188abfd.

Change-Id: I7ebd2724beb7b9b4178872374c2a177aea696e77
2021-08-04 15:26:22 -04:00
Simon Marchi
d40947728b gdb: fix typo in complaint in dwarf2/macro.c
I saw this complaint when my code had some bug, and spotted the typo.
Fix it, and while at it mention DW_MACRO as well (it would be confusing
to only see DW_MACINFO with a file that uses a DWARF 5 .debug_macro
section).  I contemplated the idea of passing the knowledge of whether
we are dealing with a .debug_macro section or .debug_macinfo section, to
print only the right one.  But in the end, I don't think that trouble is
necessary for a complaint nobody is going to see.

Change-Id: I276ce8da65c3eac5304f64a1e246358ed29cdbbc
2021-08-04 15:26:11 -04:00
Simon Marchi
ed0dcb1fd3 gdb: fix warnings in bsd-kvm.c
Building on OpenBSD, I get warnings like:

      CXX    bsd-kvm.o
    /home/simark/src/binutils-gdb/gdb/bsd-kvm.c:241:18: error: ISO C++11 does not allow conversion from string literal to 'char *' [-Werror,-Wwritable-strings]
      nl[0].n_name = "_dumppcb";
                     ^

Silence those by adding casts.

Change-Id: I2bef4eebcc306762a4e3e5b5c52f67ecf2820503
2021-08-04 15:25:52 -04:00
Andreas Krebbel
a164bbda30 IBM Z: Remove lpswey parameter
opcodes/
	* s390-opc.c (INSTR_SIY_RD): New instruction format.
	(MASK_SIY_RD): New instruction mask.
	* s390-opc.txt: Change instruction format of lpswey to SIY_RD.

gas/
	* testsuite/gas/s390/zarch-arch14.d: Remove last operand of
	lpswey.
	* testsuite/gas/s390/zarch-arch14.s: Likewise.
2021-08-04 16:51:50 +02:00
Alan Modra
0613c3306c PR28162, segment fault in mips_elf_assign_gp
For the testcase in the PR, _bfd_mips_elf32_gprel16_reloc is passed a
NULL output_bfd.  As expected for reloc special functions if called by
objdump or when final linking.  The function attempts to find the
output by
  output_bfd = symbol->section->output_section->owner;
That makes some sense, since when handling a gp-relative reloc we need
the relevant gp to which the symbol is relative.  Possibly the gp
value can be one for a shared library?  But that doesn't seem useful
or supported by the various abi docs and won't work as written.
Symbols defined in shared libraries have section->output_section
NULL, and what's more the code in mips_elf_assign_gp isn't set up to
look at shared library symbols.

Also, if the symbol is a SHN_ABS one the owner of *ABS* section is
NULL, which will result in the testcase segfault.  The only gp to
which an absolute symbol can be relative is the linker output bfd when
linking, or the input bfd when not.  This patch arranges to do that
for all gp-relative reloc symbols.

	* elf32-mips.c (_bfd_mips_elf32_gprel16_reloc): Don't use the
	section symbol to find the output bfd, use input_section.
	(mips_elf_gprel32_reloc, mips16_gprel_reloc): Likewise.
	* elf64-mips.c (mips_elf64_gprel16_reloc): Likewise.
	(mips_elf64_literal_reloc, mips_elf64_gprel32_reloc): Likewise.
	(mips16_gprel_reloc): Likewise.
2021-08-04 23:28:44 +09:30
Tom de Vries
5b3ef0a595 [gdb/symtab] Use lambda function instead of addrmap_foreach_check
Use a lambda function instead of addrmap_foreach_check,
which removes the need for static variables.

Also remove unnecessary static on local var temp_obstack in test_addrmap.

gdb/ChangeLog:

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

	* addrmap.c (addrmap_foreach_check): Remove.
	(array, val1, val2): Move ...
	(test_addrmap): ... here.  Remove static on temp_obstack.  Use lambda
	function instead of addrmap_foreach_check.
2021-08-04 14:29:47 +02:00
H.J. Lu
f897689c88 elf: Treat undefined version as hidden
Since undefined version can't be used to resolve any references without
the original definition, treat it as hidden.

bfd/

	PR binutils/28158
	* elf.c (_bfd_elf_get_symbol_version_string): Treat undefined
	version as hidden.

ld/

	PR binutils/28158
	* testsuite/ld-elf/linux-x86.exp: Run PR binutils/28158 tests.
	* testsuite/ld-elf/pr28158-1.c: New file.
	* testsuite/ld-elf/pr28158-2.S: Likewise.
	* testsuite/ld-elf/pr28158.nd: Likewise.
	* testsuite/ld-elf/pr28158.rd: Likewise.
	* testsuite/ld-elf/pr28158.t: Likewise.
	* testsuite/ld-elfvers/vers2.dsym: Updated.
	* testsuite/ld-elfvers/vers3.dsym: Likewise.
	* testsuite/ld-elfvers/vers6.dsym: Likewise.
	* testsuite/ld-elfvers/vers19.dsym: Likewise.
	* testsuite/ld-elfvers/vers22.dsym: Likewise.
	* testsuite/ld-elfvers/vers23.dsym: Likewise.
	* testsuite/ld-elfvers/vers23d.dsym: Likewise.
	* testsuite/ld-elfvers/vers27d4.dsym: Likewise.
	* testsuite/ld-elfvers/vers28c.dsym: Likewise.
2021-08-04 05:07:42 -07:00
Tom de Vries
6a7ee0010e [gdb/symtab] Implement addrmap_mutable_find
Currently addrmap_mutable_find is not implemented:
...
static void *
addrmap_mutable_find (struct addrmap *self, CORE_ADDR addr)
{
  /* Not needed yet.  */
  internal_error (__FILE__, __LINE__,
                  _("addrmap_find is not implemented yet "
                    "for mutable addrmaps"));
}
...

I implemented this because I needed it during debugging, to be able to do:
...
(gdb) p ((dwarf2_psymtab *)addrmap_find (map, addr))->filename
...
before and after a call to addrmap_set_empty.

Since this is not used otherwise, added addrmap unit test.

Build on x86_64-linux, tested by doing:
...
$ gdb -q -batch -ex "maint selftest addrmap"
Running selftest addrmap.
Ran 1 unit tests, 0 failed
...

gdb/ChangeLog:

2021-08-03  Tom de Vries  <tdevries@suse.de>

        * gdb/addrmap.c (addrmap_mutable_find): Implement
        [GDB_SELF_TESTS] (CHECK_ADDRMAP_FIND): New macro.
        [GDB_SELF_TESTS] (core_addr, addrmap_foreach_check, test_addrmap)
	(_initialize_addrmap): New function.
2021-08-04 12:53:47 +02:00
Clément Chigot
a83ef1c760 gas: correctly output XCOFF tbss symbols with XTY_CM type.
Global tbss symbols weren't correctly handled and were generating
a symbol with XTY_SD instead of XTY_CM as expected.

gas/
	* config/tc-ppc.c (ppc_frog_symbol): Generate a XTY_CM when
	a symbol has a storage class of XMC_UL.
2021-08-04 08:54:59 +02:00
Clément Chigot
934cb8492f gas: always add dummy symbols when creating XCOFF sections.
Most of the algorithms for XCOFF in tc-ppc.c assume that
the csects field of a ppc_xcoff_section isn't NULL.
This was already made for most of the sections with the creation
of a dummy symbol.
This patch simply mades it default when creating a xcoff_section.

gas/
	* config/tc-ppc.c (ppc_init_xcoff_section): Always create
	the dummy symbol.
	(md_begin): Adjust ppc_init_xcoff_section call.
	(ppc_comm): Likewise.
	(ppc_change_csect): Likewise.
2021-08-04 08:54:59 +02:00
Alan Modra
47fcfcbadc PR28156, rename.c doesn't compile with MinGW
Guard against lack of struct timespec definition.

	PR 28156
	* rename.c (get_stat_atime, get_stat_mtime): Don't compile
	unless HAVE_UTIMENSAT is defined.
2021-08-04 14:44:08 +09:30
Alan Modra
010e444b2f PR28155, Superfluous "the" in the man page
PR 28155
	* ld.texi (Options <runtime library name>): Correct grammar.
2021-08-04 13:14:29 +09:30
Alan Modra
29daccc9f3 revise PE IMAGE_SCN_LNK_NRELOC_OVFL test
* coffcode.h (coff_set_alignment_hook): Test that the resulting
	reloc count is not less than 0xffff.
2021-08-04 12:34:52 +09:30
Simon Marchi
82d1f134cc gdb: follow-fork: push target and add thread in target_follow_fork
In the context of ROCm-gdb [1], the ROCm target sits on top of the
linux-nat target.  when a process forks, it needs to carry over some
data from the forking inferior to the fork child inferior.  Ideally, the
ROCm target would implement the follow_fork target_ops method, but there
are some small problems.  This patch fixes these, which helps the ROCm
target, but also makes things more consistent and a bit nicer in
general, I believe.

The main problem is: when follow-fork-mode is "parent",
target_follow_fork is called with the parent as the current inferior.
When it's "child", target_follow_fork is called with the child as the
current inferior.  This means that target_follow_fork is sometimes
called on the parent's target stack and sometimes on the child's target
stack.

The parent's target stack may contain targets above the process target,
such as the ROCm target.  So if follow-fork-child is "parent", the ROCm
target would get notified of the fork and do whatever is needed.  But
the child's target stack, at that moment, only contains the exec and
process target copied over from the parent.  The child's target stack is
set up by follow_fork_inferior, before calling target_follow_fork.  In
that case, the ROCm target wouldn't get notified of the fork.

For consistency, I think it would be good to always call
target_follow_fork on the parent inferior's target stack.  I think it
makes sense as a way to indicate "this inferior has called fork, do
whatever is needed".  The desired outcome of the fork (whether an
inferior is created for the child, do we need to detach from the child)
can be indicated by passed parameter.

I therefore propose these changes:

 - make follow_fork_inferior always call target_follow_fork with the
   parent as the current inferior.  That lets all targets present on the
   parent's target stack do some fork-related handling and push
   themselves on the fork child's target stack if needed.

   For this purpose, pass the child inferior down to target_follow_fork
   and follow_fork implementations.  This is nullptr if no inferior is
   created for the child, because we want to detach from it.

 - as a result, in follow_fork_inferior, detach from the parent inferior
   (if needed) only after the target_follow_fork call.  This is needed
   because we want to call target_follow_fork before the parent's
   target stack is torn down.

 - hand over to the targets in the parent's target stack (including the
   process target) the responsibility to push themselves, if needed, to
   the child's target stack.  Also hand over the responsibility to the
   process target, at the same time, to create the child's initial
   thread (just like we do for follow_exec).

 - pass the child inferior to exec_on_vfork, so we don't need to swap
   the current inferior between parent and child.  Nothing in
   exec_on_vfork depends on the current inferior, after this change.

   Although this could perhaps be replaced with just having the exec
   target implement follow_fork and push itself in the child's target
   stack, like the process target does... We would just need to make
   sure the process target calls beneath()->follow_fork(...).  I'm not
   sure about this one.

gdb/ChangeLog:

	* target.h (struct target_ops) <follow_fork>: Add inferior*
	parameter.
	(target_follow_fork): Likewise.
	* target.c (default_follow_fork): Likewise.
	(target_follow_fork): Likewise.
	* fbsd-nat.h (class fbsd_nat_target) <follow_fork>: Likewise.
	(fbsd_nat_target::follow_fork): Likewise, and call
	inf_ptrace_target::follow_fork.
	* linux-nat.h (class linux_nat_target) <follow_fork>: Likewise.
	* linux-nat.c (linux_nat_target::follow_fork): Likewise, and
	call inf_ptrace_target::follow_fork.
	* obsd-nat.h (obsd_nat_target) <follow_fork>: Likewise.
	* obsd-nat.c (obsd_nat_target::follow_fork): Likewise, and call
	inf_ptrace_target::follow_fork.
	* remote.c (class remote_target) <follow_fork>: Likewise.
	(remote_target::follow_fork): Likewise, and call
	process_stratum_target::follow_fork.
	* process-stratum-target.h (class process_stratum_target)
	<follow_fork>: New.
	* process-stratum-target.c
	(process_stratum_target::follow_fork): New.
	* target-delegates.c: Re-generate.

[1] https://github.com/ROCm-Developer-Tools/ROCgdb

Change-Id: I460bd0af850f0485e8aed4b24c6d8262a4c69929
2021-08-03 20:26:49 -04:00
GDB Administrator
814be17cf9 Automatic date update in version.in 2021-08-04 00:00:29 +00:00
Carl Love
39f6207e3e Fixes for mi-fortran-modules.exp fixes
Output has additional information for a given filename.

gdb/testsuite/ChangeLog
	* gdb.mi/mi-fortran-modules.exp (system_modules_pattern,
	system_module_symbols_pattern): Add check for additional symbols
	on the line
2021-08-03 12:06:02 -05:00
Simon Marchi
4d7188abfd gdbsupport: add debug assertions in gdb::optional::get
The libstdc++ version of optional contains some runtime checks enabled
when _GLIBCXX_DEBUG is defined.  I think it would be useful if our
version contained similar checks.

Add checks in the two `get` methods, also conditional on _GLIBCXX_DEBUG.
I think it's simpler to use that macro rather than introducing a new
GDB-specific one, as I think that if somebody is interested in enabling
these runtime checks, they'll also be interested in enabling the
libstdc++ runtime checks (and vice-versa).

I implemented these checks using gdb_assert.  Note that gdb_assert
throws (after querying the user), and we are in noexcept methods.  That
means that std::terminate / abort will immediately be called.  I think
this is ok, since if those were "real" _GLIBCXX_DEBUG checks, abort
would be called straight away.

If I add a dummy failure, it looks like so:

    $ ./gdb -q -nx --data-directory=data-directory
    /home/simark/src/binutils-gdb/gdb/../gdbsupport/gdb_optional.h:206: internal-error: T& gdb::optional<T>::get() [with T = int]: Assertion `this->has_value ()' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    Quit this debugging session? (y or n) n
    [1]    658767 abort (core dumped)  ./gdb -q -nx --data-directory=data-directory

Change-Id: Iadfdcd131425bd2ca6a2de30d7b22e9b3cc67793
2021-08-03 08:50:56 -04:00
Alok Kumar Sharma
748aa9b653 [gdb/testsuite] templates.exp to accept clang++ output
Please consider below testcase with intended error.
``````````
    constexpr const char cstring[] = "Eta";
    template <const char*, typename T> class Column {};
    using quick = Column<cstring,double>; // cstring without '&'

    void lookup() {
      quick c1;
      c1.ls();
    }
``````````
It produces below error.
``````````
no member named 'ls' in 'Column<&cstring, double>'.
``````````
Please note that error message contains '&' for cstring, which is absent
in actual program.
Clang++ does not generate & in such cases and this should also be
accepted as correct output.

gdb/testsuite/ChangeLog:

	* gdb.cp/templates.exp: Accept different but correct output
	from the Clang++ compiled binary also.
2021-08-03 15:20:04 +05:30
GDB Administrator
cee6789e1b Automatic date update in version.in 2021-08-03 00:00:24 +00:00
Tom Tromey
965bc1df87 Handle compiler-generated suffixes in Ada names
The compiler may add a suffix to a mangled name.  A typical example
would be splitting a function and creating a ".cold" variant.

This patch changes Ada decoding (aka demangling) to handle these
suffixes.  It also changes the encoding process to handle them as
well.

A symbol like "function.cold" will now be displayed to the user as
"function[cold]".  The "." is not simply preserved because that is
already used in Ada.
2021-08-02 10:48:30 -06:00
Tom Tromey
9698f71410 Remove uses of fprintf_symbol_filtered
I believe that many calls to fprintf_symbol_filtered are incorrect.
In particular, there are some that pass a symbol's print name, like:

  fprintf_symbol_filtered (gdb_stdout, sym->print_name (),
			   current_language->la_language, DMGL_ANSI);

fprintf_symbol_filtered uses the "demangle" global to decide whether
or not to demangle -- but print_name does this as well.  This can lead
to double-demangling.  Normally this could be innocuous, except I also
plan to change Ada demangling in a way that causes this to fail.
2021-08-02 10:48:29 -06:00
Tom Tromey
ba8694b650 Handle type qualifier for enumeration name
Pierre-Marie noticed that the Ada expression "TYPE'(NAME)" resolved
incorrectly when "TYPE" was an enumeration type.  Here, "NAME" should
be unambiguous.

This patch fixes this problem.  Note that the patch is not perfect --
it does not give an error if TYPE is an enumeration type but NAME is
not an enumerator but does have some other meaning in scope.  Fixing
this proved difficult, and so I've left it out.
2021-08-02 10:11:23 -06:00
Tom Tromey
17a3da8399 Remove the type_qualifier global
The type_qualifier global is no longer needed in the Ada expression
parser, so this removes it.
2021-08-02 10:11:23 -06:00
Tom Tromey
03adb248d6 Defer Ada character literal resolution
In Ada, an enumeration type can use a character literal as one of the
enumerators.  The Ada expression parser handles the appropriate
conversion.

It turns out, though, that this conversion was handled incorrectly.
For an expression like TYPE'(EXP), the conversion would be done for
any such literal appearing in EXP -- but only the outermost such
expression should really be affected.

This patch defers the conversion until the resolution phase, fixing
the bug.
2021-08-02 10:11:22 -06:00
Tom Tromey
8b12db26d1 Refactor Ada resolution
In a subsequent patch, it will be convenient if an Ada expression
operation can supply its own replacement object.  This patch refactors
Ada expression resolution to make this possible.
2021-08-02 10:11:22 -06:00
Tom Tromey
cd4583499f Remove add_symbols_from_enclosing_procs
I noticed that add_symbols_from_enclosing_procs is empty, and can be
removed.  The one caller, ada_add_local_symbols, can also be
simplified, removing some code that, I think, was an incorrect attempt
to handle nested functions.
2021-08-02 10:11:22 -06:00
Tom Tromey
4d0754c5f5 Avoid crash in varobj deletion
PR varobj/28131 points out a crash in the varobj deletion code.  It
took a while to reproduce this, but essentially what happens is that a
top-level varobj deletes its root object, then deletes the "dynamic"
object.  However, deletion of the dynamic object may cause
~py_varobj_iter to run, which in turn uses gdbpy_enter_varobj:

gdbpy_enter_varobj::gdbpy_enter_varobj (const struct varobj *var)
: gdbpy_enter (var->root->exp->gdbarch, var->root->exp->language_defn)
{
}

However, because var->root has already been destroyed, this is
invalid.

I've added a new test case.  This doesn't reliably crash, but the
problem can easily be seen under valgrind (and, I presume, with ASAN,
though I did not try this).

Tested on x86-64 Fedora 32.  I also propose putting this on the GDB 11
branch, with a suitable ChangeLog entry of course.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28131
2021-08-02 07:46:30 -06:00
Tom de Vries
c894449a79 [gdb/testsuite] Fix gdb.dwarf2/dw2-using-debug-str.exp with cc-with-dwz-m
When running with target board cc-with-dwz-m, we run into:
...
(gdb) file dw2-using-debug-str-no-debug-str^M
Reading symbols from dw2-using-debug-str-no-debug-str...^M
(gdb) FAIL: gdb.dwarf2/dw2-using-debug-str.exp: file dw2-using-debug-str
...

With native, the .debug_str section is present in the
dw2-using-debug-str executable, and removed from the
dw2-using-debug-str-no-debug-str executable.  When loading the latter, a dwarf
error is triggered.

With cc-with-dwz-m, the .debug_str section is not present in the
dw2-using-debug-str executable, because it's already moved to
.tmp/dw2-using-debug-str.dwz.  Consequently, the removal has no effect, and no
dwarf error is triggered, which causes the FAIL.

The same problem arises with target board cc-with-gnu-debuglink.

Fix this by detecting whether the .debug_str section is missing, and skipping
the remainder of the test-case.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-08-02  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/dw2-using-debug-str.exp: Handle missing .debug_str
	section in dw2-using-debug-str.
2021-08-02 15:31:51 +02:00
Tom de Vries
f7ded54b34 [gdb/testsuite] Fix gdb.dwarf2/dw2-using-debug-str.exp with cc-with-gdb-index
When running with target board cc-with-gdb-index, we run into:
...
(gdb) file dw2-using-debug-str-no-debug-str^M
Reading symbols from dw2-using-debug-str-no-debug-str...^M
Dwarf Error: DW_FORM_strp used without required section^M
(gdb) FAIL: gdb.dwarf2/dw2-using-debug-str.exp: file dw2-using-debug-str
...

The test expects the dwarf error, but has no matching pattern for the entire
output.

Fix this by updating the regexp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-08-02  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/dw2-using-debug-str.exp: Update regexp to match
	cc-with-gdb-index output.
2021-08-02 15:31:51 +02:00
Tom de Vries
1df42e9083 [gdb/testsuite] Fix gdb.dwarf2/per-bfd-sharing.exp with cc-with-gdb-index
When running with target board cc-with-gdb-index, we run into:
...
rm: cannot remove '/tmp/tmp.JmYTeiuFjj/*.gdb-index': \
  No such file or directory^M
FAIL: gdb.dwarf2/per-bfd-sharing.exp: \
  couldn't remove files in temporary cache dir
...

Fix this, as in gdb.base/index-cache.exp, by only FAILing when
$expecting_index_cache_use.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-08-02  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/per-bfd-sharing.exp: Only expect index-cache files
	when $expecting_index_cache_use.
2021-08-02 15:31:51 +02:00
Tom de Vries
4d47cbdd29 [gdb/testsuite] Fix gdb.dwarf2/gdb-index-nodebug.exp with cc-with-gdb-index
When running with target board cc-with-gdb-index, we run into:
...
(gdb) save gdb-index .^M
Error while writing index for `gdb-index-nodebug': \
  Cannot use an index to create the index^M
(gdb) FAIL: gdb.dwarf2/gdb-index-nodebug.exp: try to save gdb index
...

Fix this by detecting an already present index, and marking the test
unsupported.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-08-02  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/gdb-index-nodebug.exp: Mark unsupported when index
	already present.
2021-08-02 15:31:51 +02:00
Tom de Vries
a66b7a0434 [gdb/testsuite] Fix gdb.dwarf2/fission-relative-dwo.exp with cc-with-gdb-index
When running with target board cc-with-gdb-index, we run into:
...
gdb compile failed, warning: Could not find DWO CU \
  fission-relative-dwo.dwo(0x1234) referenced by CU at offset 0xc7 \
  [in module outputs/gdb.dwarf2/fission-relative-dwo/.tmp/fission-relative-dwo]
UNTESTED: gdb.dwarf2/fission-relative-dwo.exp: fission-relative-dwo.exp
ERROR: failed to compile fission-relative-dwo
...

The problem is that:
- the .dwo file is found relative to the executable, and
- cc-with-tweaks.sh moves the executable to a temp dir, but not
  the .dwo file.

Fix this by copying the .dwo file alongside the executable in the temp dir.

Verified changes using shellcheck.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-08-02  Tom de Vries  <tdevries@suse.de>

	* contrib/cc-with-tweaks.sh: Copy .dwo files alongside executable.
2021-08-02 15:31:51 +02:00
Shahab Vahedi
91254b918f gdb: Make the builtin "boolean" type an unsigned type
When printing the fields of a register that is of a custom struct type,
the "unpack_bits_as_long ()" function is used:

    do_val_print (...)
      cp_print_value_fields (...)
        value_field_bitfield (...)
          unpack_value_bitfield (...)
            unpack_bits_as_long (...)

This function may sign-extend the extracted field while returning it:

    val >>= lsbcount;

    if (...)
      {
        valmask = (((ULONGEST) 1) << bitsize) - 1;
        val &= valmask;
        if (!field_type->is_unsigned ())
  	  if (val & (valmask ^ (valmask >> 1)))
  	      val |= ~valmask;
      }

    return val;

lsbcount:   Number of lower bits to get rid of.
bitsize:    The bit length of the field to be extracted.
val:        The register value.
field_type: The type of field that is being handled.

While the logic here is correct, there is a problem when it is
handling "field_type"s of "boolean".  Those types are NOT marked
as "unsigned" and therefore they end up being sign extended.
Although this is not a problem for "false" (0), it definitely
causes trouble for "true".

This patch constructs the builtin boolean type as such that it is
marked as an "unsigned" entity.

The issue tackled here was first encountered for arc-elf32 target
running on an x86_64 machine.  The unit-test introduced in this change
has passed for all the targets (--enable-targets=all) running on the
same x86_64 host.

Fixes: https://sourceware.org/PR28104
2021-08-02 13:00:01 +02:00
GDB Administrator
7d315ef225 Automatic date update in version.in 2021-08-02 00:00:28 +00:00
Tom de Vries
b94ed26fef [gdb/testsuite] Fix gdb.base/maint.exp with cc-with-gdb-index
With target board cc-with-gdb-index we run into:
...
FAIL: gdb.base/maint.exp: maint print statistics
...

The output that is checked is:
...
Statistics for 'maint':^M
  Number of "minimal" symbols read: 53^M
  Number of "full" symbols read: 40^M
  Number of "types" defined: 60^M
  Number of symbol tables: 7^M
  Number of symbol tables with line tables: 2^M
  Number of symbol tables with blockvectors: 2^M
  Number of read CUs: 2^M
  Number of unread CUs: 5^M
  Total memory used for objfile obstack: 20320^M
  Total memory used for BFD obstack: 4064^M
  Total memory used for string cache: 4064^M
...
and the regexp doesn't match because it expects the "Number of read/unread
CUs" lines in a different place.

Fix this by updating the regexp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-08-01  Tom de Vries  <tdevries@suse.de>

	* gdb.base/maint.exp: Update "maint print statistics" to match
	output with target board cc-with-gdb-index.
2021-08-01 19:53:42 +02:00
Tom de Vries
af51804103 [gdb/testsuite] Fix gdb.base/index-cache.exp with cc-with-gdb-index
With target board cc-with-gdb-index we run into:
...
FAIL: gdb.base/index-cache.exp: couldn't remove files in temporary cache dir
...

The problem is that there are no files to remove, because the index cache
isn't used, as indicated by $expecting_index_cache_use.

Fix this by only FAILing when $expecting_index_cache_use.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-08-01  Tom de Vries  <tdevries@suse.de>

	* gdb.base/index-cache.exp:
2021-08-01 19:53:42 +02:00
GDB Administrator
426260d246 Automatic date update in version.in 2021-08-01 00:00:29 +00:00
GDB Administrator
7d0aa7cbd4 Automatic date update in version.in 2021-07-31 00:00:24 +00:00
Tom Tromey
177ac6e47e Use iterator_range in more places
This changes a couple of spots to replace custom iterator range
classes with a specialization of iterator_range.

Regression tested on x86-64 Fedora 34.
2021-07-30 08:49:15 -06:00
Tom Tromey
785e5700ce Replace exception_print_same with operator!=
I noticed that exception_print_same is only used in a single spot, and
it seemed to be better as an operator!= method attached to
gdb_exception.

Regression tested on x86-64 Fedora 34.
2021-07-30 08:42:39 -06:00
Tom de Vries
fb6262e853 [gdb/build] Disable attribute nonnull
With trunk gcc (12.0) we're running into a -Werror=nonnull-compare build
breaker in gdb, which caused a broader review of the usage of the nonnull
attribute.

The current conclusion is that it's best to disable this.  This is explained
at length in the gdbsupport/common-defs.h comment.

Tested by building with trunk gcc.

gdb/ChangeLog:

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

	* gdbsupport/common-defs.h (ATTRIBUTE_NONNULL): Disable.
2021-07-30 14:07:40 +02:00
Clément Chigot
f681e5867d gas: ensure XCOFF DWARF subsection are initialized to 0
debug_abbrev doesn't use end_exp to compute its size. However, it must
be NULL. Otherwise, ppc_xcoff_end might try to access uninitialized
memory.

gas/
	* config/tc-ppc.c (ppc_dwsect): Use XCNEW instead of XNEW when creating
	a new subsection.
2021-07-30 08:38:49 +02:00
Clément Chigot
8ba4f8f6c2 bfd: ensure that symbols targeted by DWARF relocations are kept in XCOFF
This patch improves XCOFF garbage collector pass, in order to keep
symbols being referenced only by special sections like DWARF sections.

bfd/
	* xcofflink.c (xcoff_mark): Replace SEC_MARK by gc_mark.
	Look through relocations even if xcoff_section_data is NULL.
	(xcoff_sweep): Check if any sections of a file is kept before
	adding its special sections.
	Call xcoff_mark for special sessions being kept instead of just
	marking them.
	(SEC_MARK): Remove
	(xcoff_mark_symbol): Replace SEC_MARK by gc_mark.
	(xcoff_keep_symbol_p): Likewise.
	(bfd_xcoff_size_dynamic_sections): Likewise.
	(xcoff_find_tc0): Likewise.
2021-07-30 08:38:14 +02:00
Clément Chigot
1417c84842 bfd: avoid a crash when debug_section isn't created in XCOFF
bfd/
	* xcofflink.c (bfd_xcoff_size_dynamic_sections):
	Add check to know if debug_section is initialized.
2021-07-30 08:37:15 +02:00
Alan Modra
237877b818 readelf: catch archive_file_size of -1
Fuzzers might put -1 in arhdr.ar_size.  If the size is rounded up to
and even number of bytes we get zero.

	* readelf.c (process_archive): Don't round up archive_file_size.
	Do round up next_arhdr_offset calculation.
2021-07-30 15:33:07 +09:30