Commit Graph

104453 Commits

Author SHA1 Message Date
Alan Modra
f7c54040d7 rx-elf FAIL: SHF_GNU_RETAIN sections 27
rx-elf is an odd target with non-standard names for default text, data
and bss sections.  This patch tweaks a new test to make it pass.

	* testsuite/gas/elf/section27.s: Reorder .text, .data and .bss
	so that output section order does not depend on those sections
	being already created.  Use ".section .text" rather than ".text".
2020-12-14 14:05:05 +10:30
Pavel I. Kryukov
ad9675dd80 sim/mips/cp1.c: Include <stdlib.h> for abort() declaration
sim/mips/ChangeLog:

	* cp1.c: Include <stdlib.h>
2020-12-14 07:02:05 +04:00
Cary Coutant
f22318ef0d Re-enable incremental tests that were failing with GCC 9+.
gold/
	PR gold/23539
	PR gold/24123
	* testsuite/Makefile.am (incremental_copy_test): Re-enable for GCC 9+.
	(incremental_comdat_test_1): Likewise.
	* testsuite/Makefile.in: Regenerate.
2020-12-13 16:50:52 -08:00
GDB Administrator
70759921d8 Automatic date update in version.in 2020-12-14 00:00:11 +00:00
Cary Coutant
387a56a543 Fix incremental tests using gcc 9, which adds Gnu properties sections.
During an incremental link, we should simply ignore the Gnu properties
sections. We were not handling them properly -- failing to process the
properties from the base file. While that could be fixed, the property
sections are meant for deployed binaries, and incremental linking is
for development, so keeping the properties sections just adds to the
likelihood of forcing a full link sooner.

gold/
	PR gold/23539
	* object.cc (Sized_relobj_file::layout_gnu_property_section): Ignore
	Gnu properties during incremental links.
2020-12-13 15:28:36 -08:00
Cary Coutant
f12650bff1 Fix incremental linking with rodata merge sections.
When processing the incremental update, incoming .rodata merge sections
do not match the corresponding section in the base file, because the
SHF_MERGE flag had not been masked out of the latter.

gold/
	PR gold/24123
	* layout.cc (Layout::init_fixed_output_section): Mask out flags that
	should be ignored when matching sections.
2020-12-13 15:27:25 -08:00
Cary Coutant
4cf2ad7200 Update ELF headers and readelf with recent e_machine assignments.
binutils/
	* readelf.c (get_machine_name): Update list of e_machine values.

include/
	* elf/common.h: Update list of e_machine values.
2020-12-13 15:22:30 -08:00
Tom Tromey
f5756acc15 Constify parse_and_eval_type
I noticed that the argumen to parse_and_eval_type could be "const".
This patch implements this change.

I wonder if this could be removed.  It's only called via
check_stub_method_group, which seems questionable to me.  However, I
didn't look into doing this.

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

	* gdbtypes.c (safe_parse_type): Make argument const.
	* value.h (parse_and_eval_type): Make argument const.
	* eval.c (parse_and_eval_type): Make argument const.
2020-12-13 09:51:42 -07:00
Tom de Vries
862fcbd8f0 [gdb/testsuite] Fix gdb.base/endianity.exp with gcc-4.8
When running test-case gdb.base/endianity.exp using gcc-4.8, we get:
...
(gdb) x/x &o.v^M
0x7fffffffd120: 0x00000004^M
(gdb) XFAIL: gdb.base/endianity.exp: x/x &o.v
x/xh &o.w^M
0x7fffffffd124: 0x0003^M
(gdb) FAIL: gdb.base/endianity.exp: x/xh &o.w
...

The gcc 4.8 compiler does not support the scalar_storage_order attribute, so
the testcase is compiled without that attribute, and the expected results are
different.

Fix this by rather than xfailing, skipping the tests if the compiler does not
support the scalar_storage_order attribute.

Tested on x86_64-linux, with gcc-4.8, gcc-7, and clang-10.

gdb/testsuite/ChangeLog:

2020-12-13  Tom de Vries  <tdevries@suse.de>

	PR testsuite/26953
	* gdb.base/endianity.exp: Skip tests requiring scalar_storage_order
	attribute support if compiler doesn't support it.
2020-12-13 17:22:40 +01:00
Tom de Vries
a406a98e6e [gdb/testsuite] Handle ada in gdb_compile_shlib
The single test-case in the testsuite that creates an ada shared library is
gdb.ada/catch_ex_std.exp.

The test-case does use gdb_compile_shlib, but with a few tweaks that make sure
things are properly handled for ada.

Move the ada-specific code to gdb_compile_shlib, such that gdb_compile_sh can
be used for ada shared libs without tweaks.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-13  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (gdb_compile_shlib): Handle ada.
	* gdb.ada/catch_ex_std.exp: Use gdb_compile_shlib to compile from
	source to shared lib.  Add ada to options.
2020-12-13 16:25:19 +01:00
Tom de Vries
5d7e6ed0bd [gdb/testsuite] Avoid gnatbind/gnatlink in gdb.ada/catch_ex_std.exp
There's a single test-case in the testsuite that explicitly calls gnatbind and
gnatlink: gdb.ada/catch_ex_std.exp.

Instead, use gnatmake and pass specific gnatbind and gnatlink options using
gnatmake passthrough options -bargs and -largs.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-13  Tom de Vries  <tdevries@suse.de>

	* gdb.ada/catch_ex_std.exp: Use gnatmake -bargs and -largs instead of
	calling gnatbind and gnatlink.
2020-12-13 16:25:19 +01:00
Andrew Burgess
ee9812a001 gdb: new command 'maint flush dcache'
Add a new command to flush the dcache.

gdb/ChangeLog:

	* NEWS: Mention new commands.
	* target-dcache.c: Add 'cli/cli-cmds.h' include.
	(maint_flush_dcache_command): New function.
	(_initialize_target_dcache): Create new 'maint flush dcache'
	command.

gdb/doc/ChangeLog:

	* gdb.texinfo (Caching Target Data): Document 'maint flush
	dcache'.

gdb/testsuite/ChangeLog:

	* gdb.base/dcache-flush.c: New file.
	* gdb.base/dcache-flush.exp: New file.
2020-12-13 12:36:16 +00:00
Andrew Burgess
50a5f1878e gdb: introduce new 'maint flush ' prefix command
We currently have two flushing commands 'flushregs' and 'maint
flush-symbol-cache'.  I'm planning to add at least one more so I
thought it might be nice if we bundled these together into one place.

And so I created the 'maint flush ' command prefix.  Currently there
are two commands:

  (gdb) maint flush symbol-cache
  (gdb) maint flush register-cache

Unfortunately, even though both of the existing flush commands are
maintenance commands, I don't know how keen we about deleting existing
commands for fear of breaking things in the wild.  So, both of the
existing flush commands 'maint flush-symbol-cache' and 'flushregs' are
still around as deprecated aliases to the new commands.

I've updated the testsuite to use the new command syntax, and updated
the documentation too.

gdb/ChangeLog:

	* NEWS: Mention new commands, and that the old commands are now
	deprecated.
	* cli/cli-cmds.c (maintenanceflushlist): Define.
	* cli/cli-cmds.h (maintenanceflushlist): Declare.
	* maint.c (_initialize_maint_cmds): Initialise
	maintenanceflushlist.
	* regcache.c: Add 'cli/cli-cmds.h' include.
	(reg_flush_command): Add header comment.
	(_initialize_regcache): Create new 'maint flush register-cache'
	command, make 'flushregs' an alias.
	* symtab.c: Add 'cli/cli-cmds.h' include.
	(_initialize_symtab): Create new 'maint flush symbol-cache'
	command, make old command an alias.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Document 'maint flush symbol-cache'.
	(Maintenance Commands): Document 'maint flush register-cache'.

gdb/testsuite/ChangeLog:

	* gdb.base/c-linkage-name.exp: Update to use new 'maint flush ...'
	commands.
	* gdb.base/killed-outside.exp: Likewise.
	* gdb.opt/inline-bt.exp: Likewise.
	* gdb.perf/gmonster-null-lookup.py: Likewise.
	* gdb.perf/gmonster-print-cerr.py: Likewise.
	* gdb.perf/gmonster-ptype-string.py: Likewise.
	* gdb.python/py-unwind.exp: Likewise.
2020-12-13 12:36:15 +00:00
Borislav Petkov
7393df7f3f x86: Do not dump DS/CS segment overrides for branch hints
I've made all labels normal labels so that there's no confusion between
the different targets which is which and I match them in the .d files
with .* as Alan suggested.

Hex offsets I match with [0-9a-fx]+ since some targets prefix them with
0x, some don't, etc.

	* testsuite/gas/i386/align-branch-9.s: Don't use labels that are
	automatically local for ELF targets.
	* testsuite/gas/i386/branch.s: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-9.s: Likewise.
	* testsuite/gas/i386/x86-64-branch.s: Likewise.
	* testsuite/gas/i386/align-branch-9.d: Adjust to match more targets.
	* testsuite/gas/i386/branch.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-branch.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-9.d: Likewise.
	* testsuite/gas/i386/x86-64-branch.d: Likewise.
2020-12-13 14:02:26 +10:30
GDB Administrator
77e890c695 Automatic date update in version.in 2020-12-13 00:00:18 +00:00
GDB Administrator
33fff0ced3 Automatic date update in version.in 2020-12-12 00:00:19 +00:00
Andrew Burgess
19c659f164 gdb: improve the warning given for deprecated aliases with a prefix
Consider this GDB session:

  (gdb) define set xxx_yyy
  Type commands for definition of "set xxx_yyy".
  End with a line saying just "end".
  >echo in set xxx_yyy command\n
  >end
  (gdb) alias set qqq_aaa=set xxx_yyy
  (gdb) maintenance deprecate set qqq_aaa
  (gdb) set qqq_aaa
  Warning: 'qqq_aaa', an alias for the command 'xxx_yyy' is deprecated.
  No alternative known.

  in set xxx_yyy command
  (gdb)

Notice the warning mentions 'qqq_aaa' and 'xxx_yyy', I consider this
to be wrong.  I think the proper warning should read:

  (gdb) set qqq_aaa
  Warning: 'set qqq_aaa', an alias for the command 'set xxx_yyy', is deprecated.
  No alternative known.

With the 'set' prefixes added and a comma before the final 'is
deprecated'.  That is what this patch does.  The expected results are
updated as needed.

gdb/ChangeLog:

	* cli/cli-decode.c (deprecated_cmd_warning): Ignore the prefix
	result from lookup_cmd_composition_1, use the prefixes from both
	the command and the alias instead.
	(lookup_cmd_composition_1): Initial prefix command is the based on
	the search list being passed in.  Simplify the logic for tracking
	the prefix command.  Replace a use of alloca with a local
	std::string.

gdb/testsuite/ChangeLog:

	* gdb.base/commands.exp: Update expected results.
2020-12-11 22:10:50 +00:00
Andrew Burgess
44c77c3272 gdb: make deprecated_cmd_warning i18n friendly
Rewrite deprecated_cmd_warning to be i18n friendly.  While I'm going
through the function I also cleaned up some whitespace issues,
replaced uses of NULL with nullptr, and moved some comments to avoid
having to add { ... }.

Though the message being printed has a 'Warning: ' prefix I could have
changed from using printf_filtered to use warning, however, I haven't
done that in this commit as that would change what GDB outputs and I
wanted this commit NOT to change the output.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* cli/cli-decode.c (deprecated_cmd_warning): Use nullptr instead
	of NULL.  Don't print message piece by piece, but sentence at a
	time to allow internationalisation.  Some whitespace cleanup.
2020-12-11 22:10:50 +00:00
Andrew Burgess
9ef6d4a1b4 gdb: give deprecated command warning for aliases with a prefix
I noticed that deprecated aliases that have a prefix don't give a
deprecated command warning.  For example looking in mi/mi-main.c we
see this:

  c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &setlist);
  deprecate_cmd (c, "set mi-async");
  c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &showlist);
  deprecate_cmd (c, "show mi-async");

So both 'set target-async' and 'show target-async' are deprecated and
should be giving a warning, however, in use we see no warning given.

This is a consequence of how the code that should give this
warning (deprecated_cmd_warning) performs a second command lookup in
order to distinguish between aliases and real commands, and that the
code that calls this (lookup_cmd_1) strips off prefix commands as it
calls itself recursively.

As a result when we are considering an alias like 'set target-async'
we first enter lookup_cmd_1 with text = "set target-async", we spot
the 'set' command prefix and then recursively call lookup_cmd_1 with
text = "target-async".

We spot that 'target-async' is a known alias but that it is
deprecated, and so call deprecated_cmd_warning passing in the value of
text, which remember is now "target-async".

In deprecated_cmd_warning we again perform a command lookup starting
from the top-level cmdlist, but now we're trying to find just
"target-async", this fails (as this command requires the 'set' prefix,
and so no warning is given.

I resolved this issue by passing a command list to the function
deprecated_cmd_warning, this is the list in which the command can be
found.

A new test is added to cover this case.

However, there is an additional problem which will be addressed in a
subsequent patch.

Consider this GDB session:

  (gdb) define set xxx_yyy
  Type commands for definition of "set xxx_yyy".
  End with a line saying just "end".
  >echo in set xxx_yyy command\n
  >end
  (gdb) alias set qqq_aaa=set xxx_yyy
  (gdb) maintenance deprecate set qqq_aaa
  (gdb) set qqq_aaa
  Warning: 'qqq_aaa', an alias for the command 'xxx_yyy' is deprecated.
  No alternative known.

  in set xxx_yyy command
  (gdb)

Notice the warning mentions 'qqq_aaa' and 'xxx_yyy', I consider this
to be wrong.  I think the proper warning should read:

  (gdb) set qqq_aaa
  Warning: 'set qqq_aaa', an alias for the command 'set xxx_yyy' is deprecated.
  No alternative known.

With the 'set' prefixes added.  A later patch will resolve this
issue.

gdb/ChangeLog:

	PR cli/15104
	* cli/cli-decode.c (lookup_cmd_1): Pass command list to
	deprecated_cmd_warning.
	(deprecated_cmd_warning): Take extra parameter, call
	lookup_cmd_composition_1 and pass new parameter through.
	(lookup_cmd_composition_1): New function, takes implementation of
	lookup_cmd_composition but with extra parameter.
	(lookup_cmd_composition): Now calls lookup_cmd_composition_1
	passing in cmdlist.
	* command.h (deprecated_cmd_warning): Add extra parameter to
	declaration.
	* top.c (execute_command): Pass cmdlist to deprecated_cmd_warning.

gdb/testsuite/ChangeLog:

	PR cli/15104
	* gdb.base/commands.exp: Add additional tests.
	* gdb.base/completion.exp: Add additional tests.
2020-12-11 22:10:50 +00:00
Andrew Burgess
1536146f30 gdb: don't warn about deprecated aliases during tab completion
Consider this gdb session, where on line #3 tab completion is used:

  (gdb) alias xxx_yyy_zzz=break
  (gdb) maint deprecate xxx_yyy_zzz
  (gdb) xxx_yyy_<TAB>

The third line then updates to look like this:

  (gdb) xxx_yyy_Warning: 'xxx_yyy_zzz', an alias for the command 'break' is deprecated.
  No alternative known.

  zzz

What's happened is during tab completion the alias has been resolved
to the actual command being aliased, and at this stage the warning is
issued.  Clearly this is not what we want during tab completion.

In this commit I add a new parameter to the lookup function, a boolean
that indicates if the lookup is being done as part of completion.
This flag is used to suppress the warning.  Now we get the expected
behaviour, the alias completes without any warning, but the warning is
still given once the user executes the alias.

gdb/ChangeLog:

	* cli/cli-decode.c (lookup_cmd_1): Move header comment into
	command.h, add extra parameter, and use this to guard giving a
	warning.
	* command.h (lookup_cmd_1): Add comment from cli/cli-decode.c,
	include argument names in declaration, add new argument.
	* completer.c (complete_line_internal_1): Remove unneeded
	brackets, pass extra argument to lookup_cmd_1.

gdb/testsuite/ChangeLog:

	* gdb.base/completion.exp: Add additional tests.
2020-12-11 22:10:50 +00:00
Andrew Burgess
9664849417 gdbsupport: make use of safe-ctype functions from libiberty
Make use of the safe-ctype replacements for the standard ctype
character checking functions in gdbsupport/common-utils.cc.  The
gdbsupport library is included into both gdb and gdbserver, and on the
gdbserver side there are two targets, gdbserver itself, and also
libinproctrace.so.

libiberty was already being included in the gdbserver link command,
but was missing from the libinproctrace.so link.  As a result, after
changing gdbsupport/common-utils.cc to depend on libiberty,
libinproctrace.so would no longer link until I modified its link line.

gdbserver/ChangeLog:

	* Makefile.in (IPA_LIB): Include libiberty library.

gdbsupport/ChangeLog:

	* gdbsupport/common-utils.cc: Change 'ctype.h' include to
	'safe-ctype.h'.
	(extract_string_maybe_quoted): Use safe-ctype function versions.
	(is_digit_in_base): Likewise.
	(digit_to_int): Likewise.
	(strtoulst): Likewise.
	(skip_spaces): Likewise.
	(skip_to_space): Likewise.
2020-12-11 22:04:28 +00:00
Simon Marchi
94ba44a68d gdb: make debug_infrun a bool
gdb/ChangeLog:

	* infrun.h (debug_infrun): Make a bool.
	* infrun.c (debug_infrun): Make a bool.
	(_initialize_infrun): Use add_setshow_boolean_cmd to define "set
	debug infrun".

Change-Id: If934106a6d3f879b93d265855eb705b1d606339a
2020-12-11 14:02:52 -05:00
Simon Marchi
74b773fcd6 gdb: factor out debug_prefixed_printf_cond
The same pattern happens often to define a "debug_printf" macro:

    #define displaced_debug_printf(fmt, ...) \
      do \
        { \
          if (debug_displaced) \
    	debug_prefixed_printf ("displaced", __func__, fmt, ##__VA_ARGS__); \
        } \
      while (0)

Move this pattern behind a helper macro, debug_prefixed_printf_cond and
update the existing macros to use it.

gdb/ChangeLog:

	* displaced-stepping.h (displaced_debug_printf): Use
	debug_prefixed_printf_cond.
	* dwarf2/read.c (dwarf_read_debug_printf): Likewise.
	(dwarf_read_debug_printf_v): Likewise.
	* infrun.h (infrun_debug_printf): Likewise.
	* linux-nat.c (linux_nat_debug_printf): Likewise.

gdbsupport/ChangeLog:

	* common-debug.h (debug_prefixed_printf_cond): New.
	* event-loop.h (event_loop_debug_printf): Use
	debug_prefixed_printf_cond.

Change-Id: I1ff48b98b8d1cc405d1c7e8da8ceadf4e3a17f99
2020-12-11 14:01:12 -05:00
Tom de Vries
346e7e1923 [gdb/testsuite] Update gdb.arch/i386-mpx-call.exp for -m32
When running test-case gdb.arch/i386-mpx-call.exp with target board unix/-m32,
we run into:
...
(gdb) continue^M
Continuing.^M
(gdb) FAIL: gdb.arch/i386-mpx-call.exp: upper_bnd0: continue to a bnd violation
...

Let's look first for reference at -m64, where the test passes.

The test-case uses -mmpx -fcheck-pointer-bounds to generate pointer checks in
the exec.  Effectively, -fcheck-pointer-bounds modifies the calling ABI: a
call passes pointer bounds as well as arguments.  The call to upper (with
four pointer arguments and an int argument, passed in 5 registers) is modified
like this:
...
   lea    -0xa0(%rbp),%rcx
   lea    -0x80(%rbp),%rdx
   lea    -0x60(%rbp),%rsi
   lea    -0x40(%rbp),%rax
   mov    $0x0,%r8d
+  bndmov -0x110(%rbp),%bnd3
+  bndmov -0x100(%rbp),%bnd2
+  bndmov -0xf0(%rbp),%bnd1
+  bndmov -0xe0(%rbp),%bnd0
   mov    %rax,%rdi
-  callq  <upper>
+  bnd callq <upper>
...
passsing the four pointer bounds in bounds registers BND0-3.

The top-level mechanism of the test is as follows:
- run the exec to after all mallocs are done, such that all pointer variables
  are valid
- do inferior calls, similar to those present in the program

The inferior call mechanism doesn't differentiate between a call to a function
compiled with -fcheck-pointer-bounds, and one without.  It merely resets the
bound registers to all-allowed state (see amd64_push_dummy_call), to make sure
the checks don't trigger during the inferior call.  [ This is the same as what
happens when executing a call without bnd prefix when the BNDPRESERVE bit of
the BNDCFG register is set to 0, a provision for calling an instrumented
function using a non-instrumented call. ]

First, two inferior calls are done (default_run and verify_default_values)
with the bound registers unmodified by the test.  So, the memory accesses are
performed with the bounds registers set by amd64_push_dummy_call to
all-allowed, and the bounds checks do not trigger.

Then we try to do an inferior call with modified bounds registers, set to
none-allowed.  In order to do that, we set a breakpoint at *upper before
doing the inferior call.  Once we hit the breakpoint during the inferior call,
the bounds registers are set to none-allowed, and we continue expecting to run
into an triggered bounds check, which takes the shape of a sigsegv.

Back to -m32.  Here, the pointer arguments are passed in memory rather than
registers, so with -fcheck-pointer-bounds, the pointer bounds are placed in
the Bounds Table using bndstx:
...
  movl   $0x0,0x10(%eax)
  lea    -0x70(%ebp),%edx
  mov    %edx,0xc(%eax)
  lea    -0x5c(%ebp),%edx
  mov    %edx,0x8(%eax)
  lea    -0x48(%ebp),%edx
  mov    %edx,0x4(%eax)
  lea    -0x34(%ebp),%edx
  mov    %edx,(%eax)
  lea    0xc(%eax),%edx
  mov    0xc(%eax),%ecx
  bndmov -0xa8(%ebp),%bnd1
  bndstx %bnd1,(%edx,%ecx,1)
  lea    0x8(%eax),%edx
  mov    0x8(%eax),%ecx
  bndmov -0xa0(%ebp),%bnd3
  bndstx %bnd3,(%edx,%ecx,1)
  lea    0x4(%eax),%edx
  mov    0x4(%eax),%ecx
  bndmov -0x98(%ebp),%bnd1
  bndstx %bnd1,(%edx,%ecx,1)
  mov    (%eax),%edx
  bndmov -0x90(%ebp),%bnd3
  bndstx %bnd3,(%eax,%edx,1)
  bnd call 804893f <upper>
...

Again, the bounds registers are reset at the start of the inferior call by
amd64_push_dummy_call, and modified by the test-case, but neither has any
effect.  The code in upper reads the pointer bounds from the Bounds Table, not
from the bounds registers.

Note that for a test.c with an out-of-bounds access:
...
$ cat test.c
void foo (int *a) { volatile int v = a[1]; }
int main (void) { int a; foo (&a); return 0; }
$ gcc test.c -mmpx -fcheck-pointer-bounds -g -m32
$ ./a.out
Saw a #BR! status 1 at 0x804848d
...
and inferior call foo (&a) right before "bnd call foo" (at the point that the
bounds for a are setup in the bounds table) doesn't trigger a bounds violation:
...
(gdb) call foo (&a)
(gdb)
...
This is because the bounds table doesn't associate a pointer with bounds, but
rather a pair of pointer and pointer location.  So, the bound is setup for &a,
with as location the pushed argument in the frame.  The inferior call however
executes in a dummy frame, so the bound is checked for &a with as location the
pushed argument in the dummy frame, which is different, so the bounds check
doesn't trigger.

In conclusion, this is expected behaviour.

Update the test-case to not expect to override effective pointer bounds using
the bounds registers when the bounds passing is done via the Bounds Table.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

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

	PR testsuite/26991
	* gdb.arch/i386-mpx-call.exp: Don't expect to trigger bounds
        violations by setting bounds registers if the bounds are passed in the
        Bounds Table.
2020-12-11 18:26:40 +01:00
Tom Tromey
02c727013c Avoid side effects in expression lexers
I noticed that some of the lexers were calling write_dollar_variable
from the lexer.  This seems like a bad practice, so this patch moves
the side effects into the parsers.

I tested this by re-running gdb.fortran and gdb.modula2; the Pascal
compiler on my machine seems not to work, so I couldn't test
gdb.pascal.

I note that the type-tracking in the Pascal is also incorrect, in that
a convenience variable's type may change between parsing and
evaluation (or even during the course of evaluation).

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

	* p-exp.y (intvar): Remove global.
	(DOLLAR_VARIABLE): Change type.
	(start): Update.
	(exp): Call write_dollar_variable here...
	(yylex): ... not here.
	* m2-exp.y (DOLLAR_VARIABLE): Change type.
	(variable): Call write_dollar_variable here...
	(yylex): ... not here.
	* f-exp.y (DOLLAR_VARIABLE): Change type.
	(exp): Call write_dollar_variable here...
	(yylex): ... not here.
2020-12-11 10:10:53 -07:00
Nick Clifton
14a772212b Add support for the .bss pseudo-op to the Z80 assembler.
PR 27047
	* config/tc-z80.c (s_bss): New function.
	(md_pseudo_table): Add bss entry.
2020-12-11 16:49:38 +00:00
Tom Tromey
07d9937a20 install_variable cannot fail
I noticed that install_variable will never return false, so this patch
changes the return type to void.  I couldn't find a spot in history
where it did return false, maybe it's always been like this.

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

	* varobj.c (varobj_create): Update.
	(install_variable): Return void.
2020-12-11 09:33:42 -07:00
Tom Tromey
1345dee280 Use gdbpy_ref in instantiate_pretty_printer
This changes instantiate_pretty_printer to use gdbpy_ref, removing a
call to Py_DECREF.

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

	* varobj.c (instantiate_pretty_printer): Use gdbpy_ref.
2020-12-11 09:33:42 -07:00
Tom Tromey
446d2c032d Remove varobj_clear_saved_item
One call to varobj_clear_saved_item is from the varobj destructor.
This is no longer needed, so this patch removes the call; then inlines
the function into the sole remaining caller.

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

	* varobj.c (varobj_clear_saved_item): Remove.
	(update_dynamic_varobj_children): Update.
	(varobj::~varobj): Don't call varobj_clear_saved_item.
2020-12-11 09:33:41 -07:00
Tom Tromey
1110649507 Change varobj_item::value to a value_ref_ptr
This changes varobj_item::value to be a value_ref_ptr, removing some
manual management.

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

	* varobj.c (install_dynamic_child, varobj_clear_saved_item)
	(update_dynamic_varobj_children, create_child)
	(create_child_with_value): Update.
	* varobj-iter.h (struct varobj_item) <value>: Now a
	value_ref_ptr.
	* python/py-varobj.c (py_varobj_iter::next): Call release_value.
2020-12-11 09:33:40 -07:00
Tom Tromey
24fd95b4cd Change varobj_dynamic::child_iter to unique_ptr
This changes varobj_dynamic::child_iter to be a unique_ptr, removing
some manual management.

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

	* varobj.c (struct varobj_dynamic) <child_iter>: Now unique_ptr.
	(varobj_get_iterator): Return unique_ptr.
	(update_dynamic_varobj_children, install_visualizer)
	(varobj::~varobj): Update.
	* python/python-internal.h (py_varobj_get_iterator): Return
	unique_ptr.
	* python/py-varobj.c (py_varobj_get_iterator): Return unique_ptr.
2020-12-11 09:33:40 -07:00
Tom Tromey
7446266408 Change varobj_dynamic::saved_item to unique_ptr
This changes varobj_dynamic::saved_item to be a unique_ptr.

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

	* varobj.c (struct varobj_dynamic) <saved_item>: Now unique_ptr.
	(varobj_clear_saved_item, update_dynamic_varobj_children):
	Update.
2020-12-11 09:33:39 -07:00
Tom Tromey
60ee72f6d3 Change varobj_iter::next to return unique_ptr
This changes varobj_iter::next to return a unique_ptr.  This fits in
with the ongoing theme of trying to express these ownership transfers
via the type system.

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

	* varobj.c (update_dynamic_varobj_children): Update.
	* varobj-iter.h (struct varobj_iter) <next>: Change return type.
	* python/py-varobj.c (struct py_varobj_iter) <next>: Change return
	type.
	(py_varobj_iter::next): Likewise.
2020-12-11 09:33:39 -07:00
Tom Tromey
54746ce37a C++-ify varobj iteration
This changes the varobj iteration code to use a C++ class rather than
a C struct with a separate "ops" structure.  The only implementation
is updated to use inheritance.  This simplifies the code quite nicely.

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

	* varobj.c (update_dynamic_varobj_children, install_visualizer)
	(varobj::~varobj): Update.
	* varobj-iter.h (struct varobj_iter): Change to interface class.
	(struct varobj_iter_ops): Remove.
	(varobj_iter_next, varobj_iter_delete): Remove.
	* python/py-varobj.c (struct py_varobj_iter): Derive from
	varobj_iter.  Add constructor, destructor.  Rename members.
	(py_varobj_iter::~py_varobj_iter): Rename from
	py_varobj_iter_dtor.
	(py_varobj_iter::next): Rename from py_varobj_iter_next.
	(py_varobj_iter_ops): Remove.
	(py_varobj_iter): Rename from py_varobj_iter_ctor.
	(py_varobj_iter_new): Remove.
	(py_varobj_get_iterator): Update.
2020-12-11 09:33:38 -07:00
Tom Tromey
d8f168ddd0 Change all_root_varobjs to take a function_view
This changes all_root_varobjs to take a function_view.  This
simplifies some of the callers, in particular we can remove a data
type that only existed to be passed through.

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

	* varobj.h (all_root_varobjs): Take a function_view.
	* varobj.c (all_root_varobjs): Take a function_view.
	(varobj_invalidate_iter): Remove unused parameter.
	(varobj_invalidate): Update.
	* mi/mi-cmd-var.c (struct mi_cmd_var_update): Remove.
	(mi_cmd_var_update_iter): Change parameters.
2020-12-11 09:33:37 -07:00
Tom Tromey
76deb5d918 Change varobj.c:rootlist to a std::list
This changes varobj.c:rootlist to be a std::list.  This lets us remove
some code.  std::list is chosen because its iterator invalidation
approach suits the all_root_varobjs API.

I considered replacing all_root_varobjs with "external iteration", but
haven't gotten around to doing so.

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

	* varobj.c (struct varobj_root) <next>: Remove.
	(struct vlist): Remove.
	(rootlist): Now a std::list.
	(install_variable, uninstall_variable, all_root_varobjs): Update.
2020-12-11 09:33:37 -07:00
Tom Tromey
2c1413a98c Use htab_t in varobj
varobj.c currently has its own hash table implementation.  This patch
replaces it with htab_t, simplifying the code.

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

	* varobj.c (VAROBJ_TABLE_SIZE): Remove.
	(varobj_table): Now htab_t.
	(varobj_get_handle, install_variable, uninstall_variable):
	Update.
	(hash_varobj, eq_varobj_and_string): New functions.
	(hash_varobj): Update.
2020-12-11 09:33:36 -07:00
Tom Tromey
b6433ede07 Make bp_location derive from refcounted_object
This changes bp_location to derive from refcounted_object, introduces
a ref_ptr specialization for this type, and then changes
bpstats::bp_location_at to use that specialization.  This removes some
manual reference counting and simplifies the code.

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

	* inline-frame.c (stopped_by_user_bp_inline_frame): Update.
	* ada-lang.c (check_status_exception): Update.
	* breakpoint.c (free_bp_location): Remove.
	(decref_bp_location): Use bp_location_ref_policy.
	(bpstats::bpstats): Don't call incref_bp_location.
	(bpstats::~bpstats): Remove.
	(bpstats::bpstats): Update.
	(bpstat_check_watchpoint, bpstat_check_breakpoint_conditions)
	(bp_location::bp_location): Update.
	(incref_bp_location): Remove.
	(bkpt_print_it): Update.
	* breakpoint.h (class bp_location): Derive from
	refcounted_object.
	(struct bpstats): Remove destructor.
	<bp_location_at>: Now a bp_location_ref_ptr.
	<refc>: Remove.
	(bp_location_ref_ptr): New typedef.
	(struct bp_location_ref_policy): New.
2020-12-11 09:21:55 -07:00
Tom Tromey
bfcb9db853 Remove scoped_inc_dec_ref
We can remove scoped_inc_dec_ref by changing the sole user to instead
keep a vector of thread_info_ref objects.  This removes some manual
reference counting and simplifies the code a bit.

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

	* thread.c (class scoped_inc_dec_ref): Remove.
	(tp_array_compar_ascending, tp_array_compar_descending): Change
	parameter types.
	(thread_apply_all_command): Use thread_info_ref.
2020-12-11 09:21:55 -07:00
Tom Tromey
d634cd0bce Use thread_info_ref in stop_context
This changes stop_context to use a thread_info_ref, removing some
manual reference counting.

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

	* infrun.c (struct stop_context) <thread>: Now a thread_info_ref.
	(stop_context::stop_context): Update.
	(stop_context::~stop_context): Remove.
2020-12-11 09:21:54 -07:00
Tom Tromey
51107df53a Change current_inferior_ to be a inferior_ref
This changes current_inferior_ to be an inferior_ref, removing some
manual reference counting.

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

	* inferior.c (current_inferior_): Change type.
	(current_inferior, set_current_inferior, initialize_inferiors):
	Update.
2020-12-11 09:21:53 -07:00
Tom Tromey
15f4dddd8a Use thread_info_ref in enable_thread_stack_temporaries
This changes enable_thread_stack_temporaries to use a thread_info_ref,
removing some manual reference counting.

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

	* gdbthread.h (class enable_thread_stack_temporaries) <m_thr>:
	Change type.
2020-12-11 09:21:53 -07:00
Tom Tromey
a9f14fa549 Handle CPU offset for Ravenscar
The Ravenscar support assumes that the thread ID is the same as the
CPU ID that appears in the Ada task structure.  However, on some
systems, gdbserver will report thread IDs that are off by some
constant.  This can happen, e.g., with qemu in a scenario where there
is an additional (unreported) CPU in the emulation.

The Ada Ravenscar runtimes have been modified to store this offset in
a global variable.  This patch changes gdb to read this variable, when
it exists, and apply the offset to the base CPU ID.  This fixes some
crashes that otherwise occur.

2020-12-11  Tom Tromey  <tromey@adacore.com>

	* ada-tasks.c (struct ada_tasks_pspace_data) <cpu_id_offset>: New
	field.
	(ada_get_tcb_types_info): Look for __gnat_gdb_cpu_first_id.
	(read_atcb): Use cpu_id_offset.
2020-12-11 08:01:47 -07:00
Sebastian Huber
b143e2d506 Fix a build problem when using FreeBSD 12.
* ar.c (write_archive): Cast iostream pointer to FILE *.
	* arsup.c (ar_save): Likewise.
	* objcopy.c (copy_file): Likewise.
2020-12-11 13:27:45 +00:00
Tom de Vries
9cd7a95a2b [gdb/testsuite] Fix gdb.base/float128.exp with --with-mpfr=no
When configuring gdb using --with-mpfr=no and running test-case
gdb.base/float128.exp, we run into:
...
FAIL: gdb.base/float128.exp: print large128 (GDB may be missing MPFR support!)
...

Fix this by detecting that gdb was build without mpfr using the show
configuration command, and changing the FAIL into UNSUPPORTED.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

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

	PR testsuite/26954
	* gdb.base/float128.exp: Detect and handle no mpfr support.
2020-12-11 13:55:04 +01:00
Simon Marchi
4483a8e72a gdb/testsuite: fix race condition in gdb.multi/multi-arch-exec.exp
That test fails intermittently for me.  The problem is a race condition
between the exec syscall and GDB resuming threads.

The initial situation is that we have two threads, let's call them
"leader" and "other".  Leader is the one who is going to do the exec.
We stop at the breakpoint on the all_started function, so both threads
are stopped.  When resuming, GDB resumes leader first and other second.
However, between resuming the two threads, leader has time to run and do
its exec, making other disappear.  When GDB tries to resume other, it is
ino longer there.  We get some "Couldn't get registers: No such
process." messages, and the state is a bit messed up.

The issue can be triggered consistently by adding a small delay after
the resume syscall:

    diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
    index d5a062163c7..9540339a9da 100644
    --- a/gdb/inf-ptrace.c
    +++ b/gdb/inf-ptrace.c
    @@ -308,6 +308,8 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
       gdb_ptrace (request, ptid, (PTRACE_TYPE_ARG3)1, gdb_signal_to_host (signal));
       if (errno != 0)
         perror_with_name (("ptrace"));
    +  for (int i = 0 ; i < 100; i++)
    +    usleep (10000);
     }

     /* Wait for the child specified by PTID to do something.  Return the

This patch is about fixing the test to avoid this, since the test is not
about testing this particular corner case.  Handling of multi-threaded
program doing execs should be improved too, but that's not the goal of
this patch.

Fix it by adding a synchronization point in the test to make sure both
threads were resumed by GDB before doing the exec.  I added two
pthread_barrier_wait calls in each thread (for a total of three).  I
think adding one call in each thread would not be enough, because this
could happen:

- both threads reach the first barrier
- the "other" thread is scheduled so has time to run and hit the second
  barrier
- the "leader" thread hits the all_started function breakpoint, causing
  both threads to be stopped by GDB
- GDB resumes the "leader" thread
- Since the "other" thread has already reached the second barrier, the
  "leader" thread is free to run past its second barrier and do the
  exec, while GDB still hasn't resumed the second one

By adding two barrier calls in each thread, I think we are good.  The test
passes consistently for me, even with the artificial delay added.

gdb/testsuite/ChangeLog:

	PR gdb/24694
	* gdb.multi/multi-arch-exec.c (thread_start, main): Add barrier
	calls.

Change-Id: I25c8ea9724010b6bf20b42691c716235537d0e27
2020-12-10 19:56:23 -05:00
GDB Administrator
33e06c75aa Automatic date update in version.in 2020-12-11 00:00:24 +00:00
Tom de Vries
1006702837 [gdb/testsuite] Fix gdb.tui/new-layout.exp with tcl 8.5
In commit 4d91ddd342 "[gdb/testsuite] Fix unbalanced braces in
gdb.tui/new-layout.exp", I tried to fix a problem with test-case
gdb.tui/new-layout.exp when running with tcl 8.5.

However, at that point I only had access to the log containing the failure,
and unfortunately my patch turned out not to be effective.

So, finally fix this problem by guarding the problematic code with:
...
if { [tcl_version_at_least 8 6] } { ... }
...

Tested on x86_64-linux, specifically SLE-11 where I ran into the failure.

gdb/testsuite/ChangeLog:

2020-12-10  Tom de Vries  <tdevries@suse.de>

	PR testsuite/26947
	* gdb.tui/new-layout.exp: Don't execute tests with unbalanced curly
	braces for tcl 8.5 and earlier.
2020-12-10 23:44:49 +01:00
Kevin Buettner
2ccee230f8 Fix off-by-one error in ada_fold_name
I'm seeing a libstdc++ assertion failure when running GDB's "maint selftest"
command when GDB is configured with the following CFLAGS and CXXFLAGS as
part of the configure line:

  CFLAGS='-D_GLIBCXX_DEBUG -g3 -O0' CXXFLAGS='-D_GLIBCXX_DEBUG -g3 -O0'

This is what I see when running the self tests:

(gdb) maint 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.
Running selftest command_structure_invariants.
Running selftest copy_bitwise.
Running selftest copy_integer_to_size.
Running selftest cp_remove_params.
Running selftest cp_symbol_name_matches.
Running selftest dw2_expand_symtabs_matching.
/usr/include/c++/11/string_view:211: constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::const_reference = const char&; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
Aborted (core dumped)

Here's a partial stack trace:

  #0  0x00007ffff6ef6262 in raise () from /lib64/libc.so.6
  #1  0x00007ffff6edf8a4 in abort () from /lib64/libc.so.6
  #2  0x00000000004249bf in std::__replacement_assert (
      __file=0xef7480 "/usr/include/c++/11/string_view", __line=211,
      __function=0xef7328 "constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::ba"...,
      __condition=0xef7311 "__pos < this->_M_len")
      at /usr/include/c++/11/x86_64-redhat-linux/bits/c++config.h:2624
  #3  0x0000000000451737 in std::basic_string_view<char, std::char_traits<char> >::operator[] (this=0x7fffffffc200, __pos=8)
      at /usr/include/c++/11/string_view:211
  #4  0x00000000004329f5 in ada_fold_name (name="function")
      at /ironwood1/sourceware-git/rawhide-master/bld/../../worktree-master/gdb/ada-lang.c:988

And, looking at frame #4...

(top-gdb) up 4
    at /ironwood1/sourceware-git/rawhide-master/bld/../../worktree-master/gdb/ada-lang.c:988
988		fold_buffer[i] = tolower (name[i]);
(top-gdb) p i
$1 = 8
(top-gdb) p name.size()
$2 = 8

My patch adjusts the comparison to only copy name.size() characters
from the string.  I've added a separate statement for NUL character
termination of fold_buffer[].

gdb/ChangeLog:

	* ada-lang.c (ada_fold_name): Fix off-by-one error.
2020-12-10 14:21:31 -07:00
Luis Machado
ae1f4d2d99 Remove spurious newline on debug printf
I noticed a spurious newline on infrun debugging output. The following patch
fixes that. I'll push as obvious.

gdb/ChangeLog:

2020-12-10  Luis Machado  <luis.machado@linaro.org>

	* breakpoint.c (should_be_inserted): Don't output newline.
2020-12-10 12:25:02 -03:00