Commit Graph

108373 Commits

Author SHA1 Message Date
Tom Tromey
c0390cb8c1 Remove an xfree from add_path
This removes a temporary \0 assignment and an xfree from add_path,
replacing it with a simpler use of std::string.
2021-12-07 14:20:11 -07:00
Simon Marchi
9931e521bf gdb/linespec.c: simplify condition
We can remove the empty check: if the vector has size 1, it is obviously
not empty.  This code ended up like this because the empty check used to
be a NULL check.

Change-Id: I1571bd0228818ca93f6a6b444e9b010dc2da4c08
2021-12-07 15:58:54 -05:00
Simon Marchi
c32ce0dc6c gdb: rename "maint agent" functions
Functions agent_eval_command and agent_command are used to implement
maintenance commands, rename them accordingly (with the maint_ prefix),
as well as the agent_command_1 helper function.

Change-Id: Iacf96d4a0a26298e8dd4648a0f38da649ea5ef61
2021-12-07 15:56:25 -05:00
Simon Marchi
cd0f67f363 gdb: make set_raw_breakpoint static
set_raw_breakpoint is only used in breakpoint.c, make it static.

Change-Id: I7fbeda067685309a30b88aceaf957eff7a28e310
2021-12-07 15:51:10 -05:00
John Baldwin
b4992e9990 Support AT_FXRNG and AT_KPRELOAD on FreeBSD.
FreeBSD's kernel has recently added two new ELF auxiliary vector
entries.  AT_FXRNG points to a root seed version for the kernel's
PRNG.  Userland can use this to reseed a userland PRNG after the
kernel's PRNG has reseeded.  AT_KPRELOAD is the base address of a
kernel-provided vDSO.

This change displays the proper name and description of these entries
in 'info auxv'.

include/ChangeLog:

	* elf/common.h (AT_FREEBSD_FXRNG, AT_FREEBSD_KPRELOAD): Define.
2021-12-07 10:29:01 -08:00
Tom Tromey
c5a9fcdfee Avoid extra work in global_symbol_searcher::expand_symtabs
I noticed that global_symbol_searcher::expand_symtabs always passes a
file matcher to expand_symtabs_matching.  However, if 'filenames' is
empty, then this always returns true.  It's slightly more efficient to
pass a null file matcher in this case, because that lets the "quick"
symbol implementations skip any filename checks.

Regression tested on x86-64 Fedora 34.
2021-12-07 11:12:12 -07:00
Tom de Vries
4281b0c8fc [gdb/testsuite] Fix options arg handling in compile_jit_elf_main_as_so
In commit 80ad340c90 ("[gdb/testsuite] use -Ttext-segment for jit-elf tests")
the following change was made:
...
 proc compile_jit_elf_main_as_so {main_solib_srcfile main_solib_binfile options} {
-    set options [concat $options debug]
+    global jit_load_address jit_load_increment
+
+    set options [list \
+       additional_flags="-DMAIN=jit_dl_main" \
+       additional_flags=-DLOAD_ADDRESS=$jit_load_address \
+       additional_flags=-DLOAD_INCREMENT=$jit_load_increment \
+       debug]
...

Before the change, the options argument was used, but after the change not
anymore.

Fix this by reverting back to using "set options [concat $options ...]".

Fixing this gets us twice the -DMAIN=jit_dl_main bit, once from a caller, and
once from compile_jit_elf_main_as_so.  Fix this by removing the bit from
compile_jit_elf_main_as_so, which makes the code similar to compile_jit_main.

Tested on x86_64-linux.
2021-12-07 09:44:36 +01:00
Tom de Vries
c178f2a133 [gdb/testsuite] Fix FAIL in gdb.tui/basic.exp
On openSUSE Leap 15.2 aarch64 I ran into:
...
FAIL: gdb.tui/basic.exp: check main is where we expect on the screen
...
while this is passing on x86_64.

On x86_64-linux we have at the initial screen dump for "list -q main":
...
 0 +-/home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.tui/tui-layout.c--+
 1 |       15     You should have received a copy of the GNU General Public |
 2 |       16     along with this program.  If not, see <http://www.gnu.org/|
 3 |       17                                                               |
 4 |       18  int                                                          |
 5 |       19  main ()                                                      |
 6 |       20  {                                                            |
 7 |       21    return 0;                                                  |
 8 |       22  }                                                            |
 9 |       23                                                               |
...
but on aarch64:
...
 0 +-/home/tdevries/gdb/src/gdb/testsuite/gdb.tui/tui-layout.c--------------+
 1 |       16     along with this program.  If not, see <http://www.gnu.org/|
 2 |       17                                                               |
 3 |       18  int                                                          |
 4 |       19  main ()                                                      |
 5 |       20  {                                                            |
 6 |       21    return 0;                                                  |
 7 |       22  }                                                            |
 8 |       23                                                               |
 9 |       24                                                               |
...

The cause of the diffferent placement is that we have as line number for main
on x86_64:
...
$ gdb -q -batch outputs/gdb.tui/basic/basic -ex "info line main"
Line 20 of "tui-layout.c" starts at address 0x4004a7 <main> \
  and ends at 0x4004ab <main+4>.
...
and on aarch64 instead:
...
$ gdb -q -batch outputs/gdb.tui/basic/basic -ex "info line main"
Line 21 of "tui-layout.c" starts at address 0x4005f4 <main> \
  and ends at 0x4005f8 <main+4>.
...

Fix this by using a new source file main-one-line.c, that implements the
entire main function on a single line, in order to force the compiler to use
that line number.

Also try to do less hard-coding in the test-case.

Tested on x86_64-linux and aarch64-linux.
2021-12-07 08:16:42 +01:00
Tom de Vries
545e49f5ee [gdb/tdep] Fix inferior plt calls in PIE for i386
Consider test-case test.c:
...
int main (void) {
  void *p = malloc (10);
  return 0;
}
...

When compiled to a non-PIE exec:
...
$ gcc -m32 test.c
...
the call sequence looks like:
...
 8048447:       83 ec 0c                sub    $0xc,%esp
 804844a:       6a 0a                   push   $0xa
 804844c:       e8 bf fe ff ff          call   8048310 <malloc@plt>
...
which calls to:
...
08048310 <malloc@plt>:
 8048310:       ff 25 0c a0 04 08       jmp    *0x804a00c
 8048316:       68 00 00 00 00          push   $0x0
 804831b:       e9 e0 ff ff ff          jmp    8048300 <.plt>
...
where the first insn at 0x8048310 initially jumps to the following address
0x8048316, read from the .got.plt @ 0x804a00c:
...
 804a000 0c9f0408 00000000 00000000 16830408  ................
 804a010 26830408                             &...
...

Likewise, when compiled as a PIE:
...
$ gcc -m32 -fPIE -pie test.c
...
we have this call sequence (with %ebx setup to point to the .got.plt):
...
0000055d <main>:
 579:   83 ec 0c                sub    $0xc,%esp
 57c:   6a 0a                   push   $0xa
 57e:   89 c3                   mov    %eax,%ebx
 580:   e8 6b fe ff ff          call   3f0 <malloc@plt>
...
which calls to:
...
000003f0 <malloc@plt>:
 3f0:   ff a3 0c 00 00 00       jmp    *0xc(%ebx)
 3f6:   68 00 00 00 00          push   $0x0
 3fb:   e9 e0 ff ff ff          jmp    3e0 <.plt>
...
where the insn at 0x3f0 initially jumps to following address 0x3f6, read from
the .got.plt at offset 0xc:
...
 2000 f41e0000 00000000 00000000 f6030000  ................
 2010 06040000                             ....
...

When instead doing an inferior call to malloc (with nosharedlib to force
malloc to resolve to malloc@plt rather than the functions in ld.so or libc.so)
with the non-PIE exec, we have the expected:
...
$ gdb -q -batch a.out -ex start -ex nosharedlib -ex "p /x (void *)malloc (10)"
Temporary breakpoint 1 at 0x8048444

Temporary breakpoint 1, 0x08048444 in main ()
$1 = 0x804b160
...

But with the PIE exec, we run into:
...
$ gdb -q -batch a.out -ex start -ex nosharedlib -ex "p /x (void *)malloc (10)"
Temporary breakpoint 1 at 0x56c

Temporary breakpoint 1, 0x5655556c in main ()

Program received signal SIGSEGV, Segmentation fault.
0x565553f0 in malloc@plt ()
...

The segfault happens because:
- the inferior call mechanism doesn't setup %ebx
- %ebx instead is 0
- the jump to "*0xc(%ebx)" reads from memory at 0xc

Fix this by setting up %ebx properly in i386_thiscall_push_dummy_call.

Fixes this failure with target board unix/-m32/-pie/-fPIE reported in
PR28467:
...
FAIL: gdb.base/nodebug.exp: p/c (int) array_index("abcdef",2)
...

Tested on x86_64-linux, with target board unix/-m32 and unix/-m32/-fPIE/-pie.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28467
2021-12-07 08:07:18 +01:00
Tom de Vries
9dec38d3b1 [gdb/symtab] Support -readnow during reread
When running test-case gdb.base/cached-source-file.exp with target board
readnow, we run into:
...
FAIL: gdb.base/cached-source-file.exp: rerun program (the program exited)
...

The problem is that when rereading, the readnow is ignored.

Fix this by copying the readnow handling code from symbol_file_add_with_addrs
to reread_symbols.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26800
2021-12-07 07:51:25 +01:00
Tom de Vries
af5300fe24 [gdb/ada] Fix assert in ada_is_unconstrained_packed_array_type
On openSUSE Leap 42.3, with system compiler gcc 4.8.5 I run into:
...
(gdb) print u_one_two_three^M
src/gdb/gdbtypes.h:1050: internal-error: field: \
 Assertion `idx >= 0 && idx < num_fields ()' failed.^M
...

We run into trouble while doing this in
ada_is_unconstrained_packed_array_type:
...
1953          return TYPE_FIELD_BITSIZE (type, 0) > 0;
...
which tries to get field 0 from a type without fields:
...
(gdb) p type->num_fields ()
$6 = 0
...
which is the case because the type is a typedef:
...
(gdb) p type->code ()
$7 = TYPE_CODE_TYPEDEF
...

Fix this by using the type referenced by the typedef instead.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28323
2021-12-07 07:35:10 +01:00
Alan Modra
d91c67e873 Re: Add support for AArch64 EFI (efi-*-aarch64)
Commit b69c9d41e8 was broken in multiple ways regarding the realloc
of the target string, most notably in that "-little" wasn't actually
appended to the input_target or output_target.  This caused asan
errors and "FAIL: Check if efi app format is recognized".  I also
noticed that the input_target string wasn't being copied but rather
the output_target when dealing with the input target.  Fix that too.

	PR 26206
	* objcopy.c (convert_efi_target): Rewrite.  Allocate modified
	target strings here..
	(copy_main): ..rather than here.  Do handle input_target,
	not output_target for input.
2021-12-07 16:10:27 +10:30
Alan Modra
43908c1653 Error on ld output file name matching input file name
It's not foolproof, for example we don't catch output to a linker
script, to a library specified with -l, or to an element of a thin
archive.

	* ldlang.c (open_output): Exit with error on output file matching
	an input file.
	* testsuite/ld-misc/just-symbols.exp: Adjust ld -r test to suit.
2021-12-07 16:10:22 +10:30
GDB Administrator
21ce5fa063 Automatic date update in version.in 2021-12-07 00:00:10 +00:00
Carl Love
a85885ff7e gdb: Add PowerPC support to gdb.dwarf2/frame-inlined-in-outer-frame
This patch adds an #elif defined for PowerPC to setup the exit_0 macro.
This patch addes the needed macro definitionald logic to handle both elfV1
and elfV2.

The patch has been successfully tested on both PowerPC BE, Powerpc LE and
X86_64 with no regressions.
2021-12-06 13:49:20 -06:00
Tom de Vries
b082698c5c [gdb/testsuite] Use precise align in gdb.arch/i386-{avx,sse}.exp
Test-cases gdb.arch/i386-{avx,sse}.exp use assembly instructions that require
the memory operands to be aligned to a certain boundary, and the test-cases
use C11's _Alignas to make that happen.

The draw-back of using _Alignas is that while it does enforce a minimum
alignment, the actual alignment may be bigger, which makes the following
scenario possible:
- copy say, gdb.arch/i386-avx.c as basis for a new test-case
- run the test-case and observe a PASS
- commit the new test-case in the supposition that the test-case is correct
  and well-tested
- run later into a failure on a different test setup (which may be a setup
  where reproduction and investigation is more difficult and time-consuming),
  and find out that the specified alignment was incorrect and should have been
  updated to say, 64 bytes.  The initial PASS occurred only because the actual
  alignment happened to be greater than required.

The idea of having precise alignment as a means of having more predictable
execution which allows flushing out bugs earlier, has been filed as PR
gcc/103095.

Add a new file lib/precise-aligned-alloc.c with functions
precise_aligned_alloc and precise_aligned_dup, to support precise alignment.

Use precise_aligned_dup in aforementioned test-cases to:
- verify that the specified alignment is indeed sufficient, rather
  than too little but accidentally over-aligned.
- prevent the same type of problems in any new test-cases based on these

Tested on x86_64-linux, with both gcc and clang.
2021-12-06 16:01:47 +01:00
Tom de Vries
197a63068b [gdb/testsuite] Fix data alignment in gdb.arch/i386-{avx,sse}.exp
When running test-case gdb.arch/i386-avx.exp with clang I ran into:
...
(gdb) PASS: gdb.arch/i386-avx.exp: set first breakpoint in main
continue^M
Continuing.^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
0x000000000040052b in main (argc=1, argv=0x7fffffffd3c8) at i386-avx.c:54^M
54        asm ("vmovaps 0(%0), %%ymm0\n\t"^M
(gdb) FAIL: gdb.arch/i386-avx.exp: continue to breakpoint: \
  continue to first breakpoint in main
...

The problem is that the vmovaps insn requires an 256-bit (or 32-byte) aligned
address, and it's only 16-byte aligned:
...
(gdb) p /x $rax
$1 = 0x601030
...

Fix this by using a sufficiently aligned address, using _Alignas.

Compile using -std=gnu11 to support _Alignas.

Likewise in gdb.arch/i386-sse.exp.

Tested on x86_64-linux, with both gcc and clang.
2021-12-06 16:01:47 +01:00
Alan Modra
f21dbd7c80 [GOLD] PowerPC64 inline plt sequences
The fixes gold failures to handle inline PLT sequences properly.
PowerPC gold was always turning these back into direct calls due to
gsym->use_plt_offset() returning false.  This is fixed for dynamic
linking by correcting get_reference_flags, and for static linking by
overriding use_plt_offset() in relocate().  The rest of the patch
revolves around needing to create PLT entries for inline PLT calls
when statically linking (for gcc -mlongcall).  The lplt section
handled that for local symbols, now it does globals too.

	* powerpc.cc (Target_powerpc::plt_off): Return proper section
	for static link.
	(Target_powerpc::symval_for_branch): Make public.
	(Target_powerpc::make_lplt_section): Add Symbol_table* param.
	Adjust all calls.
	(Target_powerpc::make_local_plt_entry): Likewise.
	(Target_powerpc::make_local_plt_entry): New variant for global syms.
	(Powerpc_relobj::do_relocate_sections): Don't write lplt contents.
	(Output_data_plt_powerpc::do_write): Write lplt contents here.
	(Output_data_plt_powerpc::Output_data_plt_powerpc): Save
	symbol table pointer.  Adjust all uses.
	(Output_data_plt_powerpc::add_entry): Add stash parameter.  Don't
	do dynamic reloc handling when no reloc section.  Save symbol
	for local plt entries.
	(Output_data_plt_powerpc::add_local_entry): Save symbol.
	(Output_data_plt_powerpc::Local_plt_ent): New class.
	(Output_data_plt_powerpc::sym_ents_): New vector.
	(Target_powerpc::Scan::get_reference_flags): Return
	FUNCTION_CALL|RELATIVE_REF for inline plt relocs.
	(Target_powerpc::Scan::global): Make entries in lplt for inline
	plt call relocation symbols.
	(Target_powerpc::Relocate::relocate): Rename has_plt_offset to
	use_plt_offset.  Set use_plt_offset for inline plt relocs.
2021-12-06 22:16:46 +10:30
Clément Chigot
74044dc840 ld: improve shared tests for AIX
It's now possible to refer symbols in the main program from the
shared library. However, it still impossible to have the same
overriden features between shared objects and mains than ELF,
without using the runtime linking feature which isn't yet fully
available.

ld/ChangeLog:

	* testsuite/ld-shared/shared.exp: Improve XCOFF support
	* testsuite/ld-shared/main.c: Likewise.
	* testsuite/ld-shared/sh1.c: Likewise.
	* testsuite/ld-shared/xcoff.dat: Likewise.
2021-12-06 12:45:12 +01:00
GDB Administrator
2427f3b09e Automatic date update in version.in 2021-12-06 00:00:13 +00:00
Tom Tromey
33af066d07 Preserve artificial CU name in process_psymtab_comp_unit_reader
This fixes a use-after-free that Simon pointed out.
process_psymtab_comp_unit_reader was allocating an artificial name for
a CU, and then discarding it.  However, this name was preserved in the
cached file_and_directory.  This patch arranges for the allocated name
to be preserved there.
2021-12-05 13:13:33 -07:00
Mike Frysinger
843bf75416 sim: include ansidecl.h when needed
Avoid implicit include deps with this to help untangle sim headers
so we can get rid of arch-specific sim-main.h.
2021-12-04 22:10:04 -05:00
Mike Frysinger
33bbd5e8dd sim: include stdint.h when needed
Avoid implicit include deps with this to help untangle sim headers
so we can get rid of arch-specific sim-main.h.
2021-12-04 22:10:02 -05:00
Mike Frysinger
2c29882f83 sim: include stdarg.h when used
Avoid implicit include deps with this to help untangle sim headers
so we can get rid of arch-specific sim-main.h.
2021-12-04 22:09:42 -05:00
Mike Frysinger
20a8e078cc sim: reorder header includes
We're including system headers after local headers in a bunch of
places, but this leads to conflicts when our local headers happen
to define symbols that show up in the system headers.

Use the more standard order of:
* config.h (via defs.h)
* system headers
* local library headers (e.g. bfd & libiberty)
* sim specific headers
2021-12-04 22:09:26 -05:00
Simon Marchi
671fac7c45 gdbsupport: fix memory leak in create_file_handler when re-using file handler
ASan made me notice a memory leak, where the memory tied to the file
handle name string wasn't freed.  When register a file handler with an
fd that is already registered, we re-use the file_handler object, so we
ended up creating a new std::string object and overwriting the
file_handler::name pointer, without free-ing the old std::string.

Fix this by allocating file_handler with new, deleting it with
delete, and making file_handler::name not a pointer.

Change-Id: Ie304cc78ab5ae5dfad9a1366e9890c09de651f43
2021-12-04 21:42:43 -05:00
GDB Administrator
e8f6cf14c9 Automatic date update in version.in 2021-12-05 00:00:14 +00:00
Mike Frysinger
94f5dfed74 sim: moxie: hoist dtb rules up to common builds
These rules don't depend on the target compiler settings, so hoist
the build logic up to the common builds for better parallelization.
2021-12-04 13:55:13 -05:00
Mike Frysinger
520e19d589 sim: m68hc11: delete unused profile flags
These were moved to the common configure script a while ago and have
the same default as these, so just delete it.
2021-12-04 13:45:16 -05:00
Mike Frysinger
784712bf4f sim: msp430: delete redundant comments & settings
These were copied from the example docs, so aren't adding any value.
2021-12-04 13:45:16 -05:00
Mike Frysinger
23bd26ecf6 sim: erc32: drop old configure target
There is no configure script in here anymore to regenerate.
2021-12-04 13:45:16 -05:00
Mike Frysinger
0344e65132 sim: m32c/rl78: drop redundant -Wall settings
We already turn these on in the configure script.
2021-12-04 13:45:16 -05:00
Tom Tromey
63538d8e16 Cache the result of find_file_and_directory
This changes the DWARF reader to cache the result of
find_file_and_directory.  This is not especially important now, but it
will help the new DWARF indexer.
2021-12-04 11:16:22 -07:00
Tom Tromey
bb3f8ae290 Move file_and_directory to new file and C++-ize
This moves file_and_directory to a new file, and then C++-izes it --
replacing direct assignments with methods, and arranging for it to own
any string that must be computed.  Finally, the CU's objfile will only
be used on demand; this is an important property for the new DWARF
indexer's parallel mode.
2021-12-04 11:16:02 -07:00
Tom Tromey
17f60345f0 Remove Irix case from find_file_and_directory
find_file_and_directory has a special case for the Irix 6.2 compiler.
Since this is long obsolete, this patch removes it.
2021-12-04 11:04:48 -07:00
Mike Frysinger
3daaa003d2 sim: frv: split up testsuite a bit
Running frv's allinsn in serial is quite slow due to the sheer number
of tests it contains.  By splitting it up and running in parallel, the
execution time on my system goes from ~100sec to ~60sec.
2021-12-04 12:52:35 -05:00
Simon Marchi
e34e391824 gdb: don't show deprecated aliases
I don't think it's very useful to show deprecated aliases to the
user.  It encourages the user to use them, when the goal is the
opposite.

For example, before:

    (gdb) help set index-cache enabled
    set index-cache enabled, set index-cache off, set index-cache on
      alias set index-cache off = set index-cache enabled off
      alias set index-cache on = set index-cache enabled on
    Enable the index cache.
    When on, enable the use of the index cache.

    (gdb) help set index-cache on
    Warning: 'set index-cache on', an alias for the command 'set index-cache enabled', is deprecated.
    Use 'set index-cache enabled on'.

    set index-cache enabled, set index-cache off, set index-cache on
      alias set index-cache off = set index-cache enabled off
      alias set index-cache on = set index-cache enabled on
    Enable the index cache.
    When on, enable the use of the index cache.

After:

    (gdb) help set index-cache enabled
    Enable the index cache.
    When on, enable the use of the index cache.
    (gdb) help set index-cache on
    Warning: 'set index-cache on', an alias for the command 'set index-cache enabled', is deprecated.
    Use 'set index-cache enabled on'.

    Enable the index cache.
    When on, enable the use of the index cache.

Change-Id: I989b618a5ad96ba975367e9d16db95523cd57a4c
2021-12-04 09:06:23 -05:00
Simon Marchi
a3e9c2f9da gdb/testsuite: fix two "maint info line-table"-related tests
Commit 92228a334b ("gdb: small "maintenance info line-table"
readability improvements") change the output format of "maint info
line-table" slightly, adding some empty lines between each
line-table.  This causes two tests to start failing, update them to
account for those empty lines.

Change-Id: I9d33a58fce3e860ba0554b25f5582e8066a5c519
2021-12-03 21:03:10 -05:00
Simon Marchi
fb2a515fd0 gdb: revert one array_view copy change in ada-lang.c
Commit 4bce7cdaf4 ("gdbsupport: add array_view copy function") caused
an internal error when running gdb.ada/packed_array_assign.exp:

    print pra(1) := pr^M
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/array-view.h:217: internal-error: copy: Assertion `dest.size () == src.size ()' failed.^M

I am not sure what's the root cause of this, whether it is a GDB bug
exposed by using the array_view copy function or not.  Back out the
change that triggers the internal error for now, while we investigate
it.

Change-Id: I055ab14143e4cfd3ca7ce8f4855c6c3c05db52a7
2021-12-03 20:43:19 -05:00
Mike Frysinger
17ebe20800 bfd: unify header generation rules
The logic between these rules are extremely similar, so unify them
into a single variable.
2021-12-03 20:06:58 -05:00
Mike Frysinger
0f34c35dd9 bfd: move header updates up a directory
The rules for rebuilding the bfd headers live in the doc/ subdir
(most likely) because they rely on the chew & related tools.  But
we can collapse them into the main Makefile while keeping the tools
in the doc subdir easily enough.  This makes the code simpler and
allows for rebuilding them in parallel.

Also add automake silent rule support while we're here.
2021-12-03 20:03:05 -05:00
Mike Frysinger
f52ee74fea bfd: convert bfdver.h to silent automake rules 2021-12-03 19:57:22 -05:00
GDB Administrator
d4172973cb Automatic date update in version.in 2021-12-04 00:00:15 +00:00
Simon Marchi
92228a334b gdb: small "maintenance info line-table" readability improvements
- separate each entry with a newline, to visually separate them
 - style filenames with the filename style
 - print the name of the compunit_symtab

A header now looks like this, with the compunit_symtab name added (and
the coloring, but you can't really see it here):

    objfile: /home/simark/build/babeltrace/src/cli/.libs/babeltrace2 ((struct objfile *) 0x613000005980)
    compunit_symtab: babeltrace2-cfg-cli-args.c ((struct compunit_symtab *) 0x62100da1ed10)
    symtab: /usr/include/glib-2.0/glib/gdatetime.h ((struct symtab *) 0x62100d9ee530)
    linetable: ((struct linetable *) 0x0):

Change-Id: Idc23e10aaa66e2e692adb0a6a74144f72c4fa1c7
2021-12-03 16:52:32 -05:00
Simon Marchi
eccd14b3f5 gdb: change some alias functions parameters to const-reference
Now that we use intrusive list to link aliases, it becomes easier to
pass cmd_list_element arguments by const-reference rather than by
pointer to some functions, change a few.

Change-Id: Id0df648ed26e9447da0671fc2c858981cda31df8
2021-12-03 16:48:42 -05:00
Simon Marchi
c471bdb198 gdb: use intrusive_list for cmd_list_element aliases list
Change the manually-implemented linked list to use intrusive_list.  This
is not strictly necessary, but it makes the code much simpler.

Change-Id: Idd08090ebf2db8bdcf68e85ef72a9635f1584ccc
2021-12-03 16:48:23 -05:00
Simon Marchi
46680d22de gdb: trivial changes to use array_view
Change a few relatively obvious spots using value contents to propagate
the use array_view a bit more.

Change-Id: I5338a60986f06d5969fec803d04f8423c9288a15
2021-12-03 16:42:02 -05:00
Simon Marchi
2a50938ab7 gdb: make extract_integer take an array_view
I think it would make sense for extract_integer, extract_signed_integer
and extract_unsigned_integer to take an array_view.  This way, when we
extract an integer, we can validate that we don't overflow the buffer
passed by the caller (e.g. ask to extract a 4-byte integer but pass a
2-byte buffer).

 - Change extract_integer to take an array_view
 - Add overloads of extract_signed_integer and extract_unsigned_integer
   that take array_views.  Keep the existing versions so we don't
   need to change all callers, but make them call the array_view
   versions.

This shortens some places like:

  result = extract_unsigned_integer (value_contents (result_val).data (),
				     TYPE_LENGTH (value_type (result_val)),
				     byte_order);

into

  result = extract_unsigned_integer (value_contents (result_val), byte_order);

value_contents returns an array view that is of length
`TYPE_LENGTH (value_type (result_val))` already, so the length is
implicitly communicated through the array view.

Change-Id: Ic1c1f98c88d5c17a8486393af316f982604d6c95
2021-12-03 16:41:38 -05:00
Simon Marchi
4bce7cdaf4 gdbsupport: add array_view copy function
An assertion was recently added to array_view::operator[] to ensure we
don't do out of bounds accesses.  However, when the array_view is copied
to or from using memcpy, it bypasses that safety.

To address this, add a `copy` free function that copies data from an
array view to another, ensuring that the destination and source array
views have the same size.  When copying to or from parts of an
array_view, we are expected to use gdb::array_view::slice, which does
its own bounds check.  With all that, any copy operation that goes out
of bounds should be caught by an assertion at runtime.

copy is implemented using std::copy and std::copy_backward, which, at
least on libstdc++, appears to pick memmove when copying trivial data.
So in the end there shouldn't be much difference vs using a bare memcpy,
as we do right now.  When copying non-trivial data, std::copy and
std::copy_backward assigns each element in a loop.

To properly support overlapping ranges, we must use std::copy or
std::copy_backward, depending on whether the destination is before the
source or vice-versa.  std::copy and std::copy_backward don't support
copying exactly overlapping ranges (where the source range is equal to
the destination range).  But in this case, no copy is needed anyway, so
we do nothing.

The order of parameters of the new copy function is based on std::copy
and std::copy_backward, where the source comes before the destination.

Change a few randomly selected spots to use the new function, to show
how it can be used.

Add a test for the new function, testing both with arrays of a trivial
type (int) and of a non-trivial type (foo).  Test non-overlapping
ranges as well as three kinds of overlapping ranges: source before dest,
dest before source, and dest == source.

Change-Id: Ibeaca04e0028410fd44ce82f72e60058d6230a03
2021-12-03 16:37:36 -05:00
Simon Marchi
7509b82979 gdb: change store_waitstatus to return a target_waitstatus by value
store_waitstatus is basically a translation function between a status
integer and an equivalent target_waitstatus object.  It would make sense
for it to take the integer as a parameter and return the
target_waitstatus by value.  Do that, and rename to
host_status_to_waitstatus.  Users can then do:

  ws = host_status_to_waitstatus (status)

which does the right thing, given the move constructor of
target_waitstatus.

Change-Id: I7a07d59d3dc19d3ed66929642f82f44f3e85d61b
2021-12-03 08:31:05 -05:00