Commit Graph

29208 Commits

Author SHA1 Message Date
Tom de Vries a88ef40d0f [gdb] Ensure listing of unused static var in info locals
Consider a test-case compiled with -g:
...
int main (void) {
  static int b = 2;
  return 0;
}
...

When running info locals in main, we get:
...
(gdb) info locals
No locals.
...

The info locals documentation states:
...
Print the local variables of the selected frame, each on a separate line.
These are all variables (declared either static or automatic) accessible at
the point of execution of the selected frame.
...
So, "info locals" should have printed static variable b.

The variable is present in dwarf info:
...
 <2><14a>: Abbrev Number: 6 (DW_TAG_variable)
    <14b>   DW_AT_name        : b
    <153>   DW_AT_const_value : 2
...
but instead of a location attribute, it has a const_value attribute, which
causes the corresponding symbol to have LOC_CONST, which causes info locals to
skip it.

Fix this by handling LOC_CONST in iterate_over_block_locals.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-24  Tom de Vries  <tdevries@suse.de>

	PR gdb/25592
	* stack.c (iterate_over_block_locals): Handle LOC_CONST.

gdb/testsuite/ChangeLog:

2020-02-24  Tom de Vries  <tdevries@suse.de>

	PR gdb/25592
	* gdb.base/info-locals-unused-static-var.c: New test.
	* gdb.base/info-locals-unused-static-var.exp: New file.
2020-02-24 15:32:36 +01:00
Tom de Vries c9af65210c [gdb/testsuite] Fix layout next/prev/regs help message
With test-case gdb.gdb/unittest.exp, I run into:
...
(gdb) maintenance selftest^M
   ...
Running selftest help_doc_invariants.^M
help doc broken invariant: command 'layout next' help doc first line is \
  not terminated with a '.' character^M
help doc broken invariant: command 'layout prev' help doc first line is \
  not terminated with a '.' character^M
help doc broken invariant: command 'layout regs' help doc first line is \
  not terminated with a '.' character^M
Self test failed: self-test failed at help-doc-selftests.c:95^M
...

Fix this by adding the missing '.' character.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-24  Tom de Vries  <tdevries@suse.de>

	* tui/tui-layout.c (_initialize_tui_layout): Fix help messages for
	commands layout next/prev/regs.
2020-02-24 12:30:48 +01:00
Tom Tromey 5707a07af2 Make dwarf2_compile_expr_to_ax static
I noticed that dwarf2_compile_expr_to_ax can be static.  Nothing
outside of loc.c calls it.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/loc.h (dwarf2_compile_expr_to_ax): Don't declare.
	* dwarf2/loc.c (dwarf2_compile_expr_to_ax): Now static.
2020-02-22 13:49:56 -07:00
Tom Tromey 3b0fb49e30 Fix cast in TUI_DISASM_WIN
I noticed that the TUI_DISASM_WIN macro cast the disassembly window to
a base type, rather than its correct type.  This patch fixes this
oversight.

2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (TUI_DISASM_WIN): Cast to tui_disasm_window.

Change-Id: Ied3dbac9ef3dc48ceb9e0850fe4ada3c316dd769
2020-02-22 12:57:25 -07:00
Tom Tromey 283be8bfa4 Add "usage" text to all TUI command help
This adds "usage" text to the help for all all the TUI commands.  In
some cases the usage is borderline, but I tend to think being complete
is preferable.

2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (_initialize_tui_win): Add usage text.
	* tui/tui-stack.c (_initialize_tui_stack): Add usage text.
	* tui/tui-regs.c (_initialize_tui_regs): Add usage text.
	* tui/tui.c (_initialize_tui): Add usage text.

Change-Id: I727f7a7cfc03efa248ef98f30a18be393819e30b
2020-02-22 12:57:25 -07:00
Tom Tromey ca793b969c Use error_no_arg in TUI
This changes a couple of TUI commands to use error_no_arg.  The
commands are also simplified a bit, and changed to use other gdb CLI
utility functions like skip_to_space.  This lets us removes a couple
of defines that don't interact properly with gettext.

2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_set_focus_command)
	(tui_set_win_height_command): Use error_no_arg.
	(_initialize_tui_win): Update help text.
	(FOCUS_USAGE, WIN_HEIGHT_USAGE): Don't define.

Change-Id: I2bf95c2e5cfe1472d068388fa39f0cf07591b76c
2020-02-22 12:57:25 -07:00
Tom Tromey 432b5c4022 Make some tui_source_window_base members "protected"
This renames a few members of tui_source_window_base, and makes them
"protected".

2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (extract_display_start_addr): Rewrite.
	* tui/tui-disasm.h (struct tui_disasm_window)
	<display_start_addr>: Declare.
	* tui/tui-source.h (struct tui_source_window)
	<display_start_addr>: Declare.
	* tui/tui-winsource.h (struct tui_source_window_base)
	<show_source_line, display_start_addr>: New methods.
	<m_horizontal_offset, m_start_line_or_addr, m_gdbarch, m_content>:
	Rename and move to protected section.
	* tui/tui-winsource.c (tui_source_window_base::update_source_window)
	(tui_source_window_base::do_erase_source_content): Update.
	(tui_source_window_base::show_source_line): Now a method.
	(tui_source_window_base::show_source_content)
	(tui_source_window_base::tui_source_window_base)
	(tui_source_window_base::rerender)
	(tui_source_window_base::refill)
	(tui_source_window_base::do_scroll_horizontal)
	(tui_source_window_base::set_is_exec_point_at)
	(tui_source_window_base::update_breakpoint_info)
	(tui_source_window_base::update_exec_info): Update.
	* tui/tui-source.c (tui_source_window::set_contents)
	(tui_source_window::showing_source_p)
	(tui_source_window::do_scroll_vertical)
	(tui_source_window::location_matches_p)
	(tui_source_window::line_is_displayed): Update.
	(tui_source_window::display_start_addr): New method.
	* tui/tui-disasm.c (tui_disasm_window::set_contents)
	(tui_disasm_window::do_scroll_vertical)
	(tui_disasm_window::location_matches_p): Update.
	(tui_disasm_window::display_start_addr): New method.

Change-Id: I74d72b9da5f458664427db643a108634690c6e19
2020-02-22 12:57:25 -07:00
Tom Tromey 01b1af321f Allow TUI windows in Python
This patch adds support for writing new TUI windows in Python.

2020-02-22  Tom Tromey  <tom@tromey.com>

	* NEWS: Add entry for gdb.register_window_type.
	* tui/tui-layout.h (window_factory): New typedef.
	(tui_register_window): Declare.
	* tui/tui-layout.c (saved_tui_windows): New global.
	(tui_apply_current_layout): Use it.
	(tui_register_window): New function.
	* python/python.c (do_start_initialization): Call
	gdbpy_initialize_tui.
	(python_GdbMethods): Add "register_window_type" function.
	* python/python-internal.h (gdbpy_register_tui_window)
	(gdbpy_initialize_tui): Declare.
	* python/py-tui.c: New file.
	* Makefile.in (SUBDIR_PYTHON_SRCS): Add py-tui.c.

gdb/doc/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* python.texi (Python API): Add menu item.
	(TUI Windows In Python): New node.

gdb/testsuite/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* gdb.python/tui-window.exp: New file.
	* gdb.python/tui-window.py: New file.

Change-Id: I85fbfb923a1840450a00a7dce113a05d7f048baa
2020-02-22 12:57:25 -07:00
Tom Tromey fc96d20b2c Remove the TUI annotation hack
do_tui_putc has some code to remove annotations from gdb output.  This
was added in 2001, see commit a198b876bb.

However, I think this code is not needed.  It seems very unlikely to
enable both annotations and the TUI, and in any case I think this is
something that should not be supported.

So, this patch removes this code.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-io.c (do_tui_putc): Don't omit annotations.

Change-Id: I05728110365a362d37c9821df9c8779316100bb8
2020-02-22 11:48:39 -07:00
Tom Tromey 935c78c046 Remove tui_set_win_with_focus
I noticed that the TUI had two functions with similar names:
tui_set_win_focus_to and tui_set_win_with_focus.

However, one was just an implementation detail of the latter.  So,
this patch removes tui_set_win_with_focus entirely, to avoid any
temptation to call it.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_set_win_focus_to): Move to tui-data.c.
	* tui/tui-data.h (tui_set_win_with_focus): Don't declare.
	* tui/tui-data.c (tui_set_win_with_focus): Remove.
	(tui_set_win_focus_to): Move from tui-win.c.

Change-Id: Idffddab773436bdf80d55480906d76b292981ef2
2020-02-22 11:48:38 -07:00
Tom Tromey 0240c8f11b Change how TUI windows are instantiated
This adds a new global that maps from window names to window
constructor functions, and then changes tui_get_window_by_name and
validate_window_name to use it.  This is another step toward
user-defined window types.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (make_standard_window, get_locator_window): New
	functions.
	(known_window_types): New global.
	(tui_get_window_by_name): Reimplement.
	(initialize_known_windows): New function.
	(validate_window_name): Rewrite.
	(_initialize_tui_layout): Call initialize_known_windows.

Change-Id: I9037aac550299b9d945899220a30c2d3af9dd0de
2020-02-22 11:48:38 -07:00
Tom Tromey fdb01f0ce4 TUI windows do not need to store their type
TUI windows no longer need to store their type -- there's only a
single spot that uses this information, and it can be changed to use
dynamic_cast.  (It could be cleaned up even more, by using a virtual
method, but I haven't done so.)  This patch removes the "type" field
from tui_gen_win_info, and this in turn allows removing a couple of
enumerator constants.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui.h (enum tui_win_type) <LOCATOR_WIN, DATA_ITEM_WIN>:
	Remove constants.
	* tui/tui-winsource.h (struct tui_source_window_base)
	<tui_source_window_base>: Remove parameter.
	* tui/tui-winsource.c
	(tui_source_window_base::tui_source_window_base): Remove
	parameter.
	(tui_source_window_base::refill): Update.
	* tui/tui-stack.h (struct tui_locator_window)
	<tui_locator_window>: Update.
	* tui/tui-source.h (struct tui_source_window) <tui_source_window>:
	Default the constructor.
	* tui/tui-regs.h (struct tui_data_item_window)
	<tui_data_item_window>: Default the constructor.
	(struct tui_data_window) <tui_data_window>: Likewise.
	* tui/tui-disasm.h (struct tui_disasm_window) <tui_disasm_window>:
	Default the constructor.
	* tui/tui-data.h (struct tui_gen_win_info) <tui_gen_win_info>:
	Default the constructor.
	<type>: Remove.
	(struct tui_win_info) <tui_win_info>: Default the constructor.
	* tui/tui-data.c (tui_win_info::tui_win_info): Remove.
	* tui/tui-command.h (struct tui_cmd_window) <tui_cmd_window>:
	Default the constructor.

Change-Id: I594cd07d2e0bba71ad594a6fb263904ce2febcd6
2020-02-22 11:48:37 -07:00
Tom Tromey 865a5aec04 Remove tui_delete_invisible_windows and tui_make_all_invisible
tui_delete_invisible_windows is only needed after applying a layout,
and tui_make_all_invisible is only needed before applying a layout.

This patch removes these functions, in favor of doing this management
directly in tui_apply_current_layout.  This is needed so that the
lifetimes of non-built-in windows will be properly managed.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.h (tui_make_all_invisible): Don't declare.
	* tui/tui-wingeneral.c (tui_make_all_invisible): Remove.
	* tui/tui-win.c (tui_resize_all): Don't call
	tui_delete_invisible_windows.
	* tui/tui-layout.c (tui_apply_current_layout): Delete windows when
	done.
	(tui_set_layout): Update.
	(tui_add_win_to_layout): Don't call tui_delete_invisible_windows.
	* tui/tui-data.h (tui_delete_invisible_windows): Don't declare.
	* tui/tui-data.c (tui_delete_invisible_windows): Remove.

Change-Id: Ia3603b021dcb7ec31700a4a32640cd09b00b8f3b
2020-02-22 11:48:37 -07:00
Tom Tromey e098d18cfc Handle ambiguity in tui_partial_win_by_name
This changes tui_partial_win_by_name to correctly handle an ambiguous
name prefix.  This will be important once the user can register new
window types.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_partial_win_by_name): Handle ambiguity
	correctly.

Change-Id: I59aaacd697eeab649164183457ef722dae58d60d
2020-02-22 11:48:36 -07:00
Tom Tromey eb9c887456 Reimplement tui_next_win and tui_prev_win
This reimplements tui_next_win and tui_prev_win.  Now they account for
the possibility of windows not on tui_win_list.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.c (tui_next_win, tui_prev_win): Reimplement.

Change-Id: Ifcd402f76fe0a16e0fe9275a185d550279c01660
2020-02-22 11:48:35 -07:00
Tom Tromey 7eed1a8e83 Change TUI window iteration
This changes the TUI to track all the instantiated windows in a new
global vector.  After this, iteration over TUI windows is done by
simply iterating over this vector.

This approach makes it simpler to define new window types.  In
particular, a subsequent patch will add the ability to define a TUI
window from Python.

Note that this series will not remove tui_win_list.  This will
continue to exist in parallel, only because it was simpler to leave
this alone.  Perhaps it could still be removed in the future.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_iterator)
	<inner_iterator>: New etytypedef.
	<tui_source_window_iterator>: Take "end" parameter.
	<tui_source_window_iterator>: Take iterator.
	<operator*, advance>: Update.
	<m_iter>: Change type.
	<m_end>: New field.
	(struct tui_source_windows) <begin, end>: Update.
	* tui/tui-layout.c (tui_windows): New global.
	(tui_apply_current_layout): Clear tui_windows.
	(tui_layout_window::apply): Update tui_windows.
	* tui/tui-data.h (tui_windows): Declare.
	(all_tui_windows): Now inline function.
	(class tui_window_iterator, struct all_tui_windows): Remove.

Change-Id: I6ab77976d6326f427178f725434f8f82046e0bbf
2020-02-22 11:48:34 -07:00
Tom Tromey 7c043ba695 Add horizontal splitting to TUI layout
This changes the TUI layout engine to add horizontal splitting.  Now,
windows can be side-by-side.

A horizontal split is defined using the "-horizontal" parameter to
"tui new-layout".

This also adds the first "winheight" test to the test suite.  One open
question is whether we want a new "winwidth" command, now that
horizontal layouts are possible.  This is easily done using the
generic layout code.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	PR tui/17850:
	* tui/tui-win.c (tui_gen_win_info::max_width): New method.
	* tui/tui-layout.h (class tui_layout_base) <get_sizes>: Add
	"height" argument.
	(class tui_layout_window) <get_sizes>: Likewise.
	(class tui_layout_split) <tui_layout_split>: Add "vertical"
	argument.
	<get_sizes>: Add "height" argument.
	<m_vertical>: New field.
	* tui/tui-layout.c (tui_layout_split::clone): Update.
	(tui_layout_split::get_sizes): Add "height" argument.
	(tui_layout_split::adjust_size, tui_layout_split::apply): Update.
	(tui_new_layout_command): Parse "-horizontal".
	(_initialize_tui_layout): Update help string.
	(tui_layout_split::specification): Add "-horizontal" when needed.
	* tui/tui-layout.c (tui_layout_window::get_sizes): Add "height"
	argument.
	* tui/tui-data.h (struct tui_gen_win_info) <max_width, min_width>:
	New methods.

gdb/doc/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	PR tui/17850:
	* gdb.texinfo (TUI Commands): Document horizontal layouts.

gdb/testsuite/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	PR tui/17850:
	* gdb.tui/new-layout.exp: Add horizontal layout and winheight
	tests.

Change-Id: I38b35e504f34698578af86686be03c0fefd954ae
2020-02-22 11:48:33 -07:00
Tom Tromey 6bc5664858 Change return type of tui_layout_base::adjust_size
This changes tui_layout_base::adjust_size to return a new enum type.
I broke this out into a separate patch because it simplifies a
subsequent patch.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.h (enum tui_adjust_result): New.
	(class tui_layout_base) <adjust_size>: Return tui_adjust_result.
	(class tui_layout_window) <adjust_size>: Return
	tui_adjust_result.  Rewrite.
	(class tui_layout_split) <adjust_size>: Return tui_adjust_result.
	* tui/tui-layout.c (tui_layout_split::adjust_size): Update.

Change-Id: I821b48ab06a9b9485875e147bd08a3bc46b900a0
2020-02-22 11:48:33 -07:00
Tom Tromey c22fef7e4c Allow TUI sub-layouts in "new-layout" command
The new TUI layout engine has support for "sub-layouts" -- this is a
layout that includes another layout as a child.  A sub-layout is
treated as a unit when allocating space.

There's not a very strong reason to use sub-layouts currently.  This
patch exists to introduce the idea, and to simplify the subsequent
patch that adds horizontal layouts -- where sub-layouts are needed.

Because this patch won't go in on its own, I chose to defer
documenting this change until the subsequent horizontal layout patch.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.h (class tui_layout_split) <add_split>: Change
	parameter and return types.
	(class tui_layout_base) <specification>: Add "depth".
	(class tui_layout_window) <specification>: Add "depth".
	(class tui_layout_split) <specification>: Add "depth".
	* tui/tui-layout.c (tui_layout_split::add_split): Change parameter
	and return types.
	(tui_new_layout_command): Parse sub-layouts.
	(_initialize_tui_layout): Update help string.
	(tui_layout_window::specification): Add "depth".
	(add_layout_command): Update.

gdb/testsuite/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* gdb.tui/new-layout.exp: Add sub-layout tests.

Change-Id: Iddf52d067a552c168b8a67f29caf7ac86404b10c
2020-02-22 11:48:32 -07:00
Tom Tromey ee325b61cd Add the "tui new-layout" command
This adds a new command, "tui new-layout".  This command can be used
to define a new TUI window layout.

The command is used like:

(gdb) tui new-layout name src 1 regs 1 status 0 cmd 1

The first argument is the name of the layout.  In this example, it is
"name", so the new layout could be seen by "layout name".

Subsequent arguments come in pairs, where the first item in a pair is
the name of a window, and the second item in a pair is the window's
weight.  A weight is just an integer -- a window's allocated size is
proportional to the total of the weights given.  So, in the above
example, all windows will have the same size (the status windows's
weight does not matter, because it has fixed height).

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* NEWS: Add "tui new-layout" item.
	* tui/tui-layout.c (add_layout_command): Return cmd_list_element.
	Add new-layout command to help text.
	(validate_window_name): New function.
	(tui_new_layout_command): New function.
	(_initialize_tui_layout): Register "new-layout".
	(tui_layout_window::specification): New method.
	(tui_layout_window::specification): New method.
	* tui/tui-layout.h (class tui_layout_base) <specification>: New
	method.
	(class tui_layout_window) <specification>: New method.
	(class tui_layout_split) <specification>: New method.

gdb/doc/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (TUI Overview): Mention user layouts.
	(TUI Commands): Document "tui new-layout".

gdb/testsuite/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* gdb.tui/new-layout.exp: New file.

Change-Id: Id7c3ace20ab1e8924f8f4ad788f40210f58a5c05
2020-02-22 11:48:31 -07:00
Tom Tromey 416eb92d84 Remove hard-coded TUI layouts
This changes the TUI so that the available layouts are no longer
completely hard-coded.  "enum tui_layout_type" is removed, and then
all the fallout from this is fixed up.

This patch also reimplements the "layout" command to be a prefix
command.  The concrete layouts are simply sub-commands now.  This
provides completion and correct abbreviation behavior for free.

Finally, this also changes the name of the locator window to "status".
This matches the documentation and will be exposed to the user in a
subsequent patch.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui.c (tui_enable): Call tui_set_initial_layout.
	* tui/tui-win.c (window_name_completer): Update comment.
	* tui/tui-layout.h (class tui_layout_base) <replace_window>:
	Declare method.
	(class tui_layout_window) <replace_window>: Likewise.
	(class tui_layout_split) <replace_window>: Likewise.
	(tui_set_layout): Don't declare.
	(tui_set_initial_layout): Declare function.
	* tui/tui-layout.c (layouts, applied_skeleton, src_regs_layout)
	(asm_regs_layout): New globals.
	(tui_current_layout, show_layout): Remove.
	(tui_set_layout, tui_add_win_to_layout): Rewrite.
	(find_layout, tui_apply_layout): New function.
	(layout_completer): Remove.
	(tui_next_layout): Reimplement.
	(tui_next_layout_command): New function.
	(tui_set_initial_layout, tui_prev_layout_command): New functions.
	(tui_regs_layout): Reimplement.
	(tui_regs_layout_command): New function.
	(extract_display_start_addr): Rewrite.
	(next_layout, prev_layout): Remove.
	(tui_layout_window::replace_window): New method.
	(tui_layout_split::replace_window): New method.
	(destroy_layout): New function.
	(layout_list): New global.
	(add_layout_command): New function.
	(initialize_layouts): Update.
	(tui_layout_command): New function.
	(_initialize_tui_layout): Install "layout" commands.
	* tui/tui-data.h (enum tui_layout_type): Remove.
	(tui_current_layout): Don't declare.

Change-Id: I9b5f7ab3ce838d6b340b8c373ef649a8e0a74b73
2020-02-22 11:48:30 -07:00
Tom Tromey 0dbc2fc759 Reimplement "tui reg" command
This reimplements the low-level layout function that is used by the
"tui reg" command.  Now it simply calls into the existing "layout"
command, though this will be changed again in a subsequent patch.  The
rationale for this patch is that it makes it simpler to remove
"enum tui_layout_type".

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_reg_layout): Remove.
	(tui_reg_command): Use tui_regs_layout.
	* tui/tui-layout.h (tui_reg_command): Declare.
	* tui/tui-layout.c (tui_reg_command): New function.

Change-Id: I0ca6884e2967005e7d3fbf5f13a0ac8f9c3298cf
2020-02-22 11:48:29 -07:00
Tom Tromey 5afe342e2a Reimplement TUI "C-x 1" binding
The TUI "C-x 1" key binding removes TUI windows, based on the current
layout.  With user-defined layouts, this is no longer easy to do.

This patch changes "C-x 1" to simply delete windows, leaving just the
focus window, the locator, and the command window.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui.c (tui_rl_delete_other_windows): Call
	tui_remove_some_windows.
	* tui/tui-layout.h (class tui_layout_base) <remove_windows>:
	Declare method.
	(class tui_layout_window) <remove_windows>: New method.
	(class tui_layout_split) <remove_windows>: Declare.
	(tui_remove_some_windows): Declare.
	* tui/tui-layout.c (tui_remove_some_windows): New function.
	(tui_layout_split::remove_windows): New method.

Change-Id: If186f9c3f263913e963b965204481d1b4385c6d4
2020-02-22 11:48:29 -07:00
Tom Tromey 427326a826 Simplify TUI C-x 2 binding
The TUI "C-x 2" binding tries to switch to a different layout based on
the current layout.  Once user-defined layouts are available, this
won't really make sense.  I wasn't entirely sure how to handle this.

This patch changes the binding to simply cycle through the existing
layouts.  I considered this a reasonable, though not ideal,
compromise.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui.c (tui_rl_change_windows): Call tui_next_layout.
	* tui/tui-layout.h (tui_next_layout): Declare.
	* tui/tui-layout.c (tui_next_layout): New function.

Change-Id: Ic101f0e3831a4235a048b3090ef60f025f7449bb
2020-02-22 11:48:28 -07:00
Tom Tromey 3fe12b6d67 Fix latent display bug in tui_data_window
tui_data_window creates new curses windows, but does not pass in
coordinates relative to the data window's origin.  This means that the
data window could only ever be displayed as the topmost window in a
layout.  This is not a currently problem, because all the existing
layouts do this; but a subsequent patch will add user-defined layouts,
which could do otherwise.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_data_window::display_registers_from): Use
	correct coordinates.

Change-Id: I5101f2b2869557b87381ebdeebd9b7fd28687831
2020-02-22 11:48:28 -07:00
Tom Tromey 59b8b5d247 Simplify tui_add_win_to_layout
tui_add_win_to_layout is only ever called for the source or assembly
windows.  This simplifies the function by removing the DATA_WIN case.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.h (tui_add_win_to_layout): Add comment.
	* tui/tui-layout.c (tui_add_win_to_layout): Add assert.  Remove
	DATA_WIN case.

Change-Id: Idfca902c6c90153acc5d19af4c33aa74bc3caf31
2020-02-22 11:48:27 -07:00
Tom Tromey 2a3d458be3 Use TUI_DISASM_WIN instead of tui_win_list array
This is a minor cleanup to change tui_get_low_disassembly_address to
use TUI_DISASM_WIN, rather than the tui_win_list array.  This is more
in line with what the rest of the TUI code does.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-disasm.c (tui_get_low_disassembly_address): Use
	TUI_DISASM_WIN, not tui_win_list.

Change-Id: I999335ee3f63a4b570e84f320236b78f2bd5b780
2020-02-22 11:48:27 -07:00
Tom Tromey 3f0cbb04d0 Style field names in "print"
This changes gdb to use the "variable" style when printing field
names.  I've added new tests for C and Rust, but not other languages.

I chose "variable" because that seemed most straightforward.  However,
another option would be to introduce a new "field" style.  Similarly,
this patch uses the variable style for enumerator constants -- but
again, a new style could be used if that's preferred.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* valprint.c (generic_val_print_enum_1)
	(val_print_type_code_flags): Style member names.
	* rust-lang.c (val_print_struct, rust_print_enum)
	(rust_print_struct_def, rust_internal_print_type): Style member
	names.
	* p-valprint.c (pascal_object_print_value_fields): Style member
	names.  Only call fprintf_symbol_filtered for static members.
	* m2-typeprint.c (m2_record_fields, m2_enum): Style member names.
	* f-valprint.c (f_val_print): Style member names.
	* f-typeprint.c (f_type_print_base): Style member names.
	* cp-valprint.c (cp_print_value_fields): Style member names.  Only
	call fprintf_symbol_filtered for static members.
	(cp_print_class_member): Style member names.
	* c-typeprint.c (c_print_type_1, c_type_print_base_1): Style
	member names.
	* ada-valprint.c (ada_print_scalar): Style enum names.
	(ada_val_print_enum): Likewise.
	* ada-typeprint.c (print_enum_type): Style enum names.

gdb/testsuite/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

	* gdb.rust/rust-style.rs: New file.
	* gdb.rust/rust-style.exp: New file.
	* gdb.base/style.exp: Test structure printing.
	* gdb.base/style.c (struct some_struct): New type.
	(enum etype): New type.
	(struct_value): New global.

Change-Id: I070e1293c6cc830c9ea916af8243410aa384e944
2020-02-22 10:12:52 -07:00
Tom Tromey d4d947ae37 Update partial_symtab comment
The introductory comment for partial_symtab has been mildly incorrect
since the partial symtab code was changed to allocate partial symtabs
with "new".  This patch removes the incorrect text.

gdb/ChangeLog
2020-02-21  Tom Tromey  <tom@tromey.com>

	* psympriv.h (struct partial_symtab): Update comment.
2020-02-21 14:44:41 -07:00
Tom Tromey e94e944bf2 Fix two more mips-tdep.h declarations
My earlier patch to fix a declaration mismatch in mips-tdep.h missed a
couple of spots.  Basically, I sent it too soon.

This patch fixes a couple more mismatches between a declaration (using
bfd_vma) and the definition (using CORE_ADDR).

gdb/ChangeLog
2020-02-21  Tom Tromey  <tromey@adacore.com>

	* mips-tdep.h (mips_pc_is_mips16, mips_pc_is_micromips): Parameter
	type is CORE_ADDR.
2020-02-21 08:45:14 -07:00
Tom de Vries 1eb7317953 [gdb] Fix cc-with-dwz regression
I noticed a regression with board cc-with-dwz:
...
FAIL: gdb.cp/m-static.exp: static const int initialized elsewhere
FAIL: gdb.cp/m-static.exp: info variable everywhere
...

The problem started with commit 0494dbecdf "Consolidate partial symtab
dependency reading".

The commit replaces the dwarf2_psymtab::expand_psymtab specific reading of
dependencies, which contains a "dependencies[i]->user == NULL" test, with a
generic partial_symtab::read_dependencies call, which does not test the user
field.

This patch fixes the regression by adding back the test, in the generic
partial_symtab::read_dependencies.

Build and reg-tested on x86_64-linux.

Tested natively, as well as with boards cc-with-dwz and cc-with-dwz-m.

The patch fixes all 33 regressions with cc-with-dwz, and all 2929 regression
with cc-with-dwz-m.

gdb/ChangeLog:

2020-02-21  Tom de Vries  <tdevries@suse.de>

	PR gdb/25534
	* psymtab.c (partial_symtab::read_dependencies): Don't read dependency
	if dependencies[i]->user != NULL.
2020-02-21 16:36:48 +01:00
Ali Tamur via gdb-patches 4f180d5396 Check for null result from gdb_demangle
I am sending this patch on behalf of kmoy@google.com, who discovered the bug
and wrote the fix.

gdb_demangle can return null for strings that don't properly demangle. The null
check was mistakenly removed in commit 43816ebc33. Without this check, GDB
aborts when loading symbols from some binaries.

gdb/ChangeLog
2020-02-21  Ali Tamur  <tamur@google.com>

	* dwarf2/read.c (dwarf2_name): Add null check.
2020-02-21 08:19:21 -07:00
Tom Tromey 22b6cd7043 Fix latent bug in dwarf2_find_containing_comp_unit
dwarf2_find_containing_comp_unit has this in its binary search:

      if (mid_cu->is_dwz > offset_in_dwz
	  || (mid_cu->is_dwz == offset_in_dwz
	      && mid_cu->sect_off + mid_cu->length >= sect_off))
	high = mid;

The intent here is to determine whether SECT_OFF appears in or before
MID_CU.

I believe this has an off-by-one error, and that the check should use
">" rather than ">=".  If the two side are equal, then SECT_OFF
actually appears at the start of the next CU.

I've had this patch kicking around for ages but I forget how I found
the problem.

gdb/ChangeLog
2020-02-20  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_find_containing_comp_unit): Use ">", not
	">=", in binary search.
	(dwarf2_find_containing_comp_unit): New overload.
	(run_test): New self-test.
	(_initialize_dwarf2_read): Register new test.
2020-02-20 18:22:09 -07:00
Nelson Chu bd0cf5a6ba RISC-V: Support the ISA-dependent CSR checking.
According to the riscv privilege spec, some CSR are only valid when rv32 or
the specific extension is set.  We extend the DECLARE_CSR and DECLARE_CSR_ALIAS
to record more informaton we need, and then check whether the CSR is valid
according to these information.  We report warning message when the CSR is
invalid, so we have a choice between error and warning by --fatal-warnings
option.  Also, a --no-warn/-W option is used to turn the warnings off, if
people don't want the warnings.

	gas/
	* config/tc-riscv.c (enum riscv_csr_class): New enum.  Used to decide
	whether or not this CSR is legal in the current ISA string.
	(struct riscv_csr_extra): New structure to hold all extra information
	of CSR.
	(riscv_init_csr_hash): New function.  According to the DECLARE_CSR and
	DECLARE_CSR_ALIAS, insert CSR extra information into csr_extra_hash.
	Call hash_reg_name to insert CSR address into reg_names_hash.
	(md_begin): Call riscv_init_csr_hashes for each DECLARE_CSR.
	(reg_csr_lookup_internal, riscv_csr_class_check): New functions.
	Decide whether the CSR is valid according to the csr_extra_hash.
	(init_opcode_hash): Update 'if (hash_error != NULL)' as hash_error is
	not a boolean.  This is same as riscv_init_csr_hash, so keep the
	consistent usage.

	* testsuite/gas/riscv/csr-dw-regnums.d: Add -march=rv32if option.
	* testsuite/gas/riscv/priv-reg.d: Add f-ext by -march option.
	* testsuite/gas/riscv/priv-reg-fail-fext.d: New testcase.  The source
	file is `priv-reg.s`, and the ISA is rv32i without f-ext, so the
	f-ext CSR are not allowed.
	* testsuite/gas/riscv/priv-reg-fail-fext.l: Likewise.
	* testsuite/gas/riscv/priv-reg-fail-rv32-only.d: New testcase.  The
	source file is `priv-reg.s`, and the ISA is rv64if, so the
	rv32-only CSR are not allowed.
	* testsuite/gas/riscv/priv-reg-fail-rv32-only.l: Likewise.

	include/
	* opcode/riscv-opc.h: Extend DECLARE_CSR and DECLARE_CSR_ALIAS to
	record riscv_csr_class.

	opcodes/
	* riscv-dis.c (print_insn_args): Updated since the DECLARE_CSR is changed.

	gdb/
	* riscv-tdep.c: Updated since the DECLARE_CSR is changed.
	* riscv-tdep.h: Likewise.
	* features/riscv/rebuild-csr-xml.sh: Generate the 64bit-csr.xml without
	rv32-only CSR.
	* features/riscv/64bit-csr.xml: Regernated.

	binutils/
	* dwarf.c: Updated since the DECLARE_CSR is changed.
2020-02-20 16:49:09 -08:00
Sergio Durigan Junior 3f702acd7d Make '{putchar,fputc}_unfiltered' use 'fputs_unfiltered'
There is currently a regression when using
'{putchar,fputc}_unfiltered' with 'puts_unfiltered' which was
introduced by one of the commits that reworked the unfiltered print
code.

The regression makes it impossible to use '{putchar,fputc}_unfiltered'
with 'puts_unfiltered', because the former writes directly to the
ui_file stream using 'stream->write', while the latter uses a buffered
mechanism (see 'wrap_buffer') and delays the printing.

If you do a quick & dirty hack on e.g. top.c:show_gdb_datadir:

  @@ -2088,6 +2088,13 @@ static void
   show_gdb_datadir (struct ui_file *file, int from_tty,
		    struct cmd_list_element *c, const char *value)
   {
  +  putchar_unfiltered ('\n');
  +  puts_unfiltered ("TEST");
  +  putchar_unfiltered ('>');
  +  puts_unfiltered ("PUTS");
  +  putchar_unfiltered ('\n');

rebuild GDB and invoke the "show data-directory" command, you will
see:

  (gdb) show data-directory

  >
  TESTPUTSGDB's data directory is "/usr/local/share/gdb".

Note how the '>' was printed before the output, and "TEST" and "PUTS"
were printed together.

My first attempt to fix this was to always call 'flush_wrap_buffer' at
the end of 'fputs_maybe_filtered', since it seemed to me that the
function should always print what was requested.  But I wasn't sure
this was the right thing to do, so I talked to Tom on IRC and he gave
me another, simpler idea: make '{putchar,fputc}_unfiltered' call into
the already existing 'fputs_unfiltered' function.

This patch implements the idea.  I regtested it on the Buildbot, and
no regressions were detected.

gdb/ChangeLog:
2020-02-20  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Tom Tromey  <tom@tromey.com>

	* utils.c (fputs_maybe_filtered): Call 'stream->puts' instead
	of 'fputc_unfiltered'.
	(putchar_unfiltered): Call 'fputc_unfiltered'.
	(fputc_unfiltered): Call 'fputs_unfiltered'.
2020-02-20 16:02:37 -05:00
Andrew Burgess d13c7322fe gdb: Allow more control over where to find python libraries
The motivation behind this commit is to make it easier to bundle the
Python *.py library files with GDB when statically linking GDB against
libpython.  The Python files will be manually added into the GDB
installation tree, and GDB should be able to find them at run-time.
The installation tree will look like this:

  .
  |-- bin/
  |-- include/
  |-- lib/
  |   `-- python3.8/
  `-- share/

The benefit here is that the entire installation tree can be bundled
into a single archive and copied to another machine with a different
version of Python installed, and GDB will still work, including its
Python support.

In use the new configure options would be used something like this,
first build and install a static Python library:

  mkdir python
  cd python
  # Clone or download Python into a src/ directory.
  mkdir build
  export PYTHON_INSTALL_PATH=$PWD/install
  cd build
  ../src/configure --disable-shared --prefix=$PYTHON_INSTALL_PATH
  make
  make install

Now build and install GDB:

  mkdir binutils-gdb
  cd binutils-gdb
  # Clone or download GDB into a src/ directory.
  mkdir build
  export GDB_INSTALL_DIR=$PWD/install
  cd build
  ../src/configure \
      --prefix=$GDB_INSTALL_DIR \
      --with-python=$PYTHON_INSTALL_PATH/bin/python3 \
      --with-python-libdir=$GDB_INSTALL_DIR/lib
  make all-gdb
  make install-gdb

Finally, copy the Python libraries into the GDB install:

  cp -r $PYTHON_INSTALL_DIR/lib/python3.8/ $GDB_INSTALL_DIR/lib

After this the Python src, build, and install directories are no
longer needed and can be deleted.

If the new --with-python-libdir option is not used then the existing
behaviour is left unchanged, GDB will look for the Python libraries in
the lib/ directory within the python path.  The concatenation of the
python prefix and the string 'lib/' is now done at configure time,
rather than at run time in GDB as it was previous, however, this was
never something that the user had dynamic control over, so there's no
loss of functionality.

gdb/ChangeLog:

	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Add --with-python-libdir option.
	* main.c: Use WITH_PYTHON_LIBDIR.
2020-02-20 10:14:43 +00:00
Tom Tromey 869d89506c Two compute_and_set_names simplifications
This patch simplifies compute_and_set_names in a couple of ways.

First, it changes one spot to use obstack_strndup, which is
equivalent, but more concise.

Second, the function ends with two calls to symbol_set_demangled_name.
This can be simplified to a single call.

gdb/ChangeLog
2020-02-19  Tom Tromey  <tom@tromey.com>

	* symtab.c (general_symbol_info::compute_and_set_names): Use
	obstack_strndup.  Simplify call to symbol_set_demangled_name.
2020-02-19 17:22:13 -07:00
Simon Marchi 298e963730 gdb: dwarf2/read.c: remove unused objfile parameters/variables
This is a simple cleanup.  These functions used to use the objfile's
obstack for allocation in the hash tables, but they don't anymore.
Remove the unnecessary objfile parameters, which in turn allows removing
some local variables.

gdb/ChangeLog:

	* dwarf2/read.c (allocate_signatured_type_table,
	allocate_dwo_unit_table, allocate_type_unit_groups_table,
	allocate_dwo_file_hash_table, allocate_dwp_loaded_cutus_table):
	Remove objfile parameter, update all callers.
2020-02-19 16:04:53 -05:00
Doug Evans 084104828c rust/25535 Apply embedded offset to enum variant calculation
Hopefully straightforward (and I didn't miss anything ...).

gdb/ChangeLog
2020-02-19  Doug Evans  <dje@google.com>

	PR rust/25535
	* rust-lang.c (rust_print_enum): Apply embedded_offset to
	rust_enum_variant calculation.

gdb/testsuite/ChangeLog
2020-02-19  Doug Evans  <dje@google.com>

	PR rust/25535
	* gdb.rust/simple.exp: Add test.
	* gdb.rust/simple.rs: Add test.
2020-02-19 13:59:31 -07:00
Tom Tromey dfdeeca1cc Fix declaration of mips_pc_is_mips
A build where CORE_ADDR is not the same as bfd_vma pointed out that
mips_pc_is_mips is declared using bfd_vma as the parameter type, but
defined using CORE_ADDR.  This patch fixes the declaration.

gdb/ChangeLog
2020-02-19  Tom Tromey  <tromey@adacore.com>

	* mips-tdep.h (mips_pc_is_mips): Parameter type is CORE_ADDR.
2020-02-19 12:18:09 -07:00
Tom Tromey 2ef5453be5 Use obstack_strdup in ada-lang.c
I happened across a spot that was still using obstack_alloc and
strcpy, rather than obstack_strdup.  This patch makes the obvious fix.

gdb/ChangeLog
2020-02-19  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (cache_symbol): Use obstack_strdup.
2020-02-19 11:17:35 -07:00
Andrew Burgess 9f1528a1bd Merge changes from GCC for the config/ directory
GCC's config/ChangeLog since the last time this merge was done
(in the binutils-gdb commit 0b4d000cc4) is included at the
end of this commit message.

It is worth noting that the binutils-gdb commit 301a9420d9
added the file config/debuginfod.m4 which is not present in GCC's
config/ directory.  This file is preserved, unmodified, after this
commit.

In order to regenerate all of the configure files, I configured with
--enable-maintainer-mode, and built the 'all' target.  I then did the
same thing on a source tree without this patch, and only committed
those files that changed when this patch was added.

GCC's config/ChangeLog entries:

  2020-02-12  Sandra Loosemore  <sandra@codesourcery.com>

  	PR libstdc++/79193
  	PR libstdc++/88999

  	* no-executables.m4: Use a non-empty program to test for linker
  	support.

  2020-02-01  Andrew Burgess  <andrew.burgess@embecosm.com>

  	* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Update shell syntax.

  2020-01-27  Andrew Burgess  <andrew.burgess@embecosm.com>

  	* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new
  	--with-libXXX-type=... option.  Use this to guide the selection of
  	either a shared library or a static library.

  2020-01-24  Maciej W. Rozycki  <macro@wdc.com>

  	* toolexeclibdir.m4: New file.

  2019-09-10  Christophe Lyon  <christophe.lyon@st.com>

  	* futex.m4: Handle *-uclinux*.
  	* tls.m4 (GCC_CHECK_TLS): Likewise.

  2019-09-06  Florian Weimer  <fweimer@redhat.com>

  	* futex.m4 (GCC_LINUX_FUTEX): Include <unistd.h> for the syscall
  	function.

  2019-07-08  Richard Sandiford  <richard.sandiford@arm.com>

  	* bootstrap-Og.mk: New file.

  2019-06-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
              Andrew Stubbs  <ams@codesourcery.com>

  	* gthr.m4 (GCC_AC_THREAD_HEADER): Add case for gcn.

  2019-05-30  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

  	* ax_count_cpus.m4: New file.

  2019-05-02  Richard Biener  <rguenther@suse.de>

  	PR bootstrap/85574
  	* bootstrap-lto.mk (extra-compare): Set to gcc/lto1$(exeext).

  2019-04-16  Martin Liska  <mliska@suse.cz>

  	* bootstrap-lto-lean.mk: Filter out -flto in STAGEtrain_CFLAGS.

  2019-04-09  Martin Liska  <mliska@suse.cz>

  	* bootstrap-lto-lean.mk: New file.

  2019-03-02  Johannes Pfau  <johannespfau@gmail.com>

  	* mh-mingw: Also set __USE_MINGW_ACCESS flag for C++ code.

  2018-10-31  Joseph Myers  <joseph@codesourcery.com>

  	PR bootstrap/82856
  	* math.m4, tls.m4: Use AC_LANG_SOURCE.

  	Merge from binutils-gdb:
  	2018-06-19  Simon Marchi  <simon.marchi@ericsson.com>

  	* override.m4 (_GCC_AUTOCONF_VERSION): Bump from 2.64 to 2.69.

config/ChangeLog:

	* ax_count_cpus.m4: New file, backported from GCC.
	* bootstrap-Og.mk: New file, backported from GCC.
	* bootstrap-lto-lean.mk: New file, backported from GCC.
	* bootstrap-lto.mk: Changes backported from GCC.
	* futex.m4: Changes backported from GCC.
	* gthr.m4: Changes backported from GCC.
	* lib-link.m4: Changes backported from GCC.
	* mh-mingw: Changes backported from GCC.
	* no-executables.m4: Changes backported from GCC.
	* tls.m4: Changes backported from GCC.
	* toolexeclibdir.m4: New file, backported from GCC.

binutils/ChangeLog:

	* configure: Regenerate.

gdb/ChangeLog:

	* configure: Regenerate.

gdbserver/ChangeLog:

	* configure: Regenerate.

gdbsupport/ChangeLog:

	* configure: Regenerate.

intl/ChangeLog:

	* configure: Regenerate.

libiberty/ChangeLog:

	* configure: Regenerate.

zlib/ChangeLog.bin-gdb:

	* configure: Regenerate.
2020-02-19 17:51:24 +00:00
Tom Tromey d3c22fa82e Remove useless NULL check in python.c
I noticed that do_start_initialization, in python.c, checks the result
of xmalloc.  However, xmalloc cannot fail, so this check is useless.
This patch also changes the code to use XNEWVEC.

gdb/ChangeLog
2020-02-19  Tom Tromey  <tromey@adacore.com>

	* python/python.c (do_start_initialization): Use XNEWVEC.  Remove
	NULL check.
2020-02-19 07:50:21 -07:00
Maciej W. Rozycki bf84f70666 gdbserver: Add RISC-V/Linux support
Implement RISC-V/Linux support for both RV64 and RV32 systems, including
XML target description handling based on features determined, GPR and
FPR regset support including dynamic sizing of the latter, and software
breakpoint handling.  Define two NT_FPREGSET regsets of a different size
matching the FPR sizes supported for generic `gdbserver' code to pick
from according to what the OS supplies.

Also handle a glibc bug where ELF_NFPREG is defined in terms of NFPREG,
however NFPREG is nowhere defined.

2020-02-19  Maciej W. Rozycki  <macro@wdc.com>
	    Andrew Burgess  <andrew.burgess@embecosm.com>

	gdb/
	* NEWS: Mention RISC-V GNU/Linux GDBserver support.

	gdbserver/
	* linux-riscv-low.cc: New file.
	* Makefile.in (SFILES): Add linux-riscv-low.cc, arch/riscv.c,
	and nat/riscv-linux-tdesc.c.
	* configure.srv <riscv*-*-linux*> (srv_tgtobj)
	(srv_linux_regsets, srv_linux_usrregs, srv_linux_thread_db):
	Define.
2020-02-19 01:24:37 +00:00
Andrew Burgess d1c9b20ff9 gdb/riscv: Update API for looking up target descriptions
In preparation for adding the RISC-V gdbserver, this commit
restructures the API for looking up target descriptions.

The current API is riscv_create_target_description, which creates a
target description from a riscv_gdbarch_features, but also caches the
created target descriptions so that for a given features object we
always get back the same target description object.  This is important
for GDB due to the way gdbarch objects are reused.

As the same target description is always returned to GDB, and can be
returned multiple times, it is returned as a const, however, the
current cache actually stores a non-const target description.  This is
improved in this patch so that the cache holds a const target
description.

For gdbsever, this caching of the target descriptions is not needed,
the gdbserver looks up one target description to describe the target
it is actually running on and that is it.  Further the gdbserver
actually needs to modify the target description that is looked up, so
for the gdbsever, returning a const target description is not
acceptable.

This commit aims to address this by creating two parallel target
description APIs, on is the old riscv_create_target_description,
however, this no longer performs any caching, and just creates a new
target description, and returns it as non-const.

The second API is riscv_lookup_target_description, this one performs
the caching, and calls riscv_create_target_description to create a
target description when needed.

In order to make sure the correct API is used in the correct place I
have guarded the code using the GDBSERVER define.  For GDB the
riscv_create_target_description is static, and not generally usable
throughout GDB, only the lookup API is global.  In gdbserver, the
lookup functions, and the cache are not defined or created at all,
only the riscv_create_target_description API is available.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* arch/riscv.c (struct riscv_gdbarch_features_hasher): Only define
	if GDBSERVER is not defined.
	(riscv_tdesc_cache): Likewise, also store const target_desc.
	(STATIC_IN_GDB): Define.
	(riscv_create_target_description): Update declaration with
	STATIC_IN_GDB.
	(riscv_lookup_target_description): New function, only define if
	GDBSERVER is not defined.
	* arch/riscv.h (riscv_create_target_description): Declare only
	when GDBSERVER is defined.
	(riscv_lookup_target_description): New declaration when GDBSERVER
	is not defined.
	* nat/riscv-linux-tdesc.c (riscv_linux_read_description): Rename to...
	(riscv_linux_read_features): ...this, and return
	riscv_gdbarch_features instead of target_desc.
	* nat/riscv-linux-tdesc.h: Include 'arch/riscv.h'.
	(riscv_linux_read_description): Rename to...
	(riscv_linux_read_features): ...this.
	* riscv-linux-nat.c (riscv_linux_nat_target::read_description):
	Update to use riscv_gdbarch_features and
	riscv_lookup_target_description.
	* riscv-tdep.c (riscv_find_default_target_description): Use
	riscv_lookup_target_description instead of
	riscv_create_target_description.
2020-02-19 01:24:37 +00:00
Simon Marchi 373d7ac0f1 gdb: change print format of flag enums with value 0
If a flag enum has value 0 and the enumeration type does not have an
enumerator with value 0, we currently print:

  $1 = (unknown: 0x0)

I don't like the display of "unknown" here, since for flags, 0 is a
an expected value.  It just means that no flags are set.  This patch
makes it so that we print it as a simple 0 in this situation:

  $1 = 0

If there is an enumerator with value 0, it is still printed using that
enumerator, for example (from the test):

  $1 = FE_NONE

gdb/ChangeLog:

	* valprint.c (generic_val_print_enum_1): When printing a flag
	enum with value 0 and there is no enumerator with value 0, print
	just "0" instead of "(unknown: 0x0)".

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.exp (test_print_enums): Update expected
	output.
2020-02-18 17:33:04 -05:00
Simon Marchi b29a2df000 gdb: print unknown part of flag enum in hex
When we print the "unknown" part of a flag enum, it is printed in
decimal.  I think it would be more useful if it was printed in hex, as
it helps to determine which bits are set more than a decimal value.

gdb/ChangeLog:

	* valprint.c (generic_val_print_enum_1): Print unknown part of
	flag enum in hex.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.exp (test_print_enums): Expect hex values
	for "unknown".
2020-02-18 17:33:04 -05:00
Simon Marchi 6740f0cc3b gdb: allow duplicate enumerators in flag enums
I have come across some uses cases where it would be desirable to treat
an enum that has duplicate values as a "flag enum".  For example, this
one here [1]:

    enum membarrier_cmd {
            MEMBARRIER_CMD_QUERY                                = 0,
            MEMBARRIER_CMD_GLOBAL                               = (1 << 0),
            MEMBARRIER_CMD_GLOBAL_EXPEDITED                     = (1 << 1),
            MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED            = (1 << 2),
            MEMBARRIER_CMD_PRIVATE_EXPEDITED                    = (1 << 3),
            MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED           = (1 << 4),
            MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE          = (1 << 5),
            MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 6),

            /* Alias for header backward compatibility. */
            MEMBARRIER_CMD_SHARED = MEMBARRIER_CMD_GLOBAL,
    };

The last enumerator is kept for backwards compatibility.  Without this
patch, this enumeration wouldn't be considered a flag enum, because two
enumerators collide.   With this patch, it would be considered a flag
enum, and the value 3 would be printed as:

  MEMBARRIER_CMD_GLOBAL | MEMBARRIER_CMD_GLOBAL_EXPEDITED

Although if people prefer, we could display both MEMBARRIER_CMD_GLOBAL
and MEMBARRIER_CMD_SHARED in the result.  It wouldn't be wrong, and
could perhaps be useful in case a bit may have multiple meanings
(depending on some other bit value).

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/membarrier.h?id=0bf999f9c5e74c7ecf9dafb527146601e5c848b9#n125

gdb/ChangeLog:

	* dwarf2/read.c (update_enumeration_type_from_children): Allow
	flag enums to contain duplicate enumerators.
	* valprint.c (generic_val_print_enum_1): Update comment.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.c (enum flag_enum): Add FE_TWO_LEGACY
	enumerator.
2020-02-18 17:32:57 -05:00
Simon Marchi edd45eb06b gdb: fix printing of flag enums with multi-bit enumerators
GDB has this feature where if an enum looks like it is meant to
represent binary flags, it will present the values of that type as a
bitwise OR of the flags that are set in the value.

The original motivation for this patch is to fix this behavior:

  enum hello { AAA = 0x1, BBB = 0xf0 };

  (gdb) p (enum hello) 0x11
  $1 = (AAA | BBB)

This is wrong because the bits set in BBB (0xf0) are not all set in the
value 0x11, but GDB presents it as if they all were.

I think that enumerations with enumerators that have more than one bit
set should simply not qualify as "flag enum", as far as this
heuristic is concerned.  I'm not sure what it means to have flags of
more than one bit.  So this is what this patch implements.

I have added an assert in generic_val_print_enum_1 to make sure the flag
enum types respect that, in case they are used by other debug info
readers, in the future.

I've enhanced the gdb.base/printcmds.exp test to cover this case.  I've
also added tests for printing flag enums with value 0, both when the
enumeration has and doesn't have an enumerator for value 0.

gdb/ChangeLog:

	* dwarf2/read.c: Include "count-one-bits.h".
	(update_enumeration_type_from_children): If an enumerator has
	multiple bits set, don't treat the enumeration as a "flag enum".
	* valprint.c (generic_val_print_enum_1): Assert that enumerators
	of flag enums have 0 or 1 bit set.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.c (enum flag_enum): Prefix enumerators with
	FE_, add FE_NONE.
	(three): Update.
	(enum flag_enum_without_zero): New enum.
	(flag_enum_without_zero): New variable.
	(enum not_flag_enum): New enum.
	(three_not_flag): New variable.
	* gdb.base/printcmds.exp (test_artificial_arrays): Update.
	(test_print_enums): Add more tests for printing flag enums.
2020-02-18 17:28:23 -05:00
Bernd Edlinger 6d0cf4464e Fix build with gcc-4.8.x
Use an explicit conversion from unique_ptr<T> to
displaced_step_closure_up to avoid a compiler bug
with gcc-4.8.4:

../../binutils-gdb/gdb/amd64-tdep.c:1514:10: error: cannot bind
   'std::unique_ptr<amd64_displaced_step_closure>' lvalue to
   'std::unique_ptr<amd64_displaced_step_closure>&&'

gdb:
2020-02-18  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* aarch64-tdep.c (aarch64_displaced_step_copy_insn): Use an explicit
	conversion.
	* amd64-tdep.c (amd64_displaced_step_copy_insn): Likewise.
	* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
	* i386-tdep.c (i386_displaced_step_copy_insn): Likewise.
	* rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise.
	* s390-tdep.c (s390_displaced_step_copy_insn): Likewise.
2020-02-18 22:22:56 +01:00