RFA: patch to ignore C++ method conversion errors
nsd@cygnus.com
nsd@cygnus.com
Thu Mar 30 15:27:00 GMT 2000
Hi,
When GDB tries to handle a command like "call foo.method()", it walks
through foo's methods, calling check_stub_method() on each method until
finding one with the correct prototype.
check_stub_method() calls parse_and_eval_type(), which calls error() if it
encounters any surprises. As a result, "call foo.method()" can fail due
to problems with some other method in the same class.
For example, if a program containing the following is compiled with STABS
info and a non-debugging libstdc++:
#include <iostream>
class Foo {
public:
void method1(ostream *);
void method2();
} foo;
then "ostream" isn't present in the STABS symbol table, which makes "call
foo.method2()" fail with the following error:
No symbol "ostream" in current context.
Here's a simple fix which wraps the parse_and_eval_type() call within
catch_errors() and disables error messages during that call.
There are no regressions on sparc-sun-solaris2.5.1. It actually seems to
fix a pthreads regression; I haven't investigated why.
Okay to apply this, Dan?
Nick Duffek
nsd@cygnus.com
[patch follows]
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.6
diff -u -r1.6 gdbtypes.c
--- gdbtypes.c 2000/03/28 02:25:14 1.6
+++ gdbtypes.c 2000/03/29 20:00:39
@@ -1422,6 +1422,56 @@
#undef ADD_EXTRA
/* End of new code added to support parsing of Cfront stabs strings */
+/* safe_parse_type_stub() args and return val. */
+
+struct safe_parse_type_args
+ {
+ char *p;
+ int length;
+ struct type *type;
+ };
+
+/* catch_errors() stub for safe_parse_type(). */
+
+static int
+safe_parse_type_stub (void *argsv)
+{
+ struct safe_parse_type_args *args = (struct safe_parse_type_args *)argsv;
+ args->type = parse_and_eval_type (args->p, args->length);
+ return 1;
+}
+
+/* Restore context saved by safe_parse_type. */
+
+static void
+safe_parse_cleanup (void *gdb_stderrv)
+{
+ ui_file_delete (gdb_stderr);
+ gdb_stderr = (struct ui_file *)gdb_stderrv;
+}
+
+/* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
+ silently return builtin_type_void. */
+
+static struct type *
+safe_parse_type (char *p, int length)
+{
+ struct safe_parse_type_args args;
+ struct cleanup *cleanup;
+
+ args.p = p;
+ args.length = length;
+ cleanup = make_cleanup (safe_parse_cleanup, gdb_stderr);
+ gdb_stderr = ui_file_new ();
+
+ if (!catch_errors (safe_parse_type_stub, &args, "", RETURN_MASK_ERROR))
+ args.type = builtin_type_void;
+
+ do_cleanups (cleanup);
+
+ return args.type;
+}
+
/* Ugly hack to convert method stubs into method types.
He ain't kiddin'. This demangles the name of the method into a string
@@ -1496,7 +1546,7 @@
if (strncmp (argtypetext, "...", p - argtypetext) != 0)
{
argtypes[argcount] =
- parse_and_eval_type (argtypetext, p - argtypetext);
+ safe_parse_type (argtypetext, p - argtypetext);
argcount += 1;
}
argtypetext = p + 1;
More information about the Gdb-patches
mailing list