Commit Graph

96300 Commits

Author SHA1 Message Date
Tom Tromey 9162a27c5f Change gdb test suite's TERM setting
This changes the gdb test suite to set TERM to "dumb" by default.
This setting disables terminal styling, so that the existing tests do
not need to be updated.

gdb/testsuite/ChangeLog
2018-12-28  Tom Tromey  <tom@tromey.com>

	* lib/gdb.exp (gdb_init): Set the TERM environment variable to
	"dumb".
	* gdb.base/readline.exp (operate_and_get_next): Save and restore
	the TERM environment variable.
2018-12-28 12:49:48 -07:00
Tom Tromey eedeedd2a5 Introduce ui_file_style
This introduces the new ui_file_style class and various helpers.  This
class represents a terminal style and provides methods for parsing and
emitting the corresponding ANSI terminal escape sequences.

gdb/ChangeLog
2018-12-28  Tom Tromey  <tom@tromey.com>

	* unittests/style-selftests.c: New file.
	* ui-style.c: New file.
	* ui-style.h: New file.
	* ui-file.h: Include ui-style.h.
	* Makefile.in (COMMON_SFILES): Add ui-style.c.
	(HFILES_NO_SRCDIR): Add ui-style.h.
	(SUBDIR_UNITTESTS_SRCS): Add style-selftests.c.
2018-12-28 12:49:48 -07:00
Tom Tromey 7170dadf59 Add a "context" argument to add_setshow_enum_cmd
This adds a "context" argument to add_setshow_enum_cmd.  Now
add_setshow_enum_cmd will call set_cmd_context on both of the new
commands.  This is used in a later patch.

gdb/ChangeLog
2018-12-28  Tom Tromey  <tom@tromey.com>

	* command.h (add_setshow_enum_cmd): Add "context" argument.
	* cli/cli-decode.c (add_setshow_enum_cmd): Add "context"
	argument.  Call set_cmd_context.
2018-12-28 12:49:47 -07:00
Tom Tromey c5603d5063 Change wrap buffering to use a std::string
Currently wrap buffering is implemented by allocating a string that is
the same width as the window, and then writing characters into it.
However, if gdb emits terminal escapes, then these could possibly
overflow the buffer.

To prevent this, change the wrap buffer to be a std::string and update
the various uses.

This also changes utils.c to always emit characters to the wrap
buffer.  This simplifies future patches which emit terminal escape
sequences, and also makes it possible for the "echo" and "printf"
commands to be used to emit terminal escapes and have these work in
the TUI.

gdb/ChangeLog
2018-12-28  Tom Tromey  <tom@tromey.com>

	* utils.c (filter_initialized): New global.
	(wrap_buffer): Now a std::string.
	(wrap_pointer): Remove.
	(flush_wrap_buffer): New function.
	(filtered_printing_initialized, set_width, wrap_here)
	(fputs_maybe_filtered): Update.
2018-12-28 12:49:47 -07:00
Philippe Waroquiers 94f2c73066 Fix leak of set/show verbose doc, avoid xfree of static string
In the tests
  py-pp-registration/gdb.log
  default/gdb.log
  foll-fork/gdb.log
  setshow/gdb.log
  break-interp/gdb.log
Valgrind detects a leak of the doc strings for the set and show verbose cmd.

Here is the stacktrace of the leaked set doc:
==25548== 15 bytes in 1 blocks are definitely lost in loss record 101 of 3,120
==25548==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==25548==    by 0x409C27: xmalloc (common-utils.c:44)
==25548==    by 0x778AF9: xstrdup (xstrdup.c:34)
==25548==    by 0x3F860F: add_setshow_cmd_full(char const*, command_class, var_types, void*, char const*, char const*, char const*, void (*)(char const*, int, cmd_list_element*), void (*)(ui_file*, int, cmd_list_element*, char const*), cmd_list_element**, cmd_list_element**, cmd_list_element**, cmd_list_element**) [clone .constprop.10] (cli-decode.c:495)
==25548==    by 0x3F8ADB: add_setshow_boolean_cmd(char const*, command_class, int*, char const*, char const*, char const*, void (*)(char const*, int, cmd_list_element*), void (*)(ui_file*, int, cmd_list_element*, char const*), cmd_list_element**, cmd_list_element**) (cli-decode.c:593)
==25548==    by 0x3F7442: _initialize_cli_cmds() (cli-cmds.c:1768)
==25548==    by 0x69EED3: initialize_all_files() (init.c:365)
==25548==    by 0x658A84: gdb_init(char*) (top.c:2163)
==25548==    by 0x5403E1: captured_main_1 (main.c:863)
==25548==    by 0x5403E1: captured_main (main.c:1167)
==25548==    by 0x5403E1: gdb_main(captured_main_args*) (main.c:1193)
==25548==    by 0x289CA7: main (gdb.c:32)

The leak is created by top.c set_verbose 'elaborate joke':
the doc string is changed according to the verbosity:
  (gdb) help set verbose
  Set verbosity.
  (gdb) set verbose on
  (gdb) help set verbose
  Set verbose printing of informational messages.
  (gdb)

set_verbose creates the leak as it replaces the string allocated in
the above stacktrace by a static (non translated) string:
...
  if (info_verbose)
    {
      c->doc = "Set verbose printing of informational messages.";
...

Also, this can possibly trigger a call to 'free' of a static string,
as c->doc_allocated is kept true, while the string is not allocated anymore.

This patch:
 * fixes the leak by freeing the previous docs if doc_allocated.
 * internationalize the messages.
 * properly sets doc_allocated to 0 once doc strings are static.

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

	* top.c (set_verbose): Free previous docs if doc_allocated.
	Internationalize messages.  Set doc_allocated to 0.
2018-12-28 12:19:59 +01:00
Eli Zaretskii 156f236692 Avoid internal errors when stepping outside 'main' on MinGW
When one steps with "next" past the 'main's 'return' statement
in MinGW programs built by mingw.org's tools, PC lands in a
function whose symbol is not in any symtab.  GDB then looks
up the nearest symbol, and should find none, because all those
with addresses below PC are not real functions.  Having
unresolved symbols, whose address is zero, in minsyms tricked
GDB into using these bogus symbols, which then caused
assertion violation and internal_error.  See the discussion at
https://sourceware.org/ml/gdb-patches/2018-12/msg00176.html
for more details.

gdb/ChangeLog
2018-12-28  Eli Zaretskii  <eliz@gnu.org>

	* coffread.c (coff_symtab_read): Don't record in minsyms symbols
	that are unresolved.  This avoids triggering an internal error
	when stepping outside of 'main' in MinGW programs.
2018-12-28 09:02:04 +02:00
Alan Modra 0e41bebb93 PR24015, glibc-2.28 on little-endian mips32 broken
Commit 2bf2bf23da exposed a bug on targets that create common sections
other than the standard ELF SHN_COMMON.  If these are output by ld -r,
then their type becomes SHT_PROGBITS unless the target handles them
specially (eg. by elf_backend_special_sections), and if they are
merged into .bss/.sbss by ld -r then that section becomes SHT_PROGBITS.

Worse, if they are output by ld -r, then their size is increased by
bfd_generic_define_common_symbol during final link, which leads to
bogus file contents being copied to output.

For mips, it seems to me that the .scommon section should not be
output for ld -r, but I haven't made that change in this patch.

	PR 24015
	* elf.c (bfd_elf_get_default_section_type): Make common sections
	SHT_NOBITS.
	* linker.c (bfd_generic_define_common_symbol): Clear
	SEC_HAS_CONTENTS.
2018-12-28 15:02:08 +10:30
Alan Modra cb87d9f1a4 PR23966, mingw failure due to 32-bit long
PR 23966
	* libbfd.c (SSIZE_MAX): Define.
	(bfd_malloc, bfd_realloc): Don't cast size to long to check for
	"negative" values, compare against SSIZE_MAX instead.
2018-12-28 15:02:04 +10:30
Alan Modra d1a3c973fa PR24028, PPC_INT_FMT
PPC_INT_FMT is redundant now that bfd.h pulls in inttypes.h if
available.  Apparently MacOS Mojave defines int64_t as long long even
though long is also 64 bits, which confuses the logic selecting
PPC_INT_FMT (and BFD_PRI64 too).  Hopefully inttypes.h is available on
Mojave.

	PR 24028
include/
	* opcode/ppc.h (PPC_INT_FMT): Delete.
opcodes/
	* ppc-dis.c (print_insn_powerpc): Replace PPC_INT_FMT uses with
	PRId64/PRIx64.
2018-12-28 15:02:04 +10:30
GDB Administrator b6d3efdc59 Automatic date update in version.in 2018-12-28 00:00:22 +00:00
Tom Tromey bc543c902f Translate PyExc_KeyboardInterrupt to gdb "quit"
A while back I typed "info pretty-printers" with a large number of
printers installed, and I typed "q" to stop the pagination.  I noticed
that gdb printed a Python exception in this case.

It seems to me that, instead, quitting pagination (or control-c'ing a
Python command generally) should be handled the same way that gdb
normally handles a quit.

This patch implements this idea by changing gdbpy_handle_exception to
treat PyExc_KeyboardInterrupt specially.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* python/py-utils.c (gdbpy_handle_exception): Translate
	PyExc_KeyboardInterrupt to quit.

gdb/testsuite/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add
	pagination test.
2018-12-27 13:34:39 -07:00
Tom Tromey 6ef2312a17 Consolidate some Python exception-printing functions
A few places in the Python code would either call gdbpy_print_stack,
or throw a gdb "quit", depending on the pending exception.  This patch
consolidates these into a helper function.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* python/python-internal.h (gdbpy_print_stack_or_quit): Declare.
	* python/py-unwind.c (pyuw_sniffer): Use
	gdbpy_print_stack_or_quit.
	* python/py-framefilter.c (throw_quit_or_print_exception):
	Remove.
	(gdbpy_apply_frame_filter): Use gdbpy_print_stack_or_quit.
	* python/python.c (gdbpy_print_stack_or_quit): New function.
2018-12-27 13:34:39 -07:00
Tom Tromey ec9c2750b7 Use gdbpy_convert_exception in a few more spots
I noticed a few places were converting a gdb exception to a Python
exception "by hand".  It's better to use the existing
gdbpy_convert_exception helper function, as this handles memory errors
correctly, and in the future may be enhanced in other ways.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* python/py-value.c (convert_value_from_python): Use
	gdbpy_convert_exception.
	* python/py-param.c (parmpy_init): Use gdbpy_convert_exception.
	* python/py-cmd.c (cmdpy_init): Use gdbpy_convert_exception.
	* python/py-breakpoint.c (bppy_init): Use
	gdbpy_convert_exception.
2018-12-27 13:34:38 -07:00
Tom Tromey 6987262214 Build gdb "nat" files in subdirectory
This moves the various "nat" object files into the nat/ subdirectory.
This allows for the removal of a pattern rule from the gdb Makefile,
which is a small cleanup.

I made the configure.nat change in a (semi-) automated way, hopefully
meaning that it is more likely to be correct than had I done it by
hand.

Eventually I would like for the various configure scripts to only
mention source files, and let the Makefile compute the object file
names.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* configure.nat (NATDEPFILES): Use nat/ prefix.
	* Makefile.in (CONFIG_SRC_SUBDIR): Add nat.
	(%.o: ${srcdir}/nat/%.c): Remove rule.
	(INIT_FILES): Do not filter out NATDEPFILES.
2018-12-27 13:15:31 -07:00
Tom Tromey b180d0a254 Make init.c depend on source files
I noticed that init.c depends on the object files that go into gdb.
Because init.c actually only requires the contents of the
corresponding source files, this unnecessarily serializes the step
that builds init.c.

This patch changes gdb's Makefile to make init.c depend on the source
files.  This also simplifies the rule to build init.c.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* Makefile.in (INIT_FILES): Redefine.
	(stamp-init): Remove sed, tr invocations.  Use for loop.  Don't
	set LANG or LC_ALL.
2018-12-27 13:15:31 -07:00
Tom Tromey c88c222e3c Remove gdbtypes special case from init.c rule
The rule to make init.c has a special case for gdbtypes, with a long
explanatory comment.  All of this is obsolete, as the globals referred
to by the comment no longer exist.  This patch simplifies the rule.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* Makefile.in (stamp-init): Remove gdbtypes special case.
2018-12-27 13:15:31 -07:00
John Baldwin 47db57fd4e Remove empty nm-fbsd.h header for FreeBSD/i386 native target.
gdb/ChangeLog:

	* config/i386/nm-fbsd.h: Remove file.
	* Makefile.in (HFILES_NO_SRCDIR): Remove config/i386/nm-fbsd.h.
	* configure.nat: Remove NAT_FILE for FreeBSD/i386.
2018-12-27 11:42:32 -08:00
Tom Tromey af9a216102 Use DISABLE_COPY_AND_ASSIGN in minimal_symbol_reader
This changes minimal_symbol_reader to use DISABLE_COPY_AND_ASSIGN,
rather than the manual approach it currently uses.

Tested by rebuilding.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* minsyms.h (class minimal_symbol_reader): Use
	DISABLE_COPY_AND_ASSIGN.
2018-12-27 12:29:48 -07:00
Tom Tromey 075c55e0cc Remove more calls to xfree from Python
This changes the Python code to remove some more calls to xfree, in
favor of self-managing data structures.

Tested on x86-64 Fedora 28.

gdb/ChangeLog
2018-12-27  Tom Tromey  <tom@tromey.com>

	* python/python.c (python_interactive_command): Use std::string.
	(gdbpy_parameter): Likewise.
	* python/py-utils.c (unicode_to_encoded_string): Update comment.
	* python/py-symtab.c (salpy_str): Use PyString_FromFormat.
	* python/py-record-btrace.c (recpy_bt_insn_data): Use
	byte_vector.
	* python/py-objfile.c (objfpy_get_build_id): Use
	unique_xmalloc_ptr.
	* python/py-inferior.c (infpy_read_memory): Use
	unique_xmalloc_ptr.
	* python/py-cmd.c (gdbpy_parse_command_name): Use std::string.
2018-12-27 10:50:43 -07:00
Philippe Waroquiers 293bf1a719 Fix gdb.ada/fun_renaming.exp by using more unique names.
The test fails due to conflict between var 'next' and s-pooloc.adb next:
(gdb) print next(1)
Multiple matches for next
[0] cancel
[1] pack.next (integer) return integer at /bd/home/philippe/gdb/git/binutils-gdb/gdb/testsuite/gdb.ada/fun_renaming/pack.adb:19
[2] system.pool_local.next (system.address) return system.pool_local.acc_address at s-pooloc.adb:151
> FAIL: gdb.ada/fun_renaming.exp: print next(1) (timeout)

Fix by making the names and renamings more unique.

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

	* gdb.ada/fun_renaming/pack.ads (Next): Rename to Fun_Rename_Test_Next.
	(Renamed_Next): Rename to Renamed_Fun_Rename_Test_Next.
	gdb.ada/fun_renaming/pack.adb (Next): Rename to Fun_Rename_Test_Next.
	gdb.ada/fun_renaming/fun_renaming.adb (N): Rename to Fun_Rename_Test_N.
	gdb.ada/fun_renaming.exp: Update accordingly.
2018-12-27 10:47:00 +01:00
Philippe Waroquiers 3cf139964e Fix gdb.ada/assign_arr.exp by using more unique names.
The test fails (timeout) due to conflict between var 'input' and s-ststop.adb 'input':
(gdb) print input.u2 := (0.25,0.5,0.75)
Multiple matches for input
[0] cancel
[1] system.strings.stream_ops.storage_array_ops.input (access ada.streams.root_stream_type; system.strings.stream_ops.io_kind; natural) return system.storage_elements.storage_array at s-ststop.adb:127
[2] system.strings.stream_ops.stream_element_array_ops.input (access ada.streams.root_stream_type; system.strings.stream_ops.io_kind; natural) return ada.streams.stream_element_array at s-ststop.adb:127
[3] system.strings.stream_ops.string_ops.input (access ada.streams.root_stream_type; system.strings.stream_ops.io_kind; natural) return string at s-ststop.adb:127
[4] system.strings.stream_ops.wide_string_ops.input (access ada.streams.root_stream_type; system.strings.stream_ops.io_kind; natural) return wide_string at s-ststop.adb:127
[5] system.strings.stream_ops.wide_wide_string_ops.input (access ada.streams.root_stream_type; system.strings.stream_ops.io_kind; natural) return wide_wide_string at s-ststop.adb:127
[6] target_wrapper.input at /bd/home/philippe/gdb/git/info_t/gdb/testsuite/gdb.ada/assign_arr/target_wrapper.ads:24
> FAIL: gdb.ada/assign_arr.exp: print input.u2 := (0.25,0.5,0.75) (timeout)

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

	* gdb.ada/assign_arr/target_wrapper.ads (Input): Rename to
	Assign_Arr_Input.
	main_p324_051.adb: Update accordingly.
	gdb.ada/assign_arr.exp: Likewise.
2018-12-27 10:47:00 +01:00
Philippe Waroquiers afcfda091e Improve gdb.ada/rename_subscript_param.exp by using more unique names.
With old compilers, the test fails because no debug info is generated
for 'B' and GDB finds some 'b' in atnat.h:

(gdb) print b
Multiple matches for b
[0] cancel
[1] b at ../sysdeps/ieee754/dbl-64/atnat.h:106
[2] b at ../sysdeps/ieee754/dbl-64/atnat.h:106
[3] b at ../sysdeps/ieee754/dbl-64/atnat.h:106
> FAIL: gdb.ada/rename_subscript_param.exp: print b before changing its value (timeout)

Avoid the timeout by renaming 'b' to rename_subscript_param_b.

Also, change 'before' to 'after' in the gdb_test message that prints
the value after changing it.

The test still fails with old compilers that do not properly
generate debug info for this renaming:
(gdb) print rename_subscript_param_b
No definition of "rename_subscript_param_b" in current context.
(gdb) FAIL: gdb.ada/rename_subscript_param.exp: print rename_subscript_param_b before changing its value

Note: if the compiler would generate the correct debug info, the test should
succeed with the name B.  However, waiting for this fix, changing the name
ensures that the test fails directly, instead of causing a timeout.

2018-12-26  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	PR ada/23381
	* gdb.ada/rename_subscript_param/pkg.adb (B): Rename to
	Rename_Subscript_Param_B.  All users updated.
	gdb.ada/rename_subscript_param.exp: Test names made unique.
	Note that PR ada/23381 is only fully fixed when using a recent
	compiler.
2018-12-27 10:47:00 +01:00
Philippe Waroquiers 2ab54467f8 Fix gdb.ada/packed_array_assign.exp by using more unique names.
The test gdb.ada/packed_array_assign fails due to conflict between component 'w'
and system.dim.mks.w:

(gdb) print pra := ((x => 2, y => 0, w => 17), pr, (x => 7, y => 1, w => 23))
Unknown component name: system.dim.mks.w.
(gdb) FAIL: gdb.ada/packed_array_assign.exp: print pra := ((x => 2, y => 0, w => 17), pr, (x => 7, y => 1, w => 23))

Also, depending on the compiler version, the component w might be reordered
and placed before components x and y.
So, change the component order in the source, so that both an old
compiler (GNATMAKE 6.3.0, gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516)
and a new compiler (GNATMAKE Pro 20.0w (20181210-82), based on gcc 8.2.1)
produce the same component order (checked by using -gnatR3s).

So, update to test the new (more unique) names in the source order.

2018-12-26  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.ada/packed_array_assign/aggregates.ads (Packed_Rec):
	Rename components to Packed_Array_Assign_[X|Y|W].  Place
	component Packed_Array_Assign_W as first component, to ensure
	old and new compilers have the same representation.
	All users updated.
2018-12-27 10:47:00 +01:00
Simon Marchi 84b68c77e7 target.c: Remove struct keyword in range-based for
I get this when compiling with a gcc 6.3.0-based cross-compiler:

  CXX    target.o
/home/simark/src/binutils-gdb/gdb/target.c: In static member function 'static void target_terminal::restore_inferior()':
/home/simark/src/binutils-gdb/gdb/target.c:396:10: error: types may not be defined in a for-range-declaration [-Werror]
     for (struct inferior *inf : all_inferiors ())
          ^~~~~~

Accomodate it by dropping the unnecessary struct keyword.  Actually, I used
"::inferior", otherwise it resolves to the inferior method of the
target_terminal class.

gdb/ChangeLog:

	* target.c (target_terminal::restore_inferior): Remove struct keyword.
2018-12-26 20:14:18 -05:00
GDB Administrator 39c2d8290b Automatic date update in version.in 2018-12-27 00:00:26 +00:00
Simon Marchi 50794b45a2 Improve "set debug separate-debug-file"
"set debug separate-debug-file" shows which candidates are considered,
when trying to find separate debug info.  But it's not clear if GDB used
a certain candidate, and if not, why not.  This patch adds some
precision:

Before:

  Looking for separate debug info (debug link) for /lib/x86_64-linux-gnu/libc.so.6
    Trying /lib/x86_64-linux-gnu/libc-2.23.so
    Trying /lib/x86_64-linux-gnu/.debug/libc-2.23.so
    Trying /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.23.so

After:

  Looking for separate debug info (debug link) for /lib/x86_64-linux-gnu/libc.so.6
    Trying /lib/x86_64-linux-gnu/libc-2.23.so... no, same file as the objfile.
    Trying /lib/x86_64-linux-gnu/.debug/libc-2.23.so... no, unable to open.
    Trying /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.23.so... yes!

gdb/ChangeLog:

	* build-id.c (build_id_to_debug_bfd): Enhance debug output.
	* symfile.c (separate_debug_file_exists): Likewise.
2018-12-26 11:49:51 -05:00
GDB Administrator 5172760036 Automatic date update in version.in 2018-12-26 00:00:30 +00:00
GDB Administrator f493efef89 Automatic date update in version.in 2018-12-25 00:00:21 +00:00
Andrew Burgess 6f0ffe50c8 gdb: Allow struct fields named double
The 64-bit RISC-V target currently models the floating point registers
as having the following type:

    union riscv_double
    {
        builtin_type_ieee_single float;
        builtin_type_ieee_double double;
    }

Notice the choice of names for the fields of this struct, possibly not
ideal choices, as these are not valid field names in C.  However, this
type is only ever defined within GDB (or in the target description),
and no restriction seems to exist on the field names in that case.

The problem though is that currently:

    (gdb) info registers $ft0
    ft0            {float = 0, double = 0}	(raw 0x0000000000000000)
    (gdb) p $ft0.float
    $1 = 0
    (gdb) p $ft0.double
    A syntax error in expression, near `double'.

We can access the 'float' field, but not the 'double' field.  This is
because the string 'double' is handled differently to the string
'float' in c-exp.y.

In both cases the string '$ft0' is parsed as a VARIABLE expression.

In the 'float' case, the string 'float' becomes a generic NAME token
in 'lex_one_token', which then allows the rule "exp '.' name" to match
and the field name lookup to occur.

The 'double' case is different.  In order to allow parsing of the type
string 'long double', the 'double' string becomes the token
DOUBLE_KEYWORD.  At this point there's no rule to match "exp '.'
DOUBLE_KEYWORD", so we can never lookup the field named 'double'.

We could rename the fields for RISC-V, and maybe that would be the
best solution.  However, its not hard to allow for fields named
'double', which is what this patch does.

A new case is added to the 'field_name' rule to match the
DOUBLE_KEYWORD, and create a suitable 'struct stoken'.  With this done
the "exp '.'  field_name" pattern can now match, and we can lookup the
double field.

With this patch in place I now see this behaviour:

    (gdb) info registers $ft0
    ft0            {float = 0, double = 0}	(raw 0x0000000000000000)
    (gdb) p $ft0.float
    $1 = 0
    (gdb) p $ft0.double
    $2 = 0

I've gone ahead and handled INT_KEYWORD, LONG, SHORT, SIGNED_KEYWORD,
and UNSIGNED as well within field_name.

I've added a new test for this functionality.

This change was tested on x86-64 GNU/Linux with no regressions.

gdb/ChangeLog:

	* c-exp.y (field_name): Allow DOUBLE_KEYWORD, INT_KEYWORD, LONG,
	SHORT, SIGNED_KEYWORD, and UNSIGNED tokens to act as a field
	names.
	(typename_stoken): New function.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-unusual-field-names.c: New file.
	* gdb.dwarf2/dw2-unusual-field-names.exp: New file.
2018-12-24 17:25:25 +00:00
Andrew Burgess 0f5d3f636a gdb: Add new parser rule for structure field names
Introduces a new rule in c-exp.y for matching structure field names.

This is a restructure in preparation for the next commit, this commit
shouldn't result in any user visible changes.

gdb/ChangeLog:

	* c-exp.y (field_name): New %token, and new rule.
	(exp): Replace uses of 'name' with 'field_name' where appropriate.
2018-12-24 17:25:25 +00:00
Andrew Burgess b6c95c0cc5 gdb: Extend the comments in c-exp.y
In an attempt to fix PR gdb/13368 this commit adds some comments to
c-exp.y which hopefully makes the type parsing code a little clearer.
There are no code changes here, so there should be no user visible
changes after this commit.

gdb/ChangeLog:

	PR gdb/13368
	* c-exp.y (typebase): Extend the comment.
	(ident_tokens): Likewise.
2018-12-24 17:25:25 +00:00
Tom Tromey 45b8ae0c33 Simplify dwarf2_find_containing_comp_unit
In an earlier patch discussion we noticed that
dwarf2_find_containing_comp_unit takes the address of sect_off, but
doesn't actually need to.  This is a leftover from before
C++-ification.  This patch simplifies the function.

Tested using gdb.dwarf2 on x86-64 Fedora 28.

gdb/ChangeLog
2018-12-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_find_containing_comp_unit): Don't take
	address of sect_off.
2018-12-24 09:58:53 -07:00
Philippe Waroquiers b5a1e55720 Fix gdb.ada bp_fun_addr failure due to conflict between fun 'a' and s-dimmks.ads 'A'.
The test fails (timeout) due to:
  (gdb) PASS: gdb.ada/bp_fun_addr.exp: break *a'address
  run
  Starting program: /bd/home/philippe/gdb/git/build_info_t/gdb/testsuite/outputs/gdb.ada/bp_fun_addr/a
  Multiple matches for a
  [0] cancel
  [1] a at /bd/home/philippe/gdb/git/info_t/gdb/testsuite/gdb.ada/bp_fun_addr/a.adb:18
  [2] system.dim.mks.a at s-dimmks.ads:115
  > FAIL: gdb.ada/bp_fun_addr.exp: run until breakpoint at a'address (timeout)
  testcase /home/philippe/gdb/git/build_info_t/gdb/testsuite/../../../info_t/gdb/testsuite/gdb.ada/bp_fun_addr.exp completed in 10 seconds

Fix this by using a fun name that has more chances to be unique.

2018-12-24  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.ada/bp_fun_addr/a.adb (a): Rename to bp_fun_addr.
	Filename a.adb changed to bp_fun_addr.adb.
	gdb.ada/bp_fun_addr.exp: Update test accordingly.
2018-12-24 13:11:12 +01:00
GDB Administrator 56334baf0c Automatic date update in version.in 2018-12-24 00:00:20 +00:00
H.J. Lu b366503e45 i386: Remove the unused bfd pointer argument
Remove the unused bfd pointer argument of elf_i386_rtype_to_howto.

	* elf32-i386.c (elf_i386_rtype_to_howto): Remove the unused bfd
	pointer argument.
	(elf_i386_info_to_howto_rel): Updated.
	(elf_i386_tls_transition): Likewise.
	(elf_i386_relocate_section): Likewise.
2018-12-23 09:45:29 -08:00
Joel Brobecker 03eccf7a34 Document the GDB 8.2.1 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 8.2.1 released.
2018-12-23 10:02:17 +04:00
GDB Administrator dff021e14a Automatic date update in version.in 2018-12-23 00:01:21 +00:00
Andrew Burgess 74e3300d8a gdb/riscv: Prevent buffer overflow in riscv_return_value
The existing code for reading and writing the return value can
overflow the passed in buffers in a couple of situations.  This commit
aims to resolve these issues.

The problems were detected using valgrind, here are two examples,
first from gdb.base/structs.exp:

    (gdb) p/x fun9()
    ==31353== Invalid write of size 8
    ==31353==    at 0x4C34153: memmove (vg_replace_strmem.c:1270)
    ==31353==    by 0x632EBB: memcpy (string_fortified.h:34)
    ==31353==    by 0x632EBB: readable_regcache::raw_read(int, unsigned char*) (regcache.c:538)
    ==31353==    by 0x659D3F: riscv_return_value(gdbarch*, value*, type*, regcache*, unsigned char*, unsigned char const*) (riscv-tdep.c:2593)
    ==31353==    by 0x583641: get_call_return_value (infcall.c:448)
    ==31353==    by 0x583641: call_thread_fsm_should_stop(thread_fsm*, thread_info*) (infcall.c:546)
    ==31353==    by 0x59BBEC: fetch_inferior_event(void*) (infrun.c:3883)
    ==31353==    by 0x53890B: check_async_event_handlers (event-loop.c:1064)
    ==31353==    by 0x53890B: gdb_do_one_event() [clone .part.4] (event-loop.c:326)
    ==31353==    by 0x6CA34B: wait_sync_command_done() (top.c:503)
    ==31353==    by 0x584653: run_inferior_call (infcall.c:621)
    ...

And from gdb.base/call-sc.exp:

    (gdb) advance fun
    fun () at /gdb/gdb/testsuite/gdb.base/call-sc.c:41
    41	  return foo;
    (gdb) finish
    ==1968== Invalid write of size 8
    ==1968==    at 0x4C34153: memmove (vg_replace_strmem.c:1270)
    ==1968==    by 0x632EBB: memcpy (string_fortified.h:34)
    ==1968==    by 0x632EBB: readable_regcache::raw_read(int, unsigned char*) (regcache.c:538)
    ==1968==    by 0x659D01: riscv_return_value(gdbarch*, value*, type*, regcache*, unsigned char*, unsigned char const*) (riscv-tdep.c:2576)
    ==1968==    by 0x5891E4: get_return_value(value*, type*) (infcmd.c:1640)
    ==1968==    by 0x5892C4: finish_command_fsm_should_stop(thread_fsm*, thread_info*) (infcmd.c:1808)
    ==1968==    by 0x59BBEC: fetch_inferior_event(void*) (infrun.c:3883)
    ==1968==    by 0x53890B: check_async_event_handlers (event-loop.c:1064)
    ==1968==    by 0x53890B: gdb_do_one_event() [clone .part.4] (event-loop.c:326)
    ==1968==    by 0x6CA34B: wait_sync_command_done() (top.c:503)
    ...

There are a couple of problems with the existing code, that are all
related.

In riscv_call_arg_struct we incorrectly rounded up the size of a
structure argument.  This is unnecessary, and caused GDB to read too
much data into the output buffer when extracting a struct return
value.

In fixing this it became clear that we were incorrectly assuming that
any value being placed in a register (or read from a register) would
always access the entire register.  This is not true, for example a
9-byte struct on a 64-bit target places 8-bytes in one registers and
1-byte in a second register (assuming available registers).  To handle
this I switch from using cooked_read to cooked_read_part.

Finally, when processing basic integer return value types these are
extended to xlen sized types and then passed in registers.  We
currently don't handle this type expansion in riscv_return_value, but
we do in riscv_push_dummy_call.  The result is that small integer
types (like char) result in a full xlen sized register being written
into the output buffer, which results in buffer overflow.  To address
this issue we now create a value of the expanded type and use this
values contents buffer to hold the return value before casting the
value down to the smaller expected type.

This patch resolves all of the valgrind issues I have found so far,
and causes no regressions.  Tested against RV32/64 with and without
floating point support.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_call_arg_struct): Don't adjust size before
	assigning locations.
	(riscv_return_value): Take more care not to read/write outside of
	argument buffer.  Cast return value between the declared type and
	the abi type.
2018-12-22 10:06:50 +00:00
Andrew Burgess ecc82c0590 gdb/riscv: Add float status registers to save and restore reggroups
We should save and restore the floating point status registers.  This
became an issue when testing 32-bit float on a target with 64-bit with
the gdb.base/callfuncs.exp test.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_register_reggroup_p): Save and restore fcsr,
	fflags, and frm registers.
2018-12-22 10:02:20 +00:00
Andrew Burgess fb44d95af6 gdb/riscv: Add gdb to dwarf register number mapping
Provide a mapping between GDB's register numbers and DWARF's register
numbers.  This resolves some failures that I was seeing on
gdb.base/store.exp when running on an rv64imfdc target.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_dwarf_reg_to_regnum): New function.
	(riscv_gdbarch_init): Register new function with gdbarch.
	* riscv-tdep.h: New enum to define RISC-V DWARF register numbers.
2018-12-22 10:02:20 +00:00
Simon Marchi e08b849efa Add debug output for recorded minsyms
While discussing this issue:

  https://sourceware.org/ml/gdb-patches/2018-12/threads.html#00082

I added a printf gated by "set debug symtab-create" to be able to
quickly see all minimal symbols recorded by GDB.  I thought it would be
useful to have it built-in, for the future.  Here's how the output
looks:

  Recording minsym:  mst_data                         0x400780    15  _IO_stdin_used
  Recording minsym:  mst_text                         0x400700    13  __libc_csu_init
  Recording minsym:  mst_bss                          0x601058    25  _end

gdb/ChangeLog:

	* minsyms.c (mst_str): New.
	(minimal_symbol_reader::record_full): Add debug output.
2018-12-21 21:19:18 -05:00
GDB Administrator 5ec79917fa Automatic date update in version.in 2018-12-22 00:00:29 +00:00
Jan Vrany 6e8b1ab2fd Fix various tests to use -no-pie linker flag when needed
Various tests use test code written in i386 / x86_64 assembly that cannot
be used to create PIE executables. Therefore compilation of test programs
failed on systems where the compiler default is to create PIE executable.

The solution is to use -no-pie linker flag, however, such flag may not
(is not) supported by all compilers GDB needs to support (e.g. gcc 4.8).
To handle this, introduce a new flag to gdb_compile - nopie - which
inserts -no-pie linker flag where supported and is no-op where it is
not. By default, -no-pie flag is inserted since most modern compiler do
support it.
2018-12-21 15:53:08 -05:00
John Baldwin 6d78332e77 Workaround a FreeBSD kernel bug resulting in spurious SIGTRAP events.
The ptrace command PT_LWPINFO to request detailed information about a
stopped thread can return stale signal information from an earlier
stop.  Events which are reporting an intercepted signal will always
report the correct information, but signal stops for some other events
such as system call enter/exit events might include stale siginfo from
an earlier signal.  In particular, if a thread reports a system call
entry or exit event after previously reporting a single-step or
breakpoint event via SIGTRAP, fbsd_handle_debug_trap believed the
system call event was the previous event and claimed it resulting in a
spurious SIGTRAP event.

True breakpoint and single-step events will never report another event
in the pl_flags member of struct ptrace_lwpinfo.  Use this to detect
stale siginfo by requiring pl_flags to have only the PL_FLAG_SI flag
and no other flags before treating a SIGTRAP as a single-step or
breakpoint trap.

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_handle_debug_trap): Require pl.pl_flags to
	equal PL_FLAG_SI.
	(fbsd_nat_target::stopped_by_sw_breakpoint): Likewise.
2018-12-21 10:18:11 -08:00
Paul Marechal d00a27c5ad gdb: Fix "info os <unknown>" command
Running `info os someUnknownOsType` is crashing when gdb is built with
-D_GLIBCXX_DEBUG:

	/usr/include/c++/5/debug/vector:439:error: attempt to
	access an element in an empty container.

In target_read_stralloc from target.c, the call to
target_read_alloc_1 can return an empty vector, we then call vector::back on
this vector, which is invalid.

This commit adds a check for emptiness before trying to call
vector::back on it. It also adds test to check for `info os <unknown>`
to return the proper error message.

This is a regression in gdb 8.2 and this patch restores the behavior of
previous versions.

gdb/ChangeLog:

	PR gdb/23974
	* target.c (target_read_stralloc): Check for empty vector.

gdb/testsuite/ChangeLog:

	PR gdb/23974
	* gdb.base/info-os.exp: Check return for unknown "info os" type.
2018-12-21 13:04:43 -05:00
Дилян Палаузов 50c7c5b8df when printing the GDB config, explicitly say if configured without python
When using the --configuration command line switch, or using
the "show configuration" command with a version of GDB which
was configured without Python supoprt, this patch changes
the resulting output to include...

    --without-python

... instead of not printing anything about Python support.

gdb/ChangeLog:

        * top.c (print_gdb_configuration): Print "--without-python"
        if GDB was configured without Python.

Tested on x86_64-linux by rebuilding GDB with and without Python,
and checking the output of "gdb --configuration" in both cases.
2018-12-21 21:59:09 +04:00
Andrew Burgess a96bd1ccc0 gdb/riscv: Format CORE_ADDR as a string for printing
Avoid compiler errors caused by trying to print CORE_ADDR using '%ld'
format, instead convert to a string and print that instead.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_scan_prologue): Use plongest to format
	a signed offset as a string.
2018-12-21 17:06:27 +00:00
Dave Murphy 3dcfdc5865 Fix compile error with clang 3.8
When compiling with clang 3.8 (default clang version on Debian
Stretch, the current stable), we get errors like this:

  CXX    dtrace-probe.o
../../binutils-gdb/gdb/dtrace-probe.c:103:31: error: default initialization of an object of const type 'const dtrace_static_probe_ops' without a user-provided default constructor
const dtrace_static_probe_ops dtrace_static_probe_ops;
                              ^

Silence them by value-initializing those objects.  It's not necessary
with other compilers (later clang versions, gcc), but it shouldn't
hurt either.
2018-12-21 11:45:16 -05:00
GDB Administrator e8f2b38a26 Automatic date update in version.in 2018-12-21 00:00:27 +00:00
H.J. Lu 76268e0274 x86: Call rtype_to_howto to get reloc_howto_type pointer
* elf32-i386.c (elf_i386_relocate_section): Call
	elf_i386_rtype_to_howto to get reloc_howto_type pointer.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Call
	elf_x86_64_rtype_to_howto to get reloc_howto_type pointer.
2018-12-20 13:25:41 -08:00