Commit Graph

104070 Commits

Author SHA1 Message Date
GDB Administrator
93bbe484a4 Automatic date update in version.in 2020-11-26 00:00:19 +00:00
H.J. Lu
e8cda20905 libctf: Pass format argument to asprintf
libctf/ChangeLog
2020-09-23  H.J. Lu  <hongjiu.lu@intel.com>

	PR libctf/26934
	* ctf-dump.c (ctf_dump_objts): Pass format argument to asprintf.
2020-11-25 19:11:36 +00:00
Nick Alcock
96c61be508 binutils: readelf: support CTF dicts with non-native-endian symtabs
Now we have a way to tell libctf what the endianness of the symtab is,
get readelf to use it.  (objdump doesn't need to do so, nor does ld,
because they both use BFD-aware mechanisms to open CTF dicts, so libctf
can automatically figure the symtab endianness out.)

binutils/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

	* readelf.c (dump_section_as_ctf): Call ctf_arc_symsect_endianness.
2020-11-25 19:11:35 +00:00
Nick Alcock
53651de80f libctf, include: support foreign-endianness symtabs with CTF
The CTF symbol lookup machinery added recently has one deficit: it
assumes the symtab is in the machine's native endianness.  This is
always true when the linker is writing out symtabs (because cross
linkers byteswap symbols only after libctf has been called on them), but
may be untrue in the cross case when the linker or another tool
(objdump, etc) is reading them.

Unfortunately the easy way to model this to the caller, as an endianness
field in the ctf_sect_t, is precluded because doing so would change the
size of the ctf_sect_t, which would be an ABI break.  So, instead, allow
the endianness of the symtab to be set after open time, by calling one
of the two new API functions ctf_symsect_endianness (for ctf_dict_t's)
or ctf_arc_symsect_endianness (for entire ctf_archive_t's).  libctf
calls these functions automatically for objects opened via any of the
BFD-aware mechanisms (ctf_bfdopen, ctf_bfdopen_ctfsect, ctf_fdopen,
ctf_open, or ctf_arc_open), but the various mechanisms that just take
raw ctf_sect_t's will assume the symtab is in native endianness and need
a later call to ctf_*symsect_endianness to adjust it if needed.  (This
call is basically free if the endianness is actually native: it only
costs anything if the symtab endianness was previously guessed wrong,
and there is a symtab, and we are using it directly rather than using
symtab indexing.)

Obviously, calling ctf_lookup_by_symbol or ctf_symbol_next before the
symtab endianness is correctly set will probably give wrong answers --
but you can set it at any time as long as it is before then.

include/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h: Style nit: remove () on function names in comments.
	(ctf_sect_t): Mention endianness concerns.
	(ctf_symsect_endianness): New declaration.
	(ctf_arc_symsect_endianness): Likewise.

libctf/ChangeLog
2020-11-23  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (ctf_dict_t) <ctf_symtab_little_endian>: New.
	(struct ctf_archive_internal) <ctfi_symsect_little_endian>: Likewise.
	* ctf-create.c (ctf_serialize): Adjust for new field.
	* ctf-open.c (init_symtab): Note the semantics of repeated calls.
	(ctf_symsect_endianness): New.
	(ctf_bufopen_internal): Set ctf_symtab_little_endian suitably for
	the native endianness.
	(_Static_assert): Moved...
	(swap_thing): ... with this...
	* swap.h: ... to here.
	* ctf-util.c (ctf_elf32_to_link_sym): Use it, byteswapping the
	Elf32_Sym if the ctf_symtab_little_endian demands it.
	(ctf_elf64_to_link_sym): Likewise swap the Elf64_Sym if needed.
	* ctf-archive.c (ctf_arc_symsect_endianness): New, set the
	endianness of the symtab used by the dicts in an archive.
	(ctf_archive_iter_internal): Initialize to unknown (assumed native,
	do not call ctf_symsect_endianness).
	(ctf_dict_open_by_offset): Call ctf_symsect_endianness if need be.
	(ctf_dict_open_internal): Propagate the endianness down.
	(ctf_dict_open_sections): Likewise.
	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Get the endianness from the
	struct bfd and pass it down to the archive.
	* libctf.ver: Add ctf_symsect_endianness and
	ctf_arc_symsect_endianness.
2020-11-25 19:11:35 +00:00
Tom Tromey
cbfa382abb Remove two unnecessary variables from evaluate_subexp_standard
I noticed a couple of spots in evaluate_subexp_standard that looked
like:

    value *result;
    result = something;
    return result;

This patch simplifies these spots to a simple "return".

gdb/ChangeLog
2020-11-25  Tom Tromey  <tom@tromey.com>

	* eval.c (evaluate_subexp_standard): Remove unnecessary
	variables.
2020-11-25 10:19:40 -07:00
Tom Tromey
af30c400ea Do not include parser-defs.h from c-lang.h
While working on another series, I noticed that c-lang.h does not need
to include parser-defs.h.  This patch makes this change, and fixes up
the two .c files that needed this include.  Tested by rebuilding.

gdb/ChangeLog
2020-11-25  Tom Tromey  <tom@tromey.com>

	* d-lang.c: Include parser-defs.h.
	* rust-lang.c: Include parser-defs.h.
	* c-lang.h: Do not include parser-defs.h.
2020-11-25 10:10:11 -07:00
Alan Modra
21401fc7bf Duplicate output sections in scripts
Previously, ld merged duplicate output sections if such existed in
scripts, except for those with a constraint of SPECIAL.  This makes
scripts with duplicate output section statements create duplicate
output sections in the linker output file.

	* ldlang.c (lang_output_section_statement_lookup): Change "create"
	parameter to a tristate, if 2 then always create a new output
	section statement.  Update all callers, with
	lang_enter_output_section_statement using "2".
	(map_input_to_output_sections): Don't ignore SPECIAL constraint
	here.
	* ldlang.h (lang_output_section_statement_type): Update prototype.
	(lang_output_section_find): Update.
2020-11-25 19:13:51 +10:30
Alan Modra
6595cf3ce8 nm ifunc test tweaks
* testsuite/binutils-all/nm.exp (ifunc): xfail more targets.
2020-11-25 16:36:50 +10:30
Alan Modra
e54ae97fb7 gas output_file_close error message
Seen on arm-elf, where ELFOSABI_ARM is set too late to get a warning
when processing ifunc related directives on their source line.
../gas/as-new ifunc.s -o tmpdir/ifunc.o
../gas/as-new: symbol type STT_GNU_IFUNC is supported only by GNU and FreeBSD targets
ifunc.s: Assembler messages:
ifunc.s: Fatal error: can't close tmpdir/ifunc.o: sorry, cannot handle this file

This patch doesn't fix the real underlying problem, just the late
error message where "can't close" is a misdirection in this case.

	* output-file.c (output_file_close): Remove "can't close" from
	error message.
	* testsuite/gas/mips/reginfo-2.l: Update expected output.
2020-11-25 16:35:31 +10:30
GDB Administrator
eac5c6d392 Automatic date update in version.in 2020-11-25 00:00:13 +00:00
H.J. Lu
d0089f12f6 ld/x86-64: Add PR gold/26939 tests
GOTPCRELX relocations can be transformed only when addend == -4.  Add
tests for GOTPCRELX relocations with addend != -4.

	PR gold/26939
	* testsuite/ld-x86-64/pr26939-x32.d: New file.
	* testsuite/ld-x86-64/pr26939.d: Likewise.
	* testsuite/ld-x86-64/pr26939.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR gold/26939 tests.
2020-11-24 11:32:26 -08:00
Simon Marchi
1c64f6cbcf gdb: remove struct cached_reg typedef
Since we are in C++, this typedef is no longer necessary, we can just
refer to the struct name directly.

gdb/ChangeLog:

	* regcache.h (struct cached_reg): Remove typedef.

Change-Id: I0168b5a9cf88e9b962521760c7e2d0e6f0b52cdf
2020-11-24 10:30:37 -05:00
Tankut Baris Aktemur
50757f95a8 gdb/testsuite: do not hard-code location indices in condbreak-multi-context.exp
Breakpoint locations are sorted according to their addresses.  The
addresses are determined by how the compiler emits the code.
Therefore, we may have a different order of locations depending on the
compiler we use.  To make the gdb.base/condbreak-multi-context.exp
test flexible enough for different compilers' output, do not hard-code
location indices.

Tested with GCC and Clang.

gdb/testsuite/ChangeLog:
2020-11-24  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.base/condbreak-multi-context.exp: Do not hard-code location
	indices.
2020-11-24 09:57:31 +01:00
Joel Brobecker
2c20a6018c gdb/README: Fix the URL of the MPFR website (now https).
gdb/ChangeLog:

        * README: Fix the URL of the MPFR library.
2020-11-24 07:10:06 +04:00
Joel Brobecker
c609df6474 gdb/README: Document the --with-libgmp-prefix configure option
gdb/ChangeLog:

        * README: Document the --with-libgmp-prefix configure option.
2020-11-24 07:09:23 +04:00
Joel Brobecker
fa123c3281 gdb/NEWS: Document that GDB now supports DWARF-based fixed point types
gdb/ChangeLog:

        * NEWS: Add entry documenting support for DWARF-based fixed
        point types.
2020-11-24 07:08:42 +04:00
Joel Brobecker
0fb8bb022e gdb/NEWS: Document that building GDB now requires GMP
gdb/ChangeLog:

        * NEWS: Document that building GDB now requires GMP.
2020-11-24 07:08:05 +04:00
Joel Brobecker
4afa9fd9b0 Add TYPE_CODE_FIXED_POINT handling in print_type_scalar
This commit enhances print_type_scalar to include support for
TYPE_CODE_FIXED_POINT. This way, any language falling back to
this function for printing the description of some types
also gets basic ptype support for fixed point types as well.

This fixes a couple of XFAILs in gdb.dwarf2/dw2-fixed-point.exp.

gdb/ChangeLog:

        * typeprint.c (print_type_scalar): Add handling of
        TYPE_CODE_FIXED_POINT.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-fixed-point.exp: Fix the expected output of
        the "ptype pck__fp1_range_var" test for the module-2 and pascal
        languages.  Remove the associated setup_xfail.
2020-11-23 22:03:36 -05:00
Joel Brobecker
af619ce989 valarith.c: Replace INIT_VAL_WITH_FIXED_POINT_VAL macro by lambda
gdb/ChangeLog (Simon Marchi  <simark@simark.ca>):

        * valarith.c (fixed_point_binop): Replace the
        INIT_VAL_WITH_FIXED_POINT_VAL macro by a lambda.  Update all
        users accordingly.
2020-11-23 21:50:29 -05:00
Joel Brobecker
e6fcee3a73 Make function fixed_point_scaling_factor a method of struct type
This logically connects this function to the object it inspects.

gdb/ChangeLog:

        * gdbtypes.h (struct type) <fixed_point_scaling_factor>: New method,
        replacing fixed_point_scaling_factor.  All callers updated
        throughout this project.
        (fixed_point_scaling_factor): Delete declaration.
        * gdbtypes.c (type::fixed_point_scaling_factor): Replaces
        fixed_point_scaling_factor.  Adjust implementation accordingly.
2020-11-23 21:49:13 -05:00
Joel Brobecker
d19937a74c Make fixed_point_type_base_type a method of struct type
As suggested by Simon, to logically connect this function to
the object it inspects.

Note that, logically, this method should be "const". Unfortunately,
the implementation iterates on struct type objects starting with "this",
and thus trying to declare the method "const" triggers a compilation
error.

gdb/ChangeLog:

        * gdbtypes.h (struct type) <fixed_point_type_base_type> New method,
        replacing the fixed_point_type_base_type function. All callers
        updated throughout this project.
        (fixed_point_type_base_type): Remove declaration.
        * gdbtypes.c (type::fixed_point_type_base_type): Replaces
        fixed_point_type_base_type.  Adjust implementation accordingly.
2020-11-23 21:48:23 -05:00
Joel Brobecker
2a12c336b9 gdbtypes.h: Get rid of the TYPE_FIXED_POINT_INFO macro
This is one step further towards the removal of all these macros.

gdb/ChangeLog:

        * gdbtypes.h (struct type) <fixed_point_info, set_fixed_point_info>:
        New methods.
        (INIT_FIXED_POINT_SPECIFIC): Adjust.
        (TYPE_FIXED_POINT_INFO): Delete macro.
        (allocate_fixed_point_type_info): Change return type to void.
        * gdbtypes.c (copy_type_recursive): Replace the use of
        TYPE_FIXED_POINT_INFO by a call to the fixed_point_info method.
        (fixed_point_scaling_factor): Likewise.
        (allocate_fixed_point_type_info): Change return type to void.
        Adjust implementation accordingly.
        * dwarf2/read.c (finish_fixed_point_type): Replace the use of
        TYPE_FIXED_POINT_INFO by a call to the fixed_point_info method.
2020-11-23 21:47:40 -05:00
Joel Brobecker
c9f0b43fe4 gmp-utils: Convert the read/write methods to using gdb::array_view
This commit changes the interfaces of some of the methods declared
in gmp-utils to take a gdb::array_view of gdb_byte instead of a
(gdb_byte *, size) couple.

This makes these methods' API probably more C++-idiomatic.

        * gmp-utils.h (gdb_mpz::read): Change buf and len parameters
        into one single gdb::array_view parameter.
        (gdb_mpz::write): Likewise.
        (gdb_mpq::read_fixed_point, gdb_mpq::write_fixed_point): Likewise.
        * gmp-utils.c (gdb_mpz::read): Change buf and len parameters
        into one single gdb::array_view parameter.
        Adjust implementation accordingly.
        (gdb_mpz::write): Likewise.
        (gdb_mpq::read_fixed_point, gdb_mpq::write_fixed_point): Likewise.
        * unittests/gmp-utils-selftests.c: Adapt following changes above.
        * valarith.c, valops.c, valprint.c, value.c: Likewise.
2020-11-23 21:46:38 -05:00
Joel Brobecker
987b670356 change and rename gmp_string_asprintf to return an std::string
This was suggested by Simon during a code review of this package upstream.
The upside is that this makes the function's API more natural and C++.
The downside is an extra malloc, which might be the reason why we went
for using a unique_xmalloc_ptr in the first place. Since this function
is not expected to be called frequently, the API improvement might be
worth the performance impact.

gdb/ChangeLog:

        * gmp-utils.h (gmp_string_printf): Rename from gmp_string_asprintf.
        Change return type to std::string. Update all callers.
        * gmp-utils.c (gmp_string_printf): Likewise.
2020-11-23 21:45:35 -05:00
Joel Brobecker
4fbb7ccebe Fix stack smashing error during gdb_mpq_write_fixed_point selftest
When building GDB using Ubuntu 20.04's system libgmp and compiler,
running the "maintenance selftest" command triggers the following error:

    | Running selftest gdb_mpq_write_fixed_point.
    | *** stack smashing detected ***: terminated
    | [1]    1092790 abort (core dumped)  ./gdb gdb

This happens while trying to construct an mpq_t object (a rational)
from two integers representing the numerator and denominator.
In our test, the numerator is -8, and the denominator is 1.
The problem was that the rational was constructed using the wrong
function. This is what we were doing prior to this patch:

    mpq_set_ui (v.val, numerator, denominator);

The 'u' in "ui" stands for *unsigned*, which is wrong because
numerator and denominator's type is "int".

As a result of the above, instead of getting a rational value of -8,
we get a rational with a very large positive value (gmp_printf
says "18446744073709551608").

From there, the test performs an operation which is expected to
write this value into a buffer which was not dimensioned to fit
such a number, thus leading GMP into a buffer overflow.
This was verified by applying the formula that GMP's documentation
gives for the required memory buffer size needed during export:

    | When an application is allocating space itself the required size can
    | be determined with a calculation like the following. Since
    | mpz_sizeinbase always returns at least 1, count here will be at
    | least one, which avoids any portability problems with malloc(0),
    | though if z is zero no space at all is actually needed (or written).
    |
    |     numb = 8*size - nail;
    |     count = (mpz_sizeinbase (z, 2) + numb-1) / numb;
    |     p = malloc (count * size);

With the very large number, mpz_sizeinbase returns 66 and thus
the malloc size becomes 16 bytes instead of the 8 we allocated.

This patch fixes the issue by using the correct "set" function.

gdb/ChangeLog:

        * unittests/gmp-utils-selftests.c (write_fp_test): Use mpq_set_si
        instead of mpq_set_ui to initialize our GMP rational.
2020-11-24 06:34:57 +04:00
GDB Administrator
fc23d4728d Automatic date update in version.in 2020-11-24 00:00:17 +00:00
Simon Marchi
15a491af3c gdb/testsuite: show evaluation errors in gdb_assert
Let's say you put this gdb_assert in a test:

    gdb_assert "some invalid tcl code"

You just get:

    FAIL: gdb.base/template.exp: some invalid tcl code

That's not very easy to debug, since you don't know what's invalid in
your code.

Change gdb_assert to print the error message when catch's return code is
1 (TCL_ERROR).  The "warning" is shown both on stdout and in the log
file.  Mark the test as unresolved, because the evaluation error means
we couldn't reach a valid pass/fail conclusion.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_assert): Show error message on error.

Change-Id: Ie6477859554e909ed8d07fb2769c6f2f55e7cce6
2020-11-23 17:26:00 -05:00
Tom de Vries
891615f060 [gdb/testsuite] Fix minimal encodings KPASSes
With current master I see a couple of KPASSes:
...
KPASS: gdb.ada/enum_idx_packed.exp: scenario=minimal: ptype small \
  (PRMS minimal encodings)
  ...
KPASS: gdb.ada/mod_from_name.exp: scenario=minimal: print xp \
  (PRMS minimal encodings)
KPASS: gdb.ada/pckd_arr_ren.exp: scenario=minimal: print var \
  (PRMS minimal encodings)
...

The corresponding setup_kfail is called for everything before gnat 11.

However, the test-cases also PASS for me with gnat-4.8, gnat-7.5.0 and
gnat-8.4.0.

Fix the KPASSes by limiting the setup_kfail to gnat 9 and 10.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-11-23  Tom de Vries  <tdevries@suse.de>

	* gdb.ada/enum_idx_packed.exp: Limit setup_kfail to gnat 9 and 10.
	* gdb.ada/mod_from_name.exp: Same.
	* gdb.ada/pckd_arr_ren.exp: Same.
2020-11-23 20:09:50 +01:00
Tom de Vries
d6ab69dd54 [gdb] Don't return non-existing path in debuginfod_source_query
When setting env var DEBUGINFOD_URLS to " " and running the testsuite, we run
into these regressions:
...
FAIL: gdb.base/list-missing-source.exp: info source
FAIL: gdb.base/source-dir.exp: info source before setting directory search list
...

Setting var DEBUGINFOD_URLS to " " allows the debuginfod query function
debuginfod_source_query to get past its early exit.

The function debuginfod_source_query is documented as: "If the file is
successfully retrieved, its path on the local machine is stored in DESTNAME".

However, in case we get back -ENOENT from libdebuginfod, we still set
DESTNAME:
....
  if (fd.get () < 0 && fd.get () != -ENOENT)
    printf_filtered (_("Download failed: %s.  Continuing without source file %ps.\n"),
                     safe_strerror (-fd.get ()),
                     styled_string (file_name_style.style (),  srcpath));
  else
    *destname = make_unique_xstrdup (srcpath);

  return fd;
...

Fix this by making debuginfod_source_query fit it's documentation and only
setting DESTNAME when successfully retrieving a file.  Likewise in
debuginfod_debuginfo_query.

gdb/ChangeLog:

2020-11-23  Tom de Vries  <tdevries@suse.de>

	* debuginfod-support.c (debuginfod_source_query)
	(debuginfod_debuginfo_query): Only set DESTNAME if successful.
2020-11-23 20:09:50 +01:00
Nick Clifton
f60742b2a1 Fix an illegal memory access when accessing corrupt dynamic secondary relocations.
PR 26931
	* elf-bfd.h (struct elf_backend_data): Add bfd_boolean field to
	slurp_secondary_relocs field.
	(_bfd_elf_slurp_secondary_reloc_section): Update prototype.
	* elf.c (_bfd_elf_slurp_secondary_reloc_section): Add new
	parameter.  Compute number of symbols based upon the new
	parameter.
	* elfcode.h (elf_slurp_reloc_table): Pass dynamic as new
	parameter.
2020-11-23 14:07:02 +00:00
H.J. Lu
cbf097d7b0 s390x: Set .got sh_entsize only if .got size > 0
bfd/

	PR ld/26918
	* elf64-s390.c (elf_s390_finish_dynamic_sections): Set .got
	sh_entsize only if .got size > 0.

ld:

	PR ld/26918
	* testsuite/ld-s390/pr26918-1.d: New file.
	* testsuite/ld-s390/pr26918-1.s: Likewise.
	* testsuite/ld-s390/s390.exp: Run all *.d tests.
2020-11-23 05:13:55 -08:00
Shahab Vahedi
e1b9725dfa ld: Make ARC's tls_ie-01 test more flexible
This is to address the regressions addressed by Nic [1].

The regular expression pattern for the tls_ie-01 test was
too strict and raising false alarms.  The new pattern only
looks for matches that should be there AND ignores the boiler
plates from the object dump.

[1] New failures for ARC targets in linker testsuite
https://sourceware.org/pipermail/binutils/2020-November/114177.html

ld/

	* testsuite/ld-arc/tls_ie-01.d: Use a more general pattern.
2020-11-23 12:25:44 +02:00
Przemyslaw Wirkus
a3a02fe862 aarch64: Add support for Cortex-A78C
This patch adds support for -mcpu=cortex-a78c command line option.
For more information about this processor, see [0]:

[0] https://developer.arm.com/ip-products/processors/cortex-a/cortex-a78c
2020-11-23 10:06:15 +00:00
Simon Marchi
199225823d gdb/testsuite: add template for test cases
The wiki contains a template for new test cases:

    https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Building_the_Example_Program

... which is helpful, because even after many years I can't write all
the boilerplate for writing a test case without doing some mistakes.

However, I think it would be nice to have it in the tree.  It's much
faster to cp the files than going to the wiki and copy/pasting the
contents.

As a bonus, the copyright years will get updated in these files, unlike
those in the wiki.  So they will always be good when we start a new
test.

If this patch is merged, I plan to change the wiki to just point to
these files.

gdb/testsuite/ChangeLog:

	* gdb.base/template.exp: New.
	* gdb.base/template.c: New.

Change-Id: I7dbf068a043b48f83cc325087d70e868eee998c6
2020-11-22 22:04:27 -05:00
GDB Administrator
c751e4652d Automatic date update in version.in 2020-11-23 00:00:11 +00:00
Gary Benson
117c628d49 [gdb/testsuite] Add testcase for DW_AT_count referencing a variable
Clang describes the upper bounds of variable length arrays using
a DW_AT_count attribute which references the DIE of a synthetic
variable whose value is specified using a DW_AT_location.  GDB handles
these incorrectly if the corresponding DWARF expression finishes with a
DW_OP_stack_value (PR26905).  This commit adds a new kfailed test to
gdb.dwarf2/count.exp with the same DWARF as that generated by Clang for
gdb.base/vla-optimized-out.exp, one of the failing tests.

Checked on Fedora 32 x86_64, with GCC and Clang.

gdb/testsuite/ChangeLog:

2020-11-22  Gary Benson <gbenson@redhat.com>

	PR gdb/26905
	* gdb.dwarf2/count.exp: Add test for an array whose upper bound
	is defined using a DW_AT_count which references another DIE.
2020-11-22 10:54:58 +01:00
GDB Administrator
60b4365098 Automatic date update in version.in 2020-11-22 00:00:18 +00:00
Tom de Vries
da39d3ba57 [gdb/testsuite] Add clang xfail in gdb.base/vla-ptr.exp
When running gdb.base/vla-ptr.exp with clang-10, we run into this FAIL:
...
(gdb) print td_vla^M
$6 = 0x7fffffffd2b0^M
(gdb) FAIL: gdb.base/vla-ptr.exp: print td_vla
...

Clang 10.0.1 generates the following DWARF for td_vla.  A variable DIE:
...
 <2><19f>: Abbrev Number: 6 (DW_TAG_variable)
    <1a0>   DW_AT_location    : 0x39 (location list)
    <1a4>   DW_AT_name        : td_vla
    <1aa>   DW_AT_type        : <0x1ae>
....
with typedef type:
...
 <2><1ae>: Abbrev Number: 7 (DW_TAG_typedef)
    <1af>   DW_AT_type        : <0x1fc>
    <1b3>   DW_AT_name        : typedef_vla
...
pointing to:
...
 <1><1fc>: Abbrev Number: 11 (DW_TAG_array_type)
    <1fd>   DW_AT_type        : <0x1d3>
 <2><201>: Abbrev Number: 14 (DW_TAG_subrange_type)
    <202>   DW_AT_type        : <0x1f5>
...

The subrange type is missing the count attribute.  This was filed as
llvm PR48247 - "vla var with typedef'd type has incomplete debug info".

Mark this as xfail.

gdb/testsuite/ChangeLog:

2020-11-21  Tom de Vries  <tdevries@suse.de>

	* gdb.base/vla-ptr.exp: Add XFAIL.
2020-11-21 18:11:36 +01:00
Tom Tromey
dab7264398 Change watchpoint_exp_is_const to return bool
I noticed that watchpoint_exp_is_const should return bool; this patch
implements this change.

gdb/ChangeLog
2020-11-21  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (watchpoint_exp_is_const): Return bool.
2020-11-21 09:16:41 -07:00
Nelson Chu
abd20cb637 RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.
I get the feedback recently that enable linker relaxations may fail to
build some program.  Consider the following case,

	.text
foo:
	addi	a0, a0, %pcrel_lo(.L2)
	call	foo
.L1:	auipc	a1, %pcrel_hi(data_g)
	addi	a1, a1, %pcrel_lo(.L1)
	lui	a2, %hi(data_g)
	addi	a2, a2, %lo(data_g)
	lui	a3, %tprel_hi(data_t)
	add	a3, a3, tp, %tprel_add(data_t)
	addi	a3, a3, %tprel_lo(data_t)
.L2:	auipc	a0, %pcrel_hi(data_g)

	.data
	.word 0x0
	.global data_g
data_g:	.word 0x1

	.section .tbss
data_t:	.word 0x0

The current ld reports `dangerous relocation error` when doing the
pcgp relaxation,
test.o: in function `foo':
(.text+0x0): dangerous relocation: %pcrel_lo missing matching %pcrel_hi

The .L2 auipc should not be removed since it is behind the corresponding
addi, so we record the information in the pcgp_relocs table to avoid
removing the auipc later.  But current ld still remove it since we do not
update the pcgp_relocs table while doing other relaxations.  I have two
solutions to fix the problem,

1. Update the pcgp_relocs table once we actually delete the code.
2. Add new relax pass to do the pcgp relaxations

At first I tried to do the first solution, and we need to update at
least three information - hi_sec_off of riscv_pcgp_lo_reloc, hi_sec_off
and hi_addr (symbol value) of riscv_pcgp_hi_reloc.  Update the hi_sec_off
is simple, but it is more complicate to update the symbol value, since we
almost have to do parts the same works of _bfd_riscv_relax_call again in
the riscv_relax_delete_bytes to get the correct symbol value.

Compared with the first solution, the second one is more intuitive and
simple.  We add a new relax pass to do the pcgp relaxations later, so
we will get all the information correctly in the _bfd_riscv_relax_call,
including the symbol value, without changing so much code.  I do not see
any penalty by adding a new relax pass for now, so it should be fine
to delay the pcgp relaxations.

Besides, I have pass all riscv-gnu-toolchain regressions for this patch.

	bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_section):  Add a new relax pass
	to do the pcgp relaxation later, after the lui and call relaxations,
	but before the delete and alignment relaxations.

	ld/
	* emultempl/riscvelf.em (riscv_elf_before_allocation): Change
	link_info.relax_pass from 3 to 4.
	* testsuite/ld-riscv-elf/pcgp-relax.d: New testcase.
	* testsuite/ld-riscv-elf/pcgp-relax.s: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2020-11-21 09:41:58 +08:00
GDB Administrator
d4087e8150 Automatic date update in version.in 2020-11-21 00:00:17 +00:00
Simon Marchi
c0ad05d567 gdb: fix unittests/gmp-utils-selftests.c build on solaris
When building on solaris (gcc farm machine gcc211), I get:

      CXX    unittests/gmp-utils-selftests.o
    /export/home/simark/src/binutils-gdb/gdb/unittests/gmp-utils-selftests.c: In function 'void selftests::gdb_mpz_read_all_from_small()'  :
    /export/home/simark/src/binutils-gdb/gdb/unittests/gmp-utils-selftests.c:128:43: error: call of overloaded 'pow(int, int)'   is ambiguous
       LONGEST l_min = -pow (2, buf_len * 8 - 1);
                                               ^
    In file included from /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h:22:0,
                     from ../gnulib/import/math.h:27,
                     from /export/home/simark/src/binutils-gdb/gdb/unittests/gmp-utils-selftests.c:23:
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/math_iso.h:210:21: note: candidate: long double std::pow(long double, long double)
      inline long double pow(long double __X, long double __Y) { return
                         ^
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/math_iso.h:170:15: note: candidate: float std::pow(float, float)
      inline float pow(float __X, float __Y) { return __powf(__X, __Y); }
                   ^
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/math_iso.h:71:15: note: candidate: double std::pow(double, double)
     extern double pow __P((double, double));
                   ^

The "pow" function overloads only exist for float-like types, and the
compiler doesn't know which one we want.  Change "2" for "2.0", which
makes the compiler choose one alternative (the double one, I believe).

gdb/ChangeLog:

	* unittests/gmp-utils-selftests.c (gdb_mpz_read_all_from_small):
	Pass 2.0 to pow.
	(gdb_mpz_write_all_from_small): Likewise.

Change-Id: Ied2ae0f01494430244a7c94f8a38b07d819f4213
2020-11-20 11:19:38 -05:00
Simon Marchi
a43b29c90d gdb: fix dwarf2/read.c build on solaris
When building on solaris (gcc farm machine gcc211), I get:

      CXX    dwarf2/read.o
    /export/home/simark/src/binutils-gdb/gdb/dwarf2/read.c: In function 'void finish_fixed_point_type(type*, die_info*, dwarf2_cu*)':
    /export/home/simark/src/binutils-gdb/gdb/dwarf2/read.c:18204:42: error: call of overloaded 'abs(LONGEST&)' is ambiguous
           *num_or_denom = 1 << abs (scale_exp);
                                              ^
    In file included from /usr/include/stdlib.h:11:0,
                     from ../gnulib/import/stdlib.h:36,
                     from /opt/csw/include/c++/5.5.0/cstdlib:72,
                     from /export/home/simark/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:90,
                     from /export/home/simark/src/binutils-gdb/gdb/defs.h:28,
                     from /export/home/simark/src/binutils-gdb/gdb/dwarf2/read.c:31:
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/stdlib_iso.h:163:16: note: candidate: long int std::abs(long int)
      inline long   abs(long _l) { return labs(_l); }
                    ^
    /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/stdlib_iso.h:117:12: note: candidate: int std::abs(int)
     extern int abs(int);
                ^

I don't know why, but using std::abs instead of just abs fixes it.

gdb/ChangeLog:

	* dwarf2/read.c (finish_fixed_point_type): Use std::abs instead
	of abs.

Change-Id: I57b9098351f2a8b2d2f61e848b97f7b2dfe55908
2020-11-20 11:19:19 -05:00
Tom Tromey
14f62a099a Ignore system_error in thread startup
libstdc++ might change so that it always implements std::thread, but
then have thread startup simply fail.  This is being discussed here:

https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558736.html

This patch pre-emptively changes gdb to handle this scenario.  It
seemed fine to me to ignore all system errors at thread startup, so
that is what this does.

gdbsupport/ChangeLog
2020-11-20  Tom Tromey  <tromey@adacore.com>

	* thread-pool.cc (thread_pool::set_thread_count): Ignore system
	errors.
2020-11-20 08:22:46 -07:00
Nick Clifton
9d37f01307 Add missing test file 2020-11-20 14:06:14 +00:00
Nick Alcock
ef21dd3bcf libctf: do not crash when CTF symbol or variable linking fails
When linking fails, we delete all the generated outputs, but we fail to
remove them from the ctf_link_outputs hash we stuck them in before doing
symbol and variable section linking (which we had to do because that's
where ctf_create_per_cu, used by both, looks for them).  This leaves
stale pointers to freed memory behind, and crashes soon follow.

Fix obvious.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-link.c (ctf_link_deduplicating): Clean up the ctf_link_outputs
	hash on error.
2020-11-20 13:34:13 +00:00
Nick Alcock
8f235c90a2 libctf: error-handling fixes
libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-create.c (ctf_dtd_insert): Set ENOMEM on the dict if out of memory.
	(ctf_dvd_insert): Likewise.
	(ctf_add_function): Report ECTF_RDONLY if this dict is not writable.
	* ctf-subr.c (ctf_err_warn): Only debug-dump passed-in warnings if
	the passed-in error code is nonzero: the error on the dict for
	warnings may relate to a previous error.
2020-11-20 13:34:12 +00:00
Nick Alcock
97a2a623d0 libctf, include: add ctf_getsymsect and ctf_getstrsect
libctf has long provided ctf_getdatasect, which hands back a pointer to
the CTF section a (read-only) dict came from.  But it has no such
functions to return pointers to the ELF symbol table or string table
it's working from, which is unfortunate because several libctf functions
(ctf_open, ctf_fdopen, and ctf_bfdopen) figure out which string and
symbol table to use themselves, and don't tell the user what they
decided, so the caller can't agree on which symtab to use with libctf
even if it wanted to.

Add a pair of functions to return the symtab and strtab in use.  Like
ctf_getdatasect, these return ctf_sect_t structures by value, filled
with all-NULL/0 content if a symtab or strtab is not being used.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ctf_getsymsect): New.
	(ctf_getstrsect): Likewise.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-open.c (ctf_getsymsect): New.
	(ctf_getstrsect): Likewise.
	* libctf.ver: Add them.
2020-11-20 13:34:12 +00:00
Nick Alcock
2c78e92523 libctf, include: CTF-archive-wide symbol lookup
CTF archives may contain multiple dicts, each of which contain many
types and possibly a bunch of symtypetab entries relating to those
types: each symtypetab entry is going to appear in exactly one dict,
with the corresponding entries in the other dicts empty (either pads, or
indexed symtypetabs that do not mention that symbol).  But users of
libctf usually want to get back the type associated with a symbol
without having to dig around to find out which dict that type might be
in.

This adds machinery to do that -- and since you probably want to do it
repeatedly, it adds internal caching to the ctf-archive machinery so
that iteration over archives via ctf_archive_next and repeated symbol
lookups do not have to repeatedly reopen the archive.  (Iteration using
ctf_archive_iter will gain caching soon.)

Two new API functions:

ctf_dict_t *
ctf_arc_lookup_symbol (ctf_archive_t *arc, unsigned long symidx,
		       ctf_id_t *typep, int *errp);

This looks up the symbol with index SYMIDX in the archive ARC, returning
the dictionary in which it resides and optionally the type index as
well.  Errors are returned in ERRP.  The dict should be
ctf_dict_close()d when done, but is also cached inside the ctf_archive
so that the open cost is only paid once.  The result of the symbol
lookup is also cached internally, so repeated lookups of the same symbol
are nearly free.

void ctf_arc_flush_caches (ctf_archive_t *arc);

Flush all the caches. Done at close time, but also available as an API
function if users want to do it by hand.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ctf_arc_lookup_symbol): New.
	(ctf_arc_flush_caches): Likewise.
	* ctf.h: Document new auto-ctf_import behaviour.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h (struct ctf_archive_internal) <ctfi_dicts>: New, dicts
	the archive machinery has opened and cached.
	<ctfi_symdicts>: New, cache of dicts containing symbols looked up.
	<ctfi_syms>: New, cache of types of symbols looked up.
	* ctf-archive.c (ctf_arc_close): Free them on close.
	(enosym): New, flag entry for 'symbol not present'.
	(ctf_arc_import_parent): New, automatically import the parent from
	".ctf" if this is a child in an archive and ".ctf" is present.
	(ctf_dict_open_sections): Use it.
	(ctf_archive_iter_internal): Likewise.
	(ctf_cached_dict_close): New, thunk around ctf_dict_close.
	(ctf_dict_open_cached): New, open and cache a dict.
	(ctf_arc_flush_caches): New, flush the caches.
	(ctf_arc_lookup_symbol): New, look up a symbol in (all members of)
	an archive, and cache the lookup.
	(ctf_archive_iter): Note the new caching behaviour.
	(ctf_archive_next): Use ctf_dict_open_cached.
	* libctf.ver: Add ctf_arc_lookup_symbol and ctf_arc_flush_caches.
2020-11-20 13:34:11 +00:00
Nick Alcock
0e28ade476 libctf, ld: properly deduplicate function types
Some type kinds in CTF (functions, arrays, pointers, slices, and
cvr-quals) are intrinsically nameless: the ctt_name field in the CTF
is always zero, and the libctf API provides no way to set a name.
But the compiler can and does sometimes set names for some of these
kinds: in particular, the name it sets on CTF_K_FUNCTION types is the
means it uses to force the name of the function into the string table
so that it can point at it from the function info section.

So null out the name at hashing time so that the deduplicator can
correctly detect that e.g. function types identical but for name should
be considered truly identical, since they will not have a name when the
deduplicator re-emits them into the output.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/data-func-conflicted.d: Shrink the expected
	size of the type section now that function types are being
	deduplicated properly.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dedup.c (ctf_dedup_rhash_type): Null out the names of nameless
	type kinds, just in case the input has named them.
2020-11-20 13:34:10 +00:00