From patchwork Tue Mar 7 13:59:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 19455 Received: (qmail 1612 invoked by alias); 7 Mar 2017 13:59:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 1347 invoked by uid 89); 7 Mar 2017 13:59:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Minimal, 3990, 768, 8364 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Mar 2017 13:59:29 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12E8B3B755 for ; Tue, 7 Mar 2017 13:59:30 +0000 (UTC) Received: from cascais.lan (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v27DxRow000859 for ; Tue, 7 Mar 2017 08:59:29 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] Fix "layout reg" crash Date: Tue, 7 Mar 2017 13:59:26 +0000 Message-Id: <1488895166-28068-3-git-send-email-palves@redhat.com> Commit d7e747318f4d04 ("Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy") introduced a problem when using "layout regs", that leads gdb to crash when issuing: ./gdb ./a.out -ex 'layout regs' -ex start From the backtrace, it's caused by this 'delete' on tui_restore_gdbout(): (gdb) bt #0 0x00007ffff6b962b2 in free () from /lib64/libc.so.6 #1 0x000000000059fa47 in tui_restore_gdbout (ui=0x22997b0) at ../../gdb/tui/tui-regs.c:714 #2 0x0000000000619996 in do_my_cleanups (pmy_chain=pmy_chain@entry=0x1e08320 , old_chain=old_chain@entry=0x235b4b0) at ../../gdb/common/cleanups.c:154 #3 0x0000000000619b1d in do_cleanups (old_chain=old_chain@entry=0x235b4b0) at ../../gdb/common/cleanups.c:176 #4 0x000000000059fb0d in tui_register_format (frame=frame@entry=0x22564e0, regnum=regnum@entry=0) at ../../gdb/tui/tui-regs.c:747 #5 0x000000000059ffeb in tui_get_register (data=0x2434d18, changedp=0x0, regnum=0, frame=0x22564e0) at ../../gdb/tui/tui-regs.c:768 #6 tui_show_register_group (refresh_values_only=, frame=0x22564e0, group=0x1e09250 ) at ../../gdb/tui/tui-regs.c:287 #7 tui_show_registers (group=0x1e09250 ) at ../../gdb/tui/tui-regs.c:156 #8 0x00000000005a07cf in tui_check_register_values (frame=frame@entry=0x22564e0) at ../../gdb/tui/tui-regs.c:496 #9 0x00000000005a3e65 in tui_check_data_values (frame=frame@entry=0x22564e0) at ../../gdb/tui/tui-windata.c:232 #10 0x000000000059cf65 in tui_refresh_frame_and_register_information (registers_too_p=1) at ../../gdb/tui/tui-hooks.c:156 #11 0x00000000006d5c05 in generic_observer_notify (args=0x7fffffffdbe0, subject=) at ../../gdb/observer.c:167 #12 observer_notify_normal_stop (bs=, print_frame=print_frame@entry=1) at ./observer.inc:61 #13 0x00000000006a6409 in normal_stop () at ../../gdb/infrun.c:8364 #14 0x00000000006af8f5 in fetch_inferior_event (client_data=) at ../../gdb/infrun.c:3990 #15 0x000000000066f0fd in gdb_wait_for_event (block=block@entry=0) at ../../gdb/event-loop.c:859 #16 0x000000000066f237 in gdb_do_one_event () at ../../gdb/event-loop.c:322 #17 0x000000000066f386 in gdb_do_one_event () at ../../gdb/event-loop.c:353 #18 0x00000000007411bc in wait_sync_command_done () at ../../gdb/top.c:570 #19 0x0000000000741426 in maybe_wait_sync_command_done (was_sync=0) at ../../gdb/top.c:587 #20 execute_command (p=, p@entry=0x7fffffffe43a "start", from_tty=from_tty@entry=1) at ../../gdb/top.c:676 #21 0x00000000006c2048 in catch_command_errors (command=0x741200 , arg=0x7fffffffe43a "start", from_tty=1) at ../../gdb/main.c:376 #22 0x00000000006c2b60 in captured_main_1 (context=0x7fffffffde70) at ../../gdb/main.c:1119 #23 captured_main (data=0x7fffffffde70) at ../../gdb/main.c:1140 #24 gdb_main (args=args@entry=0x7fffffffdf90) at ../../gdb/main.c:1158 #25 0x0000000000408cf5 in main (argc=, argv=) at ../../gdb/gdb.c:32 (gdb) f 1 #1 0x000000000059fa47 in tui_restore_gdbout (ui=0x22997b0) at ../../gdb/tui/tui-regs.c:714 714 delete gdb_stdout; The problem is simply that the commit mentioned above made the ui_file that gdb_stdout is temporarily set to be a stack-allocated string_file, while before it used to be a heap-allocated ui_file. The fix is simply to remove the now-incorrect delete. New test included, which exercises enabling all TUI layouts, with and without execution. (This particular crash only triggers with execution.) gdb/ChangeLog: 2017-03-07 Pedro Alves * tui/tui-regs.c (tui_restore_gdbout): Don't delete gdb_stdout. gdb/testsuite/ChangeLog: 2017-03-07 Pedro Alves * gdb.base/tui-layout.c: New file. * gdb.base/tui-layout.exp: New file. --- gdb/ChangeLog | 4 +++ gdb/testsuite/ChangeLog | 5 ++++ gdb/testsuite/gdb.base/tui-layout.c | 22 ++++++++++++++ gdb/testsuite/gdb.base/tui-layout.exp | 56 +++++++++++++++++++++++++++++++++++ gdb/tui/tui-regs.c | 1 - 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/tui-layout.c create mode 100644 gdb/testsuite/gdb.base/tui-layout.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 681ecd0..8d6f9cc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2017-03-07 Pedro Alves + + * tui/tui-regs.c (tui_restore_gdbout): Don't delete gdb_stdout. + 2017-03-07 Walfred Tedeschi * i387-tdep.h (i387_reset_bnd_regs): Add function definition. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index cc1a14a..c99f644 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2017-03-07 Pedro Alves + * gdb.base/tui-layout.c: New file. + * gdb.base/tui-layout.exp: New file. + +2017-03-07 Pedro Alves + * gdb.base/tui-layout.c: Rename to ... * gdb.base/tui-disasm-long-lines.c: ... this. * gdb.base/tui-layout.exp: Rename to ... diff --git a/gdb/testsuite/gdb.base/tui-layout.c b/gdb/testsuite/gdb.base/tui-layout.c new file mode 100644 index 0000000..956545f --- /dev/null +++ b/gdb/testsuite/gdb.base/tui-layout.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2017 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/tui-layout.exp b/gdb/testsuite/gdb.base/tui-layout.exp new file mode 100644 index 0000000..41f9ceb --- /dev/null +++ b/gdb/testsuite/gdb.base/tui-layout.exp @@ -0,0 +1,56 @@ +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Minimal testcase that just checks that the various "layout $foo" +# commands do not cause gdb to crash. + +standard_testfile + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { + return -1 +} + +if {[skip_tui_tests]} { + return +} + +# Test one layout command. EXECUTION indicates whether to activate +# the layout with or without execution. + +proc test_layout {layout execution} { + global binfile gdb_prompt + + clean_restart $binfile + + if {$execution} { + if ![runto_main] then { + fail "can't run to main" + return 0 + } + } + + set test "layout command" + gdb_test_multiple "layout $layout" $test { + -re "$gdb_prompt $" { + pass $test + } + } +} + +foreach_with_prefix execution {0 1} { + foreach_with_prefix layout {"asm" "reg" "src" "split"} { + test_layout $layout $execution + } +} diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 7d116ee8..3f9a007 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -711,7 +711,6 @@ TUI command to control the register window."), tuicmd); static void tui_restore_gdbout (void *ui) { - delete gdb_stdout; gdb_stdout = (struct ui_file*) ui; pagination_enabled = 1; }