From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2446F3858D28 for ; Fri, 10 Feb 2023 10:42:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2446F3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676025772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/o0t6us3EQHRCy4JUyFTPLfMyTXoh89Us17x1rNgxj0=; b=O7LT1csTeicK6MvPzEJjY1z0BL0THjkj1n0GTmhI7DD8Co+wkDIKkhLjTMaY34BunAESlM H2xvmj9Lhid8xdhoDdNI82TNrBzpr46teUet7mRRqktAiD3KLJ0Z8MboJbeAcFYWRTD+vT f/X31iTf55k8acKIC+hGxjEs7zKKBT4= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-246-eNxd5cBDNA-6wqLmu_XS3A-1; Fri, 10 Feb 2023 05:42:52 -0500 X-MC-Unique: eNxd5cBDNA-6wqLmu_XS3A-1 Received: by mail-qk1-f199.google.com with SMTP id x14-20020a05620a14ae00b0072f7f0f356bso3041284qkj.1 for ; Fri, 10 Feb 2023 02:42:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/o0t6us3EQHRCy4JUyFTPLfMyTXoh89Us17x1rNgxj0=; b=iJNbYBReWrx1wfhDJxoHM4p1VnD340j18LtMuHgJiLq/YTjWhZckpIuWYbwLl4457i p2j+JGnDpjlH7JB9kgl/+m4cdtujMp3CDshAwv/EtinFKUoVi5JNafofWq/q0pceoVCn 1M06Zone9RYydfAX6yrsyf1LCnwj4RUtJMcxeOfYU46h5DPAFaaCaarT6OHEEg8TlkW0 LAYlDoQhE6LxXxEu9aKXpJ6lnv2CYHXFFMs8lP8lQTwQC2AzbAB1NE5om0+Zwk4HLHvy +3OcldFhA4+er5huNQ53x+SVBhv5a0ElfBiAlQsvqNhyOn9SF3zdOkf1pSyaaKJBl9eZ DWHw== X-Gm-Message-State: AO0yUKXxAZx0hFPUt6HHl1EuJeCvxeO4yv+Hffm6mZJjoZWuvxoA6O2Q sEqi7/lL+ptHgSKO9KyxMhWORh/+uj46TA/8N3IKJdt10sTKI3wP/wZjwpWAErD+4Secpnc3wNI 3hRMhvKEXOQ6OsbMBK9xhXVk5lL0EBSMnegy4vRUkVPH/FYQoR0eaRTKPBp6+pt27tqso6hr/cp I+g/Y= X-Received: by 2002:a05:6214:300c:b0:56b:ee60:42f2 with SMTP id ke12-20020a056214300c00b0056bee6042f2mr23254998qvb.45.1676025771247; Fri, 10 Feb 2023 02:42:51 -0800 (PST) X-Google-Smtp-Source: AK7set8UgQQYtFYtgn0gdfqGcpI3419DmzZjqKOFOaPzGm07I8SL0xu28Wm0fwuVzZvRFBQekJDTrg== X-Received: by 2002:a05:6214:300c:b0:56b:ee60:42f2 with SMTP id ke12-20020a056214300c00b0056bee6042f2mr23254976qvb.45.1676025770826; Fri, 10 Feb 2023 02:42:50 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id 2-20020a05620a048200b007290be5557bsm3266752qkr.38.2023.02.10.02.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 02:42:50 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb: add test for readline handling very long commands Date: Fri, 10 Feb 2023 10:42:46 +0000 Message-Id: <5590ca7146d94722f6ae6b2e96fe92f3ef6b4eab.1676025758.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. --- gdb/testsuite/gdb.base/readline.exp | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gdb/testsuite/gdb.base/readline.exp b/gdb/testsuite/gdb.base/readline.exp index 73c10f8000f..87225273c25 100644 --- a/gdb/testsuite/gdb.base/readline.exp +++ b/gdb/testsuite/gdb.base/readline.exp @@ -205,5 +205,45 @@ save_vars { env(TERM) } { "p 7" ".* = 7" \ "p 8" ".* = 8" \ "p 9" ".* = 9" + + # Test sending a long command to GDB, a command that requires + # multiple terminal lines. Long ago there was a readline bug + # that would cause GDB to crash in this situation. We force + # the bug by setting up a narrow terminal width, and then + # sending a long command. + clean_restart + + # The number of characters to send in the command. We + # actually send a few more than this; this total is really the + # extra characters we add on after sending the command name. + set char_total 4500 + set char_sent 0 + + # Adjust the terminal width. + gdb_test_no_output "set width 7" + + # Send the command prefix, then lots of additional characters + # that create a really long command that wraps over multiple + # lines. + send_gdb "help X" + gdb_test_multiple "" "send long command to GDB" { + -re "X" { + incr char_sent + if {$char_sent <= $char_total} { + send_gdb "X" + exp_continue + } + } + -re "\[ \b\r\n\]" { + exp_continue + } + } + + # Send the final newline so that GDB will process the command. + # Check GDB returns a suitable error. + send_gdb "\n" + gdb_test "" \ + "Undefined command: \"X+\"\\. Try \"help\"\\." \ + "All the characters transferred" } } base-commit: 1947a4a4bb7651a4656edceb1f9b246f96f89ebd -- 2.25.4