Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Aleksandar Ristovski <aristovski@qnx.com>
To: gdb@sources.redhat.com
Subject: catch catch before program starts
Date: Tue, 29 Apr 2008 18:56:00 -0000	[thread overview]
Message-ID: <fv5dc5$51m$1@ger.gmane.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

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

[-- Attachment #2: breakpoint.c.catchatplt.diff --]
[-- Type: text/plain, Size: 2104 bytes --]

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);

             reply	other threads:[~2008-04-28 20:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-29 18:56 Aleksandar Ristovski [this message]
2008-04-29 18:58 ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='fv5dc5$51m$1@ger.gmane.org' \
    --to=aristovski@qnx.com \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox