]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
4 years agoDon't cast a tui_win_info directly to tui_gen_win_info
Tom Tromey [Sun, 16 Jun 2019 20:10:25 +0000 (14:10 -0600)] 
Don't cast a tui_win_info directly to tui_gen_win_info

I found a few spots that directly cast a tui_win_info to a
tui_gen_win_info.  However, I think it's a bit better here to take the
address of the "generic" member.  As far as I know, nothing relies on
being able to downcast here, so this gives us the freedom to rearrange
the structure.

gdb/ChangeLog
2019-06-16  Tom Tromey  <tom@tromey.com>

* tui/tui-wingeneral.c (tui_unhighlight_win, tui_highlight_win)
(make_all_visible): Use address of member.

4 years agoRemove more unnecessary casts of NULL
Tom Tromey [Sun, 16 Jun 2019 19:48:21 +0000 (13:48 -0600)] 
Remove more unnecessary casts of NULL

I found a few more spots that unnecessarily cast NULL to a pointer
type.  My earlier search included a "*" in the cast, but these use a
typedef to a pointer type instead.  This patch removes these casts.

gdb/ChangeLog
2019-06-16  Tom Tromey  <tom@tromey.com>

* tui/tui-data.c (tui_clear_win_detail, init_win_info)
(tui_free_window, free_content, free_content_elements): Remove
unnecessary cast.
* tui/tui-windata.c (tui_display_all_data): Remove unnecessary
cast.
* tui/tui-regs.c (tui_show_register_group)
(tui_display_registers_from, tui_display_reg_element_at_line):
Remove unnecessary cast.

4 years agogdb: Remove unused signal mask
Andrew Burgess [Sun, 16 Jun 2019 16:34:22 +0000 (17:34 +0100)] 
gdb: Remove unused signal mask

In the following commit:

    commit 7feb7d068ae65557ede03c36468ebac61b0939ca
    Date:   Mon May 11 12:08:03 2009 +0000

The last useful uses of normal_mask in linux-nat.c were removed, since
then this variable has sat around being initialised, but never used.
There should be no user visible changes after this commit.

gdb/ChangeLog:

* linux-nat.c (normal_mask): Delete.
(_initialize_linux_nat): Don't initialise normal_mask.

4 years agoWrite index for dwz -m file
Simon Marchi [Sun, 16 Jun 2019 14:13:56 +0000 (10:13 -0400)] 
Write index for dwz -m file

PR 24445 ("dwz multifile index not written to index cache") exposed the
fact that we are not doing things right when we generate an index for an
object file that has is linked to a dwz file.  The same happens whether
the index is generated with the intent of populating the index cache or
using the save gdb-index command.

The problem can be observed when running these tests with the
cc-with-dwz-m board:

    FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
    FAIL: gdb.dwarf2/gdb-index.exp: index used
    FAIL: gdb.dwarf2/gdb-index.exp: index used after symbol reloading

When generating the index for such file and inspecting the CU list of the
resulting index (with readelf --debug-dump=gdb_index), we can see something
like:

    CU table:
    [  0] 0x0 - 0xb9
    [  1] 0x0 - 0x44

This is supposed to be a sorted list of the ranges of all CUs in the
file this index represents, so already having some overlap is a red
flag.  It turns out that we save the ranges of CUs coming from both the
main file and the dwz file in the same index.

After digging a little bit, it became quite obvious that the index in
the main file should only list the CUs present in the main file, and a
separate index should be generated for the dwz file, listing the CUs
present in that file.

First, that's what happens if you run dwz on a file that already has a
GDB index embedded.  Second, dwarf2read.c has code to read an index from
a dwz file.  The index in the dwz file is actually required to be
present, if the main file has an index.

So this patch changes write_psymtabs_to_index to generate an index for
the dwz file, if present.  That index only contains a CU list, just like
what the dwz tool does when processing a file that already contains an
index.

Some notes about the implementation:

- The file management (creating a temp file, make sure it's
  close/removed on error - in the right order) is a bit heavy in
  write_psymtabs_to_index, and I needed to add a third file.  I factored
  this pattern in a separate class, index_wip_file.
- It became a bit tedious to keep the call to assert_file_size in
  write_psymtabs_to_index, write_gdbindex would have had to return two
  sizes.  Instead, I moved the calls to assert_file_size where the file
  is written.  The downside is that we lose the filename at this point,
  but it was only used for the very improbable case of ftell failing, so
  I think it's not a problem.
- The actual writing of the index file is factored out to
  write_gdbindex_1, so it can be re-used for both index files.
- While the "save gdb-index" command will now write two .gdb-index
  files, this patch does not update the gdb-add-index.sh script, this
  will come in a later patch.

gdb/ChangeLog:

YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

PR gdb/24445
* dwarf-index-write.h (write_psymtabs_to_index): Add
dwz_basename parameter.
* dwarf-index-write.c (write_gdbindex): Move file writing to
write_gdbindex_1.  Change return type void.
(assert_file_size): Move up, remove filename parameter.
(write_gdbindex_1): New function.
(write_debug_names): Change return type to void, call
assert_file_size.
(struct index_wip_file): New struct.
(write_psymtabs_to_index): Add dwz_basename parameter.  Move
file logic to index_wip_file.  Write index for dwz file if
needed.
(save_gdb_index_command): Pass basename of dwz file, if present.
* dwarf-index-cache.c (index_cache::store): Obtain and pass
build-id of dwz file, if present.
* dwarf2read.c (struct dwz_file): Move to dwarf2read.h.
(dwarf2_get_dwz_file): Likewise.
* dwarf2read.h (struct dwz_file): Move from dwarf2read.c.
(dwarf2_get_dwz_file): Likewise.

gdb/testsuite/ChangeLog:

YYYY-MM-DD  Tom de Vries  <tdevries@suse.de>

PR gdb/24445
* gdb.dwarf2/gdb-index.exp (add_gdb_index): Update dwz file with
generated index.

4 years agoReplace uses of concat with xstrdup
Tom Tromey [Sun, 16 Jun 2019 16:00:52 +0000 (10:00 -0600)] 
Replace uses of concat with xstrdup

I noticed a couple of spots using concat that could use xstrdup
instead.  This patch fixes these.

gdb/ChangeLog
2019-06-16  Tom Tromey  <tom@tromey.com>

* coffread.c (process_coff_symbol): Use xstrdup.
* value.c (create_internalvar): Use xstrdup.

4 years agoRemove unnecessary casts of NULL
Tom Tromey [Sun, 16 Jun 2019 15:56:35 +0000 (09:56 -0600)] 
Remove unnecessary casts of NULL

I noticed some unnecessary casts of NULL.  This removes all the
unnecessary ones, leaving only ones where we must ensure that NULL has
pointer type for passing through varargs.

I removed a couple of useless casts of 0 that I noticed while writing
this.

Tested by rebuilding.

gdb/ChangeLog
2019-06-16  Tom Tromey  <tom@tromey.com>

* valops.c (value_cast, value_slice): Remove unnecessary cast.
* breakpoint.c (stopin_command, stopat_command)
(until_break_command, decode_location_default): Remove unnecessary
cast.
* utils.c (subset_compare): Remove unnecessary cast.
* ada-lang.c (ada_update_initial_language): Remove unnecessary
cast.
* linespec.c (decode_line_with_last_displayed): Remove unnecessary
cast.
* infcmd.c (path_command): Remove unnecessary cast.
* coffread.c (decode_type): Remove unnecessary cast.
* xcoffread.c (read_xcoff_symtab): Remove unnecessary cast.
* mipsread.c (mipscoff_symfile_read): Remove unnecessary cast.
* tui/tui-stack.c (tui_show_locator_content)
(tui_show_frame_info): Remove unnecessary cast.
* tui/tui-win.c (tui_scroll_forward_command)
(tui_scroll_backward_command, tui_set_focus, tui_set_win_height)
(parse_scrolling_args): Remove unnecessary cast.
* tui/tui-data.c (init_win_info, tui_del_window)
(tui_free_window, tui_del_data_windows, tui_free_data_content)
(free_content_elements): Remove unnecessary cast.
* tui/tui-windata.c (tui_first_data_item_displayed): Remove
unnecessary cast.
* tui/tui-source.c (tui_set_source_content)
(tui_vertical_source_scroll): Remove unnecessary cast.
* tui/tui-layout.c (tui_default_win_height): Remove unnecessary
cast.
* tui/tui-io.c (tui_initialize_io): Remove unnecessary cast.
* tui/tui-regs.c (tui_display_registers_from)
(tui_display_register): Remove unnecessary cast.
* tui/tui-wingeneral.c (tui_refresh_win, tui_delete_win)
(tui_unhighlight_win, tui_highlight_win, tui_make_window)
(make_visible): Remove unnecessary cast.
* tui/tui-winsource.c (tui_erase_source_content)
(tui_update_breakpoint_info, tui_set_exec_info_content): Remove
unnecessary cast.
* ax-gdb.c (agent_command_1): Remove unnecessary cast.
* cli/cli-setshow.c (cmd_show_list): Remove unnecessary cast.
* stabsread.c (read_type, read_array_type, read_range_type):
Remove unnecessary cast.
* mdebugread.c (mdebug_build_psymtabs): Remove unnecessary cast.
(parse_symbol, parse_type, upgrade_type, parse_external)
(parse_partial_symbols, psymtab_to_symtab_1, cross_ref): Remove
unnecessary cast.
* gdb_bfd.c (gdb_bfd_map_section): Remove unnecessary cast.

4 years agogdb/testsuite: Improve detection of bug gdb/24541
Andrew Burgess [Sun, 16 Jun 2019 15:17:59 +0000 (16:17 +0100)] 
gdb/testsuite: Improve detection of bug gdb/24541

In bug gdb/24686 a testsuite failure was reported, this failure was
actually just another instance of bug gdb/24541, however, due to the
non-deterministic nature of bug gdb/24541 the testsuite pattern that
was intended to catch this bug failed.

This commit adds a second pattern to help detect gdb/24541, which
should change the FAIL reported in gdb/24686 into a KFAIL.

gdb/testsuite/ChangeLog:

PR gdb/24686
* gdb.mi/mi-catch-cpp-exceptions.exp: Add an extra pattern to
improve detection of bug gdb/24541.

4 years agoRemove some NULL checks from the TUI
Tom Tromey [Sat, 15 Jun 2019 22:06:27 +0000 (16:06 -0600)] 
Remove some NULL checks from the TUI

I found a few spots in the TUI that were NULL-checking the result of
XNEW.  This cannot return NULL, so this patch removes the checks.

gdb/ChangeLog
2019-06-16  Tom Tromey  <tom@tromey.com>

* tui/tui-data.c (tui_alloc_generic_win_info)
(tui_alloc_win_info, tui_add_content_elements): Remove NULL
checks.

4 years agoFix some whitespace issues in gdb ChangeLogs
Simon Marchi [Sun, 16 Jun 2019 14:00:39 +0000 (10:00 -0400)] 
Fix some whitespace issues in gdb ChangeLogs

4 years agoMake gdb.base/index-cache.exp work with readnow board (PR 24669)
Simon Marchi [Sun, 16 Jun 2019 13:07:16 +0000 (09:07 -0400)] 
Make gdb.base/index-cache.exp work with readnow board (PR 24669)

The gdb.base/index-cache.exp test fails with the readnow board:

  $ make check TESTS="gdb.base/index-cache.exp" RUNTESTFLAGS="--target_board=readnow"
  FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: at least one file was created
  FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: expected file is there
  FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: check index-cache stats
  FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats

The problem is similar to what was fixed in

  5a56d6a65f84 ("[gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names}")

In that commit, gdb.base/index-cache.exp was modified to account for the
fact that the index cache is not used when the binary already has an
embedded index.

The same situation happens when GDB is started with the -readnow flag:
it bypasses indices and partial symbols.  So this patch updates the test
to also expect the index cache not to be used if -readnow is present in
$GDBFLAGS,

gdb/testsuite/ChangeLog:

PR gdb/24669
* gdb.base/index-cache.exp (uses_readnow,
expecting_index_cache_use): Define global variable.
(test_cache_enabled_miss, test_cache_enabled_hit): Use
expecting_index_cache_use.

4 years agoAutomatic date update in version.in
GDB Administrator [Sun, 16 Jun 2019 00:01:04 +0000 (00:01 +0000)] 
Automatic date update in version.in

4 years agogdb/fortran: Show the type for non allocated / associated types
Andrew Burgess [Fri, 1 Mar 2019 11:12:33 +0000 (11:12 +0000)] 
gdb/fortran: Show the type for non allocated / associated types

Show the type of not-allocated and/or not-associated types.  For array
types and pointer to array types we are going to print the number of
ranks.

Consider this Fortran program:

  program test
    integer, allocatable :: vla (:)
    logical l
    allocate (vla(5:12))
    l = allocated (vla)
  end program test

And this GDB session with current HEAD:

  (gdb) start
  ...
  2   integer, allocatable :: vla (:)
  (gdb) n
  4   allocate (vla(5:12))
  (gdb) ptype vla
  type = <not allocated>
  (gdb) p vla
  $1 = <not allocated>
  (gdb)

And the same session with this patch applied:

  (gdb) start
  ...
  2   integer, allocatable :: vla (:)
  (gdb) n
  4   allocate (vla(5:12))
  (gdb) ptype vla
  type = integer(kind=4), allocatable (:)
  (gdb) p vla
  $1 = <not allocated>
  (gdb)

The type of 'vla' is now printed correctly, while the value itself
still shows as '<not allocated>'.  How GDB prints the type of
associated pointers has changed in a similar way.

gdb/ChangeLog:

* f-typeprint.c (f_print_type): Don't return early for not
associated or not allocated types.
(f_type_print_varspec_suffix): Add print_rank parameter and print
ranks of array types in case they dangling.
(f_type_print_base): Add print_rank parameter.

gdb/testsuite/ChangeLog:

* gdb.fortran/pointers.f90: New file.
* gdb.fortran/print_type.exp: New file.
* gdb.fortran/vla-ptype.exp: Adapt expected results.
* gdb.fortran/vla-type.exp: Likewise.
* gdb.fortran/vla-value.exp: Likewise.
* gdb.mi/mi-vla-fortran.exp: Likewise.

4 years agogdb/mi: New commands to catch C++ exceptions
Andrew Burgess [Wed, 8 May 2019 18:01:36 +0000 (19:01 +0100)] 
gdb/mi: New commands to catch C++ exceptions

Adds some MI commands to catch C++ exceptions.  The new commands are
-catch-throw, -catch-rethrow, and -catch-catch, these all correspond
to the CLI commands 'catch throw', 'catch rethrow', and 'catch catch'.

Each MI command takes two optional arguments, '-t' has the effect of
calling 'tcatch' instead of 'catch', for example:

   (gdb)
   -catch-throw -t

Is the same as:

   (gdb) tcatch throw

There is also a '-r REGEXP' argument that can supply a regexp to match
against the exception type, so:

   (gdb)
   -catch-catch -r PATTERN

Is the same as:

   (gdb) catch catch PATTERN

The change in print_mention_exception_catchpoint might seem a little
strange; changing the output from using ui_out::field_int and
ui_out::text to using  ui_out::message.

The print_mention_exception_catchpoint is used as the 'print_mention'
method for the exception catchpoint breakpoint object.  Most of the
other 'print_mention' methods (see breakpoint.c) use either
printf_filtered, of ui_out::message.  Using field_int was causing an
unexpected field to be added to the MI output.  Here's the output
without the change in print_mention_exception_catchpoint:

    (gdb)
    -catch-throw
    ^done,bkptno="1",bkpt={number="1",type="breakpoint",disp="keep",
                           enabled="y",addr="0x00000000004006c0",
                           what="exception throw",catch-type="throw",
                           thread-groups=["i1"],times="0"}

Notice the breakpoint number appears in both the 'bkptno' field, and
the 'number' field within the 'bkpt' tuple.  Here's the output with
the change in print_mention_exception_catchpoint:

    (gdb)
    -catch-throw
    ^done,bkpt={number="1",type="breakpoint",disp="keep",
                enabled="y",addr="0x00000000004006c0",
                what="exception throw",catch-type="throw",
                thread-groups=["i1"],times="0"}

gdb/ChangeLog:

* NEWS: Mention new MI commands.
* break-catch-throw.c (enum exception_event_kind): Move to
breakpoint.h.
(print_mention_exception_catchpoint): Output text as a single
message.
(catch_exception_command_1): Rename to...
(catch_exception_event): ...this, make non-static, update header
command, and change some parameter types.
(catch_catch_command): Update for changes to
catch_exception_command_1.
(catch_throw_command): Likewise.
(catch_rethrow_command): Likewise.
* breakpoint.c (enum exception_event_kind): Delete.
* breakpoint.h (enum exception_event_kind): Moved here from
break-catch-throw.c.
(catch_exception_event): Declare.
* mi/mi-cmd-catch.c (mi_cmd_catch_exception_event): New function.
(mi_cmd_catch_throw): New function.
(mi_cmd_catch_rethrow): New function.
(mi_cmd_catch_catch): New function.
* mi/mi-cmds.c (mi_cmds): Add 'catch-throw', 'catch-rethrow', and
'catch-catch' entries.
* mi/mi-cmds.h (mi_cmd_catch_throw): Declare.
(mi_cmd_catch_rethrow): Declare.
(mi_cmd_catch_catch): Declare.

gdb/doc/ChangeLog:

* gdb.texinfo (GDB/MI Catchpoint Commands): Add menu entry to new
node.
(C++ Exception GDB/MI Catchpoint Commands): New node to describe
new MI commands.

gdb/testsuite/ChangeLog:

* gdb.mi/mi-catch-cpp-exceptions.cc: New file.
* gdb.mi/mi-catch-cpp-exceptions.exp: New file.
* lib/mi-support.exp (mi_expect_stop): Handle 'exception-caught'
as a stop reason.

4 years agogdb: Don't allow annotations to influence what else GDB prints
Andrew Burgess [Fri, 14 Jun 2019 22:43:00 +0000 (23:43 +0100)] 
gdb: Don't allow annotations to influence what else GDB prints

The annotations should be additional information printed by GDB to be
consumed by users (GUIs), but GDB shouldn't reduce what it prints
based on whether annotations are on or not.  However, this is what
happens for annotate_source_line.

This commit makes annotate_source_line a void function that simply
outputs the annotation information, GDB will then print the contents
of the source line to the terminal in the normal way.

Some tests needed to be updated after this commit.

gdb/ChangeLog:

* annotate.c (annotate_source_line): Change return type to void,
update implementation to match.
* annotate.h (annotate_source_line): Change return type to void,
update header comment.
* stack.c (print_frame_info): Don't change what frame information
is printed based on whether annotations are on or not.

gdb/testsuite/ChangeLog:

* gdb.base/annota1.exp: Update expected results.
* gdb.cp/annota2.exp: Likewise.
* gdb.cp/annota3.exp: Likewise.

4 years agogdb: Remove an update of current_source_line and current_source_symtab
Andrew Burgess [Wed, 12 Jun 2019 21:34:26 +0000 (22:34 +0100)] 
gdb: Remove an update of current_source_line and current_source_symtab

While reviewing some of the annotation code I noticed that
identify_source_line (in source.c) sets current_source_line,
current_source_symtab, and also calls clear_lines_listed_range.  This
seems a little strange, identify_source_line is really a wrapper
around annotate_source, and is only called when annotation_level is
greater than 0 (so annotations are turned on).

It seems weird (to me) that when annotations are on we update GDB's
idea of the "current" line/symtab, but when they are off we don't,
given that annotations are really about communicating GDB's state to a
user (GUI) and surely shouldn't be changing GDB's behaviour.

This commit removes from identify_source_line all of the setting of
current line/symtab and the call to clear_lines_listed_range, after
doing this GDB still passes all tests, so I don't believe these lines
were actually required.

With this code removed identify_source_line is only a wrapper around
annotate_source, so I moved identify_source_line to annotate.c and
renamed it to annotate_source_line.

gdb/ChangeLog:

* annotate.c: Add 'source.h' and 'objfiles.h' includes.
(annotate_source): Make static.
(annotate_source_line): Moved from source.c and renamed from
identify_source_line.  Update the return type.
* annotate.h (annotate_source): Delete declaration.
(annotate_source_line): Declaration moved from source.h, and
renamed from identify_source_line.  Return type updated.
* source.c (identify_source_line): Moved to annotate.c and renamed
to annotate_source_line.
(info_line_command): Remove check of annotation_level.
* source.h (identify_source_line): Move declaration to annotate.h
and rename to annotate_source_line.
* stack.c: Add 'annotate.h' include.
(print_frame_info): Remove check of annotation_level before
calling annotate_source_line.

4 years agogdb: New function to open source file and compute line charpos data
Andrew Burgess [Fri, 14 Jun 2019 21:16:52 +0000 (22:16 +0100)] 
gdb: New function to open source file and compute line charpos data

Every place that a symtab's line_charpos data is loaded always follows
the same pattern, so create a new function to contain this logic and
make use of it throughout GDB.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* source-cache.c (source_cache::get_plain_source_lines): Use
open_source_file_with_line_charpos instead of just
open_source_file, remove call to find_source_lines.
(source_cache::get_source_lines): Likewise.
* source.c (find_source_lines): Make static.
(get_filename_and_charpos): Renamed into...
(open_source_file_with_line_charpos): ..this along with changes to
return a scoped_fd, and some other minor clean ups.
(identify_source_line): Use open_source_file_with_line_charpos.
(search_command_helper): Use open_source_file_with_line_charpos
instead of just open_source_file, remove call to
find_source_lines.
* source.h (open_source_file_with_line_charpos): Declare new
function.
(find_source_lines): Delete declaration.

4 years agogdb: Remove unused parameter
Andrew Burgess [Fri, 14 Jun 2019 20:57:42 +0000 (21:57 +0100)] 
gdb: Remove unused parameter

The parameter 'fullname' is always passed as NULL to the function
get_filename_and_charpos in source.c, so lets remove the parameter.
There should be no user visible changes after this commit.

gdb/ChangeLog:

* source.c (get_filename_and_charpos): Remove fullname
parameter.
(identify_source_line): Update call to get_filename_and_charpos.

4 years agogdb: Remove file path from test name
Andrew Burgess [Fri, 14 Jun 2019 22:31:10 +0000 (23:31 +0100)] 
gdb: Remove file path from test name

Having paths in test names makes comparing sum files difficult, rename
a test to avoid paths in test names.

gdb/testsuite/ChangeLog:

* gdb.base/style-logging.exp: Remove path from test name.

4 years agoAutomatic date update in version.in
GDB Administrator [Sat, 15 Jun 2019 00:00:41 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoDo not emit style escape sequences to log file
Tom Tromey [Tue, 30 Apr 2019 17:17:15 +0000 (11:17 -0600)] 
Do not emit style escape sequences to log file

PR gdb/24502 requests that the "set logging" log file not contain
style escape sequences emitted by gdb.

This seemed like a reasonable request to me, so this patch implements
filtering for the log file.

This also updates a comment in ui-style.h that I noticed while writing
the patch.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

PR gdb/24502:
* ui-style.h (skip_ansi_escape): Update comment.
* ui-file.h (class no_terminal_escape_file): New class.
* ui-file.c (no_terminal_escape_file::write)
(no_terminal_escape_file::puts): New methods.
* cli/cli-logging.c (handle_redirections): Use
no_terminal_escape_file.

gdb/testsuite/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

PR gdb/24502:
* gdb.base/style-logging.exp: New file.

4 years agoMinor NEWS rearrangement
Tom Tromey [Fri, 14 Jun 2019 18:30:17 +0000 (12:30 -0600)] 
Minor NEWS rearrangement

I noticed that a NEWS item about Python scripting changes appeared
between an item about a convenience function and an item about a
convenience variable.  I think it's better for the latter to be next
to each other.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* NEWS: Move convenience variable news above Python news.

4 years agoMove gnulib to top level
Tom Tromey [Sun, 5 May 2019 23:35:20 +0000 (17:35 -0600)] 
Move gnulib to top level

This patch moves the gdb/gnulib subdirectory to the top level.

It adjusts the top-level build system to build gnulib when necessary,
and changes gdb to use this.  However, gdbserver still builds its own
copy of gnulib, just from the new source location.

A small hack was needed to ensure that gnulib is only built when gdb
is enabled.  The Makefile only provides an ordering -- the directory
must be mentioned in configdirs to actually be compiled at all.

Most of the patch is just a "git mv" of gnulib, though a few minor
path adjustments were needed in some files there.

Tested by the buildbot.

ChangeLog
2019-06-14  Tom Tromey  <tom@tromey.com>

* MAINTAINERS: Add gnulib.
* gnulib: New directory, move from gdb/gnulib.
* configure.ac (host_libs): Add gnulib.
* configure: Rebuild.
* Makefile.def (host_modules, dependencies): Add gnulib.
* Makefile.in: Rebuild.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tom@tromey.com>

* gnulib: Move directory to top-level.
* configure.ac: Don't configure gnulib.
* configure: Rebuild.
* common/common-defs.h: Use new path to gnulib.
* Makefile.in (GNULIB_BUILDDIR): Now ../gnulib.
(GNULIB_H): Remove.
(INCGNU): Look in new gnulib location.
(HFILES_NO_SRCDIR): Remove gnulib files.
(SUBDIR, REQUIRED_SUBDIRS): Remove gnulib.
(generated_files): Remove GNULIB_H.
($(LIBGNU), all-lib): Remove targets.
(distclean): Don't mention GNULIB_BUILDDIR.
($(GNULIB_BUILDDIR)/Makefile): Remove target.

gdb/gdbserver/ChangeLog
2019-06-14  Tom Tromey  <tom@tromey.com>

* configure.ac: Use new path to gnulib.
* configure: Rebuild.
* Makefile.in (INCGNU, $(GNULIB_BUILDDIR)/Makefile): Use new path
to gnulib.

gnulib/ChangeLog
2019-06-14  Tom Tromey  <tom@tromey.com>

* update-gnulib.sh: Adjust paths.
* Makefile.in: Adjust paths.
* configure.ac: Adjust paths.  Use ACX_LARGEFILE.
* configure: Rebuild.

4 years agoWarn if add-symbol-file does not provide any symbols
Tom Tromey [Tue, 4 Jun 2019 19:35:44 +0000 (13:35 -0600)] 
Warn if add-symbol-file does not provide any symbols

A user suggested that add-symbol-file ought to warn if the file does
not in fact provide any symbols.  This seemed like a decent idea, so
this patch implements this idea.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* symfile.c (add_symbol_file_command): Remove obsolete comment.
Warn if symbol file does not provide any symbols.

gdb/testsuite/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* gdb.base/symfile-warn.exp: New file.
* gdb.base/symfile-warn.c: New file.

4 years agoOnly compute realpath when basenames_may_differ is set
Tom Tromey [Thu, 30 May 2019 16:59:03 +0000 (10:59 -0600)] 
Only compute realpath when basenames_may_differ is set

A user noted that, when sources are symlinked, gdb annotations will
print the real path, rather than the name of the symlink.

It seems to me that it is better to print the name of the file that
was actually used in the build, unless there is some reason not to.

This patch implements this, with the caveat that it will not work when
basenames-may-differ is enabled.  The way this mode is currently
implemented, returning the symbolic (not real) path is not possible.

While I think it would be good to redo the source file name cache and
perhaps integrate it with class source_cache, I haven't done so here.

Regression tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* source.c (find_and_open_source): Respect basenames_may_differ.

gdb/testsuite/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* gdb.base/annotate-symlink.exp: New file.

4 years agogdb: Use scoped_restore_terminal_state in annotate.c
Andrew Burgess [Thu, 13 Jun 2019 21:13:28 +0000 (22:13 +0100)] 
gdb: Use scoped_restore_terminal_state in annotate.c

In a couple of places in annotate.c we are manually backing up and
restoring the terminal ownership, we could instead make use of
scoped_restore_terminal_state.

gdb/ChangeLog:

* annotate.c (annotate_breakpoints_invalid): Make use of
scoped_restore_terminal_state.
(annotate_frames_invalid): Likewise.

4 years agoAllow re-assigning to convenience variables
Tom Tromey [Wed, 5 Jun 2019 16:53:16 +0000 (10:53 -0600)] 
Allow re-assigning to convenience variables

In Ada mode, re-assigning an array of a different size to a
convenience variable will cause an error:

    (gdb) set lang ada
    (gdb) set $v := "abc"
    (gdb) set $v := "abcd"
    cannot assign arrays of different length

However, this does not really make sense -- instead, it should always
be possible to overwrite a convenience variable.

This patch fixes this bug.

This was reviewed off-list by Joel.  I'm checking it in.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (ada_evaluate_subexp) <case BINOP_ASSIGN>: Always
allow assignment to an internalvar.

gdb/testsuite/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* gdb.ada/set_wstr.exp: Add reassignment test.

4 years agoRecognize _ in attribute names
Tom Tromey [Fri, 7 Jun 2019 17:29:36 +0000 (11:29 -0600)] 
Recognize _ in attribute names

Ada attribute names can contain "_", but the lexer currently does not
allow this -- even though the "attributes" array lists some attributes
spelled this way.

This patch fixes the bug and adds test cases for the existing
attributes.

This was reviewed off-list by Joel.  I'm checking it in.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* ada-lex.l: Allow "_" in attribute names.

gdb/testsuite/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

* gdb.ada/formatted_ref.exp (test_p_x_addr): Check
'unchecked_access and 'unrestricted_access as well.

4 years agoRemove alloca(0) calls
Tom Tromey [Tue, 11 Jun 2019 12:59:38 +0000 (06:59 -0600)] 
Remove alloca(0) calls

PR gdb/24653 points out that a gcc snapshot will complain about the
calls to alloca(0) in gdb.

These calls are only needed when using the C alloca.  I'm inclined to
think that no current platform needs this, so this patch removes the
calls.

Let me know what you think.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

PR gdb/24653:
* regcache.c (registers_changed): Don't call alloca.
* top.c (execute_command): Don't call alloca.

4 years agoFix gdb.ada/vla.exp
Tom Tromey [Wed, 29 May 2019 16:21:52 +0000 (10:21 -0600)] 
Fix gdb.ada/vla.exp

PR ada/24539 concerns a test failure in gdb.ada/vla.exp.

The problem here is that different versions of Gnat emit the
structure's fields in different orders -- with the order currently
failing actually being the correct one.

Joel pointed out that this can be fixed by simply adding the
No_Component_Reordering pragma to the type in question, which is what
this patch does.

I've reported a Gnat compiler bug internally in hopes of getting the
underlying problem fixed.

gdb/testsuite/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

PR ada/24539:
* gdb.ada/vla.exp: Update tests.
* gdb.ada/vla/vla.adb (Record_Type): Use No_Component_Reordering
pragma.

4 years agoAdd R_AARCH64_P32_MOVW_PREL_* ELF32 relocs
Szabolcs Nagy [Wed, 28 Nov 2018 19:35:04 +0000 (19:35 +0000)] 
Add R_AARCH64_P32_MOVW_PREL_* ELF32 relocs

These ilp32 relocations were missing for some reason.

bfd/ChangeLog:

* elfnn-aarch64.c: Enable MOVW_PREL relocs for ELF32.

include/ChangeLog:

* elf/aarch64.h (R_AARCH64_P32_MOVW_PREL_G0): Define.
(R_AARCH64_P32_MOVW_PREL_G0_NC): Define.
(R_AARCH64_P32_MOVW_PREL_G1): Define.

ld/ChangeLog:

* testsuite/ld-aarch64/aarch64-elf.exp: Add emit-relocs-22 and -23.
* testsuite/ld-aarch64/emit-relocs-22.d: New test.
* testsuite/ld-aarch64/emit-relocs-22.s: New test.
* testsuite/ld-aarch64/emit-relocs-23.d: New test.
* testsuite/ld-aarch64/emit-relocs-23.s: New test.

4 years agoUpdated French translation for the opcodes subdirectory.
Nick Clifton [Fri, 14 Jun 2019 10:43:53 +0000 (11:43 +0100)] 
Updated French translation for the opcodes subdirectory.

* po/fr.po; Updated French translation.

4 years agoRegenerate with approved autotools version
Alan Modra [Fri, 14 Jun 2019 01:00:35 +0000 (10:30 +0930)] 
Regenerate with approved autotools version

bfd/
* Makefile.in: Regenerate.
* configure: Regenerate.
binutils/
* Makefile.in: Regenerate.
* aclocal.m4: Regenerate.
* doc/Makefile.in: Regenerate.
gas/
* Makefile.in: Regenerate.
* configure: Regenerate.
* doc/Makefile.in: Regenerate.
ld/
* Makefile.in: Regenerate.
* configure: Regenerate.
libctf/
* configure: Regenerate.

4 years agoFix alpha testsuite regression
Alan Modra [Fri, 14 Jun 2019 00:53:20 +0000 (10:23 +0930)] 
Fix alpha testsuite regression

readelf st_other display improved for alpha.

PR 24662
* testsuite/ld-alpha/tlsbin.rd: Update.
* testsuite/ld-alpha/tlsbinr.rd: Update.
* testsuite/ld-alpha/tlspic.rd: Update.

4 years agoPowerPC comment fixes
Alan Modra [Fri, 14 Jun 2019 00:52:49 +0000 (10:22 +0930)] 
PowerPC comment fixes

"paddi rt,sym@pcrel" as an abbreviation for "paddi rt,0,sym@pcrel,1"
is invalid, so replace with "pla rt,sym@pcrel" which is a valid form
of "pla rt,sym@pcrel(0),1".

* elf64-ppc.c: Fix comments involving paddi.

4 years agoAutomatic date update in version.in
GDB Administrator [Fri, 14 Jun 2019 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoFix "set integer-command unlimited junk"
Pedro Alves [Thu, 13 Jun 2019 14:22:44 +0000 (15:22 +0100)] 
Fix "set integer-command unlimited junk"

With integer commands that support "unlimited", we currently fail to
notice junk after "unlimited":

 (gdb) show print elements
 Limit on string chars or array elements to print is 200.
 (gdb) set print elements unlimited foo
 (gdb) show print elements
 Limit on string chars or array elements to print is unlimited.

This commit fixes that.  After, we get:

 (gdb) set print elements unlimited foo
 Junk after "unlimited": foo

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-setshow.c (cli/cli-setshow.c): New parameter
'expression'.  When parsing an expression, error out if there's
junk after "unlimited".
(parse_cli_var_uinteger, parse_cli_var_zuinteger_unlimited)
(do_set_command): Adjust calls to is_unlimited_literal.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/settings.exp (test-integer): Test junk after
"unlimited".

4 years agosim/testsuite/or1k: Add tests for unordered compares
Stafford Horne [Thu, 13 Jun 2019 12:27:10 +0000 (21:27 +0900)] 
sim/testsuite/or1k: Add tests for unordered compares

Add tests for 32-bit and 64-bit unordered compare instructions.

sim/testsuite/sim/or1k/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

* fpu-unordered.S: New file.
* fpu64a32-unordered.S: New file.

4 years agosim/testsuite/or1k: Add test case for l.adrp instruction
Stafford Horne [Thu, 13 Jun 2019 12:27:10 +0000 (21:27 +0900)] 
sim/testsuite/or1k: Add test case for l.adrp instruction

This is a simple test to ensure that the l.adrp instruction can be assembled and
simulated correctly.

sim/testsuite/sim/or1k/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

* adrp.S: New file.

4 years agosim/testsuite/or1k: Add test for 64-bit fpu operations
Stafford Horne [Thu, 13 Jun 2019 12:27:10 +0000 (21:27 +0900)] 
sim/testsuite/or1k: Add test for 64-bit fpu operations

This is a very basic test but it ensure the machine is wired up
correctly and that the assembler works.

sim/testsuite/sim/or1k/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

* fpu64a32.S: New file.

4 years agosim/common: wire up new unordered comparisons
Stafford Horne [Thu, 13 Jun 2019 12:27:10 +0000 (21:27 +0900)] 
sim/common: wire up new unordered comparisons

Define and wire up unordered floating point comparison operations for cgen
targets.  This patch depends on my posted cgen patches[0].

[0] https://www.sourceware.org/ml/cgen/2019-q2/msg00013.html

sim/common/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

* cgen-accfp.c (unorderedsf, unordereddf): New functions.
(cgen_init_accurate_fpu): Wire up unorderedsf and unordereddf.
* cgen-fpu.h (cgen_fp_ops): Define fields unorderedsf and unordereddf.

4 years agosim/common: Wire in df/di conversion
Stafford Horne [Thu, 13 Jun 2019 12:27:10 +0000 (21:27 +0900)] 
sim/common: Wire in df/di conversion

Up until now these have not been used in any CGEN targets, add them as
they are now used by OpenRISC.

sim/common/ChangeLog:

* cgen-accfp.c (floatdidf, fixdfdi): New functions.
(cgen_init_accurate_fpu): Add floatdidf and fixdfdi.

4 years agosim/or1k: Regenerate sim
Stafford Horne [Thu, 13 Jun 2019 12:27:09 +0000 (21:27 +0900)] 
sim/or1k: Regenerate sim

This picks up changes for:

 - new orfpx64a32 spec
 - new unordered instructions
 - documentation and symbol updates

sim/ChangeLog:

* or1k/cpu.c: Regenerate.
* or1k/cpu.h: Regenerate.
* or1k/decode.c: Regenerate.
* or1k/decode.h: Regenerate.
* or1k/model.c: Regenerate.
* or1k/sem-switch.c: Regenerate.
* or1k/sem.c: Regenerate.

4 years agoFix gdb build with -std=gnu++11
Pedro Alves [Thu, 13 Jun 2019 07:58:54 +0000 (08:58 +0100)] 
Fix gdb build with -std=gnu++11

The options framework series broken the build with gcc 4.8, or any
other compiler were we end up forcing -std=gnu++11, causing errors
like these:

 ../../binutils-gdb/gdb/compile/compile.c: In function gdb::option::option_def_group make_compile_options_def_group(compile_options*):
 ../../binutils-gdb/gdb/compile/compile.c:266:44: error: could not convert (const gdb::option::option_def*)(& compile_command_option_defs) from const gdb::option::option_def* to gdb::array_view<const gdb::option::option_def>
    return {compile_command_option_defs, opts};
     ^
   CXX    copying.o
 ../../binutils-gdb/gdb/compile/compile.c:267:1: error: control reaches end of non-void function [-Werror=return-type]
  }
  ^

This is a C++11 vs C++14 difference -- C++14 relaxed the rules for
eliding braces.

This commit fixes it by adding the missing (in C++11) braces.  Tested
with g++ 4.8.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* compile/compile.c (make_compile_options_def_group): Add braces
around array_view initializer.
* thread.c (make_thread_apply_all_options_def_group)
(make_thread_apply_all_options_def_group): Likewise.

4 years agoAutomatic date update in version.in
GDB Administrator [Thu, 13 Jun 2019 00:00:38 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoNEWS and manual changes for command options changes
Pedro Alves [Wed, 12 Jun 2019 23:06:54 +0000 (00:06 +0100)] 
NEWS and manual changes for command options changes

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* NEWS (New commands): Mention "maint test-options
require-delimiter", "maint test-options unknown-is-error", "maint
test-options unknown-is-operand" and "maint show
test-options-completion-result".
(New command options, command completion): New section.
(Completion improvements): New section.
Mention that you can abbreviate "unlimited".

gdb/doc/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.texinfo (Command Completion): Mention command options too.
(Command Options): New node.
(Threads): Add anchors.  Extend descriptions of the "taas" and
"tfaas" commands.
(Backtrace): Describe new options of the "backtrace" command.  Add
anchors.
(Frame Apply): Describe new options of the "frame apply" and
"faas" commands.  Add anchors.
(Data): Describe new options of the "print" command.  Add anchors.
(Compiling and Injecting Code): Mention options of the "compile
print" command.
(Maintenance Commands): Mention "maint test-options" subcommands
and the "maint show test-options-completion-result" command.

4 years agoDelete parse_flags/parse_flags_qcs
Pedro Alves [Wed, 12 Jun 2019 23:06:54 +0000 (00:06 +0100)] 
Delete parse_flags/parse_flags_qcs

Now that "thread/frame apply" have been converted to the gdb::option
framework, these functions are no longer used.

For a while, I thought about keeping the unit tests, by making a local
version of parse_flags_qcs in the unit tests file.  But all that would
really test that is used by GDB itself, is the validate_flags_qcs
function.  So in the end, I went through all the unit tests, and
converted any that wasn't already covered to gdb.base/options.exp
tests.  And those have all already been added in previous patches.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-utils.c (parse_flags, parse_flags_qcs): Delete.
* cli/cli-utils.h (parse_flags, parse_flags_qcs): Delete.
* unittests/cli-utils-selftests.c (test_parse_flags)
(test_parse_flags_qcs): Delete.
(test_cli_utils): Don't call deleted functions.

4 years agoMake "thread apply" use the gdb::option framework
Pedro Alves [Wed, 12 Jun 2019 23:06:54 +0000 (00:06 +0100)] 
Make "thread apply" use the gdb::option framework

Similarly to the "frame apply" patch, this makes the "thread apply"
family of commands -- "thread apply TID", "thread apply all" and
"taas" use the gdb::option framework for '-'-style options.

No new options are added, but there are some user-visible changes:

- Can now abbreviate and complete "-ascending"

- We now have a completer for "thread apply" commands

  Can now complete options ("thread apply all -[TAB]"), and also,
  'thread apply all COMMAND[TAB]' now does what you'd expect, by
  making use of the new complete_command routine.

- "help" output tweaked with auto-generated option descriptions:

   ~~~
   Usage: thread apply all [OPTION]... COMMAND
   Prints per-inferior thread number and target system's thread id
   followed by COMMAND output.

   By default, an error raised during the execution of COMMAND
   aborts "thread apply".

   Options:
     -ascending
       Call COMMAND for all threads in ascending order.
       The default is descending order.

     -q
       Disables printing the thread information.

     -c
       Print any error raised by COMMAND and continue.

     -s
       Silently ignore any errors or empty output produced by COMMAND.
   ~~~

  The "By default ..." sentence is new as well.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* thread.c: Include "cli/cli-option.h".
(tp_array_compar_ascending): Global.
(tp_array_compar): Delete function.
(tp_array_compar_ascending, tp_array_compar_descending): New
functions.
(ascending_option_def, qcs_flag_option_def)
(thr_qcs_flags_option_defs)
(make_thread_apply_all_options_def_group)
(make_thread_apply_options_def_group): New.
(thread_apply_all_command): Use gdb::option::process_options.
(thread_apply_command_completer)
(thread_apply_all_command_completer): New.
(thread_apply_command): Use gdb::option::process_options.
(_initialize_thread): Delete THREAD_APPLY_FLAGS_HELP, replace it
with a new THREAD_APPLY_OPTION_HELP.  Use gdb::option::build_help
to generate help text of "thread apply".  Adjust "taas"'s help.
* tid-parse.c (tid_range_parser::in_thread_range): New method.
* tid-parse.h (tid_range_parser::in_thread_range): New method.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/options.exp (test-thread-apply): New.
(top level): Call it.

4 years ago"thread apply 1 -- -" vs "frame apply level 0 -- -"
Pedro Alves [Wed, 12 Jun 2019 23:06:54 +0000 (00:06 +0100)] 
"thread apply 1 -- -" vs "frame apply level 0 -- -"

With the following patch, we'll be able to explicitly tell "thread
apply" where options end, using the "--" delimiter.  A test added by
that patch caught a pre-existing inconsistency:

 (gdb) thread apply 1 -- -
 Invalid thread ID: -

 (gdb) frame apply level 0 -- -
 #0  main () at threads.c:55
 Cannot enable the TUI when output is not a terminal

Above, "thread apply" did not try to run the command, while "frame
apply level" did.  ("-" is a valid TUI command.)

That "-" is past "--", so it should have not been confused with an
invalid TID, in the "thread apply" case.

That error actually doesn't come from the TID parser, but instead from
thread_apply_command directly.

So that error/check needs tweaking.  The next question is what to
tweak it to.

"-" is actually a valid TUI command:

 (gdb) help -
 Scroll window backward.
 Usage: - [WIN] [N]

(gdb) frame apply level 0 -- -
#0  main () at threads.c:55
Cannot enable the TUI when output is not a terminal

While I don't imagine it being useful to use that "-" command with
"thread apply" or "frame apply level", the fact is that you can use it
with "frame apply level", but not with "thread apply".  And since it's
an actual command, pedantically it seems right to allow it.

That's what this commit does.

Note: simply removing the "isalpha" check regresses
gdb.multi/tids.exp -- see related commit 3f5b7598805c.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* thread.c (thread_apply_command): Check for invalid TID with
isdigit instead of !isalpha.

4 years agoMake "frame apply" support -OPT options
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
Make "frame apply" support -OPT options

This adds support for '-'-style options to the "frame apply" family of
commands -- "frame apply COUNT", "frame apply level", "frame apply
all", "faas" and "tfaas".

The -q/-c/-s flags were already supported, -past-main/-past-entry is
new:

~~~
(gdb) help frame apply all
Apply a command to all frames.

Usage: frame apply all [OPTION]... COMMAND
Prints the frame location information followed by COMMAND output.

By default, an error raised during the execution of COMMAND
aborts "frame apply".

Options:
  -q
    Disables printing the frame location information.

  -c
    Print any error raised by COMMAND and continue.

  -s
    Silently ignore any errors or empty output produced by COMMAND.

  -past-main [on|off]
    Set whether backtraces should continue past "main".
    Normally the caller of "main" is not of interest, so GDB will terminate
    the backtrace at "main".  Set this if you need to see the rest
    of the stack trace.

  -past-entry [on|off]
    Set whether backtraces should continue past the entry point of a program.
    Normally there are no callers beyond the entry point of a program, so GDB
    will terminate the backtrace there.  Set this if you need to see
    the rest of the stack trace.
~~~

TAB completion of options is now supported.  Also, TAB completion of
COMMAND in "frame apply all COMMAND" does the right thing now, making
use of complete_command, added by the previous patch.  E.g.:

 (gdb) thread apply all -ascending frame apply all -past-main print -[TAB]
 -address         -elements        -pretty          -symbol
 -array           -null-stop       -repeats         -union
 -array-indexes   -object          -static-members  -vtbl
 (gdb) thread apply all -ascending frame apply all -past-main print glo[TAB]
 global1         global2

The change to tfaas_command is necessary because otherwise you get
this:

 (gdb) tfaas --
 Unrecognized option at: frame apply all -s --

That's because the above is equivalent to:

 (gdb) thread apply all -s frame apply all -s --

and the "--" instructs "thread apply" to consider everything up to
"--" as its command options.  And from that view, "frame" is an
invalid option.

The change makes tfaas be equivalent to:

 (gdb) thread apply all -s -- frame apply all -s --

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-utils.c (parse_flags_qcs): Use validate_flags_qcs.
(validate_flags_qcs): New.
* cli/cli-utils.h (struct qcs_flags): Change field types to int.
(validate_flags_qcs): Declare.
* stack.c (qcs_flag_option_def, fr_qcs_flags_option_defs): New.
(make_frame_apply_options_def_group): New.
(frame_apply_command_count): Process options with
gdb::option::process_options.
(frame_apply_completer): New.
(frame_apply_level_completer, frame_apply_all_completer)
(frame_apply_completer): New.
(_initialize_stack): Update help of "frame apply", "frame apply
level", "frame apply all" and "faas" to mention supported options
and install command completers.
* stack.h (frame_apply_all_completer): Declare.
* thread.c: Include "stack.h".
(tfaas_command): Add "--".
(_initialize_thread): Update help "tfaas" to mention supported
options and install command completer.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/options.exp (test-frame-apply): New.
(top level): Test print commands with different "frame apply"
prefixes.

4 years agoIntroduce complete_nested_command_line
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
Introduce complete_nested_command_line

This adds a completion helper routine that makes it possible for a
command that takes another command as argument, such as "frame apply
all COMMAND" as "thread apply all COMMAND", to complete on COMMAND,
and have the completion machinery recurse and complete COMMAND as if
you tried to complete "(gdb) COMMAND".  I.e., we'll be able to
complete like this, for example:

 (gdb) thread apply all -[TAB]
 -c           -ascending   -q           -s
 (gdb) thread apply all -ascending frame apply all -[TAB]
 -c           -limit       -past-entry  -past-main   -q           -s
 (gdb) thread apply all -ascending frame apply all -past-main print -[TAB]
 -address         -elements        -pretty          -symbol
 -array           -null-stop       -repeats         -union
 -array-indexes   -object          -static-members  -vtbl
 (gdb) thread apply all -ascending frame apply all -past-main print glo[TAB]
 global1         global2

Above, the completer function understands that "thread apply all" is a
command, and then parses "-ascending" successfully and understand that
the rest of the string is "thread apply all"'s operand.  And then, the
process repeats for the "frame apply" command, and on and on.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* completer.c (complete_nested_command_line): New.
(gdb_completion_word_break_characters_throw): Add assertion.
* completer.h (complete_nested_command_line): Declare.

4 years agolib/completion-support.exp: Add test_gdb_completion_offers_commands
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
lib/completion-support.exp: Add test_gdb_completion_offers_commands

This adds a procedure to the collection of completion-testing
routines, that allows checking whether completion offers all commands
as completion candidates.  This will be used for testing completing
"frame apply all [TAB]", "thread apply all [TAB]", etc.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

        * lib/completion-support.exp (test_gdb_complete_tab_multiple)
(test_gdb_complete_cmd_multiple, test_gdb_complete_multiple): Add
'max_completions' parameter and handle it.
(test_gdb_completion_offers_commands): New.

4 years ago"backtrace full/no-filters/hide" completer
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
"backtrace full/no-filters/hide" completer

"backtrace"'s completer now completes on command options:

 (gdb) bt -[TAB]
 -entry-values         -full                 -no-filters           -past-main
 -frame-arguments      -hide                 -past-entry           -raw-frame-arguments

But it doesn't know how to complete on qualifiers:

 (gdb) bt fu[TAB]
 funlockfile       futimens          futimes.c
 funlockfile.c     futimens.c        futimesat
 futex-internal.h  futimes           futimesat.c

This commit fixes that:

 (gdb) bt fu[TAB]ll
 (gdb) bt n[TAB]o-filters
 (gdb) bt h[TAB]ide

I considered teaching the gdb::option framework to handle non-'-'
options, but decided it wasn't worth it for this special case, and I'd
rather not make it easy to add new qualifier-like options.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* stack.c (parse_backtrace_qualifiers): New.
(backtrace_command): Use it.
(backtrace_command_completer): Complete on qualifiers.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/options.exp (test-backtrace): Test completing qualifiers.

4 years agoMake "backtrace" support -OPT options
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
Make "backtrace" support -OPT options

This adds support for comand options to the "backtrace" command.  We'll get:

  (gdb) bt -
  -entry-values         -hide                 -past-main
  -frame-arguments      -no-filters           -raw-frame-arguments
  -full                 -past-entry

~~~~
(gdb) help backtrace
Print backtrace of all stack frames, or innermost COUNT frames.
Usage: backtrace [OPTION]... [QUALIFIER]... [COUNT | -COUNT]

Options:
  -entry-values no|only|preferred|if-needed|both|compact|default
    Set printing of function arguments at function entry
    GDB can sometimes determine the values of function arguments at entry,
    in addition to their current values.  This option tells GDB whether
    to print the current value, the value at entry (marked as val@entry),
    or both.  Note that one or both of these values may be <optimized out>.

  -frame-arguments all|scalars|none
    Set printing of non-scalar frame arguments

  -raw-frame-arguments [on|off]
    Set whether to print frame arguments in raw form.
    If set, frame arguments are printed in raw form, bypassing any
    pretty-printers for that value.

  -past-main [on|off]
    Set whether backtraces should continue past "main".
    Normally the caller of "main" is not of interest, so GDB will terminate
    the backtrace at "main".  Set this if you need to see the rest
    of the stack trace.

  -past-entry [on|off]
    Set whether backtraces should continue past the entry point of a program.
    Normally there are no callers beyond the entry point of a program, so GDB
    will terminate the backtrace there.  Set this if you need to see
    the rest of the stack trace.

  -full
    Print values of local variables.

  -no-filters
    Prohibit frame filters from executing on a backtrace.

  -hide
    Causes Python frame filter elided frames to not be printed.

For backward compatibility, the following qualifiers are supported:

   full       - same as -full option.
   no-filters - same as -no-filters option.
   hide       - same as -hide.

With a negative COUNT, print outermost -COUNT frames.
~~~~

Implementation wise, this:

- Moves relevant options/settings globals to structures.
- Tweaks a number of functions to pass down references to such structures.
- Adds option_def structures describing the options/settings.
- Makes backtrace_command parse the options, with gdb::option::process_options.
- Tweaks "backtrace"'s help to describe the new options.
- Adds testcases.

Note that backtrace is a PROCESS_OPTIONS_UNKNOWN_IS_OPERAND command,
because of the "-COUNT" argument.

The COUNT/-COUNT argument is currently parsed as an expression.  I
considered whether it would be prudent here to require "--", but
concluded that the risk of causing a significant breakage here is much
lower compared to "print", since printing the expression is not the
whole point of the "backtrace" command.  Seems OK to me to require
typing "backtrace -past-main -- -p" if the user truly wants to refer
to the negative of a backtrace count stored in an inferior variable
called "p".

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* frame.c: Include "cli/cli-option.h.
(user_set_backtrace_options): New.
(backtrace_past_main, backtrace_past_entry, backtrace_limit):
Delete.
(get_prev_frame): Adjust.
(boolean_option_def, uinteger_option_def)
(set_backtrace_option_defs): New.
(_initialize_frame): Adjust and use
gdb::option::add_setshow_cmds_for_options to install "set
backtrace past-main" and "set backtrace past-entry".
* frame.h: Include "cli/cli-option.h".
(struct frame_print_options): Forward declare.
(print_frame_arguments_all, print_frame_arguments_scalars)
(print_frame_arguments_none): Declare.
(print_entry_values): Delete declaration.
(struct frame_print_options, user_frame_print_options): New.
(struct set_backtrace_options): New.
(set_backtrace_option_defs, user_set_backtrace_options): Declare.
* mi/mi-cmd-stack.c (mi_cmd_stack_list_frames)
(mi_cmd_stack_list_locals, mi_cmd_stack_list_args)
(mi_cmd_stack_list_variables): Pass down USER_FRAME_PRINT_OPTIONS.
(list_args_or_locals): Add frame_print_options parameter.
(mi_cmd_stack_info_frame): Pass down USER_FRAME_PRINT_OPTIONS.
* python/py-framefilter.c (enumerate_args): Pass down
USER_FRAME_PRINT_OPTIONS.
* stack.c: Include "cli/cli-option.h".
(print_frame_arguments_all, print_frame_arguments_scalars)
(print_frame_arguments_none): Declare.
(print_raw_frame_arguments, print_entry_values): Delete.
(user_frame_print_options): New.
(boolean_option_def, enum_option_def, frame_print_option_defs):
New.
(struct backtrace_cmd_options): New.
(bt_flag_option_def): New.
(backtrace_command_option_defs): New.
(print_stack_frame): Pass down USER_FRAME_PRINT_OPTIONS.
(print_frame_arg, read_frame_arg, print_frame_args)
(print_frame_info, print_frame): Add frame_print_options parameter
and use it.
(info_frame_command_core): Pass down USER_FRAME_PRINT_OPTIONS.
(backtrace_command_1): Add frame_print_options and
backtrace_cmd_options parameters and use them.
(make_backtrace_options_def_group): New.
(backtrace_command): Process command options with
gdb::option::process_options.
(backtrace_command_completer): New.
(_initialize_stack): Extend "backtrace"'s help to mention
supported options.  Install completer for "backtrace".
Install some settings commands with add_setshow_cmds_for_options.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/options.exp (test-backtrace): New.
(top level): Call it.

4 years ago"set print raw frame-arguments" -> "set print raw-frame-arguments"
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
"set print raw frame-arguments" -> "set print raw-frame-arguments"

A following patch will introduce options for the "backtrace" command,
based on some "set print" and "set backtrace" settings.  There's one
setting in particular that is a bit annoying if we want to describe
the backtrace options and the settings commands using the same data
structures:

  "set print raw frame-arguments"

The problem is that space between "raw" and "frame-arguments".

Calling the option

  "bt -raw frame-arguments"

would be odd.  So I'm calling the option

  "bt -raw-frame-arguments"

instead.

And for consistency, this patch renames the set/show commands to:

 "set print raw-frame-arguments"
 "show print raw-frame-arguments"

I.e., dash instead of space.  The old commands are left in place, but
marked deprecated.

We need to adjust a couple testcases, because the relevant tests use
gdb_test_no_output and the old commands are no longer silent:

  (gdb) set print raw frame-arguments on
  Warning: command 'set print raw frame-arguments' is deprecated.
  Use 'set print raw-frame-arguments'.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* NEWS (Changed commands): Mention set/show print raw-frame-arguments,
and that "set/show print raw frame-arguments" are now deprecated.

* cli/cli-decode.c (add_setshow_boolean_cmd): Now returns the
command.
* command.h (add_setshow_boolean_cmd): Return cmd_list_element *.
* stack.c (_initialize_stack): Install "set/show print
raw-frame-arguments", and deprecate "set/show print raw
frame-arguments".
* valprint.c (_initialize_valprint): Deprecate "set/show print
raw".

gdb/doc/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.texinfo (Print Settings): Document "set/show print
raw-frame-arguments" instead of "set/show print raw
frame-arguments".

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.guile/scm-frame-args.exp: Use "set print
raw-frame-arguments" instead of "set print raw frame-arguments".
* gdb.python/py-frame-args.exp: Likewise.

4 years agoMigrate rest of compile commands to new options framework
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
Migrate rest of compile commands to new options framework

As I was in the neighbourhood, I converted the other "compile"
subcommands to the new options framework too.  Specifically, "compile
code" and "compile file".

The user-visible changes are:

  - All abbreviations of "-raw" are accepted now, instead of just -r.
    Obviously that means "-ra" is now accepted.

  - Option completion now works.

  - "compile file" did not have a completer yet, and now it knows to
    complete on filenames.

  - You couldn't use "compile file" with a file named "-something".
    You can now, with "compile file -- -something".

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* compile/compile.c (struct compile_options): New.
(compile_flag_option_def, compile_command_option_defs)
(make_compile_options_def_group): New.
(compile_file_command): Handle options with
gdb::option::process_options.
(compile_file_command_completer): New function.
(compile_code_command): Handle options with
gdb::option::process_options.
(compile_code_command_completer): New function.
(_initialize_compiler): Install completers for "compile code" and
"compile file".  Mention available options in "compile code" and
"compile code"'s help.
* completer.c (advance_to_completion_word): New, factored out from
...
(advance_to_expression_complete_word_point): ... this.
(advance_to_filename_complete_word_point): New.
* completer.h (advance_to_filename_complete_word_point): New
declaration.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.compile/compile.exp: Adjust expected output to option
processing changes.

4 years agoMake "print" and "compile print" support -OPT options
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
Make "print" and "compile print" support -OPT options

This patch adds support for "print -option optval --", etc.
Likewise for "compile print".

We'll get:

~~~~~~
(gdb) help print
Print value of expression EXP.
Usage: print [[OPTION]... --] [/FMT] [EXP]

Options:
  -address [on|off]
    Set printing of addresses.

  -array [on|off]
    Set pretty formatting of arrays.

  -array-indexes [on|off]
    Set printing of array indexes.

  -elements NUMBER|unlimited
    Set limit on string chars or array elements to print.
    "unlimited" causes there to be no limit.

  -max-depth NUMBER|unlimited
    Set maximum print depth for nested structures, unions and arrays.
    When structures, unions, or arrays are nested beyond this depth then they
    will be replaced with either '{...}' or '(...)' depending on the language.
    Use "unlimited" to print the complete structure.

  -null-stop [on|off]
    Set printing of char arrays to stop at first null char.

  -object [on|off]
    Set printing of C++ virtual function tables.

  -pretty [on|off]
    Set pretty formatting of structures.

  -repeats NUMBER|unlimited
    Set threshold for repeated print elements.
    "unlimited" causes all elements to be individually printed.

  -static-members [on|off]
    Set printing of C++ static members.

  -symbol [on|off]
    Set printing of symbol names when printing pointers.

  -union [on|off]
    Set printing of unions interior to structures.

  -vtbl [on|off]
    Set printing of C++ virtual function tables.

Note: because this command accepts arbitrary expressions, if you
specify any command option, you must use a double dash ("--")
to mark the end of option processing.  E.g.: "print -o -- myobj".
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I want to highlight the comment above about "--".

At first, I thought we could make the print command parse the options,
and if the option wasn't recognized, fallback to parsing as an
expression.  Then, if the user wanted to disambiguate, he'd use the
"--" option delimiter.  For example, if you had a variable called
"object" and you wanted to print its negative, you'd have to do:

  (gdb) print -- -object

After getting that working, I saw that gdb.pascal/floats.exp
regressed, in these tests:

 gdb_test "print -r" " = -1\\.2(499.*|5|500.*)"
 gdb_test "print -(r)" " = -1.2(499.*|5|500.*)"
 gdb_test "print -(r + s)" " = -3\\.4(499.*|5|500.*)"

It's the first one that I found most concerning.  It regressed because
"-r" is the abbreviation of "-raw".  I realized then that the behavior
change was a bit risker than I'd like, considering scripts, wrappers
around gdb, etc., and even user expectation.  So instead, I made the
print command _require_ the "--" options delimiter if you want to
specify any option.  So:

  (gdb) print -r

is parsed as an expression, and

  (gdb) print -r --

is parsed as an option.

I noticed that that's also what lldb's expr (the equivalent of print)
does to handle the same problem.

Going back the options themselves, note that:

 - you can shorten option names, as long as unambiguous.
 - For boolean options, 0/1 stand for off/on.
 - For boolean options, "true" is implied.

So these are all equivalent:

 (gdb) print -object on -static-members off -pretty on -- foo
 (gdb) print -object -static-members off -pretty -- foo
 (gdb) print -object -static-members 0 -pretty -- foo
 (gdb) print -o -st 0 -p -- foo

TAB completion is fully supported:

  (gdb) p -[TAB]
  -address         -elements        -pretty          -symbol
  -array           -null-stop       -repeats         -union
  -array-indexes   -object          -static-members  -vtbl

Note that the code is organized such that some of the options and the
"set/show" commands code is shared.  In particular, the "print"
options and the corresponding "set print" commands are defined with
the same structures.  The commands are installed with the
gdb::option::add_setshow_cmds_for_options function.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* compile/compile.c: Include "cli/cli-option.h".
(compile_print_value): Scope data pointer is now a
value_print_options pointer; adjust.
(compile_print_command): Process options.  Scope data pointer is
now a value_print_options pointer; adjust.
(_initialize_compile): Update "compile print"'s help to include
supported options.  Install a completer for "compile print".
* cp-valprint.c (show_vtblprint, show_objectprint)
(show_static_field_print): Delete.
(_initialize_cp_valprint): Don't install "set print
static-members", "set print vtbl", "set print object" here.
* printcmd.c: Include "cli/cli-option.h" and
"common/gdb_optional.h".
(print_command_parse_format): Rework to fill in a
value_print_options instead of a format_data.
(print_value): Change parameter type from format_data pointer to
value_print_options reference.  Adjust.
(print_command_1): Process options.  Adjust to pass down a
value_print_options.
(print_command_completer): New.
(_initialize_printcmd): Install print_command_completer as
handle_brkchars completer for the "print" command.  Update
"print"'s help to include supported options.
* valprint.c: Include "cli/cli-option.h".
(show_vtblprint, show_objectprint, show_static_field_print): Moved
here from cp-valprint.c.
(boolean_option_def, uinteger_option_def)
(value_print_option_defs, make_value_print_options_def_group):
New.  Use gdb::option::add_setshow_cmds_for_options to install
"set print elements", "set print null-stop", "set print repeats",
"set print pretty", "set print union", "set print array", "set
print address", "set print symbol", "set print array-indexes".
* valprint.h: Include <string> and "cli/cli-option.h".
(make_value_print_options_def_group): Declare.
(print_value): Change parameter type from format_data pointer to
value_print_options reference.
(print_command_completer): Declare.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/options.exp: Build executable.
(test-print): New procedure.
(top level): Call it, once for "print" and another for "compile
print".

4 years agoIntroduce generic command options framework
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
Introduce generic command options framework

This commit adds a generic command options framework, that makes it
easy enough to add '-'-style options to commands in a uniform way,
instead of each command implementing option parsing in its own way.

Options are defined in arrays of option_def objects (for option
definition), and the same options definitions are used for supporting
TAB completion, and also for generating the relevant help fragment of
the "help" command.  See the gdb::options::build_help function, which
returns a string with the result of replacing %OPTIONS% in a template
string with an auto-generated "help" string fragment for all the
passed-in options.

Since most options in GDB are in the form of "-OPT", with a single
dash, this is the format that the framework supports.

I like to think of gdb's "-OPT" as the equivalent to getopt's long
options format ("--OPT"), and gdb's "/" as the equivalent to getopt's
short options format.  getopt's short options format allows mixing
several one-character options, like "ls -als", kind of similar to
gdb's "x /FMT" and "disassemble /MOD", etc.  While with gdb's "-"
options, the option is expected to have a full name, and to be
abbreviatable.  E.g., "watch -location", "break -function main", etc.

This patch only deals with "-" options.  The above comment serves more
to disclose why I don't think we should support mixing several
unrelated options in a single "-" option invocation, like "thread
apply -qcs" instead of "thread apply -q -c -s".

The following patches will add uses of the infrastructure to several
key commands.  Most notably, "print", "compile print", "backtrace",
"frame apply" and "thread apply".  I tried to add options to several
commands in order to make sure the framework didn't leave that many
open holes open.

Options use the same type as set commands -- enum var_types.  So
boolean options are var_boolean, enum options are var_enum, etc.  The
idea is to share code between settings commands and command options.
The "print" options will be based on the "set print" commands, and
their names will be the same.  Actually, their definitions will be the
same too.  There is a function to create "set/show" commands from an
array for option definitions:

 /* Install set/show commands for options defined in OPTIONS.  DATA is
    a pointer to the structure that holds the data associated with the
    OPTIONS array.  */
 extern void add_setshow_cmds_for_options (command_class cmd_class, void *data,
   gdb::array_view<const option_def> options,
   struct cmd_list_element **set_list,
   struct cmd_list_element **show_list);

That will be used by several following patches.

Other features:

 - You can use the "--" delimiter to explicitly indicate end of
   options.  Several existing commands use this token sequence for
   this effect already, so this just standardizes it.

 - You can shorten option names, as long as unambiguous.  Currently,
   some commands allow this (e.g., break -function), while others do
   not (thread apply all -ascending).  As GDB allows abbreviating
   command names and other things, it feels more GDB-ish to allow
   abbreviating option names too, to me.

 - For boolean options, 0/1 stands for off/on, just like with boolean
   "set" commands.

 - For boolean options, "true" is implied, just like with boolean "set
   commands.

These are the option types supported, with a few examples:

 - boolean options (var_boolean).  The option's argument is optional.

   (gdb) print -pretty on -- *obj
   (gdb) print -pretty off -- *obj
   (gdb) print -p -- *obj
   (gdb) print -p 0 -- *obj

 - flag options (like var_boolean, but no option argument (on/off))

   (gdb) thread apply all -s COMMAND

 - enum options  (var_enum)

   (gdb) bt -entry-values compact
   (gdb) bt -e c

 - uinteger options (var_uinteger)

   (gdb) print -elements 100 -- *obj
   (gdb) print -e 100 -- *obj
   (gdb) print -elements unlimited -- *obj
   (gdb) print -e u -- *obj

 - zuinteger-unlimited options (var_zuinteger_unlimited)

   (gdb) print -max-depth 100 -- obj
   (gdb) print -max-depth -1 -- obj
   (gdb) print -max-depth unlimited -- obj

Other var_types could be supported, of course.  These were just the
types that I needed for the commands that I ported over, in the
following patches.

It was interesting (and unfortunate) to find that we need at least 3
different modes to cover the existing commands:

- Commands that require ending options with "--" if you specify any
  option: "print" and "compile print".

- Commands that do not want to require "--", and want to error out if
  you specify an unknown option (i.e., an unknown argument that starts
  with '-'): "compile code" / "compile file".

- Commands that do not want to require "--", and want to process
  unknown options themselves: "bt", because of "bt -COUNT",
  "thread/frame apply", because "-" is a valid command.

The different behavior is encoded in the process_options_mode enum,
passed to process_options/complete_options.

For testing, this patch adds one representative maintenance command
for each of the process_options_mode values, that are used by the
testsuite to exercise the options framework:

 (gdb) maint test-options require-delimiter
 (gdb) maint test-options unknown-is-error
 (gdb) maint test-options unknown-is-operand

and adds another command to help with TAB-completion testing:

 (gdb) maint show test-options-completion-result

See their description at the top of the maint-test-options.c file.

Docs/NEWS are in a patch later in the series.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* Makefile.in (SUBDIR_CLI_SRCS): Add cli/cli-option.c.
(COMMON_SFILES): Add maint-test-settings.c.
* cli/cli-decode.c (boolean_enums): New global, factored out from
...
(add_setshow_boolean_cmd): ... here.
* cli/cli-decode.h (boolean_enums): Declare.
* cli/cli-option.c: New file.
* cli/cli-option.h: New file.
* cli/cli-setshow.c (parse_cli_boolean_value(const char **)): New,
factored out from ...
(parse_cli_boolean_value(const char *)): ... this.
(is_unlimited_literal): Change parameter type to pointer to
pointer.  Adjust and advance ARG pointer.
(parse_cli_var_uinteger, parse_cli_var_zuinteger_unlimited)
(parse_cli_var_enum): New, factored out from ...
(do_set_command): ... this.  Adjust.
* cli/cli-setshow.h (parse_cli_boolean_value)
(parse_cli_var_uinteger, parse_cli_var_zuinteger_unlimited)
(parse_cli_var_enum): Declare.
* cli/cli-utils.c: Include "cli/cli-option.h".
(get_ulongest): New.
* cli/cli-utils.h (get_ulongest): Declare.
(check_for_argument): New overloads.
* maint-test-options.c: New file.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/options.c: New file.
* gdb.base/options.exp: New file.

4 years agonumber_or_range_parser::get_number, don't treat "1 -" as a range
Pedro Alves [Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)] 
number_or_range_parser::get_number, don't treat "1 -" as a range

While adding -OPT options to "frame apply level", I noticed that:

 (gdb) frame apply level 0 -[TAB]

wasn't completing on the supported options.  This commit fixes it.
We'll get instead:

  (gdb) frame apply level 0 -
  -c           -past-entry  -past-main   -q           -s

I added the isspace check because this case:

  (gdb) frame apply level 0-

can't be an option.

Tests for this will be in a new gdb.base/options.exp file, in a
following patch.  It will exercise all of:

  (gdb) frame apply level 0-
  (gdb) frame apply level 0 -
  (gdb) frame apply level 0 --
  (gdb) frame apply level 0 -- -

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-utils.c (number_or_range_parser::get_number): Do not
parse a range if "-" is at the end of the string.

4 years agoboolean/auto-boolean commands, make "o" ambiguous
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
boolean/auto-boolean commands, make "o" ambiguous

We currently accept "o" with boolean/auto-boolean commands, taking it
to mean "on".  But "o" is ambiguous, between "on" and "off".  I can't
imagine why assuming the user wanted to type "on" is a good idea, it
might have been a typo.

This commit makes gdb error out.  We now get:

 (gdb) maint test-settings set boolean o
 "on" or "off" expected.

 (gdb) maint test-settings set auto-boolean o
 "on", "off" or "auto" expected.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-setshow.c (parse_auto_binary_operation)
(parse_cli_boolean_value): Don't allow "o".

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/settings.exp (test-boolean, test-auto-boolean): Check
that "o" is ambiguous.

4 years agoNew set/show testing framework (gdb.base/settings.exp)
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
New set/show testing framework (gdb.base/settings.exp)

This commit adds new representative commands for all types of settings
commands supported by gdb (enum var_types), and then uses them to
exercise settings parsing and completion.

  (gdb) maint test-settings s[TAB]
  set   show

  (gdb) maint test-settings set [TAB]
  auto-boolean         integer              uinteger
  boolean              optional-filename    zinteger
  enum                 string               zuinteger
  filename             string-noescape      zuinteger-unlimited

  (gdb) maint test-settings set enum [TAB]
  xxx  yyy  zzz

  etc.

This is basically unit testing, except that it goes fully via GDB.  It
must be done this way in order to exercise TAB completion properly,
which must go via readline.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* Makefile.in (COMMON_SFILES): Add maint-test-settings.c.
* NEWS: Mention maint test-settings KIND.
* maint-test-settings.c: New file.

gdb/doc/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.texinfo (Maintenance Commands): Document "maint
test-settings" commands.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/settings.c: New file.
* gdb.base/settings.exp: New file.

4 years agogdb.base/completion.exp: Fix comment typo
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
gdb.base/completion.exp: Fix comment typo

Noticed this while writing the following patch.  We cd to $srcdir, not $objdir.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.base/completion.exp: Fix comment typo.

4 years agoRemove "show" command completers, "set" command completers for string commands
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
Remove "show" command completers, "set" command completers for string commands

The default command completer is symbol_completer, but it makes no
sense for a "show" command to complete on symbols, or anything else,
really.

I wonder whether we should instead make the default be no completer.
That seems like a much larger/complicated audit/change, so I'd like to
move forward with this version, as it'll be covered by tests.  I
noticed this because a following patch will add a new
gdb.base/settings.exp testcase that exercises all sorts of details of
settings commands, including completing the show commands, using new
representative "maint test-settings <type or settings command>"
commands.

Also remove the completer for var_string and var_string_noescape
commands.  No point in completing symbols when GDB is expecting a
string.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-decode.c (add_setshow_cmd_full): Remove "show"
completer.
(add_setshow_string_cmd, add_setshow_string_noescape_cmd): Remove
"set" completers.

4 years agoFix "set enum-command value junk"
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
Fix "set enum-command value junk"

With enum commands, we currently fail to notice junk after the value.

Currently:

  (gdb) set print entry-values compact foo
  (gdb) show print entry-values foo
  Printing of function arguments at function entry is "compact".

After this fix:

 (gdb) set print entry-values compact foo
  Junk after item "compact": foo

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-setshow.c (do_set_command) <var_enum>: Detect junk
after item.

4 years agoAllow "unlimited" abbreviations
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
Allow "unlimited" abbreviations

Currently we can abbreviate "on/off/enable/disable/yes/no" in boolean
settings,

  (gdb) set non-stop of
  (gdb) set non-stop en

we can abbreviate the items of enumeration commands,

  (gdb) set print frame-arguments scal
  (gdb) set scheduler-locking rep

but we cannot abbreviate "unlimited" in integer commands.

 (gdb) set print elements u
 No symbol "u" in current context.

This commit fixes that.

Testcases will be in gdb.base/settings.exp and gdb.base/options.exp,
in following patches.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-setshow.c (is_unlimited_literal): Allow abbreviations.

4 years agoMake check_for_argument skip whitespace after arg itself
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
Make check_for_argument skip whitespace after arg itself

Basically every caller of check_for_argument needs to skip space after
the argument.  This patch makes check_for_argument do it itself.

Suggested by Philippe Waroquiers.

gdb/ChangeLog:
2019-06-13  Pedro Alves <palves@redhat.com>

* ax-gdb.c (agent_command_1): Remove skip_spaces call.
* breakpoint.c (watch_maybe_just_location): Remove skip_spaces
call.
* cli/cli-cmds.c (apropos_command): Remove skip_spaces call.
* cli/cli-utils.c (extract_info_print_args): Remove skip_spaces
calls.
(check_for_argument): Skip spaces after argument.

4 years agoFix TID parser bug
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
Fix TID parser bug

I noticed this inconsistency in the error messages below:

 (gdb) print --1
 Left operand of assignment is not an lvalue.

 (gdb) thread apply 1 print --1

 Thread 1 (Thread 0x7ffff7fb6740 (LWP 17805)):
 inverted range

The "inverted range" error happens because get_number_trailer returns
0 to indicate error, but number_or_range_parser::get_number is not
checking for that.  I tried detected the error there, but that doesn't
work because number_of_range_parser is used in places that _do_ want
to legitimately handle 0.  IMO we should fix get_number_trailer's
interface or use something else when we want to parse 0 too.

I've decided to fix it in a different way, similarly to how
number_or_range_parser::finished was changed in commit 529c08b25ec7
("Add helper functions parse_flags and parse_flags_qcs").

Seems like a good change, even if we tweaked
number_or_range_parser::get_number, as it simplifies
thread_apply_command and makes them consistent with
number_or_range_parser::finished().

We now get the same error message in both cases:

 (gdb) print --1
 Left operand of assignment is not an lvalue.

 (gdb) thread apply 1 print --1

 Thread 1 (Thread 0x7ffff7fb6740 (LWP 17805)):
 Left operand of assignment is not an lvalue.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* thread.c (thread_apply_command): Adjust TID parsing.
* tid-parse.c (tid_range_parser::finished): Ensure parsing end is
detected before end of string.
(tid_is_in_list): Error out if LIST is invalid.

gdb/testsuite/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* gdb.multi/tids.exp: Adjust expected output.  Add "thread apply 1
foo --1" test.

4 years agoFix latent bug with custom word point completers
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
Fix latent bug with custom word point completers

Completion routines that use a custom word point, and that then
recurse into complete_line (e.g., if we make "thread apply" a custom
word point completer, and complete on the command passed as argument),
we stumble on this latent bug:

 (gdb) thread apply all pri[TAB]
 (gdb) thread apply all priprint

The problem is that there's a spot in complete_line_internal_1 that
rewinds the completion word but does not reflect that change in the
custom word point in the tracker.  This patch fixes it.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* completer.c (complete_line_internal_1): Rewind completion word
point.
(completion_tracker::advance_custom_word_point_by): Change
parameter type to int.
* completer.h (completion_tracker::advance_custom_word_point_by):
Likewise.

4 years agoFix latent bug in custom word point completion handling
Pedro Alves [Wed, 12 Jun 2019 23:06:52 +0000 (00:06 +0100)] 
Fix latent bug in custom word point completion handling

Without this fix, if we switch the "print" completer to custom word
point handling, we regress gdb.base/completion.exp like this:

 (gdb) p "break1.c FAIL: gdb.base/completion.exp: complete 'p "break1' (timeout)

The problem is that completing an expression that starts with double
quotes, and resolves to a filename, like this:

 (gdb) p "break1[TAB]

would change from this, with current master:

 (gdb) p "break1.c"|
         ^^^^^^^^^^|
                   \- cursor here

to this:

 (gdb) p "break1.c |
         ^^^^^^^^^^|
                   \- quote replaced by space

The issue is that completer.c:advance_to_completion_word misses
telling the completion tracker to emulate readline's handling of
completing a string when rl_find_completion_word returns a delimiter.

This commit fixes the latent bug.

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* completer.c (advance_to_completion_word): Handle delimiters.

4 years agoopcodes/or1k: Regenerate opcodes
Stafford Horne [Wed, 12 Jun 2019 21:16:19 +0000 (06:16 +0900)] 
opcodes/or1k: Regenerate opcodes

This picks up changes for:
  - new orfpx64a32 spec additions
  - new unordered instructions
  - symbol and documentation updates

opcodes/ChangeLog:

* or1k-asm.c: Regenerated.
* or1k-desc.c: Regenerated.
* or1k-desc.h: Regenerated.
* or1k-dis.c: Regenerated.
* or1k-ibld.c: Regenerated.
* or1k-opc.c: Regenerated.
* or1k-opc.h: Regenerated.
* or1k-opinst.c: Regenerated.

4 years agocpu/or1k: Update fpu compare symbols to imply set flag
Stafford Horne [Wed, 12 Jun 2019 21:16:19 +0000 (06:16 +0900)] 
cpu/or1k: Update fpu compare symbols to imply set flag

The fpu compare symbols where not including 'sf' in the mnemonic.  So
instead of `lf-sfeq` (implying set flag if operands are equal) we were
having `lf-eq`.   This patch adds the 'sf'.  This helps with making the
generated CGEN documentation consistent and ordered correctly.

cpu/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

* or1korfpx.cpu (float-setflag-insn-base): Add 'sf' to symbol.

4 years agocpu/or1k: Document no branch delay slot architectures and l.adrp
Stafford Horne [Wed, 12 Jun 2019 21:16:19 +0000 (06:16 +0900)] 
cpu/or1k: Document no branch delay slot architectures and l.adrp

The 'nd' architectures did not mention what the 'nd' stands for.
Document that these mean 'no brach delay slot'.

cpu/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

* or1k.cpu (or64nd, or32nd, or1200nd): Update comment.a
(l-adrp): Improve comment.

4 years agocpu/or1k: Define unordered comparisons
Stafford Horne [Wed, 12 Jun 2019 21:16:19 +0000 (06:16 +0900)] 
cpu/or1k: Define unordered comparisons

Add support for new floating point unordered comparisons.  These have been
defined in OpenRISC architecture proposal 7[0] and are now included in the
architecture specification 1.3.

These new instructions provide the ability for floating point comparisons to
detect NaNs.

[0] https://openrisc.io/proposals/lfsf

cpu/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

* or1korfpx.cpu (insn-opcode-float-regreg): Add SFUEQ_S, SFUNE_S,
SFUGT_S, SFUGE_S, SFULT_S, SFULE_S, SFUN_S, SFUEQ_D, SFUNE_D, SFUGT_D,
SFUGE_D, SFULT_D, SFULE_D, SFUN_D opcodes.
(float-setflag-insn-base): New pmacro based on float-setflag-insn.
(float-setflag-symantics, float-setflag-unordered-cmp-symantics,
float-setflag-unordered-symantics): New pmacro for instruction
symantics.
(float-setflag-insn): Update to use float-setflag-insn-base.
(float-setflag-unordered-insn): New pmacro for generating instructions.

4 years agocpu/or1k: Add support for orfp64a32 spec
Stafford Horne [Wed, 12 Jun 2019 21:16:18 +0000 (06:16 +0900)] 
cpu/or1k: Add support for orfp64a32 spec

This patch adds support for OpenRISC 64-bit FPU operations on 32-bit cores by
using register pairs.  The functionality has been added to OpenRISC architecture
specification version 1.3 as per architecture proposal 14[0].

For supporting assembly of both 64-bit and 32-bit precision instructions we have
defined CGEN_VALIDATE_INSN_SUPPORTED.  This allows cgen to use 64-bit bit
architecture assembly parsing on 64-bit toolchains and 32-bit architecture
assembly parsing on 32-bit toolchains.  Without this the assembler has issues
parsing register pairs.

This patch also contains a few fixes to the symantics for existing OpenRISC
single and double precision FPU operations.

[0] https://openrisc.io/proposals/orfpx64a32

cpu/ChangeLog:

yyyy-mm-dd  Andrey Bacherov  <avbacherov@opencores.org>
    Stafford Horne  <shorne@gmail.com>

* or1k.cpu (ORFPX64A32-MACHS): New pmacro.
(ORFPX-MACHS): Removed pmacro.
* or1k.opc (or1k_cgen_insn_supported): New function.
(CGEN_VALIDATE_INSN_SUPPORTED): Define macro.
(parse_regpair, print_regpair): New functions.
* or1kcommon.cpu (h-spr, spr-shift, spr-address, h-gpr): Reorder
and add comments.
(h-fdr): Update comment to indicate or64.
(reg-pair-reg-lo, reg-pair-reg-hi): New pmacros for register pairs.
(h-fd32r): New hardware for 64-bit fpu registers.
(h-i64r): New hardware for 64-bit int registers.
* or1korbis.cpu (f-resv-8-1): New field.
* or1korfpx.cpu (rDSF, rASF, rBSF): Update attribute to ORFPX32-MACHS.
(rDDF, rADF, rBDF): Update operand comment to indicate or64.
(f-rdoff-10-1, f-raoff-9-1, f-rboff-8-1): New fields.
(h-roff1): New hardware.
(double-field-and-ops mnemonic): New pmacro to generate operations
rDD32F, rAD32F, rBD32F, rDDI and rADI.
(float-regreg-insn): Update single precision generator to MACH
ORFPX32-MACHS.  Add generator for or32 64-bit instructions.
(float-setflag-insn): Update single precision generator to MACH
ORFPX32-MACHS.  Fix double instructions from single to double
precision.  Add generator for or32 64-bit instructions.
(float-cust-insn cust-num): Update single precision generator to MACH
ORFPX32-MACHS.  Add generator for or32 64-bit instructions.
(lf-rem-s, lf-itof-s, lf-ftoi-s, lf-madd-s): Update MACH to
ORFPX32-MACHS.
(lf-rem-d): Fix operation from mod to rem.
(lf-rem-d32, lf-itof-d32, lf-ftoi-d32, lf-madd-d32): New instruction.
(lf-itof-d): Fix operands from single to double.
(lf-ftoi-d): Update operand mode from DI to WI.

4 years agoAdd missing ChangeLog entries
Peter Bergner [Wed, 12 Jun 2019 20:51:01 +0000 (15:51 -0500)] 
Add missing ChangeLog entries

4 years agoRemove the ldmx mnemonic that never made it into POWER9.
Peter Bergner [Wed, 12 Jun 2019 20:48:53 +0000 (15:48 -0500)] 
Remove the ldmx mnemonic that never made it into POWER9.

opcodes/
* ppc-opc.c (powerpc_opcodes) <ldmx>: Delete mnemonic.

gas/
* testsuite/gas/ppc/power9.d: Delete ldmx tests.
* testsuite/gas/ppc/power9.s: Likewise.

4 years agoPrevent a seg-fault from objdup when disassembling binaries which do not contain...
Adam Lackorzymski [Wed, 12 Jun 2019 14:05:21 +0000 (15:05 +0100)] 
Prevent a seg-fault from objdup when disassembling binaries which do not contain a symbol table.

PR 24643
* elf32-arm.c (arm_elf_find_function): Fail if the symol table is
absent, or the bfd is not in the ELF formart.
* elfnn-aarch64.c (aarch64_elf_find_function): Likewise.

4 years agoAdd support for NetBSD PaX notes to readelf.
Christos Zoulas [Wed, 12 Jun 2019 13:51:17 +0000 (14:51 +0100)] 
Add support for NetBSD PaX notes to readelf.

PR 24663
* readelf.c (process_netbsd_elf_note): Add support for
NT_NETBSD_PAX.
(process_note): Add support for PaX notes.

4 years agoAdd support for NetBSD/sh3 core reg sections to readelf.
Christos Zoulas [Wed, 12 Jun 2019 13:35:04 +0000 (14:35 +0100)] 
Add support for NetBSD/sh3 core reg sections to readelf.

PR 24665
* readelf.c (get_netbsd_elfcore_note_type): Add support for SH
core notes.

4 years agoAdd support to readelf to display NetBSD auxv notes in core files.
Christos Zoulas [Wed, 12 Jun 2019 12:52:04 +0000 (13:52 +0100)] 
Add support to readelf to display NetBSD auxv notes in core files.

PR 24664
* readelf.c (get_netbsd_elfcore_note_type): Add support for NetBSD
auxv notes.

4 years agoAutomatic date update in version.in
GDB Administrator [Wed, 12 Jun 2019 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agoDwarf: Don't add nameless modules to partial symbol table (ChangeLogs)
Pedro Alves [Tue, 11 Jun 2019 19:37:09 +0000 (20:37 +0100)] 
Dwarf: Don't add nameless modules to partial symbol table (ChangeLogs)

Add missing ChangeLog entries for previous commit.

gdb/ChangeLog:
2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>

* dwarf2read.c (add_partial_symbol): Skip nameless modules.

gdb/testsuite/Changelog:
2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>

* gdb.fortran/block-data.f: New.
* gdb.fortran/block-data.exp: New.

4 years agoDwarf: Don't add nameless modules to partial symbol table
Bernhard Heckel [Wed, 27 Feb 2019 14:21:12 +0000 (15:21 +0100)] 
Dwarf: Don't add nameless modules to partial symbol table

A name for BLOCK DATA in Fortran is optional.  If no name has been
assigned, GDB crashes during read-in of DWARF when BLOCK DATA is
represented via DW_TAG_module.  BLOCK DATA is used for one-time
initialization of non-pointer variables in named common blocks.

As of now there is no issue when gfortran is used as DW_TAG_module is
not emitted.  However, with Intel ifort the nameless DW_TAG_module is
present and has the following form:

 ...
  <1><dd>: Abbrev Number: 7 (DW_TAG_module)
     <de>   DW_AT_decl_line   : 46
     <df>   DW_AT_decl_file   : 1
     <e0>   DW_AT_description : (indirect string, offset: 0x110): block
 data
     <e4>   DW_AT_high_pc     : 0x402bb7
     <ec>   DW_AT_low_pc      : 0x402bb7
 ...

The missing name leads to a crash in add_partial_symbol, during length
calculation.

gdb/ChangeLog:
2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>

* dwarf2read.c (add_partial_symbol): Skip nameless modules.

gdb/testsuite/Changelog:
2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>

* gdb.fortran/block-data.f: New.
* gdb.fortran/block-data.exp: New.

4 years agoAdd support for reporting Alpha and Vax symbol visibility in readelf.
Christos Zoulas [Tue, 11 Jun 2019 15:43:25 +0000 (16:43 +0100)] 
Add support for reporting Alpha and Vax symbol visibility in readelf.

PR 24662
* readelf.c (get_alpha_symbol_other): New function.
(get_symbol_other): Use for Alpha symbols.
(is_32bit_pcrel_reloc): Add R_VAX_PCREL32.

4 years agoMove gdb's xmalloc and friends to new file
Tom Tromey [Wed, 29 May 2019 21:49:10 +0000 (15:49 -0600)] 
Move gdb's xmalloc and friends to new file

When "common" becomes a library, linking will cause a symbol clash,
because "xmalloc" and some related symbols are defined in that
library, libiberty, and readline.

To work around this problem, this patch moves the clashing symbols to
a new file, which is then compiled separately for both gdb and
gdbserver.

gdb/ChangeLog
2019-06-11  Tom Tromey  <tom@tromey.com>

* common/common-utils.c (xmalloc, xrealloc, xcalloc)
(xmalloc_failed): Move to alloc.c.
* alloc.c: New file.
* Makefile.in (COMMON_SFILES): Add alloc.c.

gdb/gdbserver/ChangeLog
2019-06-11  Tom Tromey  <tom@tromey.com>

* Makefile.in (SFILES): Add alloc.c.
(OBS): Add alloc.o.
(IPA_OBJS): Add alloc-ipa.o.
(alloc-ipa.o): New target.
(%.o: ../%.c): New pattern rule.

4 years agoRemove linux-waitpid.c debugging code
Tom Tromey [Mon, 6 May 2019 00:28:13 +0000 (18:28 -0600)] 
Remove linux-waitpid.c debugging code

The debugging code in linux-waitpid.c is one of the few remaining
spots that depends on the gdb/gdbserver difference.

My first thought was that this code is not extremely useful, so this
patch removes this code.  (However, if it is actually useful to
someone, we could make it work by introducing a new abstraction.)

gdb/ChangeLog
2019-06-11  Tom Tromey  <tom@tromey.com>

* nat/linux-waitpid.c: Don't include server.h.
(linux_debug): Remove.
(my_waitpid): Update.

4 years agoFix an unitinitalised local variable in decode_arm_unwind().
Christos Zoulas [Tue, 11 Jun 2019 13:36:47 +0000 (14:36 +0100)] 
Fix an unitinitalised local variable in decode_arm_unwind().

PR 24661
* readelf.c (decode_arm_unwind): Ensure that the local variable
'addr' is always initialised.

4 years agoRemove trailing newlines from help text
Tom Tromey [Tue, 4 Jun 2019 12:17:09 +0000 (06:17 -0600)] 
Remove trailing newlines from help text

I noticed recently that some command had a trailing newline in its
"help" output.  So, I temporarily hacked cli-decode.c to print
something when a new command was installed that had a trailing newline
in its help message, and wrote this patch, which removes all the ones
I could find this way.  (There could still be a few more in *-nat
files.)

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-06-11  Tom Tromey  <tromey@adacore.com>

* infcall.c (_initialize_infcall): Remove trailing newline from
help.
* user-regs.c (_initialize_user_regs): Remove trailing newline
from help.
* typeprint.c (_initialize_typeprint): Remove trailing newline
from help.
* reverse.c (_initialize_reverse): Remove trailing newlines from
help.
* tracepoint.c (_initialize_tracepoint): Remove trailing newlines
from help.
* language.c (add_set_language_command): Remove trailing newline
from help.
* infcmd.c (_initialize_infcmd): Remove trailing newlines from
help.
* disasm.c (_initialize_disasm): Remove trailing newline from
help.
* top.c (init_main): Remove trailing newline from help.
* interps.c (_initialize_interpreter): Remove trailing newline
from help.
* btrace.c (_initialize_btrace): Remove trailing newlines from
help.
* breakpoint.c (_initialize_breakpoint): Remove trailing newline
from help.
* python/python.c (_initialize_python): Remove trailing newline
from help.
* spu-tdep.c (_initialize_spu_tdep): Remove trailing newlines from
help.
* tui/tui-win.c (_initialize_tui_win): Remove trailing newlines
from help.  Reformat some text.
* tui/tui-stack.c (_initialize_tui_stack): Remove trailing newline
from help.
* tui/tui-layout.c (_initialize_tui_layout): Remove trailing
newline from help.

4 years ago[gdb/testsuite] Fix remove-inferiors.exp FAIL with readnow board
Tom de Vries [Tue, 11 Jun 2019 11:54:10 +0000 (13:54 +0200)] 
[gdb/testsuite] Fix remove-inferiors.exp FAIL with readnow board

We see this failure with the readnow board:
...
FAIL: gdb.multi/remove-inferiors.exp: load binary
...

When running with board readnow, an extra message "Expanding full symbols" is
emitted after the "Reading symbols" message, and the regexp corresponding to
the FAIL only allows the first message.

Fix this by allowing the extra message in the regexp.

gdb/testsuite/ChangeLog:

2019-06-11  Tom de Vries  <tdevries@suse.de>

PR testsuite/24521
* gdb.multi/remove-inferiors.exp: Allow "Expanding full symbols"
message.

4 years agoRemove shadowing from darwin-nat.c
Tom Tromey [Mon, 10 Jun 2019 20:49:04 +0000 (22:49 +0200)] 
Remove shadowing from darwin-nat.c

Building on Darwin with gcc showed that darwin-nat.c had some
shadowing variable declarations.  This removes them.

gdb/ChangeLog
2019-06-11  Tom Tromey  <tromey@adacore.com>

* darwin-nat.c (darwin_decode_exception_message)
(darwin_decode_message, darwin_nat_target::kill): Fix shadowing.

4 years ago[gdb/testsuite] Fix main high_pc in nonvar-access.exp
Tom de Vries [Tue, 11 Jun 2019 11:22:27 +0000 (13:22 +0200)] 
[gdb/testsuite] Fix main high_pc in nonvar-access.exp

When running gdb.dwarf2/nonvar-access.exp with board readnow, we have:
...
FAIL: gdb.dwarf2/nonvar-access.exp: print/x def_implicit_s
...
and 12 more similar failures.

I've tracked this down to the range of main being hardcoded to
[_main, _main+0x10000) in the dwarf assembly:
...
            DW_TAG_subprogram {
                {name main}
                {DW_AT_external 1 flag}
                {low_pc [gdb_target_symbol main] DW_FORM_addr}
{high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr}
            } {
...
which overlaps with the .debug_info for the elf-init.c CU (containing
__libc_csu_init and __libc_csu_fini).

Fix this by using function_range to find the actual range of main.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-06-11  Tom de Vries  <tdevries@suse.de>

PR testsuite/24521
* gdb.dwarf2/nonvar-access.exp: Fix main high_pc.

4 years ago[gdb/testsuite] Add readnow.exp
Tom de Vries [Tue, 11 Jun 2019 07:42:56 +0000 (09:42 +0200)] 
[gdb/testsuite] Add readnow.exp

Add a target board to test -readnow.

gdb/testsuite/ChangeLog:

2019-06-11  Tom de Vries  <tdevries@suse.de>

* boards/readnow.exp: New file.

4 years agoAutomatic date update in version.in
GDB Administrator [Tue, 11 Jun 2019 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

4 years agogdb: Check for not allocated/associated values during array slicing
Andrew Burgess [Thu, 23 May 2019 18:49:41 +0000 (19:49 +0100)] 
gdb: Check for not allocated/associated values during array slicing

When extracting an array slice we should give up if the array is
not-allocated or not-associated.  For Fortran, at least in gfortran
compiled code, the upper and lower bounds are undefined if the array
is not allocated or not associated, in which case performing checks
against these bounds will result in undefined behaviour.

Better then to throw an error if we try to slice such an array.  This
changes the error message that the user will receive in these
cases (if they got an error message before).  Previously they may have
gotten "slice out of range" now they'll get "array not allocated" or
"array not associated".

gdb/ChangeLog:

* valops.c (value_slice): Check for not allocated or not
associated values.

gdb/testsuite/ChangeLog:

* gdb.fortran/vla-sizeof.exp: Update expected results.

4 years ago[gdb] Fix heap-buffer-overflow in cp_find_first_component_aux
Tom de Vries [Mon, 10 Jun 2019 18:27:09 +0000 (20:27 +0200)] 
[gdb] Fix heap-buffer-overflow in cp_find_first_component_aux

When compiling gdb with '-lasan -fsanitizer=address' and running tests with:
- export ASAN_OPTIONS="detect_leaks=0:alloc_dealloc_mismatch=0",
- target board cc-with-gdb-index,
- the "[gdb/testsuite] Fix gdb.base/break-probes.exp with native-gdbserver"
  commit reverted to avoid running into PR24617,
we get with gdb.arch/amd64-init-x87-values.exp:
...
==31229==ERROR: AddressSanitizer: heap-buffer-overflow on address \
  0x62500098c93c at pc 0x000000bcc748 bp 0x7ffe39487660 sp 0x7ffe39487658
READ of size 1 at 0x62500098c93c thread T0
    #0 0xbcc747 in cp_find_first_component_aux src/gdb/cp-support.c:999
    #1 0xbcc6e9 in cp_find_first_component(char const*) \
                   src/gdb/cp-support.c:977
    #2 0xcc2cf3 in mapped_index_base::build_name_components() \
                   src/gdb/dwarf2read.c:4499
    #3 0xcc3322 in dw2_expand_symtabs_matching_symbol src/gdb/dwarf2read.c:4552
    #4 0xcc817f in dw2_expand_symtabs_matching src/gdb/dwarf2read.c:5228
    #5 0xfe8f48 in iterate_over_all_matching_symtabs src/gdb/linespec.c:1147
    #6 0x1003506 in add_matching_symbols_to_info src/gdb/linespec.c:4413
    #7 0xffe21b in find_function_symbols src/gdb/linespec.c:3886
    #8 0xffe4a2 in find_linespec_symbols src/gdb/linespec.c:3914
    #9 0xfee3ad in linespec_parse_basic src/gdb/linespec.c:1865
    #10 0xff5128 in parse_linespec src/gdb/linespec.c:2655
    #11 0xff8872 in event_location_to_sals src/gdb/linespec.c:3150
    #12 0xff90a8 in decode_line_full(event_location const*, int, \
                    program_space*, symtab*, int, linespec_result*, \
    char const*, char const*) src/gdb/linespec.c:3230
    #13 0x9ce449 in parse_breakpoint_sals src/gdb/breakpoint.c:9057
    #14 0x9ea022 in create_sals_from_location_default src/gdb/breakpoint.c:13708
    #15 0x9e2c1f in bkpt_create_sals_from_location src/gdb/breakpoint.c:12514
    #16 0x9cff06 in create_breakpoint(gdbarch*, event_location const*, \
                    char const*, int, char const*, int, int, bptype, int, \
    auto_boolean, breakpoint_ops const*, int, int, int, \
    unsigned int) src/gdb/breakpoint.c:9238
    #17 0x9d114a in break_command_1 src/gdb/breakpoint.c:9402
    #18 0x9d1b60 in break_command(char const*, int) src/gdb/breakpoint.c:9473
    #19 0xac96aa in do_const_cfunc src/gdb/cli/cli-decode.c:106
    #20 0xad0e5a in cmd_func(cmd_list_element*, char const*, int) \
                    src/gdb/cli/cli-decode.c:1892
    #21 0x15226f6 in execute_command(char const*, int) src/gdb/top.c:630
    #22 0xddde37 in command_handler(char const*) src/gdb/event-top.c:586
    #23 0xdde7c1 in command_line_handler(std::unique_ptr<char, \
                    gdb::xfree_deleter<char> >&&) src/gdb/event-top.c:773
    #24 0xddc9e8 in gdb_rl_callback_handler src/gdb/event-top.c:217
    #25 0x16f2198 in rl_callback_read_char src/readline/callback.c:220
    #26 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \
                    src/gdb/event-top.c:175
    #27 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192
    #28 0xddd9f5 in stdin_event_handler(int, void*) src/gdb/event-top.c:514
    #29 0xdd7d8f in handle_file_event src/gdb/event-loop.c:731
    #30 0xdd8607 in gdb_wait_for_event src/gdb/event-loop.c:857
    #31 0xdd629c in gdb_do_one_event() src/gdb/event-loop.c:321
    #32 0xdd6344 in start_event_loop() src/gdb/event-loop.c:370
    #33 0x10a7715 in captured_command_loop src/gdb/main.c:331
    #34 0x10aa548 in captured_main src/gdb/main.c:1173
    #35 0x10aa5d8 in gdb_main(captured_main_args*) src/gdb/main.c:1188
    #36 0x87bd35 in main src/gdb/gdb.c:32
    #37 0x7f16e1434f89 in __libc_start_main (/lib64/libc.so.6+0x20f89)
    #38 0x87bb49 in _start (build/gdb/gdb+0x87bb49)

0x62500098c93c is located 0 bytes to the right of 8252-byte region \
  [0x62500098a900,0x62500098c93c)
allocated by thread T0 here:
    #0 0x7f16e359a600 in malloc (/usr/lib64/libasan.so.5+0xeb600)
    #1 0x1742ddf in bfd_malloc src/bfd/libbfd.c:275
    #2 0x1738824 in bfd_get_full_section_contents src/bfd/compress.c:253
    #3 0xe30044 in gdb_bfd_map_section(bfd_section*, unsigned long*) \
                   src/gdb/gdb_bfd.c:704
    #4 0xcb56bf in dwarf2_read_section(objfile*, dwarf2_section_info*) \
                   src/gdb/dwarf2read.c:2539
    #5 0xd5bcd0 in get_gdb_index_contents_from_section<dwarf2_per_objfile> \
                   src/gdb/dwarf2read.c:6217
    #6 0xd7fc7d in gdb::function_view<gdb::array_view<unsigned char const> \
                   (...) const src/gdb/common/function-view.h:284
    #7 0xd7fddd in gdb::function_view<gdb::array_view<unsigned char const> \
                   (...) src/gdb/common/function-view.h:278
    #8 0xd730cf in gdb::function_view<gdb::array_view<unsigned char const> \
                   (...) const src/gdb/common/function-view.h:247
    #9 0xcbc7ee in dwarf2_read_gdb_index src/gdb/dwarf2read.c:3582
    #10 0xcce731 in dwarf2_initialize_objfile(objfile*, dw_index_kind*) \
                    src/gdb/dwarf2read.c:6297
    #11 0xdb88c4 in elf_symfile_read src/gdb/elfread.c:1256
    #12 0x141262a in read_symbols src/gdb/symfile.c:798
    #13 0x14140a7 in syms_from_objfile_1 src/gdb/symfile.c:1000
    #14 0x1414393 in syms_from_objfile src/gdb/symfile.c:1017
    #15 0x1414fb7 in symbol_file_add_with_addrs src/gdb/symfile.c:1124
    #16 0x14159b7 in symbol_file_add_from_bfd(bfd*, char const*, \
                     enum_flags<symfile_add_flag>, std::vector<other_sections, \
             std::allocator<other_sections> >*, \
     enum_flags<objfile_flag>, objfile*) src/gdb/symfile.c:1203
    #17 0x1415b6c in symbol_file_add(char const*,
                     enum_flags<symfile_add_flag>, std::vector<other_sections, \
     std::allocator<other_sections> >*, \
     enum_flags<objfile_flag>) src/gdb/symfile.c:1216
    #18 0x1415f2f in symbol_file_add_main_1 src/gdb/symfile.c:1240
    #19 0x1418599 in symbol_file_command(char const*, int) \
                     src/gdb/symfile.c:1675
    #20 0xde2fa6 in file_command src/gdb/exec.c:433
    #21 0xac96aa in do_const_cfunc src/gdb/cli/cli-decode.c:106
    #22 0xad0e5a in cmd_func(cmd_list_element*, char const*, int) \
                    src/gdb/cli/cli-decode.c:1892
    #23 0x15226f6 in execute_command(char const*, int) src/gdb/top.c:630
    #24 0xddde37 in command_handler(char const*) src/gdb/event-top.c:586
    #25 0xdde7c1 in command_line_handler(std::unique_ptr<char, \
                    gdb::xfree_deleter<char> >&&) src/gdb/event-top.c:773
    #26 0xddc9e8 in gdb_rl_callback_handler src/gdb/event-top.c:217
    #27 0x16f2198 in rl_callback_read_char src/readline/callback.c:220
    #28 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \
                    src/gdb/event-top.c:175
    #29 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192

SUMMARY: AddressSanitizer: heap-buffer-overflow src/gdb/cp-support.c:999 in \
  cp_find_first_component_aux
Shadow bytes around the buggy address:
  0x0c4a801298d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a801298e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a801298f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a80129900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a80129910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c4a80129920: 00 00 00 00 00 00 00[04]fa fa fa fa fa fa fa fa
  0x0c4a80129930: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a80129940: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a80129950: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a80129960: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a80129970: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==31229==ABORTING
...

The problem happens as follows.

The executable amd64-init-x87-values gets an index (due to target board
cc-with-gdb-index), which looks as follows:
...
Hex dump of section '.gdb_index':
  0x00000000 08000000 18000000 28000000 28000000 ........(...(...
  0x00000010 3c000000 3c200000 00000000 00000000 <...< ..........
  0x00000020 2e000000 00000000 d4004000 00000000 ..........@.....
  0x00000030 db004000 00000000 00000000 00000000 ..@.............
  0x00000040 00000000 00000000 00000000 00000000 ................
  0x00000050 00000000 00000000 00000000 00000000 ................
  ... more zeroes ...
  0x00002010 00000000 00000000 00000000 00000000 ................
  0x00002020 00000000 00000000 00000000 00000000 ................
  0x00002030 00000000 00000000 00000000          ............
...

The structure of this index is:
...
header       : [0x0, 0x18)     : size 0x18
culist       : [0x18 ,0x28)    : size 0x10
typesculist  : [0x28, 0x28)    : size 0x0
adress area  : [0x28, 0x3c)    : size 0x14
symbol table : [0x3c, 0x203c)  : size 0x2000
constant pool: [0x203c, 0x203c): size 0x0
EOF          : 0x203c
...

Note that the symbol table consists entirely of empty slots (where an empty
slot is a pair of 32-bit zeroes), and that the constant pool is empty.

The problem happens here in mapped_index_base::build_name_components:
...
  auto count = this->symbol_name_count ();
  for (offset_type idx = 0; idx < count; idx++)
    {
      if (this->symbol_name_slot_invalid (idx))
continue;

      const char *name = this->symbol_name_at (idx);
...
when accessing the slot at idx == 0 in the symbol table,
symbol_name_slot_invalid returns false so we calculate name, which is
calculated using 'constant_pool + symbol_table[idx].name', which means we get
name == constant_pool.  And given that the constant pool is empty, name now
points past the memory allocated for the index, and when we access name[0] for
the first time in cp_find_first_component_aux, we run into the
heap-buffer-overflow.

Fix this by fixing the definition of symbol_name_slot_invalid:
...
-    return bucket.name == 0 && bucket.vec;
+    return bucket.name == 0 && bucket.vec == 0;
...

Tested on x86_64-linux.

gdb/ChangeLog:

2019-06-10  Tom de Vries  <tdevries@suse.de>

PR gdb/24618
* dwarf2read.c (struct mapped_index::symbol_name_slot_invalid): Make
sure an empty slot (defined by a 32-bit zero pair) is recognized as
invalid.

4 years ago[gdb] Fix dynamic-stack-buffer-overflow in linespec_lexer_lex_string
Tom de Vries [Mon, 10 Jun 2019 18:17:14 +0000 (20:17 +0200)] 
[gdb] Fix dynamic-stack-buffer-overflow in linespec_lexer_lex_string

When compiling gdb with '-lasan -fsanitizer=address' and running tests with
'export ASAN_OPTIONS="detect_leaks=0:alloc_dealloc_mismatch=0"', I run into:
...
ERROR: GDB process no longer exists
UNRESOLVED: gdb.linespec/cpls-abi-tag.exp: \
  test_abi_tag: completion: at tag: tab complete "b test_abi_tag_function[abi:"
...

In more detail:
...
==3637==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address \
  0x7fff5952bbdd at pc 0x000000fe5c57 bp 0x7fff5952af30 sp 0x7fff5952af28
READ of size 1 at 0x7fff5952bbdd thread T0
    #0 0xfe5c56 in linespec_lexer_lex_string src/gdb/linespec.c:727
    #1 0xfe7473 in linespec_lexer_lex_one src/gdb/linespec.c:946
    #2 0xfe799d in linespec_lexer_consume_token src/gdb/linespec.c:982
    #3 0xff446d in parse_linespec src/gdb/linespec.c:2564
    #4 0xff78be in linespec_complete(completion_tracker&, char const*, \
                   symbol_name_match_type) src/gdb/linespec.c:2961
    #5 0xb9299c in complete_address_and_linespec_locations \
                   src/gdb/completer.c:573
    #6 0xb93e90 in location_completer(cmd_list_element*, completion_tracker&, \
                   char const*, char const*) src/gdb/completer.c:919
    #7 0xb940c5 in location_completer_handle_brkchars src/gdb/completer.c:956
    #8 0xb957ec in complete_line_internal_normal_command \
                   src/gdb/completer.c:1208
    #9 0xb96507 in complete_line_internal_1 src/gdb/completer.c:1430
    #10 0xb965c2 in complete_line_internal src/gdb/completer.c:1449
    #11 0xb98630 in gdb_completion_word_break_characters_throw \
                    src/gdb/completer.c:1862
    #12 0xb98838 in gdb_completion_word_break_characters() \
                    src/gdb/completer.c:1897
    #13 0x16c6362 in _rl_find_completion_word src/readline/complete.c:943
    #14 0x16ca8d0 in rl_complete_internal src/readline/complete.c:1843
    #15 0x16c460c in rl_complete src/readline/complete.c:408
    #16 0x16b3368 in _rl_dispatch_subseq src/readline/readline.c:774
    #17 0x16b3092 in _rl_dispatch src/readline/readline.c:724
    #18 0x16b2939 in readline_internal_char src/readline/readline.c:552
    #19 0x16f1fb0 in rl_callback_read_char src/readline/callback.c:201
    #20 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \
                    src/gdb/event-top.c:175
    #21 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192
    #22 0xddd9f5 in stdin_event_handler(int, void*) src/gdb/event-top.c:514
    #23 0xdd7d8f in handle_file_event src/gdb/event-loop.c:731
    #24 0xdd8607 in gdb_wait_for_event src/gdb/event-loop.c:857
    #25 0xdd629c in gdb_do_one_event() src/gdb/event-loop.c:321
    #26 0xdd6344 in start_event_loop() src/gdb/event-loop.c:370
    #27 0x10a7715 in captured_command_loop src/gdb/main.c:331
    #28 0x10aa548 in captured_main src/gdb/main.c:1173
    #29 0x10aa5d8 in gdb_main(captured_main_args*) src/gdb/main.c:1188
    #30 0x87bd35 in main src/gdb/gdb.c:32
    #31 0x7fb0364c6f89 in __libc_start_main (/lib64/libc.so.6+0x20f89)
    #32 0x87bb49 in _start (build/gdb/gdb+0x87bb49)

Address 0x7fff5952bbdd is located in stack of thread T0 at offset 557 in frame
    #0 0xb93702 in location_completer(cmd_list_element*, completion_tracker&, \
                   char const*, char const*) src/gdb/completer.c:831

  This frame has 4 object(s):
    [32, 40) 'copy'
    [96, 104) 'location'
    [160, 168) 'text'
    [224, 256) 'completion_info' <== Memory access at offset 557 overflows \
                                    this variable
HINT: this may be a false positive if your program uses some custom stack \
      unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow \
         src/gdb/linespec.c:727 in linespec_lexer_lex_string
Shadow bytes around the buggy address:
  0x10006b29d720: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006b29d730: 00 00 00 00 00 00 f1 f1 f1 f1 00 f2 f2 f2 f2 f2
  0x10006b29d740: f2 f2 00 f2 f2 f2 f2 f2 f2 f2 00 f2 f2 f2 f2 f2
  0x10006b29d750: f2 f2 00 00 00 00 f3 f3 f3 f3 00 00 00 00 00 00
  0x10006b29d760: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10006b29d770: 00 00 00 00 ca ca ca ca 00 00 00[05]cb cb cb cb
  0x10006b29d780: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
  0x10006b29d790: 00 f2 f2 f2 f2 f2 f2 f2 00 f2 f2 f2 f3 f3 f3 f3
  0x10006b29d7a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006b29d7b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006b29d7c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==3637==ABORTING
...

The problem happens in linespec_lexer_lex_string when lexing
"b test_abi_tag_function[abi:\0" (using a notation where we make the implicit
terminating \0 explicit).

We arrrive here with (PARSER_STREAM (parser)) == ":\0":
...
             /* Do not tokenize ABI tags such as "[abi:cxx11]".  */
             else if (PARSER_STREAM (parser) - start > 4
                      && startswith (PARSER_STREAM (parser) - 4, "[abi"))
               ++(PARSER_STREAM (parser));
...
and consume ':', after which we end up here and consume '\0':
...
         /* Advance the stream.  */
         ++(PARSER_STREAM (parser));
...
after which (PARSER_STREAM (parser)) points past the end of the string.

Fix this by removing the first "++(PARSER_STREAM (parser))", and add an assert
to the second one to detect moving past the end-of-string.

Build and tested on x86_64-linux.

gdb/ChangeLog:

2019-06-10  Tom de Vries  <tdevries@suse.de>

PR gdb/24611
* linespec.c (linespec_lexer_lex_string): Remove incorrect
"++(PARSER_STREAM (parser))" for "[abi"-prefixed colon.  Add assert.

4 years ago[gdb/symtab] Fix symbol loading performance regression
Tom de Vries [Mon, 10 Jun 2019 18:05:04 +0000 (20:05 +0200)] 
[gdb/symtab] Fix symbol loading performance regression

The commit "[gdb/symtab] Fix language of duplicate static minimal symbol"
introduces a performance regression, when loading a cc1 executable build with
-O0 -g and gcc 7.4.0.  The performance regression, measured in 'real' time is
about 175%.

The slower execution comes from the fact that the fix in symbol_set_names
makes the call to symbol_find_demangled_name unconditional.

Fix this by reverting the commit, and redoing the fix as follows.

Recapturing the original problem, the first time symbol_set_names is called
with gsymbol.language == lang_auto and linkage_name == "_ZL3foov", the name is
not present in the per_bfd->demangled_names_hash hash table, so
symbol_find_demangled_name is called to demangle the name, after which the
mangled/demangled pair is added to the hashtable.  The call to
symbol_find_demangled_name also sets gsymbol.language to lang_cplus.
The second time symbol_set_names is called with gsymbol.language == lang_auto
and linkage_name == "_ZL3foov", the name is present in the hash table, so the
demangled name from the hash table is used.  However, the language of the
symbol remains lang_auto.

Fix this by adding a field language in struct demangled_name_entry, and using
the field in symbol_set_names to set the language of gsymbol, if necessary.

Tested on x86_64-linux.

gdb/ChangeLog:

2019-06-10  Tom de Vries  <tdevries@suse.de>

PR symtab/24545
* symtab.c (struct demangled_name_entry): Add language field.
(symbol_set_names):  Revert "[gdb/symtab] Fix language of duplicate
static minimal symbol".  Set and use language field.

4 years agoFix printing large decimal values in strings.
Nick Clifton [Mon, 10 Jun 2019 14:30:02 +0000 (15:30 +0100)] 
Fix printing large decimal values in strings.

PR 24651
* strings.c (print_strings): Use %u to print unsigned values in
decimal.

4 years agoUpdate help text in ada-lang.c
Tom Tromey [Mon, 3 Jun 2019 15:25:39 +0000 (09:25 -0600)] 
Update help text in ada-lang.c

I noticed that the "catch assert" help text erroneously claimed to
accept an argument, and while fixing this I went ahead and added
"Usage" text and made other minor updates to the commands in
ada-lang.c.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-06-10  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (_initialize_ada_language): Update help text.

4 years agoRemove newlines from warnings
Tom Tromey [Mon, 3 Jun 2019 14:07:29 +0000 (08:07 -0600)] 
Remove newlines from warnings

ARI pointed out that a recent patch introduced a call to "warning"
with a string that ended in a newline:

    https://sourceware.org/ml/gdb-patches/2019-06/msg00000.html

This is generally forbidden, I believe, because warning adds its own
newline.

This patch removes all of the trailing newlines I was able to find.  I
searched for 'warning (.*\\n"' and then fixed the ones where the
newline appeared at the end of the string (some had internal
newlines).

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-06-10  Tom Tromey  <tromey@adacore.com>

* m32c-tdep.c (m32c_m16c_address_to_pointer): Don't end warning
with a newline.
* guile/guile.c (handle_boot_error): Don't end warning with a
newline.
* cli/cli-cmds.c (exit_status_set_internal_vars): Don't end
warning with a newline.
* s12z-tdep.c (s12z_skip_prologue): Don't end warning with a
newline.
(s12z_frame_cache): Likewise.
* dwarf-index-cache.c (index_cache::store): Don't end warning with
a newline.
* solib-svr4.c (disable_probes_interface): Don't end warning with
a newline.
* nat/fork-inferior.c (fork_inferior): Don't end warning with a
newline.
* python/python.c (do_finish_initialization): Don't end warning
with a newline.

gdb/gdbserver/ChangeLog
2019-06-10  Tom Tromey  <tromey@adacore.com>

* remote-utils.c (look_up_one_symbol, relocate_instruction): Don't
end warning with a newline.
* linux-s390-low.c (s390_get_wordsize): Don't end warning with a
newline.
* thread-db.c (attach_thread): Don't end warning with a newline.
(thread_db_notice_clone): Likewise.
* tracepoint.c (gdb_agent_helper_thread): Don't end warning with a
newline.
* linux-x86-low.c (x86_get_min_fast_tracepoint_insn_len): Don't
end warning with a newline.

4 years agoAdd support for NetBSD/sh3 core file sections. Merge multiple copies of auxv section...
Christos Zoulas [Mon, 10 Jun 2019 13:41:35 +0000 (14:41 +0100)] 
Add support for NetBSD/sh3 core file sections.  Merge multiple copies of auxv section creation into one function.

PR 24650
* elf.c (elfcore_make_auxv_note_section): New function.
(elfcore_grok_note): Use it.
(elfcore_grok_freebsd_note): Likewise.
(elfcore_grok_openbsd_note): Likewise.
(elfcore_grok_netbsd_note): Likewise.  Plus add support for
NT_NETBSDCORE_AUXV notes.