Commit Graph

2442 Commits

Author SHA1 Message Date
Stafford Horne b67d92b06e reggroups: Add test and docs for `info reg $reggroup` feature
Until now this feature has existed but was not documented.  Adding docs
and tests.

gdb/ChangeLog:

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

	* infcmd.c (_initialize_infcmd): Add help for info reg $reggroup
	and info all-registers $reggroup feature.

gdb/doc/ChangeLog:

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

	* gdb.texinfo (Registers): Document info reg $reggroup feature.

gdb/testsuite/ChangeLog:

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

	* gdb.base/reggroups.c: New file.
	* gdb.base/reggroups.exp: New file.
2017-12-27 23:36:30 +09:00
Sergio Durigan Junior 7c1618381f Implement pahole-like 'ptype /o' option
This commit implements the pahole-like '/o' option for 'ptype', which
prints the offsets and sizes of struct fields, reporting whenever
there is a hole found.

The output is heavily based on pahole(1), with a few modifications
here and there to adjust it to our reality.  Here's an example:

  /* offset    |  size */  type = struct wer : public tuv {
			   public:
  /*   32      |    24 */    struct tyu {
  /*   32:31   |     4 */        int a1 : 1;
  /*   32:28   |     4 */        int a2 : 3;
  /*   32: 5   |     4 */        int a3 : 23;
  /*   35: 3   |     1 */        char a4 : 2;
  /* XXX  3-bit hole   */
  /* XXX  4-byte hole  */
  /*   40      |     8 */        int64_t a5;
  /*   48:27   |     4 */        int a6 : 5;
  /*   48:56   |     8 */        int64_t a7 : 3;

				 /* total size (bytes):   24 */
			     } a1;

			     /* total size (bytes):   56 */
			   }

A big part of this patch handles the formatting logic of 'ptype',
which is a bit messy.  The code to handle bitfield offsets, however,
took some time to craft.  My thanks to Pedro Alves for figuring things
out and pointing me to the right direction, as well as coming up with
a way to inspect the layout of structs with bitfields (see testcase
for comments).

After many discussions both on IRC and at the mailing list, I tried to
implement printing vtables and inherited classes.  Unfortunately the
code grew too complex and there were still a few corner cases failing
so I had to drop the attempt.  This should be implemented in a future
patch.

This patch is the start of a long-term work I'll do to flush the local
patches we carry for Fedora GDB.  In this specific case, I'm aiming at
upstreaming the feature implemented by the 'pahole.py' script that is
shipped with Fedora GDB:

  <https://src.fedoraproject.org/rpms/gdb/blob/master/f/gdb-archer.patch#_311>

This has been regression-tested on the BuildBot.  There's a new
testcase for it, along with an update to the documentation.  I also
thought it was worth mentioning this feature in the NEWS file.

gdb/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	PR cli/16224
	* NEWS (Changes since GDB 8.0): Mention new '/o' flag.
	* c-typeprint.c (OFFSET_SPC_LEN): New define.
	(c_type_print_varspec_prefix): New argument 'struct
	print_offset_data *'.
	(c_type_print_base_1): New function and prototype.
	(c_print_type_1): New function, with code from 'c_print_type'.
	(c_print_type): Use 'c_print_type_1'.
	(c_type_print_varspec_prefix): New argument 'struct
	print_offset_data *'.  Use it.  Call 'c_type_print_base_1'
	instead of 'c_print_type_base'.
	(print_spaces_filtered_with_print_options): New function.
	(output_access_specifier): Take new argument FLAGS.  Modify
	function to call 'print_spaces_filtered_with_print_options'.
	(c_print_type_vtable_offset_marker): New function.
	(c_print_type_union_field_offset): New function.
	(c_print_type_struct_field_offset): New function.
	(c_print_type_no_offsets): New function.
	(c_type_print_base_struct_union): New argument 'struct
	print_offset_data *'.  Print offsets and sizes for
	struct/union/class fields.
	* typeprint.c (const struct type_print_options
	type_print_raw_options): Initialize 'print_offsets'.
	(static struct type_print_options default_ptype_flags):
	Likewise.
	(struct print_offset_data print_offset_default_data): New
	variable.
	(whatis_exp): Handle '/o' option.
	(_initialize_typeprint): Add '/o' flag to ptype's help.
	* typeprint.h (struct print_offset_data): New struct.
	(struct type_print_options) <print_offsets>: New field.

gdb/testsuite/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/16224
	* gdb.base/ptype-offsets.cc: New file.
	* gdb.base/ptype-offsets.exp: New file.

gdb/doc/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/16224
	* gdb.texinfo (ptype): Add documentation for new flag '/o'.
2017-12-15 15:07:42 -05:00
Joel Brobecker 9937536c23 fix "server" command prefix handling (unexpected confirmation queries)
The "server" command prefix no longer turns confirmation queries off.
We can reproduce this with any program by tring to delete all breakpoints,
for instance:

    (gdb) break main
    Breakpoint 1 at 0x40049b: file /[...]/break-fun-addr1.c, line 21.
    (gdb) server delete breakpoints
    Delete all breakpoints? (y or n)

GDB should not be asking "Delete all breakpoints? (y or n)", but
instead just delete all breakpoints without asking for confirmation.

Looking at utils.c::defaulted_query gives a glimpse of how this feature
is expected to work:

  /* Automatically answer the default value if the user did not want
     prompts or the command was issued with the server prefix.  */
  if (!confirm || server_command)
    return def_value;

So, it relies on the server_command global to be set when the "server "
command prefix is used, which is no longer the case since the following
commit:

    commit b69d38afde
    Date:   Wed Mar 9 18:25:00 2016 +0000
    Subject: Command line input handling TLC

The patch was simplifying the handling for the command line, and
I believe there was just a small oversight of removing the setting
of the server_command global.

This patch restores that, and adds a testcase to make sure we test
that feature.

gdb/ChangeLog:

        * event-top.c (handle_line_of_input): Set server_command.

gdb/testsuite/ChangeLog:

        * gdb.base/server-del-break.c: New file.
        * gdb.base/server-del-break.exp: New file.

Tested on x86_64-linux, no regression.
2017-12-12 22:23:19 -05:00
Stafford Horne c3d186206b gdb: testsuite: Add or1k l.nop instruction
The test case requires adding a nop instruction.  For or1k the
instruction is `l.nop`. This change uses the correct operation.

gdb/testsuite/ChangeLog:

2017-12-12  Stafford Horne  <shorne@gmail.com>

	* gdb.base/bp-permanent.c: Define nop of or1k.
2017-12-12 23:37:04 +09:00
Jan Kratochvil 927aa2e778 DWARF-5: .debug_names index consumer
Some testcases needed to be updated as they were missing
.debug_aranges.  While that does not matter for no-index (as GDB
builds the mapping internally during dwarf2_build_psymtabs_hard) and
neither for .gdb_index (as GDB uses that internally built mapping
which it stores into .gdb_index) it does matter for .debug_names as
that simply assumes existing .debug_aranges from GCC.

gdb/ChangeLog:
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* defs.h (elf_sym_fns_debug_names): New declaration.
	* dwarf2read.c: Include "hash_enum.h".
	(mapped_debug_names): New.
	(struct dwarf2_per_objfile): Add debug_names, debug_aranges and
	debug_names_table.
	(dwarf2_elf_names): Add ".debug_names" and ".debug_aranges".
	(struct dwz_file): Add debug_names.
	(dwarf2_per_objfile::locate_sections): Handle debug_names and
	debug_aranges.
	(locate_dwz_sections): Handle debug_names.
	(create_signatured_type_table_from_debug_names)
	(create_addrmap_from_aranges): New.
	(dwarf2_read_index): Update function comment.
	(dwarf5_augmentation): Moved up.
	(read_debug_names_from_section, create_cus_from_debug_names_list)
	(create_cus_from_debug_names, dwarf2_read_debug_names): New.
	(dwarf5_djb_hash): Moved up.
	(dw2_debug_names_iterator): New.
	(read_indirect_string_at_offset): New declaration.
	(mapped_debug_names::namei_to_name)
	(dw2_debug_names_iterator::find_vec_in_debug_names)
	(dw2_debug_names_iterator::next, dw2_debug_names_lookup_symbol)
	(dw2_debug_names_dump, dw2_debug_names_expand_symtabs_for_function)
	(dw2_debug_names_expand_symtabs_matching, dwarf2_debug_names_functions):
	New.
	(dwarf2_initialize_objfile): Return also elf_sym_fns_debug_names.
	(debug_names::djb_hash): Rename it to dwarf5_djb_hash.
	(debug_names::build): Update djb_hash caller.
	(write_debug_names): Move out and rename augmentation to
	dwarf5_augmentation.
	* elfread.c (elf_sym_fns_debug_names): New.
	* psymtab.h (dwarf2_debug_names_functions): New declaration.
	* symfile.h (struct dwarf2_debug_sections): Add debug_names and
	debug_aranges.
	* xcoffread.c (dwarf2_xcoff_names): Add debug_names and debug_aranges.

gdb/testsuite/ChangeLog:
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/maint.exp (check for .gdb_index): Check also for
	.debug_names.
	* gdb.dlang/watch-loc.c (.debug_aranges): New.
	* gdb.dwarf2/dw2-case-insensitive-debug.S: Likewise.
	* gdb.dwarf2/gdb-index.exp (check if index present, .gdb_index used)
	(.gdb_index used after symbol reloading): Support also .debug_names.
	* gdb.mi/dw2-ref-missing-frame-func.c (.debug_aranges): New.
2017-12-08 23:37:31 +00:00
Tom Tromey 99598d713f Fix regression in "commands"
Pedro pointed out a regression in "commands", where trying to clear a
breakpoint's command list would fail:

    (top-gdb) commands
    Type commands for breakpoint(s) 3, one per line.
    End with a line saying just "end".
    >end
    No breakpoints specified.
    (top-gdb)

I believe the bug was introduced by my patch that changes
counted_command_line to be a shared_ptr.  This causes the problem
because now the counted_command_line in commands_command_1 can be NULL,
whereas previously it never could be.

After some discussion, we agreed to simply remove the error case from
commands_command_1.

2017-12-07  Tom Tromey  <tom@tromey.com>

	PR breakpoints/22511:
	* breakpoint.c (commands_command_1): Don't throw an exception when
	no commands have been read.

2017-12-07  Tom Tromey  <tom@tromey.com>

	* gdb.base/break.exp: Add test for empty "commands".
2017-12-07 14:52:20 -07:00
Sergio Lopez 3e1a70a018 Extend gdb.core/coredump-filter.exp to test dump-excluded-mappings.
gdb/testsuite/ChangeLog:
2017-11-30  Sergio Lopez  <slp@redhat.com>

	* gdb.core/coredump-filter.exp: Extend test to verify
	the functionality of the dump-excluded-mappings command.
2017-12-04 12:05:58 -05:00
Sergio Durigan Junior 97cbe998d0 Add support for the readnever concept
The purpose of this concept is to turn the load of debugging
information off, either globally (via the '--readnever' option), or
objfile-specific.  The implementation proposed here is an extension of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature is when a user simply wants to do the
following sequence: attach, dump core, detach.  Loading the debugging
information in this case is an unnecessary cause of delay.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.

Tested on the BuildBot.

gdb/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* coffread.c (coff_symfile_read): Do not map over sections with
	'coff_locate_sections' if readnever is on.
	* dwarf2read.c (dwarf2_has_info): Return 0 if
	readnever is on.
	* elfread.c (elf_symfile_read): Do not map over sections with
	'elf_locate_sections' if readnever is on.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(_initialize_symfile): Document new '-readnever' option for
	both 'symbol-file' and 'add-symbol-file' commands.
	* top.h (readnever_symbol_files): New extern global.
	* xcoffread.c (xcoff_initial_scan): Do not read debug
	information if readnever is on.

gdb/doc/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file' and
	'add-symbol-file'.

gdb/testsuite/ChangeLog:

2017-12-01  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
2017-12-01 21:28:31 -05:00
Sergio Durigan Junior 40fc416f4e Make '{add-,}symbol-file' not care about the position of command line arguments
This is a bug that's been detected while doing the readnever work.

If you use 'symbol-file' or 'add-symbol-file', the position of each
argument passed to the command matters.  This means that if you do:

  (gdb) symbol-file -readnow /foo/bar

The symbol file specified will (correctly) have all of its symbols
read by GDB (because of the -readnow flag).  However, if you do:

  (gdb) symbol-file /foo/bar -readnow

GDB will silently ignore the -readnow flag, because it was specified
after the filename.  This is not a good thing to do and may confuse
the user.

To address that, I've modified the argument parsing mechanisms of
symbol_file_command and add_symbol_file_command to be
"position-independent".  I have also added one error call at the end
of add_symbol_file_command's argument parsing logic, which now clearly
complains if no filename has been specified.  Both commands now
support the "--" option to stop argument processing.

This patch provides a testcase for both commands, in order to make
sure that the argument order does not matter.  It has been
regression-tested on BuildBot.

gdb/ChangeLog:

2017-12-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* symfile.c (symbol_file_command): Call
	'symbol_file_add_main_1' only after processing all command
	line options.
	(add_symbol_file_command): Modify logic to make arguments
	position-independent.

gdb/testsuite/ChangeLog:

2017-12-01  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/relocate.exp: Add tests to guarantee that arguments
	to 'symbol-file' and 'add-symbol-file' can be
	position-independent.
2017-12-01 17:01:24 -05:00
Sergio Durigan Junior 7f0f8ac8b1 Revert "Add support for the readnever concept"
This reverts commit e2e321740c.

It was mistakenly pushed.
2017-12-01 16:58:47 -05:00
Sergio Durigan Junior e2e321740c Add support for the readnever concept
The purpose of this concept is to turn the load of debugging
information off, either globally (via the '--readnever' option), or
objfile-specific.  The implementation proposed here is an extension of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature is when a user simply wants to do the
following sequence: attach, dump core, detach.  Loading the debugging
information in this case is an unnecessary cause of delay.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.

Tested on the BuildBot.

gdb/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* coffread.c (coff_symfile_read): Do not map over sections with
	'coff_locate_sections' if readnever is on.
	* dwarf2read.c (dwarf2_has_info): Return 0 if
	readnever is on.
	* elfread.c (elf_symfile_read): Do not map over sections with
	'elf_locate_sections' if readnever is on.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(_initialize_symfile): Document new '-readnever' option for
	both 'symbol-file' and 'add-symbol-file' commands.
	* top.h (readnever_symbol_files): New extern global.
	* xcoffread.c (xcoff_initial_scan): Do not read debug
	information if readnever is on.

gdb/doc/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file' and
	'add-symbol-file'.

gdb/testsuite/ChangeLog:

2017-12-01  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
2017-12-01 12:23:30 -05:00
Yao Qi 1cc75e929f Replace mail address with the URL in copyright header
The copyright header in most of GDB files were changed from mail address
to the URL in the conversion to GPLv3 in Aug 2007.  However, some files
still use mail address instead of the URL.  This patch fixes them.

gdb/testsuite:

2017-12-01  Yao Qi  <yao.qi@linaro.org>

	* gdb.arch/aarch64-atomic-inst.exp: Replace mail address with
	the URL in copyright header.
	* gdb.arch/aarch64-fp.exp: Likewise.
	* gdb.arch/ppc64-atomic-inst.exp: Likewise.
	* gdb.arch/ppc64-isa207-atomic-inst.exp: Likewise.
	* gdb.base/expand-psymtabs.exp: Likewise.
	* gdb.cp/expand-psymtabs-cxx.exp: Likewise.
	* gdb.fortran/common-block.exp: Likewise.
	* gdb.fortran/common-block.f90: Likewise.
	* gdb.fortran/logical.exp: Likewise.
	* gdb.fortran/vla-datatypes.f90: Likewise.
	* gdb.fortran/vla-sub.f90: Likewise.
2017-12-01 11:34:14 +00:00
Pedro Alves a20714ff39 Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching]
This patch teaches GDB about setting breakpoints in all scopes
(namespaces and classes) by default.

Here's a contrived example:

  (gdb) b func<tab>
  (anonymous namespace)::A::function()            Bn::(anonymous namespace)::B::function()        function(int, int)
  (anonymous namespace)::B::function()            Bn::(anonymous namespace)::function()           gdb::(anonymous namespace)::A::function()
  (anonymous namespace)::B::function() const      Bn::(anonymous namespace)::function(int, int)   gdb::(anonymous namespace)::function()
  (anonymous namespace)::function()               Bn::B::func()                                   gdb::(anonymous namespace)::function(int, int)
  (anonymous namespace)::function(int, int)       Bn::B::function()                               gdb::A::func()
  A::func()                                       Bn::func()                                      gdb::A::function()
  A::function()                                   Bn::function()                                  gdb::func()
  B::func()                                       Bn::function(int, int)                          gdb::function()
  B::function()                                   Bn::function(long)                              gdb::function(int, int)
  B::function() const                             func()                                          gdb::function(long)
  B::function_const() const                       function()
  (gdb) b function
  Breakpoint 1 at 0x4005ce: function. (26 locations)

  (gdb) b B::function<tab>
  (anonymous namespace)::B::function()        B::function() const                         Bn::B::function()
  (anonymous namespace)::B::function() const  B::function_const() const
  B::function()                               Bn::(anonymous namespace)::B::function()
  (gdb) b B::function
  Breakpoint 1 at 0x40072c: B::function. (6 locations)

To get back the original behavior of interpreting the function name as
a fully-qualified name, you can use the new "-qualified" (or "-q")
option/flag (added by this commit).  For example:

 (gdb) b B::function
 (anonymous namespace)::B::function()        B::function() const                         Bn::B::function()
 (anonymous namespace)::B::function() const  B::function_const() const
 B::function()                               Bn::(anonymous namespace)::B::function()

vs:

 (gdb) b -qualified B::function
 B::function()              B::function() const        B::function_const() const

I've chosen "-qualified" / "-q" because "-f" (for "full" or
"fully-qualified") is already taken for "-function".

Note: the "-qualified" option works with both linespecs and explicit
locations.  I.e., these are equivalent:

 (gdb) b -q func
 (gdb) b -q -f func

and so are these:

 (gdb) b -q filename.cc:func
 (gdb) b -q -s filename.cc -f func
 (gdb) b -s filename.cc -q -f func
 (gdb) b -s filename.cc -f func -q

To better understand why I consider wild matching the better default,
consider what happens when we get to the point when _all_ of GDB is
wrapped under "namespace gdb {}".  I have a patch series that does
that, and when I started debugging that GDB, I immediately became
frustrated.  You'd have to write "b gdb::internal_error", "b
gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty
quickly.  OTOH, consider how this makes it very easy to set
breakpoints in classes wrapped in anonymous namespaces.  You just
don't think of them, GDB finds the symbols for you automatically.

(At the Cauldron a couple months ago, several people told me that they
run into a similar issue when debugging other C++ projects.  One
example was when debugging LLVM, which puts all its code under the
"llvm" namespace.)

Implementation-wise, what the patch does is:

  - makes C++ symbol name hashing only consider the last component of
    a symbol name. (so that we can look up symbol names by
    last-component name only).

  - adds a C++ symbol name matcher for symbol_name_match_type::WILD,
    which ignores missing leading specifiers / components.

  - adjusts a few preexisting testsuite tests to use "-qualified" when
    they mean it.

  - adds new testsuite tests.

  - adds unit tests.

Grows the gdb.linespec/ tests like this:

  -# of expected passes           7823
  +# of expected passes           8977

gdb/ChangeLog:
2017-11-29  Pedro Alves  <palves@redhat.com>

	* NEWS: Mention that breakpoints on C++ functions are now set on
	on all namespaces/classes by default, and mention "break
	-qualified".
	* ax-gdb.c (agent_command_1): Adjust to pass a
	symbol_name_match_type to new_linespec_location.
	* breakpoint.c (parse_breakpoint_sals): Adjust to
	get_linespec_location's return type change.
	(strace_marker_create_sals_from_location): Adjust to pass a
	symbol_name_match_type to new_linespec_location.
	(strace_marker_decode_location): Adjust to get_linespec_location's
	return type change.
	(strace_command): Adjust to pass a symbol_name_match_type to
	new_linespec_location.
	(LOCATION_HELP_STRING): Add paragraph about wildmatching, and
	mention "-qualified".
	* c-lang.c (cplus_language_defn): Install cp_search_name_hash.
	* completer.c (explicit_location_match_type::MATCH_QUALIFIED): New
	enumerator.
	(complete_address_and_linespec_locations): New parameter
	'match_type'.  Pass it down.
	(explicit_options): Add "-qualified".
	(collect_explicit_location_matches): Pass the requested match type
	to the linespec completers.  Handle MATCH_QUALIFIED.
	(location_completer): Handle "-qualified" combined with linespecs.
	* cp-support.c (cp_search_name_hash): New.
	(cp_symbol_name_matches_1): Implement wild matching for C++.
	(cp_fq_symbol_name_matches): Reimplement.
	(cp_get_symbol_name_matcher): Return different matchers depending
	on the lookup name's match type.
	(selftests::test_cp_symbol_name_matches): Add wild matching tests.
	* cp-support.h (cp_search_name_hash): New declaration.
	* dwarf2read.c
	(selftests::dw2_expand_symtabs_matching::test_symbols): Add
	symbols.
	(test_dw2_expand_symtabs_matching_symbol): Add wild matching
	tests.
	* guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to
	pass a symbol_name_match_type to new_linespec_location.
	* linespec.c (linespec_parse_basic): Lookup function symbols using
	the parser's symbol name match type.
	(convert_explicit_location_to_linespec): New
	symbol_name_match_type parameter.  Pass it down to
	find_linespec_symbols.
	(convert_explicit_location_to_sals): Pass the location's name
	match type to convert_explicit_location_to_linespec.
	(parse_linespec): New match_type parameter.  Save it in the
	parser.
	(linespec_parser_new): Default to symbol_name_match_type::WILD.
	(linespec_complete_function): New symbol_name_match_type
	parameter.  Use it.
	(complete_linespec_component): Pass down the parser's recorded
	name match type.
	(linespec_complete_label): New symbol_name_match_type parameter.
	Use it.
	(linespec_complete): New symbol_name_match_type parameter.  Save
	it in the parser and pass it down.  Adjust to
	get_linespec_location's prototype change.
	(find_function_symbols, find_linespec_symbols): New
	symbol_name_match_type parameter.  Pass it down instead of
	assuming symbol_name_match_type::WILD.
	* linespec.h (linespec_complete, linespec_complete_function)
	(linespec_complete_label): New symbol_name_match_type parameter.
	* location.c (event_location::linespec_location): Now a struct
	linespec_location.
	(EL_LINESPEC): Adjust.
	(initialize_explicit_location): Default to
	symbol_name_match_type::WILD.
	(new_linespec_location): New symbol_name_match_type parameter.
	Record it in the location.
	(get_linespec_location): Now returns a struct linespec_location.
	(new_explicit_location): Also copy func_name_match_type.
	(explicit_to_string_internal)
	(string_to_explicit_location): Handle "-qualified".
	(copy_event_location): Adjust to LINESPEC_LOCATION type change.
	Copy symbol_name_match_type fields.
	(event_location_deleter::operator()): Adjust to LINESPEC_LOCATION
	type change.
	(event_location_to_string): Adjust to LINESPEC_LOCATION type
	change.  Handle "-qualfied".
	(string_to_explicit_location): Handle "-qualified".
	(string_to_event_location_basic): New symbol_name_match_type
	parameter.  Pass it down.
	(string_to_event_location): Handle "-qualified".
	* location.h (struct linespec_location): New.
	(explicit_location::func_name_match_type): New field.
	(new_linespec_location): Now returns a const linespec_location *.
	(string_to_event_location_basic): New symbol_name_match_type
	parameter.
	(explicit_completion_info::saw_explicit_location_option): New
	field.
	* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a
	symbol_name_match_type to new_linespec_location.
	* python/py-breakpoint.c (bppy_init): Likewise.
	* python/python.c (gdbpy_decode_line): Likewise.

gdb/testsuite/ChangeLog:
2017-11-29  Pedro Alves  <palves@redhat.com>

	* gdb.base/langs.exp: Use -qualified.
	* gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without
	it.
	* gdb.cp/namespace.exp: Use -qualified.
	* gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2)
	(overload-3, template-overload, template-ret-type, const-overload)
	(const-overload-quoted, anon-ns, ambiguous-prefix): New
	procedures.
	(test_driver): Call them.
	* gdb.cp/save-bp-qualified.cc: New.
	* gdb.cp/save-bp-qualified.exp: New.
	* gdb.linespec/explicit.exp: Test -qualified.
	* lib/completion-support.exp (completion::explicit_opts_list): Add
	"-qualified".
	* lib/gdb.exp (gdb_breakpoint): Handle "qualified".

gdb/doc/ChangeLog:
2017-11-29  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Linespec Locations): Document how "function" is
	interpreted in C++ and Ada.  Document "-qualified".
	(Explicit Locations): Document how "-function" is interpreted in
	C++ and Ada.  Document "-qualified".
2017-11-29 19:43:48 +00:00
Tom Tromey 02ca603a48 Fix add-symbol-file usage and errors
This patch updates add-symbol-file help and error text.

It changes add-symbol-file to throw an exception if "-s" is seen but
not all of the arguments are given.  Previously this was silently
ignored.

It changes the unrecognized argument message to more clearly state
what went wrong.

Finally, it updates the usage line in the help text to follow GNU
style regarding "metasyntactic variables"; a change I believe should
be made to all gdb help messages.

gdb/ChangeLog
2017-11-29  Tom Tromey  <tom@tromey.com>

	* symfile.c (add_symbol_file_command): Error if some arguments to
	-s are missing.  Change unrecognized-argument error message.
	(_initialize_symfile): Fix usage text for add-symbol-file.

gdb/testsuite/ChangeLog
2017-11-29  Tom Tromey  <tom@tromey.com>

	* gdb.base/relocate.exp: Update invalid argument test.
	Add new tests for invalid arguments.
2017-11-29 09:21:43 -07:00
Pedro Alves a81aaca057 Fix completing an empty string
Earlier while working on the big completer rework series, I managed to
break

 (gdb) [TAB]

locally, and make GDB crash, but only notice a few weeks down the
road, because we have no test for that...

I also noticed that:

 (gdb)     [TAB]

didn't work (didn't show all commands as matches), even though
entering a command with leading whitespace works:

 (gdb)     help

This commit fixes the latter and adds a testcase that covers both
issues.

The gdb.base/completion.exp change is necessary because the new test
has a file name that also starts with "gdb.base/complet", making that
particular test ambiguous.  Adding another letter disambiguates.

gdb/ChangeLog:
2017-11-25   Pedro Alves  <palves@redhat.com>

	* completer.c (complete_line_internal_1): Skip spaces until the
	start of the command.

gdb/testsuite/ChangeLog:
2017-11-25   Pedro Alves  <palves@redhat.com>

	* gdb.base/complete-empty.exp: New file.
	* gdb.base/completion.exp: Adjust.
2017-11-25 00:20:31 +00:00
Yao Qi 7c3c1aa885 [testsuite] Pass -g3 to clang in gdb.base/macscp.exp
clang accepts option -g3 too.  I checked the manual of xlc and icc, looks
they don't accept -g3 option, so I don't pass -g3 for them.

gdb/testsuite:

2017-11-23  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/macscp.exp: Append -g3 to additional_flags for clang.
2017-11-23 15:31:13 +00:00
Yao Qi 1daad298d6 [testsuite] Pass pthreads in prepare_for_testing
"pthreads" in the right flag to pass in prepare_for_testing to linker,
instead of additional_flags.  Without this patch, the test case can't be
complied by clang.

gdb compile failed, clang: warning: -lpthread: 'linker' input unused

gdb/testsuite:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/info-os.exp: Pass pthreads.
	* gdb.multi/multi-attach.exp: Likewise.
2017-11-22 16:50:53 +00:00
Yao Qi dc196b230b [testsuite] Pass -pie in ldflags
-pie is a linker flag, it should be passed via "ldflags", instead
of "additional_flags".  Otherwise, clang complains,

clang: warning: argument unused during compilation: '-pie'

gdb/testsuite:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/attach-pie-noexec.exp: Pass "-pie" in ldflags.
	* gdb.base/break-interp.exp: Likewise.
	* gdb.base/jit-attach-pie.exp: Likewise.
2017-11-22 14:35:01 +00:00
Ulrich Weigand 2400729ecf Target FP: Make use of MPFR if available
This second patch introduces mfpr_float_ops, an new implementation
of target_float_ops.  This implements precise emulation of target
floating-point formats using the MPFR library.  This is then used
to perform operations on types that do not match any host type.

Note that use of MPFR is still not required.  The patch adds
a configure option --with-mpfr similar to --with-expat.  If use of
MPFR is disabled via the option or MPFR is not available, code will
fall back to current behavior.  This means that operations on types
that do not match any host type will be implemented on the host
long double type instead.

A new test case verifies that we can correctly print the largest
__float128 value now.

gdb/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* NEWS: Document use of GNU MPFR.
	* README: Likewise.

	* Makefile.in (LIBMPFR): Add define.
	(CLIBS): Add $(LIBMPFR).
	* configure.ac: Add --with-mpfr configure option.
	* configure: Regenerate.
	* config.in: Regenerate.

	* target-float.c [HAVE_LIBMPFR]: Include <mpfr.h>.
	(class mpfr_float_ops): New type.
	(mpfr_float_ops::from_target): Two new overloaded functions.
	(mpfr_float_ops::to_target): Likewise.
	(mpfr_float_ops::to_string): New function.
	(mpfr_float_ops::from_string): Likewise.
	(mpfr_float_ops::to_longest): Likewise.
	(mpfr_float_ops::from_longest): Likewise.
	(mpfr_float_ops::from_ulongest): Likewise.
	(mpfr_float_ops::to_host_double): Likewise.
	(mpfr_float_ops::from_host_double): Likewise.
	(mpfr_float_ops::convert): Likewise.
	(mpfr_float_ops::binop): Likewise.
	(mpfr_float_ops::compare): Likewise.
	(get_target_float_ops): Use mpfr_float_ops if available.

gdb/doc/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.texinfo (Requirements): Document use of GNU MPFR.

gdb/testsuite/ChangeLog:
2017-11-22  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.base/float128.c (large128): New variable.
	* gdb.base/float128.exp: Add test to print largest __float128 value.
2017-11-22 13:53:43 +01:00
Pedro Alves 73fcf6418d Fix gdb.base/whatis-ptype-typedefs.exp on 32-bit archs
The gdb.base/whatis-ptype-typedefs.exp testcase has several tests that
fail on 32-bit architectures.  E.g., on 'x86-64 -m32', I see:

 ...
 FAIL: gdb.base/whatis-ptype-typedefs.exp: lang=c: cast: whatis (float_typedef) v_uchar_array_t_struct_typedef (invalid)
 FAIL: gdb.base/whatis-ptype-typedefs.exp: lang=c: cast: ptype (float_typedef) v_uchar_array_t_struct_typedef (invalid)
 ...

gdb.log:

 (gdb) whatis (float_typedef) v_uchar_array_t_struct_typedef
 type = float_typedef
 (gdb) FAIL: gdb.base/whatis-ptype-typedefs.exp: lang=c: cast: whatis (float_typedef) v_uchar_array_t_struct_typedef (invalid)

As Simon explained [1], the issue boils down to the fact that on
64-bit, this is an invalid cast:

 (gdb) p (float_typedef) v_uchar_array_t_struct_typedef
 Invalid cast.

while on 32 bits it is valid:

 (gdb) p (float_typedef) v_uchar_array_t_struct_typedef
 $1 = 1.16251721e-41

The expression basically tries to cast an array (which decays to a
pointer) to a float.  The cast works on 32 bits because a float and a
pointer are of the same size, and value_cast works in that case:

~~~
   More general than a C cast: accepts any two types of the same length,
   and if ARG2 is an lvalue it can be cast into anything at all.  */
~~~

On 64 bits, they are not the same size, so it ends throwing the
"Invalid cast" error.

The testcase is expecting the invalid cast behavior, thus the FAILs.

A point of these tests was to cover as many code paths in value_cast
as possible, as a sort of documentation of the current behavior:

    # The main idea here is testing all the different paths in the
    # value casting code in GDB (value_cast), making sure typedefs are
    # preserved.
...
    # We try all combinations, even those that don't parse, or are
    # invalid, to catch the case of a regression making them
    # inadvertently valid.  For example, these convertions are
    # invalid:
...

In that spirit, this commit makes the testcase adjust itself depending
on size of floats and pointers, and also test floats of different
sizes.

Passes cleanly on x86-64 GNU/Linux both -m64/-m32.

[1] - https://sourceware.org/ml/gdb-patches/2017-11/msg00382.html

gdb/ChangeLog:
2017-11-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/whatis-ptype-typedefs.c (double_typedef)
	(long_double_typedef): New typedefs.
	Use DEF on double and long double.
	* gdb.base/whatis-ptype-typedefs.exp: Add double and long double
	cases.
	(run_tests): New 'float_ptr_same_size', 'double_ptr_same_size',
	and 'long_double_ptr_same_size' locals.  Use them to decide
	whether cast from array/function to float is valid/invalid.
2017-11-20 23:03:17 +00:00
Pedro Alves a0922d80df Test breakpoint commands w/ "continue" + Ctrl-C
This adds the testcase that exposed the multiple problems with Ctrl-C
handling fixed by the previous patches, when run against both native
and gdbserver GNU/Linux.

gdb/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* gdb.base/bp-cmds-continue-ctrl-c.c: New file.
	* gdb.base/bp-cmds-continue-ctrl-c.exp: New file.
2017-11-16 18:44:44 +00:00
Pedro Alves 968a13f836 Fix gdb.base/starti.exp racy test
This commit fixes a couple problems with gdb.base/starti.exp, causing
spurious FAILs.

The first is a double-prompt problem:

~~~
 (gdb) PASS: gdb.base/starti.exp: hook-stop
 starti
 [....]
 gdb_expect_list pattern: /\$1 = 0/
 $1 = 0

 gdb_expect_list pattern: //
 0x00007ffff7ddcc80 in _start () from /lib64/ld-linux-x86-64.so.2

 (gdb)                                         # EXPECTED PROMPT
 (gdb) PASS: gdb.base/starti.exp: starti       # ANOTHER PROMPT!
 break main
~~~

This happens because the test uses gdb_test_sequence with no command,
like this:

 gdb_test_sequence "" "starti" {
     "Program stopped."
     "\\$1 = 0"
 }

but gdb_test_sequence doesn't have a check for empty command like
gdb_test_multiple does, and so sends "\n" to GDB:

 proc gdb_test_sequence { command test_name expected_output_list } {
     global gdb_prompt
     if { $test_name == "" } {
	 set test_name $command
     }
     lappend expected_output_list ""; # implicit ".*" before gdb prompt
     send_gdb "$command\n"
     return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
 }

"starti" is a no-repeat command, so pressing <ret> just makes another
prompt appear, confusing the following gdb_test/gdb_test_multiple/etc.

Even with that fixed, the testcase is still racy though.

The second problem is that sometimes the "continue" test times out
here:

~~~
 continue
 Continuing.
 $2 = 1


 gdb_expect_list pattern: /.*Breakpoint .*main \(\) at .*starti.c.*/
 Breakpoint 1, main () at /home/pedro/src/gdb/testsuite/gdb.base/starti.c:29
 29	  return 0;
 (gdb) gdb_expect_list pattern: //
 * hung here *
~~~

The problem is that the too-greedy ".*" trailing match in
gdb_expect_list's pattern ends up consuming GDB's prompt too soon.
Fix that by removing the unnecessary trailing ".*".  While at it,
remove all ".*"s to be stricter.

Tested on x86_64 GNU/Linux.

gdb/testsuite/ChangeLog:
2017-11-16  Pedro Alves  <palves@redhat.com>

	* gdb.base/starti.exp ("continue" test): Remove ".*"s from
	pattern.
	* lib/gdb.exp (gdb_test_sequence): Don't send empty command to
	GDB.
2017-11-16 11:57:01 +00:00
Pedro Alves 2c88253fc4 Fix racy output matching in gdb.base/memattr.exp
Testing with:
 $ make check-read1 TESTS="gdb.base/memattr.exp"


Exposes a testcase bug that can result in racy fails:

  info mem
  Using user-defined memory regions.
  Num Enb Low Addr           High Addr          Attrs
  1   y   0x0000000000601060 0x0000000000601160 wo nocache
  2   y   0x0000000000601180 0x0000000000601280 ro nocache
  4   y   0x0000000000601280 0x0000000000601380 rw nocache
  3   y   0x0000000000601380 0x0000000000601480 rw nocache
  5   y   0x0000000000601480 0x0000000000601580 rw nocache
  (gdb) FAIL: gdb.base/memattr.exp: info mem (1)

The problem is that:

  "Attrs\[^\n\r]*.."

matches:

  "Attrs \r"

when the output buffer is filled with partial output like this:

  "info mem\r\nUsing user-defined memory regions.\r\nNum Enb Low Addr           High Addr          Attrs \r"

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.base/memattr.exp: Tighten regexes to match the end line.
2017-11-09 22:45:39 +00:00
Pedro Alves c7a3851716 Fix racy output matching in gdb.base/completion.exp
Testing with:
 $ make check-read1 TESTS="gdb.base/completion.exp"

Exposes a testcase bug that can result in racy fails:

  FAIL: gdb.base/completion.exp: command-name completion limiting using tab character
  ERROR: Undefined command "".
  FAIL: gdb.base/completion.exp: symbol-name completion limiting using tab character
  FAIL: gdb.base/completion.exp: symbol-name completion limiting using complete command

testsuite/gdb.log shows:

  (gdb) PASS: gdb.base/completion.exp: set max-completions 5
  p^G
  passcount     path          print         print-object  printf
  *** List may be truncated, max-completions reached. ***
  (gdb) FAIL: gdb.base/completion.exp: command-name completion limiting using tab character
  pcomplete p
  Undefined command: "pcomplete".  Try "help".
  (gdb) ERROR: Undefined command "".

The problem is that the expect buffer can get filled with partial
output that ends in the gdb prompt, and so the default FAIL inside
gdb_test_multiple matches.

Fix that by splitting the gdb_test_multiple in two stages.  Since that
is done in more than one place in the testcase, move the otherwise
duplicate code to helper procedures.

gdb/testsuite/ChangeLog:
2017-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.base/completion.exp (ignore_and_resync, test_tab_complete):
	New procedures, factored out from ...
	(top level): ... here, and adjusted to avoid expecting beyond the
	prompt in one go.
2017-11-09 22:45:06 +00:00
Pedro Alves 95e95a6de2 Make breakpoint/location number parsing error output consistent
... and also make GDB catch a few more cases of invalid input.

This fixes the inconsistency in GDB's output (e.g., "bad" vs "Bad")
exposed by the new tests added in the previous commit.

Also, makes the "0-0" and "inverted range" cases be loud errors.

Also makes GDB reject negative breakpoint number in ranges.  We
already rejected negative number literals, but you could still subvert
that via convenience variables, like:

  (gdb) set $bp -1
  (gdb) disable $bp.1-2

The change to get_number_trailer fixes a bug exposed by the new tests.
The function did not handle parsing "-$num".  [This wasn't visible in
the gdb.multi/tids.exp (which has similar tests) because the TID range
parsing is implemented differently.]

gdb/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (extract_bp_kind): New enum.
	(extract_bp_num, extract_bp_or_bp_range): New functions, partially
	factored out from ...
	(extract_bp_number_and_location): ... here.
	* cli/cli-utils.c (get_number_trailer): Handle '-$variable'.

gdb/testsuite/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/ena-dis-br.exp (test_ena_dis_br): Adjust test.
	* gdb.cp/ena-dis-br-range.exp: Adjust tests.
	(disable_invalid, disable_inverted, disable_negative): New
	procedures.
	("bad numbers"): New set of tests.
2017-11-07 11:07:19 +00:00
Pedro Alves cc638e867c Breakpoint location parsing: always error instead of warning
It's odd that when parsing a breakpoint or location number, we error out
in most cases, but warn in others.

  (gdb) disable 1-
  bad breakpoint number at or near: '1-'
  (gdb) disable -1
  bad breakpoint number at or near: '-1'
  (gdb) disable .foo
  bad breakpoint number at or near: '.foo'
  (gdb) disable foo.1
  Bad breakpoint number 'foo.1'
  (gdb) disable 1.foo
  warning: bad breakpoint number at or near '1.foo'

This changes GDB to always error out.  It required touching one testcase
that expected the warning.

gdb/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (extract_bp_number_and_location): Change return
	type to void.  Throw error instead of warning.
	(enable_disable_command): Adjust.

gdb/testsuite/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/ena-dis-br.exp: Don't expect "warning:".
2017-11-07 11:06:00 +00:00
Xavier Roirand d0fe47010f Allow enabling/disabling breakpoint location ranges
When a breakpoint has multiple locations, like e.g.:

 Num  Type       Disp Enb  Address    What
 1    breakpoint keep y    <MULTIPLE>
 1.1                  y    0x080486a2 in void foo<int>()...
 1.2                  y    0x080486ca in void foo<double>()...
 [....]
 1.5                  y    0x080487fa in void foo<long>()...

it's possible to enable/disable the individual locations using the
'<breakpoint_number>.<location_number>' syntax, like e.g.:

 (gdb) disable 1.2 1.3 1.4 1.5

That's inconvenient when you have a long list of locations to disable,
however.

This patch adds shorthand for the above, by making it possible to
specify a range of locations with the following syntax (similar to
thread id ranges):

 <breakpoint_number>.<first_location_number>-<last_location_number>

For example, the command above can now be simplified to:

 (gdb) disable 1.2-5

gdb/ChangeLog:
2017-11-07  Xavier Roirand  <roirand@adacore.com>
	    Pedro Alves  <palves@redhat.com>

	* breakpoint.c (map_breakpoint_number_range): New, factored out
	from ...
	(map_breakpoint_numbers): ... here.
	(find_location_by_number): Change parameters from string to
	breakpoint number and location.
	(extract_bp_number_and_location): New function.
	(enable_disable_bp_num_loc)
	(enable_disable_breakpoint_location_range)
	(enable_disable_command): New functions, factored out ...
	(enable_command, disable_command): ... these functions, and
	adjusted to support ranges.
	* NEWS: Document enable/disable breakpoint location range feature.

gdb/doc/ChangeLog:
2017-11-07  Xavier Roirand  <roirand@adacore.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Set Breaks): Document support for breakpoint
	location ranges in the enable/disable commands.

gdb/testsuite/ChangeLog:
2017-11-07  Xavier Roirand  <roirand@adacore.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/ena-dis-br.exp: Add reference to
	gdb.cp/ena-dis-br-range.exp.
	* gdb.cp/ena-dis-br-range.exp: New file.
	* gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 11:00:31 +00:00
Pedro Alves 46f67f80dd Test attaching to a process that isn't a process group leader
The patch at
<https://sourceware.org/ml/gdb-patches/2017-11/msg00039.html> was
proposing to add an assertion to child_terminal_init that turns out
would fail if you tried to attach to a process that isn't a process
group leader.

Since the testsuite failed to catch the problem, this commit adds a
new testcase that would catch it, like:

  (gdb) attach 12415
  Attaching to program: build/gdb/testsuite/outputs/gdb.base/attach-non-pgrp-leader/attach-non-pgrp-leader, process 12415
  src/gdb/inflow.c:180: internal-error: void child_terminal_init(target_ops*): Assertion `getpgid (inf->pid) == inf->pid' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) FAIL: gdb.base/attach-non-pgrp-leader.exp: child: attach to child (GDB internal error)

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

	* gdb.base/attach-non-pgrp-leader.c: New.
	* gdb.base/attach-non-pgrp-leader.exp: New.
2017-11-06 16:32:04 +00:00
Pedro Alves 792ccf005f Fix racy test in gdb.base/new-ui.exp
I noticed gdb.base/new-ui.exp failing once here with:

 FAIL: gdb.base/new-ui.exp: do_test: delete all breakpoints on extra console (got interactive prompt)
 FAIL: gdb.base/new-ui.exp: do_test: main console: next causes no spurious output on other console
 FAIL: gdb.base/new-ui.exp: do_test: main console: breakpoint hit reported on other console

The problem is 100% reproducible with check-read1:
  $ make check-read1 TESTS="gdb.*/new-ui.exp"

testsuite/gdb.log shows:
  delete
  Delete all breakpoints? (y or n) [answered Y; input not from terminal]
  (gdb) FAIL: gdb.base/new-ui.exp: do_test: delete all breakpoints on extra console (got interactive prompt)

This commit fixes the problem.

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.base/new-ui.exp (do_test): Split "delete all breakpoints on
	extra console" test in two stages.
2017-10-24 23:22:56 +01:00
Pedro Alves 10389c2c8b Fix unstable test names in gdb.base/startup-with-shell.exp
Currently, if you diff testsuite/gdb.sum of two builds in different
directories you see these spurious hunks:

  -PASS: gdb.base/startup-with-shell.exp: touch /home/pedro/gdb1/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/unique-file.unique-extension
  +PASS: gdb.base/startup-with-shell.exp: touch /home/pedro/gdb2/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/unique-file.unique-extension

  -PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = *.unique-extension: set args /home/pedro/gdb1/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension
  +PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = *.unique-extension: set args /home/pedro/gdb2/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension

  -PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = *.unique-extension: set args /home/pedro/gdb1/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension
  +PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = *.unique-extension: set args /home/pedro/gdb2/build/gdb/testsuite/outputs/gdb.base/startup-with-shell/*.unique-extension

Since the run_args arguments are already shown in the test prefix, we
can change the "set args" test name to literally "set args $run_args".
I.e., after this commit we'll show:

  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = *.unique-extension: set args $run_args
  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = *.unique-extension: set args $run_args
  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = on; run_args = $TEST: set args $run_args
  PASS: gdb.base/startup-with-shell.exp: startup_with_shell = off; run_args = $TEST: set args $run_args

gdb/testsuite/ChangeLog:
2017-10-24  Pedro Alves  <palves@redhat.com>

	* gdb.base/startup-with-shell.exp ('touch $unique_file'): Don't
	include the unstable output directory name in the test's name.
	(initial_setup_simple) <'set args'>: Use custom test name.
2017-10-24 10:52:09 +01:00
Pedro Alves 15763a09d4 Fix 'gdb.base/quit.exp hangs forever' if the test fails
The [wait -i $gdb_spawn_id] in the test is dangerous in the sense that
it won't be subject to timeout logic.  So if GDB fails quiting, this
testcase hangs forever, hanging the test run with it.  See:
  https://sourceware.org/ml/gdb-patches/2016-10/msg00728.html

Instead of 'wait'ing directly, use gdb_test_multiple and expect 'eof'.

Tested that the testcase no longer hangs by hacking the test to send
"info threads" instead of "quit".

Tested with
  --target_board={unix, native-gdbserver,native-extended-gdbserver}
and tested with
  --host_board=local-remote-host
as well.

gdb/testsuite/ChangeLog:
2017-10-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/quit.exp: Use gdb_test_multiple and expect 'eof' before
	'wait -i'.  Use gdb_assert and remote_close.
2017-10-20 15:33:57 +01:00
Pedro Alves a75868f50b Fix inferior deadlock with "target remote | CMD"
Comparing test results between

  --target_board=native-gdbserver
  --target_board=native-stdio-gdbserver

I noticed that gdb.base/bigcore.exp is failing with native-stdio-gdbserver:

  Running src/gdb/testsuite/gdb.base/bigcore.exp ...
  FAIL: gdb.base/bigcore.exp: continue (timeout)
  ...

The problem is that:

  1. When debugging with "target remote | CMD", the inferior's
     stdout/stderr streams are connected to a pipe.

  2. The bigcore.c program prints a lot to the screen before it
     reaches the breakpoint location that the "continue" shown above
     wants to reach.

  3. GDB is not flushing the inferior's output pipe while the inferior
     is running.

  4. The pipe becomes full.

  5. The inferior thus deadlocks.

The bug is #3 above, which is what this commit fixes.  A new test is
added, that specifically exercises this scenario.  The test fails
before the fix, and passes after, and gdb.base/bigcore.exp also starts
passing.

gdb/ChangeLog:
2017-10-19  Pedro Alves  <palves@redhat.com>

	* ser-base.c (ser_base_read_error_fd): Delete the file handler if
	async.
	(handle_error_fd): New function.
	(ser_base_async): Add/delete an event loop file handler for
	error_fd.

gdb/testsuite/ChangeLog:
2017-10-19  Pedro Alves  <palves@redhat.com>

	* gdb.base/long-inferior-output.c: New file.
	* gdb.base/long-inferior-output.exp: New file.
2017-10-19 16:00:21 +01:00
Pedro Alves 8484c95545 Add several "quit with live inferior" tests
In my multi-target branch, I had managed to break GDB exiting
successfuly in response to "quit" or SIGHUP/SIGTERM when:

 - you're debugging with "target extended-remote",
 - have more than one inferior loaded in gdb, some running, and at
   least one not running, and,
 - quit gdb with the inferior that is not running yet selected.

The testsuite still passed cleanly anyway.  I only noticed because I
was left with a bunch of core dumps in the gdb/testsuite/ directory --
the testsuite infrastructure closes GDB's pty after running each
testcase, which results in GDB getting a SIGHUP and should make GDB
exit gracefully.  If GDB crashes at that point though, there's no
indication about it in gdb.sum/gdb.log.

This commit adds a multitude of tests exercising quitting GDB with
live inferiors, some of which would have caught the problem.

gdb/testsuite/ChangeLog:
2017-10-17  Pedro Alves  <palves@redhat.com>

	* gdb.base/quit-live.c: New file.
	* gdb.base/quit-live.exp: New file.
2017-10-17 14:58:54 +01:00
Pedro Alves 300b6685f1 Skip a few tests on targets that can't use the "run" commmand.
These tests want to use raw "run", so skip them on targets that can't
do that.

Also adds a small utility procedure that clearly conveys intent instead of
explicitly checking use_gdb_stub in the testcases.

This makes sure these testcases continue to be skipped with
--target_board=native-gdbserver once that board stops setting
is_remote.

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

	* lib/gdb.exp (target_can_use_run_cmd): New procedure.
	* gdb.base/annota1.exp: Use it instead of is_remote.
	* gdb.base/annota3.exp: Use it instead of is_remote.
	* gdb.cp/annota2.exp: Use it instead of is_remote.
	* gdb.cp/annota3.exp: Use it instead of is_remote.
	* gdb.multi/bkpt-multi-exec.exp: Use it instead of is_remote.
2017-10-13 18:11:31 +01:00
Pedro Alves 50500caf81 Fix gdb.base/testenv.exp against --target_board=native-extended-gdbserver
Currently we get:

  Running ..../src/gdb/testsuite/gdb.base/testenv.exp ...
  FAIL: gdb.base/testenv.exp: test no TEST_GDB var
  FAIL: gdb.base/testenv.exp: test with one TEST_GDB var
  FAIL: gdb.base/testenv.exp: test with two TEST_GDB var
  FAIL: gdb.base/testenv.exp: test with one TEST_GDB var, after unset
  FAIL: gdb.base/testenv.exp: test with TEST_GDB_GLOBAL
  FAIL: gdb.base/testenv.exp: test with TEST_GDB_GLOBAL unset

The problem is that the testcase relies on stdio.  While we could fix
this for gdbserver by read output from inferior_spawn_id, a better fix
it to not rely on stdio at all.  That's what this commit does.
Instead, it reads variables off of the inferior to extract the
necessary information.

Along the way, most of the .exp file is reimplemented/cleaned up using
more modern mechanisms.  E.g., with_test_prefix, proc_with_prefix,
save_vars, etc.  Also, a missing check for "is_remote host" is added.

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

	* gdb.base/testenv.exp: Check use_gdb_stub instead of is_remote.
	(test_num_test_vars, run_and_count_vars, find_env)
	(test_set_unset_env, test_inherit_env_var): New procedures.
	(top level): Use them.
2017-10-13 17:50:19 +01:00
Pedro Alves 8b0553c18f Make gdb.base/find-unmapped.exp pass on remote targets
Currently, with --target_board=native-extended-gdbserver, we get:

  Running .../src/gdb/testsuite/gdb.base/find-unmapped.exp ...
  FAIL: gdb.base/find-unmapped.exp: find global_var_0, global_var_2, 0xff
  FAIL: gdb.base/find-unmapped.exp: find global_var_1, global_var_2, 0xff
  FAIL: gdb.base/find-unmapped.exp: find global_var_2, (global_var_2 + 16), 0xff

This commit makes the test pass there, and also enables in on
--target_board=native-gdbserver, and other remote targets.

I've filed PR gdb/22293 to track the missing-warning problem.

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

	PR gdb/22293
	* gdb.base/find-unmapped.exp: Don't skip if is_remote target.
	(top level): Move some tests to ...
	(test_not_found): ... this new procedure.
	(top level): Call it.
2017-10-13 16:34:50 +01:00
Pedro Alves 7594f62360 Fix gdb.base/term.exp on non-"target native" boards
With --target_board=native-extended-gdbserver, we get:

  Running .../src/gdb/testsuite/gdb.base/term.exp ...
  FAIL: gdb.base/term.exp: info terminal at breakpoint

  (gdb) info terminal
  No saved terminal information.

Fix it by running the test everywhere, and expecting different output
on non-native targets.

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

	* gdb.base/term.exp: Don't skip if is_remote target.  Instead,
	expect different "info terminal" output if testing with a
	non-native target.
2017-10-13 13:41:44 +01:00
Pedro Alves df479dc6e0 Tweak gdb.base/corefile.exp is_remote check
1. Otherwise, when we make native-gdbserver board no longer is_remote,
   we get:

  Running .../src/gdb/testsuite/gdb.base/corefile.exp ...
  ERROR: tcl error sourcing .../src/gdb/testsuite/gdb.base/corefile.exp.
  ERROR: gdbserver does not support attach 9327 without extended-remote
      while executing
  "error "gdbserver does not support $command without extended-remote""

  That's fixed by using can_spawn_for_attach instead.

2. The gdb_protocol check fixes this current problem with
   --target_board=extended-remote-gdbserver:

     Running .../src/gdb/testsuite/gdb.base/corefile.exp ...
     FAIL: gdb.base/corefile.exp: run: with core
     FAIL: gdb.base/corefile.exp: run: core file is cleared
     FAIL: gdb.base/corefile.exp: attach: with core
     FAIL: gdb.base/corefile.exp: attach: core file is cleared

   gdb.log:
     (...)
     attach 10859
     Don't know how to attach.  Try "help target".
     (...)

The fix for #2 alone would fix #1 too, but can_spawn_for_attach
expresses the requirement directly, so I still left it there.

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

	* gdb.base/corefile.exp (corefile_test_run): Skip if gdb_protocol
	is set.
	(corefile_test_attach): Likewise.  Check can_spawn_for_attach
	instead of is_remote.
2017-10-13 12:15:52 +01:00
Pedro Alves 23fb630af0 Fix is_remote check in gdb.base/remote.exp
1. Otherwise, when the native-gdbserver board stops setting is_remote,
   this test would stop running there.

2. Makes the test run with --target_board=native-extended-gdbserver
   too.

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

	* gdb.base/remote.exp: Check gdb_protocol instead of is_remote.
	(top level): Add comment.
2017-10-13 11:20:37 +01:00
Pedro Alves cc77b1dc33 gdb.base/remote.exp: Fix typo and add missing return
(Dropped 'u' while at it because we're supposed to prefer American
English spelling...)

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

	* gdb.base/remote.exp (top level): Fix comment typo and add
	missing return.
2017-10-13 11:14:16 +01:00
Pedro Alves 27c9e813f9 Make gdb.base/solib-nodir.exp work with --target_board=native-extended-gdbserver
Fixes:
 Running .../src/gdb/testsuite/gdb.base/solib-nodir.exp ...
 FAIL: gdb.base/solib-nodir.exp: library loaded

... by using the new "set cwd" command.

gdb/testsuite/ChangeLog:
2017-10-13  Pedro Alves  <palves@redhat.com>
	    Simon Marchi <simon.marchi@polymtl.ca>

	* gdb.base/solib-nodir.exp: Split is_remote and skip_shlib_tests
	calls and add comments.  Skip test if use_gdb_stub is set.
	(top level): Use "set cwd" command instead of "cd" command.
2017-10-13 10:29:30 +01:00
Pedro Alves 5e830d9807 Eliminate is_remote check in gdb.base/shlib-call.exp
gdb/testsuite/ChangeLog:
2017-10-13  Pedro Alves  <palves@redhat.com>

	* gdb.base/shlib-call.exp (top level): Use gdb_run_cmd and remove
	is_remote target check.
2017-10-13 10:22:09 +01:00
Pedro Alves f5ca00321d Eliminate is_remote check in gdb.base/scope.exp
This commit makes --target_board=native-gdbserver (and in principle
all other is_remote boards) pass all the same gdb.base/scope.exp tests
as native testing.

I first wrote the gdb.base/scope.exp change described in the ChangeLog
below and in the new comments in the patch, knowing that gdb_file_cmd
was the right thing to use here.

However, that revealed that the native-extended-gdbserver board should
be overriding gdb_file_cmd+gdb_reload instead of gdb_load, as is
hinted at by the comments on top of the default implementations in
testsuite/lib/gdb.exp, because otherwise a gdb_run_cmd after
gdb_file_cmd misses setting "set remote exec-file".  However, if we do
that and remove gdb_load, then we regress gdb.base/dbx.exp, so for now
keep the gdb_load override as well.

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

	* gdb.base/scope.exp: Use build_executable + clean_restart +
	gdb_file_cmd instead of prepare_for_testing and no longer skip
	"before run" tests on is_remote target boards.  Update comments.
	* boards/native-extended-gdbserver.exp
	(extended_gdbserver_load_last_file): New, factored out from ...
	(gdb_load): ... this.  Move further below and add comment.
	(extended_gdbserver_gdb_file_cmd, gdb_file_cmd, gdb_reload): New.
2017-10-13 01:27:18 +01:00
Pedro Alves 8aed1c0d04 Remove references to gdb64 in the testsuite
I'm not sure whether this gdb64 was ever a thing in the upstream repo,
but it certainly doesn't exist nowadays.

AFAICT, this came in with the original big merge with the HP tree:
https://sourceware.org/ml/gdb-patches/1999-q2/msg00149.html

gdb/testsuite/ChangeLog:
2017-10-12  Pedro Alves  <palves@redhat.com>

	* gdb.base/attach.exp: Remove references to gdb64.
	* gdb.base/dbx.exp: Remove references to gdb64.
2017-10-13 00:40:23 +01:00
Simon Marchi cfa34c871c Remove is_remote check in labels.exp
This works fine with remote target boards.

gdb/testsuite/ChangeLog:
2017-10-12  Simon Marchi  <simon.marchi@polymtl.ca>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/label.exp: Remove is_remote target check.
2017-10-12 23:14:09 +01:00
Pedro Alves 9192b7decc Make gdb.base/auvx.exp work with --target_board=native-extended-gdbserver
Currently we get:
 Running .../src/gdb/testsuite/gdb.base/auxv.exp ...
 WARNING: can't generate a core file - core tests suppressed - check ulimit -c

After this commit we get all the same PASSes as when native testing.

The problem is that the testcase wants to create a core dump in a
temporary directory and it is using the "cd" command to start the
inferior with that directory as current directory, but that command
only affects the inferior's cwd when native debugging.  Fix it by
using using the new "set cwd" command instead, which works with
gdbserver as well.

This still won't work with stub-like targets, because with those when
we connect the inferior is already running.  It'd be possible to make
it work by making the inferior itself change dirs, but we'll need to
make the native-gdbserver board no longer set is_remote first.

gdb/testsuite/ChangeLog:
2017-10-12  Pedro Alves  <palves@redhat.com>

	* gdb.base/auvx.exp (coredir): Update comment.
	(top level) <core_works>: Use "set cwd" command instead of "cd"
	command.
2017-10-12 23:06:15 +01:00
Pedro Alves 6bf0052db8 Run gdb.base/catch-fork-static.exp on remote target boards
Another case of a stale check.  We support following forks in the
remote protocol nowadays.

gdb/testsuite/ChangeLog:
2017-10-12  Pedro Alves  <palves@redhat.com>
	    Simon Marchi  <simon.marchi@polymtl.ca>

	* gdb.base/catch-fork-static.exp: No longer skip on is_remote
	target boards.
2017-10-12 20:06:59 +01:00
Pedro Alves e48ef82dd2 checkpoint.exp: Check for non-"target native" instead of isnative/is_remote
This gets rid of a number of FAILs with
--target_board=native-extended-gdbserver.

The fact that checkpointing does not work has nothing to do with
dejagnu's native and remote concepts.  It only works with native Linux
targets because the implementation is currently baked with
linux-nat.c.

gdb/testsuite/ChangeLog:
2017-10-12  Pedro Alves  <palves@redhat.com>
	    Simon Marchi  <simon.marchi@polymtl.ca>

	* gdb.base/checkpoint.exp: Don't check is_remote or isnative.
	Instead skip if there's any gdb_protocol set.
2017-10-12 19:54:57 +01:00
Simon Marchi 8d7aea574a Remove is_remote target check from gdb.base/dprintf-non-stop.exp
1. is_remote is not the right check.

2. Both Simon & Pedro ran it continuously for some time against
   native-gdbserver and didn't see a failure.

3. The test has been running against native-extended-gdbserver anyway.

gdb/testsuite/ChangeLog:
2017-10-12  Simon Marchi  <simon.marchi@polymtl.ca>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/dprintf-non-stop.exp: Remove is_remote target check.
2017-10-12 19:33:06 +01:00
Pedro Alves 30440677f3 Tighten remote check in gdb.base/argv0-symlink.exp
Check for gdbserver instead of dejagnu remote.  Unlike what the
comment says, the test actually fails with target remote + gdbserver
(it does pass with extended-remote).  The result is:

 FAIL -> KFAIL with --target_board=native-gdbserver
 KPASS -> PASS with --target_board=native-extended-gdbserver

gdb/testsuite/ChangeLog:
2017-10-12  Pedro Alves  <palves@redhat.com>
	    Simon Marchi  <simon.marchi@polymtl.ca>

	* gdb.base/argv0-symlink.exp: kfail on remote gdbserver,
	instead of on dejagnu remote boards.
2017-10-12 19:16:54 +01:00