1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "exceptions.h"
38 #include "dwarf2expr.h"
39 #include "dwarf2loc.h"
40 #include "dwarf2-frame.h"
42 #include "gdb_string.h"
43 #include "gdb_assert.h"
46 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
47 gdb_byte
**start
, size_t *length
);
49 /* A helper function for dealing with location lists. Given a
50 symbol baton (BATON) and a pc value (PC), find the appropriate
51 location expression, set *LOCEXPR_LENGTH, and return a pointer
52 to the beginning of the expression. Returns NULL on failure.
54 For now, only return the first matching location expression; there
55 can be more than one in the list. */
58 find_location_expression (struct dwarf2_loclist_baton
*baton
,
59 size_t *locexpr_length
, CORE_ADDR pc
)
62 gdb_byte
*loc_ptr
, *buf_end
;
64 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
65 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
66 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
67 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
68 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
69 /* Adjust base_address for relocatable objects. */
70 CORE_ADDR base_offset
= ANOFFSET (objfile
->section_offsets
,
71 SECT_OFF_TEXT (objfile
));
72 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
74 loc_ptr
= baton
->data
;
75 buf_end
= baton
->data
+ baton
->size
;
79 if (buf_end
- loc_ptr
< 2 * addr_size
)
80 error (_("find_location_expression: Corrupted DWARF expression."));
82 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
85 /* A base-address-selection entry. */
88 base_address
= dwarf2_read_address (gdbarch
,
89 loc_ptr
, buf_end
, addr_size
);
94 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
97 /* An end-of-list entry. */
98 if (low
== 0 && high
== 0)
101 /* Otherwise, a location expression entry. */
103 high
+= base_address
;
105 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
108 if (pc
>= low
&& pc
< high
)
110 *locexpr_length
= length
;
118 /* This is the baton used when performing dwarf2 expression
120 struct dwarf_expr_baton
122 struct frame_info
*frame
;
123 struct objfile
*objfile
;
126 /* Helper functions for dwarf2_evaluate_loc_desc. */
128 /* Using the frame specified in BATON, return the value of register
129 REGNUM, treated as a pointer. */
131 dwarf_expr_read_reg (void *baton
, int dwarf_regnum
)
133 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
134 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
138 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
139 result
= address_from_register (builtin_type (gdbarch
)->builtin_data_ptr
,
140 regnum
, debaton
->frame
);
144 /* Read memory at ADDR (length LEN) into BUF. */
147 dwarf_expr_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
149 read_memory (addr
, buf
, len
);
152 /* Using the frame specified in BATON, find the location expression
153 describing the frame base. Return a pointer to it in START and
154 its length in LENGTH. */
156 dwarf_expr_frame_base (void *baton
, gdb_byte
**start
, size_t * length
)
158 /* FIXME: cagney/2003-03-26: This code should be using
159 get_frame_base_address(), and then implement a dwarf2 specific
161 struct symbol
*framefunc
;
162 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
164 /* Use block_linkage_function, which returns a real (not inlined)
165 function, instead of get_frame_function, which may return an
167 framefunc
= block_linkage_function (get_frame_block (debaton
->frame
, NULL
));
169 /* If we found a frame-relative symbol then it was certainly within
170 some function associated with a frame. If we can't find the frame,
171 something has gone wrong. */
172 gdb_assert (framefunc
!= NULL
);
174 dwarf_expr_frame_base_1 (framefunc
,
175 get_frame_address_in_block (debaton
->frame
),
180 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
181 gdb_byte
**start
, size_t *length
)
183 if (SYMBOL_LOCATION_BATON (framefunc
) == NULL
)
185 else if (SYMBOL_COMPUTED_OPS (framefunc
) == &dwarf2_loclist_funcs
)
187 struct dwarf2_loclist_baton
*symbaton
;
189 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
190 *start
= find_location_expression (symbaton
, length
, pc
);
194 struct dwarf2_locexpr_baton
*symbaton
;
195 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
196 if (symbaton
!= NULL
)
198 *length
= symbaton
->size
;
199 *start
= symbaton
->data
;
206 error (_("Could not find the frame base for \"%s\"."),
207 SYMBOL_NATURAL_NAME (framefunc
));
210 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
211 the frame in BATON. */
214 dwarf_expr_frame_cfa (void *baton
)
216 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
217 return dwarf2_frame_cfa (debaton
->frame
);
220 /* Using the objfile specified in BATON, find the address for the
221 current thread's thread-local storage with offset OFFSET. */
223 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
225 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
227 return target_translate_tls_address (debaton
->objfile
, offset
);
232 /* The number of pieces used to describe this variable. */
235 /* The target address size, used only for DWARF_VALUE_STACK. */
238 /* The pieces themselves. */
239 struct dwarf_expr_piece
*pieces
;
242 /* Allocate a closure for a value formed from separately-described
245 static struct piece_closure
*
246 allocate_piece_closure (int n_pieces
, struct dwarf_expr_piece
*pieces
,
249 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
251 c
->n_pieces
= n_pieces
;
252 c
->addr_size
= addr_size
;
253 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
255 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
261 read_pieced_value (struct value
*v
)
266 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
267 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
269 contents
= value_contents_raw (v
);
270 for (i
= 0; i
< c
->n_pieces
; i
++)
272 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
275 case DWARF_VALUE_REGISTER
:
277 struct gdbarch
*arch
= get_frame_arch (frame
);
278 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
,
282 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
283 && p
->size
< register_size (arch
, gdb_regnum
))
284 /* Big-endian, and we want less than full size. */
285 reg_offset
= register_size (arch
, gdb_regnum
) - p
->size
;
287 get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
, p
->size
,
292 case DWARF_VALUE_MEMORY
:
293 if (p
->v
.expr
.in_stack_memory
)
294 read_stack (p
->v
.expr
.value
, contents
+ offset
, p
->size
);
296 read_memory (p
->v
.expr
.value
, contents
+ offset
, p
->size
);
299 case DWARF_VALUE_STACK
:
301 struct gdbarch
*gdbarch
= get_type_arch (value_type (v
));
303 if (n
> c
->addr_size
)
305 store_unsigned_integer (contents
+ offset
, n
,
306 gdbarch_byte_order (gdbarch
),
311 case DWARF_VALUE_LITERAL
:
314 if (n
> p
->v
.literal
.length
)
315 n
= p
->v
.literal
.length
;
316 memcpy (contents
+ offset
, p
->v
.literal
.data
, n
);
321 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
328 write_pieced_value (struct value
*to
, struct value
*from
)
333 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (to
);
334 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
338 set_value_optimized_out (to
, 1);
342 contents
= value_contents_raw (from
);
343 for (i
= 0; i
< c
->n_pieces
; i
++)
345 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
348 case DWARF_VALUE_REGISTER
:
350 struct gdbarch
*arch
= get_frame_arch (frame
);
351 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.expr
.value
);
354 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
355 && p
->size
< register_size (arch
, gdb_regnum
))
356 /* Big-endian, and we want less than full size. */
357 reg_offset
= register_size (arch
, gdb_regnum
) - p
->size
;
359 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
, p
->size
,
363 case DWARF_VALUE_MEMORY
:
364 write_memory (p
->v
.expr
.value
, contents
+ offset
, p
->size
);
367 set_value_optimized_out (to
, 1);
375 copy_pieced_value_closure (struct value
*v
)
377 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
379 return allocate_piece_closure (c
->n_pieces
, c
->pieces
, c
->addr_size
);
383 free_pieced_value_closure (struct value
*v
)
385 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
391 /* Functions for accessing a variable described by DW_OP_piece. */
392 static struct lval_funcs pieced_value_funcs
= {
395 copy_pieced_value_closure
,
396 free_pieced_value_closure
399 /* Evaluate a location description, starting at DATA and with length
400 SIZE, to find the current location of variable VAR in the context
402 static struct value
*
403 dwarf2_evaluate_loc_desc (struct symbol
*var
, struct frame_info
*frame
,
404 gdb_byte
*data
, unsigned short size
,
405 struct dwarf2_per_cu_data
*per_cu
)
407 struct value
*retval
;
408 struct dwarf_expr_baton baton
;
409 struct dwarf_expr_context
*ctx
;
410 struct cleanup
*old_chain
;
414 retval
= allocate_value (SYMBOL_TYPE (var
));
415 VALUE_LVAL (retval
) = not_lval
;
416 set_value_optimized_out (retval
, 1);
421 baton
.objfile
= dwarf2_per_cu_objfile (per_cu
);
423 ctx
= new_dwarf_expr_context ();
424 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
426 ctx
->gdbarch
= get_objfile_arch (baton
.objfile
);
427 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
429 ctx
->read_reg
= dwarf_expr_read_reg
;
430 ctx
->read_mem
= dwarf_expr_read_mem
;
431 ctx
->get_frame_base
= dwarf_expr_frame_base
;
432 ctx
->get_frame_cfa
= dwarf_expr_frame_cfa
;
433 ctx
->get_tls_address
= dwarf_expr_tls_address
;
435 dwarf_expr_eval (ctx
, data
, size
);
436 if (ctx
->num_pieces
> 0)
438 struct piece_closure
*c
;
439 struct frame_id frame_id
= get_frame_id (frame
);
441 c
= allocate_piece_closure (ctx
->num_pieces
, ctx
->pieces
,
443 retval
= allocate_computed_value (SYMBOL_TYPE (var
),
446 VALUE_FRAME_ID (retval
) = frame_id
;
450 switch (ctx
->location
)
452 case DWARF_VALUE_REGISTER
:
454 struct gdbarch
*arch
= get_frame_arch (frame
);
455 CORE_ADDR dwarf_regnum
= dwarf_expr_fetch (ctx
, 0);
456 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
457 retval
= value_from_register (SYMBOL_TYPE (var
), gdb_regnum
, frame
);
461 case DWARF_VALUE_MEMORY
:
463 CORE_ADDR address
= dwarf_expr_fetch (ctx
, 0);
464 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
466 retval
= allocate_value (SYMBOL_TYPE (var
));
467 VALUE_LVAL (retval
) = lval_memory
;
468 set_value_lazy (retval
, 1);
470 set_value_stack (retval
, 1);
471 set_value_address (retval
, address
);
475 case DWARF_VALUE_STACK
:
477 ULONGEST value
= (ULONGEST
) dwarf_expr_fetch (ctx
, 0);
479 size_t n
= ctx
->addr_size
;
481 retval
= allocate_value (SYMBOL_TYPE (var
));
482 contents
= value_contents_raw (retval
);
483 if (n
> TYPE_LENGTH (SYMBOL_TYPE (var
)))
484 n
= TYPE_LENGTH (SYMBOL_TYPE (var
));
485 store_unsigned_integer (contents
, n
,
486 gdbarch_byte_order (ctx
->gdbarch
),
491 case DWARF_VALUE_LITERAL
:
496 retval
= allocate_value (SYMBOL_TYPE (var
));
497 contents
= value_contents_raw (retval
);
498 if (n
> TYPE_LENGTH (SYMBOL_TYPE (var
)))
499 n
= TYPE_LENGTH (SYMBOL_TYPE (var
));
500 memcpy (contents
, ctx
->data
, n
);
505 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
509 set_value_initialized (retval
, ctx
->initialized
);
511 do_cleanups (old_chain
);
516 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
518 struct needs_frame_baton
523 /* Reads from registers do require a frame. */
525 needs_frame_read_reg (void *baton
, int regnum
)
527 struct needs_frame_baton
*nf_baton
= baton
;
528 nf_baton
->needs_frame
= 1;
532 /* Reads from memory do not require a frame. */
534 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
536 memset (buf
, 0, len
);
539 /* Frame-relative accesses do require a frame. */
541 needs_frame_frame_base (void *baton
, gdb_byte
**start
, size_t * length
)
543 static gdb_byte lit0
= DW_OP_lit0
;
544 struct needs_frame_baton
*nf_baton
= baton
;
549 nf_baton
->needs_frame
= 1;
552 /* CFA accesses require a frame. */
555 needs_frame_frame_cfa (void *baton
)
557 struct needs_frame_baton
*nf_baton
= baton
;
558 nf_baton
->needs_frame
= 1;
562 /* Thread-local accesses do require a frame. */
564 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
566 struct needs_frame_baton
*nf_baton
= baton
;
567 nf_baton
->needs_frame
= 1;
571 /* Return non-zero iff the location expression at DATA (length SIZE)
572 requires a frame to evaluate. */
575 dwarf2_loc_desc_needs_frame (gdb_byte
*data
, unsigned short size
,
576 struct dwarf2_per_cu_data
*per_cu
)
578 struct needs_frame_baton baton
;
579 struct dwarf_expr_context
*ctx
;
581 struct cleanup
*old_chain
;
583 baton
.needs_frame
= 0;
585 ctx
= new_dwarf_expr_context ();
586 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
588 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (per_cu
));
589 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
591 ctx
->read_reg
= needs_frame_read_reg
;
592 ctx
->read_mem
= needs_frame_read_mem
;
593 ctx
->get_frame_base
= needs_frame_frame_base
;
594 ctx
->get_frame_cfa
= needs_frame_frame_cfa
;
595 ctx
->get_tls_address
= needs_frame_tls_address
;
597 dwarf_expr_eval (ctx
, data
, size
);
599 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
601 if (ctx
->num_pieces
> 0)
605 /* If the location has several pieces, and any of them are in
606 registers, then we will need a frame to fetch them from. */
607 for (i
= 0; i
< ctx
->num_pieces
; i
++)
608 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
612 do_cleanups (old_chain
);
614 return baton
.needs_frame
|| in_reg
;
618 dwarf2_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
619 struct agent_expr
*ax
, struct axs_value
*value
,
620 gdb_byte
*data
, int size
)
623 error (_("Symbol \"%s\" has been optimized out."),
624 SYMBOL_PRINT_NAME (symbol
));
627 && data
[0] >= DW_OP_reg0
628 && data
[0] <= DW_OP_reg31
)
630 value
->kind
= axs_lvalue_register
;
631 value
->u
.reg
= data
[0] - DW_OP_reg0
;
633 else if (data
[0] == DW_OP_regx
)
636 read_uleb128 (data
+ 1, data
+ size
, ®
);
637 value
->kind
= axs_lvalue_register
;
640 else if (data
[0] == DW_OP_fbreg
)
643 struct symbol
*framefunc
;
645 LONGEST frame_offset
;
649 LONGEST base_offset
= 0;
651 b
= block_for_pc (ax
->scope
);
654 error (_("No block found for address"));
656 framefunc
= block_linkage_function (b
);
659 error (_("No function found for block"));
661 dwarf_expr_frame_base_1 (framefunc
, ax
->scope
,
662 &base_data
, &base_size
);
664 if (base_data
[0] >= DW_OP_breg0
665 && base_data
[0] <= DW_OP_breg31
)
667 frame_reg
= base_data
[0] - DW_OP_breg0
;
668 buf_end
= read_sleb128 (base_data
+ 1, base_data
+ base_size
, &base_offset
);
669 if (buf_end
!= base_data
+ base_size
)
670 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
671 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
675 /* We don't know what to do with the frame base expression,
676 so we can't trace this variable; give up. */
677 error (_("Cannot generate expression to collect symbol \"%s\"; DWARF 2 encoding not handled"),
678 SYMBOL_PRINT_NAME (symbol
));
681 buf_end
= read_sleb128 (data
+ 1, data
+ size
, &frame_offset
);
682 if (buf_end
!= data
+ size
)
683 error (_("Unexpected opcode after DW_OP_fbreg for symbol \"%s\"."),
684 SYMBOL_PRINT_NAME (symbol
));
686 ax_reg (ax
, frame_reg
);
687 ax_const_l (ax
, base_offset
+ frame_offset
);
688 ax_simple (ax
, aop_add
);
690 value
->kind
= axs_lvalue_memory
;
692 else if (data
[0] >= DW_OP_breg0
693 && data
[0] <= DW_OP_breg31
)
699 reg
= data
[0] - DW_OP_breg0
;
700 buf_end
= read_sleb128 (data
+ 1, data
+ size
, &offset
);
701 if (buf_end
!= data
+ size
)
702 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
703 reg
, SYMBOL_PRINT_NAME (symbol
));
706 ax_const_l (ax
, offset
);
707 ax_simple (ax
, aop_add
);
709 value
->kind
= axs_lvalue_memory
;
712 error (_("Unsupported DWARF opcode 0x%x in the location of \"%s\"."),
713 data
[0], SYMBOL_PRINT_NAME (symbol
));
716 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
717 evaluator to calculate the location. */
718 static struct value
*
719 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
721 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
723 val
= dwarf2_evaluate_loc_desc (symbol
, frame
, dlbaton
->data
, dlbaton
->size
,
729 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
731 locexpr_read_needs_frame (struct symbol
*symbol
)
733 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
734 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
738 /* Print a natural-language description of SYMBOL to STREAM. */
740 locexpr_describe_location (struct symbol
*symbol
, struct ui_file
*stream
)
742 /* FIXME: be more extensive. */
743 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
744 int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
746 if (dlbaton
->size
== 1
747 && dlbaton
->data
[0] >= DW_OP_reg0
748 && dlbaton
->data
[0] <= DW_OP_reg31
)
750 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
751 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
752 int regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
,
753 dlbaton
->data
[0] - DW_OP_reg0
);
754 fprintf_filtered (stream
,
755 "a variable in register %s",
756 gdbarch_register_name (gdbarch
, regno
));
760 /* The location expression for a TLS variable looks like this (on a
763 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
764 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
766 0x3 is the encoding for DW_OP_addr, which has an operand as long
767 as the size of an address on the target machine (here is 8
768 bytes). 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
769 The operand represents the offset at which the variable is within
770 the thread local storage. */
772 if (dlbaton
->size
> 1
773 && dlbaton
->data
[dlbaton
->size
- 1] == DW_OP_GNU_push_tls_address
)
774 if (dlbaton
->data
[0] == DW_OP_addr
)
776 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
777 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
778 CORE_ADDR offset
= dwarf2_read_address (gdbarch
,
780 &dlbaton
->data
[dlbaton
->size
- 1],
782 fprintf_filtered (stream
,
783 "a thread-local variable at offset %s in the "
784 "thread-local storage for `%s'",
785 paddress (gdbarch
, offset
), objfile
->name
);
790 fprintf_filtered (stream
,
791 "a variable with complex or multiple locations (DWARF2)");
796 /* Describe the location of SYMBOL as an agent value in VALUE, generating
797 any necessary bytecode in AX.
799 NOTE drow/2003-02-26: This function is extremely minimal, because
800 doing it correctly is extremely complicated and there is no
801 publicly available stub with tracepoint support for me to test
802 against. When there is one this function should be revisited. */
805 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
806 struct agent_expr
*ax
, struct axs_value
*value
)
808 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
810 dwarf2_tracepoint_var_ref (symbol
, gdbarch
, ax
, value
,
811 dlbaton
->data
, dlbaton
->size
);
814 /* The set of location functions used with the DWARF-2 expression
816 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
817 locexpr_read_variable
,
818 locexpr_read_needs_frame
,
819 locexpr_describe_location
,
820 locexpr_tracepoint_var_ref
824 /* Wrapper functions for location lists. These generally find
825 the appropriate location expression and call something above. */
827 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
828 evaluator to calculate the location. */
829 static struct value
*
830 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
832 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
837 data
= find_location_expression (dlbaton
, &size
,
838 frame
? get_frame_address_in_block (frame
)
842 val
= allocate_value (SYMBOL_TYPE (symbol
));
843 VALUE_LVAL (val
) = not_lval
;
844 set_value_optimized_out (val
, 1);
847 val
= dwarf2_evaluate_loc_desc (symbol
, frame
, data
, size
,
853 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
855 loclist_read_needs_frame (struct symbol
*symbol
)
857 /* If there's a location list, then assume we need to have a frame
858 to choose the appropriate location expression. With tracking of
859 global variables this is not necessarily true, but such tracking
860 is disabled in GCC at the moment until we figure out how to
866 /* Print a natural-language description of SYMBOL to STREAM. */
868 loclist_describe_location (struct symbol
*symbol
, struct ui_file
*stream
)
870 /* FIXME: Could print the entire list of locations. */
871 fprintf_filtered (stream
, "a variable with multiple locations");
875 /* Describe the location of SYMBOL as an agent value in VALUE, generating
876 any necessary bytecode in AX. */
878 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
879 struct agent_expr
*ax
, struct axs_value
*value
)
881 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
885 data
= find_location_expression (dlbaton
, &size
, ax
->scope
);
887 error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol
));
889 dwarf2_tracepoint_var_ref (symbol
, gdbarch
, ax
, value
, data
, size
);
892 /* The set of location functions used with the DWARF-2 expression
893 evaluator and location lists. */
894 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
895 loclist_read_variable
,
896 loclist_read_needs_frame
,
897 loclist_describe_location
,
898 loclist_tracepoint_var_ref