This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA] SEGV during AX eval of OP_DOUBLE (unsupported)
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Cc: Joel Brobecker <brobecker at adacore dot com>
- Date: Fri, 16 Mar 2012 16:26:25 -0700
- Subject: [RFA] SEGV during AX eval of OP_DOUBLE (unsupported)
Hello again,
This is the problem I metioned I was investigating in:
RFC: merge std-operator.def and ada-operator.def?
http://www.sourceware.org/ml/gdb-patches/2012-03/msg00641.html
To reproduce the problem, simply try the following with any program:
(gdb) maintenance agent-eval 1.0
Critical error handler: process [...] terminated due to access violation
(this is on Windows; on GNU/Linux, the libc copes better)
I noticed this problem while debugging on Windows using GDBserver.
I had a conditional breakpoint where the AX agent wasn't able to
convert the expression into bytecode. But instead of recovering
nicely, GDB crashed.
The problem is quite simple: gen_expr is given an expression that
contains an unrecognized operator (OP_DOUBLE in this case). When that
happens, it tries to report an error with a string image of the operator
in the error message. Conversion of the opcode into a string is done
using op_string which, despite its name, probably is not what the author
was looking for. This function returns NULL for a lot of the opcodes,
thus triggering the crash.
There is a function that corresponds to what we are looking for:
expprint.c:op_name. It was static, though, so I made it non-static,
and used it from ax-gdb.c:gen_expr.
gdb/ChangeLog:
* expression.h (op_name): Add declaration.
* expprint.c (op_name): Remove declaration. Make non-static.
* ax-gdb.c (gen_expr): Use op_name instead of op_string.
Tested on x86_64-linux. OK?
---
gdb/ax-gdb.c | 2 +-
gdb/expprint.c | 3 +--
gdb/expression.h | 2 ++
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index a76e781..aaefed6 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2217,7 +2217,7 @@ gen_expr (struct expression *exp, union exp_element **pc,
default:
error (_("Unsupported operator %s (%d) in expression."),
- op_string (op), op);
+ op_name (exp, op), op);
}
}
diff --git a/gdb/expprint.c b/gdb/expprint.c
index d9d9b8f..fd1fccb 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -647,12 +647,11 @@ op_string (enum exp_opcode op)
/* Support for dumping the raw data from expressions in a human readable
form. */
-static char *op_name (struct expression *, enum exp_opcode);
static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
/* Name for OPCODE, when it appears in expression EXP. */
-static char *
+char *
op_name (struct expression *exp, enum exp_opcode opcode)
{
return exp->language_defn->la_exp_desc->op_name (opcode);
diff --git a/gdb/expression.h b/gdb/expression.h
index be26002..ace58f2 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -137,6 +137,8 @@ extern struct value *evaluate_subexp_standard
extern void print_expression (struct expression *, struct ui_file *);
+extern char *op_name (struct expression *exp, enum exp_opcode opcode);
+
extern char *op_string (enum exp_opcode);
extern void dump_raw_expression (struct expression *,
--
1.7.1