[obv] Code cleanup: Move print_command_1 expr variable scope
Commit Message
gdb/ChangeLog
2015-03-26 Jan Kratochvil <jan.kratochvil@redhat.com>
Code cleanup.
* printcmd.c (print_command_1): Move expr variable scope.
---
gdb/ChangeLog | 5 +++++
gdb/printcmd.c | 3 ++-
2 files changed, 7 insertions(+), 1 deletion(-)
Comments
Hi Jan,
I think this patch is wrong. Starting with that commit (f30d5c7),
some tests (e.g. mi-break.exp) started to fail for me, because
of gdb segfaulting. Backtrace here: http://paste.ubuntu.com/10690836/
The address of expr is passed to the cleanup. When the cleanup is ran,
expr is no longer in scope, so what is at that address is probably not
safe to use anymore. That's my guess.
Simon
@@ -1,6 +1,11 @@
2015-03-26 Jan Kratochvil <jan.kratochvil@redhat.com>
Code cleanup.
+ * printcmd.c (print_command_1): Move expr variable scope.
+
+2015-03-26 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ Code cleanup.
* printcmd.c (validate_format): Make the parameter cmdname const.
2015-03-26 Don Breazeal <donb@codesourcery.com>
@@ -946,7 +946,6 @@ validate_format (struct format_data fmt, const char *cmdname)
static void
print_command_1 (const char *exp, int voidprint)
{
- struct expression *expr;
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
char format = 0;
struct value *val;
@@ -969,6 +968,8 @@ print_command_1 (const char *exp, int voidprint)
if (exp && *exp)
{
+ struct expression *expr;
+
expr = parse_expression (exp);
make_cleanup (free_current_contents, &expr);
val = evaluate_expression (expr);