From 18ec983167982fde21392b3be307aaf15fd12c0d Mon Sep 17 00:00:00 2001 From: Kevin Buettner Date: Wed, 14 May 2003 22:45:41 +0000 Subject: [PATCH] * dwarf2expr.c (new_dwarf_expr_context): Set ``stack_len'' to correctly indicate an empty stack and ``stack_allocated'' to the indicate the number of elements initially allocated. (dwarf_expr_grow_stack): Simplify method for computing new stack size. Don't loop infinitely if ``stack_len'' is zero. (execute_stack_op): Move ``ctx->in_reg'' initialization out of loop. Allow DW_OP_reg0 ... DW_OP_reg31 and DW_OP_regx to be used in conjuction with DW_OP_piece. Revise error message accordingly. --- gdb/ChangeLog | 12 ++++++++++++ gdb/dwarf2expr.c | 26 ++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8f9f0b00b69..a62ecd3a369 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2003-05-14 Kevin Buettner + + * dwarf2expr.c (new_dwarf_expr_context): Set ``stack_len'' to + correctly indicate an empty stack and ``stack_allocated'' to the + indicate the number of elements initially allocated. + (dwarf_expr_grow_stack): Simplify method for computing new + stack size. Don't loop infinitely if ``stack_len'' is zero. + (execute_stack_op): Move ``ctx->in_reg'' initialization + out of loop. Allow DW_OP_reg0 ... DW_OP_reg31 and DW_OP_regx to + be used in conjuction with DW_OP_piece. Revise error message + accordingly. + 2003-05-14 Theodore A. Roth * MAINTAINERS: Update my email address. diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c index 35e76f3cd40..410cd54c622 100644 --- a/gdb/dwarf2expr.c +++ b/gdb/dwarf2expr.c @@ -39,8 +39,9 @@ new_dwarf_expr_context (void) { struct dwarf_expr_context *retval; retval = xcalloc (1, sizeof (struct dwarf_expr_context)); - retval->stack_len = 10; - retval->stack = xmalloc (10 * sizeof (CORE_ADDR)); + retval->stack_len = 0; + retval->stack_allocated = 10; + retval->stack = xmalloc (retval->stack_allocated * sizeof (CORE_ADDR)); return retval; } @@ -61,12 +62,10 @@ dwarf_expr_grow_stack (struct dwarf_expr_context *ctx, size_t need) { if (ctx->stack_len + need > ctx->stack_allocated) { - size_t templen = ctx->stack_len * 2; - while (templen < (ctx->stack_len + need)) - templen *= 2; + size_t newlen = ctx->stack_len + need + 10; ctx->stack = xrealloc (ctx->stack, - templen * sizeof (CORE_ADDR)); - ctx->stack_allocated = templen; + newlen * sizeof (CORE_ADDR)); + ctx->stack_allocated = newlen; } } @@ -228,6 +227,8 @@ static void execute_stack_op (struct dwarf_expr_context *ctx, unsigned char *op_ptr, unsigned char *op_end) { + ctx->in_reg = 0; + while (op_ptr < op_end) { enum dwarf_location_atom op = *op_ptr++; @@ -236,8 +237,6 @@ execute_stack_op (struct dwarf_expr_context *ctx, unsigned char *op_ptr, LONGEST offset; int bytes_read; - ctx->in_reg = 0; - switch (op) { case DW_OP_lit0: @@ -355,10 +354,9 @@ execute_stack_op (struct dwarf_expr_context *ctx, unsigned char *op_ptr, case DW_OP_reg29: case DW_OP_reg30: case DW_OP_reg31: - /* NOTE: in the presence of DW_OP_piece this check is incorrect. */ - if (op_ptr != op_end) + if (op_ptr != op_end && *op_ptr != DW_OP_piece) error ("DWARF-2 expression error: DW_OP_reg operations must be " - "used alone."); + "used either alone or in conjuction with DW_OP_piece."); result = op - DW_OP_reg0; ctx->in_reg = 1; @@ -367,9 +365,9 @@ execute_stack_op (struct dwarf_expr_context *ctx, unsigned char *op_ptr, case DW_OP_regx: op_ptr = read_uleb128 (op_ptr, op_end, ®); - if (op_ptr != op_end) + if (op_ptr != op_end && *op_ptr != DW_OP_piece) error ("DWARF-2 expression error: DW_OP_reg operations must be " - "used alone."); + "used either alone or in conjuction with DW_OP_piece."); result = reg; ctx->in_reg = 1; -- 2.30.2