From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27103 invoked by alias); 30 Sep 2008 18:13:00 -0000 Received: (qmail 26924 invoked by uid 22791); 30 Sep 2008 18:12:58 -0000 X-Spam-Check-By: sourceware.org Received: from igw3.br.ibm.com (HELO igw3.br.ibm.com) (32.104.18.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 30 Sep 2008 18:11:59 +0000 Received: from d24relay01.br.ibm.com (unknown [9.8.31.16]) by igw3.br.ibm.com (Postfix) with ESMTP id 966763901F8 for ; Tue, 30 Sep 2008 14:49:37 -0300 (BRST) Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by d24relay01.br.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id m8UIBnlP999676 for ; Tue, 30 Sep 2008 15:11:49 -0300 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m8UIBtfi029069 for ; Tue, 30 Sep 2008 15:11:56 -0300 Received: from [9.18.238.184] (IBM-708585AE534-009018238184.br.ibm.com [9.18.238.184]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id m8UIBt2m029063 for ; Tue, 30 Sep 2008 15:11:55 -0300 Subject: [PATCH 4/4] catch syscall' feature -- Testcase part From: =?ISO-8859-1?Q?S=E9rgio?= Durigan =?ISO-8859-1?Q?J=FAnior?= To: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Date: Tue, 30 Sep 2008 18:13:00 -0000 Message-Id: <1222798416.30389.27.camel@miki> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-09/txt/msg00586.txt.bz2 This is the part that implements the testcase. Regards, -- Sérgio Durigan Júnior Linux on Power Toolchain - Software Engineer Linux Technology Center - LTC IBM Brazil 2008-09-29 Sergio Durigan Junior * gdb.base/catch-syscall.exp: New file. * gdb.base/catch-syscall.c: New file. * gdb.base/Makefile.in: Inclusion of catch-syscall object. diff --git a/gdb/testsuite/gdb.base/Makefile.in b/gdb/testsuite/gdb.base/Makefile.in index 9f382db..12db521 100644 --- a/gdb/testsuite/gdb.base/Makefile.in +++ b/gdb/testsuite/gdb.base/Makefile.in @@ -12,7 +12,7 @@ EXECUTABLES = all-types annota1 bitfields break \ scope section_command setshow setvar shmain sigall signals \ solib solib_sl so-impl-ld so-indr-cl \ step-line step-test structs structs2 \ - twice-tmp varargs vforked-prog watchpoint whatis + twice-tmp varargs vforked-prog watchpoint whatis catch-syscall MISCELLANEOUS = coremmap.data ../foobar.baz \ shr1.sl shr2.sl solib_sl.sl solib1.sl solib2.sl diff --git a/gdb/testsuite/gdb.base/catch-syscall.c b/gdb/testsuite/gdb.base/catch-syscall.c new file mode 100644 index 0000000..eafb63c --- /dev/null +++ b/gdb/testsuite/gdb.base/catch-syscall.c @@ -0,0 +1,25 @@ +/* This file is used to test the 'catch syscall' feature on GDB. + + Please, if you are going to edit this file DO NOT change the syscalls + being called (nor the order of them). If you really must do this, then + take a look at catch-syscall.exp and modify there too. + + Written by Sergio Durigan Junior + September, 2008 */ + +#include +#include +#include + +int +main (void) +{ + /* A close() with a wrong argument. We are only + interested in the syscall. */ + close (-1); + + chroot ("."); + + /* The last syscall. Do not change this. */ + _exit (0); +} diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp new file mode 100644 index 0000000..4b12850 --- /dev/null +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -0,0 +1,240 @@ +# Copyright 1997, 1999, 2007, 2008 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 program tests the 'catch syscall' functionality. +# +# It was written by Sergio Durigan Junior +# on September/2008. + +if { [is_remote target] || ![isnative] } then { + continue +} + +set prms_id 0 +set bug_id 0 + +global srcfile +set testfile "catch-syscall" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested catch-syscall.exp + return -1 +} + +# Until "catch syscall" is implemented on other targets... +if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then { + continue +} + +# Internal procedure used to check if, before any syscall is caught, +# the command 'info breakpoints' correctly lists the catchpoints AND +# says that nothing was caught yet. +proc check_init_info_breakpoints {} { + global gdb_prompt + + # Verifying that the catchpoint appears in the 'info breakpoints' + # command, but with "". + set thistest "catch syscall appears in 'info breakpoints'" + gdb_test "info breakpoints" ".*catch syscall.*keep y.*syscall \"\".*" $thistest +} + +# This procedure checks if, after a syscall catchpoint is hit, the +# command 'info breakpoints' correctly lists the syscall name. +proc check_info_breakpoints { syscall_name } { + global gdb_prompt + + set thistest "syscall '$syscall_name' appears in 'info breakpoints'" + gdb_test "info breakpoints" ".*catch syscall.*keep y.*syscall \"$syscall_name\".*" $thistest +} + +# This procedure checks if there was a call to a syscall. +proc check_call_to_syscall { syscall_name } { + global gdb_prompt + + set thistest "program has called '$syscall_name'" + gdb_test "continue" "Catchpoint .*(called syscall .$syscall_name ().).*in.*from.*" $thistest + + # Checking if the syscall is reported to be caught in + # 'info breakpoints'. + check_info_breakpoints $syscall_name +} + +# This procedure checks if the syscall returned. +proc check_return_from_syscall { syscall_name } { + global gdb_prompt + + set thistest "syscall '$syscall_name' has returned" + gdb_test "continue" "Catchpoint .*(returned from syscall .$syscall_name ().).*in.*from.*" $thistest + + # Checking if the syscall is reported to be caught in + # 'info breakpoints'. + check_info_breakpoints $syscall_name +} + +# Internal procedure that performs two 'continue' commands and checks if +# a syscall call AND return occur. +proc check_continue { syscall_name } { + global gdb_prompt + + # Testing if the 'continue' stops at the + # specified syscall_name. If it does, then it should + # first print that the infeior has called the syscall, + # and after print that the syscall has returned. + + # Testing if the inferiorr has called the syscall. + check_call_to_syscall $syscall_name + # And now, that the syscall has returned. + check_return_from_syscall $syscall_name +} + +# Inserts a syscall catchpoint with an argument. +proc insert_catch_syscall_with_arg { syscall_name } { + global gdb_prompt + + # Trying to set the syscall + set thistest "catch syscall with arguments ($syscall_name)" + gdb_test "catch syscall $syscall_name" "Catchpoint .*(syscall .$syscall_name ().).*" $thistest + +} + +proc check_for_program_end {} { + global gdb_prompt + + # Deleting the catchpoints + delete_breakpoints + + set thistest "successful program end" + gdb_test "continue" "Program exited normally.*" $thistest + +} + +proc test_catch_syscall_without_args {} { + global gdb_prompt + # All (but the last) syscalls from the example code + # They are ordered according to the file, so do not change this. + set all_syscalls { "close" "chroot" } + # The last syscall (exit()) does not return, so + # we cannot expect the catchpoint to be triggered + # twice. It is a special case. + set last_syscall "exit_group" + + # Trying to set the syscall + set thistest "setting catch syscall without arguments" + gdb_test "catch syscall" "Catchpoint .*(syscall).*" $thistest + + check_init_info_breakpoints + + # We have to check every syscall + foreach name $all_syscalls { + check_continue $name + } + + # At last but not least, we check if the inferior + # has called the last (exit) syscall. + check_call_to_syscall $last_syscall + + # Now let's see if the inferior correctly finishes. + check_for_program_end +} + +proc test_catch_syscall_with_args {} { + global gdb_prompt + set syscall_name "close" + + insert_catch_syscall_with_arg $syscall_name + check_init_info_breakpoints + + # Can we continue until we catch the syscall? + check_continue $syscall_name + + # Now let's see if the inferior correctly finishes. + check_for_program_end +} + +proc test_catch_syscall_with_wrong_args {} { + global gdb_prompt + # mlock is not called from the source + set syscall_name "mlock" + + insert_catch_syscall_with_arg $syscall_name + check_init_info_breakpoints + + # Now, we must verify if the program stops with a continue. + # If it doesn't, everything is right (since we don't have + # a syscall named "mlock" in it). Otherwise, this is a failure. + set thistest "catch syscall with unused syscall ($syscall_name)" + gdb_test "continue" "Program exited normally.*" $thistest +} + +proc test_catch_syscall_restarting_inferior {} { + global gdb_prompt + set syscall_name "chroot" + + insert_catch_syscall_with_arg $syscall_name + check_init_info_breakpoints + + # Let's first reach the call of the syscall. + check_call_to_syscall $syscall_name + + # Now, restart the program + rerun_to_main + + # And check for call/return + check_continue $syscall_name + + # Can we finish? + check_for_program_end +} + +proc do_syscall_tests {} { + global gdb_prompt + + # Verify that the 'catch syscall' help is available + set thistest "help catch syscall" + gdb_test "help catch syscall" "Catch calls to syscalls.*" $thistest + + # Try to set a catchpoint to a nonsense syscall + set thistest "catch syscall to a nonsense syscall is prohibited" + gdb_test "catch syscall nonsense_syscall" "Invalid syscall name .*" $thistest + + # Testing the 'catch syscall' command without arguments. + # This test should catch any syscalls. + if [runto_main] then { test_catch_syscall_without_args } + + # Testing the 'catch syscall' command with arguments. + # This test should only catch the specified syscall. + if [runto_main] then { test_catch_syscall_with_args } + + # Testing the 'catch syscall' command with WRONG arguments. + # This test should not trigger any catchpoints. + if [runto_main] then { test_catch_syscall_with_wrong_args } + + # Testing the 'catch' syscall command during a restart of + # the inferior. + if [runto_main] then { test_catch_syscall_restarting_inferior } +} + +# Start with a fresh gdb + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# Execute the tests +do_syscall_tests