binutils-gdb/gdb/tui
Tom de Vries 947f759778 [gdb/tui,c++17] Fix NULL string_view in tui_partial_win_by_name
When building gdb with CFLAGS=-std=gnu17 and CXXFLAGS=-std=gnu++17 and running
test-case gdb.tui/new-layout.exp, we run into:
...
UNRESOLVED: gdb.tui/new-layout.exp: left window box after shrink (ll corner)
FAIL: gdb.tui/new-layout.exp: right window box after shrink (ll corner)
...

In a minimal form, we run into an abort when issuing a winheight command:
...
$ gdb -tui -ex "winheight src - 5"
   <tui stuff>
Aborted (core dumped)
$
...
with this backtrace at the abort:
...
\#0  0x0000000000438db0 in std::char_traits<char>::length (__s=0x0)
     at /usr/include/c++/9/bits/char_traits.h:335
\#1  0x000000000043b72e in std::basic_string_view<char, \
   std::char_traits<char> >::basic_string_view (this=0x7fffffffd4f0, \
   __str=0x0) at /usr/include/c++/9/string_view:124
\#2  0x000000000094971b in tui_partial_win_by_name (name="src")
     at src/gdb/tui/tui-win.c:663
...
due to a NULL comparison which constructs a string_view object from NULL:
...
   657  /* Answer the window represented by name.  */
   658  static struct tui_win_info *
   659  tui_partial_win_by_name (gdb::string_view name)
   660  {
   661    struct tui_win_info *best = nullptr;
   662
   663    if (name != NULL)
...

In gdbsupport/gdb_string_view.h, we either use:
- gdb's copy of libstdc++-v3/include/experimental/string_view, or
- the standard implementation of string_view, when built with C++17 or later
  (which in gcc's case comes from libstdc++-v3/include/std/string_view)

In the first case, there's support for constructing a string_view from a NULL
pointer:
...
      /*constexpr*/ basic_string_view(const _CharT* __str)
      : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
        _M_str{__str}
      { }
...
but in the second case, there's not:
...
      __attribute__((__nonnull__)) constexpr
      basic_string_view(const _CharT* __str) noexcept
      : _M_len{traits_type::length(__str)},
        _M_str{__str}
      { }
...

Fix this by removing the NULL comparison altogether.

Build on x86_64-linux with CFLAGS=-std=gnu17 and CXXFLAGS=-std=gnu++17, and
tested.

gdb/ChangeLog:

2020-07-06  Tom de Vries  <tdevries@suse.de>

	PR tui/26205
	* tui/tui-win.c (tui_partial_win_by_name): Don't test for NULL name.
2020-07-06 09:54:43 +02:00
..
ChangeLog-1998-2003
tui-command.c Remove flickering from the TUI 2020-01-19 13:08:49 -07:00
tui-command.h TUI windows do not need to store their type 2020-02-22 11:48:37 -07:00
tui-data.c Remove tui_set_win_with_focus 2020-02-22 11:48:38 -07:00
tui-data.h Make tui_win_info::name pure virtual 2020-07-01 21:21:17 -06:00
tui-disasm.c Make some tui_source_window_base members "protected" 2020-02-22 12:57:25 -07:00
tui-disasm.h Make some tui_source_window_base members "protected" 2020-02-22 12:57:25 -07:00
tui-file.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-file.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-hooks.c Move event-loop.[ch] to gdbsupport/ 2020-04-13 14:10:04 -06:00
tui-hooks.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-interp.c Fix crash when exiting TUI with gdb -tui 2020-06-16 18:02:20 -06:00
tui-io.c Remove tui_expand_tabs 2020-07-01 21:21:13 -06:00
tui-io.h Remove tui_expand_tabs 2020-07-01 21:21:13 -06:00
tui-layout.c Remove tui_gen_win_info 2020-07-01 21:21:17 -06:00
tui-layout.h Remove tui_gen_win_info 2020-07-01 21:21:17 -06:00
tui-out.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-out.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-regs.c Don't derive tui_data_item_window from tui_gen_win_info 2020-07-01 21:21:15 -06:00
tui-regs.h Don't derive tui_data_item_window from tui_gen_win_info 2020-07-01 21:21:15 -06:00
tui-source.c Change get_objfile_arch to a method on objfile 2020-04-18 08:35:04 -06:00
tui-source.h Make some tui_source_window_base members "protected" 2020-02-22 12:57:25 -07:00
tui-stack.c Move some code out of tui-data.h 2020-07-01 21:21:13 -06:00
tui-stack.h Make tui_win_info::name pure virtual 2020-07-01 21:21:17 -06:00
tui-win.c [gdb/tui,c++17] Fix NULL string_view in tui_partial_win_by_name 2020-07-06 09:54:43 +02:00
tui-win.h Remove unnecessary TUI declarations 2020-06-17 20:07:04 -06:00
tui-wingeneral.c Remove tui_gen_win_info 2020-07-01 21:21:17 -06:00
tui-wingeneral.h Remove tui_delete_invisible_windows and tui_make_all_invisible 2020-02-22 11:48:37 -07:00
tui-winsource.c Change get_objfile_arch to a method on objfile 2020-04-18 08:35:04 -06:00
tui-winsource.h Move some code out of tui-data.h 2020-07-01 21:21:13 -06:00
tui.c Fix crash when exiting TUI with gdb -tui 2020-06-16 18:02:20 -06:00
tui.h Fix crash when exiting TUI with gdb -tui 2020-06-16 18:02:20 -06:00