From patchwork Fri Aug 22 19:05:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 2519 Received: (qmail 13736 invoked by alias); 22 Aug 2014 19:05:26 -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 13583 invoked by uid 89); 22 Aug 2014 19:05:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg20.ericsson.net Received: from usevmg20.ericsson.net (HELO usevmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 22 Aug 2014 19:05:23 +0000 Received: from EUSAAHC006.ericsson.se (Unknown_Domain [147.117.188.90]) by usevmg20.ericsson.net (Symantec Mail Security) with SMTP id 43.01.05330.AEF37F35; Fri, 22 Aug 2014 15:04:42 +0200 (CEST) Received: from simark-hp.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.90) with Microsoft SMTP Server (TLS) id 14.3.174.1; Fri, 22 Aug 2014 15:05:18 -0400 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH v3 2/2] Add dprintf and detach test (PR breakpoints/17012) Date: Fri, 22 Aug 2014 15:05:15 -0400 Message-ID: <1408734315-21207-2-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1408734315-21207-1-git-send-email-simon.marchi@ericsson.com> References: <1408734315-21207-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-IsSubscribed: yes This adds a test to demonstrate PR 17012, where adding a dprintf in a linux native process and detaching leaves the trap instruction in the process. One issue is that the test does not pass when running with --target_board=native-extended-gdbserver, partly due to bug 17302 [1]. One quick hack I tried for this was to add a useless "next" between the call to getpid() and detach, which avoids the bug. There is still one case where the test fails, and that is with: - breakpoint always-inserted on - dprintf-style agent - disconnected-dprintf on What happens is that my detach does not actually detach the process, because some persistent commands (the disconnected dprintf) is present. However since gdbserver is ran with --once, when gdb disconnects, gdbserver goes down and takes with it all the processes it spawned and that are still under its control (which includes my test process). When the test checks if the test process is still alive, it obvisouly fails. Investigating about that led me to ask a question on the ML [2] about the behavior of detach. Until the remote case is sorted out, would it be ok to disable the test for all remote targets or KFAIL the tests? I will tackle the blocking problems in separate patches. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=17302 [2] https://sourceware.org/ml/gdb/2014-08/msg00115.html New in v3: * Follow-up Pedro's review * Fix wrong include and formatting in test program. * Remove check to run the test only on Linux. * Disable test for stubs instead of all remote targets * Test with all cominations of dprintf-style, breakpoint always-inserted and disconnected-dprintf. * Check if "call getpid ()" succeeds. * Clean restart gdb when re-attaching, New in v2: * Verify process existence by trying to attach it with a new gdb. * Added/updated copyright notices. gdb/testsuite/ChangeLog: PR breakpoints/17012 gdb.base/dprintf-detach.c: New file. gdb.base/dprintf-detach.exp: New file. --- gdb/testsuite/gdb.base/dprintf-detach.c | 33 ++++++++++++ gdb/testsuite/gdb.base/dprintf-detach.exp | 87 +++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 gdb/testsuite/gdb.base/dprintf-detach.c create mode 100644 gdb/testsuite/gdb.base/dprintf-detach.exp diff --git a/gdb/testsuite/gdb.base/dprintf-detach.c b/gdb/testsuite/gdb.base/dprintf-detach.c new file mode 100644 index 0000000..16d7023 --- /dev/null +++ b/gdb/testsuite/gdb.base/dprintf-detach.c @@ -0,0 +1,33 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014 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 . */ + +#include + +static void +function (void) +{ + sleep (1); +} + +int +main (void) +{ + int i; + + for (i = 0; i < 30; i++) + function (); +} diff --git a/gdb/testsuite/gdb.base/dprintf-detach.exp b/gdb/testsuite/gdb.base/dprintf-detach.exp new file mode 100644 index 0000000..c0fb6fc --- /dev/null +++ b/gdb/testsuite/gdb.base/dprintf-detach.exp @@ -0,0 +1,87 @@ +# Copyright 2014 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 . */ + +# This test checks that inserting a dprintf and detaching does not crash +# the program. +# +# Related bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17012 + +# The test relies on "detach/attach". +if { [target_info exists use_gdb_stub] } then { + return 0 +} + +standard_testfile +set escapedbinfile [string_to_regexp ${binfile}] + +if [prepare_for_testing "failed to prepare for dprintf-detach" \ + ${testfile} ${srcfile} {debug}] { + return -1 +} + +proc dprintf_detach_test { breakpoint_always_inserted dprintf_style disconnected_dprintf } { + set test_prefix "bai=${breakpoint_always_inserted} ds=${dprintf_style} dd=${disconnected_dprintf}" + global binfile decimal gdb_prompt escapedbinfile + + with_test_prefix "$test_prefix" { + # Start with a clean gdb + clean_restart ${binfile} + + gdb_test_no_output "set breakpoint always-inserted ${breakpoint_always_inserted}" + gdb_test_no_output "set dprintf-style ${dprintf_style}" + gdb_test_no_output "set disconnected-dprintf ${disconnected_dprintf}" + + if ![runto_main] { + fail "Can't run to main" + return -1 + } + + # Get PID of test program. + set inferior_pid -1 + set test "get inferior process ID" + gdb_test_multiple "call getpid ()" $test { + -re ".* = ($decimal).*$gdb_prompt $" { + set inferior_pid $expect_out(1,string) + pass $test + } + } + + if {$inferior_pid == -1} { + return + } + + # Add a dprintf and detach. + gdb_test "dprintf function, \"hello\"" "Dprintf .*" "dprintf insertion" + gdb_test "detach" "Detaching from program: .*$escapedbinfile, .*" "detach program" + + gdb_exit + + # Give some time for the ex-inferior to run and hopefully not crash. + sleep 1 + + # Check that the process still exists by attaching a new gdb to it. + clean_restart ${binfile} + + gdb_test "attach $inferior_pid" "Attaching to program: $escapedbinfile, process $inferior_pid.*Reading symbols from.*" "re-attach to inferior" + } +} + +foreach breakpoint_always_inserted { "on" "off" } { + foreach dprintf_style { "gdb" "call" "agent" } { + foreach disconnected_dprintf { "on" "off" } { + dprintf_detach_test $breakpoint_always_inserted $dprintf_style $disconnected_dprintf + } + } +}