gdb: add test for readline handling very long commands
authorAndrew Burgess <aburgess@redhat.com>
Thu, 9 Feb 2023 10:52:47 +0000 (10:52 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Sat, 11 Feb 2023 17:17:56 +0000 (17:17 +0000)
commitbb146a79c7d65e2b578e8c3f652cb118c63741e5
tree7e28e34618f41c81d547e0924a56d0b357017415
parentb9c05fc03d313d8505df2c1265481faf6594b62a
gdb: add test for readline handling very long commands

The test added in this commit tests for a long fixed readline issue
relating to long command lines.  A similar patch has existed in the
Fedora GDB tree for several years, but I don't see any reason why this
test would not be suitable for inclusion in upstream GDB.  I've
updated the patch to current testsuite standards.

The test is checking for an issue that was fixed by this readline
patch:

  https://lists.gnu.org/archive/html/bug-readline/2006-11/msg00002.html

Which was merged into readline 6.0 (released ~2010).  The issue was
triggered when the user enters a long command line, which wrapped over
multiple terminal lines.  The crash looks like this:

  free(): invalid pointer

  Fatal signal: Aborted
  ----- Backtrace -----
  0x4fb583 gdb_internal_backtrace_1
          ../../src/gdb/bt-utils.c:122
  0x4fb583 _Z22gdb_internal_backtracev
          ../../src/gdb/bt-utils.c:168
  0x6047b9 handle_fatal_signal
          ../../src/gdb/event-top.c:964
  0x7f26e0cc56af ???
  0x7f26e0cc5625 ???
  0x7f26e0cae8d8 ???
  0x7f26e0d094be ???
  0x7f26e0d10aab ???
  0x7f26e0d124ab ???
  0x7f26e1d32e12 rl_free_undo_list
          ../../readline-5.2/undo.c:119
  0x7f26e1d229eb readline_internal_teardown
          ../../readline-5.2/readline.c:405
  0x7f26e1d3425f rl_callback_read_char
          ../../readline-5.2/callback.c:197
  0x604c0d gdb_rl_callback_read_char_wrapper_noexcept
          ../../src/gdb/event-top.c:192
  0x60581d gdb_rl_callback_read_char_wrapper
          ../../src/gdb/event-top.c:225
  0x60492f stdin_event_handler
          ../../src/gdb/event-top.c:545
  0xa60015 gdb_wait_for_event
          ../../src/gdbsupport/event-loop.cc:694
  0xa6078d gdb_wait_for_event
          ../../src/gdbsupport/event-loop.cc:593
  0xa6078d _Z16gdb_do_one_eventi
          ../../src/gdbsupport/event-loop.cc:264
  0x6fc459 start_event_loop
          ../../src/gdb/main.c:411
  0x6fc459 captured_command_loop
          ../../src/gdb/main.c:471
  0x6fdce4 captured_main
          ../../src/gdb/main.c:1310
  0x6fdce4 _Z8gdb_mainP18captured_main_args
          ../../src/gdb/main.c:1325
  0x44f694 main
          ../../src/gdb/gdb.c:32
  ---------------------

I recreated the above crash by a little light hacking on GDB, and then
linking GDB against readline 5.2.  The above stack trace was generated
from the test included in this patch, and matches the trace that was
included in the original bug report.

It is worth acknowledging that without hacking things GDB has a
minimum requirement of readline 7.0.  This test is not about checking
whether GDB has been built against an older version of readline, it is
about checking that readline doesn't regress in this area.

Reviewed-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.base/readline.exp