Commit Graph

2537 Commits

Author SHA1 Message Date
Tom Tromey 3453e7e409 Clean up "Reading symbols" output
This patch is another attempt to fix PR cli/19551.  Unlike my previous
attempt, it doesn't print progress.  Instead, it just changes some
messages and adds newlines to make the output a bit nicer.

It also removes the "done." text that was previously emitted.  The
idea here is that it is obvious when gdb is done reading debug info,
as it starts then doing something else; and that while this message
did not provide much benefit to users, it did make it harder to make
the output clean.

After this change the output from "./gdb -iex 'set complaint 1' -nx ./gdb"
reads:

    Reading symbols from ./gdb...
    .debug_ranges entry has start address of zero [in module /home/tromey/gdb/build/gdb/gdb]
    DW_AT_low_pc 0x0 is zero for DIE at 0x17116c1 [in module /home/tromey/gdb/build/gdb/gdb]
    .debug_line address at offset 0xa22f5 is 0 [in module /home/tromey/gdb/build/gdb/gdb]
    During symbol reading, unsupported tag: 'DW_TAG_unspecified_type'.
    During symbol reading, const value length mismatch for 'std::ratio<1, 1000000000>::num', got 8, expected 0.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	PR cli/19551:
	* symfile.c (symbol_file_add_with_addrs): Update output.
	* psymtab.c (require_partial_symbols): Update output.

gdb/testsuite/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	PR cli/19551:
	* lib/mi-support.exp (mi_gdb_file_cmd): Update.
	* lib/gdb.exp (gdb_file_cmd): Update.
	* gdb.stabs/weird.exp (print_weird_var): Update.
	* gdb.server/solib-list.exp: Update.
	* gdb.multi/remove-inferiors.exp (test_remove_inferiors): Update.
	* gdb.mi/mi-cli.exp: Update.
	* gdb.linespec/linespec.exp: Update.
	* gdb.dwarf2/dw2-stack-boundary.exp: Update.
	* gdb.dwarf2/dw2-objfile-overlap.exp: Update.
	* gdb.cp/cp-relocate.exp: Update.
	* gdb.base/sym-file.exp: Update.
	* gdb.base/relocate.exp: Update.
	* gdb.base/readnever.exp: Update.
	* gdb.base/print-symbol-loading.exp (test_load_core): Update.
	* gdb.base/kill-detach-inferiors-cmd.exp: Update.
	* gdb.base/dbx.exp (gdb_file_cmd): Update.
	* gdb.base/code_elim.exp: Update.
	* gdb.base/break-unload-file.exp (test_break): Update.
	* gdb.base/break-interp.exp (test_attach_gdb): Update.
	* gdb.base/break-idempotent.exp (force_breakpoint_re_set):
	Update.
	* gdb.base/attach.exp (do_attach_tests): Update.
	* gdb.base/sepdebug.exp: Update.
	* gdb.python/py-section-script.exp: Update.
2018-10-04 13:40:10 -06:00
Tom Tromey fef1b2933d Avoid pagination in attach.exp
While re-testing the complaint series, I saw some unresolved tests in
attach.exp.  In particular, the tests were failing because the pager
was active.

This is partly a new problem, introduced because that series changes
some prints from unfiltered to filtered.  However, it is also a latent
bug, which you can see by shrinking your window very small and then
running the test.

This patch avoids the problem by passing -quiet to gdb and arranging
to set the window height and width in one other test.

Arguably instead of -quiet we should disable the pager during gdb's
welcome message.  I can do that if it seems desirable; but meanwhile
this patch is safe.

gdb/testsuite/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

	* gdb.base/attach.exp (test_command_line_attach_run): Use -quiet;
	set width and height to 0.
	(test_command_line_attach_run): Use -quiet.
2018-10-04 11:01:53 -06:00
Sandra Loosemore ca98345e0b Skip gdb ifunc tests on targets that don't support this feature.
2018-10-03  Sandra Loosemore  <sandra@codesourcery.com>

	* lib/gdb.exp (skip_ifunc_tests): New.
	* gdb.base/gnu-ifunc.exp: Skip if no ifunc support.  Handle
	other compile failures.
	* gdb.compile/compile-ifunc.exp: Skip if no ifunc support.
2018-10-03 09:16:53 -07:00
Andrew Burgess f67ffa6a78 gdb: Change how frames are selected for 'frame' and 'info frame'.
The 'frame' command, and thanks to code reuse the 'info frame' and
'select-frame' commands, currently have an overloaded mechanism for
selecting a frame.

These commands take one or two parameters, if it's one parameter then
we first try to use the parameter as an integer to select a frame by
level (or depth in the stack).  If that fails then we treat the
parameter as an address and try to select a stack frame by
stack-address.  If we still have not selected a stack frame, or we
initially had two parameters, then GDB allows the user to view a stack
frame that is not part of the current backtrace.  Internally, a new
frame is created with the given stack and pc addresses, and this is
shown to the user.

The result of this is that a typo by the user, entering the wrong stack
frame level for example, can result in a brand new frame being viewed
rather than an error.

The purpose of this commit is to remove this overloading, while still
offering the same functionality through some new sub-commands.  By
making the default behaviour of 'frame' (and friends) be to select a
stack frame by level index, it is hoped that enough
backwards-compatibility is maintained that users will not be overly
inconvenienced.

The 'frame', 'select-frame', and 'info frame' commands now all take a
frame specification string as an argument, this string can be any of the
following:

  (1) An integer.  This is treated as a frame level.  If a frame for
  that level does not exist then the user gets an error.

  (2) A string like 'level <LEVEL>', where <LEVEL> is a frame level
  as in option (1) above.

  (3) A string like 'address <STACK-ADDRESS>', where <STACK-ADDRESS>
  is a stack-frame address.  If there is no frame for this address
  then the user gets an error.

  (4) A string like 'function <NAME>', where <NAME> is a function name,
  the inner most frame for function <NAME> is selected.  If there is no
  frame for function <NAME> then the user gets an error.

  (5) A string like 'view <STACK-ADDRESS>', this views a new frame
  with stack address <STACK-ADDRESS>.

  (6) A string like 'view <STACK-ADDRESS> <PC-ADDRESS>', this views
  a new frame with stack address <STACK-ADDRESS> and the pc <PC-ADDRESS>.

This change assumes that the most common use of the commands like
'frame' is to select a frame by frame level, it is for this reason
that this is the behaviour that is kept for backwards compatibility.
Any of the alternative behaviours, which are assumed to be less used,
now require a change in user behaviour.

The MI command '-stack-select-frame' has not been changed.  This
ensures that we maintain backwards compatibility for existing
frontends.

gdb/ChangeLog:

	(NEWS): Mention changes to frame related commands.
	* cli/cli-decode.c (add_cmd_suppress_notification): New function.
	(add_prefix_cmd_suppress_notification): New function.
	(add_com_suppress_notification): Call
	add_cmd_suppress_notification.
	* command.h (add_cmd_suppress_notification): Declare.
	(add_prefix_cmd_suppress_notification): Declare.
	* mi/mi-cmd-stack.c: Add 'safe-ctype.h' include.
	(parse_frame_specification): Moved from stack.c, with
	simplification to handle a single argument.
	(mi_cmd_stack_select_frame): Use parse_frame_specification, the
	switch to the selected frame.  Add a header comment.
	* stack.c: Remove 'safe-ctype.h' include.
	(find_frame_for_function): Add declaration.
	(find_frame_for_address): New function.
	(parse_frame_specification): Moved into mi/mi-cmd-stack.c.
	(frame_selection_by_function_completer): New function.
	(info_frame_command): Rename to...
	(info_frame_command_core): ...this, and update parameter types.
	(select_frame_command): Rename to...
	(select_frame_command_core): ...this, and update parameter types.
	(frame_command): Rename to...
	(frame_command_core): ...this, and update parameter types.
	(class frame_command_helper): New class to wrap implementations of
	frame related sub-commands.
	(frame_apply_cmd_list): New static global.
	(frame_cmd_list): Make static.
	(select_frame_cmd_list): New global for sub-commands.
	(info_frame_cmd_list): New global for sub-commands.
	(_initialize_stack): Register sub-commands for 'frame',
	'select-frame', and 'info frame'.  Update 'frame apply' commands
	to use frame_apply_cmd_list.  Move function local static
	frame_apply_list to file static frame_apply_cmd_list for
	consistency.
	* stack.h (select_frame_command): Delete declarationn.
	(select_frame_for_mi): Declare new function.

gdb/doc/ChangeLog:

	* gdb.texinfo (Frames): Rewrite the description of 'frame number'
	to highlight that the number is also the frame's level.
	(Selection): Rewrite documentation for 'frame' and 'select-frame'
	commands.
	(Frame Info): Rewrite documentation for 'info frame' command.

gdb/testsuite/ChangeLog:

	* gdb.base/frame-selection.exp: New file.
	* gdb.base/frame-selection.c: New file.
2018-09-28 11:59:34 +01:00
Andrew Burgess d354055e6e gdb/riscv: Improve non-dwarf stack unwinding
This commit improves the prologue scanning stack unwinder, to better
support AUIPC, LUI, and more variants of ADD and ADDI.

This allows unwinding over frames containing large local variables,
where the frame size does not fit into a single instruction immediate,
and is first loaded into a temporary register, before being added to
the stack pointer.

A new test is added that tests this behaviour.  As there's nothing
truely RiscV specific about this test I've added it into gdb.base, but
as this depends on target specific code to perform the unwind it is
possible that some targets might fail this new test.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_insn::decode): Decode c.lui.
	(riscv_scan_prologue): Split handling of AUIPC, LUI, ADD, ADDI,
	and NOP.

gdb/testsuite/ChangeLog:

	* gdb.base/large-frame-1.c: New file.
	* gdb.base/large-frame-2.c: New file.
	* gdb.base/large-frame.exp: New file.
	* gdb.base/large-frame.h: New file.
2018-09-26 14:08:39 +01:00
Jozef Lawrynowicz db72737006 Fix PR gdb/20948: --write option to GDB causes segmentation fault
When opening a BFD for update, as gdb --write does, modifications to
anything but the contents of sections is restricted.

Do not try to write back any ELF headers in this case.

bfd/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	PR gdb/20948
	* elf.c (_bfd_elf_write_object_contents): Return from function
	early if abfd->direction == both_direction.

gdb/testsuite/ChangeLog
2018-09-24  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	PR gdb/20948
	* gdb.base/write_mem.exp: New test.
	* gdb.base/write_mem.c: Likewise.
2018-09-24 06:20:17 -06:00
Hafiz Abid Qadeer a466edac5f Add '_' in the match pattern.
I was looking at GDB testcase results for arm-eabi target with qemu and
noticed that register groups returned by the qemu can have '_' in the
name e.g. 'cp_regs'. The reggroups.exp fails to recognize that as group
name. Fixed by adding '_' in the pattern.

2018-09-20  Hafiz Abid Qadeer  <abidh@codesourcery.com>

	gdb.base/reggroups.exp (fetch_reggroups): Add '_' in match pattern.
2018-09-20 16:46:00 +01:00
Sandra Loosemore 4ee9b0c53a Skip GDB tab-completion tests if no readline.
2018-09-18  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.base/complete-empty.exp: Skip tab-completion tests if
	no readline.
	* gdb.base/utf8-identifiers.exp: Likewise.
	* gdb.cp/cpcompletion.exp: Likewise.
	* gdb.linespec/cpcompletion.exp: Likewise.
	* gdb.linespec/cpls-abi-tag.exp: Likewise.
	* gdb.linespec/cpls-ops.exp: Likewise.
2018-09-19 19:05:39 -07:00
Tom Tromey 65e65158c5 Use GNU style for metasyntactic variables in gdb
I searched for other spots that did not use the GNU style for
metasyntactic syntactic variables.  This patch fixes most of the ones
I found in gdb proper.  There are a few remaining in MI, but I was
unsure whether those should be touched.

gdb/ChangeLog
2018-09-16  Tom Tromey  <tom@tromey.com>

	* top.c (new_ui_command): Use GNU style for metasyntactic
	variables.
	* breakpoint.c (stopat_command): Use GNU style for metasyntactic
	variables.
	* maint.c (maintenance_translate_address): Remove "<>" around
	text.
	* interps.c (interpreter_exec_cmd): Use GNU style for
	metasyntactic variables.
	* nto-procfs.c (nto_procfs_target_info): Use GNU style for
	metasyntactic variables.
	* tracepoint.c (tfind_range_command): Use GNU style for
	metasyntactic variables.
	(tfind_outside_command): Likewise.
	(_initialize_tracepoint): Likewise.
	* remote.c (extended_remote_target::create_inferior): Use GNU
	style for metasyntactic variables.
	* sparc64-tdep.c (adi_examine_command): Use GNU style for
	metasyntactic variables.
	(adi_assign_command): Likewise.

gdb/testsuite/ChangeLog
2018-09-16  Tom Tromey  <tom@tromey.com>

	* gdb.base/new-ui.exp (do_execution_tests): Update.
	* gdb.base/dbx.exp (test_breakpoints): Update.
2018-09-16 06:25:17 -06:00
Andrew Burgess 96b6697fd8 gdb/testsuite: Make test names unique in gdb.base/watchpoint.exp
Extend test names and add test name prefixes to make test names
unique.

gdb/testsuite/ChangeLog:

	* gdb.base/watchpoint.exp (test_complex_watchpoint): Extend test
	names, and add test prefixes to make test names unique.
2018-09-07 14:06:53 +01:00
Gary Benson dd083ee23d Fix batch exit status test failure on Fedora 28
This commit adds calls to remote_close and clear_gdb_spawn_id to
gdb.base/batch-exit-status.exp, fixing failures reported by buildbot
on Fedora 28 where gdb_spawn_id not being reset by the previous test
caused default_gdb_spawn to return without spawning.

This commit also changes the test to use detect GDB's exit using
gdb_test_multiple expecting 'eof', rather than using 'wait -i' alone.
This means the testcase won't hang forever on failure as fixed in
gdb.base/quit.exp by commit 15763a09d4 ("Fix 'gdb.base/quit.exp
hangs forever' if the test fails").

gdb/testsuite/ChangeLog:

	* gdb.base/batch-exit-status.exp: Use gdb_test_multiple and expect
	'eof' before 'wait -i'.  Use remote_close and clear_gdb_spawn_id.
2018-09-04 15:29:20 +01:00
Andrew Burgess c67f2e1518 gdb: Ensure compiler doesn't optimise variable out in test
In the test gdb.base/funcargs.exp, there's this function:

    void recurse (SVAL a, int depth)
    {
      a.s = a.i = a.l = --depth;
      if (depth == 0)
        hitbottom ();
      else
        recurse (a, depth);
    }

The test script places a breakpoint in hitbottom, and runs the
executable which calls recurse with an initial depth of 4.

When GDB hits the breakpoint in hitbottom the testscript performs a
backtrace, and examines 'a' at each level.

The problem is that 'a' is not live after either the call to
'hitbottom' or the call to 'recurse', and as a result the test fails.

In the particular case I was looking at GCC for RISC-V 32-bit, the
variable 'a' is on the stack and GCC selects the register $ra (the
return address register) to hold the pointer to 'a'.  This is fine,
because, by the time the $ra register is needed to hold a return
address (calling hitbottom or recurse) then 'a' is dead.

In this patch I propose that a use of 'a' is added after the calls to
hitbottom and recurse, this should cause the compiler to keep 'a'
around, which should ensure GDB can find it.

gdb/testsuite/ChangeLog:

	* gdb.base/funcargs.c (use_a): New function.
	(recurse): Call use_a.
2018-08-30 16:33:49 +01:00
Gary Benson b0f492b90f Indicate batch mode failures by exiting with nonzero status
This commit causes GDB in batch mode to exit with nonzero status
if the last command to be executed fails.

gdb/ChangeLog:

	PR gdb/13000:
	* gdb/main.c (captured_main_1): Exit with nonzero status
	in batch mode if the last command to be executed failed.
	* NEWS: Mention the above.

gdb/testsuite/ChangeLog:

	PR gdb/13000:
	* gdb.base/batch-exit-status.exp: New file.
	* gdb.base/batch-exit-status.good-commands: Likewise.
	* gdb.base/batch-exit-status.bad-commands: Likewise.
2018-08-29 16:11:50 +01:00
Alan Hayward 36eb4c5f9b infcall-nested-structs: Test up to five fields
Aarch64 can pass structures of up to four members of identical
types in float registers (See AAPCS 5.3 and 5.4). Expand test to
cover this.

Remove the need to specify an additional sets of structures if tB
is not defined.

gdb/testsuite/
	* gdb.base/infcall-nested-structs.c (struct struct01): Remove.
	(struct struct02): Likewise.
	(struct struct03): Likewise.
	(struct struct04): Likewise.
	(struct struct_01_01): New struct.
	(struct struct_01_02): Likewise.
	(struct struct_01_03): Likewise.
	(struct struct_01_04): Likewise.
	(struct struct_02_01): Likewise.
	(struct struct_02_02): Likewise.
	(struct struct_02_03): Likewise.
	(struct struct_02_04): Likewise.
	(struct struct_04_01): Likewise.
	(struct struct_04_02): Likewise.
	(struct struct_04_03): Likewise.
	(struct struct_04_04): Likewise.
	(struct struct_05_01): Likewise.
	(struct struct_05_02): Likewise.
	(struct struct_05_03): Likewise.
	(struct struct_05_04): Likewise.
	(cmp_struct01): Remove function.
	(cmp_struct02): Likewise.
	(cmp_struct03): Likewise.
	(cmp_struct04): Likewise.
	(cmp_struct_01_01): Add Function.
	(cmp_struct_01_02): Likewise.
	(cmp_struct_01_03): Likewise.
	(cmp_struct_01_04): Likewise.
	(cmp_struct_02_01): Likewise.
	(cmp_struct_02_02): Likewise.
	(cmp_struct_02_03): Likewise.
	(cmp_struct_02_04): Likewise.
	(cmp_struct_04_01): Likewise.
	(cmp_struct_04_02): Likewise.
	(cmp_struct_04_03): Likewise.
	(cmp_struct_04_04): Likewise.
	(cmp_struct_05_01): Likewise.
	(cmp_struct_05_02): Likewise.
	(cmp_struct_05_03): Likewise.
	(cmp_struct_05_04): Likewise.
	(call_all): Add new structs.
	* gdb.base/infcall-nested-structs.exp: Likewise.
2018-08-29 11:43:53 +01:00
Philippe Waroquiers ead9aa39bf Modify gdb.base/commands.exp to test multi breakpoints command clearing.
gdb/testsuite/ChangeLog
2018-08-26  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/commands.exp: Test multi breakpoints command clearing.
2018-08-28 22:40:59 +02:00
Simon Marchi ae739fe7b8 Fix restoring of inferior terminal settings
I noticed that the child_terminal_save_inferior function was not used
since the commit f6ac5f3d63 ("Convert struct target_ops to C++").  I
was able to make a little test program to illustrate the problem (see
test case).

I think we're just missing the override of the terminal_save_inferior
method in inf_child_target (along with the other terminal-related
methods).

Instead of creating a new test, I thought that gdb.base/term.exp was a
good candidate for testing that gdb restores properly the inferior's
terminal settings.

gdb/ChangeLog:

	* inf-child.h (inf_child_target) <terminal_save_inferior>: New.
	* inf-child.c (inf_child_target::terminal_save_inferior): New.

gdb/testsuite/ChangeLog:

	* gdb.base/term.exp: Compare terminal settings with values from
	the inferior.
	* gdb.base/term.c: Get and set terminal settings.
2018-08-22 11:09:45 -04:00
Michael Spang be2d111a87 Fix debugging of stripped PIE executables with padded PT_TLS
Certain PIE executables produced by gold cannot be debugged by gdb after
being stripped. GDB requires program headers of PIE executables to match,
and those checks may fail due to adjustments made during stripping.

One case of this occurs because strip recomputes the memsz of PT_TLS and
does not add alignment, while gold does. This is another variant of PR
11786, so apply the same fix of relaxing the program header matching.

gdb/ChangeLog:

	PR gdb/11786
	* solib-svr4.c (svr4_exec_displacement): Ignore memsz fields
	for PT_TLS segments.

gdb/testsuite/ChangeLog:

	PR gdb/11786
	* gdb.base/gcore-tls-pie.c: New file.
	* gdb.base/gcore-tls-pie.exp: New file.
2018-08-19 11:00:39 -04:00
Andrew Burgess 5ff2bbae19 gdb: Check element of optimised out vla exists
If a vla is not in memory, and the upper bound is not defined, then we
can't know that an array element exists or not, and we should not try
to access the array element.  One case where this happens is for
arrays that have been optimised out, the array will then have
VALUE_LVAL of not_lval, and an undefined upper bound, if we then try
to access an element of this array we will index into random GDB
memory.

An argument could be made that even for arrays that are in inferior
memory, if the upper bound is not defined then we should not try to
access the array element, however, in some of the Fortran tests, it
seems as though we do rely indexing from a base address into an array
which has no bounds defined.  In this case GDBs standard protection
for detecting unreadable target memory prevents bad thing happening.

gdb/ChangeLog:

	* valarith.c (value_subscripted_rvalue): If an array is not in
	memory, and we don't know the upper bound, then we can't know that
	the requested element exists or not.

gdb/testsuite/ChangeLog:

	* gdb.base/vla-optimized-out.exp: Add new test.
2018-08-09 17:17:35 +01:00
Andrew Burgess e5bbcd0f04 gdb: Merge similar tests into a single test script
The three test scripts:

  gdb/testsuite/gdb.base/vla-optimized-out.exp
  gdb/testsuite/gdb.base/vla-optimized-out-o3.exp
  gdb/testsuite/gdb.base/vla-optimized-out-o3-strict.exp

are all pretty similar, with differences in the compile flags used,
and some of the expected results.

Instead of maintaining 3 files, merge them into a single test script,
and use parameters to control the test behaviour.

gdb/testsuite/ChangeLog:

	* gdb.base/vla-optimized-out-o3.exp: Delete.
	* gdb.base/vla-optimized-out-o3-strict.exp: Delete.
	* gdb.base/vla-optimized-out.exp: Extend to cover all of the
	deleted tests.
2018-08-09 17:17:34 +01:00
Simon Marchi 87d6a7aa93 Add DWARF index cache
New in v3:

- Remove things related to the dwarf-5 format.
- Fix compilation on mingw (scoped_mmap.c).

GDB can generate indexes for DWARF debug information, which, when
integrated in the original binary, can speed up loading object files.
This can be done using the gdb-add-index script or directly by the
linker itself.  However, not many people know about this.  And even
among those who do, because it requires additional steps, I don't know a
lot of people who actually go through that trouble.

To help make using the DWARF index more transparent, this patch
introduces a DWARF index cache.  When enabled, loading an index-less
binary in GDB will automatically save an index file in ~/.cache/gdb.
When loading that same object file again, the index file will be looked
up and used to load the DWARF index.  You therefore get the benefit of
the DWARF index without having to do additional manual steps or
modifying your build system.  When an index section is already present
in the file, GDB will prefer that one over looking up the cache.

When doing my edit-compile-debug cycle, I often debug multiple times the
same build, so the cache helps reducing the load time of the debug
sessions after the first one.

- The saved index file is exactly the same as the output of the "save
  gdb-index" command.  It is therefore the exact same content that would
  be found in the .gdb_index or .debug_names section.  We just leave it
  as a standalone file instead of merging it in the binary.

- The cache is just a directory with files named after the object
  file's build-id.  It is not possible to save/load the index for an
  object file without build-id in the cache.

- The cache uses the gdb index format.  The problem with the dwarf-5
  format is that we can generate an addendum to the .debug_str section
  that you're supposed to integrate to the original binary.  This
  complicates a little bit loading the data from the cached index files,
  so I would leave this for later.

- The size taken up by ~/.cache/gdb is not limited.  I was thinking we
  could add configurable limit (like ccache does), but that would come
  after.  Also, maybe a command to flush the cache.

- The cache is disabled by default.  I think once it's been out there
  and tested for a while, it could be turned on by default, so that
  everybody can enjoy it.

- The code was made to follow the XDG specification: if the
  XDG_CACHE_HOME environment variable, it is used, otherwise it falls
  back to ~/.cache/gdb.  It is possible to change it using "set
  index-cache directory".  On other OSes than GNU/Linux, ~/.cache may
  not be the best place to put such data.  On macOS it should probably
  default to ~/Library/Caches/...  On Windows, %LocalAppData%/...  I
  don't intend to do this part, but further patches are welcome.

- I think that we need to be careful that multiple instances of GDB
  don't interfere with each other (not far fetched at all if you run GDB
  in some automated script) and the cache is always coherent (either the
  file is not found, or it is found and entirely valid).  Writing the
  file directly to its final location seems like a recipe for failure.
  One GDB could read a file in the index while it is being written by
  another GDB.  To mitigate this, I made write_psymtabs_to_index write
  to temporary files and rename them once it's done.  Two GDB instances
  writing the index for the same file should not step on each other's
  toes (the last file to be renamed will stay).  A GDB looking up a file
  will only see a complete file or no file.  Also, if GDB crashes while
  generating the index file, it will leave a work-in-progress file, but
  it won't be picked up by other instances looking up in the cache.

gdb/ChangeLog:

	* common/pathstuff.h (get_standard_cache_dir): New.
	* common/pathstuff.c (get_standard_cache_dir): New.
	* build-id.h (build_id_to_string): New.
	* dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX,
	DEBUG_STR_SUFFIX): Move to here.
	* dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX,
	DEBUG_STR_SUFFIX): Move from there.
	(write_psymtabs_to_index): Make non-static, add basename
	parameter.  Write to temporary files, rename when done.
	(save_gdb_index_command): Adjust call to
	write_psymtabs_to_index.
	* dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New
	field.
	* dwarf2read.c (dwz_file) <index_cache_res>: New field.
	(get_gdb_index_contents_from_cache): New.
	(get_gdb_index_contents_from_cache_dwz): New.
	(dwarf2_initialize_objfile): Read index from cache.
	(dwarf2_build_psymtabs): Save to index.
	* dwarf-index-cache.h: New file.
	* dwarf-index-cache.c: New file.
	* dwarf-index-write.h: New file.

gdb/testsuite/ChangeLog:

	* boards/index-cache-gdb.exp: New file.
	* gdb.dwarf2/index-cache.exp: New file.
	* gdb.dwarf2/index-cache.c: New file.
	* gdb.base/maint.exp: Check if we are using the index cache.
2018-08-07 18:14:20 -04:00
Tom de Vries 37cc0caeca [gdb/exp] Interpret size of vla with unknown size as <optimized out>
At -O3 -g -gstrict-dwarf, gcc generates for an optimized out vla 'a' a
DW_TAG_variable with type DW_TAG_array_type containing one
DW_TAG_subrange_type, but without DW_AT_upper_bound or DW_AT_count, which
makes the upper bound value 'unknown':
...
	.uleb128 0x15   # (DIE (0x161) DW_TAG_variable)
        .long   0xec    # DW_AT_abstract_origin
        .long   0x170   # DW_AT_type
	...
        .uleb128 0xa    # (DIE (0x170) DW_TAG_array_type)
        .long   0x110   # DW_AT_type
        .long   0x17f   # DW_AT_sibling
        .uleb128 0x17   # (DIE (0x179) DW_TAG_subrange_type)
        .long   0xc6    # DW_AT_type
        .byte   0       # end of children of DIE 0x170
...

But gdb prints '0' for the size of 'a':
...
/gdb ./vla-1.exe -batch -ex "b f1" -ex "run" -ex "p sizeof(a)"
Breakpoint 1 at 0x4004c0: f1. (2 locations)

Breakpoint 1, f1 (i=<optimized out>) at vla-1.c:18
18      }
$1 = 0
...
while <optimized out> would be more appropriate.

This patch fixes that in evaluate_subexp_for_sizeof.

Build and reg-tested on x86_64-linux.

2018-07-28  Tom de Vries  <tdevries@suse.de>

	* eval.c (evaluate_subexp_for_sizeof): Interpret size of dynamic type
	with undefined upper bound as <optimized out>.

	* gdb.base/vla-optimized-out-o3-strict.exp: New file.
2018-07-28 10:16:30 +02:00
Tom de Vries 63b4ecf76f [gdb/testsuite] Add comment in gdb.base/vla-optimized-out.c
2018-07-26  Tom de Vries  <tdevries@suse.de>

	* gdb.base/vla-optimized-out.c: Add comment about origin of test-case.
2018-07-26 10:22:22 +02:00
Andrew Burgess 3c3bb0580b gdb: Add switch to disable DWARF stack unwinders
Add a maintenance command to disable the DWARF stack unwinders.
Normal users would not need this feature, but it is useful to allow
extended testing of fallback stack unwinding strategies, for example,
prologue scanners.

This is a partial implementation of the idea discussed in pr gdb/8434,
which talks about a generic ability to disable any frame unwinder.

Being able to arbitrarily disable any frame unwinder would be a more
complex patch, and I was unsure how useful such a feature would really
be, however, I can see (and have) a real need to disable DWARF
unwinders.  That's why this patch only targets that specific set of
unwinders.

If in the future we find ourselves adding more switches to disable
different unwinders, then we should probably move to a more generic
solution, and remove this patch.

gdb/ChangeLog:

	* dwarf2-frame-tailcall.c (tailcall_frame_sniffer): Exit early if
	DWARF unwinders are disabled.
	* dwarf2-frame.c: Add dwarf2read.h include.
	(dwarf2_frame_sniffer): Exit early if DWARF unwinders are
	disabled.
	(dwarf2_frame_unwinders_enabled_p): Define.
	(show_dwarf_unwinders_enabled_p): New function.
	(_initialize_dwarf2_frame): Register switch to control DWARF
	unwinder use.
	* dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Declare.
	* dwarf2read.c (set_dwarf_cmdlist): Remove static keyword.
	(show_dwarf_cmdlist): Remove static keyword.
	* dwarf2read.h (set_dwarf_cmdlist): Declare.
	(show_dwarf_cmdlist): Declare.
	* NEWS: Document new feature.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Add description of
	maintenance command to control dwarf unwinders.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Add check that dwarf unwinders control flag
	is visible.
2018-07-26 08:53:02 +01:00
Tom de Vries 9e7f3bbbbf [gdb/breakpoints] Fix sigsegv in info prog at exec catchpoint
With the test-case contained in this patch and compiled for debug we run into
a segfault with trunk gdb:
...
$ gdb catch-follow-exec -batch -ex "catch exec" \
  -ex "set follow-exec-mode new" -ex "run" -ex "info prog"
Catchpoint 1 (exec)
process xxx is executing new program: /usr/bin/ls
[New inferior 2 (process 0)]
[New process xxx]

Thread 2.1 "ls" hit Catchpoint 1 (exec'd /usr/bin/ls), in _start () from
  /lib64/ld-linux-x86-64.so.2
Segmentation fault (core dumped)
...

The patch fixes the segfault by returning an error in info_program_command
if get_last_target_status returns minus_one_ptid.

The test-case is non-standard, because the standard approach runs into
PR23368, a problem with gdb going to the background.

Build and reg-tested on x86_64-linux.

2018-07-26  Tom de Vries  <tdevries@suse.de>

	PR breakpoints/23366
	* infcmd.c (info_program_command): Handle ptid == minus_one_ptid.

	* gdb.base/catch-follow-exec.c: New test.
	* gdb.base/catch-follow-exec.exp: New file.
2018-07-26 00:56:41 +02:00
Tom de Vries 16f808ec99 [gdb/exp] Fix exception when printing optimized out vla
When compiling vla-optimized-out.c with -O3 and a recent gcc, and trying to
print the vla a in f1, we run into this gdb exception:
...
Cannot find matching parameter at DW_TAG_call_site 0x4003be at main
...

This is a regression introduced by 42dc7699a2 "[gdb/exp] Fix printing of type
of optimized out vla".

This patch fixes the regression by wrapping the ctx.eval call in
dwarf2_locexpr_baton_eval in try/catch, similar to what is done in
dwarf2_evaluate_loc_desc_full.

Build and reg-tested on x86_64-linux.

2018-07-25  Tom de Vries  <tdevries@suse.de>

	* dwarf2loc.c (dwarf2_locexpr_baton_eval): Wrap ctx.eval call in
	try/catch.

	* gdb.base/vla-optimized-out-o3.exp: New file.  Reuse
	vla-optimized-out.c.
2018-07-25 21:25:16 +02:00
Tom de Vries 232a00325b [gdb/testsuite] Make noclone conditional in vla-optimized-out.c
Make the noclone attribute on f1 in vla-optimized-out.c conditional.  This
makes the test-case by default identical to
gcc/testsuite/gcc.dg/guality/vla-1.c.

Tested on x86_64-linux.

2018-07-20  Tom de Vries  <tdevries@suse.de>

	* gdb.base/vla-optimized-out.c: Make noclone attribute conditional on
	NOCLONE macro.
	* gdb.base/vla-optimized-out.exp: Use additional_flags -DNOCLONE.
2018-07-20 17:04:02 +02:00
Tom de Vries 42dc7699a2 [gdb/exp] Fix printing of type of optimized out vla
Consider this snippet from gcc/testsuite/gcc.dg/guality/vla-1.c:
...
int __attribute__((noinline))
f1 (int i)
{
  char a[i + 1];
  a[0] = 5;             /* { dg-final { gdb-test .+1 "i" "5" } } */
  return a[0];          /* { dg-final { gdb-test . "sizeof (a)" "6" } } */
}
...

When we compile the test-case with -O1 -g, and query the size of optimized
out vla 'a', we get:
...
$ ./gdb -batch -ex "b f1" -ex "r" -ex "p sizeof (a)" vla-1.exe
Breakpoint 1 at 0x4004a8: file vla-1.c, line 17.

Breakpoint 1, f1 (i=i@entry=5) at vla-1.c:17
17        return a[0];
$1 = 0
...
while we expect a size of '6'.

The problem is that default_read_var_value does not resolve the dynamic type
of a variable if the variable is optimized out.

This patch fixes that, and consequently gdb prints '6', as expected.

Tested on x86_64-linux.

2018-07-18  Tom de Vries  <tdevries@suse.de>

	* findvar.c (default_read_var_value): Also resolve dynamic type for
	LOC_OPTIMIZED_OUT vars.

	* gdb.base/vla-optimized-out.c: New test.
	* gdb.base/vla-optimized-out.exp: New file.
2018-07-18 22:02:34 +02:00
Philippe Waroquiers 3606ccab0f Add a test for 'frame apply'
gdb/testsuite/ChangeLog
2018-07-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/frameapply.c: New file.
	* gdb.base/frameapply.exp: New file.
2018-07-12 23:06:08 +02:00
Philippe Waroquiers 529c08b25e Add helper functions parse_flags and parse_flags_qcs
Add helper functions parse_flags and parse_flags_qcs.
parse_flags helper function allows to look for a set of flags at
the start of a string.
A flag must be given individually.

parse_flags_qcs is a specialised helper function to handle
the flags -q, -c and -s, that are used in the new command 'frame apply'
and in the command 'thread apply.

Modify number_or_range_parser::get_number to differentiate a
- followed by digits from a - followed by an alpha (i.e. a flag or an option).
That is needed for the addition of the [FLAG]... arguments to
thread apply ID... [FLAG]... COMMAND

Remove bool number_or_range_parser::m_finished, rather
implement the 'finished' logic inside number_or_range_parser::finished.
The new logic properly detects the end of parsing even if not at
end of the string. This ensures that number_or_range_parser::cur_tok
really points past the last parsed token when parsing is finished.
Before, it was always pointing at the end of the string.
As parsing now is finished directly when not positioned on a number,
number_is_in_list must do an error check before the loop getting all
numbers.

The error message for 'thread apply -$unknownconvvar p 1'
is now the more clear:
  Convenience variable must have integer value.
  Invalid thread ID: -$unknownconvvar p 1
instead of previously:
  negative value

gdb/ChangeLog
2018-07-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli-utils.c (number_or_range_parser::get_number): Only handle
	numbers or convenience var as numbers.
	(parse_flags): New function.
	(parse_flags_qcs): New function.
	(number_or_range_parser::finished): Ensure parsing end is detected
	before end of string.
	* cli-utils.h (parse_flags): New function.
	(parse_flags_qcs): New function.
	(number_or_range_parser): Remove m_finished bool.
	(number_or_range_parser::skip_range): Set m_in_range to false.

gdb/testsuite/ChangeLog
2018-07-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/skip.exp: Update expected error message.
2018-07-12 22:50:26 +02:00
Sergio Durigan Junior 16ff70ddd4 Fix PR c++/23373: GDB hangs when printing a struct with a static member of itself
This patch fixes a failure that happens when a structure has a static
member whose type is the same as itself.  From the bug report:

  Example code:
  struct A
  {
      static A Empty;
      int a;
  };

  int main(void) {
      A a;
      return 0;
  }

  Output:
  (gdb) ptype/o A
  /* offset    |  size */  type = struct A {
			     static struct A {
				 static struct A {
				     static struct A {
					 static struct A {
					     static struct A {
						 static struct A {
						     ... # infinite loop

The problem here is that GDB is not taking into account the fact that
static members inside a class/struct are not stored in the
class/struct, and therefore they should not be accounted for during
the display of the offsets/sizes.  The fix is simple: we just check if
the field we're dealing with (on
c-typeprint.c:c_type_print_base_struct_union) is static, and if it is
then we don't iterate over it.

This patch also adds a new test for this case, and doesn't introduce
any regressions.  I believe it is important enough to be included in
the 8.2 branch.

OK?

gdb/ChangeLog:
2018-07-11  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR c++/23373
	* c-typeprint.c (c_type_print_base_struct_union): Don't print
	offsets/sizes for static members of a class/struct.

gdb/testsuite/ChangeLog:
2018-07-11  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR c++/23373
	* gdb.base/ptype-offsets.cc (struct static_member): New
	struct.
	(main) <stmember>: New variable.
	* gdb.base/ptype-offsets.exp: Add test for printing a struct
	with a static member in it.
2018-07-11 14:53:44 -04:00
Andrew Burgess 3541979fff gdb/testsuite: Run test with software and hardware watchpoints
Expand the gdb.base/watchpoint-reuse-slot.exp test to be run twice,
once with hardware watchpoints disabled (this is new) and then with
hardware watchpoints enabled (the old way).

Running with hardware watchpoints enabled is skipped if the board file
says that hardware watchpoints are not supported on this target.

gdb/testsuite/ChangeLog:

	* gdb.base/watchpoint-reuse-slot.exp: Test with hardware
	watchpoints enabled and disabled.
2018-07-10 14:47:38 +01:00
Andrew Burgess c8ad9b9a31 gdb/testsuite: Allow for failure to read some memory addresses
In the gdb.base/examine-backward.exp test script, we check to see if
address zero is readable, and then read memory first forward from
address zero, and then backward from address zero.

The problem is, being able to read address zero does not guarantee
that you'll be able to read from the other end of the address space,
and the test probably shouldn't assume that is the case.

This patch updates the test script so that even if address zero is
known non-readable, we still run the tests, the tests in question are
mostly about, can GDB calculate the correct address to read from, we
can confirm this even if the final read ultimately fails.  We also no
longer assume that if address zero is readable, then the other end of
the address space will be readable.

One further change is that, when we examined the memory at address
zero, the regexp used to match the address expected that the zero
address would have two '0' digits as the least significant digits.  As
GDB strips leading zeros from addresses this was causing the test to
fail.  I've reduced the zero address to a single 0 digit.

gdb/testsuite/ChangeLog:

	* gdb.base/examine-backward.exp: Still run tests around address
	0x0, even if address 0x0 is not readable.  Update the pattern for
	matching address 0x0 in expected output.
2018-07-09 15:08:20 +01:00
Andrew Burgess e0e5e971ae gdb/testsuite: Ensure test links in malloc and free
The test associated with the source file
gdb.base/share-env-with-gdbserver.c relies on calling malloc and free
within the inferior from GDB.  However, as the test source itself
makes no use of these functions, there's no requirement that they be
linked into the test executable.

This commit adds a dummy call to malloc and free to ensure they are
linked into the test executable.

gdb/testsuite/ChangeLog:

	* gdb.base/share-env-with-gdbserver.c (main): Add call to
	malloc/free.
2018-07-06 14:31:37 +01:00
Richard Bunt 49af4b7012 Remove unstable test output
Changed test output from:
PASS: gdb.base/watchpoint-hw-attach.exp: attach 25501
to
PASS: gdb.base/watchpoint-hw-attach.exp: attach

gdb/testsuite/ChangeLog:

	* gdb.base/watchpoint-hw-attach.exp: Remove unstable output.
2018-06-29 17:34:58 +01:00
Richard Bunt be1b6474f0 Fixed top frame assumption in watchpoint-hw-attach
watchpoint-hw-attach.exp was noticed to fail on some machines.
Thanks to the input from sergiodj and palves on the IRC channel,
it was concluded that the test case incorrectly assumed that on
attach it was landed in the top-most frame of the inferior. This
was fixed by running to a break point in main by explicitly
defining the source file name before continuing with the test.

Tested on the following architectures x86_64, aarch64 and ppc64le.

gdb/testsuite/ChangeLog:

	* gdb.base/watchpoint-hw-attach.c (main): Remove unneeded
	code.
	* gdb.base/watchpoint-hw-attach.exp: Break in outermost frame.
2018-06-28 08:59:59 +01:00
Petr Tesarik 291f9a9643 Add an optional offset option to the "add-symbol-file" command
If all sections of a symbol file are loaded with a fixed offset, it
is easier to specify that offset than listing all sections
explicitly.  There is also a similar option for "symbol-file".

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* symfile.c (add_symbol_file_command, _initialize_symfile): Add
	option "-o" to add-symbol-file-load to add an offset to each
	section's load address.
	* symfile.c (set_objfile_default_section_offset): New function.

gdb/doc/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.texinfo (Files): Document "add-symbol-file -o offset".

gdb/testsuite/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.base/relocate.exp: Add test for "add-symbol-file -o ".
2018-06-28 08:35:34 +02:00
Petr Tesarik ed6dfe517e Make add-symbol-file's address argument optional
The (first) .text section must be always specified as the second
non-option argument.  The documentation states that GDB cannot
figure out this address by itself.  This is true if the object file
was indeed relocated, but it is also confusing, because all other
sections can be omitted and will use the address provided by BFD.

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* symfile.c (add_symbol_file_command, _initialize_symfile): Do not
	require the second argument.  If omitted, load sections at the
	addresses specified in the file.

gdb/doc/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.texinfo (Files): The address argument for "add-symbol-file"
	is no longer mandatory.

gdb/testsuite/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.base/relocate.exp: Test add-symbol-file behavior when the
	address argument is omitted.
2018-06-28 08:35:34 +02:00
Petr Tesarik d4d429d589 Add an optional offset option to the "symbol-file" command
If the main file is relocated at runtime, all symbols are offset by
a fixed amount.  Let the user specify this offset when loading a
symbol file.

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* symfile.c (symbol_file_command, symbol_file_add_main_1)
	(_initialize_symfile): Add option "-o" to symbol-file to add an
	offset to each section of the symbol file.

gdb/doc/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.texinfo (Files): Document "symbol-file -o offset".

gdb/testsuite/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

	* gdb.base/relocate.exp: Add test for "symbol-file -o ".
2018-06-28 08:35:34 +02:00
Omair Javaid 7ab6656f27 Fix lost line info for symbol at addr zero
This patch fixes a unique condition where GDB fails to provide line
information of symbol at address zero when code is compiled with text
address zero but loaded at an offset > 0.

For example lets compile following code snippet:

int main() {
  return 0;
}

gcc -O0 -g3 -nostdlib -emain -Wl,-Ttext=0x00 -o file.out file.c

Start gdb and run:

add-symbol-file file.out 0xffff0000
info line main

GDB will return error saying no line info is available for the symbol.

This is a direct consequence of the fix for PR 12528 where GDB tries to ignore
line table for a function which has been garbage collected by the linker.

As the garbage collected symbols are sent to address zero GDB assumes a symbol
actually placed at address zero as garbage collected.

This was fixed with an additional check address < lowpc. But when symbol is
loaded at an offset lowpc becomes lowpc + offset while no offset is added to
address rather final symbol address is calculated based on baseaddr and address
added together. So in case where symbols are loaded at an offset the condition
address < lowpc will always return true.

This patch fixes this by comparing address against a non offset lowpc.

This patch also adds a GDB test case to replicate this behavior.

gdb:

2018-06-27  Omair Javaid  <omair.javaid@linaro.org>

	PR gdb/21695
	* dwarf2read.c (lnp_state_machine::check_line_address): Update declaration.
	(dwarf_decode_lines_1): Adjust.

gdb/testsuite:

2018-06-27  Omair Javaid  <omair.javaid@linaro.org>

	PR gdb/21695
	* gdb.base/infoline-reloc-main-from-zero.exp: New test.
	* gdb.base/infoline-reloc-main-from-zero.c: New file.
2018-06-27 20:12:49 +05:00
Simon Marchi 6d72d289c4 Fix "info registers" regexes in gdb.base/jit-reader.exp
Commit

  e813d34 ("Align natural-format register values to the same column")

changed the output of "info registers" (tabs to spaces), but didn't
update gdb.base/jit-reader.exp.  Update the regexes to expect spaces
instead.

gdb/testsuite/ChangeLog:

	* gdb.base/jit-reader.exp (jit_reader_test): Expect spaces in
	"info registers" output.
2018-06-22 13:40:47 -04:00
Richard Bunt 8363f9d5f2 Enable hardware watchpoints on attach for aarch64
This commit fixes a bug whereby hardware watchpoints are not used on
aarch64 when attaching to a target. The fix adds an aarch64 specialization
of post_attach which records the number of available hardware debug registers
using aarch64_linux_get_debug_reg_capacity. This implementation mirrors that
of aarch64_linux_child_post_startup_inferior which successfully enables the
use of hardware watchpoints when launching the target under the debugger.

gdb/ChangeLog:

	* aarch64-linux-nat.c (post_attach): New.
	(aarch64_linux_nat_target::post_attach): Override post_attach to
	record the number of hardware debug registers.

gdb/testsuite/ChangeLog:

	* gdb.base/watchpoint-hw-attach.c: New test.
	* gdb.base/watchpoint-hw-attach.exp: New file.
2018-06-21 14:09:34 +01:00
Ulrich Weigand 1d554008b3 Improve gdb.base/float128.exp failure message
If the "print large128" sub-test fails in a manner that typically
indicates internal overflow due to GDB being built without MPFR
support, explicitly state this in the failure message.

gdb/testsuite/ChangeLog:
2018-06-20  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.base/float128.exp: Add comment and improved fail message
	to the failure case of "print large128" test.
2018-06-20 16:24:16 +02:00
Pedro Alves 14897d65b5 Avoid gdb.base/fork-running-state.exp lingering processes
Currently, the gdb.base/fork-running-state.exp testcase leaves a few
processes lingering until a 3 minutes alarm kills them:

 pedro    28308     1  0 13:55 ?        00:00:00 /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
 pedro    28340     1  0 13:55 ?        00:00:00 /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
 pedro    28372     1  0 13:55 ?        00:00:00 /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
 pedro    28400     1  0 13:55 ?        00:00:00 /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
 pedro    28431     1  0 13:55 ?        00:00:00 /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state
 pedro    28463     1  0 13:55 ?        00:00:00 /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.base/fork-running-state/fork-running-state

Those processes used to kill themselves, but that was changed by
commit f50d8a2eae ("Fix gdb.base/fork-running-state.exp race").

This commit restores the self-killing, but only in the cases gdb won't
try killing the processes, thus avoiding the old race.

(The restored code in fork_parent isn't exactly the same as it was.
In this version, we're exiting immediately when 'wait' returns
success, while in the old version we'd loop again and end up in the
perror call.  The output from that perror call is not expected by the
"kill inferior" tests, and would result in a test FAIL.)

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

	* gdb.base/fork-running-state.c: Include <errno.h>.
	(exit_if_relative_exits): New.
	(fork_child): If 'exit_if_relative_exits' is true, exit if the parent
	exits.
	(fork_parent): If 'exit_if_relative_exits' is true, exit if the
	child exits.
2018-06-14 17:47:03 +01:00
Tom de Vries 5d9a060879 [gdb/cli] Honour 'print pretty' when printing result of finish command
Consider this testcase:
...
struct s {
  int a;
  int b;
};

struct s foo ()
{
  struct s r;
  r.a = 1;
  r.b = 2;
  return r;
}

int
main (void)
{
  struct s v;
  v = foo ();
  return v.a + v.b;
}
...

When we compile it with -g, load the exec with gdb, and run till the end of foo,
we can print r:
...
(gdb) p r
$1 = {a = 1, b = 2}
...

and by setting pretty printing to on, we can get the fields of r printed each
on its own line:
...
(gdb) set print pretty
(gdb) p r
$2 = {
  a = 1,
  b = 2
}
...

However, when we finish foo, the printed function result value is not using
the pretty printing setting:
...
(gdb) finish
Run till exit from #0  foo () at test.c:11
0x00000000004004c1 in main () at test.c:18
18        v = foo ();
Value returned is $3 = {a = 1, b = 2}
...

This patch fixes that by using get_user_print_options instead of
get_no_prettyformat_print_options in print_return_value_1, which gives us:
...
(gdb) finish
Run till exit from #0  foo () at test.c:11
0x00000000004004c1 in main () at test.c:18
18        v = foo ();
Value returned is $2 = {
  a = 1,
  b = 2
}
...

Build & reg-tested on x86_64.

2018-06-14  Tom de Vries  <tdevries@suse.de>

	PR cli/22573
	* infcmd.c (print_return_value_1): Use get_user_print_options instead of
	get_no_prettyformat_print_options.

	* gdb.base/finish-pretty.c: New test.
	* gdb.base/finish-pretty.exp: New file.
2018-06-14 15:30:47 +02:00
Tom de Vries a08ac84b96 [gdb/testsuite] Fix hang in fork-running-state.c
When I run make check:
...
$ cd build/gdb
$ make check 2>&1 | tee ../CHECKLOG.gdb
...
I see after ~30m the summary of the test run printed, but make still hangs.

This seems to be due to some sleeping processes:
...
$ ps  fx | grep fork-run
 6475 ?        S      0:00 gdb.base/fork-running-state/fork-running-state
 6451 ?        S      0:00 gdb.base/fork-running-state/fork-running-state
 6427 ?        S      0:00 gdb.base/fork-running-state/fork-running-state
...

Killing the sleeping processes like this:
...
kill -9 $(ps -A  | grep fork-running-st | awk '{print $1}')
...
allows make to finish.

If I isolate one debug session from fork-running-state.exp that causes one of
these sleeping processes, we get:
...
(gdb) set non-stop on
(gdb) break main
Breakpoint 1 at 0x400665: file src/gdb/testsuite/gdb.base/fork-running-state.c,
line 52.
(gdb) run
Starting program: build/gdb/testsuite/outputs/gdb.base/fork-running-state/
fork-running-state

Breakpoint 1, main () at src/gdb/testsuite/gdb.base/fork-running-state.c:52
52        save_parent = getpid ();
(gdb) set detach-on-fork on
(gdb) set follow-fork parent
(gdb) continue &
Continuing.
[Detaching after fork from child process 18797]
(gdb) info threads
  Id   Target Id         Frame
* 1    process 18793 "fork-running-st" (running)
(gdb) set print inferior-events off
(gdb) kill inferior 1
...
So, AFAIU, the hanging process is the child process that gdb detaches from.

There's an alarm set in main before the fork, but alarms are not preserved in
the fork child:
...
$ man alarm
   ...
NOTES
       Alarms created by alarm() are preserved across execve(2) and are not
       inherited by children created via fork(2).
...
So, AFAIU, once the parent is killed, there's no alarm to terminate the child.

The patch fixes this by moving the setting of the alarm into the
fork_main/fork_child functions, making sure that an alarm will trigger for
the child.

Tested with make check on x86_64.

2018-06-13  Tom de Vries  <tdevries@suse.de>

	PR testsuite/23269
	* gdb.base/fork-running-state.c (main): Move setting of alarm ...
	(fork_child): ... here, and ...
	(fork_parent): ... here.
2018-06-13 14:15:52 +02:00
Tom Tromey c61b06a19a Remove some text from --version output
I happened to notice recently that "gdb --version" says:

    GNU gdb (GDB) 8.0.50.20170911-git
    Copyright (C) 2017 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-pc-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word".

This is a bit on the wordy side, but also references interactive
commands, which I think doesn't really make sense for --version.

This patch removes some text from --version, while leaving it in the
"show version" output.  It also adds a newline between the URLs and
the "For help, ..." text, because I thought that was easier to read.
Finally, it indents one of the URLs, since that was simpler to read,
but not the other URL, because the current format is specified by the
GNU coding standards section on "--version".

Now the --version output looks like:

    GNU gdb (GDB) 8.1.50.20180511-git
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

Tested by the buildbot.

gdb/ChangeLog
2018-06-05  Tom Tromey  <tom@tromey.com>

	* cli/cli-cmds.c (show_version): Update.
	* top.c (print_gdb_version): Add "interactive" parameter.
	Update.
	* main.c (captured_main_1): Update.
	* top.h (print_gdb_version): Add "interactive" parameter and a
	comment.

gdb/testsuite/ChangeLog
2018-06-05  Tom Tromey  <tom@tromey.com>

	* gdb.base/default.exp: Update expected "show version" output.
2018-06-05 11:47:50 -06:00
Tom Tromey eb6af80922 Add "continue" response to pager
This adds a "continue" response to the pager.  If the user types "c"
in response to the pager prompt, pagination will be disabled for the
duration of one command -- but re-enabled afterward.  This is handy if
you type a command that produces a lot of output, and you don't want
to baby-sit it by typing "return" each time the prompt comes up.

Tested by the buildbot.

gdb/ChangeLog
2018-06-05  Tom Tromey	<tom@tromey.com>

	PR cli/12326:
	* NEWS: Add entry about pager.
	* utils.c (pagination_disabled_for_command): New global.
	(prompt_for_continue): Allow "c" response to prompt.
	(reinitialize_more_filter): Clear
	pagination_disabled_for_command.
	(fputs_maybe_filtered): Check pagination_disabled_for_command.

gdb/doc/ChangeLog
2018-06-05  Tom Tromey	<tom@tromey.com>

	PR cli/12326:
	* gdb.texinfo (Screen Size): Document "c" response to pagination
	prompt.

gdb/testsuite/ChangeLog
2018-06-05  Tom Tromey	<tom@tromey.com>

	PR cli/12326:
	* gdb.cp/static-print-quit.exp: Update.
	* lib/gdb.exp (pagination_prompt): Update.
	* gdb.base/page.exp: Use pagination_prompt.  Add new tests.
	* gdb.python/python.exp: Update.
2018-06-05 11:02:52 -06:00
Tom Tromey e86ca25fd6 Remove TYPE_TAG_NAME
TYPE_TAG_NAME has been an occasional source of confusion and bugs.  It
seems to me that it is only useful for C and C++ -- but even there,
not so much, because at least with DWARF there doesn't seem to be any
way to wind up with a type where the name and the tag name are both
non-NULL and different.

So, this patch removes TYPE_TAG_NAME entirely.  This should save a
little memory, but more importantly, it simplifies this part of gdb.

A few minor test suite adjustments were needed.  In some situations
the new code does not yield identical output to the old code.

gdb/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* valops.c (enum_constant_from_type, value_namespace_elt)
	(value_maybe_namespace_elt): Update.
	* valarith.c (find_size_for_pointer_math): Update.
	* target-descriptions.c (make_gdb_type): Update.
	* symmisc.c (print_symbol): Update.
	* stabsread.c (define_symbol, read_type)
	(complain_about_struct_wipeout, add_undefined_type)
	(cleanup_undefined_types_1): Update.
	* rust-lang.c (rust_tuple_type_p, rust_slice_type_p)
	(rust_range_type_p, val_print_struct, rust_print_struct_def)
	(rust_internal_print_type, rust_composite_type)
	(rust_evaluate_funcall, rust_evaluate_subexp)
	(rust_inclusive_range_type_p): Update.
	* python/py-type.c (typy_get_tag): Update.
	* p-typeprint.c (pascal_type_print_base): Update.
	* mdebugread.c (parse_symbol, parse_type): Update.
	* m2-typeprint.c (m2_long_set, m2_record_fields, m2_enum):
	Update.
	* guile/scm-type.c (gdbscm_type_tag): Update.
	* go-lang.c (sixg_string_p): Update.
	* gnu-v3-abi.c (build_gdb_vtable_type, build_std_type_info_type):
	Update.
	* gdbtypes.h (struct main_type) <tag_name>: Remove.
	(TYPE_TAG_NAME): Remove.
	* gdbtypes.c (type_name_no_tag): Simplify.
	(check_typedef, check_types_equal, recursive_dump_type)
	(copy_type_recursive, arch_composite_type): Update.
	* f-typeprint.c (f_type_print_base): Update.  Print "Type" prefix
	in summary mode when needed.
	* eval.c (evaluate_funcall): Update.
	* dwarf2read.c (fixup_go_packaging, read_structure_type)
	(process_structure_scope, read_enumeration_type)
	(read_namespace_type, read_module_type, determine_prefix): Update.
	* cp-support.c (inspect_type): Update.
	* coffread.c (process_coff_symbol, decode_base_type): Update.
	* c-varobj.c (c_is_path_expr_parent): Update.
	* c-typeprint.c (c_type_print_base_struct_union): Update.
	(c_type_print_base_1): Update.  Print struct/class/union/enum in
	summary when using C language.
	* ax-gdb.c (gen_struct_ref, gen_namespace_elt)
	(gen_maybe_namespace_elt): Update.
	* ada-lang.c (ada_type_name): Simplify.
	(empty_record, ada_template_to_fixed_record_type_1)
	(template_to_static_fixed_type)
	(to_record_with_fixed_variant_part, ada_check_typedef): Update.

gdb/testsuite/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* gdb.xml/tdesc-regs.exp (load_description): Update expected
	results.
	* gdb.dwarf2/method-ptr.exp: Set language to C++.
	* gdb.dwarf2/member-ptr-forwardref.exp: Set language to C++.
	* gdb.cp/typeid.exp (do_typeid_tests): Update type_re.
	* gdb.base/maint.exp (maint_pass_if): Update.
2018-06-01 10:19:55 -06:00
Maciej W. Rozycki 4b2dfa9d87 arch-utils: Make the last endianness actually chosen sticky
Use the last endianness explicitly selected, either by choosing a binary
file or with the `set endian' command, for future automatic selection.

As observed with the `gdb.base/step-over-no-symbols.exp' test case when
discarding the binary file even while connected to a live target the
endianness automatically selected is reset to the GDB target's default,
even if it does not match the endianness of the target being talked to.

For example with a little-endian MIPS target and the default endianness
being big we get this:

(gdb) file .../gdb/testsuite/outputs/gdb.base/step-over-no-symbols/step-over-no-symbols
Reading symbols from .../gdb/testsuite/outputs/gdb.base/step-over-no-symbols/step-over-no-symbols...done.
(gdb) delete breakpoints
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) break main
Breakpoint 1 at 0x400840: file .../gdb/testsuite/gdb.base/start.c, line 34.
[...]
(gdb) continue
Continuing.

Breakpoint 1, main () at .../gdb/testsuite/gdb.base/start.c:34
34	  foo();
(gdb) delete breakpoints
Delete all breakpoints? (y or n) y
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) file
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
No executable file now.
Discard symbol table from `.../gdb/testsuite/outputs/gdb.base/step-over-no-symbols/step-over-no-symbols'? (y or n) y
No symbol file now.
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: purging symbols
p /x $pc
$1 = 0x40084000
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: get before PC
break *$pc
Breakpoint 2 at 0x40084000
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: break *$pc
set displaced-stepping off
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: set displaced-stepping off
stepi
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x40084000

Command aborted.
(gdb) FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: stepi
p /x $pc
$2 = 0x40084000
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: get after PC
FAIL: gdb.base/step-over-no-symbols.exp: displaced=off: advanced
Remote debugging from host ...
monitor exit
(gdb) Killing process(es): ...
testcase .../gdb/testsuite/gdb.base/step-over-no-symbols.exp completed in 2 seconds

which shows that with the removal of the executable debugged the
endianness of $pc still at `main' gets swapped and the value in that
register is now incorrectly interpreted as 0x40084000 rather than
0x400840 as shown earlier on with the `break' command.  Consequently the
debug session no longer works as expected, until the endianness is
overridden with an explicit `set endian little' command.

This will happen while working with any target hardware whose endianness
does not match the default GDB target's endianness guessed and recorded
for a later use in `initialize_current_architecture'.

Given that within a single run of GDB it is more likely that consecutive
target connections will use the same endianness than that the endianness
will be swapped between connections, it makes sense to preserve the last
endianness explicitly selected as the automatic default.  It will make a
session like above, where an executable is removed, work correctly and
will retain the endianness for a further reconnection to the target.

And the new automatic default will still be overridden by subsequently
choosing a binary to debug, or with an explicit `set endian' command.

With the change in place the test case above completes successfully:

(gdb) continue
Continuing.

Breakpoint 1, main () at .../gdb/testsuite/gdb.base/start.c:34
34	  foo();
(gdb) delete breakpoints
Delete all breakpoints? (y or n) y
(gdb) info breakpoints
No breakpoints or watchpoints.
(gdb) file
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
No executable file now.
Discard symbol table from `.../gdb/testsuite/outputs/gdb.base/step-over-no-symbols/step-over-no-symbols'? (y or n) y
No symbol file now.
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: purging symbols
p /x $pc
warning: GDB can't find the start of the function at 0x400840.

    GDB is unable to find the start of the function at 0x400840
and thus can't determine the size of that function's stack frame.
This means that GDB may be unable to access that stack frame, or
the frames below it.
    This problem is most likely caused by an invalid program counter or
stack pointer.
    However, if you think GDB should simply search farther back
from 0x400840 for code which looks like the beginning of a
function, you can increase the range of the search using the `set
heuristic-fence-post' command.
$1 = 0x400840
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: get before PC
break *$pc
Breakpoint 2 at 0x400840
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: break *$pc
set displaced-stepping off
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: set displaced-stepping off
stepi
warning: GDB can't find the start of the function at 0x4007f8.
0x004007f8 in ?? ()
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: stepi
p /x $pc
$2 = 0x4007f8
(gdb) PASS: gdb.base/step-over-no-symbols.exp: displaced=off: get after PC
PASS: gdb.base/step-over-no-symbols.exp: displaced=off: advanced
Remote debugging from host ...
monitor exit
(gdb) Killing process(es): ...
testcase .../gdb/testsuite/gdb.base/step-over-no-symbols.exp completed in 2 seconds

	gdb/
	* arch-utils.c (gdbarch_info_fill): Set `default_byte_order' to
	the endianness selected.
	* NEWS: Document `set endian auto' mode operation update.

	gdb/doc/
	* gdb.texinfo (Choosing Target Byte Order): Document endianness
	selection details with the `set endian auto' mode.

	gdb/testsuite
	* gdb.base/endian.exp: New test.
	* gdb.base/endian.c: New test source.
2018-05-31 15:15:35 +01:00
Andrew Burgess 45f25d6c83 gdb: Restore selected frame in print_frame_local_vars
PR gdb/23203 reports 'bt full' causing the currently selected frame to
change, this issue is fixed in this commit.

Add a new class scoped_restore_selected_frame that saves and restores
the selected frame.  Make use of this in print_frame_local_vars to
restore the selected frame on exit.

gdb/ChangeLog:

	PR gdb/23203
	* frame.c
	(scoped_restore_selected_frame::scoped_restore_selected_frame):
	Define.
	(scoped_restore_selected_frame::~scoped_restore_selected_frame):
	Define.
	* frame.h (class scoped_restore_selected_frame): New class.
	* stack.c (print_frame_local_vars): Remove catching and rethrowing
	of any exception, use scoped_restore_selected_frame to restore the
	frame instead.

gdb/testsuite/ChangeLog:

	PR gdb/23203
	* gdb.base/bt-selected-frame.c: New file.
	* gdb.base/bt-selected-frame.exp: New file.
	* lib/gdb.exp (get_current_frame_number): New function.
2018-05-24 18:01:31 +01:00