Commit Graph

7579 Commits

Author SHA1 Message Date
Andrew Burgess 93cb9841d6 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.
2019-06-16 16:27:14 +01:00
Simon Marchi e79be6e5f3 Fix some whitespace issues in gdb ChangeLogs 2019-06-16 10:02:50 -04:00
Simon Marchi 399aaebd1a 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

  5a56d6a65f ("[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.
2019-06-16 09:07:17 -04:00
Andrew Burgess 584a927c5a 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.
2019-06-16 00:29:35 +01:00
Andrew Burgess 30056ea04a 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.
2019-06-15 23:22:22 +01:00
Andrew Burgess ec8e2b6d30 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.
2019-06-15 21:39:06 +01:00
Andrew Burgess 09e4c4e1f1 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.
2019-06-15 21:31:04 +01:00
Tom Tromey 0735b091ab 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.
2019-06-14 14:13:29 -06:00
Tom Tromey f568655424 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.
2019-06-14 12:38:15 -06:00
Tom Tromey a0c1ffedcf 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.
2019-06-14 08:34:24 -06:00
Tom Tromey f411722cbc 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.
2019-06-14 08:06:16 -06:00
Tom Tromey 4268ec187d 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.
2019-06-14 08:02:20 -06:00
Tom Tromey 9a9e394b05 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.
2019-06-14 06:53:24 -06:00
Pedro Alves 4c04873103 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".
2019-06-13 15:22:44 +01:00
Pedro Alves 6665660a41 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.
2019-06-13 00:23:25 +01:00
Pedro Alves 5d7071341d 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.
2019-06-13 00:22:07 +01:00
Pedro Alves e2a689da55 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.
2019-06-13 00:20:59 +01:00
Pedro Alves 90a1ef8762 "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.
2019-06-13 00:20:08 +01:00
Pedro Alves d4c16835ca 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.
2019-06-13 00:19:14 +01:00
Pedro Alves 2daf894ed0 "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.
2019-06-13 00:18:41 +01:00
Pedro Alves e6ed716cd5 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.
2019-06-13 00:18:33 +01:00
Pedro Alves 7d8062de98 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".
2019-06-13 00:18:24 +01:00
Pedro Alves 9d0faba9f5 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.
2019-06-13 00:18:12 +01:00
Pedro Alves dee7b4c83a 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.
2019-06-13 00:17:58 +01:00
Pedro Alves dca0f6c0a4 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.
2019-06-13 00:12:20 +01:00
Pedro Alves ccf46844d3 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.
2019-06-13 00:10:41 +01:00
Pedro Alves b9a3f8429b 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 529c08b25e
("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.
2019-06-13 00:08:09 +01:00
Pedro Alves d106773eac 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.
2019-06-11 20:37:09 +01:00
Bernhard Heckel a5fd13a915 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.
2019-06-11 19:20:09 +01:00
Tom de Vries fea82da0fe [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.
2019-06-11 13:54:10 +02:00
Tom de Vries 8c2e74f181 [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.
2019-06-11 13:22:27 +02:00
Tom de Vries b49851c8e2 [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.
2019-06-11 09:42:56 +02:00
Andrew Burgess a706786341 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.
2019-06-10 23:05:58 +01:00
Amos Bird 1a3da2cd61 Add thread-exit annotation.
gdb/ChangeLog
2019-04-26  Amos Bird  <amosbird@gmail.com>

	* annotate.c (annotate_thread_exited): Add "thread-exited"
	annotation.

gdb/doc/ChangeLog
2019-06-06  Amos Bird  <amosbird@gmail.com>

	* annotate.texinfo (Multi-threaded Apps): Add entry for thread-exited
	annotation.

gdb/testsuite/ChangeLog
2019-06-06  Amos Bird  <amosbird@gmail.com>

	* gdb.base/annota1.exp (thread_switch): Add test for
	thread-exited annotation.
2019-06-06 11:35:15 -06:00
Tom Tromey 3847a7bfbf Add timestamps to "maint time" output
Currently "maint time" will print the amount of time a command took.
Sometimes, though, it's useful to have a timestamp as well -- for
example if one is correlating a gdb log with some other log.

This patch adds a timestamp to the start and end of each command when
this setting is in effect.

This also removes a "//" comment and changes scoped_command_stats to
use DISABLE_COPY_AND_ASSIGN; two minor things I noticed while working
on the patch.

Tested on x86-64 Fedora 29.

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

	* maint.h (class scoped_command_stats): Use
	DISABLE_COPY_AND_ASSIGN.
	<print_time>: New method.
	* maint.c (scoped_command_stats, ~scoped_command_stats): Call
	print_time.
	(scoped_command_stats::print_time): New method.

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

	* gdb.base/maint.exp: Expect command started/finished output.
2019-06-06 08:53:56 -06:00
Andrew Burgess 0088ba596b gdb/testsuite: Improve comments in recently added test
Remove the use of 'I' within some comments in a recently added test.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-unwind-long-insn-6.s: Remove use of 'I' in
	comment.
	* gdb.arch/riscv-unwind-long-insn-8.s: Likewise.
2019-06-05 10:35:35 +01:00
Andrew Burgess 312617a3d0 gdb/riscv: Don't error when decoding a 6 or 8 byte instruction
If the RISC-V prologue scanner finds a 6 or 8 byte instruction we
currently throw an internal error, which is not great for the user.

A mechanism already exists in the prologue scanner to leave
instructions marked as unknown so that we can stop the prologue scan
without raising an error, this is used for all 2 and 4 byte
instructions that are not part of the small set the prologue scanner
actually understands.

This commit changes GDB so that all 6 and 8 byte instructions are
marked as unknown, rather than causing an error.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_insn::decode): Gracefully ignore
	instructions of lengths 6 or 8 bytes.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-unwind-long-insn-6.s: New file.
	* gdb.arch/riscv-unwind-long-insn-8.s: New file.
	* gdb.arch/riscv-unwind-long-insn.c: New file.
	* gdb.arch/riscv-unwind-long-insn.exp: New file.
2019-06-05 09:54:47 +01:00
Pedro Alves d3238f7d90 Fix paths to ChangeLog files 2019-06-04 22:44:36 +01:00
Christian Biesinger via gdb-patches e1f2e1a2da Add an objfile getter to gdb.Type
This allows users of the Python API to find the objfile where a type
was defined.

gdb/ChangeLog:

gdb/ChangeLog
2019-06-04  Christian Biesinger  <cbiesinger@google.com>

	Add objfile property to gdb.Type.
	* gdb/NEWS: Mention Python API addition.
	* gdb/python/py-type.c (typy_get_objfile): New method.

gdb/doc/ChangeLog
2019-06-04  Christian Biesinger  <cbiesinger@google.com>

	* gdb/doc/python.texi: Document new gdb.Type.objfile property.

gdb/testsuite/ChangeLog
2019-06-04  Christian Biesinger  <cbiesinger@google.com>

	* gdb/testsuite/gdb.python/py-type.exp: Test for new
	  gdb.Type.objfile property.
2019-06-04 09:46:06 -06:00
Philippe Waroquiers 206584bdf1 Update tests following changes to "help" and "apropos"
Factorizes the testing of the help output, by having a single place
that defines the common help trailer and/or prefix messages.
2019-06-03 21:59:35 +02:00
Philippe Waroquiers 708dc93ed0 Test the | (pipe) command.
gdb/testsuite/ChangeLog
2019-05-31  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/shell.exp: Test pipe command, $_shell_exitcode,
	$_shell_exitsignal.
	* gdb.base/default.exp: Update for new convenience variables.
2019-05-31 17:13:07 +02:00
Tom Tromey f49055a52f Fix failure in gdb.ada/complete.exp
I noticed a failure in gdb.ada/complete.exp when testing locally:

    FAIL: gdb.ada/complete.exp: complete break ada

This failed due to this output:

    [...]
    break ada/generated/gnatvsn.ads
    break ada/libgnat/s-excmac.ads
    break ada/sdefault.adb
    break ada/snames.adb
    break ada/snames.ads

This patch updates the regexp to allow "/" and "-" to appear.

gdb/testsuite/ChangeLog
2019-05-29  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/complete.exp (test_gdb_no_completion): Add "/" and "-"
	to "break complete ada" test case's regexp.
2019-05-29 10:06:13 -06:00
Tom Tromey 4330d61dfb Fix crash in cp_print_value_fields
PR c++/20020 concerns a crash in cp_print_value_fields.  The immediate
cause is that cp_print_value_fields does not handle the case where
value_static_field fails.  This is fixed in this patch by calling
cp_print_static_field from the "try" block.

Digging a bit deeper, the error occurs because GCC does not emit a
DW_AT_const_value for a static constexpr member appearing in a
template class.  I've filed a GCC bug for this.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-05-29  Tom Tromey  <tromey@adacore.com>

	PR c++/20020:
	* cp-valprint.c (cp_print_value_fields): Call
	cp_print_static_field inside "try".

gdb/testsuite/ChangeLog
2019-05-29  Tom Tromey  <tromey@adacore.com>

	PR c++/20020:
	* gdb.cp/constexpr-field.exp: New file.
	* gdb.cp/constexpr-field.cc: New file.
2019-05-29 09:44:09 -06:00
Tom Tromey 000439d528 Add "set print finish"
A user wanted to be able to disable the display of the value when
using "finish" -- but still have the value entered into the value
history in case it was useful later on.  Part of the rationale here is
that sometimes the value might be quite large, or expensive to display
(in their case this was compounded by a rogue pretty-printer).

This patch implements this idea.

gdb/ChangeLog
2019-05-29  Tom Tromey  <tromey@adacore.com>

	* NEWS: Add entry.
	* infcmd.c (print_return_value_1): Handle finish_print
	option.
	(show_print_finish): New function.
	(_initialize_infcmd): Add "set/show print finish" commands.
	* valprint.c (user_print_options): Initialize new member.
	* valprint.h (struct value_print_options) <finish_print>: New
	member.

gdb/doc/ChangeLog
2019-05-29  Tom Tromey  <tromey@adacore.com>

	* gdb.texinfo (Continuing and Stepping): Document new
	commands.

gdb/testsuite/ChangeLog
2019-05-29  Tom Tromey  <tromey@adacore.com>

	* gdb.base/finish.exp (finish_no_print): New proc.
	(finish_tests): Call it.
2019-05-29 08:25:38 -06:00
Tom de Vries 5a01c34c62 [gdb/testsuite] Add test-case for gdb-add-index.sh
Add a test-case gdb.dwarf2/gdb-add-index.exp to test
gdb/contrib/gdb-add-index.sh.

Tested with x86_64-linux.

gdb/testsuite/ChangeLog:

2019-05-24  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/gdb-add-index.exp: New file.
2019-05-24 14:25:33 +02:00
Tom Tromey 18125b1639 Add "style" proc to the test suite
This adds a "style" helper proc to the test suite, and updates
existing style tests to use it.  Thanks to Sergio for the idea.

Tested on x86-64 Fedora 29.

gdb/testsuite/ChangeLog
2019-05-22  Tom Tromey  <tromey@adacore.com>

	* gdb.base/info-shared.exp (check_info_shared): Use "style".
	* gdb.base/style.exp: Use "style".
	* lib/gdb-utils.exp (style): New proc.
2019-05-22 13:59:52 -04:00
Tom de Vries af1a8d0387 [gdb/testsuite] Require c++11 for gdb.base/align.exp
When building gdb on ubuntu 16.04 with gcc 5.4.0, and running the gdb
testsuite we run into a failure due align.exp requiring at least c++11.

Fix this by adding -std=c++11.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-05-22  Tom de Vries  <tdevries@suse.de>

	* gdb.base/align.exp: Require c++11.
2019-05-22 18:13:04 +02:00
Tom de Vries e7fe496b1b [gdb/testsuite] Add missing mi_skip_python_tests to py-mi-var-info-path-expression.exp
Fix gdb.python/py-mi-var-info-path-expression.exp for a gdb build without
python support.

gdb/testsuite/ChangeLog:

2019-05-22  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24586
	* gdb.python/py-mi-var-info-path-expression.exp: Call
	mi_skip_python_tests to check if python is supported.
2019-05-22 17:55:44 +02:00
Alan Hayward 8fca4da075 AArch64: Treat pauth ops as nops on non-pauth systems
Running an address signed binary through GDB on a non pauth system
gives the following error:
Call Frame Instruction op 45 in vendor extension space is not handled on this architecture.

Instead GDB should ignore the op, treating it as a nop.

Add test case for pauth binaries, regardless of whether the target
supports it.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_execute_dwarf_cfa_vendor_op): Treat
	DW_CFA_AARCH64_negate_ra_state as nop on non pauth targets.

gdb/testsuite/ChangeLog:

	* gdb.arch/aarch64-pauth.c: New test.
	* gdb.arch/aarch64-pauth.exp: New file.
2019-05-22 14:35:25 +01:00
Alan Hayward b706061469 Document gdb.in/gdb.cmd files and debugredirect cli command
Add missing documentation for the debugredirect setting.

Add description and uses of gdb.in/gdb.cmd to the testsuite README.

Mention this in the NEWS file.

gdb/ChangeLog:

	* NEWS: Add debugredirect and testsuite sections.

gdb/doc/ChangeLog:

	* gdb.texinfo (Shell Commands): Add debugredirect.

gdb/testsuite/ChangeLog:

	* README (Re-running Tests Outside The Testsuite): New section.
2019-05-22 13:40:20 +01:00