From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5614 invoked by alias); 28 Apr 2008 20:51:57 -0000 Received: (qmail 5601 invoked by uid 22791); 28 Apr 2008 20:51:56 -0000 X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 28 Apr 2008 20:51:32 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JqaJp-0006mQ-La for gdb@sources.redhat.com; Mon, 28 Apr 2008 20:51:25 +0000 Received: from mobius.qnx.com ([209.226.137.108]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Apr 2008 20:51:25 +0000 Received: from aristovski by mobius.qnx.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Apr 2008 20:51:25 +0000 To: gdb@sources.redhat.com From: Aleksandar Ristovski Subject: catch catch before program starts Date: Tue, 29 Apr 2008 18:56:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000804060707040303080905" User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-04/txt/msg00247.txt.bz2 This is a multi-part message in MIME format. --------------000804060707040303080905 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 829 Hello, When we first load symbols, we can not set "catch catch" or "catch throw". The error message will say "Function __cxa_... not defined". However, we can set a breakpoint in .plt section. The attached patch illustrates this (it is not finished as there will be some error messages even though the catch will be set). The idea is to try __cxa_begin_catch and then, failing that, to try with __cxa_begin_catch@plt. Now: (gdb) catch catch Function "__cxa_begin_catch" not defined. (gdb) After patch: (gdb) file /tmp/sig/main Reading symbols from /tmp/sig/main...done. (gdb) catch catch Oops...Function "__cxa_begin_catch" not defined. Catchpoint 1 (catch) (gdb) catch throw Oops...Function "__cxa_throw" not defined. Catchpoint 2 (throw) (Ignore the "Oops" part). Comments? Aleksandar Ristovski QNX Software Systems --------------000804060707040303080905 Content-Type: text/plain; name="breakpoint.c.catchatplt.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="breakpoint.c.catchatplt.diff" Content-length: 2104 Index: gdb/breakpoint.c =================================================================== RCS file: /cvs/src/src/gdb/breakpoint.c,v retrieving revision 1.316 diff -u -p -r1.316 breakpoint.c --- gdb/breakpoint.c 26 Apr 2008 05:43:45 -0000 1.316 +++ gdb/breakpoint.c 28 Apr 2008 20:43:44 -0000 @@ -6561,6 +6566,19 @@ static struct breakpoint_ops gnu_v3_exce print_mention_exception_catchpoint }; +struct decode_line_args +{ + char **argptr; + struct symtabs_and_lines *sals; +}; + +static int decode_line_no_exceptions (void *arg) +{ + struct decode_line_args *dlargs = arg; + *dlargs->sals = decode_line_1 (dlargs->argptr, 1, NULL, 0, NULL, NULL); + return 0; +} + static int handle_gnu_v3_exceptions (int tempflag, char *cond_string, enum exception_event_kind ex_event, int from_tty) @@ -6568,18 +6586,39 @@ handle_gnu_v3_exceptions (int tempflag, char *trigger_func_name, *nameptr; struct symtabs_and_lines sals; struct breakpoint *b; + struct decode_line_args dummy; + + sals.nelts = 0; if (ex_event == EX_EVENT_CATCH) trigger_func_name = xstrdup ("__cxa_begin_catch"); - else + else if (ex_event == EX_EVENT_THROW) trigger_func_name = xstrdup ("__cxa_throw"); + else + trigger_func_name = NULL; nameptr = trigger_func_name; - sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL); + dummy.argptr = &nameptr; + dummy.sals = &sals; + catch_errors (decode_line_no_exceptions, &dummy, "Oops...", RETURN_MASK_ERROR); if (sals.nelts == 0) { + /* Try setting the breakpoint in trampoline. */ xfree (trigger_func_name); - return 0; + + if (ex_event == EX_EVENT_CATCH) + trigger_func_name = xstrdup ("\"'__cxa_begin_catch@plt'\""); + else if (ex_event == EX_EVENT_THROW) + trigger_func_name = xstrdup ("\"'__cxa_throw@plt'\""); + + nameptr = trigger_func_name; + catch_errors (decode_line_no_exceptions, + &dummy, "No go.", RETURN_MASK_ERROR); + if (sals.nelts == 0) + { + xfree (trigger_func_name); + return 0; + } } b = set_raw_breakpoint (sals.sals[0], bp_breakpoint); --------------000804060707040303080905--