Commit Graph

106821 Commits

Author SHA1 Message Date
Mike Frysinger
54e66d16e8 sim: callback: drop unused printf helpers
These cover functions aren't used anywhere, so drop them.  There was
one caller, but it's old DOS code that most likely hasn't been tested
in years, so just delete that too.
2021-06-29 02:00:29 -04:00
Mike Frysinger
1fb164a112 sim: cgen: require long long support
We require C11 now, so we can assume & require long long exists.
Drop this old code that hasn't been used for a long long time.
2021-06-29 01:25:11 -04:00
GDB Administrator
327f11dee1 Automatic date update in version.in 2021-06-29 00:00:12 +00:00
Simon Marchi
2608aff552 gdb: use gdb_bfd_count_sections in macho_symfile_offsets
When loading a mach-o (macOS) executable and trying to set a breakpoint,
a GDB built with ASan or -D_GLIBCXX_DEBUG will crash with an
out-of-bound vector access.  This can be reproduced on Linux using the
repro files in bug 28017 [1]:

    $ ./gdb -nx --data-directory=data-directory -q repro/test -ex "b main" -batch
    /usr/include/c++/11.1.0/debug/vector:445:
    In function:
        std::__debug::vector<_Tp, _Allocator>::const_reference
        std::__debug::vector<_Tp,
        _Allocator>::operator[](std::__debug::vector<_Tp,
        _Allocator>::size_type) const [with _Tp = long unsigned int; _Allocator
        = std::allocator<long unsigned int>; std::__debug::vector<_Tp,
        _Allocator>::const_reference = const long unsigned int&;
        std::__debug::vector<_Tp, _Allocator>::size_type = long unsigned int]

    Error: attempt to subscript container with out-of-bounds index 13, but
    container only holds 13 elements.

    Objects involved in the operation:
        sequence "this" @ 0x0x61300000a590 {
          type = std::__debug::vector<unsigned long, std::allocator<unsigned long> >;
        }

The out-of-bound access happens here:

    #0  0x00007ffff6405d22 in raise () from /usr/lib/libc.so.6
    #1  0x00007ffff63ef862 in abort () from /usr/lib/libc.so.6
    #2  0x00007ffff664e21e in __gnu_debug::_Error_formatter::_M_error() const [clone .cold] from /usr/lib/libstdc++.so.6
    #3  0x000055555699e5ff in std::__debug::vector<unsigned long, std::allocator<unsigned long> >::operator[] (this=0x61300000a590, __n=13) at /usr/include/c++/11.1.0/debug/vector:445
    #4  0x0000555556a58c17 in objfile::section_offset (this=0x61300000a4c0, section=0x55555bbe4ac0 <_bfd_std_section>) at /home/simark/src/binutils-gdb/gdb/objfiles.h:644
    #5  0x0000555556a58cac in obj_section::offset (this=0x62100016d2a8) at /home/simark/src/binutils-gdb/gdb/objfiles.h:838
    #6  0x0000555556a58cfa in obj_section::addr (this=0x62100016d2a8) at /home/simark/src/binutils-gdb/gdb/objfiles.h:850
    #7  0x000055555779f5f7 in sort_cmp (sect1=0x62100016d2a8, sect2=0x62100016d170) at /home/simark/src/binutils-gdb/gdb/objfiles.c:902
    #8  0x00005555577aae35 in __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(obj_section const*, obj_section const*)>::operator()<obj_section**, obj_section**> (this=0x7fffffffa9e0, __it1=0x60c000015970, __it2=0x60c000015940) at /usr/include/c++/11.1.0/bits/predefined_ops.h:158
    #9  0x00005555577aa2b8 in std::__insertion_sort<obj_section**, __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(obj_section const*, obj_section const*)> > (__first=0x60c000015940, __last=0x60c0000159c0, __comp=...) at /usr/include/c++/11.1.0/bits/stl_algo.h:1826
    #10 0x00005555577a8e26 in std::__final_insertion_sort<obj_section**, __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(obj_section const*, obj_section const*)> > (__first=0x60c000015940, __last=0x60c0000159c0, __comp=...) at /usr/include/c++/11.1.0/bits/stl_algo.h:1871
    #11 0x00005555577a723c in std::__sort<obj_section**, __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(obj_section const*, obj_section const*)> > (__first=0x60c000015940, __last=0x60c0000159c0, __comp=...) at /usr/include/c++/11.1.0/bits/stl_algo.h:1957
    #12 0x00005555577a50f4 in std::sort<obj_section**, bool (*)(obj_section const*, obj_section const*)> (__first=0x60c000015940, __last=0x60c0000159c0, __comp=0x55555779f4e7 <sort_cmp(obj_section const*, obj_section const*)>) at /usr/include/c++/11.1.0/bits/stl_algo.h:4875
    #13 0x00005555577a147e in update_section_map (pspace=0x61200001d2c0, pmap=0x6030000d40b0, pmap_size=0x6030000d40b8) at /home/simark/src/binutils-gdb/gdb/objfiles.c:1165
    #14 0x00005555577a19a0 in find_pc_section (pc=0x100003fa0) at /home/simark/src/binutils-gdb/gdb/objfiles.c:1212
    #15 0x00005555576dd39e in lookup_minimal_symbol_by_pc_section (pc_in=0x100003fa0, section=0x0, prefer=lookup_msym_prefer::TEXT, previous=0x0) at /home/simark/src/binutils-gdb/gdb/minsyms.c:750
    #16 0x00005555576de552 in lookup_minimal_symbol_by_pc (pc=0x100003fa0) at /home/simark/src/binutils-gdb/gdb/minsyms.c:986
    #17 0x0000555557d44b54 in find_pc_sect_line (pc=0x100003fa0, section=0x62100016d170, notcurrent=0) at /home/simark/src/binutils-gdb/gdb/symtab.c:3163
    #18 0x0000555557d489fa in find_function_start_sal_1 (func_addr=0x100003fa0, section=0x62100016d170, funfirstline=true) at /home/simark/src/binutils-gdb/gdb/symtab.c:3650
    #19 0x0000555557d49015 in find_function_start_sal (sym=0x621000191670, funfirstline=true) at /home/simark/src/binutils-gdb/gdb/symtab.c:3706
    #20 0x0000555557485283 in symbol_to_sal (result=0x7fffffffbb30, funfirstline=1, sym=0x621000191670) at /home/simark/src/binutils-gdb/gdb/linespec.c:4460
    #21 0x00005555574728c2 in convert_linespec_to_sals (state=0x7fffffffc390, ls=0x7fffffffc3e0) at /home/simark/src/binutils-gdb/gdb/linespec.c:2335
    #22 0x0000555557475a8e in parse_linespec (parser=0x7fffffffc360, arg=0x60200007a550 "main", match_type=symbol_name_match_type::WILD) at /home/simark/src/binutils-gdb/gdb/linespec.c:2716
    #23 0x0000555557479027 in event_location_to_sals (parser=0x7fffffffc360, location=0x606000097be0) at /home/simark/src/binutils-gdb/gdb/linespec.c:3173
    #24 0x00005555574798f7 in decode_line_full (location=0x606000097be0, flags=1, search_pspace=0x0, default_symtab=0x0, default_line=0, canonical=0x7fffffffcca0, select_mode=0x0, filter=0x0) at /home/simark/src/binutils-gdb/gdb/linespec.c:3253
    #25 0x0000555556b4949f in parse_breakpoint_sals (location=0x606000097be0, canonical=0x7fffffffcca0) at /home/simark/src/binutils-gdb/gdb/breakpoint.c:9134
    #26 0x0000555556b6ce95 in create_sals_from_location_default (location=0x606000097be0, canonical=0x7fffffffcca0, type_wanted=bp_breakpoint) at /home/simark/src/binutils-gdb/gdb/breakpoint.c:13819
    #27 0x0000555556b645a6 in bkpt_create_sals_from_location (location=0x606000097be0, canonical=0x7fffffffcca0, type_wanted=bp_breakpoint) at /home/simark/src/binutils-gdb/gdb/breakpoint.c:12631
    #28 0x0000555556b4badf in create_breakpoint (gdbarch=0x621000152d10, location=0x606000097be0, cond_string=0x0, thread=0, extra_string=0x0, force_condition=false, parse_extra=1, tempflag=0, type_wanted=bp_breakpoint, ignore_count=0, pending_break_support=AUTO_BOOLEAN_AUTO, ops=0x55555bd728a0 <bkpt_breakpoint_ops>, from_tty=0, enabled=1, internal=0, flags=0) at /home/simark/src/binutils-gdb/gdb/breakpoint.c:9410
    #29 0x0000555556b4d3b1 in break_command_1 (arg=0x7fffffffe291 "", flag=0, from_tty=0) at /home/simark/src/binutils-gdb/gdb/breakpoint.c:9590
    #30 0x0000555556b4dc1b in break_command (arg=0x7fffffffe28d "main", from_tty=0) at /home/simark/src/binutils-gdb/gdb/breakpoint.c:9660
    #31 0x0000555556d24ca9 in do_const_cfunc (c=0x61100003a240, args=0x7fffffffe28d "main", from_tty=0) at /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:102
    #32 0x0000555556d2fcd3 in cmd_func (cmd=0x61100003a240, args=0x7fffffffe28d "main", from_tty=0) at /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:2160
    #33 0x0000555557e84e93 in execute_command (p=0x7fffffffe290 "n", from_tty=0) at /home/simark/src/binutils-gdb/gdb/top.c:674
    #34 0x00005555575a9933 in catch_command_errors (command=0x555557e84043 <execute_command(char const*, int)>, arg=0x7fffffffe28b "b main", from_tty=0, do_bp_actions=true) at /home/simark/src/binutils-gdb/gdb/main.c:523
    #35 0x00005555575a9fdb in execute_cmdargs (cmdarg_vec=0x7fffffffd910, file_type=CMDARG_FILE, cmd_type=CMDARG_COMMAND, ret=0x7fffffffd5b0) at /home/simark/src/binutils-gdb/gdb/main.c:618
    #36 0x00005555575ad48a in captured_main_1 (context=0x7fffffffdd00) at /home/simark/src/binutils-gdb/gdb/main.c:1322
    #37 0x00005555575ada9c in captured_main (data=0x7fffffffdd00) at /home/simark/src/binutils-gdb/gdb/main.c:1343
    #38 0x00005555575adb31 in gdb_main (args=0x7fffffffdd00) at /home/simark/src/binutils-gdb/gdb/main.c:1368
    #39 0x000055555681e179 in main (argc=8, argv=0x7fffffffde78) at /home/simark/src/binutils-gdb/gdb/gdb.c:32

The section being dealt with at that moment is the special *COM*
section:

    (top-gdb) p section.name
    $1 = 0x55555a1bbe60 "*COM*"
    (top-gdb) p section
    $2 = (bfd_section *) 0x55555bbe4ac0 <_bfd_std_section>

I'm not too sure what this section is for, but this is one of four
special BFD sections that GDB puts after the regular sections in the
objfile::sections and objfile::section_offsets lists.  You can check
gdb_bfd_section_index to see how they are handled.
gdb_bfd_count_sections returns "+ 4" to account for those sections.

The problem is that macho_symfile_offsets uses bfd_count_sections
instead of gdb_bfd_count_sections when allocating the
objfile::section_offsets vector.  The vector will therefore contain,
say, 13 elements instead of 17.  When trying to access the section
offset of the *COM* section, the first after the regular sections, we
access section_offsets[13], which is out of bounds.

Fix that by using gdb_bfd_count_sections instead of bfd_count_sections.
I'm fairly confident that this is correct, as this is what
default_symfile_offsets does.

With this patch, the command shown above terminates normally:

    $ ./gdb -nx --data-directory=data-directory -q repro/test -ex "b main" -batch
    Breakpoint 1 at 0x100003fad: file test.c, line 2.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=28017

gdb/ChangeLog:

	PR gdb/28017
	* machoread.c (macho_symfile_offsets): Use
	gdb_bfd_count_sections to allocate objfile::section_offsets.

Change-Id: Ic3a56f46f7232e9f24581f8255fc1ab981935450
2021-06-28 15:28:49 -04:00
Simon Marchi
0c1bcd2327 gdb: convert obj_section macros to methods
Convert these three macros to methods of obj_section.  The problem fixed
by the following patch is caused by an out of bound access of the
objfile::section_offsets vector.  Since this is deep in macros, we don't
get a clear backtrace and it's difficult to debug.  Changing that to
methods means we can step in them and break on them.

Because their implementation requires knowing about struct objfile, move
struct obj_section below struct objfile in objfiles.h.

The obj_section_offset was used in one place as an lvalue to set
offsets, in machoread.c.  Replace that with a set_offset method.

Add the objfile::section_offset and objfile::set_section_offset methods
to improve encapsulation (reduce other objects poking into struct
objfile's internals).

gdb/ChangeLog:

	* objfiles.h (struct obj_section): Move down.
	<offset, set_offset, addr, endaddr>: New.
	(obj_section_offset, obj_section_addr, obj_section_endaddr),
	replace all users to use obj_section methods.
	(struct objfile) <section_offset, set_section_offset>: New.

Change-Id: I97e8fcae93ab2353fbdadcb4a5ec10d7949a7334
2021-06-28 15:28:26 -04:00
Simon Marchi
f07fad95a9 gdb: add .flake8 file
Add a .flake8 file, which is used to set default options to the flake8
Python linter.  Use it to disable these two kinds of diagnostics, which
we don't care about since formatting is handled by black.  This reduces
the amount of noise when running flake8 on Python files.

    ./python/lib/gdb/function/caller_is.py:30:80: E501 line too long (81 > 79 characters)
    ./python/lib/gdb/command/frame_filters.py:468:17: W503 line break before binary operator

gdb/ChangeLog:

	* .flake8: New.

Change-Id: I2b41379fdd1f6e8bf2a784d55a10b406e4d1c828
2021-06-28 15:27:21 -04:00
Luis Machado
a52d0b9de1 Sanitize the address before working with allocation tags
Remove the logical tag/top byte from the address whenever we have to work with
allocation tags.

gdb/ChangeLog:

2021-06-28  Luis Machado  <luis.machado@linaro.org>

	* aarch64-linux-tdep.c (aarch64_linux_memtag_matches_p): Remove the top
	byte.
	(aarch64_linux_set_memtags): Likewise.
	(aarch64_linux_get_memtag): Likewise.
	(aarch64_linux_report_signal_info): Likewise.
2021-06-28 15:20:55 -03:00
Luis Machado
e660f4e905 Fix FFR register size for core files.
The FFR register has a size of VL bits, not 32 bits.

This causes issues when writing core files with the gcore command and when
reading them. The FFR register sometimes shows up with garbage data.

gdb/ChangeLog:

2021-06-28  Luis Machado  <luis.machado@linaro.org>

	* aarch64-linux-tdep.c
	(aarch64_linux_iterate_over_regset_sections): Fix FFR register size.
2021-06-28 15:20:18 -03:00
Luis Machado
0a3b55a669 Fix tag_ctl register size in the core file.
This register should be 64 bits in size, but the current code only saves
32 bits. This is due to an early assumption that tag_ctl would be 32 bits
in size.

gdb/ChangeLog:

2021-06-28  Luis Machado  <luis.machado@linaro.org>

	* aarch64-linux-tdep.c
	(aarch64_linux_iterate_over_regset_sections): Update tag_ctl register
	size.
	* aarch64-linux-tdep.h (AARCH64_LINUX_SIZEOF_MTE_REGSET): Set to
	8 and update comments.
2021-06-28 15:19:10 -03:00
Simon Marchi
b447dd03c1 gdb: remove gdbarch_info_init
While reviewing another patch, I realized that gdbarch_info_init could
easily be removed in favor of initializing gdbarch_info fields directly
in the struct declaration.  The only odd part is the union.  I don't
know if it's actually important for it to be zero-initialized, but I
presume it is.  I added a constructor to gdbarch_info to take care of
that.  A proper solution would be to use std::variant.  Or, these could
also be separate fields, the little extra space required wouldn't
matter.

gdb/ChangeLog:

	* gdbarch.sh (struct gdbarch_info): Initialize fields, add
	constructor.
	* gdbarch.h: Re-generate.
	* arch-utils.h (gdbarch_info_init): Remove, delete all usages.
	* arch-utils.c (gdbarch_info_init): Remove.

Change-Id: I7502e08fe0f278d84eef1667a072e8a97bda5ab5
2021-06-28 11:49:22 -04:00
Simon Marchi
c87c999c51 gdb: remove gdbarch_info::tdep_info
This field is not actually used, remove it.

gdb/ChangeLog:

	* gdbarch.sh (struct gdbarch_info) <tdep_info>: Remove.
	(gdbarch_find_by_info): Remove print.
	* gdbarch.c, gdbarch.h: Re-generate.

Change-Id: I00af4681b8e1a27727441cbadc3827f5914bd8eb
2021-06-28 11:49:22 -04:00
Andrew Burgess
4d60b89770 gdb/remote: Use true/false instead of 1/0
The remote_state::starting_up member variable is already of type bool,
but in some places we still write to it using 1 and 0.  This commit
just updates things to use true and false.

There should be no user visible change after this commit.

gdb/ChangeLog:

	* remote.c (remote_target::start_remote): Set 'starting_up' using
	boolean values instead of integers.
2021-06-28 16:31:30 +01:00
Mike Frysinger
78484bcab9 sim: bpf: enable -Werror usage
Now that all bpf warnings have been cleaned up, turn on -Werror.
2021-06-28 11:30:47 -04:00
Mike Frysinger
f2ddf6e39d sim: bpf: fix printf warnings on 32-bit systems
Use PRI macros to display 64-bit types instead of assuming long is
a 64-bit type itself.
2021-06-28 11:26:09 -04:00
Mike Frysinger
ba4990f13f sim: cgen: delete unused record_trace_results functions
Since there are no callers of this anywhere, nor is the function
implemented by anyone, drop it across the board to cleanup warnings.
2021-06-28 11:25:21 -04:00
Bhuvanendra Kumar N
05b8577206 gdb/fortran: Add type info of formal parameter for clang.
Additional compiler generated formal parameter exist with clang and type
information for the same is added accordingly. Also few kind parameter
printing are removed which is not default for clang.
Note: More details about this kind parameter omission while printing can
be found with similar patch
        commit 0a709cba00
        Author Alok Kumar Sharma (alokkumar.sharma@amd.com)

gdb/testsuite/ChangeLog:
        * gdb.fortran/ptype-on-functions.exp: Add type info of formal
        parameter for clang. Also removed the kind parameter for clang.
2021-06-28 10:56:03 +05:30
Mike Frysinger
dd5ef931df sim: frv: add missing const type 2021-06-27 23:36:56 -04:00
Mike Frysinger
520ca9a7be sim: frv: fix engine hook
This hook doesn't return a value, so don't define it to 0 to avoid
the compiler warning about it not being used.
2021-06-27 23:36:28 -04:00
Mike Frysinger
a9d200398a sim: frv: fix up various missing prototype warnings
Some of these were missing includes, some were unused funcs we can
cleanup, and some were missing prototypes for use in other files.
2021-06-27 23:35:46 -04:00
Mike Frysinger
2b83b95803 sim: frv: fix some printf type mismatch warnings
The %p usage was a real bug that would probably cause a crash.
2021-06-27 23:33:26 -04:00
Mike Frysinger
247867ebd3 sim: frv: fix uninitialized variable warning
This variable isn't set anywhere, so pass down NULL_CIA to indicate
we don't have a pc to pass.
2021-06-27 23:31:28 -04:00
Mike Frysinger
1415825a1b sim: frv: fix return type for post_wait_for funcs
These functions never return anything, so change the int return type
to void to fix a bunch of compiler warnings about missing return.
2021-06-27 23:30:01 -04:00
Mike Frysinger
ff68b4b5b1 sim: frv: fix ambiguous else compiler warnings
Add explicit braces to if bodies when the body is another if/else
to fix a bunch of compiler warnings.
2021-06-27 23:30:01 -04:00
GDB Administrator
9df51d7c47 Automatic date update in version.in 2021-06-28 00:00:11 +00:00
Mike Frysinger
e0fd25e485 sim: bpf/cris: include cgen-mem in decoders
These arches use cgen memory functions, so make sure to include the
header in the modules.
2021-06-27 10:54:06 -04:00
Mike Frysinger
76f11310df sim: bpf: include more local headers & fix broken funcs
Various files were not including the relevant headers, or some funcs
were missing prototypes entirely, leading to mismatch between the
actual definition of the functions.  Add includes to a few places and
fix the broken functions that are uncovered as a result.  Fixing some
compile warnings (e.g. missing prototypes) often find real bugs.
2021-06-27 10:53:15 -04:00
Mike Frysinger
5db3a175cc sim: cgen: suppress trace non-literal printf warning
The cgen trace macros are a bit ugly in that they specify a series of
format strings & arguments in a single call.  This means we pass a
non-literal string to printf and the compiler warns about it.  Use
the diagnostic macros to suppress that in this one place.
2021-06-27 10:49:38 -04:00
Mike Frysinger
b69bd9e723 sim: cgen: add asserts to fix unused engine warnings
If the user passed in values outside the range of [0, MAX_NR_PROCESSORS),
it would cause the code to access out-of-bind engine function pointers.
Add some asserts to catch that and to fix the related compiler warnings.
2021-06-27 10:48:07 -04:00
Mike Frysinger
a7ffa88dc6 sim: cgen: add printf attributes in a few more calls
This helps the compiler process calls to these functions and emit
warnings about mismatched format arguments.
2021-06-27 10:46:27 -04:00
Mike Frysinger
ded82565c6 sim: cgen: constify trace strings
Shouldn't be any functional changes here.
2021-06-27 10:45:51 -04:00
Mike Frysinger
2d922d86ba sim: cgen: always leverage the mem prototypes
This fixes missing prototype warnings, and guarantees the prototypes
stay in sync with the function definitions.  One of the macros had
fallen out by declaring the wrong return type.
2021-06-27 10:44:22 -04:00
Mike Frysinger
694d6fdba1 sim: cgen: always leverage the ops prototypes
This fixes missing prototype warnings, and guarantees the prototypes
stay in sync with the function definitions.
2021-06-27 10:42:51 -04:00
Mike Frysinger
5a4ce7aea0 sim: cgen: sync prototypes with implementation
These prototype blocks are not normally used, so they've fallen out
of sync with the actual function definitions.  Resync them all.
2021-06-27 10:41:02 -04:00
Mike Frysinger
44e88cd631 sim: bpf: add explicit casts when using explicit formats
Since the value variable usually has an incompatible type for the wide
variety of types it is printed as, add explicit casts to them all.
2021-06-27 10:37:37 -04:00
Mike Frysinger
cc9c19b030 sim: bpf: fix mixed decls & code warnings (and style) 2021-06-27 10:36:55 -04:00
Mike Frysinger
5d0b3088f7 sim: erc32: merge with common configure script
Move the unique library tests to the common code so we can delete
the erc32 configure logic entirely.
2021-06-27 01:21:47 -04:00
Mike Frysinger
d57b653328 sim: bfin: move pkg-config & SDL checks to common code
This reduces the unique logic in bfin/configure to make it easier to
(eventually) unify it entirely.
2021-06-27 01:18:22 -04:00
GDB Administrator
f1fa7a3d88 Automatic date update in version.in 2021-06-27 00:00:13 +00:00
Simon Marchi
6a72dbb692 gdb/guile: use return values of add_setshow functions in add_setshow_generic
Use the set_show_commands objects returned by the add_setshow functions
in add_setshow_generic.  This lets us avoid looking up the commands
after creating them, instead using the return objects directly.

Make add_setshow_generic return a set_show_commands object, which is a
bit nicer than returning both commands by parameter.

Finally, store using that object in param_smob.

Equivalent of 7bd22f56a3 ("gdb/python: use return values of
add_setshow functions in add_setshow_generic"), but for guile.

gdb/ChangeLog:

	* guile/scm-param.c (struct param_smob) <set_command,
	show_command>: Remove.
	<commands>: New.
	(pascm_is_valid): Adjust.
	(add_setshow_generic): Use return values of add_setshow
	functions, return a set_show_commands.
	(gdbscm_register_parameter_x): Adjust.

Change-Id: I18ed9e7dd5646529491c86749a5cb20763acd1f0
2021-06-25 21:39:29 -04:00
Simon Marchi
4c0ba02a74 gdb: remove context parameter from add_setshow_enum_cmd
I propose removing the context parameter from add_setshow_enum_cmd.  It
was useful before add_setshow_enum_cmd returned both created commands,
as the caller couldn't easily set the context itself.  But now, I think
it's fine to just let the caller do it.

gdb/ChangeLog:

	* command.h (add_setshow_enum_cmd): Remove context parameter.
	* cli/cli-decode.c (add_setshow_enum_cmd): Likewise, and don't
	set context.
	* cli/cli-style.c (cli_style_option::add_setshow_commands): Set
	context here.

Change-Id: I377c4e6820ec9d5069492ed28f4cba342ce1336e
2021-06-25 21:39:26 -04:00
Simon Marchi
d6ff04a343 gdb: add assert in cmd_list_element::set_context
If something tries to set a context pointer on a cmd_list_element and
m_context is not nullptr, it's likely that two parts of the code are
trying to set different contexts, and one will overwrite the other.
This is almost guaranteed to lead to bad behavior or a crash, as one of
the spots will not be using the data it expects.  This happened to me
during development, so I think having this assert would be useful to
catch this problem earlier.

gdb/ChangeLog:

	* cli/cli-decode.h (struct cmd_list_element) <set_context>: Add
	assert.

Change-Id: I1f2e9fda1bf2bec1b732c9b90e7d7910a97f2ac6
2021-06-25 21:38:51 -04:00
Simon Marchi
0f8e203412 gdb: add context getter/setter to cmd_list_element
Straightforward replacement of get_cmd_context / set_cmd_context with
cmd_list_element methods.

gdb/ChangeLog:

	* cli/cli-decode.h (struct cmd_list_element) <set_context,
	context>: New.
	<context>: Rename to...
	<m_context>: ... this.
	* cli/cli-decode.c (set_cmd_context, get_cmd_context): Remove.
	* command.h (set_cmd_context, get_cmd_context): Remove, use
	cmd_list_element::set_context and cmd_list_element::context
	everywhere instead.

Change-Id: I5016b0079014e3f17d1aa449ada7954473bf2b5d
2021-06-25 21:35:40 -04:00
GDB Administrator
ac2d77c6a1 Automatic date update in version.in 2021-06-26 00:00:10 +00:00
Andrew Burgess
bd742128ba gdb: change info sources to group results by objfile
Currently the 'info sources' command lists all of the known source
files together, regardless of their source, e.g. here is a session
debugging a test application that makes use of a shared library:

  (gdb) info sources
  Source files for which symbols have been read in:

  /tmp/info-sources/test.c, /usr/include/stdc-predef.h,
  /tmp/info-sources/header.h, /tmp/info-sources/helper.c

  Source files for which symbols will be read in on demand:

  (gdb)

In this commit I change the format of the 'info sources' results so
that the results are grouped by the object file that uses that source
file.  Here's the same session with the new output format:

  (gdb) info sources
  /tmp/info-sources/test.x:

  /tmp/info-sources/test.c, /usr/include/stdc-predef.h,
  /tmp/info-sources/header.h

  /lib64/ld-linux-x86-64.so.2:
  (Objfile has no debug information.)

  system-supplied DSO at 0x7ffff7fcf000:
  (Objfile has no debug information.)

  /tmp/info-sources/libhelper.so:

  /tmp/info-sources/helper.c, /usr/include/stdc-predef.h,
  /tmp/info-sources/header.h

  /lib64/libc.so.6:
  (Objfile has no debug information.)

  (gdb)

Notice that in the new output some source files are repeated,
e.g. /tmp/info-sources/header.h, as multiple objfiles use this source
file.

Further, some object files are tagged with the message '(Objfile has
no debug information.)', it is also possible to see the message '(Full
debug information has not yet been read for this file.)', which is
printed when some symtabs within an objfile have not yet been
expanded.

All of the existing regular expression based filtering still works.

An original version of this patch added the new format as an option to
'info sources', however, it was felt that the new layout was so much
better than the old style that GDB should just switch to the new
result format completely.

gdb/ChangeLog:

	* NEWS: Mention changes to 'info sources'.
	* symtab.c (info_sources_filter::print): Delete.
	(struct output_source_filename_data) <print_header>: Delete
	declaration.  <printed_filename_p>: New member function.
	(output_source_filename_data::print_header): Delete.
	(info_sources_worker): Update group-by-objfile style output to
	make it CLI suitable, simplify non-group-by-objfile now this is
	only used from the MI.
	(info_sources_command): Make group-by-objfile be the default for
	CLI info sources command.
	* symtab.h (struct info_sources_filter) <print>: Delete.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Document new output format for 'info
	sources'.

gdb/testsuite/ChangeLog:

	* gdb.base/info_sources_2-header.h: New file.
	* gdb.base/info_sources_2-lib.c: New file.
	* gdb.base/info_sources_2-test.c: New file.
	* gdb.base/info_sources_2.exp: New file.
2021-06-25 20:54:29 +01:00
Andrew Burgess
1fb1ce02fc gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files
This commit adds a new option '--group-by-objfile' to the MI command
-file-list-exec-source-files.  With this option the output format is
changed; instead of a single list of source files the results are now
a list of objfiles.  For each objfile all of the source files
associated with that objfile are listed.

Here is an example of the new output format taken from the
documentation (the newlines are added just for readability):

  -file-list-exec-source-files --group-by-objfile
  ^done,files=[{filename="/tmp/info-sources/test.x",
                debug-info="fully-read",
                sources=[{file="test.c",
                          fullname="/tmp/info-sources/test.c",
                          debug-fully-read="true"},
                         {file="/usr/include/stdc-predef.h",
                          fullname="/usr/include/stdc-predef.h",
                          debug-fully-read="true"},
                         {file="header.h",
                          fullname="/tmp/info-sources/header.h",
                          debug-fully-read="true"}]},
               {filename="/lib64/ld-linux-x86-64.so.2",
                debug-info="none",
                sources=[]},
               {filename="system-supplied DSO at 0x7ffff7fcf000",
                debug-info="none",
                sources=[]},
               {filename="/tmp/info-sources/libhelper.so",
                debug-info="fully-read",
                sources=[{file="helper.c",
                          fullname="/tmp/info-sources/helper.c",
                          debug-fully-read="true"},
                         {file="/usr/include/stdc-predef.h",
                          fullname="/usr/include/stdc-predef.h",
                          debug-fully-read="true"},
                         {file="header.h",
                          fullname="/tmp/info-sources/header.h",
                          debug-fully-read="true"}]},
               {filename="/lib64/libc.so.6",
                debug-info="none",
                sources=[]}]

In the above output the 'debug-info' field associated with each
objfile will have one of the values 'none', 'partially-read', or
'fully-read'.  For example, /lib64/libc.so.6 has the value 'none',
this indicates that this object file has no debug information
associated with it, unsurprisingly then, the sources list of this
object file is empty.

An object file that was compiled with debug, for example
/tmp/info-sources/libhelper.so, has the value 'fully-read' above
indicating that this object file does have debug information, and the
information is fully read into GDB.  At different times this field
might have the value 'partially-read' indicating that that the object
file has debug information, but it has not been fully read into GDB
yet.

Source files can appear at most once for any single objfile, but can
appear multiple times in total, if the same source file is part of
multiple objfiles, for example /tmp/info-sources/header.h in the above
output.

The new output format is hidden behind a command option to ensure that
the default output is unchanged, this ensures backward compatibility.

The behaviour of the CLI "info sources" command is unchanged after
this commit.

gdb/ChangeLog:

	* NEWS: Mention additions to -file-list-exec-source-files.
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Add
	--group-by-objfile option.
	* symtab.c (isrc_flag_option_def): Rename to...
	(isrc_match_flag_option_def): ...this.
	(info_sources_option_defs): Rename to...
	(info_sources_match_option_defs): ...this, and update to rename of
	isrc_flag_option_def.
	(struct filename_grouping_opts): New struct.
	(isrc_grouping_flag_option_def): New type.
	(info_sources_grouping_option_defs): New static global.
	(make_info_sources_options_def_group): Update to return two option
	groups.
	(info_sources_command_completer): Update for changes to
	make_info_sources_options_def_group.
	(info_sources_worker): Add extra parameter, use this to display
	alternative output format.
	(info_sources_command): Pass extra parameter to
	info_sources_worker.
	(_initialize_symtab): Update for changes to
	make_info_sources_options_def_group.
	* symtab.h (info_sources_worker): Add extra parameter.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI File Commands): Document --group-by-objfile
	extension for -file-list-exec-source-files.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-info-sources.exp: Add additional tests.
2021-06-25 20:54:29 +01:00
Andrew Burgess
0e350a054b gdb/mi: add regexp filtering to -file-list-exec-source-files
This commit extends the existing MI command
-file-list-exec-source-files to provide the same regular expression
based filtering that the equivalent CLI command "info sources"
provides.

The new command syntax is:

  -file-list-exec-source-files [--basename | --dirname] [--] [REGEXP]

All options are optional, which ensures the command is backward
compatible.

As part of this work I have unified the CLI and MI code.

As a result of the unified code I now provide additional information
in the MI command output, there is now a new field 'debug-fully-read'
included with each source file.  This field which has the values
'true' or 'false', indicates if the source file is from a compilation
unit that has had its debug information fully read.  However, as this
is additional information, a well written front-end should just ignore
this field if it doesn't understand it, so things should still be
backward compatible.

gdb/ChangeLog:

	* NEWS: Mention additions to -file-list-exec-source-files.
	* mi/mi-cmd-file.c (print_partial_file_name): Delete.
	(mi_cmd_file_list_exec_source_files): Rewrite to handle command
	options, and make use of info_sources_worker.
	* symtab.c (struct info_sources_filter): Moved to symtab.h.
	(info_sources_filter::print): Take uiout argument, produce output
	through uiout.
	(struct output_source_filename_data)
	<output_source_filename_data>: Take uiout argument, store into
	m_uiout.  <output>: Rewrite comment, add additional arguments to
	declaration.  <operator()>: Send more arguments to
	output. <m_uiout>: New member variable.
	(output_source_filename_data::output): Take extra arguments,
	produce output through m_uiout, and structure for MI.
	(output_source_filename_data::print_header): Produce output
	through m_uiout.
	(info_sources_worker): New function, the implementation is taken
	from info_sources_command, but modified so produce output through
	a ui_out.
	(info_sources_command): The second half of this function has gone
	to become info_sources_worker.
	* symtab.h (struct info_sources_filter): Moved from symtab.c, add
	extra parameter to print member function.
	(info_sources_worker): Declare.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI File Commands): Document extensions to
	-file-list-exec-source-files.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-filename.exp: Update expected results.
	* gdb.mi/mi-file.exp: Likewise.
	* gdb.mi/mi-info-sources-base.c: New file.
	* gdb.mi/mi-info-sources.c: New file.
	* gdb.mi/mi-info-sources.exp: New file.
2021-06-25 20:54:29 +01:00
Andrew Burgess
4a0788e08c gdb: make struct output_source_filename_data more C++ like
In a future commit I'm going to be making some changes to the 'info
sources' command.  While looking at the code I noticed that things
could be improved by making struct output_source_filename_data more
C++ like (private member variables, and more member functions).
That's what this commit does.

The 'info sources' filename filtering is split out into a separate
class in this commit.  In a future commit this new filter
class (info_sources_filter) will move into the header file and be used
from the MI code.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* symtab.c (struct info_sources_filter): New.
	(info_sources_filter::info_sources_filter): New function.
	(info_sources_filter::matches): New function.
	(info_sources_filter::print): New function.
	(struct filename_partial_match_opts): Moved to later in the file
	and update the comment.
	(struct output_source_filename_data)
	<output_source_filename_data>: New constructor.  <regexp>: Delete,
	this is now in info_sources_filter.  <c_regexp>: Delete, this is
	now in info_sources_filter.  <reset_output>: New member function.
	<filename_seen_cache>: Rename to m_filename_seen_cache, change
	from being a pointer, to being an actual object.  <first>: Rename
	to m_first.  <print_header>: New member function. <partial_match>:
	Delete.
	(output_source_filename_data::output): Update now
	m_filename_seen_cache is no longer a pointer, and for other member
	variable name changes. Add a header comment.
	(print_info_sources_header): Renamed to...
	(output_source_filename_data::print_header): ...this.  Update now
	it's a member function and to take account of member variable
	renaming.
	(info_sources_command): Add a header comment, delete stack local
	filename_seen_cache, initialization of output_source_filename_data
	is now done by the constructor.  Call print_header member function
	instead of print_info_sources_header, call reset_output member
	function instead of manually performing the reset.
2021-06-25 20:54:28 +01:00
Andrew Burgess
fc4d5ebf8f gdb: add new function quick_symbol_functions::has_unexpanded_symbols
Adds a new function to the quick_symbol_functions API to let us know
if there are any unexpanded symbols.  This functionality is required
by a later commit.  After this commit the functionality is unused, and
untested.

The new function objfile::has_unexpanded_symtabs is added to the
symfile-debug.c file which is a little strange, but this
is (currently) where many of the other objfile::* functions (that call
onto the quick_symbol_functions) are defined, so I'm reluctant to
break this pattern.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* dwarf2/read.c (struct dwarf2_base_index_functions)
	<has_unexpanded_symtabs>: Declare.
	(dwarf2_base_index_functions::has_unexpanded_symtabs): Define new
	function.
	* objfiles.h (struct objfile) <has_unexpanded_symtabs>: Declare.
	* psympriv.h (struct psymbol_functions) <has_unexpanded_symtabs>:
	Declare.
	* psymtab.c (psymbol_functions::has_unexpanded_symtabs): Define
	new function.
	* quick-symbol.h (struct quick_symbol_functions)
	<has_unexpanded_symtabs>: Declare.
	* symfile-debug.c (objfile::has_unexpanded_symtabs): Define new
	function.
2021-06-25 20:54:28 +01:00
Andrew Burgess
d038ce48f1 gdb: fix invalid arg coercion when calling static member functions
In this commit:

  commit 7022349d5c
  Date:   Mon Sep 4 20:21:13 2017 +0100

      Stop assuming no-debug-info functions return int

A new if case was added to call_function_by_hand_dummy to decide if a
function should be considered prototyped or not.  Previously the code
was structured like this:

  if (COND_1)
    ACTION_1
  else if (COND_2)
    ACTION_2
  else
    ACTION_3

With the new block the code now looks like this:

  if (COND_1)
    ACTION_1
  if (NEW_COND)
    NEW_ACTION
  else if (COND_2)
    ACTION_2
  else
    ACTION_3

Notice the new block was added as and 'if' not 'else if'.  I'm running
into a case where GDB executes ACTION_1 and then ACTION_2.  Prior to
the above commit GDB would only have executed ACTION_1.

The actions in the code in question are trying to figure out if a
function should be considered prototyped or not.  When a function is
not prototyped some arguments will be coerced, e.g. floats to doubles.

The COND_1 / ACTION_1 are a very broad, any member function should be
considered prototyped, however, after the above patch GDB is now
executing the later ACTION_2 which checks to see if the function's
type has the 'prototyped' flag set - this is not the case for the
member functions I'm testing, and so GDB treats the function as
unprototyped and casts the float argument to a double.

I believe that adding the new check as 'if' rather than 'else if' was
a mistake, and so in this commit I add in the missing 'else'.

gdb/ChangeLog:

	* infcall.c (call_function_by_hand_dummy): Add missing 'else' when
	setting prototyped flag.

gdb/testsuite/ChangeLog:

	* gdb.cp/method-call-in-c.cc (struct foo_type): Add static member
	function static_method.
	(global_var): New global.
	(main): Use new static_method to ensure it is compiled in.
	* gdb.cp/method-call-in-c.exp: Test calls to static member
	function.
2021-06-25 20:43:07 +01:00
Andrew Burgess
158cc4feb7 gdb: use gdb::optional instead of passing a pointer to gdb::array_view
Following on from the previous commit, this commit changes the API of
value_struct_elt to take gdb::optional<gdb::array_view<value *>>
instead of a pointer to the gdb::array_view.

This makes the optional nature of the array_view parameter explicit.

This commit is purely a refactoring commit, there should be no user
visible change after this commit.

I have deliberately kept this refactor separate from the previous two
commits as this is a more extensive change, and I'm not 100% sure that
using gdb::optional for the parameter type, instead of a pointer, is
going to be to everyone's taste.  If there's push back on this patch
then this one can be dropped from the series.

gdb/ChangeLog:

	* ada-lang.c (desc_bounds): Use '{}' instead of NULL to indicate
	an empty gdb::optional when calling value_struct_elt.
	(desc_data): Likewise.
	(desc_one_bound): Likewise.
	* eval.c (structop_base_operation::evaluate_funcall): Pass
	gdb::array_view, not a gdb::array_view* to value_struct_elt.
	(eval_op_structop_struct): Use '{}' instead of NULL to indicate
	an empty gdb::optional when calling value_struct_elt.
	(eval_op_structop_ptr): Likewise.
	* f-lang.c (fortran_structop_operation::evaluate): Likewise.
	* guile/scm-value.c (gdbscm_value_field): Likewise.
	* m2-lang.c (eval_op_m2_high): Likewise.
	(eval_op_m2_subscript): Likewise.
	* opencl-lang.c (opencl_structop_operation::evaluate): Likewise.
	* python/py-value.c (valpy_getitem): Likewise.
	* rust-lang.c (rust_val_print_str): Likewise.
	(rust_range): Likewise.
	(rust_subscript): Likewise.
	(eval_op_rust_structop): Likewise.
	(rust_aggregate_operation::evaluate): Likewise.
	* valarith.c (value_user_defined_op): Likewise.
	* valops.c (search_struct_method): Change parameter type, update
	function body accordingly, and update header comment.
	(value_struct_elt): Change parameter type, update function body
	accordingly.
	* value.h (value_struct_elt): Update declaration.
2021-06-25 20:43:06 +01:00