From patchwork Tue Nov 18 03:30:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 3783 Received: (qmail 21025 invoked by alias); 18 Nov 2014 03:30:29 -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 21009 invoked by uid 89); 18 Nov 2014 03:30:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 18 Nov 2014 03:30:26 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAI3ULWG024314 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Nov 2014 22:30:22 -0500 Received: from localhost (dhcp-10-15-16-169.yyz.redhat.com [10.15.16.169]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAI3UKN8023710 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 17 Nov 2014 22:30:21 -0500 From: Sergio Durigan Junior To: Pedro Alves Cc: GDB Patches , Gabriel Krisman Bertazi Subject: Re: [PATCH 3/3] Testcase References: <1415837887-28888-1-git-send-email-sergiodj@redhat.com> <1415837887-28888-4-git-send-email-sergiodj@redhat.com> <546625C4.5050007@redhat.com> X-URL: http://blog.sergiodj.net Date: Mon, 17 Nov 2014 22:30:20 -0500 Message-ID: <87y4r9xk1f.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes On Friday, November 14 2014, Pedro Alves wrote: > On 11/13/2014 12:18 AM, Sergio Durigan Junior wrote: >> This patch implements the testcase for this fix. The test is very >> simple: we just have to verify if the syscall number for each >> architecture has different meanings. I chose to test i386 and x86_64 >> here, but it could be any other architecture supported by the "catch >> syscall" command. > > This only works if the built GDB has these architectures configured > in. > > E.g., an --enable-targets=all build on x86: > > (gdb) set architecture aarch64 > The target architecture is assumed to be aarch64 > > while on a default x86 build: > > (gdb) set architecture aarch64 > Undefined item: "aarch64". > > From that, you can see that: > > (gdb) set architecture i386 > > would fail on non-x86 builds that don't include x86 in --enable-targets=foo. True, thanks for catching this. When I tested it in my machine, I made some confusion and used the same GDB to test both scenarios. Sorry about that. >> >> +proc test_catch_syscall_multi_target {} { > > Please make this "multi_arch". Let's leave "multi-target" for > https://sourceware.org/gdb/wiki/MultiTarget. Ouch, sorry. Fixed. > >> + global decimal binfile >> + >> + with_test_prefix "multiple targets" { >> + clean_restart $binfile >> + >> + gdb_test "set architecture i386" \ >> + "The target architecture is assumed to be i386" \ >> + "set arch to i386" >> + >> + gdb_test "catch syscall 1" \ >> + "Catchpoint $decimal \\(syscall .exit. \\\[1\\\]\\)" \ >> + "insert catch syscall on syscall 1 -- exit on i386" >> + >> + gdb_test "set architecture i386:x86-64" \ >> + "The target architecture is assumed to be i386:x86-64" \ >> + "set arch to x86_64" >> + >> + gdb_test "catch syscall 1" \ >> + "Catchpoint $decimal \\(syscall .write. \\\[1\\\]\\)" \ >> + "insert catch syscall on syscall 1 -- exit on i386" > > The "exit on i386" part seems stale here. Fixed. > I think we should do something like this: > > if { [istarget "i*86-*-*"] || [istarget "x86_64-*-*"] } { > set arch1 "i386" > set syscall1 "exit" > set arch2 "i386:x86-64" > set syscall2 "write" > } elseif { [istarget "powerpc-*-linux*"] || [istarget "powerpc64-*-linux*"] } { > ... > } elseif { [istarget "sparc-*-linux*"] && ![istarget "sparc64-*-linux*"] } { > ... > } elseif { [istarget "mips*-linux*"] } { > ... > } elseif { [istarget "arm*-linux*"] } { > ... > } elseif { [istarget "s390*-linux*"] } { > ... > } else { > error "please port me" > } That was my first idea, but I was trying to avoid having yet another set of if...elseif... on catch-syscall.exp. And due to my mistake when testing this patch, I thought I wouldn't need to worry about that after all. Silly me. Anyway, here is the updated patch. WDYT? diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp index a70534c..ed87d61 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.exp +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -311,6 +311,10 @@ proc do_syscall_tests {} { # Testing the 'catch' syscall command during a restart of # the inferior. if [runto_main] then { test_catch_syscall_restarting_inferior } + + # Testing if the 'catch syscall' command works when switching to + # different architectures on-the-fly (PR gdb/10737). + if [runto_main] then { test_catch_syscall_multi_arch } } proc test_catch_syscall_without_args_noxml {} { @@ -372,6 +376,73 @@ proc test_catch_syscall_with_wrong_args_noxml {} { } } +proc test_catch_syscall_multi_arch {} { + global decimal binfile + + if { [istarget "i*86-*-*"] || [istarget "x86_64-*-*"] } { + set arch1 "i386" + set arch2 "i386:x86-64" + set syscall1_name "exit" + set syscall2_name "write" + set syscall_number 1 + } elseif { [istarget "powerpc-*-linux*"] \ + || [istarget "powerpc64-*-linux*"] } { + set arch1 "powerpc:common" + set arch2 "powerpc:common64" + set syscall1_name "openat" + set syscall2_name "unlinkat" + set syscall_number 286 + } elseif { [istarget "sparc-*-linux*"] \ + || [istarget "sparc64-*-linux*"] } { + set arch1 "sparc" + set arch2 "sparc:v9" + set syscall1_name "setresuid32" + set syscall2_name "setresuid" + set syscall_number 108 + } elseif { [istarget "mips*-linux*"] } { + # MIPS does not use the same numbers for syscalls on 32 and 64 + # bits. + verbose "Not testing MIPS for multi-arch syscall support" + return + } elseif { [istarget "arm*-linux*"] } { + # catch syscall supports only 32-bit ARM for now. + verbose "Not testing ARM for multi-arch syscall support" + return + } elseif { [istarget "s390*-linux*"] } { + set arch1 "" + set arch2 "s390:64-bit" + set syscall1_name "_newselect" + set syscall2_name "select" + set syscall_number 142 + } + + with_test_prefix "multiple targets" { + # We are not interested in loading any binary here, and in + # some systems (PowerPC, for example), if we load a binary + # there is no way to set other architecture. + gdb_exit + gdb_start + + gdb_test "set architecture $arch1" \ + "The target architecture is assumed to be $arch1" \ + "set arch to $arch1" + + gdb_test "catch syscall $syscall_number" \ + "Catchpoint $decimal \\(syscall .${syscall1_name}. \\\[${syscall_number}\\\]\\)" \ + "insert catch syscall on syscall $syscall_number -- $syscall1_name on $arch1" + + gdb_test "set architecture $arch2" \ + "The target architecture is assumed to be $arch2" \ + "set arch to $arch2" + + gdb_test "catch syscall $syscall_number" \ + "Catchpoint $decimal \\(syscall .${syscall2_name}. \\\[${syscall_number}\\\]\\)" \ + "insert catch syscall on syscall $syscall_number -- $syscall2_name on $arch2" + + clean_restart $binfile + } +} + proc do_syscall_tests_without_xml {} { # Make sure GDB doesn't load the syscalls xml from the system data # directory.