deliverable/binutils-gdb.git
3 years agolibctf, include: CTF-archive-wide symbol lookup
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
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.

3 years agolibctf, ld: properly deduplicate function types
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
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.

3 years agold, ctf: new and adjusted CTF tests due to func info / object data sections
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
ld, ctf: new and adjusted CTF tests due to func info / object data sections

The flags word is nonzero now (so all the tests have been adjusted to
not depend on its content): some of them have data objects and functions
in the data object and function info sections now, rather than in the
variable section or recorded nowhere.  There is a new test for
parent/child relationships and index section emission.

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

* testsuite/ld-ctf/array.d: Adjust for nonzero flags word and
public symbols in the data section rather than variables: use
sysv hash style to keep test results the same on non-GNU targets.
* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
* testsuite/ld-ctf/diag-cuname.d: Likewise.
* testsuite/ld-ctf/diag-parlabel.d: Likewise.
* testsuite/ld-ctf/slice.d: Likewise.
* testsuite/ld-ctf/function.d: Likewise, but in the function section.
* testsuite/ld-ctf/conflicting-cycle-1.B-1.d:  Adjust for nonzero
flags word.
* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
* testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise.
* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
* testsuite/ld-ctf/cycle-1.d: Likewise.
* testsuite/ld-ctf/cycle-2.A.d: Likewise.
* testsuite/ld-ctf/cycle-2.B.d: Likewise.
* testsuite/ld-ctf/cycle-2.C.d: Likewise.
* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d:  Likewise.
* testsuite/ld-ctf/super-sub-cycles.d:  Likewise.
* testsuite/ld-ctf/data-func-1.c: New test.
* testsuite/ld-ctf/data-func-2.c: Likewise.
* testsuite/ld-ctf/data-func-conflicted.d: Likewise.

3 years agolibctf: adjust dumper for symtypetab changes
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf: adjust dumper for symtypetab changes

Now that we have a new format for the function info section, it's much
easier to dump it: we can use the same code we use for the object type
section, and that's got simpler too because we can use ctf_symbol_next.

Also dump the new stuff in the header: the new flags bits and the index
section lengths.

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

* ctf-dump.c (ctf_dump_header): Dump the new flags bits and the index
section lengths.
(ctf_dump_objts): Report indexed sections.  Also dump functions.  Use
ctf_symbol_next, not manual looping.
(ctf_dump_funcs): Delete.
(ctf_dump): Use ctf_dump_objts, not ctf_dump_funcs.

3 years agolibctf: symbol type linking support
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf: symbol type linking support

This adds facilities to write out the function info and data object
sections, which efficiently map from entries in the symbol table to
types.  The write-side code is entirely new: the read-side code was
merely significantly changed and support for indexed tables added
(pointed to by the no-longer-unused cth_objtidxoff and cth_funcidxoff
header fields).

With this in place, you can use ctf_lookup_by_symbol to look up the
types of symbols of function and object type (and, as before, you can
use ctf_lookup_variable to look up types of file-scope variables not
present in the symbol table, as long as you know their name: but
variables that are also data objects are now found in the data object
section instead.)

(Compatible) file format change:

The CTF spec has always said that the function info section looks much
like the CTF_K_FUNCTIONs in the type section: an info word (including an
argument count) followed by a return type and N argument types. This
format is suboptimal: it means function symbols cannot be deduplicated
and it causes a lot of ugly code duplication in libctf.  But
conveniently the compiler has never emitted this!  Because it has always
emitted a rather different format that libctf has never accepted, we can
be sure that there are no instances of this function info section in the
wild, and can freely change its format without compatibility concerns or
a file format version bump.  (And since it has never been emitted in any
code that generated any older file format version, either, we need keep
no code to read the format as specified at all!)

So the function info section is now specified as an array of uint32_t,
exactly like the object data section: each entry is a type ID in the
type section which must be of kind CTF_K_FUNCTION, the prototype of
this function.

This allows function types to be deduplicated and also correctly encodes
the fact that all functions declared in C really are types available to
the program: so they should be stored in the type section like all other
types.  (In format v4, we will be able to represent the types of static
functions as well, but that really does require a file format change.)

We introduce a new header flag, CTF_F_NEWFUNCINFO, which is set if the
new function info format is in use.  A sufficiently new compiler will
always set this flag.  New libctf will always set this flag: old libctf
will refuse to open any CTF dicts that have this flag set.  If the flag
is not set on a dict being read in, new libctf will disregard the
function info section.  Format v4 will remove this flag (or, rather, the
flag has no meaning there and the bit position may be recycled for some
other purpose).

New API:

Symbol addition:
  ctf_add_func_sym: Add a symbol with a given name and type.  The
                    type must be of kind CTF_K_FUNCTION (a function
                    pointer).  Internally this adds a name -> type
                    mapping to the ctf_funchash in the ctf_dict.
  ctf_add_objt_sym: Add a symbol with a given name and type.  The type
                    kind can be anything, including function pointers.
    This adds to ctf_objthash.

These both treat symbols as name -> type mappings: the linker associates
symbol names with symbol indexes via the ctf_link_shuffle_syms callback,
which sets up the ctf_dynsyms/ctf_dynsymidx/ctf_dynsymmax fields in the
ctf_dict.  Repeated relinks can add more symbols.

Variables that are also exposed as symbols are removed from the variable
section at serialization time.

CTF symbol type sections which have enough pads, defined by
CTF_INDEX_PAD_THRESHOLD (whether because they are in dicts with symbols
where most types are unknown, or in archive where most types are defined
in some child or parent dict, not in this specific dict) are sorted by
name rather than symidx and accompanied by an index which associates
each symbol type entry with a name: the existing ctf_lookup_by_symbol
will map symbol indexes to symbol names and look the names up in the
index automatically.  (This is currently ELF-symbol-table-dependent, but
there is almost nothing specific to ELF in here and we can add support
for other symbol table formats easily).

The compiler also uses index sections to communicate the contents of
object file symbol tables without relying on any specific ordering of
symbols: it doesn't need to sort them, and libctf will detect an
unsorted index section via the absence of the new CTF_F_IDXSORTED header
flag, and sort it if needed.

Iteration:
  ctf_symbol_next: Iterator which returns the types and names of symbols
                   one by one, either for function or data symbols.

This does not require any sorting: the ctf_link machinery uses it to
pull in all the compiler-provided symbols cheaply, but it is not
restricted to that use.

(Compatible) changes in API:
  ctf_lookup_by_symbol: can now be called for object and function
                        symbols: never returns ECTF_NOTDATA (which is
now not thrown by anything, but is kept for
                        compatibility and because it is a plausible
                        error that we might start throwing again at some
                        later date).

Internally we also have changes to the ctf-string functionality so that
"external" strings (those where we track a string -> offset mapping, but
only write out an offset) can be consulted via the usual means
(ctf_strptr) before the strtab is written out.  This is important
because ctf_link_add_linker_symbol can now be handed symbols named via
strtab offsets, and ctf_link_shuffle_syms must figure out their actual
names by looking in the external symtab we have just been fed by the
ctf_link_add_strtab callback, long before that strtab is written out.

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

* ctf-api.h (ctf_symbol_next): New.
(ctf_add_objt_sym): Likewise.
(ctf_add_func_sym): Likewise.
* ctf.h: Document new function info section format.
(CTF_F_NEWFUNCINFO): New.
(CTF_F_IDXSORTED): New.
(CTF_F_MAX): Adjust accordingly.

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

* ctf-impl.h (CTF_INDEX_PAD_THRESHOLD): New.
(_libctf_nonnull_): Likewise.
(ctf_in_flight_dynsym_t): New.
(ctf_dict_t) <ctf_funcidx_names>: Likewise.
<ctf_objtidx_names>: Likewise.
<ctf_nfuncidx>: Likewise.
<ctf_nobjtidx>: Likewise.
<ctf_funcidx_sxlate>: Likewise.
<ctf_objtidx_sxlate>: Likewise.
<ctf_objthash>: Likewise.
<ctf_funchash>: Likewise.
<ctf_dynsyms>: Likewise.
<ctf_dynsymidx>: Likewise.
<ctf_dynsymmax>: Likewise.
<ctf_in_flight_dynsym>: Likewise.
(struct ctf_next) <u.ctn_next>: Likewise.
(ctf_symtab_skippable): New prototype.
(ctf_add_funcobjt_sym): Likewise.
(ctf_dynhash_sort_by_name): Likewise.
(ctf_sym_to_elf64): Rename to...
(ctf_elf32_to_link_sym): ... this, and...
(ctf_elf64_to_link_sym): ... this.
* ctf-open.c (init_symtab): Check for lack of CTF_F_NEWFUNCINFO
flag, and presence of index sections.  Refactor out
ctf_symtab_skippable and ctf_elf*_to_link_sym, and use them.  Use
ctf_link_sym_t, not Elf64_Sym.  Skip initializing objt or func
sxlate sections if corresponding index section is present.  Adjust
for new func info section format.
(ctf_bufopen_internal): Add ctf_err_warn to corrupt-file error
handling.  Report incorrect-length index sections.  Always do an
init_symtab, even if there is no symtab section (there may be index
sections still).
(flip_objts): Adjust comment: func and objt sections are actually
identical in structure now, no need to caveat.
(ctf_dict_close):  Free newly-added data structures.
* ctf-create.c (ctf_create): Initialize them.
(ctf_symtab_skippable): New, refactored out of
init_symtab, with st_nameidx_set check added.
(ctf_add_funcobjt_sym): New, add a function or object symbol to the
ctf_objthash or ctf_funchash, by name.
(ctf_add_objt_sym): Call it.
(ctf_add_func_sym): Likewise.
(symtypetab_delete_nonstatic_vars): New, delete vars also present as
data objects.
(CTF_SYMTYPETAB_EMIT_FUNCTION): New flag to symtypetab emitters:
this is a function emission, not a data object emission.
(CTF_SYMTYPETAB_EMIT_PAD): New flag to symtypetab emitters: emit
pads for symbols with no type (only set for unindexed sections).
(CTF_SYMTYPETAB_FORCE_INDEXED): New flag to symtypetab emitters:
always emit indexed.
(symtypetab_density): New, figure out section sizes.
(emit_symtypetab): New, emit a symtypetab.
(emit_symtypetab_index): New, emit a symtypetab index.
(ctf_serialize): Call them, emitting suitably sorted symtypetab
sections and indexes.  Set suitable header flags.  Copy over new
fields.
* ctf-hash.c (ctf_dynhash_sort_by_name): New, used to impose an
order on symtypetab index sections.
* ctf-link.c (ctf_add_type_mapping): Delete erroneous comment
relating to code that was never committed.
(ctf_link_one_variable): Improve variable name.
(check_sym): New, symtypetab analogue of check_variable.
(ctf_link_deduplicating_one_symtypetab): New.
(ctf_link_deduplicating_syms): Likewise.
(ctf_link_deduplicating): Call them.
(ctf_link_deduplicating_per_cu): Note that we don't call them in
this case (yet).
(ctf_link_add_strtab): Set the error on the fp correctly.
(ctf_link_add_linker_symbol): New (no longer a do-nothing stub), add
a linker symbol to the in-flight list.
(ctf_link_shuffle_syms): New (no longer a do-nothing stub), turn the
in-flight list into a mapping we can use, now its names are
resolvable in the external strtab.
* ctf-string.c (ctf_str_rollback_atom): Don't roll back atoms with
external strtab offsets.
(ctf_str_rollback): Adjust comment.
(ctf_str_write_strtab): Migrate ctf_syn_ext_strtab population from
writeout time...
(ctf_str_add_external): ... to string addition time.
* ctf-lookup.c (ctf_lookup_var_key_t): Rename to...
(ctf_lookup_idx_key_t): ... this, now we use it for syms too.
<clik_names>: New member, a name table.
(ctf_lookup_var): Adjust accordingly.
(ctf_lookup_variable): Likewise.
(ctf_lookup_by_id): Shuffle further up in the file.
(ctf_symidx_sort_arg_cb): New, callback for...
(sort_symidx_by_name): ... this new function to sort a symidx
found to be unsorted (likely originating from the compiler).
(ctf_symidx_sort): New, sort a symidx.
(ctf_lookup_symbol_name): Support dynamic symbols with indexes
provided by the linker.  Use ctf_link_sym_t, not Elf64_Sym.
Check the parent if a child lookup fails.
(ctf_lookup_by_symbol): Likewise.  Work for function symbols too.
(ctf_symbol_next): New, iterate over symbols with types (without
sorting).
(ctf_lookup_idx_name): New, bsearch for symbol names in indexes.
(ctf_try_lookup_indexed): New, attempt an indexed lookup.
(ctf_func_info): Reimplement in terms of ctf_lookup_by_symbol.
(ctf_func_args): Likewise.
(ctf_get_dict): Move...
* ctf-types.c (ctf_get_dict): ... here.
* ctf-util.c (ctf_sym_to_elf64): Re-express as...
(ctf_elf64_to_link_sym): ... this.  Add new st_symidx field, and
st_nameidx_set (always 0, so st_nameidx can be ignored).  Look in
the ELF strtab for names.
(ctf_elf32_to_link_sym): Likewise, for Elf32_Sym.
(ctf_next_destroy): Destroy ctf_next_t.u.ctn_next if need be.
* libctf.ver: Add ctf_symbol_next, ctf_add_objt_sym and
ctf_add_func_sym.

3 years agobfd, include, ld, binutils, libctf: CTF should use the dynstr/sym
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
bfd, include, ld, binutils, libctf: CTF should use the dynstr/sym

This is embarrassing.

The whole point of CTF is that it remains intact even after a binary is
stripped, providing a compact mapping from symbols to types for
everything in the externally-visible interface of an ELF object: it has
connections to the symbol table for that purpose, and to the string
table to avoid duplicating symbol names.  So it's a shame that the hooks
I implemented last year served to hook it up to the .symtab and .strtab,
which obviously disappear on strip, leaving any accompanying the CTF
dict containing references to strings (and, soon, symbols) which don't
exist any more because their containing strtab has been vaporized.  The
original Solaris design used .dynsym and .dynstr (well, actually,
.ldynsym, which has more symbols) which do not disappear. So should we.

Thankfully the work we did before serves as guide rails, and adjusting
things to use the .dynstr and .dynsym was fast and easy.  The only
annoyance is that the dynsym is assembled inside elflink.c in a fairly
piecemeal fashion, so that the easiest way to get the symbols out was to
hook in before every call to swap_symbol_out (we also leave in a hook in
front of symbol additions to the .symtab because it seems plausible that
we might want to hook them in future too: for now that hook is unused).
We adjust things so that rather than being offered a whole hash table of
symbols at once, libctf is now given symbols one at a time, with st_name
indexes already resolved and pointing at their final .dynstr offsets:
it's now up to libctf to resolve these to names as needed using the
strtab info we pass it separately.

Some bits might be contentious.  The ctf_new_dynstr callback takes an
elf_internal_sym, and this remains an elf_internal_sym right down
through the generic emulation layers into ldelfgen.  This is no worse
than the elf_sym_strtab we used to pass down, but in the future when we
gain non-ELF CTF symtab support we might want to lower the
elf_internal_sym to some other representation (perhaps a
ctf_link_symbol) in bfd or in ldlang_ctf_new_dynsym.  We rename the
'apply_strsym' hooks to 'acquire_strings' instead, becuse they no longer
have anything to do with symbols.

There are some API changes to pieces of API which are technically public
but actually totally unused by anything and/or unused by anything but ld
so they can change freely: the ctf_link_symbol gains new fields to allow
symbol names to be given as strtab offsets as well as strings, and a
symidx so that the symbol index can be passed in.  ctf_link_shuffle_syms
loses its callback parameter: the idea now is that linkers call the new
ctf_link_add_linker_symbol for every symbol in .dynsym, feed in all the
strtab entries with ctf_link_add_strtab, and then a call to
ctf_link_shuffle_syms will apply both and arrange to use them to reorder
the CTF symtab at CTF serialization time (which is coming in the next
commit).

Inside libctf we have a new preamble flag CTF_F_DYNSTR which is always
set in v3-format CTF dicts from this commit forwards: CTF dicts without
this flag are associated with .strtab like they used to be, so that old
dicts' external strings don't turn to garbage when loaded by new libctf.
Dicts with this flag are associated with .dynstr and .dynsym instead.
(The flag is not the next in sequence because this commit was written
quite late: the missing flags will be filled in by the next commit.)

Tests forthcoming in a later commit in this series.

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

* elflink.c (elf_finalize_dynstr): Call examine_strtab after
dynstr finalization.
(elf_link_swap_symbols_out): Don't call it here.  Call
ctf_new_symbol before swap_symbol_out.
(elf_link_output_extsym): Call ctf_new_dynsym before
swap_symbol_out.
(bfd_elf_final_link): Likewise.
* elf.c (swap_out_syms): Pass in bfd_link_info.  Call
ctf_new_symbol before swap_symbol_out.
(_bfd_elf_compute_section_file_positions): Adjust.

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

* readelf.c (dump_section_as_ctf): Use .dynsym and .dynstr, not
.symtab and .strtab.

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

* bfdlink.h (struct elf_sym_strtab): Replace with...
(struct elf_internal_sym): ... this.
(struct bfd_link_callbacks) <examine_strtab>: Take only a
symstrtab argument.
<ctf_new_symbol>: New.
<ctf_new_dynsym>: Likewise.
* ctf-api.h (struct ctf_link_sym) <st_symidx>: New.
<st_nameidx>: Likewise.
<st_nameidx_set>: Likewise.
(ctf_link_iter_symbol_f): Removed.
(ctf_link_shuffle_syms): Remove most parameters, just takes a
ctf_dict_t now.
(ctf_link_add_linker_symbol): New, split from
ctf_link_shuffle_syms.
* ctf.h (CTF_F_DYNSTR): New.
(CTF_F_MAX): Adjust.

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

* ldelfgen.c (struct ctf_strsym_iter_cb_arg): Rename to...
(struct ctf_strtab_iter_cb_arg): ... this, changing fields:
<syms>: Remove.
<symcount>: Remove.
<symstrtab>: Rename to...
<strtab>: ... this.
(ldelf_ctf_strtab_iter_cb): Adjust.
(ldelf_ctf_symbols_iter_cb): Remove.
(ldelf_new_dynsym_for_ctf): New, tell libctf about a single
symbol.
(ldelf_examine_strtab_for_ctf): Rename to...
(ldelf_acquire_strings_for_ctf): ... this, only doing the strtab
portion and not symbols.
* ldelfgen.h: Adjust declarations accordingly.
* ldemul.c (ldemul_examine_strtab_for_ctf): Rename to...
(ldemul_acquire_strings_for_ctf): ... this.
(ldemul_new_dynsym_for_ctf): New.
* ldemul.h: Adjust declarations accordingly.
* ldlang.c (ldlang_ctf_apply_strsym): Rename to...
(ldlang_ctf_acquire_strings): ... this.
(ldlang_ctf_new_dynsym): New.
(lang_write_ctf): Call ldemul_new_dynsym_for_ctf with NULL to do
the actual symbol shuffle.
* ldlang.h (struct elf_strtab_hash): Adjust accordingly.
* ldmain.c (bfd_link_callbacks): Wire up new/renamed callbacks.

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

* ctf-link.c (ctf_link_shuffle_syms): Adjust.
(ctf_link_add_linker_symbol): New, unimplemented stub.
* libctf.ver: Add it.
* ctf-create.c (ctf_serialize): Set CTF_F_DYNSTR on newly-serialized
dicts.
* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Check for the flag: open the
symtab/strtab if not present, dynsym/dynstr otherwise.
* ctf-archive.c (ctf_arc_bufpreamble): New, get the preamble from
some arbitrary member of a CTF archive.
* ctf-impl.h (ctf_arc_bufpreamble): Declare it.

3 years agoobjdump, readelf: Report errors from CTF archive iteration
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
objdump, readelf: Report errors from CTF archive iteration

We were failing to report errors from ctf_archive_iter, which results in
silent early termination if (for example) one CTF archive member in a
.ctf section is corrupted and cannot be opened.  Report the error in the
usual fashion instead.

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

* objdump.c (dump_ctf): Report errors from ctf_archive_iter.
* readelf.c (dump_section_as_ctf): Likewise.

3 years agolibctf, include, binutils, gdb: rename CTF-opening functions
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf, include, binutils, gdb: rename CTF-opening functions

The functions that return ctf_dict_t's given a ctf_archive_t and a name
are very clumsily named.  It sounds like they return *archives*, not
dictionaries, and the names are very long and clunky.  Why do we
have a ctf_arc_open_by_name when it opens a dictionary, not an archive,
and when there is no way to open a dictionary in any other way?  The
answer is purely internal: the function is located in ctf-archive.c,
and everything in there was called ctf_arc_*, and there is another
way to open a dict (by offset in the archive), that is internal to
ctf-archive.c and that nothing else can call.

This is clearly bad naming. The internal organization of the source tree
should not dictate public API names!

So rename things (keeping the old, bad names for compatibility), and
adjust all users.  You now open a dict using ctf_dict_open, and
open it giving ELF sections via ctf_dict_open_sections.

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

* objdump.c (dump_ctf): Use ctf_dict_open, not
ctf_arc_open_by_name.
* readelf.c (dump_section_as_ctf): Likewise.

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

* ctfread.c (elfctf_build_psymtabs): Use ctf_dict_open, not
ctf_arc_open_by_name.

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

* ctf-api.h (ctf_arc_open_by_name): Rename to...
(ctf_dict_open): ... this, keeping compatibility function.
(ctf_arc_open_by_name_sections): Rename to...
(ctf_dict_open_sections): ... this, keeping compatibility function.

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

* ctf-archive.c (ctf_arc_open_by_offset): Rename to...
(ctf_dict_open_by_offset): ... this.  Adjust callers.
(ctf_arc_open_by_name_internal): Rename to...
(ctf_dict_open_internal): ... this.  Adjust callers.
(ctf_arc_open_by_name_sections): Rename to...
(ctf_dict_open_sections): ... this, keeping compatibility function.
(ctf_arc_open_by_name): Rename to...
(ctf_dict_open): ... this, keeping compatibility function.
* libctf.ver: New functions added.
* ctf-link.c (ctf_link_one_input_archive): Adjusted accordingly.
(ctf_link_deduplicating_open_inputs): Likewise.

3 years agolibctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t
Nick Alcock [Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)] 
libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t

The naming of the ctf_file_t type in libctf is a historical curiosity.
Back in the Solaris days, CTF dictionaries were originally generated as
a separate file and then (sometimes) merged into objects: hence the
datatype was named ctf_file_t, and known as a "CTF file".  Nowadays, raw
CTF is essentially never written to a file on its own, and the datatype
changed name to a "CTF dictionary" years ago.  So the term "CTF file"
refers to something that is never a file!  This is at best confusing.

The type has also historically been known as a 'CTF container", which is
even more confusing now that we have CTF archives which are *also* a
sort of container (they contain CTF dictionaries), but which are never
referred to as containers in the source code.

So fix this by completing the renaming, renaming ctf_file_t to
ctf_dict_t throughout, and renaming those few functions that refer to
CTF files by name (keeping compatibility aliases) to refer to dicts
instead.  Old users who still refer to ctf_file_t will see (harmless)
pointer-compatibility warnings at compile time, but the ABI is unchanged
(since C doesn't mangle names, and ctf_file_t was always an opaque type)
and things will still compile fine as long as -Werror is not specified.
All references to CTF containers and CTF files in the source code are
fixed to refer to CTF dicts instead.

Further (smaller) renamings of annoyingly-named functions to come, as
part of the process of souping up queries across whole archives at once
(needed for the function info and data object sections).

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

* objdump.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
(dump_ctf_archive_member): Likewise.
(dump_ctf): Likewise. Use ctf_dict_close, not ctf_file_close.
* readelf.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
(dump_ctf_archive_member): Likewise.
(dump_section_as_ctf): Likewise.  Use ctf_dict_close, not
ctf_file_close.

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

* ctfread.c: Change uses of ctf_file_t to ctf_dict_t.
(ctf_fp_info::~ctf_fp_info): Call ctf_dict_close, not ctf_file_close.

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

* ctf-api.h (ctf_file_t): Rename to...
(ctf_dict_t): ... this.  Keep ctf_file_t around for compatibility.
(struct ctf_file): Likewise rename to...
(struct ctf_dict): ... this.
(ctf_file_close): Rename to...
(ctf_dict_close): ... this, keeping compatibility function.
(ctf_parent_file): Rename to...
(ctf_parent_dict): ... this, keeping compatibility function.
All callers adjusted.
* ctf.h: Rename references to ctf_file_t to ctf_dict_t.
(struct ctf_archive) <ctfa_nfiles>: Rename to...
<ctfa_ndicts>: ... this.

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

* ldlang.c (ctf_output): This is a ctf_dict_t now.
(lang_ctf_errs_warnings): Rename ctf_file_t to ctf_dict_t.
(ldlang_open_ctf): Adjust comment.
(lang_merge_ctf): Use ctf_dict_close, not ctf_file_close.
* ldelfgen.h (ldelf_examine_strtab_for_ctf): Rename ctf_file_t to
ctf_dict_t.  Change opaque declaration accordingly.
* ldelfgen.c (ldelf_examine_strtab_for_ctf): Adjust.
* ldemul.h (examine_strtab_for_ctf): Likewise.
(ldemul_examine_strtab_for_ctf): Likewise.
* ldeuml.c (ldemul_examine_strtab_for_ctf): Likewise.

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

* ctf-impl.h: Rename ctf_file_t to ctf_dict_t: all declarations
adjusted.
(ctf_fileops): Rename to...
(ctf_dictops): ... this.
(ctf_dedup_t) <cd_id_to_file_t>: Rename to...
<cd_id_to_dict_t>: ... this.
(ctf_file_t): Fix outdated comment.
<ctf_fileops>: Rename to...
<ctf_dictops>: ... this.
(struct ctf_archive_internal) <ctfi_file>: Rename to...
<ctfi_dict>: ... this.
* ctf-archive.c: Rename ctf_file_t to ctf_dict_t.
Rename ctf_archive.ctfa_nfiles to ctfa_ndicts.
Rename ctf_file_close to ctf_dict_close.  All users adjusted.
* ctf-create.c: Likewise.  Refer to CTF dicts, not CTF containers.
(ctf_bundle_t) <ctb_file>: Rename to...
<ctb_dict): ... this.
* ctf-decl.c: Rename ctf_file_t to ctf_dict_t.
* ctf-dedup.c: Likewise.  Rename ctf_file_close to
ctf_dict_close. Refer to CTF dicts, not CTF containers.
* ctf-dump.c: Likewise.
* ctf-error.c: Likewise.
* ctf-hash.c: Likewise.
* ctf-inlines.h: Likewise.
* ctf-labels.c: Likewise.
* ctf-link.c: Likewise.
* ctf-lookup.c: Likewise.
* ctf-open-bfd.c: Likewise.
* ctf-string.c: Likewise.
* ctf-subr.c: Likewise.
* ctf-types.c: Likewise.
* ctf-util.c: Likewise.
* ctf-open.c: Likewise.
(ctf_file_close): Rename to...
(ctf_dict_close): ...this.
(ctf_file_close): New trivial wrapper around ctf_dict_close, for
compatibility.
(ctf_parent_file): Rename to...
(ctf_parent_dict): ... this.
(ctf_parent_file): New trivial wrapper around ctf_parent_dict, for
compatibility.
* libctf.ver: Add ctf_dict_close and ctf_parent_dict.

3 years agolanguage_lookup_primitive_type, std::function -> gdb::function_view
Pedro Alves [Mon, 16 Nov 2020 19:15:00 +0000 (19:15 +0000)] 
language_lookup_primitive_type, std::function -> gdb::function_view

gdb/ChangeLog:

* language.c (language_arch_info::lookup_primitive_type): Use
gdb::function_view instead of gdb::function.
(template language_lookup_primitive_type): Rename to ...
(language_lookup_primitive_type_1): ... this, and make static.
(language_lookup_primitive_type(const struct language_defn *,
struct gdbarch *, const char *): Make non-template.
(language_lookup_primitive_type(const struct language_defn *,
struct gdbarch *, std::function<bool (struct type *)>): Make
non-template and use gdb::function_view.
* language.h (language_arch_info::lookup_primitive_type): Use
gdb::function_view instead of std::function.
(language_lookup_primitive_type): No longer template.
* opencl-lang.c (lookup_opencl_vector_type): 'filter' is now a
lambda instead of a std::function.

3 years agoAdd option to nm to change the characters displayed for ifunc symbols. Add a configu...
Nick Clifton [Fri, 20 Nov 2020 13:04:56 +0000 (13:04 +0000)] 
Add option to nm to change the characters displayed for ifunc symbols.  Add a configure time option to change the default characters.

PR 22967
* nm.c (ifunc_type_chars): New variable.
(long_options): Add --ifunc-chars.
(print_symbol): Use ifunc_type_chars for ifunc symbols.
(main): Handle the new option.
* doc/binutils.texi: Document the new option.
* configure.ac: Add --enable-f-for-ifunc-symbols option which
changes the default symbol displayed by nm.
* NEWS: Mention the new feature.
* testsuite/binutils-all/nm.exp: Test the new feature.
* config.in: Regenerate.
* configure: Regenerate.

3 years agoAdd a warning to dllwrap that it is deprecated.
Linda Zhang [Fri, 20 Nov 2020 11:07:26 +0000 (11:07 +0000)] 
Add a warning to dllwrap that it is deprecated.

PR 20979
* dllwrap.c (main): Deprecate and warn the use of dllwrap.

3 years agoFix SHF_GNU_RETAIN testsuite fallout
Jozef Lawrynowicz [Fri, 20 Nov 2020 10:31:07 +0000 (10:31 +0000)] 
Fix SHF_GNU_RETAIN testsuite fallout

binutils/ChangeLog:

* testsuite/binutils-all/readelf-maskos-1a.d: Fix test for unrecognized
bit set in SHF_MASKOS range.
* testsuite/binutils-all/readelf-maskos-1b.d: Likewise.
* testsuite/binutils-all/readelf-maskos-unknown.s: New test.

ld/ChangeLog:

* testsuite/ld-elf/retain3.s: Move symbolic reference into writeable
.data section from read-only .text section.
* testsuite/ld-elf/retain5.d: Don't pass --print-gc-sections for test
that doesn't require it.
* testsuite/ld-elf/retain6a.d: Adjust test.
* testsuite/ld-elf/retain6main.s: Move symbolic reference into writeable
.data section from read-only .text section.

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 20 Nov 2020 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogas/testsuite: Fix SHF_GNU_RETAIN tests for FreeBSD OSABIs
Jozef Lawrynowicz [Thu, 19 Nov 2020 18:56:15 +0000 (18:56 +0000)] 
gas/testsuite: Fix SHF_GNU_RETAIN tests for FreeBSD OSABIs

gas/ChangeLog:

* testsuite/gas/elf/section22.d: Allow FreeBSD OSABI in readelf
output.
* testsuite/gas/elf/section23a.d: Likewise.
* testsuite/gas/elf/section24a.d: Likewise.

3 years agogdb/s390: Correct recording of "store on condition" insns
Andreas Arnez [Thu, 19 Nov 2020 18:10:58 +0000 (19:10 +0100)] 
gdb/s390: Correct recording of "store on condition" insns

The "store on condition" instructions STOC, STOCG, and STOCFH are recorded
as if their instruction formats resembled that of STG.  This is wrong,
usually resulting in "failed to record execution log" errors when trying
to record code with any of these instructions.

This patch fixes the recording of these instructions.

gdb/ChangeLog:

PR tdep/26916
* s390-tdep.c (s390_process_record): Fix recording of STOC, STOCG,
and STOCFH.

3 years agoFix a bug in the s390x linker when discarding all inpuit files.
Nick Clifton [Thu, 19 Nov 2020 17:36:24 +0000 (17:36 +0000)] 
Fix a bug in the s390x linker when discarding all inpuit files.

PR 26918
* elf64-s390.c (elf_s390_finish_dynamic_sections): Check for the
existance of an sgot output section before setting the
sh_entsize.

3 years agogdb: fix format string warnings in f-lang.c
Simon Marchi [Thu, 19 Nov 2020 16:31:34 +0000 (11:31 -0500)] 
gdb: fix format string warnings in f-lang.c

I get a bunch of these warnings when compiling for i386 (32-bit):

      CXX    f-lang.o
    /home/simark/src/binutils-gdb/gdb/f-lang.c: In function 'value* fortran_value_subarray(value*, expression*, int*, int, noside)':
    /home/simark/src/binutils-gdb/gdb/f-lang.c:453:48: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'LONGEST' {aka 'long long int'} [-Werror=format=]
      453 |        debug_printf ("|   |   |-> Low bound: %ld\n", lb);
          |                                              ~~^     ~~
          |                                                |     |
          |                                                |     LONGEST {aka long long int}
          |                                                long int
          |                                              %lld

Fix them by using plongest/pulongest.

gdb/ChangeLog:

* f-lang.c (fortran_value_subarray): Use plongest/pulongest.

Change-Id: I666ead5593653d5a1a3dab2ffdc72942c928c7d2

3 years agogdb: remove `other` parameter in read_core_file_mappings parameter
Simon Marchi [Thu, 19 Nov 2020 15:34:57 +0000 (10:34 -0500)] 
gdb: remove `other` parameter in read_core_file_mappings parameter

The `void *other` parameter in read_core_file_mappings' loop_cb
parameter is never used, remove it.

gdb/ChangeLog:

* gdbarch.sh (read_core_file_mappings): Remove `other` parameter
in `loop_cb` parameter.
* gdbarch.c: Re-generate.
* gdbarch.h: Re-generate.
* arch-utils.c (default_read_core_file_mappings): Remove `other`
parameter.
* arch-utils.h (default_read_core_file_mappings): Likewise.
* corelow.c (core_target::build_file_mappings): Likewise.
* linux-tdep.c (linux_read_core_file_mappings): Likewise.
(linux_core_info_proc_mappings): Likewise.

Change-Id: I6f408b4962b61b8a603642a844772b3026625523

3 years agogdb/fortran: Add support for Fortran array slices at the GDB prompt
Andrew Burgess [Thu, 8 Oct 2020 15:45:59 +0000 (16:45 +0100)] 
gdb/fortran: Add support for Fortran array slices at the GDB prompt

This commit brings array slice support to GDB.

WARNING: This patch contains a rather big hack which is limited to
Fortran arrays, this can be seen in gdbtypes.c and f-lang.c.  More
details on this below.

This patch rewrites two areas of GDB's Fortran support, the code to
extract an array slice, and the code to print an array.

After this commit a user can, from the GDB prompt, ask for a slice of
a Fortran array and should get the correct result back.  Slices can
(optionally) have the lower bound, upper bound, and a stride
specified.  Slices can also have a negative stride.

Fortran has the concept of repacking array slices.  Within a compiled
Fortran program if a user passes a non-contiguous array slice to a
function then the compiler may have to repack the slice, this involves
copying the elements of the slice to a new area of memory before the
call, and copying the elements back to the original array after the
call.  Whether repacking occurs will depend on which version of
Fortran is being used, and what type of function is being called.

This commit adds support for both packed, and unpacked array slicing,
with the default being unpacked.

With an unpacked array slice, when the user asks for a slice of an
array GDB creates a new type that accurately describes where the
elements of the slice can be found within the original array, a
value of this type is then returned to the user.  The address of an
element within the slice will be equal to the address of an element
within the original array.

A user can choose to select packed array slices instead using:

  (gdb) set fortran repack-array-slices on|off
  (gdb) show fortran repack-array-slices

With packed array slices GDB creates a new type that reflects how the
elements of the slice would look if they were laid out in contiguous
memory, allocates a value of this type, and then fetches the elements
from the original array and places then into the contents buffer of
the new value.

One benefit of using packed slices over unpacked slices is the memory
usage, taking a small slice of N elements from a large array will
require (in GDB) N * ELEMENT_SIZE bytes of memory, while an unpacked
array will also include all of the "padding" between the
non-contiguous elements.  There are new tests added that highlight
this difference.

There is also a new debugging flag added with this commit that
introduces these commands:

  (gdb) set debug fortran-array-slicing on|off
  (gdb) show debug fortran-array-slicing

This prints information about how the array slices are being built.

As both the repacking, and the array printing requires GDB to walk
through a multi-dimensional Fortran array visiting each element, this
commit adds the file f-array-walk.h, which introduces some
infrastructure to support this process.  This means the array printing
code in f-valprint.c is significantly reduced.

The only slight issue with this commit is the "rather big hack" that I
mentioned above.  This hack allows us to handle one specific case,
array slices with negative strides.  This is something that I don't
believe the current GDB value contents model will allow us to
correctly handle, and rather than rewrite the value contents code
right now, I'm hoping to slip this hack in as a work around.

The problem is that, as I see it, the current value contents model
assumes that an object base address will be the lowest address within
that object, and that the contents of the object start at this base
address and occupy the TYPE_LENGTH bytes after that.

( We do have the embedded_offset, which is used for C++ sub-classes,
such that an object can start at some offset from the content buffer,
however, the assumption that the object then occupies the next
TYPE_LENGTH bytes is still true within GDB. )

The problem is that Fortran arrays with a negative stride don't follow
this pattern.  In this case the base address of the object points to
the element with the highest address, the contents of the array then
start at some offset _before_ the base address, and proceed for one
element _past_ the base address.

As the stride for such an array would be negative then, in theory the
TYPE_LENGTH for this type would also be negative.  However, in many
places a value in GDB will degrade to a pointer + length, and the
length almost always comes from the TYPE_LENGTH.

It is my belief that in order to correctly model this case the value
content handling of GDB will need to be reworked to split apart the
value's content buffer (which is a block of memory with a length), and
the object's in memory base address and length, which could be
negative.

Things are further complicated because arrays with negative strides
like this are always dynamic types.  When a value has a dynamic type
and its base address needs resolving we actually store the address of
the object within the resolved dynamic type, not within the value
object itself.

In short I don't currently see an easy path to cleanly support this
situation within GDB.  And so I believe that leaves two options,
either add a work around, or catch cases where the user tries to make
use of a negative stride, or access an array with a negative stride,
and throw an error.

This patch currently goes with adding a work around, which is that
when we resolve a dynamic Fortran array type, if the stride is
negative, then we adjust the base address to point to the lowest
address required by the array.  The printing and slicing code is aware
of this adjustment and will correctly slice and print Fortran arrays.

Where this hack will show through to the user is if they ask for the
address of an array in their program with a negative array stride, the
address they get from GDB will not match the address that would be
computed within the Fortran program.

gdb/ChangeLog:

* Makefile.in (HFILES_NO_SRCDIR): Add f-array-walker.h.
* NEWS: Mention new options.
* f-array-walker.h: New file.
* f-lang.c: Include 'gdbcmd.h' and 'f-array-walker.h'.
(repack_array_slices): New static global.
(show_repack_array_slices): New function.
(fortran_array_slicing_debug): New static global.
(show_fortran_array_slicing_debug): New function.
(value_f90_subarray): Delete.
(skip_undetermined_arglist): Delete.
(class fortran_array_repacker_base_impl): New class.
(class fortran_lazy_array_repacker_impl): New class.
(class fortran_array_repacker_impl): New class.
(fortran_value_subarray): Complete rewrite.
(set_fortran_list): New static global.
(show_fortran_list): Likewise.
(_initialize_f_language): Register new commands.
(fortran_adjust_dynamic_array_base_address_hack): New function.
* f-lang.h (fortran_adjust_dynamic_array_base_address_hack):
Declare.
* f-valprint.c: Include 'f-array-walker.h'.
(class fortran_array_printer_impl): New class.
(f77_print_array_1): Delete.
(f77_print_array): Delete.
(fortran_print_array): New.
(f_value_print_inner): Update to call fortran_print_array.
* gdbtypes.c: Include 'f-lang.h'.
(resolve_dynamic_type_internal): Call
fortran_adjust_dynamic_array_base_address_hack.

gdb/testsuite/ChangeLog:

        * gdb.fortran/array-slices-bad.exp: New file.
        * gdb.fortran/array-slices-bad.f90: New file.
        * gdb.fortran/array-slices-sub-slices.exp: New file.
        * gdb.fortran/array-slices-sub-slices.f90: New file.
        * gdb.fortran/array-slices.exp: Rewrite tests.
        * gdb.fortran/array-slices.f90: Rewrite tests.
        * gdb.fortran/vla-sizeof.exp: Correct expected results.

gdb/doc/ChangeLog:

        * gdb.texinfo (Debugging Output): Document 'set/show debug
        fortran-array-slicing'.
        (Special Fortran Commands): Document 'set/show fortran
        repack-array-slices'.

3 years agogdb: update command completion for watch, awatch, and rwatch
Andrew Burgess [Mon, 16 Nov 2020 16:50:03 +0000 (16:50 +0000)] 
gdb: update command completion for watch, awatch, and rwatch

Switch over to using new option processing mechanism for watch,
awatch, and rwatch commands.  Add command completion function.

This means that expression completion now works correctly when the
-location flag is used.  So previously:

  (gdb) watch var.<TAB><TAB>
  .... list fields of var ....

But,

  (gdb) watch -location var.<TAB><TAB>
  .... list all symbols ....

After this commit only the fields of 'var' are listed even when
'-location' is passed.

Another benefit of this change is that '-location' will now complete.

One thing to note is that previous these commands accepted both
'-location' or '-l' (these being synonyms).  The new option scheme
doesn't really allow for official short form flags, however, it does
allow for non-ambiguous sub-strings to be used.  What this means is
that currently (as these commands only have the '-location' flag) the
user can still use '-l', so there's no change there.

The interactive help text for these commands now emphasises
'-location' as the real option, but does mention that '-l' can also be
used.

gdb/ChangeLog:

* breakpoint.c (struct watch_options): New struct.
(watch_option_defs): New static global.
(make_watch_options_def_group): New function.
(watch_maybe_just_location): Convert option parsing.
(watch_command_completer): New function.
(_initialize_breakpoint): Build help text using options mechanism.

gdb/testsuite/ChangeLog:

* gdb.base/completion.exp: Add new completion tests.

3 years agogdb: convert some function arguments from int to bool
Andrew Burgess [Mon, 16 Nov 2020 16:12:44 +0000 (16:12 +0000)] 
gdb: convert some function arguments from int to bool

A little int to bool conversion around the 'watch' type commands.
There should be no user visible changes after this commit.

gdb/ChangeLog:

* breakpoint.c (update_watchpoint): Pass 'false' not '0'.
(watch_command_1): Update parameter types.  Convert locals to
bool.
(watch_command_wrapper): Change parameter type.
(watch_maybe_just_location): Change locals to bool.
(rwatch_command_wrapper): Update parameter type.
(awatch_command_wrapper): Update parameter type.
* breakpoint.h (watch_command_wrapper): Change parameter type.
(rwatch_command_wrapper): Update parameter type.
(awatch_command_wrapper): Update parameter type.
* eval.c (fetch_subexp_value): Change parameter type.
* ppc-linux-nat.c (ppc_linux_nat_target::check_condition): Pass
'false' not '0'.
* value.h (fetch_subexp_value): Change parameter type in
declaration.

3 years agogdb: make use of skip_to_space and skip_spaces
Andrew Burgess [Thu, 19 Nov 2020 10:09:42 +0000 (10:09 +0000)] 
gdb: make use of skip_to_space and skip_spaces

Some late feedback on this commit:

  commit 037d7135de575c9e0c20e9158c105979bfee339c
  Date:   Mon Nov 16 11:36:56 2020 +0000

      gdb: improve command completion for 'print', 'x', and 'display'

Suggested making use of the skip_to_space and skip_spaces helper
functions.  There should be no user visible changes after this commit.

gdb/ChangeLog:

* printcmd.c (skip_over_slash_fmt): Make use of skip_to_space and
skip_spaces.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 19 Nov 2020 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoSquash coverity warning for REVERSE_INULL in dump_note_entry_p
Keith Seitz [Wed, 18 Nov 2020 20:57:53 +0000 (12:57 -0800)] 
Squash coverity warning for REVERSE_INULL in dump_note_entry_p

Coverity detected a "defect" in dump_note_entry_p in linux-tdep.c:

  static int
  dump_note_entry_p (filter_flags filterflags, const struct smaps_vmflags *v,
                  int maybe_private_p, int mapping_anon_p, int mapping_file_p,
                  const char *filename, ULONGEST addr, ULONGEST offset)
  {
    /* vDSO and vsyscall mappings will end up in the core file.  Don't
       put them in the NT_FILE note.  */
    if (strcmp ("[vdso]", filename) == 0
        || strcmp ("[vsyscall]", filename) == 0)
      return 0;

    /* Otherwise, any other file-based mapping should be placed in the
       note.  */
    return filename != nullptr;
  }

Those strcmp's will derefernce `filename' so there is little point
to checking whether it is non-NULL or not;  we would have already
segfaulted.  It also cannot be nullptr because its value is read directly
from /proc/PID/maps. The "worst" it can be is an empty string.

gdb/ChangeLog
2020-11-18  Keith Seitz  <keiths@redhat.com>

* linux-tdep.c (dump_note_entry_p): Return true instead of
checking `filename'.

3 years ago[gdb] Improve early exits for env var in debuginfod-support.c
Tom de Vries [Wed, 18 Nov 2020 21:15:50 +0000 (22:15 +0100)] 
[gdb] Improve early exits for env var in debuginfod-support.c

There's an early exit in libdebuginfod's debuginfod_query_server, which checks
both for:
- getenv (DEBUGINFOD_URLS_ENV_VAR) == NULL, and
- (getenv (DEBUGINFOD_URLS_ENV_VAR))[0] == '\0'.

In debuginfod_source_query and debuginfod_debuginfo_query (which both
end up calling debuginfod_query_server) there are also early exits checking
the same env var, but those just check for NULL.

Make the early exit tests in debuginfod-support.c match those in
libdebuginfod.

gdb/ChangeLog:

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

* debuginfod-support.c (debuginfod_source_query)
(debuginfod_debuginfo_query): Also do early exit if
"(getenv (DEBUGINFOD_URLS_ENV_VAR))[0] == '\0'".

3 years agogdb/testsuite: gdb.mi/mi-nonstop-exit.exp: enable non-stop using GDBFLAGS
Simon Marchi [Wed, 18 Nov 2020 19:58:43 +0000 (14:58 -0500)] 
gdb/testsuite: gdb.mi/mi-nonstop-exit.exp: enable non-stop using GDBFLAGS

When running

    make check TESTS="gdb.mi/mi-nonstop-exit.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"

We get:

    220^error,msg="Unexpected vCont reply in non-stop mode: T05swbreak:;06:60d5ffffff7f0000;07:d0d2ffffff7f0000;10:5b57fdf7ff7f0000;thread:p2a4eed.2a4eed;core    :4;"^M
    (gdb) ^M
    UNRESOLVED: gdb.mi/mi-nonstop-exit.exp: first run: unable to start target

This is because non-stop is enabled using "-gdb-set non-stop 1".  This
doesn't work with the native-extended-gdbserver board, because with that
board GDB connects to GDBserver as soon as it's started.  Non-stop needs
to be enabled before connecting.

The usual pattern to follow is to set non-stop on the command line, like
gdb.mi/mi-nonstop.exp does.  Change the non-stop MI tests to use that
pattern.

The results diff when running gdb.mi/*.exp is:

    -# of expected passes           2877
    +# of expected passes           2938
     # of unexpected failures       34
     # of expected failures         8
     # of known failures            13
     # of unresolved testcases      4
     # of unsupported tests         1
    -# of duplicate test names      34
    +# of duplicate test names      35

gdb/testsuite/ChangeLog:

* gdb.mi/mi-nonstop-exit.exp: Enable non-stop through GDBFLAGS.
* gdb.mi/mi-ns-stale-regcache.exp: Likewise.
* gdb.mi/mi-nsintrall.exp: Likewise.
* gdb.mi/mi-nsmoribund.exp: Likewise.
* gdb.mi/mi-nsthrexec.exp: Likewise.
* gdb.mi/mi-watch-nonstop.exp: Likewise.

Change-Id: Ic2736bedea8d448eee8c2b534d26b2427f6b4d27

3 years agogdb/testsuite: use unresolved in mi_run_cmd_full
Simon Marchi [Wed, 18 Nov 2020 19:58:42 +0000 (14:58 -0500)] 
gdb/testsuite: use unresolved in mi_run_cmd_full

Running:

    make check TESTS="gdb.mi/mi-nonstop-exit.exp" RUNTESTFLAGS="--target_board=native-extended-gdbserver"

We get:

    Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.mi/mi-nonstop-exit.exp ...
    ERROR: Unable to start target

                    === gdb Summary ===

    # of expected passes            2

The root cause of the problem is the typical "we try to enable non-stop
after having connected to gdbserver".  This is because with the
native-extended-gdbserver board, GDB connects to GDBserver as soon as
it's started.  It's too late then to do "set non-stop 1" or "-gdb-set
non-stop 1".  This is fixed by the following patch.

More worrying is that the error is not reported (except for the
printout).  From the testsuite point of view, everything went fine.
runtest exits with status 0.

This is because mi_run_cmd_full uses perror.  perror just prints that
ERROR and makes it so the next test becomes UNRESOLVED.  However,
there's no next test, because we just return early, seeing that we
couldn't run.

Change mi_run_cmd_full to call unresolved directly instead.  This
ensures that the failure is recorded.

This is the results diff when running the gdb.mi/*.exp tests:

     # of unexpected failures       34
     # of expected failures         8
     # of known failures            13
    -# of unresolved testcases      4
    +# of unresolved testcases      10
     # of unsupported tests         1
     # of duplicate test names      34

gdb/testsuite/ChangeLog:

* lib/mi-support.exp (mi_run_cmd_full): Use unresovled instead
of perror.

Change-Id: Ib0f214c0127fbe73f2033c6c29d678e025690220

3 years agoFix Windows-target testing in mi_gdb_file_cmd
Joseph Myers [Wed, 18 Nov 2020 19:44:20 +0000 (19:44 +0000)] 
Fix Windows-target testing in mi_gdb_file_cmd

Similar to my recent fix for gdb_file_cmd, mi_gdb_file_cmd also runs
into problems when GCC has created foo.exe given "-o foo".

Apply exactly the same fix there as in gdb_file_cmd.  This allows many
more tests to succeed for Windows target that previously fell over.

2020-11-18  Joseph Myers  <joseph@codesourcery.com>

* lib/mi-support.exp (mi_gdb_file_cmd): Check for case where
$arg.exe exists but $arg does not.

3 years ago[gdb/build] Fix -Werror=bool-compare warning in update_static_array_size
Tom de Vries [Wed, 18 Nov 2020 18:59:45 +0000 (19:59 +0100)] 
[gdb/build] Fix -Werror=bool-compare warning in update_static_array_size

With current trunk I run into:
...
src/gdb/gdbtypes.c: In function 'bool update_static_array_size(type*)':
src/gdb/gdbtypes.c:1250:64: error: comparison of constant '0' with boolean \
  expression is always true [-Werror=bool-compare]
    && get_array_bounds (element_type, &low_bound, &high_bound) >= 0
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
...

Fix this by dropping the compare.

gdb/ChangeLog:

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

* gdbtypes.c (update_static_array_size): Fix -Werror=bool-compare
warning.

3 years agoPowerPC paranioa testing of symbol merging involving comdat groups
Alan Modra [Wed, 18 Nov 2020 09:59:25 +0000 (20:29 +1030)] 
PowerPC paranioa testing of symbol merging involving comdat groups

Ensures we don't mistreat st_other localentry bits.

* testsuite/ld-powerpc/group1.d,
* testsuite/ld-powerpc/group1.s,
* testsuite/ld-powerpc/group1.sym,
* testsuite/ld-powerpc/group2.d,
* testsuite/ld-powerpc/group2.s,
* testsuite/ld-powerpc/group2.sym,
* testsuite/ld-powerpc/group3.s,
* testsuite/ld-powerpc/group3.sym: New test files.
* testsuite/ld-powerpc/powerpc.exp: Run new tests.

3 years agoRe: Stop Gas from generating line info or address ranges
Alan Modra [Tue, 17 Nov 2020 02:11:36 +0000 (12:41 +1030)] 
Re: Stop Gas from generating line info or address ranges

* doc/as.texi (.nop): Document optional size arg.
* dwarf2dbg.c (dwarf2_gen_line_info_1): Only check SEC_ALLOC
when ELF.  Warn whenever dwarf line number information is ignored.
* frags.c (frag_offset_ignore_align_p): New function.
* frags.h (frag_offset_ignore_align_p): Declare.
* read.c (s_nop): Extend to support optional size arg.
* testsuite/gas/elf/dwarf2-20.d: Expect warnings, and exact range.
* testsuite/gas/elf/dwarf2-20.s: Emit 16 bytes worth of nops.
* testsuite/gas/m68hc11/indexed12.d: Expect warnings.

3 years agoSupport SHF_GNU_RETAIN ELF section flag
Jozef Lawrynowicz [Wed, 18 Nov 2020 11:51:13 +0000 (11:51 +0000)] 
Support SHF_GNU_RETAIN ELF section flag

The SHF_GNU_RETAIN section flag is an extension to the GNU ELF OSABI.
It is defined as follows:

=========================================================
Section Attribute Flags
+-------------------------------------+
| Name           | Value              |
+-------------------------------------+
| SHF_GNU_RETAIN | 0x200000 (1 << 21) |
+-------------------------------------+

SHF_GNU_RETAIN
  The link editor should not garbage collect the section.
=========================================================

The .section directive accepts the "R" flag, which indicates
SHF_GNU_RETAIN should be applied to the section.

There is not a direct mapping of SHF_GNU_RETAIN to the BFD
section flag SEC_KEEP. Keeping these flags distinct allows
SHF_GNU_RETAIN sections to be explicitly removed by placing them in
/DISCARD/.

bfd/ChangeLog:

* elf-bfd.h (enum elf_gnu_osabi): Add elf_gnu_osabi_retain.
(struct elf_obj_tdata): Increase has_gnu_osabi to 4 bits.
* elf.c (_bfd_elf_make_section_from_shdr): Set elf_gnu_osabi_retain
for SHF_GNU_RETAIN.
(_bfd_elf_final_write_processing): Report if SHF_GNU_RETAIN is
not supported by the OSABI.
Adjust error messages.
* elflink.c (elf_link_input_bfd): Copy enabled has_gnu_osabi bits from
input BFD to output BFD.
(bfd_elf_gc_sections): gc_mark the section if SHF_GNU_RETAIN is set.

binutils/ChangeLog:

* NEWS: Announce SHF_GNU_RETAIN support.
* readelf.c (get_elf_section_flags): Handle SHF_GNU_RETAIN.
Recognize SHF_GNU_RETAIN and SHF_GNU_MBIND only for supported OSABIs.
* testsuite/binutils-all/readelf.exp: Run new tests.
Don't run run_dump_test when there isn't an assembler available.
* testsuite/lib/binutils-common.exp (supports_gnu_osabi): Adjust
comment.
* testsuite/binutils-all/readelf-maskos-1a.d: New test.
* testsuite/binutils-all/readelf-maskos-1b.d: New test.
* testsuite/binutils-all/readelf-maskos.s: New test.
* testsuite/binutils-all/retain1.s: New test.
* testsuite/binutils-all/retain1a.d: New test.
* testsuite/binutils-all/retain1b.d: New test.

gas/ChangeLog:

* NEWS: Announce SHF_GNU_RETAIN support.
* config/obj-elf.c (obj_elf_change_section): Merge SHF_GNU_RETAIN bit
between section declarations.
(obj_elf_parse_section_letters): Handle 'R' flag.
Handle numeric flag values within the SHF_MASKOS range.
(obj_elf_section): Validate SHF_GNU_RETAIN usage.
* doc/as.texi: Document 'R' flag to .section directive.
* testsuite/gas/elf/elf.exp: Run new tests.
* testsuite/gas/elf/section10.d: Unset SHF_GNU_RETAIN bit.
* testsuite/gas/elf/section10.s: Likewise.
* testsuite/gas/elf/section22.d: New test.
* testsuite/gas/elf/section22.s: New test.
* testsuite/gas/elf/section23.s: New test.
* testsuite/gas/elf/section23a.d: New test.
* testsuite/gas/elf/section23b.d: New test.
* testsuite/gas/elf/section23b.err: New test.
* testsuite/gas/elf/section24.l: New test.
* testsuite/gas/elf/section24.s: New test.
* testsuite/gas/elf/section24a.d: New test.
* testsuite/gas/elf/section24b.d: New test.

include/ChangeLog:

* elf/common.h (SHF_GNU_RETAIN): Define.

ld/ChangeLog:

* NEWS: Announce support for SHF_GNU_RETAIN.
* ld.texi (garbage collection): Document SHF_GNU_RETAIN.
(Output Section Discarding): Likewise.
* testsuite/ld-elf/elf.exp: Run new tests.
* testsuite/ld-elf/retain1.s: New test.
* testsuite/ld-elf/retain1a.d: New test.
* testsuite/ld-elf/retain1b.d: New test.
* testsuite/ld-elf/retain2.d: New test.
* testsuite/ld-elf/retain2.ld: New test.
* testsuite/ld-elf/retain2.map: New test.
* testsuite/ld-elf/retain3.d: New test.
* testsuite/ld-elf/retain3.s: New test.
* testsuite/ld-elf/retain4.d: New test.
* testsuite/ld-elf/retain4.s: New test.
* testsuite/ld-elf/retain5.d: New test.
* testsuite/ld-elf/retain5.map: New test.
* testsuite/ld-elf/retain5lib.s: New test.
* testsuite/ld-elf/retain5main.s: New test.
* testsuite/ld-elf/retain6a.d: New test.
* testsuite/ld-elf/retain6b.d: New test.
* testsuite/ld-elf/retain6lib.s: New test.
* testsuite/ld-elf/retain6main.s: New test.

3 years agogdb/ChangeLog: fix typo in an entry from 2020-11-15 (gmp-utils.c)
Joel Brobecker [Wed, 18 Nov 2020 03:52:46 +0000 (07:52 +0400)] 
gdb/ChangeLog: fix typo in an entry from 2020-11-15 (gmp-utils.c)

3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 18 Nov 2020 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: make get_array_bounds return bool
Simon Marchi [Tue, 17 Nov 2020 22:53:27 +0000 (17:53 -0500)] 
gdb: make get_array_bounds return bool

Obvious change from int to bool.  I took the opportunity to move the doc
to the header file.

gdb/ChangeLog:

* gdbtypes.h (get_array_bounds): Return bool, adjust some
callers.  Move doc here.
* gdbtypes.c (get_array_bounds): Return bool

Change-Id: I8ed20298cb0927963c1f09b345966533d5ed06e2

3 years agoWhen reading string arguments for the assembler's string directives treat space separ...
Nick Clifton [Tue, 17 Nov 2020 15:45:01 +0000 (15:45 +0000)] 
When reading string arguments for the assembler's string directives treat space separated strings as a single entity.

* read.c (stringer): Treat space separated, quote enclosed strings
as a single string.
* doc/as.texi (asciz): Mention this behaviour in the description
of the asciz directive.
* testsuite/gas/all/asciz.s: New test.
* testsuite/gas/all/asciz.d: New test driver.
* testsuite/gas/all/gas.exp: Run the new test.

3 years agoFix gdb.trace testcase build failures with Clang
Gary Benson [Tue, 17 Nov 2020 14:52:49 +0000 (14:52 +0000)] 
Fix gdb.trace testcase build failures with Clang

25 gdb.trace tests failed to build on x86 with Clang because the
x86_trace_dummy function is optimized out, causing the builds to
fail with variations on the following error:

  gdb compile failed, /usr/bin/ld:
    /gdbtest/build/gdb/testsuite/outputs/gdb.trace/backtrace/backtrace0.o:
    in function `main':
    /gdbtest/src/gdb/testsuite/gdb.trace/actions.c:146: undefined
    reference to `x86_trace_dummy'
    clang-12: error: linker command failed with exit code 1

This commit adds __attribute__ ((used)) to x86_trace_dummy to prevent
this.

gdb/testsuite/ChangeLog:

* gdb.trace/trace-common.h (x86_trace_dummy): Add
__attribute__ ((used)).

3 years agoPlace the libdeps record in the second archive slot.
Howard Chu [Tue, 17 Nov 2020 14:00:08 +0000 (14:00 +0000)] 
Place the libdeps record in the second archive slot.

* ar.c (main): Place the libdeps record in the second archive
slot.

3 years ago[GOLD] powerpc incremental-dump assertion failure
Alan Modra [Tue, 17 Nov 2020 04:43:37 +0000 (15:13 +1030)] 
[GOLD] powerpc incremental-dump assertion failure

incremental-dump wants to instantiate Target_powerpc without options
being set up.  This patch fixes
  internal error in options, at gold/parameters.h:92

* powerpc.cc (Target_powerpc::no_tprel_opt_): Rename from tprel_opt_.
Init to false.
(Target_powerpc::tprel_opt): Test parameters->options().tls_optimize().
(Target_powerpc::set_tprel_opt): Delete.
(Target_powerpc::set_no_tprel_opt): New function.  Update all uses
of set_tprel_opt.

3 years ago[GOLD] fix jump to long branch on powerpc
Michael Hudson-Doyle [Mon, 16 Nov 2020 01:20:23 +0000 (14:20 +1300)] 
[GOLD] fix jump to long branch on powerpc

PR 26902
* powerpc.cc (Relocate::relocate): Do not include local entry
offset of target function when computing the address of a stub.

3 years agoPR26882, --enable-textrel-check=warning test failures on powerpc
Alan Modra [Mon, 16 Nov 2020 22:08:05 +0000 (08:38 +1030)] 
PR26882, --enable-textrel-check=warning test failures on powerpc

PR 26882
* testsuite/ld-powerpc/dotsym3.d: Add "-z notext" to ld options.
* testsuite/ld-powerpc/dotsym4.d: Likewise.
* testsuite/ld-powerpc/ppc476-shared.d: Likewise.
* testsuite/ld-powerpc/ppc476-shared2.d: Likewise.
* testsuite/ld-powerpc/powerpc.exp: Likewise for various tests.
* testsuite/ld-undefined/weak-fundef.s: Add BLPLT variant.
* testsuite/ld-undefined/weak-undef.exp: Define BLPLT for ppc32.

3 years agogdb/arc: fix print_one_insn selftest
Andrew Burgess [Mon, 16 Nov 2020 15:31:16 +0000 (15:31 +0000)] 
gdb/arc: fix print_one_insn selftest

I noticed that the ARC print_one_insn selftest was failing.  The
problem is that in print_one_insn_test the arc case falls through into
the special case that handles nios2, score, and riscv.

The special case for these targets hard codes the breakpoint kind to
'4'.  This is find for bare metal arc (see arc-tdep.c,
arc_sw_breakpoint_from_kind), however, for arc/linux only breakpoint
kind '2' is supported (see arc-linux-tdep.c,
arc_linux_sw_breakpoint_from_kind).

So the code in print_one_insn_test as it is currently written passed
in an invalid breakpoint kind, this leads to GDB trying to disassemble
unexpected memory.

The fix is to reorder the code in print_one_insn_test so that the arc
case falls through into the default case.  In the default we no longer
hard code the breakpoint kind, and everything should be good.

Additionally, given the arc code only expects specific breakpoint kind
values, I thought it would be nice to add some gdb_assert to validate
things.  This assert would have triggered in this case and made it
easier to find the error.

After this commit, configure GDB with --enable-targets=all, then run
gdb.gdb/unittest.exp, there should no longer be any failures.

gdb/ChangeLog:

* arc-linux-tdep.c (arc_linux_sw_breakpoint_from_kind): Add an
assert.
* arc-tdep.c (arc_breakpoint_kind_from_pc): Likewise.
* disasm-selftests.c (print_one_insn_test): Fall throough from ARC
case to the default.

3 years agogdb/testsuite: prevent timeout in gdb.gdb/unittest.exp
Andrew Burgess [Mon, 16 Nov 2020 15:16:25 +0000 (15:16 +0000)] 
gdb/testsuite: prevent timeout in gdb.gdb/unittest.exp

When GDB is compiled with --enable-targets=all I would sometimes see
the 'maintenance selftest' in gdb.gdb/unittest.exp test timeout.

This one command causes GDB to run many separate self tests, this can
take some time.  The output of this command basically follows this
pattern:

  (gdb) maintenance selftest
  Running selftest aarch64-analyze-prologue.
  Running selftest aarch64-process-record.
  Running selftest arm-record.
  Running selftest arm_analyze_prologue.
  Running selftest array_view.
  Running selftest child_path.
  Running selftest cli_utils.
  ..... snip lots more lines ....
  Ran 79 unit tests, 0 failed

Currently the expect script waits for the final summary line ("Ran 79
unit test, 0 failed") before declaring pass or fail.  The problem is
that if the summary line takes too long to appear the test will
timeout.

As this test makes use of gdb_test_multiple then all I've done is add
an extra pattern that matches the 'Running selftest ....' lines and
then calls exp_continue.  Doing this means we find matches much more
frequently, and each time we do the timeout timer resets, preventing
the overall test from timing out.

gdb/testsuite/ChangeLog:

* gdb.gdb/unittest.exp: Spot 'Running...' lines.

3 years agogdb: improve command completion for 'print', 'x', and 'display'
Andrew Burgess [Mon, 16 Nov 2020 11:36:56 +0000 (11:36 +0000)] 
gdb: improve command completion for 'print', 'x', and 'display'

The /FMT specification on the print command currently breaks command
completion, so:

  (gdb) p var.<TAB><TAB>
  .... list of fields in var .....

But,

  (gdb) p/d var.<TAB><TAB>
  ..... list of all symbols .....

After this commit this issue is now resolved.

There are some other details around tab-completion and /FMT which
hopefully this commit improves.  So, before:

  (gdb) p/<TAB><TAB>
  .... lists all symbols .....

After:

  (gdb) p/<TAB><TAB> # Nothing changes...

The thinking here is that after a / the user must type a FMT, but we
don't offer tab completion on FMT characters.  Placing a symbol
directly after a / will not do what the user expects, so offering that
seems wrong.

Similarly, before we had:

  (gdb) p/d<TAB><TAB>
  ... lists all symbols starting with 'd' ....

But afterwards:

  (gdb) p/d<TAB><TAB> # Adds a single space, so we get:
  (gdb) p/d <CURSOR>

As before, typing a symbol where FMT is expected will not do what the
user expects.  If the user has added a FMT string then upon tab
completion GDB assumes the FMT string is complete and prepares the
user to type an expression.

In this commit I have also added completion functions for the 'x' and
'display' commands.  These commands also support /FMT specifiers and
so share some code with 'print'.

gdb/ChangeLog:

* printcmd.c: Include 'safe-ctype.c'.
(skip_over_slash_fmt): New function.
(print_command_completer): Call skip_over_slash_fmt.
(display_and_x_command_completer): New function.
(_initialize_printcmd): Add command completion for 'x' and
'display'.

gdb/testsuite/ChangeLog:

* gdb.base/completion.exp: Add new tests.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 17 Nov 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoaarch64: Add +pauth flag for Pointer Authentication feature
Przemyslaw Wirkus [Mon, 16 Nov 2020 21:17:25 +0000 (21:17 +0000)] 
aarch64: Add +pauth flag for Pointer Authentication feature

New -march option +pauth enables PAuth vel PAC (Pointer Authentication)
feature.

3 years agoaarch64: Extract Condition flag manipulation feature from Armv8.4-A
Przemyslaw Wirkus [Mon, 16 Nov 2020 20:37:39 +0000 (20:37 +0000)] 
aarch64: Extract Condition flag manipulation feature from Armv8.4-A

Extract FLAGM (Condition flag manipulation) feature from Armv8.4-A.
Please note that FLAGM stays a Armv8.4-A feature but now can be
assigned to other architectures or CPUs.

New -march option +flagm is added to enable independently this
feature.

3 years agoarm: Add support for Cortex-A78C
Przemyslaw Wirkus [Mon, 16 Nov 2020 20:26:29 +0000 (20:26 +0000)] 
arm: 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

3 years agoUpdate gdb.dwarf2/data-loc.exp
Tom Tromey [Mon, 16 Nov 2020 15:55:53 +0000 (08:55 -0700)] 
Update gdb.dwarf2/data-loc.exp

Tom de Vries pointed out that the series to handle
-fgnat-encodings=minimal regressed data-loc.exp:

https://sourceware.org/pipermail/gdb-patches/2020-November/173035.html

This was my oversight.  Looking at the test, it mimics what GNAT
emits.  The patch series in question changed the approach that gdb
takes to such arrays -- now they are transformed back into "old" style
structures.  (This is perhaps a step backward in a semantics sense,
but on the other hand it more accurately reflects the underlying
reality, and lets gdb continue to create objects of this type.)

This patch updates the test case, by adjusting the expected output.
It also removes the tests done in the C language, because they are now
incorrect, and because (IMO) they don't add much value.

gdb/testsuite/ChangeLog
2020-11-16  Tom Tromey  <tromey@adacore.com>

* gdb.dwarf2/data-loc.exp: Update expected output.  Remove C
tests.

3 years agoFix frame cycle detection
Pedro Alves [Sat, 31 Oct 2020 00:27:18 +0000 (00:27 +0000)] 
Fix frame cycle detection

The recent commit to make scoped_restore_current_thread's cdtors
exception free regressed gdb.base/eh_return.exp:

  Breakpoint 1, 0x00000000004012bb in eh2 (gdb/frame.c:641: internal-error: frame_id get_frame_id(frame_info*): Assertion `stashed' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) FAIL: gdb.base/eh_return.exp: hit breakpoint (GDB internal error)

That testcase uses __builtin_eh_return and, before the regression, the
backtrace at eh2 looked like this:

 (gdb) bt
 #0  0x00000000004006eb in eh2 (p=0x4006ec <continuation>) at src/gdb/testsuite/gdb.base/eh_return.c:54
 Backtrace stopped: previous frame identical to this frame (corrupt stack?)

That "previous frame identical to this frame" is caught by the cycle
detection based on frame id.

The assertion failing is this one:

 638           /* Since this is the first frame in the chain, this should
 639              always succeed.  */
 640           bool stashed = frame_stash_add (fi);
 641           gdb_assert (stashed);

originally added by

  commit f245535cf583ae4ca13b10d47b3c7d3334593ece
  Author:     Pedro Alves <palves@redhat.com>
  AuthorDate: Mon Sep 5 18:41:38 2016 +0100

      Fix PR19927: Avoid unwinder recursion if sniffer uses calls parse_and_eval

The assertion is failing because frame #1's frame id was stashed
before the id of frame #0 is stashed.  The frame id of frame #1 was
stashed here:

 (top-gdb) bt
 #0  frame_stash_add (frame=0x1e24c90) at src/gdb/frame.c:276
 #1  0x0000000000669c1b in get_prev_frame_if_no_cycle (this_frame=0x19f8370) at src/gdb/frame.c:2120
 #2  0x000000000066a339 in get_prev_frame_always_1 (this_frame=0x19f8370) at src/gdb/frame.c:2303
 #3  0x000000000066a360 in get_prev_frame_always (this_frame=0x19f8370) at src/gdb/frame.c:2319
 #4  0x000000000066b56c in get_frame_unwind_stop_reason (frame=0x19f8370) at src/gdb/frame.c:3028
 #5  0x000000000059f929 in dwarf2_frame_cfa (this_frame=0x19f8370) at src/gdb/dwarf2/frame.c:1462
 #6  0x00000000005ce434 in dwarf_evaluate_loc_desc::get_frame_cfa (this=0x7fffffffc070) at src/gdb/dwarf2/loc.c:666
 #7  0x00000000005989a9 in dwarf_expr_context::execute_stack_op (this=0x7fffffffc070, op_ptr=0x1b2a053 "\364\003", op_end=0x1b2a053 "\364\003") at src/gdb/dwarf2/expr.c:1161
 #8  0x0000000000596af6 in dwarf_expr_context::eval (this=0x7fffffffc070, addr=0x1b2a052 "\234\364\003", len=1) at src/gdb/dwarf2/expr.c:303
 #9  0x0000000000597b4e in dwarf_expr_context::execute_stack_op (this=0x7fffffffc070, op_ptr=0x1b2a063 "", op_end=0x1b2a063 "") at src/gdb/dwarf2/expr.c:865
 #10 0x0000000000596af6 in dwarf_expr_context::eval (this=0x7fffffffc070, addr=0x1b2a061 "\221X", len=2) at src/gdb/dwarf2/expr.c:303
 #11 0x00000000005c8b5a in dwarf2_evaluate_loc_desc_full (type=0x1b564d0, frame=0x19f8370, data=0x1b2a061 "\221X", size=2, per_cu=0x1b28760, per_objfile=0x1a84930, subobj_type=0x1b564d0, subobj_byte_offset=0) at src/gdb/dwarf2/loc.c:2260
 #12 0x00000000005c9243 in dwarf2_evaluate_loc_desc (type=0x1b564d0, frame=0x19f8370, data=0x1b2a061 "\221X", size=2, per_cu=0x1b28760, per_objfile=0x1a84930) at src/gdb/dwarf2/loc.c:2444
 #13 0x00000000005cb769 in locexpr_read_variable (symbol=0x1b59840, frame=0x19f8370) at src/gdb/dwarf2/loc.c:3687
 #14 0x0000000000663137 in language_defn::read_var_value (this=0x122ea60 <c_language_defn>, var=0x1b59840, var_block=0x0, frame=0x19f8370) at src/gdb/findvar.c:618
 #15 0x0000000000663c3b in read_var_value (var=0x1b59840, var_block=0x0, frame=0x19f8370) at src/gdb/findvar.c:822
 #16 0x00000000008c7d9f in read_frame_arg (fp_opts=..., sym=0x1b59840, frame=0x19f8370, argp=0x7fffffffc470, entryargp=0x7fffffffc490) at src/gdb/stack.c:542
 #17 0x00000000008c89cd in print_frame_args (fp_opts=..., func=0x1b597c0, frame=0x19f8370, num=-1, stream=0x1aba860) at src/gdb/stack.c:890
 #18 0x00000000008c9bf8 in print_frame (fp_opts=..., frame=0x19f8370, print_level=0, print_what=SRC_AND_LOC, print_args=1, sal=...) at src/gdb/stack.c:1394
 #19 0x00000000008c92b9 in print_frame_info (fp_opts=..., frame=0x19f8370, print_level=0, print_what=SRC_AND_LOC, print_args=1, set_current_sal=1) at src/gdb/stack.c:1119
 #20 0x00000000008c75f0 in print_stack_frame (frame=0x19f8370, print_level=0, print_what=SRC_AND_LOC, set_current_sal=1) at src/gdb/stack.c:366
 #21 0x000000000070250b in print_stop_location (ws=0x7fffffffc9e0) at src/gdb/infrun.c:8110
 #22 0x0000000000702569 in print_stop_event (uiout=0x1a8b9e0, displays=true) at src/gdb/infrun.c:8126
 #23 0x000000000096d04b in tui_on_normal_stop (bs=0x1bcd1c0, print_frame=1) at src/gdb/tui/tui-interp.c:98
 ...

Before the commit to make scoped_restore_current_thread's cdtors
exception free, scoped_restore_current_thread's dtor would call
get_frame_id on the selected frame, and we use
scoped_restore_current_thread pervasively.  That had the side effect
of stashing the frame id of frame #0 before reaching the path shown in
the backtrace.  I.e., the frame id of frame #0 happened to be stashed
before the frame id of frame #1.  But that was by chance, not by
design.

This commit:

  commit 256ae5dbc73d1348850f86ee77a0dc3b04bc7cc0
  Author:     Kevin Buettner <kevinb@redhat.com>
  AuthorDate: Mon Oct 31 12:47:42 2016 -0700

      Stash frame id of current frame before stashing frame id for previous frame

Fixed a similar problem, by making sure get_prev_frame computes the
frame id of the current frame before unwinding the previous frame, so
that the cycle detection works properly.  That fix misses the scenario
we're now running against, because if you notice, the backtrace above
shows that frame #4 calls get_prev_frame_always, not get_prev_frame.
I.e., nothing is calling get_frame_id on the current frame.

The fix here is to move Kevin's fix down from get_prev_frame to
get_prev_frame_always.  Or actually, a bit further down to
get_prev_frame_always_1 -- note that inline_frame_this_id calls
get_prev_frame_always, so we need to be careful to avoid recursion in
that scenario.

gdb/ChangeLog:

* frame.c (get_prev_frame): Move get_frame_id call from here ...
(get_prev_frame_always_1): ... to here.
* inline-frame.c (inline_frame_this_id): Mention
get_prev_frame_always_1 in comment.

Change-Id: Id960c98ab2d072c48a436c3eb160cc4b2a5cfd1d

3 years agoUpdate the Spanish translation for the ld/ subdirectory.
Nick Clifton [Mon, 16 Nov 2020 12:32:06 +0000 (12:32 +0000)] 
Update the Spanish translation for the ld/ subdirectory.

* po/es.po: Updated Spanish translation.

3 years agold: Fix the tls_ie-01 test for arc
Shahab Vahedi [Mon, 16 Nov 2020 11:48:49 +0000 (13:48 +0200)] 
ld: Fix the tls_ie-01 test for arc

The purpose of the test is to look for entries of "foo" and
"bar" in the ".got".  The old "objdump -s ..." has been replaced
with "objdump -D ..." to inspect the final executable.  A sample
output looks like:

------------------------8<------------------------

$ arc-elf32-objdump -D -j .got tls_ie-01

tls_ie-01:     file format elf32-littlearc

Disassembly of section .got:

00002110 <_GLOBAL_OFFSET_TABLE_>:
        ...
    211c:       08 00 00 00        .word   0x00000008
    2120:       0c 00 00 00        .word   0x0000000c

------------------------>8------------------------

ld/
* testsuite/ld-arc/tls_ie-01.d: Update the dump command.

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 16 Nov 2020 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoAdd support for fixed-point type comparison operators
Joel Brobecker [Sun, 15 Nov 2020 08:18:35 +0000 (03:18 -0500)] 
Add support for fixed-point type comparison operators

This patch adds support for binary comparison operators with
fixed-point type values.

gdb/ChangeLog:

        * valarith.c (fixed_point_binop): Add BINOP_EQUAL and BINOP_LESS
        handling.
        (value_less): Add fixed-point handling.

gdb/testsuite/ChangeLog:

        * gdb.ada/fixed_cmp.exp: Add -fgnat-encodings=minimal testing.
        * gdb.dwarf2/dw2-fixed-point.c (pck__fp1_var2): New global.
        (main): Add reference to pck__fp1_var2.
        * gdb.dwarf2/dw2-fixed-point.exp: Add comparison operator testing.

3 years agoAdd support for fixed-point type arithmetic
Joel Brobecker [Sun, 15 Nov 2020 08:17:12 +0000 (03:17 -0500)] 
Add support for fixed-point type arithmetic

This patch adds support for binary operations on fixed-point values,
as well as for the negative unary operator.

gdb/ChangeLog:

        * eval.c (binop_promote): Add fixed-point type handling.
        * valarith.c (fixed_point_binop): New function.
        (scalar_binop): Add fixed-point type handling.
        (value_neg): Add fixed-point type handling.
        * valops.c (value_cast_to_fixed_point): New function.
        (value_cast): Add fixed-point type handling.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-fixed-point.exp: Add arithmetic tests.

3 years agoAdd ptype support for DWARF-based fixed-point types
Joel Brobecker [Sun, 15 Nov 2020 08:16:01 +0000 (03:16 -0500)] 
Add ptype support for DWARF-based fixed-point types

Note that the ptype information printed for types described
via pure DWARF debug info is slightly less informative as
the one printed when the information is encoded in the type's
name, via the GNAT encoding. As a result, the output in
the case of DWARF-described fixed point types is slightly
different. In pratice, this is no real loss because the information
not available in DWARF has no bearing on how the type is actually
stored in memory.

gdb/ChangeLog:

        * ada-typeprint.c (ada_print_type): Add handing of fixed-point
        range types.
        * c-typeprint.c (c_type_print_varspec_prefix)
        (c_type_print_varspec_suffix, c_type_print_base_1): Add
        TYPE_CODE_FIXED_POINT handling.
        * p-typeprint.c (pascal_type_print_varspec_prefix)
        (pascal_type_print_varspec_suffix): Likewise.
        * typeprint.c (print_type_fixed_point): New function.
        * typeprint.h (print_type_fixed_point): Add declaration.

gdb/testsuite/ChangeLog:

        * gdb.ada/fixed_points.exp: Add ptype tests.
        * gdb.dwarf2/dw2-fixed-point.exp: Likewise.

3 years agofix printing of DWARF fixed-point type objects with format modifier
Joel Brobecker [Sun, 15 Nov 2020 08:14:24 +0000 (03:14 -0500)] 
fix printing of DWARF fixed-point type objects with format modifier

Consider a fixed-point type such the scaling factor is 1/16,
as the following Ada code snippet would create:

      type FP1_Type is delta 0.1 range -1.0 .. +1.0;
      FP1_Var : FP1_Type := 0.25;

Printing the value of this variable with a format modifier yields
the wrong value. E.g.:

    (gdb) p /x fp1_var
    $6 = 0x4

Since the real value is 0.25, we therefore expected...

    (gdb) p /x fp1_var
    $6 = 0x0

What happens, in this case, is that the value being printed is
actually the "raw" value of our object, before the scaling factor
gets applied.

This commit fixes the issue by using approach as for float values,
where we convert the value into an integer value, prior to printing,
knowing that the conversion takes the scaling factor into account.

gdb/ChangeLog:

        * printcmd.c (print_scalar_formatted): Add fixed-point type
        handling when options->format is set.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-fixed-point.exp: Add "print /x" tests.

3 years agoAdd support for printing value of DWARF-based fixed-point type objects
Joel Brobecker [Sun, 15 Nov 2020 08:12:52 +0000 (03:12 -0500)] 
Add support for printing value of DWARF-based fixed-point type objects

This commit introduces a new kind of type, meant to describe
fixed-point types, using a new code added specifically for
this purpose (TYPE_CODE_FIXED_POINT).

It then adds handling of fixed-point base types in the DWARF reader.

And finally, as a first step, this commit adds support for printing
the value of fixed-point type objects.

Note that this commit has a known issue: Trying to print the value
of a fixed-point object with a format letter (e.g. "print /x NAME")
causes the wrong value to be printed because the scaling factor
is not applied. Since the fix for this issue is isolated, and
this is not a regression, the fix will be made in a pach of its own.
This is meant to simplify review and archeology.

Also, other functionalities related to fixed-point type handling
(ptype, arithmetics, etc), will be added piecemeal as well, for
the same reasons (faciliate reviews and archeology). Related to this,
the testcase gdb.ada/fixed_cmp.exp is adjusted to compile the test
program with -fgnat-encodings=all, so as to force the use of GNAT
encodings, rather than rely on the compiler's default to use them.
The intent is to enhance this testcase to also test the pure DWARF
approach using -fgnat-encodings=minimal as soon as the corresponding
suport gets added in. Thus, the modification to the testcase is made
in a way that it prepares this testcase to be tested in both modes.

gdb/ChangeLog:

        * ada-valprint.c (ada_value_print_1): Add fixed-point type handling.
        * dwarf2/read.c (get_dwarf2_rational_constant)
        (get_dwarf2_unsigned_rational_constant, finish_fixed_point_type)
        (has_zero_over_zero_small_attribute): New functions.
        read_base_type, set_die_type): Add fixed-point type handling.
        * gdb-gdb.py.in: Add fixed-point type handling.
        * gdbtypes.c: #include "gmp-utils.h".
        (create_range_type, set_type_code): Add fixed-point type handling.
        (init_fixed_point_type): New function.
        (is_integral_type, is_scalar_type): Add fixed-point type handling.
        (print_fixed_point_type_info): New function.
        (recursive_dump_type, copy_type_recursive): Add fixed-point type
        handling.
        (fixed_point_type_storage): New typedef.
        (fixed_point_objfile_key): New static global.
        (allocate_fixed_point_type_info, is_fixed_point_type): New functions.
        (fixed_point_type_base_type, fixed_point_scaling_factor): New
        functions.
        * gdbtypes.h: #include "gmp-utils.h".
        (enum type_code) <TYPE_SPECIFIC_FIXED_POINT>: New enum.
        (union type_specific) <fixed_point_info>: New field.
        (struct fixed_point_type_info): New struct.
        (INIT_FIXED_POINT_SPECIFIC, TYPE_FIXED_POINT_INFO): New macros.
        (init_fixed_point_type, is_fixed_point_type)
        (fixed_point_type_base_type, fixed_point_scaling_factor)
        (allocate_fixed_point_type_info): Add declarations.
        * valprint.c (generic_val_print_fixed_point): New function.
        (generic_value_print): Add fixed-point type handling.
        * value.c (value_as_address, unpack_long): Add fixed-point type
        handling.

gdb/testsuite/ChangeLog:

        * gdb.ada/fixed_cmp.exp: Force compilation to use -fgnat-encodings=all.
        * gdb.ada/fixed_points.exp: Add fixed-point variables printing tests.
        * gdb.ada/fixed_points/pck.ads, gdb.ada/fixed_points/pck.adb:
        New files.
        * gdb.ada/fixed_points/fixed_points.adb: Add use of package Pck.

        * gdb.dwarf2/dw2-fixed-point.c, gdb.dwarf2/dw2-fixed-point.exp:
        New files.

3 years agoMove uinteger_pow gdb/valarith.c to gdb/utils.c and make it public
Joel Brobecker [Sun, 15 Nov 2020 08:10:52 +0000 (03:10 -0500)] 
Move uinteger_pow gdb/valarith.c to gdb/utils.c and make it public

This is a generic function which I would like to use in a followup
patch adding support for fixed-point types. So this commit moves it
out of valarith.c into util.c, and makes it non-static.

gdb/ChangeLog:

        * utils.h (uinteger_pow): Add declaration.
        * utils.c (uinteger_pow): Moved here (without changes)...
        * valarith.c (uinteger_pow): ... from here.

3 years agogmp-utils: New API to simply use of GMP's integer/rational/float objects
Joel Brobecker [Sun, 15 Nov 2020 08:09:44 +0000 (03:09 -0500)] 
gmp-utils: New API to simply use of GMP's integer/rational/float objects

This API was motivated by a number of reasons:
  - GMP's API does not handle "long long" and "unsigned long long",
    so using LONGEST and ULONGEST is not straightforward;
  - Automate the need to initialize GMP objects before use, and
    clear them when no longer used.

However, this API grew also to help with similar matter such
as formatting to a string, and also reading/writing fixed-point
values from byte buffers.

Dedicated unit testing is also added.

gdb/ChangeLog:

        * gmp-utils.h,  gmp-utils.h: New file.
        * unittests/gmp-utils-selftests.c: New file.
        * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
        unittests/gmp-utils-selftests.c.
        (COMMON_SFILES) Add gmp-utils.c.
        (HFILES_NO_SRCDIR): Add gmp-utils.h.

3 years agogdb: Make GMP a required dependency for building GDB
Joel Brobecker [Sun, 15 Nov 2020 08:08:40 +0000 (03:08 -0500)] 
gdb: Make GMP a required dependency for building GDB

This commit modifies gdb's configure script to trigger an error
if we cannot find a usable libgmp.

For the record, making this a requirement was discussed in March 2018:
https://sourceware.org/pipermail/gdb-patches/2018-March/147373.html

gdb/ChangeLog:

        * configure.ac: Generate an error if a usable GMP library
        could not be found.
        * configure: Regenerate.

3 years agogdb/configure: Add --with-libgmp-prefix option
Joel Brobecker [Sun, 15 Nov 2020 08:07:45 +0000 (03:07 -0500)] 
gdb/configure: Add --with-libgmp-prefix option

This patch allows a user to tell gdb's configure script where
his GMP library is installed.

gdb/ChangeLog:

        * configure.ac: Add support for --with-libgmp-prefix.
        * Makefile.in (LIBGMP): New variable.
        (CLIBS): Include $(LIBGMP).
        * configure, config.in: Regenerate

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 15 Nov 2020 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: add tab completion of type field names for Fortran
Andrew Burgess [Fri, 13 Nov 2020 18:27:42 +0000 (18:27 +0000)] 
gdb: add tab completion of type field names for Fortran

Add support for tab-completion on Fortran field names.  Consider this
test case:

 program test
   type my_type
      integer :: field_a
      integer :: other_field
      integer :: last_field
   end type my_type

   type(my_type) :: var

   print *, var
 end program test

And the GDB session before this patch:

 (gdb) start
 ...
 (gdb) p var%                   <- Trigger TAB completion here.
 Display all 200 possibilities? (y or n) n
 (gdb) p var%

And the GDB session with this patch:

 (gdb) start
 ...
 (gdb) p var%                   <- Trigger TAB completion here.
 field_a      last_field   other_field
 (gdb) p var%

The implementation for this is basically copied from c-exp.y, I
tweaked the parser patterns to be appropriate for Fortran, and it
"just worked".

gdb/ChangeLog:

PR cli/26879
* f-exp.y (COMPLETE): New token.
(exp): Two new rules for tab-completion.
(saw_name_at_eof): New static global.
(last_was_structop): Likewise.
(yylex): Set new variables, and return COMPLETE token at the end
of the input stream in some cases.

gdb/testsuite/ChangeLog:

PR cli/26879
* gdb.fortran/completion.exp: New file.
* gdb.fortran/completion.f90: New file.

3 years agoUse "bool" in fetch_inferior_event
Tom Tromey [Sat, 14 Nov 2020 16:44:56 +0000 (09:44 -0700)] 
Use "bool" in fetch_inferior_event

A while back I noticed that fetch_inferior_event used "int" for
should_stop, whereas it can be bool.  The method it is assigned from:

      should_stop = thread_fsm->should_stop (thr);

... already returns bool.

Tested by rebuilding.

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

* infrun.c (fetch_inferior_event): Use "bool" for should_stop.

3 years agoAdd use of const in opencl-lang.c
Tom Tromey [Sat, 14 Nov 2020 16:22:17 +0000 (09:22 -0700)] 
Add use of const in opencl-lang.c

I found another expression-related spot that could use constification.
This patch adds it.  Tested by rebuilding.

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

* opencl-lang.c (opencl_component_ref): Make "comps" const.

3 years agogdb: fix comment in arm-tdep.c
Simon Marchi [Sat, 14 Nov 2020 16:16:41 +0000 (11:16 -0500)] 
gdb: fix comment in arm-tdep.c

gdb/ChangeLog:

* arm-tdep.c (class arm_instruction_reader) <read>: Fix comment.

Change-Id: I8f5355b314e8db643b645a6281042f514b46a908

3 years agox86: Ignore CS/DS/ES/SS segment-override prefixes in 64-bit mode
Borislav Petkov [Sat, 14 Nov 2020 14:16:26 +0000 (06:16 -0800)] 
x86: Ignore CS/DS/ES/SS segment-override prefixes in 64-bit mode

"In 64-bit mode, the CS, DS, ES, and SS segment-override prefixes have
no effect. These four prefixes are not treated as segment-override
prefixes for the purposes of multiple-prefix rules. Instead, they are
treated as null prefixes." (AMD APM v2).

However, objdump disassembles instructions containing those ignored
prefixes by still generating that segment override:

  66 66 2e 0f 1f 84 00  data16 nopw %cs:0x0(%rax,%rax,1)
  00 00 00 00

Print those segment override prefixes as excessive ones:

  66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
  00 00 00 00

which is what they actually are - they have no effect and the decoding
hardware ignores them.

gas/

2020-11-14  Borislav Petkov  <bp@suse.de>

* testsuite/gas/i386/x86-64-segovr.d: Adjust regexes.
* testsuite/gas/i386/x86-64-nops.d: Likewise.
* testsuite/gas/i386/x86-64-nops-1.d: Likewise.
* testsuite/gas/i386/x86-64-nops-1-g64.d: Likewise.
* testsuite/gas/i386/x86-64-nops-1-core2.d: Likewise.
* testsuite/gas/i386/x86-64-nops-1-k8.d: Likewise.
* testsuite/gas/i386/x86-64-nops-2.d: Likewise.
* testsuite/gas/i386/x86-64-nops-3.d: Likewise.
* testsuite/gas/i386/x86-64-nops-4.d: Likewise.
* testsuite/gas/i386/x86-64-nops-4-core2.d: Likewise.
* testsuite/gas/i386/x86-64-nops-4-k8.d: Likewise.
* testsuite/gas/i386/x86-64-nops-5.d: Likewise.
* testsuite/gas/i386/x86-64-nops-5-k8.d: Likewise.
* testsuite/gas/i386/x86-64-nops-7.d: Likewise.
* testsuite/gas/i386/x86-64-nop-1.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-1a.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-1b.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-1c.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-1d.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-1g.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-2c.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-6.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-7.d: Likewise.
* testsuite/gas/i386/x86-64-align-branch-8.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-1-core2.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-1-k8.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-1.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-2.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-3.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-4-core2.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-4-k8.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-4.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-5-k8.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops-5.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-nops.d:: Likewise.

ld/

2020-11-14  Borislav Petkov  <bp@suse.de>

* testsuite/ld-x86-64/pe-x86-64-4.od: Adjust regexes.
* testsuite/ld-x86-64/tlsld3.dd: Likewise.
* testsuite/ld-x86-64/tlsld4.dd: Likewise.

opcodes/

2020-11-14  Borislav Petkov  <bp@suse.de>

* i386-dis.c (ckprefix): Do not assign active_seg_prefix in
64-bit addressing mode.
(NOTRACK_Fixup): Test prefixes for PREFIX_DS, instead of
active_seg_prefix.

3 years agoUse const more in c-lang.c
Tom Tromey [Sat, 14 Nov 2020 02:40:29 +0000 (19:40 -0700)] 
Use const more in c-lang.c

This changes a few functions in c-lang.c to add "const" to parameters
and return types.  Tested by rebuilding.

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

* c-lang.c (convert_ucn, convert_octal, convert_hex)
(convert_escape, parse_one_string): Constify.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 14 Nov 2020 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoelf: Set rel_from_abs to 1 for __ehdr_start
H.J. Lu [Fri, 13 Nov 2020 23:44:35 +0000 (15:44 -0800)] 
elf: Set rel_from_abs to 1 for __ehdr_start

bfdlink.h has

  /* Symbol will be converted from absolute to section-relative.  Set for
     symbols defined by a script from "dot" (also SEGMENT_START or ORIGIN)
     outside of an output section statement.  */
  unsigned int rel_from_abs : 1;

linker.c has

.{* Return TRUE if the symbol described by a linker hash entry H
.   is going to be absolute.  Linker-script defined symbols can be
.   converted from absolute to section-relative ones late in the
.   link.  Use this macro to correctly determine whether the symbol
.   will actually end up absolute in output.  *}
.#define bfd_is_abs_symbol(H) \
.  (((H)->type == bfd_link_hash_defined \
.    || (H)->type == bfd_link_hash_defweak) \
.   && bfd_is_abs_section ((H)->u.def.section) \
.   && !(H)->rel_from_abs)
.

Set rel_from_abs to 1 for __ehdr_start which will be converted from
absolute to section-relative in assign_file_positions_for_load_sections.

PR ld/26869
* ldelf.c (ldelf_before_allocation): Set rel_from_abs to 1 for
__ehdr_start.
* testsuite/ld-i386/i386.exp: Run pr26869.
* testsuite/ld-i386/pr26869.d: New file.
* testsuite/ld-i386/pr26869.s: Likewise.

3 years agoExclude debuginfo files from "outside of ELF segments" warning
Keith Seitz [Fri, 13 Nov 2020 17:31:49 +0000 (09:31 -0800)] 
Exclude debuginfo files from "outside of ELF segments" warning

When GDB loads an ELF file, it will warn when a section is not located
in an ELF segment:

$ ./gdb -q -iex "set build-id-verbose 0" --ex "b systemctl_main" -ex "r" -batch --args systemctl kexec
Breakpoint 1 at 0xc24d: file ../src/systemctl/systemctl.c, line 8752.
warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libgcc_s.so.1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libcap.so.2
warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libacl.so.1
warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libcryptsetup.so.12
warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libgcrypt.so.20
warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libip4tc.so.2
[snip]
This has feature has also been reported by various users, most notably
the Fedora-EOL'd bug 1553086.

Mark Wielaard explains the issue quite nicely in

   https://sourceware.org/bugzilla/show_bug.cgi?id=24717#c2

The short of it is, the ELF program headers for debuginfo files are
not suited to this particular use case. Consequently, the warning
generated above really is useless and should be ignored.

This patch follows the same heuristic that BFD itself uses.

gdb/ChangeLog
2020-11-13  Keith Seitz  <keiths@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1553086
* elfread.c (elf_symfile_segments): Omit "Loadable section ...
outside of ELF segments" warning for debugin

3 years agoAdd file name to "Loadable section ... outside of ELF segments" warning
Keith Seitz [Fri, 13 Nov 2020 17:28:50 +0000 (09:28 -0800)] 
Add file name to "Loadable section ... outside of ELF segments" warning

As requested in gdb/23034, I would like to extend the warning message
GDB displays when it detects a loadable section that is outside any
ELF segment.

Before:

$ gdb -q --ex "b systemctl_main" -ex "r" -batch --args systemctl kexec
Breakpoint 1 at 0xc24d: file ../src/systemctl/systemctl.c, line 8752.
warning: Loadable section ".note.gnu.property" outside of ELF segments
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
warning: Loadable section ".note.gnu.property" outside of ELF segments
[snip]

Breakpoint 1, systemctl_main (argv=0x7fffffffd348, argc=2) at ../src/systemctl/systemctl.c:8752
8752                    r = systemctl_main(argc, argv);

After:

warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libcap.so.2
warning: Loadable section ".note.gnu.property" outside of ELF segments
  in .gnu_debugdata for /lib64/libacl.so.1
[snip]

I think this is eminently more useful output.

gdb/ChangeLog
2020-11-13  Keith Seitz  <keiths@redhat.com>

PR gdb/23034
* elfread.c (elf_symfile_segments): Output a BFD file name
for the "Loadable section ... outside of ELF segments" warning.

3 years agogdb/arm: avoid undefined behavior shift when decoding immediate value
Simon Marchi [Fri, 13 Nov 2020 16:58:37 +0000 (11:58 -0500)] 
gdb/arm: avoid undefined behavior shift when decoding immediate value

When loading the code file provided in PR 26828 and GDB is build with
UBSan, we get:

    Core was generated by `./Foo'.
    Program terminated with signal SIGABRT, Aborted.
    #0  0xb6c3809c in pthread_cond_wait () from /home/simark/build/binutils-gdb/gdb/repo/lib/libpthread.so.0
    [Current thread is 1 (LWP 29367)]
    (gdb) bt
    /home/simark/src/binutils-gdb/gdb/arm-tdep.c:1551:30: runtime error: shift exponent 32 is too large for 32-bit type 'unsigned int'

The sequence of instructions at pthread_cond_wait, in the
libpthread.so.0 library, contains this instruction with an immediate
constant with a "rotate amount" of 0:

    e24dd044        sub     sp, sp, #68     ; 0x44

Since arm_analyze_prologue shifts by "32 - rotate amount", it does a 32
bit shift of a 32 bit type, which is caught by UBSan.

Fix it by factoring out the decoding of immediates in a new function,
arm_expand_immediate.

I added a selftest for arm_analyze_prologue that replicates the
instruction sequence.  Without the fix, it crashes GDB if it is build
with --enable-ubsan.

I initially wanted to re-use the abstract_memory_reader class already in
arm-tdep.c, used to make arm_process_record testable.  However,
arm_process_record and arm_analyze_prologue don't use the same kind of
memory reading functions.  arm_process_record uses a function that
returns an error status on failure while arm_analyze_prologue uses one
that throws an exception.  Since i didn't want to introduce any other
behavior change, I decided to just introduce a separate interface
(arm_instruction_reader).  It is derived from
abstract_instruction_reader in aarch64-tdep.c.

gdb/ChangeLog:

PR gdb/26835
* arm-tdep.c (class arm_instruction_reader): New.
(target_arm_instruction_reader): New.
(arm_analyze_prologue): Add instruction reader parameter and use
it.  Use arm_expand_immediate.
(class target_arm_instruction_reader): Adjust.
(arm_skip_prologue): Adjust.
(arm_expand_immediate): New.
(arm_scan_prologue): Adjust.
(arm_analyze_prologue_test): New.
(class test_arm_instruction_reader): New.

Change-Id: Ieb1c1799bd66f8c7421384f44f5c2777b578ff8d

3 years agoFix Windows-target testing in gdb_file_cmd
Joseph Myers [Fri, 13 Nov 2020 16:35:02 +0000 (16:35 +0000)] 
Fix Windows-target testing in gdb_file_cmd

GCC for Windows target produces executables called foo.exe when given
"-o foo".  (More specifically, it's done that for native compilers for
a long time, and for cross compilers to Windows target since GCC
commit 5bc86b599054f494ec0a45e49b82749320eaa9c4, in GCC 8 and later.)
This causes problems for many GDB tests expecting a program to have
the exact file name passed to -o.

Fix this by checking for the case where only the .exe exists in
gdb_file_cmd and adjusting the name passed to the file command
accordingly.  There may well be other places with this issue in the
GDB testsuite, but this fix allows many tests to succeed that
previously fell over.

2020-11-12  Joseph Myers  <joseph@codesourcery.com>

* lib/gdb.exp (gdb_file_cmd): Check for case where $arg.exe exists
but $arg does not.

3 years agoFix readelf's and objdump's dislplay of DWO links when multiple links are present.
Nick Clifton [Fri, 13 Nov 2020 16:02:39 +0000 (16:02 +0000)] 
Fix readelf's and objdump's dislplay of DWO links when multiple links are present.

 PR 26829
 * dwarf.c (struct dwo_info): Add cu_offset field.
 (add_dwo_info): Add cu_offset parameter.  Record in new dwo_info
 struct.
 (add_dwo_name): Add cu_offset field.
 (add_dwo_dir): Add cu_offset field.
 (add_dwo_id): Add cu_offset field.
 (read_and_display_attr_value): Pass cu_offset to dwo recording
 functions.
 (load_separate_debug_files): Accumulate name, dir and id values
 and display once for each CU.
 * testsuite/binutils-all/dwo.sL Use a separate CU for the second
 dwo link.
 * testsuite/binutils-all/readelf.k2: Update expected output.

3 years agogdb: delete a couple of declarations from f-lang.h
Andrew Burgess [Fri, 13 Nov 2020 11:03:05 +0000 (11:03 +0000)] 
gdb: delete a couple of declarations from f-lang.h

One declaration in f-lang.h is for a function that doesn't even exist,
another is for a function that is only used within f-lang.c.

One declaration is deleted, the other function I make static in
f-lang.c.

gdb/ChangeLog:

* f-lang.c (fortran_argument_convert): Add declaration.  Add
header comment, taken from f-lang.h.  Make static.
* f-lang.h (f77_get_dynamic_array_length): Delete declaration.
(fortran_argument_convert): Delete declaration.

3 years agogas, arm: PR26858 Fix availability of single precision vmul/vmla in arm mode
Andre Vieira [Fri, 13 Nov 2020 08:59:48 +0000 (08:59 +0000)] 
gas, arm: PR26858 Fix availability of single precision vmul/vmla in arm mode

This patch fixes a mistake when enabling MVE instructions that disabled support
for single precision vmla and vmul for arm mode.

gas/ChangeLog:
2020-11-12  Andre Vieira  <andre.simoesdiasvieira@arm.com>

PR 26858
*  config/tc-arm.c (asm_opcode insns): Fix vmul and vmla's ARM_VARIANT.
* testsuite/gas/arm/pr26858.s: New test.
* testsuite/gas/arm/pr26858.d: New test.

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 13 Nov 2020 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: rewrite how per language primitive types are managed
Andrew Burgess [Fri, 30 Oct 2020 20:40:59 +0000 (20:40 +0000)] 
gdb: rewrite how per language primitive types are managed

Consider the following GDB session:

  $ gdb
  (gdb) set language c
  (gdb) ptype void
  type = void
  (gdb) set language fortran
  (gdb) ptype void
  No symbol table is loaded.  Use the "file" command.
  (gdb)

With no symbol file loaded GDB and the language set to C GDB knows
about the type void, while when the language is set to Fortran GDB
doesn't know about the void, why is that?

In f-lang.c, f_language::language_arch_info, we do have this line:

  lai->primitive_type_vector [f_primitive_type_void]
    = builtin->builtin_void;

where we add the void type to the list of primitive types that GDB
should always know about, so what's going wrong?

It turns out that the primitive types are stored in a C style array,
indexed by an enum, so Fortran uses `enum f_primitive_types'.  The
array is allocated and populated in each languages language_arch_info
member function.  The array is allocated with an extra entry at the
end which is left as a NULL value, and this indicates the end of the
array of types.

Unfortunately for Fortran, a type is not assigned for each element in
the enum.  As a result the final populated array has gaps in it, gaps
which are initialised to NULL, and so every time we iterate over the
list (for Fortran) we stop early, and never reach the void type.

This has been the case since 2007 when this functionality was added to
GDB in commit cad351d11d6c3f6487cd.

Obviously I could just fix Fortran by ensuring that either the enum is
trimmed, or we create types for the missing types.  However, I think a
better approach would be to move to C++ data structures and removed
the fixed enum indexing into the array approach.

After this commit the primitive types are pushed into a vector, and
GDB just iterates over the vector in the obvious way when it needs to
hunt for a type.  After this commit all the currently defined
primitive types can be found when the language is set to Fortran, for
example:

  $ gdb
  (gdb) set language fortran
  (gdb) ptype void
  type = void
  (gdb)

A new test checks this functionality.

I didn't see any other languages with similar issues, but I could have
missed something.

gdb/ChangeLog:

* ada-exp.y (find_primitive_type): Make parameter const.
* ada-lang.c (enum ada_primitive_types): Delete.
(ada_language::language_arch_info): Update.
* c-lang.c (enum c_primitive_types): Delete.
(c_language_arch_info): Update.
(enum cplus_primitive_types): Delete.
(cplus_language::language_arch_info): Update.
* d-lang.c (enum d_primitive_types): Delete.
(d_language::language_arch_info): Update.
* f-lang.c (enum f_primitive_types): Delete.
(f_language::language_arch_info): Update.
* go-lang.c (enum go_primitive_types): Delete.
(go_language::language_arch_info): Update.
* language.c (auto_or_unknown_language::language_arch_info):
Update.
(language_gdbarch_post_init): Use obstack_new, use array indexing.
(language_string_char_type): Add header comment, call function in
language_arch_info.
(language_bool_type): Likewise
(language_arch_info::bool_type): Define.
(language_lookup_primitive_type_1): Delete.
(language_lookup_primitive_type): Rewrite as a templated function
to call function in language_arch_info, then instantiate twice.
(language_arch_info::type_and_symbol::alloc_type_symbol): Define.
(language_arch_info::lookup_primitive_type_and_symbol): Define.
(language_arch_info::lookup_primitive_type): Define twice with
different signatures.
(language_arch_info::lookup_primitive_type_as_symbol): Define.
(language_lookup_primitive_type_as_symbol): Rewrite to call a
member function in language_arch_info.
* language.h (language_arch_info): Complete rewrite.
(language_lookup_primitive_type): Make templated.
* m2-lang.c (enum m2_primitive_types): Delete.
(m2_language::language_arch_info): Update.
* opencl-lang.c (OCL_P_TYPE): Delete.
(enum opencl_primitive_types): Delete.
(opencl_type_data): Delete.
(builtin_opencl_type): Delete.
(lookup_opencl_vector_type): Update.
(opencl_language::language_arch_info): Update, lots of content
moved from...
(build_opencl_types): ...here.  This function is now deleted.
(_initialize_opencl_language): Delete.
* p-lang.c (enum pascal_primitive_types): Delete.
(pascal_language::language_arch_info): Update.
* rust-lang.c (enum rust_primitive_types): Delete.
(rust_language::language_arch_info): Update.

gdb/testsuite/ChangeLog:

* gdb.fortran/types.exp: Add more tests.

3 years agogdb/dwarf: fix call to dwarf2_queue_guard in dw2_do_instantiate_symtab
Simon Marchi [Thu, 12 Nov 2020 22:42:55 +0000 (17:42 -0500)] 
gdb/dwarf: fix call to dwarf2_queue_guard in dw2_do_instantiate_symtab

It took me a while to understand why that would even compile: it looks
like we pass a type name as a pointer, that makes no sense.  By looking
at the DWARF, I understood that the compiler actually interprets it as a
function declaration.  So the statement was doing nothing, no
dwarf2_queue_guard was instantiated.  Fix it by passing the right
variable name.

gdb/ChangeLog:

* dwarf2/read.c (dw2_do_instantiate_symtab): Fix call to
dwarf2_queue_guard.

Change-Id: I3a7bdead9e8c39f8342a471f10181b85b8f0d801

3 years agosim: pru: Add support for LMBD instruction
Dimitar Dimitrov [Thu, 12 Nov 2020 20:23:26 +0000 (22:23 +0200)] 
sim: pru: Add support for LMBD instruction

Binutils support for LMBD instruction was merged [1]. So add it also
to simulator.

LMBD instruction does left-most-bit-detection. It returns 32 if
the given bit value is not found in the provided word value.

[1] https://sourceware.org/pipermail/binutils/2020-October/113901.html

sim/pru/ChangeLog:

* pru.h (RS1SEL): New macro.
(RS1_WIDTH): New macro.
* pru.isa: Describe the LMBD instruction.

sim/testsuite/sim/pru/ChangeLog:

* lmbd.s: New test.

3 years agogdb/dwarf: fix typo in dwarf2/read.c
Simon Marchi [Thu, 12 Nov 2020 19:59:35 +0000 (14:59 -0500)] 
gdb/dwarf: fix typo in dwarf2/read.c

gdb/ChangeLog:

* dwarf2/read.c (dw2_do_instantiate_symtab): Fix typo in
comment.

Change-Id: I6cb98768c04a537cf3d427648bddc57c631518e5

3 years agogdb: convert "set debug dwarf-read" to new style
Simon Marchi [Thu, 12 Nov 2020 19:43:58 +0000 (14:43 -0500)] 
gdb: convert "set debug dwarf-read" to new style

Add dwarf_read_debug_printf and dwarf_read_debug_printf_v macros and use
them throughout dwarf2/read.c.  The second one is used for "verbose"
prints, when the value of "set debug dwarf-read" is >= 2.

gdb/ChangeLog:

* dwarf2/read.c (dwarf_read_debug_printf,
dwarf_read_debug_printf_v): New macros, use throughout the file.

Change-Id: I694da69da2e1f2caa4c27a421a975790636411e2

3 years agoMSP430: gas: Ignore -md option required for GCC backward compatibility
Jozef Lawrynowicz [Thu, 12 Nov 2020 19:10:18 +0000 (19:10 +0000)] 
MSP430: gas: Ignore -md option required for GCC backward compatibility

The redundant -md option was removed in e4ae357fe8, but it is required
for backwards compatibility with GCC 10, which passes it to the
assembler implicitly in certain situations.

It is now silently ignored.

gas/ChangeLog:

* config/tc-msp430.c (OPTION_MOVE_DATA): Define.
(md_parse_option): Ignore OPTION_MOVE_DATA.
(md_longopts): Handle -md option.
* testsuite/gas/msp430/msp430.exp: Run new test.
* testsuite/gas/msp430/empty.s: New test.
* testsuite/gas/msp430/ignore-md.d: New test.

3 years agoarc: Write correct "eret" value during register collection
Shahab Vahedi [Thu, 12 Nov 2020 11:50:33 +0000 (12:50 +0100)] 
arc: Write correct "eret" value during register collection

In collect_register() function of arc-linux-tdep.c, the "eret"
(exception return) register value was not being reported correctly.
This patch fixes that.

Background:
When asked for the "pc" value, we have to update the "eret" register
with GDB's STOP_PC.  The "eret" instructs the kernel code where to
jump back when an instruction has stopped due to a breakpoint.  This
is how collect_register() was doing so:

--------------8<--------------
  if (regnum == gdbarch_pc_regnum (gdbarch))
    regnum = ARC_ERET_REGNUM;
  regcache->raw_collect (regnum, buf + arc_linux_core_reg_offsets[regnum]);
-------------->8--------------

Root cause:
Although this is using the correct offset (ERET register's), it is also
changing the REGNUM itself.  Therefore, raw_collect (regnum, ...) is
not reading from "pc" anymore.

v2:
- Fix a copy/paste issue as rightfully addressed by Tom [1].

[1]
https://sourceware.org/pipermail/gdb-patches/2020-November/173208.html

gdb/ChangeLog:

* arc-linux-tdep.c (collect_register): Populate "eret" by
"pc" value from the regcache when asked for "pc" value.

3 years agoFix Rust regression with -readnow
Tom Tromey [Thu, 12 Nov 2020 15:47:09 +0000 (08:47 -0700)] 
Fix Rust regression with -readnow

PR rust/26799 points out that a certain test case fails with -readnow.
This happens because, with -readnow, there are no partial symtabs; but
find_symbol_at_address requires these.

This patch fixes this problem by searching all of an objfile's
compunit symtabs if it does not have partial symbols.

Note that this test will still fail with .gdb_index.  I don't think
that is readily fixable.

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

PR rust/26799:
* symtab.c (find_symbol_at_address): Search symtabs if no psymtabs
exist.

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

PR rust/26799:
* gdb.rust/traits.exp: Remove kfails.

3 years agoFix gdb.threads/tls-so_extern.exp with Clang
Gary Benson [Thu, 12 Nov 2020 15:05:22 +0000 (15:05 +0000)] 
Fix gdb.threads/tls-so_extern.exp with Clang

Clang fails to compile gdb.threads/tls-so_extern_main.c, giving the
following error:

  /gdbtest/src/gdb/testsuite/gdb.threads/tls-so_extern_main.c:28:1:
    warning: non-void function does not return a value [-Wreturn-type]

This commit adds a return statement to the offending function.

gdb/testsuite/ChangeLog:

* gdb.threads/tls-so_extern_main.c (tls_ptr): Add missing return
statement.

3 years agoFix up changelog entry of previous delta
Nick Clifton [Thu, 12 Nov 2020 13:22:26 +0000 (13:22 +0000)] 
Fix up changelog entry of previous delta

3 years agom32r sim: Add prototypes for functions that pass/return DI values
Nick Clifton [Thu, 12 Nov 2020 12:22:18 +0000 (12:22 +0000)] 
m32r sim: Add prototypes for functions that pass/return DI values

* m32r-sim.h (m32rbf_h_accum_get_handler): Always provide a
prototype for this function.
(m32rbf_h_accum_set_handler): Likewise.
(m32r2f_h_accums_get_handler): Prototype.
(m32r2f_h_accums_set_handler): Prototype.

3 years agoStop Gas from generating line info or address ranges for sections that do not contain...
Nick Clifton [Thu, 12 Nov 2020 11:43:20 +0000 (11:43 +0000)] 
Stop Gas from generating line info or address ranges for sections that do not contain code or are not loaded.

PR 26850
* dwarf2dbg.c (dwarf2_gen_line_info_1): Do not record lines in
sections that are not executable or not loadable.
(out_debug_line): Move warning message into dwarf2_gen_line_info_1.
* testsuite/gas/elf/dwarf2-20.s: New test.
* testsuite/gas/elf/dwarf2-20.d: New test driver.
* testsuite/gas/elf/elf.exp: Run the new test.
* testsuite/gas/elf/warn-2.s: Use the .nop directive.

3 years agogdb: add an option flag to 'maint print c-tdesc'
Andrew Burgess [Sun, 11 Oct 2020 18:26:59 +0000 (19:26 +0100)] 
gdb: add an option flag to 'maint print c-tdesc'

GDB has two approaches to generating the target descriptions found in
gdb/features/, the whole description approach, where the XML file
contains a complete target description which is then used to generate
a single C file that builds that target description.  Or, the split
feature approach, where the XML files contain a single target feature,
each feature results in a single C file to create that one feature,
and then a manually written C file is used to build a complete target
description from individual features.

There's a Makefile, gdb/features/Makefile, which is responsible for
managing the regeneration of the C files from the XML files.

However, some of the logic that selects between the whole description
approach, or the split feature approach, is actually hard-coded into
GDB, inside target-descriptions.c:maint_print_c_tdesc_cmd we check the
path to the incoming XML file and use this to choose which type of C
file we should generate.

This commit removes this hard coding from GDB, and makes the Makefile
entirely responsible for choosing the approach.  This makes sense as
the Makefile already has the XML files partitioned based on which
approach they should use.

In order to allow this change the 'maint print c-tdesc' command is
given a new command option '-single-feature', which tells GDB which
type of C file should be created.  The makefile now supplies this flag
to GDB.

This did reveal a bug in features/Makefile, the rx.xml file was in the
wrong list, this didn't matter previously as the actual choice of
which approach to use was done in GDB.  Now the Makefile decides, so
placing each XML file in the correct list is critical.

Tested this by doing 'make GDB=/path/to/gdb clean-cfiles cfiles' to
regenerate all the C files from their XML source.  There are no
changes after this commit.

gdb/ChangeLog:

* features/Makefile (XMLTOC): Add rx.xml.
(FEATURE_XMLFILES): Remove rx.xml.
(FEATURE_CFILES rule): Pass '-single-feature' flag.
* features/rx.c: Regenerate.
* features/rx.xml: Wrap in `target` tags, and reindent.
* target-descriptions.c (struct maint_print_c_tdesc_options): New
structure.
(maint_print_c_tdesc_opt_def): New typedef.
(maint_print_c_tdesc_opt_defs): New static global.
(make_maint_print_c_tdesc_options_def_group): New function.
(maint_print_c_tdesc_cmd): Make use of command line flags, only
print single feature C file for target descriptions containing a
single feature.
(maint_print_c_tdesc_cmd_completer): New function.
(_initialize_target_descriptions): Update call to register command
completer, and include command line flag in help text.

gdb/doc/ChangeLog:

* gdb.texinfo (Maintenance Commands): Update description of 'maint
print c-tdesc'.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 12 Nov 2020 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb/testsuite: add "breakpoint always-inserted" axis in gdb.base/continue-after-abort...
Simon Marchi [Wed, 11 Nov 2020 16:18:10 +0000 (11:18 -0500)] 
gdb/testsuite: add "breakpoint always-inserted" axis in gdb.base/continue-after-aborted-step-over.exp

The test gdb.base/continue-after-aborted-step-over.exp fails on ROCm GDB
[1] when using the unix board (when debugging a standard x86-64/Linux
program), with:

    (gdb) b *0^M
    Breakpoint 2 at 0x0^M
    Warning:^M
    Cannot insert breakpoint 2.^M
    Cannot access memory at address 0x0^M
    ^M
    (gdb) FAIL: gdb.base/continue-after-aborted-step-over.exp: displaced-stepping=off: b *0

This happens because that build of GDB defaults to "set breakpoint
always-inserted on", for reasons that are unrelevant to explain here.
As soon as the breakpoint is created, GDB tries to insert it and
(expectedly) fails.  This causes more text to be output than what the
pattern expects.

It is actually be relevant to run the test with both "set breakpoint
always-inserted" on and off.  With it on, it mimics what happens when
running in non-stop mode, with other threads running.  This is relevant
for upstream even outside of the ROCm port, so here's a patch for it.

Add this other axis and adjust the "b *0" test to handle the extra
output when it is on.

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

gdb/testsuite/ChangeLog:

* gdb.base/continue-after-aborted-step-over.exp: Add "breakpoint
always-inserted" axis.
(do_test): Add breakpoint_always_inserted parameter.

Change-Id: I95126cae563a0b9a72f4a99627809fc34340cd5e

3 years agoaarch64: Allow LS64 feature with Armv8.6
Przemyslaw Wirkus [Wed, 11 Nov 2020 15:28:48 +0000 (15:28 +0000)] 
aarch64: Allow LS64 feature with Armv8.6

Allow users to use LS64 extension with Armv8.6 architecture.

3 years agoreadelf: Fix output of rnglists section
Bernd Edlinger [Wed, 11 Nov 2020 14:31:46 +0000 (14:31 +0000)] 
readelf: Fix output of rnglists section

* dwarf.c (display_debug_rnglists_list): Only bias the
DW_RLS_offset_pair with the base address.

3 years agoFix Windows-x-PPC build
Tom Tromey [Tue, 10 Nov 2020 16:15:31 +0000 (09:15 -0700)] 
Fix Windows-x-PPC build

A recent BFD change caused a build failure for a Windows->PPC cross:

ld.exe: ../bfd/libbfd.a(coff-rs6000.o):coff-rs6000.c:(.text+0x4571): undefined reference to `getuid'
ld.exe: ../bfd/libbfd.a(coff-rs6000.o):coff-rs6000.c:(.text+0x457e): undefined reference to `getgid'

This patch fixes the problem by moving the replacement definitions of
getuid and getgid to system.h.

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

* archive.c (getuid, getgid): Move...
* sysdep.h (getuid, getgid): ...here.

3 years agogdb/riscv: add ability to decode dwarf CSR numbers
Andrew Burgess [Wed, 11 Nov 2020 11:55:08 +0000 (11:55 +0000)] 
gdb/riscv: add ability to decode dwarf CSR numbers

Extends riscv_dwarf_reg_to_regnum to add the ability to convert the
DWARF register numbers for CSRs into GDB's internal numbers.

gdb/ChangeLog:

* riscv-tdep.c (riscv_dwarf_reg_to_regnum): Decode DWARF CSR
numbers.
* riscv-tdep.h (RISCV_DWARF_FIRST_CSR, RISCV_DWARF_LAST_CSR): New
enum values.

3 years agogdbserver: add missing --disable-packet options to help text
Andrew Burgess [Tue, 10 Nov 2020 17:54:05 +0000 (17:54 +0000)] 
gdbserver: add missing --disable-packet options to help text

The help text for the --disable-packet option was missing one of the
possible values.

As this option is for maintainers only it is explicitly not documented
in gdb/doc/gdb.texinfo, so no update is needed there.

gdbserver/ChangeLog:

* server.cc (gdbserver_usage): Add missing option to usage text.
(gdbserver_show_disableable): Likewise.

This page took 0.062735 seconds and 4 git commands to generate.