diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2011-07-15 20:54:32 +0000 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2011-07-15 20:54:32 +0000 |
commit | 9e8b7a03dd9c4754ff3f18ca13a1dad851f4ec58 (patch) | |
tree | 7df265b8f00f013025d31216b505e3e2fe7a21b8 /gdb | |
parent | e9ea266294fcba2548c9b30d8229b1b430d45eee (diff) | |
download | fsf-binutils-gdb-9e8b7a03dd9c4754ff3f18ca13a1dad851f4ec58.zip fsf-binutils-gdb-9e8b7a03dd9c4754ff3f18ca13a1dad851f4ec58.tar.gz fsf-binutils-gdb-9e8b7a03dd9c4754ff3f18ca13a1dad851f4ec58.tar.bz2 |
gdb/
Code cleanup.
* dwarf2-frame.c (dwarf2_frame_ctx_funcs): New.
(execute_stack_op): Use dwarf2_frame_ctx_funcs
* dwarf2expr.c (dwarf_get_base_type): Access get_base_type via funcs.
(execute_stack_op): Access read_reg, get_frame_base, read_mem,
get_frame_cfa, get_tls_address and dwarf_call via funcs.
* dwarf2expr.h (struct dwarf_expr_context): New forward declaration.
(struct dwarf_expr_context_funcs): New, move here methods from ...
(struct dwarf_expr_context): ... here. New fields funcs.
* dwarf2loc.c (dwarf_expr_dwarf_call): Access get_frame_pc via funcs.
(dwarf_expr_ctx_funcs): New.
(dwarf2_evaluate_loc_desc_full): Use dwarf_expr_ctx_funcs.
(needs_frame_dwarf_call): Access get_frame_pc via funcs.
(needs_frame_ctx_funcs): New.
(dwarf2_loc_desc_needs_frame): Use needs_frame_ctx_funcs.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 18 | ||||
-rw-r--r-- | gdb/dwarf2-frame.c | 23 | ||||
-rw-r--r-- | gdb/dwarf2expr.c | 27 | ||||
-rw-r--r-- | gdb/dwarf2expr.h | 88 | ||||
-rw-r--r-- | gdb/dwarf2loc.c | 49 |
5 files changed, 127 insertions, 78 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 787ce79..b5bb858 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,21 @@ +2011-07-15 Jan Kratochvil <jan.kratochvil@redhat.com> + + Code cleanup. + * dwarf2-frame.c (dwarf2_frame_ctx_funcs): New. + (execute_stack_op): Use dwarf2_frame_ctx_funcs + * dwarf2expr.c (dwarf_get_base_type): Access get_base_type via funcs. + (execute_stack_op): Access read_reg, get_frame_base, read_mem, + get_frame_cfa, get_tls_address and dwarf_call via funcs. + * dwarf2expr.h (struct dwarf_expr_context): New forward declaration. + (struct dwarf_expr_context_funcs): New, move here methods from ... + (struct dwarf_expr_context): ... here. New fields funcs. + * dwarf2loc.c (dwarf_expr_dwarf_call): Access get_frame_pc via funcs. + (dwarf_expr_ctx_funcs): New. + (dwarf2_evaluate_loc_desc_full): Use dwarf_expr_ctx_funcs. + (needs_frame_dwarf_call): Access get_frame_pc via funcs. + (needs_frame_ctx_funcs): New. + (dwarf2_loc_desc_needs_frame): Use needs_frame_ctx_funcs. + 2011-07-15 Fawzi Mohamed <fawzi.mohamed@nokia.com> * MAINTAINERS (Write After Approval): Add myself to the list. diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index 4791592..3d031f3 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -391,6 +391,20 @@ register %s (#%d) at %s"), paddress (gdbarch, fs->pc)); } +/* Virtual method table for execute_stack_op below. */ + +static const struct dwarf_expr_context_funcs dwarf2_frame_ctx_funcs = +{ + read_reg, + read_mem, + no_get_frame_base, + no_get_frame_cfa, + no_get_frame_pc, + no_get_tls_address, + no_dwarf_call, + no_base_type +}; + static CORE_ADDR execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size, CORE_ADDR offset, struct frame_info *this_frame, @@ -408,14 +422,7 @@ execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size, ctx->addr_size = addr_size; ctx->offset = offset; ctx->baton = this_frame; - ctx->read_reg = read_reg; - ctx->read_mem = read_mem; - ctx->get_frame_base = no_get_frame_base; - ctx->get_frame_cfa = no_get_frame_cfa; - ctx->get_frame_pc = no_get_frame_pc; - ctx->get_tls_address = no_get_tls_address; - ctx->dwarf_call = no_dwarf_call; - ctx->get_base_type = no_base_type; + ctx->funcs = &dwarf2_frame_ctx_funcs; dwarf_expr_push_address (ctx, initial, initial_in_stack_memory); dwarf_expr_eval (ctx, exp, len); diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c index 21a8363..efa497e 100644 --- a/gdb/dwarf2expr.c +++ b/gdb/dwarf2expr.c @@ -466,9 +466,9 @@ dwarf_get_base_type (struct dwarf_expr_context *ctx, ULONGEST die, int size) { struct type *result; - if (ctx->get_base_type) + if (ctx->funcs->get_base_type) { - result = ctx->get_base_type (ctx, die); + result = ctx->funcs->get_base_type (ctx, die); if (result == NULL) error (_("Could not find type for DW_OP_GNU_const_type")); if (size != 0 && TYPE_LENGTH (result) != size) @@ -759,7 +759,7 @@ execute_stack_op (struct dwarf_expr_context *ctx, case DW_OP_breg31: { op_ptr = read_sleb128 (op_ptr, op_end, &offset); - result = (ctx->read_reg) (ctx->baton, op - DW_OP_breg0); + result = (ctx->funcs->read_reg) (ctx->baton, op - DW_OP_breg0); result += offset; result_val = value_from_ulongest (address_type, result); } @@ -768,7 +768,7 @@ execute_stack_op (struct dwarf_expr_context *ctx, { op_ptr = read_uleb128 (op_ptr, op_end, ®); op_ptr = read_sleb128 (op_ptr, op_end, &offset); - result = (ctx->read_reg) (ctx->baton, reg); + result = (ctx->funcs->read_reg) (ctx->baton, reg); result += offset; result_val = value_from_ulongest (address_type, result); } @@ -788,14 +788,13 @@ execute_stack_op (struct dwarf_expr_context *ctx, /* FIXME: cagney/2003-03-26: This code should be using get_frame_base_address(), and then implement a dwarf2 specific this_base method. */ - (ctx->get_frame_base) (ctx->baton, &datastart, &datalen); + (ctx->funcs->get_frame_base) (ctx->baton, &datastart, &datalen); dwarf_expr_eval (ctx, datastart, datalen); if (ctx->location == DWARF_VALUE_MEMORY) result = dwarf_expr_fetch_address (ctx, 0); else if (ctx->location == DWARF_VALUE_REGISTER) - result - = (ctx->read_reg) (ctx->baton, - value_as_long (dwarf_expr_fetch (ctx, 0))); + result = (ctx->funcs->read_reg) (ctx->baton, + value_as_long (dwarf_expr_fetch (ctx, 0))); else error (_("Not implemented: computing frame " "base using explicit value operator")); @@ -880,7 +879,7 @@ execute_stack_op (struct dwarf_expr_context *ctx, else type = address_type; - (ctx->read_mem) (ctx->baton, buf, addr, addr_size); + (ctx->funcs->read_mem) (ctx->baton, buf, addr, addr_size); /* If the size of the object read from memory is different from the type length, we need to zero-extend it. */ @@ -1089,7 +1088,7 @@ execute_stack_op (struct dwarf_expr_context *ctx, break; case DW_OP_call_frame_cfa: - result = (ctx->get_frame_cfa) (ctx->baton); + result = (ctx->funcs->get_frame_cfa) (ctx->baton); result_val = value_from_ulongest (address_type, result); in_stack_memory = 1; break; @@ -1105,7 +1104,7 @@ execute_stack_op (struct dwarf_expr_context *ctx, returned. */ result = value_as_long (dwarf_expr_fetch (ctx, 0)); dwarf_expr_pop (ctx); - result = (ctx->get_tls_address) (ctx->baton, result); + result = (ctx->funcs->get_tls_address) (ctx->baton, result); result_val = value_from_ulongest (address_type, result); break; @@ -1178,13 +1177,13 @@ execute_stack_op (struct dwarf_expr_context *ctx, case DW_OP_call2: result = extract_unsigned_integer (op_ptr, 2, byte_order); op_ptr += 2; - ctx->dwarf_call (ctx, result); + ctx->funcs->dwarf_call (ctx, result); goto no_push; case DW_OP_call4: result = extract_unsigned_integer (op_ptr, 4, byte_order); op_ptr += 4; - ctx->dwarf_call (ctx, result); + ctx->funcs->dwarf_call (ctx, result); goto no_push; case DW_OP_GNU_entry_value: @@ -1220,7 +1219,7 @@ execute_stack_op (struct dwarf_expr_context *ctx, op_ptr = read_uleb128 (op_ptr, op_end, &type_die); type = dwarf_get_base_type (ctx, type_die, 0); - result = (ctx->read_reg) (ctx->baton, reg); + result = (ctx->funcs->read_reg) (ctx->baton, reg); result_val = value_from_ulongest (address_type, result); result_val = value_from_contents (type, value_contents_all (result_val)); diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h index 676b54b..987f295 100644 --- a/gdb/dwarf2expr.h +++ b/gdb/dwarf2expr.h @@ -23,6 +23,53 @@ #if !defined (DWARF2EXPR_H) #define DWARF2EXPR_H +struct dwarf_expr_context; + +/* Virtual method table for struct dwarf_expr_context below. */ + +struct dwarf_expr_context_funcs +{ + /* Return the value of register number REGNUM. */ + CORE_ADDR (*read_reg) (void *baton, int regnum); + + /* Read LENGTH bytes at ADDR into BUF. */ + void (*read_mem) (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t length); + + /* Return the location expression for the frame base attribute, in + START and LENGTH. The result must be live until the current + expression evaluation is complete. */ + void (*get_frame_base) (void *baton, const gdb_byte **start, size_t *length); + + /* Return the CFA for the frame. */ + CORE_ADDR (*get_frame_cfa) (void *baton); + + /* Return the PC for the frame. */ + CORE_ADDR (*get_frame_pc) (void *baton); + + /* Return the thread-local storage address for + DW_OP_GNU_push_tls_address. */ + CORE_ADDR (*get_tls_address) (void *baton, CORE_ADDR offset); + + /* Execute DW_AT_location expression for the DWARF expression subroutine in + the DIE at DIE_OFFSET in the CU from CTX. Do not touch STACK while it + being passed to and returned from the called DWARF subroutine. */ + void (*dwarf_call) (struct dwarf_expr_context *ctx, size_t die_offset); + + /* Return the base type given by the indicated DIE. This can throw + an exception if the DIE is invalid or does not represent a base + type. If can also be NULL in the special case where the + callbacks are not performing evaluation, and thus it is + meaningful to substitute a stub type of the correct size. */ + struct type *(*get_base_type) (struct dwarf_expr_context *ctx, size_t die); + +#if 0 + /* Not yet implemented. */ + + /* Return the `object address' for DW_OP_push_object_address. */ + CORE_ADDR (*get_object_address) (void *baton); +#endif +}; + /* The location of a value. */ enum dwarf_value_location { @@ -85,45 +132,8 @@ struct dwarf_expr_context to all of the callback functions. */ void *baton; - /* Return the value of register number REGNUM. */ - CORE_ADDR (*read_reg) (void *baton, int regnum); - - /* Read LENGTH bytes at ADDR into BUF. */ - void (*read_mem) (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t length); - - /* Return the location expression for the frame base attribute, in - START and LENGTH. The result must be live until the current - expression evaluation is complete. */ - void (*get_frame_base) (void *baton, const gdb_byte **start, size_t *length); - - /* Return the CFA for the frame. */ - CORE_ADDR (*get_frame_cfa) (void *baton); - - /* Return the PC for the frame. */ - CORE_ADDR (*get_frame_pc) (void *baton); - - /* Return the thread-local storage address for - DW_OP_GNU_push_tls_address. */ - CORE_ADDR (*get_tls_address) (void *baton, CORE_ADDR offset); - - /* Execute DW_AT_location expression for the DWARF expression subroutine in - the DIE at DIE_OFFSET in the CU from CTX. Do not touch STACK while it - being passed to and returned from the called DWARF subroutine. */ - void (*dwarf_call) (struct dwarf_expr_context *ctx, size_t die_offset); - - /* Return the base type given by the indicated DIE. This can throw - an exception if the DIE is invalid or does not represent a base - type. If can also be NULL in the special case where the - callbacks are not performing evaluation, and thus it is - meaningful to substitute a stub type of the correct size. */ - struct type *(*get_base_type) (struct dwarf_expr_context *ctx, size_t die); - -#if 0 - /* Not yet implemented. */ - - /* Return the `object address' for DW_OP_push_object_address. */ - CORE_ADDR (*get_object_address) (void *baton); -#endif + /* Callback functions. */ + const struct dwarf_expr_context_funcs *funcs; /* The current depth of dwarf expression recursion, via DW_OP_call*, DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 7c8ffbe..fc9a417 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -283,7 +283,7 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset) struct dwarf_expr_baton *debaton = ctx->baton; per_cu_dwarf_call (ctx, die_offset, debaton->per_cu, - ctx->get_frame_pc, ctx->baton); + ctx->funcs->get_frame_pc, ctx->baton); } /* Callback function for dwarf2_evaluate_loc_desc. */ @@ -1072,6 +1072,20 @@ invalid_synthetic_pointer (void) "referenced via synthetic pointer")); } +/* Virtual method table for dwarf2_evaluate_loc_desc_full below. */ + +static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs = +{ + dwarf_expr_read_reg, + dwarf_expr_read_mem, + dwarf_expr_frame_base, + dwarf_expr_frame_cfa, + dwarf_expr_frame_pc, + dwarf_expr_tls_address, + dwarf_expr_dwarf_call, + dwarf_expr_get_base_type +}; + /* Evaluate a location description, starting at DATA and with length SIZE, to find the current location of variable of TYPE in the context of FRAME. BYTE_OFFSET is applied after the contents are @@ -1107,14 +1121,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, ctx->addr_size = dwarf2_per_cu_addr_size (per_cu); ctx->offset = dwarf2_per_cu_text_offset (per_cu); ctx->baton = &baton; - ctx->read_reg = dwarf_expr_read_reg; - ctx->read_mem = dwarf_expr_read_mem; - ctx->get_frame_base = dwarf_expr_frame_base; - ctx->get_frame_cfa = dwarf_expr_frame_cfa; - ctx->get_frame_pc = dwarf_expr_frame_pc; - ctx->get_tls_address = dwarf_expr_tls_address; - ctx->dwarf_call = dwarf_expr_dwarf_call; - ctx->get_base_type = dwarf_expr_get_base_type; + ctx->funcs = &dwarf_expr_ctx_funcs; TRY_CATCH (ex, RETURN_MASK_ERROR) { @@ -1341,9 +1348,23 @@ needs_frame_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset) struct needs_frame_baton *nf_baton = ctx->baton; per_cu_dwarf_call (ctx, die_offset, nf_baton->per_cu, - ctx->get_frame_pc, ctx->baton); + ctx->funcs->get_frame_pc, ctx->baton); } +/* Virtual method table for dwarf2_loc_desc_needs_frame below. */ + +static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs = +{ + needs_frame_read_reg, + needs_frame_read_mem, + needs_frame_frame_base, + needs_frame_frame_cfa, + needs_frame_frame_cfa, /* get_frame_pc */ + needs_frame_tls_address, + needs_frame_dwarf_call, + NULL /* get_base_type */ +}; + /* Return non-zero iff the location expression at DATA (length SIZE) requires a frame to evaluate. */ @@ -1368,13 +1389,7 @@ dwarf2_loc_desc_needs_frame (const gdb_byte *data, unsigned short size, ctx->addr_size = dwarf2_per_cu_addr_size (per_cu); ctx->offset = dwarf2_per_cu_text_offset (per_cu); ctx->baton = &baton; - ctx->read_reg = needs_frame_read_reg; - ctx->read_mem = needs_frame_read_mem; - ctx->get_frame_base = needs_frame_frame_base; - ctx->get_frame_cfa = needs_frame_frame_cfa; - ctx->get_frame_pc = needs_frame_frame_cfa; - ctx->get_tls_address = needs_frame_tls_address; - ctx->dwarf_call = needs_frame_dwarf_call; + ctx->funcs = &needs_frame_ctx_funcs; dwarf_expr_eval (ctx, data, size); |