Commit Graph

96325 Commits

Author SHA1 Message Date
Joel Brobecker 5bbd631dca rotate gdb/ChangeLog 2019-01-01 09:59:27 +04:00
GDB Administrator bba9069622 Automatic date update in version.in 2019-01-01 00:00:27 +00:00
Philippe Waroquiers 2139e8dc9f Use gdb::unique_xmalloc_ptr<char> in command_line_input to fix a leak
Following the change of logic where the input_handler gets a
gdb::unique_xmalloc_ptr<char>, a call to readline directly
followed by a call to handle_line_of_input is missing a free,
and causes the below leak.

Use gdb::unique_xmalloc_ptr<char> to solve the leak.

==16291== VALGRIND_GDB_ERROR_BEGIN
==16291== 64 bytes in 1 blocks are definitely lost in loss record 1,815 of 4,111
==16291==    at 0x4C2E2B3: realloc (vg_replace_malloc.c:836)
==16291==    by 0x41EB1C: xrealloc (common-utils.c:62)
==16291==    by 0x41DBD3: buffer_grow(buffer*, char const*, unsigned long) [clone .part.1] (buffer.c:40)
==16291==    by 0x66E8FF: buffer_grow_char (buffer.h:40)
==16291==    by 0x66E8FF: gdb_readline_no_editing (top.c:798)
==16291==    by 0x66E8FF: command_line_input(char const*, char const*) (top.c:1249)
==16291==    by 0x66EBD8: read_command_file(_IO_FILE*) (top.c:421)
==16291==    by 0x412C0C: script_from_file(_IO_FILE*, char const*) (cli-script.c:1547)
==16291==    by 0x40BE90: source_script_from_stream (cli-cmds.c:569)
==16291==    by 0x40BE90: source_script_with_search(char const*, int, int) (cli-cmds.c:606)
==16291==    by 0x54D567: catch_command_errors(void (*)(char const*, int), char const*, int) (main.c:379)
==16291==    by 0x54EA84: captured_main_1 (main.c:994)
==16291==    by 0x54EA84: captured_main (main.c:1167)
==16291==    by 0x54EA84: gdb_main(captured_main_args*) (main.c:1193)
==16291==    by 0x29DA27: main (gdb.c:32)
==16291==
==16291== VALGRIND_GDB_ERROR_END

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

	* top.c (command_line_input): Use unique_xmalloc_ptr to
	manage memory allocated by readline.
2018-12-31 17:28:54 +01:00
Alan Modra 8fd04a4255 PR24042, Global-buffer-overflow problem in output_rel_find
place_orphan handled ELF SHT_REL/SHT_RELA specially, output_rel_find
didn't.  This mismatch was a bug and also meant it was possible to
craft an object where ld accessed section->name out of bounds.

	PR 24042
	* emultempl/elf32.em (output_rel_find): Drop "sec" param.  Add
	"rela".
	(gld${EMULATION_NAME}_place_orphan): Use sh_type to calculate
	"rela" param of output_rel_find when ELF.  Tidy uses of elfinput.
2018-12-31 17:56:32 +10:30
Alan Modra 54025d5812 PR24041, Invalid Memory Address Dereference in elf_link_add_object_symbols
PR 24041
	* elflink.c (elf_link_add_object_symbols): Don't segfault on
	crafted ET_DYN with no program headers.
2018-12-31 15:57:39 +10:30
Alan Modra c96e057398 [PowerPC64] Nop out ld 2,24(1) after old-style __tls_get_addr
When optimising inline plt calls to __tls_get_addr without tls marker
relocs, ld should zap any toc restore insn after the bctrl, to stop a
load-hit-store stall.

	* elf64-ppc.c (ppc64_elf_relocate_section <tls_ldgd_opt>): When
	editing an old-style __tls_get_addr call, replace a toc restore
	insn with a nop.
2018-12-31 12:12:38 +10:30
GDB Administrator 17c885c618 Automatic date update in version.in 2018-12-31 00:00:18 +00:00
Tom Tromey 95bc9f0bf0 Change input_handler to take a unique_xmalloc_ptr
This changes ui::input_handler to take a unique_xmalloc_ptr.  This
clarifies the ownership transfer of input_handler's argument.

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

	* event-top.h (command_line_handler): Update.
	* top.c (class gdb_readline_wrapper_cleanup) <m_handler_orig>:
	Update.
	(gdb_readline_wrapper_line): Update.
	* top.h (struct ui) <input_handler>: Take a unique_xmalloc_ptr.
	(handle_line_of_input): Update.
	* event-top.c: Update.
	(gdb_readline_no_editing_callback): Update.
	(command_line_handler): Take a unique_xmalloc_ptr.
	(handle_line_of_input): Take a const char *.
	(command_line_append_input_line): Take a const char *.
2018-12-30 08:54:13 -07:00
Philippe Waroquiers ecad3b215d Fix 'help set/show style' strange layouts/results.
The layout for 'help set address|variable' is strange, e.g.:
  (gdb) help set style address
  style address

  List of show Address display styling
  Configure address colors and display intensity subcommands:

  show Address display styling
  Configure address colors and display intensity background -- Set the background color for this property
  show Address display styling
  Configure address colors and display intensity foreground -- Set the foreground color for this property
  show Address display styling
  Configure address colors and display intensity intensity -- Set the display intensity color for this property

  Type "help show Address display styling
  Configure address colors and display intensity" followed by show Address display styling
  Configure address colors and display intensity subcommand name for full documentation.
  Type "apropos word" to search for commands related to "word".
  Command name abbreviations are allowed if unambiguous.
  (gdb)

The help for 'set style function|filename' gives help for 'Show':
  (gdb) help set style filename
  Filename display styling
  Configure filename colors and display intensity.

  List of show style filename subcommands:

  show style filename background -- Set the background color for this property
  show style filename foreground -- Set the foreground color for this property
  show style filename intensity -- Set the display intensity color for this property

The help for 'show style function|filename' is equally strange, as it speaks
about commands, instead of sub commands:
  (gdb) help show style filename
  Filename display styling
  Configure filename colors and display intensity.

  List of commands:

  background -- Show the background color for this property
  foreground -- Show the foreground color for this property
  intensity -- Show the display intensity color for this property

  Type "help" followed by command name for full documentation.
  Type "apropos word" to search for commands related to "word".
  Command name abbreviations are allowed if unambiguous.
  (gdb)

This patch fixes all this.

Note that the 'set style' and 'show style' have the same prefix_doc:
  (gdb) help show style
  Style-specific settings
  Configure various style-related variables, such as colors
  ...
  (gdb) help set style
  Style-specific settings
  Configure various style-related variables, such as colors
  ...

Other similar commands (such as set|show history) have typically
a more specific prefix:
  (gdb) help show history
  Generic command for showing command history parameters.
  ...
  (gdb) help set history
  Generic command for setting command history parameters.
  ...

This could be fixed by having set_prefix_doc and show_prefix_doc instead of
the single prefix_doc argument to cli_style_option::add_setshow_commands.
That could be improved if deemed better.

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

	* cli/cli-style.c (cli_style_option::add_setshow_commands):
	Initialize m_set_prefix with "set", instead of re-assigning
	m_show_prefix.  Use m_set_prefix for set_list and m_show_prefix
	for show_list.
	(_initialize_cli_style): Correct the order of arguments in
	variable_name_style.add_setshow_commands and
	address_style.add_setshow_commands calls.
2018-12-30 09:26:21 +01:00
GDB Administrator f1d3b1665f Automatic date update in version.in 2018-12-30 00:00:54 +00:00
Tom Tromey 64c45143db Fix the build when GNU Source Highlight is not available
The builder pointed out that, when GNU Source Highlight is not
available, get_language_name is not used.  This patch makes it
conditional, fixing the build problem.

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

	* source-cache.c (get_language_name): Conditionally compile.
2018-12-28 21:07:24 -07:00
GDB Administrator f9f981e5f6 Automatic date update in version.in 2018-12-29 00:00:35 +00:00
Tom Tromey 2cd8cc0b66 Fix a crash in jit.c
A user at Mozilla pointed out a crash in jit.c.  In his situation, an
inferior using the JIT API exec'd an executable that did not use it.
This caused an assertion failure when jit.c:free_objfile_data called
delete_breakpoint with NULL.

This patch fixes the problem in the obvious way.  New test case
included.

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

	* jit.c (free_objfile_data): Only delete breakpoint if non-null.

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

	* gdb.base/jit-exec.exp: New file.
	* gdb.base/jit-exec.c: New file.
	* gdb.base/jit-execd.c: New file.
2018-12-28 14:08:03 -07:00
Tom Tromey 140a4bc099 Document the "set style" commands
This documents the new "set style" commands.

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

	* NEWS: Mention terminal styling.

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

	* gdb.texinfo (Output Styling): New node.
2018-12-28 12:49:54 -07:00
Tom Tromey 62f29fda90 Highlight source code using GNU Source Highlight
This changes gdb to highlight source using GNU Source Highlight, if it
is available.

This affects the output of the "list" command and also the TUI source
window.

No new test because I didn't see a way to make it work when Source
Highlight is not found.

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

	* utils.h (can_emit_style_escape): Declare.
	* utils.c (can_emit_style_escape): No longer static.
	* cli/cli-style.c (set_style_enabled): New function.
	(_initialize_cli_style): Use it.
	* tui/tui-winsource.c (tui_show_source_line): Use tui_puts.
	(tui_alloc_source_buffer): Change how source lines are allocated.
	* tui/tui-source.c (copy_source_line): New function.
	(tui_set_source_content): Use source cache.
	* tui/tui-io.h (tui_puts): Update.
	* tui/tui-io.c (tui_puts_internal): Add window parameter.
	(tui_puts): Likewise.
	(tui_redisplay_readline): Update.
	* tui/tui-data.c (free_content_elements): Change how source window
	contents are freed.
	* source.c (forget_cached_source_info): Clear the source cache.
	(print_source_lines_base): Use the source cache.
	* source-cache.h: New file.
	* source-cache.c: New file.
	* configure.ac: Check for GNU Source Highlight library.
	* configure: Update.
	* config.in: Update.
	* Makefile.in (SRCHIGH_LIBS, SRCHIGH_CFLAGS): New variables.
	(INTERNAL_CFLAGS_BASE): Add SRCHIGH_CFLAGS.
	(CLIBS): Add SRCHIGH_LIBS.
	(COMMON_SFILES): Add source-cache.c.
	(HFILES_NO_SRCDIR): Add source-cache.h.
2018-12-28 12:49:54 -07:00
Tom Tromey 4a3045920b Use wclrtoeol in tui_show_source_line
This changes tui_show_source_line to use wclrtoeol rather than
manually emitting a sequence of spaces.

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

	* tui/tui-winsource.c (tui_show_source_line): Use wclrtoeol.
2018-12-28 12:49:53 -07:00
Tom Tromey 1d1d0bf76f Make ANSI terminal escape sequences work in TUI
PR tui/14126 notes that ANSI terminal escape sequences don't affect
the colors shown in the TUI.  A simple way to see this is to try the
extended-prompt example from the gdb manual.

Curses does not pass escape sequences through to the terminal.
Instead, it replaces non-printable characters with a visible
representation, for example "^[" for the ESC character.

This patch fixes the problem by adding a simple ANSI terminal sequence
parser to gdb.  These sequences are decoded and those that are
recognized are turned into the appropriate curses calls.

The curses approach to color handling is unusual and so there are some
oddities in the implementation.

Standard curses has no notion of the default colors of the terminal.
So, if you set the foreground color, it is not possible to reset it --
you have to pick some other color.  ncurses provides an extension to
handle this, so this patch updates configure and uses it when
available.

Second, in curses, colors always come in pairs: you cannot set just
the foreground.  This patch handles this by tracking actually-used
pairs of colors and keeping a table of these for reuse.

Third, there are a limited number of such pairs available.  In this
patch, if you try to use too many color combinations, gdb will just
ignore some color changes.

Finally, in addition to limiting the number of color pairs, curses
also limits the number of colors.  This means that, when using
extended 8- or 24-bit color sequences, it may be possible to exhaust
the curses color table.

I am very sour on the curses design now.

I do not know how to write a test for this, so I did not.

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

	PR tui/14126:
	* tui/tui.c (tui_enable): Call start_color and
	use_default_colors.
	* tui/tui-io.c (struct color_pair): New.
	(color_pair_map, last_color_pair, last_style): New globals.
	(tui_setup_io): Clean up color map when shutting down.
	(curses_colors): New constant.
	(get_color_pair, apply_ansi_escape): New functions.
	(tui_write): Rewrite.
	(tui_puts_internal): New function, from tui_puts.  Add "height"
	parameter.
	(tui_puts): Use tui_puts_internal.
	(tui_redisplay_readline): Use tui_puts_internal.
	(_initialize_tui_io): New function.
	(color_map): New globals.
	(get_color): New function.
	* configure.ac: Check for use_default_colors.
	* config.in, configure: Rebuild.
2018-12-28 12:49:53 -07:00
Tom Tromey 35fb8261b9 Style addresses
This changes gdb to style addresses.

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

	* ui-out.h (enum class ui_out_style_kind) <ADDRESS>: New
	constant.
	* ui-out.c (ui_out::field_core_addr): Add styling.
	* stack.c (print_frame): Add styling.
	* printcmd.c (print_address): Add styling.
	(print_address_demangle, info_address_command): Likewise.
	* cli/cli-style.h (address_style): Declare.
	* cli/cli-style.c (address_style): New global.
	(_initialize_cli_style): Register new commands.
	* cli-out.c (cli_ui_out::do_field_string): Update.

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

	* gdb.base/style.exp: Update test to check for address styling.
2018-12-28 12:49:52 -07:00
Tom Tromey 47fd17cdc1 Style the "Reading symbols" message
The "Reading symbols" message does not use ui-out (perhaps it
should?), so this styles it using the low-level API.

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

	* symfile.c (symbol_file_add_with_addrs): Style file name.

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

	* gdb.base/style.exp: Add test for styling of "Reading symbols"
	message.
2018-12-28 12:49:52 -07:00
Tom Tromey d47032b7ca Style the gdb welcome message
This changes gdb to style the welcome message that is shown by
default.  The styling is only done interactively.

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

	* top.c (print_gdb_version): Style gdb version number.

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

	* gdb.base/style.exp: Add test for version number styling.
2018-12-28 12:49:51 -07:00
Tom Tromey af79b68d7f Style print_address_symbolic
print_address_symbolic does not use ui-out, so it did not style
function names.  This patch changes it to use the low-level style code
directly.

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

	* printcmd.c (print_address_symbolic): Style function name.

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

	* gdb.base/style.exp: Add test for print_address_symbolic.
2018-12-28 12:49:51 -07:00
Tom Tromey 0bb296cb5f Style locations when setting a breakpoint
say_where does not use ui-out, so function and file names printed by
it were not styled.  This patch changes say_where to use the low-level
style code directly.

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

	* breakpoint.c (say_where): Style file name.

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

	* gdb.base/style.exp: Add test for breakpoint setting.
2018-12-28 12:49:50 -07:00
Tom Tromey 80ae204359 Style variable names
This adds style support for variable names.  For the time being, this
is only done in backtraces, not in ptype or print; those places do not
use ui-out and so would need ad hoc changes.

This also adds styling to the names printed for local variables in
"backtrace full".  This code does not use ui-out, so the styling is
done using the low-level API.

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

	* ui-out.h (enum class ui_out_style_kind) <VARIABLE>: New global.
	* stack.c (print_frame_arg): Style name.
	* printcmd.c (print_variable_and_value): Style variable name.
	* cli/cli-style.h (variable_name_style): Declare.
	* cli/cli-style.c (variable_name_style): New global.
	(_initialize_cli_style): Update.
	* cli-out.c (cli_ui_out::do_field_string): Update.

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

	* gdb.base/style.exp: Add test for variable names.
2018-12-28 12:49:50 -07:00
Tom Tromey ef1dfa3644 Reset terminal styles
This adds a function that can be used to reset terminal styles,
regardless of what style the low-level output routines currently think
is applied.

This is used to make "echo" and "printf" work properly when emitting
ANSI terminal escapes -- now gdb will reset the style at the end of
the command.

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

	* utils.h (reset_terminal_style): Declare.
	* utils.c (can_emit_style_escape): New function.
	(set_output_style): Use it.
	(reset_terminal_style): New function.
	* printcmd.c (printf_command): Call reset_terminal_style.
	* cli/cli-cmds.c (echo_command): Call reset_terminal_style.
2018-12-28 12:49:49 -07:00
Tom Tromey cbe5657196 Add output styles to gdb
This adds some output styling to the CLI.

A style is currently a foreground color, a background color, and an
intensity (dim or bold).  (This list could be expanded depending on
terminal capabilities.)

A style can be applied while printing.  For ui-out, this is done by
passing the style constant as an argument.  For low-level cases,
fprintf_styled and fputs_styled are provided.

Users can control the style via a number of new set/show commands.  In
the interest of not typing many nearly-identical documentation
strings, I automated this.  On the down side, this is not very
i18n-friendly.

I've chose some default colors to use.  I think it would be good to
enable this by default, so that when users start the new gdb, they
will see the new feature.

Stylizing is done if TERM is set and is not "dumb".  This could be
improved when the TUI is available by using the curses has_colors
call.  That is, the lowest layer could call this without committing to
using curses everywhere; see my other patch for TUI colorizing.

I considered adding a new "set_style" method to ui_file.  However,
because the implementation had to interact with the pager code, I
didn't take this approach.  But, one idea might be to put the isatty
check there and then have it defer to the lower layers.

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

	* utils.h (set_output_style, fprintf_styled)
	(fputs_styled): Declare.
	* utils.c (applied_style, desired_style): New globals.
	(emit_style_escape, set_output_style): New function.
	(prompt_for_continue): Emit style escapes.
	(fputs_maybe_filtered): Likewise.
	(fputs_styled, fprintf_styled): New functions.
	* ui-out.h (enum class ui_out_style_kind): New.
	(class ui_out) <field_string, field_stream, do_field_string>: Add
	style parameter.
	* ui-out.c (ui_out::field_stream, ui_out::field_string): Add style
	parameter.
	* tui/tui-out.h (class tui_ui_out) <do_field_string>: Add style
	parameter.
	* tui/tui-out.c (tui_ui_out::do_field_string): Add style
	parameter.
	(tui_ui_out::do_field_string): Update.
	* tracepoint.c (print_one_static_tracepoint_marker): Style
	output.
	* stack.c (print_frame_info, print_frame): Style output.
	* source.c (print_source_lines_base): Style output.
	* skip.c (info_skip_command): Style output.
	* record-btrace.c (btrace_call_history_src_line): Style output.
	(btrace_call_history): Likewise.
	* python/py-framefilter.c (py_print_frame): Style output.
	* mi/mi-out.h (class mi_ui_out) <do_field_string>: Add style
	parameter.
	* mi/mi-out.c (mi_ui_out::do_table_header)
	(mi_ui_out::do_field_int): Update.
	(mi_ui_out::do_field_string): Update.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Style output.
	* cli/cli-style.h: New file.
	* cli/cli-style.c: New file.
	* cli-out.h (class cli_ui_out) <do_field_string>: Add style
	parameter.
	* cli-out.c (cli_ui_out::do_table_header)
	(cli_ui_out::do_field_int, cli_ui_out::do_field_skip): Update.
	(cli_ui_out::do_field_string): Add style parameter.  Style the
	output.
	* breakpoint.c (print_breakpoint_location): Style output.
	(update_static_tracepoint): Likewise.
	* Makefile.in (SUBDIR_CLI_SRCS): Add cli-style.c.
	(HFILES_NO_SRCDIR): Add cli-style.h.

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

	* gdb.base/style.exp: New file.
	* gdb.base/style.c: New file.
2018-12-28 12:49:49 -07:00
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