From patchwork Wed Jun 18 14:26:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 1556 Received: (qmail 19219 invoked by alias); 18 Jun 2014 14:26:24 -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 19204 invoked by uid 89); 18 Jun 2014 14:26:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg21.ericsson.net Received: from usevmg21.ericsson.net (HELO usevmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 18 Jun 2014 14:26:18 +0000 Received: from EUSAAHC002.ericsson.se (Unknown_Domain [147.117.188.78]) by usevmg21.ericsson.net (Symantec Mail Security) with SMTP id 7F.18.11744.EED41A35; Wed, 18 Jun 2014 10:29:34 +0200 (CEST) Received: from simark-hp.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.78) with Microsoft SMTP Server (TLS) id 14.3.174.1; Wed, 18 Jun 2014 10:26:14 -0400 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 1/2] Add dprintf and detach test (PR breakpoints/17012) Date: Wed, 18 Jun 2014 10:26:10 -0400 Message-ID: <1403101571-1190-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. I copied bits from many other existing tests. The test fails now, but is fixed by the following commit. gdb/testsuite/ChangeLog: 2014-06-18 Simon Marchi simon.marchi@ericsson.com PR breakpoints/17012 gdb.base/dprintf-detach.c: New file. gdb.base/dprintf-detach.exp: New file. --- gdb/testsuite/gdb.base/dprintf-detach.c | 18 +++++++ gdb/testsuite/gdb.base/dprintf-detach.exp | 80 +++++++++++++++++++++++++++++++ 2 files changed, 98 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..91f49ce --- /dev/null +++ b/gdb/testsuite/gdb.base/dprintf-detach.c @@ -0,0 +1,18 @@ +#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..18ba154 --- /dev/null +++ b/gdb/testsuite/gdb.base/dprintf-detach.exp @@ -0,0 +1,80 @@ +# Copyright 2003-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 + +# Only GNU/Linux is known to support (dprintf and detach). +if { ! [istarget "*-*-linux*"] } { + return 0 +} + +# Are we on a target board? +if [is_remote target] 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 +} + +# The problem was showing up in non-stop mode, since it enables +# "breakpoint always-inserted", so this could also be +# "set breakpoint always-inserted on". +gdb_test_no_output "set non-stop on" + +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 + } +} + +# Add a dprintf and detach. +gdb_test "dprintf function, \"hello\"" "Dprintf .*" "dprintf insertion" +gdb_test "detach" "Detaching from program: .*$escapedbinfile, .*" "detach program" + +# Exit gdb. Until we do that, the process will exist as a zombie. +gdb_exit + +# Give some time for the ex-inferior to run and hopefully not crash. +sleep 1 + +# Check that the process still exists. +set test "detached process should continue to exist" +if {[catch {exec kill -0 $inferior_pid}]} { + # Process does not exist. + fail "$test" +} else { + # Process exists. + pass "$test" +} + +# Clean up. +catch {exec kill -9 $inferior_pid}