This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: expressions with C preprocessor macro info
A Saturday 03 May 2008 21:27:44, Daniel Jacobowitz wrote:
> On Sat, May 03, 2008 at 09:19:27PM +0100, Pedro Alves wrote:
> > 2008-05-03 Pedro Alves <pedro@codesourcery.com>
> >
> > gdb/
> > * parse.c (parse_exp_in_context): Don't override
> > expression_context_pc if get_selected_block returned a valid block.
> >
> > gdb/testsuite/
> > * gdb.base/macscp.exp, gdb.base/macscp1.c: Add test for printing
> > expressions with macros.
>
> This patch is OK since it's clearly progress.
Thanks, I installed it -- better keep this regression fix separate
from follow up improvements.
> But doesn't this mean
> that we should be passing a PC to parse_exp_1, not a block? Otherwise
> macros will not be correct in e.g. breakpoint conditions:
>
> loc->cond =
> parse_exp_1 (&arg, block_for_pc (loc->address), 0);
Yes, looks like it. At some point, it may even be better to get rid
of expression_context_block in the language parsers, in favor of
expression_context_pc for variables declared midblock, I guess:
{
a = 1;
f ();
B b;
g ();
}
I'll submit a patch to the insight side if the attached is OK. Tested
on x86_64-unknown-linux-gnu.
--
Pedro Alves
2008-05-03 Pedro Alves <pedro@codesourcery.com>
* expression.h (parse_exp_1): Take a context PC instead of a
context block.
* parse.c (parse_exp_1): Adjust.
(parse_exp_in_context): Take a context PC instead of a context
block. If valid PC is passed, get the context block from it.
(parse_expression): Adjust to the new signature of parse_exp_1.
* ada-lang.c (ada_parse_catchpoint_condition): Likewise.
* breakpoint.c (condition_command, update_watchpoint): Likewise.
* eval.c (parse_and_eval_address_1, parse_to_comma_and_eval):
Likewise.
* tracepoint.c (validate_actionline, encode_actions): Likewise.
* varobj.c (varobj_create, varobj_set_value): Likewise.
* wrapper.h (gdb_parse_exp_1): Take a context PC instead of a
context block.
* wrapper.c (gdb_parse_exp_1): Adjust to the new signature of
parse_exp_1.
---
gdb/ada-lang.c | 2 +-
gdb/breakpoint.c | 24 +++++++++++++++---------
gdb/eval.c | 4 ++--
gdb/expression.h | 2 +-
gdb/parse.c | 49 +++++++++++++++++++++++++------------------------
gdb/tracepoint.c | 5 ++---
gdb/varobj.c | 11 ++++++-----
gdb/wrapper.c | 4 ++--
gdb/wrapper.h | 2 +-
9 files changed, 55 insertions(+), 48 deletions(-)
Index: src/gdb/expression.h
===================================================================
--- src.orig/gdb/expression.h 2008-05-03 23:17:27.000000000 +0100
+++ src/gdb/expression.h 2008-05-03 23:23:41.000000000 +0100
@@ -389,7 +389,7 @@ struct expression
extern struct expression *parse_expression (char *);
-extern struct expression *parse_exp_1 (char **, struct block *, int);
+extern struct expression *parse_exp_1 (char **, CORE_ADDR, int);
/* The innermost context required by the stack and register variables
we've encountered so far. To use this, set it to NULL, then call
Index: src/gdb/parse.c
===================================================================
--- src.orig/gdb/parse.c 2008-05-03 23:23:39.000000000 +0100
+++ src/gdb/parse.c 2008-05-03 23:23:41.000000000 +0100
@@ -105,8 +105,7 @@ static void prefixify_expression (struct
static void prefixify_subexp (struct expression *, struct expression *, int,
int);
-static struct expression *parse_exp_in_context (char **, struct block *, int,
- int);
+static struct expression *parse_exp_in_context (char **, CORE_ADDR, int, int);
void _initialize_parse (void);
@@ -924,8 +923,8 @@ prefixify_subexp (struct expression *ine
/* Read an expression from the string *STRINGPTR points to,
parse it, and return a pointer to a struct expression that we malloc.
- Use block BLOCK as the lexical context for variable names;
- if BLOCK is zero, use the block of the selected stack frame.
+ Use CONTEXT_PC to get the lexical context for variable names;
+ if CONTEXT_PC is -1, use the block of the selected stack frame.
Meanwhile, advance *STRINGPTR to point after the expression,
at the first nonwhite character that is not part of the expression
(possibly a null character).
@@ -933,16 +932,16 @@ prefixify_subexp (struct expression *ine
If COMMA is nonzero, stop if a comma is reached. */
struct expression *
-parse_exp_1 (char **stringptr, struct block *block, int comma)
+parse_exp_1 (char **stringptr, CORE_ADDR context_pc, int comma)
{
- return parse_exp_in_context (stringptr, block, comma, 0);
+ return parse_exp_in_context (stringptr, context_pc, comma, 0);
}
/* As for parse_exp_1, except that if VOID_CONTEXT_P, then
no value is expected from the expression. */
static struct expression *
-parse_exp_in_context (char **stringptr, struct block *block, int comma,
+parse_exp_in_context (char **stringptr, CORE_ADDR context_pc, int comma,
int void_context_p)
{
struct cleanup *old_chain;
@@ -961,24 +960,26 @@ parse_exp_in_context (char **stringptr,
old_chain = make_cleanup (free_funcalls, 0 /*ignore*/);
funcall_chain = 0;
- expression_context_block = block;
-
- /* If no context specified, try using the current frame, if any. */
- if (!expression_context_block)
- expression_context_block = get_selected_block (&expression_context_pc);
+ if (context_pc != ~(CORE_ADDR) 0)
+ {
+ expression_context_block = block_for_pc (context_pc);
+ expression_context_pc = context_pc;
+ }
else
- expression_context_pc = BLOCK_START (expression_context_block);
-
- /* Fall back to using the current source static context, if any. */
-
- if (!expression_context_block)
{
- struct symtab_and_line cursal = get_current_source_symtab_and_line ();
- if (cursal.symtab)
- expression_context_block
- = BLOCKVECTOR_BLOCK (BLOCKVECTOR (cursal.symtab), STATIC_BLOCK);
- if (expression_context_block)
- expression_context_pc = BLOCK_START (expression_context_block);
+ /* If no context specified, try using the current frame, if any. */
+ expression_context_block = get_selected_block (&expression_context_pc);
+
+ /* Fall back to using the current source static context, if any. */
+ if (!expression_context_block)
+ {
+ struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+ if (cursal.symtab)
+ expression_context_block
+ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (cursal.symtab), STATIC_BLOCK);
+ if (expression_context_block)
+ expression_context_pc = BLOCK_START (expression_context_block);
+ }
}
expout_size = 10;
@@ -1027,7 +1028,7 @@ struct expression *
parse_expression (char *string)
{
struct expression *exp;
- exp = parse_exp_1 (&string, 0, 0);
+ exp = parse_exp_1 (&string, ~(CORE_ADDR) 0, 0);
if (*string)
error (_("Junk after end of expression."));
return exp;
Index: src/gdb/ada-lang.c
===================================================================
--- src.orig/gdb/ada-lang.c 2008-05-03 23:17:27.000000000 +0100
+++ src/gdb/ada-lang.c 2008-05-03 23:23:41.000000000 +0100
@@ -10402,7 +10402,7 @@ static struct expression *
ada_parse_catchpoint_condition (char *cond_string,
struct symtab_and_line sal)
{
- return (parse_exp_1 (&cond_string, block_for_pc (sal.pc), 0));
+ return (parse_exp_1 (&cond_string, sal.pc, 0));
}
/* Return the symtab_and_line that should be used to insert an exception
Index: src/gdb/breakpoint.c
===================================================================
--- src.orig/gdb/breakpoint.c 2008-05-03 23:23:15.000000000 +0100
+++ src/gdb/breakpoint.c 2008-05-03 23:23:41.000000000 +0100
@@ -617,7 +617,7 @@ condition_command (char *arg, int from_t
{
arg = p;
loc->cond =
- parse_exp_1 (&arg, block_for_pc (loc->address), 0);
+ parse_exp_1 (&arg, loc->address, 0);
if (*arg)
error (_("Junk at end of expression"));
}
@@ -910,13 +910,17 @@ update_watchpoint (struct breakpoint *b,
if (within_current_scope && reparse)
{
char *s;
+ CORE_ADDR context_pc = ~(CORE_ADDR) 0;
+
if (b->exp)
{
xfree (b->exp);
b->exp = NULL;
}
s = b->exp_string;
- b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
+ if (b->exp_valid_block)
+ context_pc = BLOCK_START (b->exp_valid_block);
+ b->exp = parse_exp_1 (&s, context_pc, 0);
/* If the meaning of expression itself changed, the old value is
no longer relevant. We don't want to report a watchpoint hit
to the user when the old value and the new value may actually
@@ -1001,7 +1005,10 @@ update_watchpoint (struct breakpoint *b,
if (b->cond_string != NULL)
{
char *s = b->cond_string;
- b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
+ CORE_ADDR context_pc = ~(CORE_ADDR) 0;
+ if (b->exp_valid_block)
+ context_pc = BLOCK_START (b->exp_valid_block);
+ b->loc->cond = parse_exp_1 (&s, context_pc, 0);
}
}
else if (!within_current_scope)
@@ -5111,7 +5118,7 @@ create_breakpoint (struct symtabs_and_li
if (b->cond_string)
{
char *arg = b->cond_string;
- loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
+ loc->cond = parse_exp_1 (&arg, loc->address, 0);
if (*arg)
error (_("Garbage %s follows condition"), arg);
}
@@ -5410,7 +5417,7 @@ find_condition_and_thread (char *tok, CO
if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
{
tok = cond_start = end_tok + 1;
- parse_exp_1 (&tok, block_for_pc (pc), 0);
+ parse_exp_1 (&tok, pc, 0);
cond_end = tok;
*cond_string = savestring (cond_start,
cond_end - cond_start);
@@ -5916,7 +5923,7 @@ watch_command_1 (char *arg, int accessfl
/* Parse the rest of the arguments. */
innermost_block = NULL;
exp_start = arg;
- exp = parse_exp_1 (&arg, 0, 0);
+ exp = parse_exp_1 (&arg, ~(CORE_ADDR) 0, 0);
exp_end = arg;
exp_valid_block = innermost_block;
mark = value_mark ();
@@ -5936,7 +5943,7 @@ watch_command_1 (char *arg, int accessfl
if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
{
tok = cond_start = end_tok + 1;
- cond = parse_exp_1 (&tok, 0, 0);
+ cond = parse_exp_1 (&tok, ~(CORE_ADDR) 0, 0);
cond_end = tok;
}
if (*tok)
@@ -7326,8 +7333,7 @@ update_breakpoint_locations (struct brea
s = b->cond_string;
TRY_CATCH (e, RETURN_MASK_ERROR)
{
- new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
- 0);
+ new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, 0);
}
if (e.reason < 0)
{
Index: src/gdb/eval.c
===================================================================
--- src.orig/gdb/eval.c 2008-05-03 23:17:27.000000000 +0100
+++ src/gdb/eval.c 2008-05-03 23:23:41.000000000 +0100
@@ -98,7 +98,7 @@ parse_and_eval_address (char *exp)
CORE_ADDR
parse_and_eval_address_1 (char **expptr)
{
- struct expression *expr = parse_exp_1 (expptr, (struct block *) 0, 0);
+ struct expression *expr = parse_exp_1 (expptr, ~(CORE_ADDR) 0, 0);
CORE_ADDR addr;
struct cleanup *old_chain =
make_cleanup (free_current_contents, &expr);
@@ -143,7 +143,7 @@ parse_and_eval (char *exp)
struct value *
parse_to_comma_and_eval (char **expp)
{
- struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1);
+ struct expression *expr = parse_exp_1 (expp, ~(CORE_ADDR) 0, 1);
struct value *val;
struct cleanup *old_chain =
make_cleanup (free_current_contents, &expr);
Index: src/gdb/tracepoint.c
===================================================================
--- src.orig/gdb/tracepoint.c 2008-05-03 23:17:27.000000000 +0100
+++ src/gdb/tracepoint.c 2008-05-03 23:23:41.000000000 +0100
@@ -973,7 +973,7 @@ validate_actionline (char **line, struct
}
/* else fall thru, treat p as an expression and parse it! */
}
- exp = parse_exp_1 (&p, block_for_pc (t->address), 1);
+ exp = parse_exp_1 (&p, t->address, 1);
old_chain = make_cleanup (free_current_contents, &exp);
if (exp->elts[0].opcode == OP_VAR_VALUE)
@@ -1600,8 +1600,7 @@ encode_actions (struct tracepoint *t, ch
struct cleanup *old_chain1 = NULL;
struct agent_reqs areqs;
- exp = parse_exp_1 (&action_exp,
- block_for_pc (t->address), 1);
+ exp = parse_exp_1 (&action_exp, t->address, 1);
old_chain = make_cleanup (free_current_contents, &exp);
switch (exp->elts[0].opcode)
Index: src/gdb/varobj.c
===================================================================
--- src.orig/gdb/varobj.c 2008-05-03 23:17:27.000000000 +0100
+++ src/gdb/varobj.c 2008-05-03 23:23:41.000000000 +0100
@@ -447,7 +447,6 @@ varobj_create (char *objname,
struct varobj *var;
struct frame_info *fi;
struct frame_info *old_fi = NULL;
- struct block *block;
struct cleanup *old_chain;
/* Fill out a varobj structure for the (root) variable being constructed. */
@@ -460,6 +459,7 @@ varobj_create (char *objname,
enum varobj_languages lang;
struct value *value = NULL;
int expr_len;
+ CORE_ADDR context_pc;
/* Parse and evaluate the expression, filling in as much
of the variable's data as possible */
@@ -480,15 +480,16 @@ varobj_create (char *objname,
if (type == USE_SELECTED_FRAME)
var->root->floating = 1;
- block = NULL;
if (fi != NULL)
- block = get_frame_block (fi, 0);
+ context_pc = get_frame_pc (fi);
+ else
+ context_pc = ~(CORE_ADDR) 0;
p = expression;
innermost_block = NULL;
/* Wrap the call to parse expression, so we can
return a sensible error. */
- if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp))
+ if (!gdb_parse_exp_1 (&p, context_pc, 0, &var->root->exp))
{
return NULL;
}
@@ -898,7 +899,7 @@ varobj_set_value (struct varobj *var, ch
gdb_assert (varobj_editable_p (var));
input_radix = 10; /* ALWAYS reset to decimal temporarily */
- exp = parse_exp_1 (&s, 0, 0);
+ exp = parse_exp_1 (&s, ~(CORE_ADDR) 0, 0);
if (!gdb_evaluate_expression (exp, &value))
{
/* We cannot proceed without a valid expression. */
Index: src/gdb/wrapper.h
===================================================================
--- src.orig/gdb/wrapper.h 2008-05-03 23:17:27.000000000 +0100
+++ src/gdb/wrapper.h 2008-05-03 23:23:41.000000000 +0100
@@ -24,7 +24,7 @@ struct value;
struct expression;
struct block;
-extern int gdb_parse_exp_1 (char **, struct block *,
+extern int gdb_parse_exp_1 (char **, CORE_ADDR,
int, struct expression **);
extern int gdb_evaluate_expression (struct expression *, struct value **);
Index: src/gdb/wrapper.c
===================================================================
--- src.orig/gdb/wrapper.c 2008-05-03 23:17:27.000000000 +0100
+++ src/gdb/wrapper.c 2008-05-03 23:23:41.000000000 +0100
@@ -22,14 +22,14 @@
#include "ui-out.h"
int
-gdb_parse_exp_1 (char **stringptr, struct block *block, int comma,
+gdb_parse_exp_1 (char **stringptr, CORE_ADDR context_pc, int comma,
struct expression **expression)
{
volatile struct gdb_exception except;
TRY_CATCH (except, RETURN_MASK_ERROR)
{
- *expression = parse_exp_1 (stringptr, block, comma);
+ *expression = parse_exp_1 (stringptr, context_pc, comma);
}
if (except.reason < 0)