From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 72201 invoked by alias); 21 Nov 2017 11:32:38 -0000 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 Received: (qmail 62902 invoked by uid 89); 21 Nov 2017 11:30:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Nov 2017 11:30:56 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6E1AA81C40 for ; Tue, 21 Nov 2017 12:30:47 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nGvn4pmjTFH7 for ; Tue, 21 Nov 2017 12:30:47 +0100 (CET) Received: from Xaviers-MacBook-Pro.local (unknown [10.10.8.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 0BEE481387 for ; Tue, 21 Nov 2017 12:30:46 +0100 (CET) From: Xavier Roirand Subject: [RFC] Add support for stopping in Ada exception handler To: gdb-patches@sourceware.org Message-ID: <40168bfe-b228-0655-9a5e-0406309841d1@adacore.com> Date: Tue, 21 Nov 2017 11:32:00 -0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------E714F2A198CA19DC007A34CF" X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00431.txt.bz2 This is a multi-part message in MIME format. --------------E714F2A198CA19DC007A34CF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 3387 Hello, I'm working on a patch that adds support for stopping on Ada exceptions handling using Ada catchpoint. This command is: - catch handle [exception name] If the exception name is omitted, then all Ada exception handlers are used. This command will stop if the program handles an Ada exception which has been raised or on all Ada exception handlers if not exception name has been specified. Here is a typical GDB session debugging a program that does the following: 1. Raise exception Constraint_Error (and catch it) 2. Raise exception Program_Error (and catch it) 3. Raise exception Storage_Error (and catch all exceptions) We'll first stop on Constraint_Error exception handle, and see how it catches it for the first exception: (gdb) catch handle Constraint_Error Catchpoint 1: `Constraint_Error' Ada exception handler (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y 0x00000000004030f8 `Constraint_Error' Ada exception handler Starting program: /tmp/foo Catchpoint 1, exception at 0x0000000000402553 in foo () at foo.adb:24 24 when Constraint_Error => -- SPOT1 Now we add a Program_Error exception handling: (gdb) catch handle Program_Error Note: breakpoint 1 also set at pc 0x4030f8. Catchpoint 2: `Program_Error' Ada exception handler (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x00000000004030f8 `Constraint_Error' Ada exception handler breakpoint already hit 1 time 2 breakpoint keep y 0x00000000004030f8 `Program_Error' Ada exception handler (gdb) c Continuing. Catchpoint 2, exception at 0x00000000004025a5 in foo () at foo.adb:33 33 when Program_Error => -- SPOT2 Then we finally add a global exception handling catchpoint for all exceptions type: (gdb) catch handle Note: breakpoints 1 and 2 also set at pc 0x4030f8. Catchpoint 3: all Ada exceptions handler (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x00000000004030f8 `Constraint_Error' Ada exception handler breakpoint already hit 1 time 2 breakpoint keep y 0x00000000004030f8 `Program_Error' Ada exception handler breakpoint already hit 1 time 3 breakpoint keep y 0x00000000004030f8 all Ada exceptions handler (gdb) c Continuing. Catchpoint 3, exception at 0x00000000004025f7 in foo () at foo.adb:42 42 when others => -- SPOT3 (gdb) In terms of implementation, these catchpoints are implemented using breakpoints inside known functions of the GNAT runtime. However, when we stop at these breakpoints, it would be confusing to the user to leave them there. This is why, after the catchpoint hit, we go up the stack automatically, and find the first "printable" frame, that is a frame that is not part of the GNAT runtime and that has debugging info (see ada_find_printable_frame). I already have a small testcase that tests the general functioning of these handler catchpoints. I will write some documentation, but I want to make sure that no one has any objection, that is, at least the user-interface is agreed on before I start this work. --------------E714F2A198CA19DC007A34CF Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="foo.adb" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="foo.adb" Content-length: 1554 LS0gIENvcHlyaWdodCAyMDE3IEZyZWUgU29mdHdhcmUgRm91bmRhdGlvbiwg SW5jLgotLQotLSAgVGhpcyBwcm9ncmFtIGlzIGZyZWUgc29mdHdhcmU7IHlv dSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vciBtb2RpZnkKLS0gIGl0IHVu ZGVyIHRoZSB0ZXJtcyBvZiB0aGUgR05VIEdlbmVyYWwgUHVibGljIExpY2Vu c2UgYXMgcHVibGlzaGVkIGJ5Ci0tICB0aGUgRnJlZSBTb2Z0d2FyZSBGb3Vu ZGF0aW9uOyBlaXRoZXIgdmVyc2lvbiAzIG9mIHRoZSBMaWNlbnNlLCBvcgot LSAgKGF0IHlvdXIgb3B0aW9uKSBhbnkgbGF0ZXIgdmVyc2lvbi4KLS0KLS0g IFRoaXMgcHJvZ3JhbSBpcyBkaXN0cmlidXRlZCBpbiB0aGUgaG9wZSB0aGF0 IGl0IHdpbGwgYmUgdXNlZnVsLAotLSAgYnV0IFdJVEhPVVQgQU5ZIFdBUlJB TlRZOyB3aXRob3V0IGV2ZW4gdGhlIGltcGxpZWQgd2FycmFudHkgb2YKLS0g IE1FUkNIQU5UQUJJTElUWSBvciBG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