aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2013-10-30 11:18:24 +0100
committerJoel Brobecker <brobecker@adacore.com>2013-11-11 19:19:07 +0400
commit2df4d1d5c4393fd06c2bffe75499e70a8d8ac8a8 (patch)
treed7129814a8a20fde9eb916a1d693e7a78c844902 /gdb/mi
parent99c1d4518bf2ff230eaa6ee54c08e85f2d6c008e (diff)
downloadgdb-2df4d1d5c4393fd06c2bffe75499e70a8d8ac8a8.zip
gdb-2df4d1d5c4393fd06c2bffe75499e70a8d8ac8a8.tar.gz
gdb-2df4d1d5c4393fd06c2bffe75499e70a8d8ac8a8.tar.bz2
Dandling memory pointers in Ada catchpoints with GDB/MI.
When using the GDB/MI commands to insert a catchpoint on a specific Ada exception, any re-evaluation of that catchpoint (for instance a re-evaluation performed after a shared library got mapped by the inferior) fails. For instance, with any Ada program: (gdb) -catch-exception -e program_error ^done,bkptno="1",bkpt={[...]} (gdb) -exec-run =thread-group-started,id="i1",pid="28315" =thread-created,id="1",group-id="i1" ^running *running,thread-id="all" (gdb) =library-loaded,[...] &"warning: failed to reevaluate internal exception condition for catchpoint 1: No definition of \"exec\" in current context.\n" &"warning: failed to reevaluate internal exception condition for catchpoint 1: No definition of \"exec\" in current context.\n" [...] The same is true if using an Ada exception catchpoint. The problem comes from the fact that that we deallocate the strings given as arguments to create_ada_exception_catchpoint, while the latter just makes shallow copies of those strings, thus creating dandling pointers. This patch fixes the issue by passing freshly allocated strings to create_ada_exception_catchpoint, while at the same time updating create_ada_exception_catchpoint's documentation to make it clear that deallocating the strings is no longer the responsibility of the caller. gdb/ChangeLog: * ada-lang.c (create_ada_exception_catchpoint): Enhance the documentation of fields "except_string" and "condition". * mi/mi-cmd-catch.c (mi_cmd_catch_assert): Reallocate CONDITION on the heap before passing it to create_ada_exception_catchpoint. (mi_cmd_catch_exception): Likewise for EXCEPTION_NAME and CONDITION. gdb/testsuite/ChangeLog: * gdb.ada/mi_ex_cond: New testcase. Tested on x86_64-linux. The "-break-list" test FAILs without this patch.
Diffstat (limited to 'gdb/mi')
-rw-r--r--gdb/mi/mi-cmd-catch.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c
index 23e30d0..bcfc1ba 100644
--- a/gdb/mi/mi-cmd-catch.c
+++ b/gdb/mi/mi-cmd-catch.c
@@ -81,6 +81,10 @@ mi_cmd_catch_assert (char *cmd, char *argv[], int argc)
error (_("Invalid argument: %s"), argv[oind]);
setup_breakpoint_reporting ();
+ /* create_ada_exception_catchpoint needs CONDITION to be xstrdup'ed,
+ and will assume control of its lifetime. */
+ if (condition != NULL)
+ condition = xstrdup (condition);
create_ada_exception_catchpoint (gdbarch, ada_catch_assert,
NULL, condition, temp, enabled, 0);
}
@@ -154,6 +158,12 @@ mi_cmd_catch_exception (char *cmd, char *argv[], int argc)
error (_("\"-e\" and \"-u\" are mutually exclusive"));
setup_breakpoint_reporting ();
+ /* create_ada_exception_catchpoint needs EXCEPTION_NAME and CONDITION
+ to be xstrdup'ed, and will assume control of their lifetime. */
+ if (exception_name != NULL)
+ exception_name = xstrdup (exception_name);
+ if (condition != NULL)
+ condition = xstrdup (condition);
create_ada_exception_catchpoint (gdbarch, ex_kind,
exception_name, condition,
temp, enabled, 0);