1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "exceptions.h"
37 #include "dwarf2expr.h"
38 #include "dwarf2loc.h"
39 #include "dwarf2-frame.h"
41 #include "gdb_string.h"
42 #include "gdb_assert.h"
45 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
46 gdb_byte
**start
, size_t *length
);
48 /* A helper function for dealing with location lists. Given a
49 symbol baton (BATON) and a pc value (PC), find the appropriate
50 location expression, set *LOCEXPR_LENGTH, and return a pointer
51 to the beginning of the expression. Returns NULL on failure.
53 For now, only return the first matching location expression; there
54 can be more than one in the list. */
57 find_location_expression (struct dwarf2_loclist_baton
*baton
,
58 size_t *locexpr_length
, CORE_ADDR pc
)
61 gdb_byte
*loc_ptr
, *buf_end
;
63 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
64 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
65 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
66 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
67 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
68 /* Adjust base_address for relocatable objects. */
69 CORE_ADDR base_offset
= ANOFFSET (objfile
->section_offsets
,
70 SECT_OFF_TEXT (objfile
));
71 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
73 loc_ptr
= baton
->data
;
74 buf_end
= baton
->data
+ baton
->size
;
78 if (buf_end
- loc_ptr
< 2 * addr_size
)
79 error (_("find_location_expression: Corrupted DWARF expression."));
81 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
84 /* A base-address-selection entry. */
87 base_address
= dwarf2_read_address (gdbarch
,
88 loc_ptr
, buf_end
, addr_size
);
93 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
96 /* An end-of-list entry. */
97 if (low
== 0 && high
== 0)
100 /* Otherwise, a location expression entry. */
102 high
+= base_address
;
104 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
107 if (pc
>= low
&& pc
< high
)
109 *locexpr_length
= length
;
117 /* This is the baton used when performing dwarf2 expression
119 struct dwarf_expr_baton
121 struct frame_info
*frame
;
122 struct objfile
*objfile
;
125 /* Helper functions for dwarf2_evaluate_loc_desc. */
127 /* Using the frame specified in BATON, return the value of register
128 REGNUM, treated as a pointer. */
130 dwarf_expr_read_reg (void *baton
, int dwarf_regnum
)
132 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
133 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
137 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
138 result
= address_from_register (builtin_type (gdbarch
)->builtin_data_ptr
,
139 regnum
, debaton
->frame
);
143 /* Read memory at ADDR (length LEN) into BUF. */
146 dwarf_expr_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
148 read_memory (addr
, buf
, len
);
151 /* Using the frame specified in BATON, find the location expression
152 describing the frame base. Return a pointer to it in START and
153 its length in LENGTH. */
155 dwarf_expr_frame_base (void *baton
, gdb_byte
**start
, size_t * length
)
157 /* FIXME: cagney/2003-03-26: This code should be using
158 get_frame_base_address(), and then implement a dwarf2 specific
160 struct symbol
*framefunc
;
161 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
163 /* Use block_linkage_function, which returns a real (not inlined)
164 function, instead of get_frame_function, which may return an
166 framefunc
= block_linkage_function (get_frame_block (debaton
->frame
, NULL
));
168 /* If we found a frame-relative symbol then it was certainly within
169 some function associated with a frame. If we can't find the frame,
170 something has gone wrong. */
171 gdb_assert (framefunc
!= NULL
);
173 dwarf_expr_frame_base_1 (framefunc
,
174 get_frame_address_in_block (debaton
->frame
),
179 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
180 gdb_byte
**start
, size_t *length
)
182 if (SYMBOL_LOCATION_BATON (framefunc
) == NULL
)
184 else if (SYMBOL_COMPUTED_OPS (framefunc
) == &dwarf2_loclist_funcs
)
186 struct dwarf2_loclist_baton
*symbaton
;
188 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
189 *start
= find_location_expression (symbaton
, length
, pc
);
193 struct dwarf2_locexpr_baton
*symbaton
;
194 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
195 if (symbaton
!= NULL
)
197 *length
= symbaton
->size
;
198 *start
= symbaton
->data
;
205 error (_("Could not find the frame base for \"%s\"."),
206 SYMBOL_NATURAL_NAME (framefunc
));
209 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
210 the frame in BATON. */
213 dwarf_expr_frame_cfa (void *baton
)
215 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
216 return dwarf2_frame_cfa (debaton
->frame
);
219 /* Using the objfile specified in BATON, find the address for the
220 current thread's thread-local storage with offset OFFSET. */
222 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
224 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
226 return target_translate_tls_address (debaton
->objfile
, offset
);
231 /* The number of pieces used to describe this variable. */
234 /* The architecture, used only for DWARF_VALUE_STACK. */
235 struct gdbarch
*arch
;
237 /* The pieces themselves. */
238 struct dwarf_expr_piece
*pieces
;
241 /* Allocate a closure for a value formed from separately-described
244 static struct piece_closure
*
245 allocate_piece_closure (int n_pieces
, struct dwarf_expr_piece
*pieces
,
246 struct gdbarch
*arch
)
248 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
250 c
->n_pieces
= n_pieces
;
252 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
254 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
260 read_pieced_value (struct value
*v
)
265 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
266 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
268 contents
= value_contents_raw (v
);
269 for (i
= 0; i
< c
->n_pieces
; i
++)
271 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
274 case DWARF_VALUE_REGISTER
:
276 struct gdbarch
*arch
= get_frame_arch (frame
);
277 bfd_byte regval
[MAX_REGISTER_SIZE
];
278 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
,
280 get_frame_register (frame
, gdb_regnum
, regval
);
281 memcpy (contents
+ offset
, regval
, p
->size
);
285 case DWARF_VALUE_MEMORY
:
286 if (p
->v
.expr
.in_stack_memory
)
287 read_stack (p
->v
.expr
.value
, contents
+ offset
, p
->size
);
289 read_memory (p
->v
.expr
.value
, contents
+ offset
, p
->size
);
292 case DWARF_VALUE_STACK
:
294 gdb_byte bytes
[sizeof (ULONGEST
)];
296 int addr_size
= gdbarch_addr_bit (c
->arch
) / 8;
297 store_unsigned_integer (bytes
, addr_size
,
298 gdbarch_byte_order (c
->arch
),
303 memcpy (contents
+ offset
, bytes
, n
);
307 case DWARF_VALUE_LITERAL
:
310 if (n
> p
->v
.literal
.length
)
311 n
= p
->v
.literal
.length
;
312 memcpy (contents
+ offset
, p
->v
.literal
.data
, n
);
317 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
324 write_pieced_value (struct value
*to
, struct value
*from
)
329 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (to
);
330 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
334 set_value_optimized_out (to
, 1);
338 contents
= value_contents_raw (from
);
339 for (i
= 0; i
< c
->n_pieces
; i
++)
341 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
344 case DWARF_VALUE_REGISTER
:
346 struct gdbarch
*arch
= get_frame_arch (frame
);
347 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.expr
.value
);
348 put_frame_register (frame
, gdb_regnum
, contents
+ offset
);
351 case DWARF_VALUE_MEMORY
:
352 write_memory (p
->v
.expr
.value
, contents
+ offset
, p
->size
);
355 set_value_optimized_out (to
, 1);
363 copy_pieced_value_closure (struct value
*v
)
365 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
367 return allocate_piece_closure (c
->n_pieces
, c
->pieces
, c
->arch
);
371 free_pieced_value_closure (struct value
*v
)
373 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
379 /* Functions for accessing a variable described by DW_OP_piece. */
380 static struct lval_funcs pieced_value_funcs
= {
383 copy_pieced_value_closure
,
384 free_pieced_value_closure
387 /* Evaluate a location description, starting at DATA and with length
388 SIZE, to find the current location of variable VAR in the context
390 static struct value
*
391 dwarf2_evaluate_loc_desc (struct symbol
*var
, struct frame_info
*frame
,
392 gdb_byte
*data
, unsigned short size
,
393 struct dwarf2_per_cu_data
*per_cu
)
395 struct value
*retval
;
396 struct dwarf_expr_baton baton
;
397 struct dwarf_expr_context
*ctx
;
398 struct cleanup
*old_chain
;
402 retval
= allocate_value (SYMBOL_TYPE (var
));
403 VALUE_LVAL (retval
) = not_lval
;
404 set_value_optimized_out (retval
, 1);
409 baton
.objfile
= dwarf2_per_cu_objfile (per_cu
);
411 ctx
= new_dwarf_expr_context ();
412 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
414 ctx
->gdbarch
= get_objfile_arch (baton
.objfile
);
415 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
417 ctx
->read_reg
= dwarf_expr_read_reg
;
418 ctx
->read_mem
= dwarf_expr_read_mem
;
419 ctx
->get_frame_base
= dwarf_expr_frame_base
;
420 ctx
->get_frame_cfa
= dwarf_expr_frame_cfa
;
421 ctx
->get_tls_address
= dwarf_expr_tls_address
;
423 dwarf_expr_eval (ctx
, data
, size
);
424 if (ctx
->num_pieces
> 0)
426 struct piece_closure
*c
;
427 struct frame_id frame_id
= get_frame_id (frame
);
429 c
= allocate_piece_closure (ctx
->num_pieces
, ctx
->pieces
, ctx
->gdbarch
);
430 retval
= allocate_computed_value (SYMBOL_TYPE (var
),
433 VALUE_FRAME_ID (retval
) = frame_id
;
437 switch (ctx
->location
)
439 case DWARF_VALUE_REGISTER
:
441 struct gdbarch
*arch
= get_frame_arch (frame
);
442 CORE_ADDR dwarf_regnum
= dwarf_expr_fetch (ctx
, 0);
443 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
444 retval
= value_from_register (SYMBOL_TYPE (var
), gdb_regnum
, frame
);
448 case DWARF_VALUE_MEMORY
:
450 CORE_ADDR address
= dwarf_expr_fetch (ctx
, 0);
451 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
453 retval
= allocate_value (SYMBOL_TYPE (var
));
454 VALUE_LVAL (retval
) = lval_memory
;
455 set_value_lazy (retval
, 1);
457 set_value_stack (retval
, 1);
458 set_value_address (retval
, address
);
462 case DWARF_VALUE_STACK
:
464 gdb_byte bytes
[sizeof (ULONGEST
)];
465 ULONGEST value
= (ULONGEST
) dwarf_expr_fetch (ctx
, 0);
467 size_t n
= ctx
->addr_size
;
469 store_unsigned_integer (bytes
, ctx
->addr_size
,
470 gdbarch_byte_order (ctx
->gdbarch
),
472 retval
= allocate_value (SYMBOL_TYPE (var
));
473 contents
= value_contents_raw (retval
);
474 if (n
> TYPE_LENGTH (SYMBOL_TYPE (var
)))
475 n
= TYPE_LENGTH (SYMBOL_TYPE (var
));
476 memcpy (contents
, bytes
, n
);
480 case DWARF_VALUE_LITERAL
:
485 retval
= allocate_value (SYMBOL_TYPE (var
));
486 contents
= value_contents_raw (retval
);
487 if (n
> TYPE_LENGTH (SYMBOL_TYPE (var
)))
488 n
= TYPE_LENGTH (SYMBOL_TYPE (var
));
489 memcpy (contents
, ctx
->data
, n
);
494 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
498 set_value_initialized (retval
, ctx
->initialized
);
500 do_cleanups (old_chain
);
505 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
507 struct needs_frame_baton
512 /* Reads from registers do require a frame. */
514 needs_frame_read_reg (void *baton
, int regnum
)
516 struct needs_frame_baton
*nf_baton
= baton
;
517 nf_baton
->needs_frame
= 1;
521 /* Reads from memory do not require a frame. */
523 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
525 memset (buf
, 0, len
);
528 /* Frame-relative accesses do require a frame. */
530 needs_frame_frame_base (void *baton
, gdb_byte
**start
, size_t * length
)
532 static gdb_byte lit0
= DW_OP_lit0
;
533 struct needs_frame_baton
*nf_baton
= baton
;
538 nf_baton
->needs_frame
= 1;
541 /* CFA accesses require a frame. */
544 needs_frame_frame_cfa (void *baton
)
546 struct needs_frame_baton
*nf_baton
= baton
;
547 nf_baton
->needs_frame
= 1;
551 /* Thread-local accesses do require a frame. */
553 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
555 struct needs_frame_baton
*nf_baton
= baton
;
556 nf_baton
->needs_frame
= 1;
560 /* Return non-zero iff the location expression at DATA (length SIZE)
561 requires a frame to evaluate. */
564 dwarf2_loc_desc_needs_frame (gdb_byte
*data
, unsigned short size
,
565 struct dwarf2_per_cu_data
*per_cu
)
567 struct needs_frame_baton baton
;
568 struct dwarf_expr_context
*ctx
;
570 struct cleanup
*old_chain
;
572 baton
.needs_frame
= 0;
574 ctx
= new_dwarf_expr_context ();
575 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
577 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (per_cu
));
578 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
580 ctx
->read_reg
= needs_frame_read_reg
;
581 ctx
->read_mem
= needs_frame_read_mem
;
582 ctx
->get_frame_base
= needs_frame_frame_base
;
583 ctx
->get_frame_cfa
= needs_frame_frame_cfa
;
584 ctx
->get_tls_address
= needs_frame_tls_address
;
586 dwarf_expr_eval (ctx
, data
, size
);
588 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
590 if (ctx
->num_pieces
> 0)
594 /* If the location has several pieces, and any of them are in
595 registers, then we will need a frame to fetch them from. */
596 for (i
= 0; i
< ctx
->num_pieces
; i
++)
597 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
601 do_cleanups (old_chain
);
603 return baton
.needs_frame
|| in_reg
;
607 dwarf2_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
608 struct agent_expr
*ax
, struct axs_value
*value
,
609 gdb_byte
*data
, int size
)
612 error (_("Symbol \"%s\" has been optimized out."),
613 SYMBOL_PRINT_NAME (symbol
));
616 && data
[0] >= DW_OP_reg0
617 && data
[0] <= DW_OP_reg31
)
619 value
->kind
= axs_lvalue_register
;
620 value
->u
.reg
= data
[0] - DW_OP_reg0
;
622 else if (data
[0] == DW_OP_regx
)
625 read_uleb128 (data
+ 1, data
+ size
, ®
);
626 value
->kind
= axs_lvalue_register
;
629 else if (data
[0] == DW_OP_fbreg
)
632 struct symbol
*framefunc
;
634 LONGEST frame_offset
;
638 LONGEST base_offset
= 0;
640 b
= block_for_pc (ax
->scope
);
643 error (_("No block found for address"));
645 framefunc
= block_linkage_function (b
);
648 error (_("No function found for block"));
650 dwarf_expr_frame_base_1 (framefunc
, ax
->scope
,
651 &base_data
, &base_size
);
653 if (base_data
[0] >= DW_OP_breg0
654 && base_data
[0] <= DW_OP_breg31
)
656 frame_reg
= base_data
[0] - DW_OP_breg0
;
657 buf_end
= read_sleb128 (base_data
+ 1, base_data
+ base_size
, &base_offset
);
658 if (buf_end
!= base_data
+ base_size
)
659 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
660 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
664 /* We don't know what to do with the frame base expression,
665 so we can't trace this variable; give up. */
666 error (_("Cannot generate expression to collect symbol \"%s\"; DWARF 2 encoding not handled"),
667 SYMBOL_PRINT_NAME (symbol
));
670 buf_end
= read_sleb128 (data
+ 1, data
+ size
, &frame_offset
);
671 if (buf_end
!= data
+ size
)
672 error (_("Unexpected opcode after DW_OP_fbreg for symbol \"%s\"."),
673 SYMBOL_PRINT_NAME (symbol
));
675 ax_reg (ax
, frame_reg
);
676 ax_const_l (ax
, base_offset
+ frame_offset
);
677 ax_simple (ax
, aop_add
);
679 value
->kind
= axs_lvalue_memory
;
681 else if (data
[0] >= DW_OP_breg0
682 && data
[0] <= DW_OP_breg31
)
688 reg
= data
[0] - DW_OP_breg0
;
689 buf_end
= read_sleb128 (data
+ 1, data
+ size
, &offset
);
690 if (buf_end
!= data
+ size
)
691 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
692 reg
, SYMBOL_PRINT_NAME (symbol
));
695 ax_const_l (ax
, offset
);
696 ax_simple (ax
, aop_add
);
698 value
->kind
= axs_lvalue_memory
;
701 error (_("Unsupported DWARF opcode 0x%x in the location of \"%s\"."),
702 data
[0], SYMBOL_PRINT_NAME (symbol
));
705 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
706 evaluator to calculate the location. */
707 static struct value
*
708 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
710 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
712 val
= dwarf2_evaluate_loc_desc (symbol
, frame
, dlbaton
->data
, dlbaton
->size
,
718 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
720 locexpr_read_needs_frame (struct symbol
*symbol
)
722 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
723 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
727 /* Print a natural-language description of SYMBOL to STREAM. */
729 locexpr_describe_location (struct symbol
*symbol
, struct ui_file
*stream
)
731 /* FIXME: be more extensive. */
732 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
733 int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
735 if (dlbaton
->size
== 1
736 && dlbaton
->data
[0] >= DW_OP_reg0
737 && dlbaton
->data
[0] <= DW_OP_reg31
)
739 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
740 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
741 int regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
,
742 dlbaton
->data
[0] - DW_OP_reg0
);
743 fprintf_filtered (stream
,
744 "a variable in register %s",
745 gdbarch_register_name (gdbarch
, regno
));
749 /* The location expression for a TLS variable looks like this (on a
752 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
753 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
755 0x3 is the encoding for DW_OP_addr, which has an operand as long
756 as the size of an address on the target machine (here is 8
757 bytes). 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
758 The operand represents the offset at which the variable is within
759 the thread local storage. */
761 if (dlbaton
->size
> 1
762 && dlbaton
->data
[dlbaton
->size
- 1] == DW_OP_GNU_push_tls_address
)
763 if (dlbaton
->data
[0] == DW_OP_addr
)
765 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
766 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
767 CORE_ADDR offset
= dwarf2_read_address (gdbarch
,
769 &dlbaton
->data
[dlbaton
->size
- 1],
771 fprintf_filtered (stream
,
772 "a thread-local variable at offset %s in the "
773 "thread-local storage for `%s'",
774 paddress (gdbarch
, offset
), objfile
->name
);
779 fprintf_filtered (stream
,
780 "a variable with complex or multiple locations (DWARF2)");
785 /* Describe the location of SYMBOL as an agent value in VALUE, generating
786 any necessary bytecode in AX.
788 NOTE drow/2003-02-26: This function is extremely minimal, because
789 doing it correctly is extremely complicated and there is no
790 publicly available stub with tracepoint support for me to test
791 against. When there is one this function should be revisited. */
794 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
795 struct agent_expr
*ax
, struct axs_value
*value
)
797 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
799 dwarf2_tracepoint_var_ref (symbol
, gdbarch
, ax
, value
,
800 dlbaton
->data
, dlbaton
->size
);
803 /* The set of location functions used with the DWARF-2 expression
805 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
806 locexpr_read_variable
,
807 locexpr_read_needs_frame
,
808 locexpr_describe_location
,
809 locexpr_tracepoint_var_ref
813 /* Wrapper functions for location lists. These generally find
814 the appropriate location expression and call something above. */
816 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
817 evaluator to calculate the location. */
818 static struct value
*
819 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
821 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
826 data
= find_location_expression (dlbaton
, &size
,
827 frame
? get_frame_address_in_block (frame
)
831 val
= allocate_value (SYMBOL_TYPE (symbol
));
832 VALUE_LVAL (val
) = not_lval
;
833 set_value_optimized_out (val
, 1);
836 val
= dwarf2_evaluate_loc_desc (symbol
, frame
, data
, size
,
842 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
844 loclist_read_needs_frame (struct symbol
*symbol
)
846 /* If there's a location list, then assume we need to have a frame
847 to choose the appropriate location expression. With tracking of
848 global variables this is not necessarily true, but such tracking
849 is disabled in GCC at the moment until we figure out how to
855 /* Print a natural-language description of SYMBOL to STREAM. */
857 loclist_describe_location (struct symbol
*symbol
, struct ui_file
*stream
)
859 /* FIXME: Could print the entire list of locations. */
860 fprintf_filtered (stream
, "a variable with multiple locations");
864 /* Describe the location of SYMBOL as an agent value in VALUE, generating
865 any necessary bytecode in AX. */
867 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
868 struct agent_expr
*ax
, struct axs_value
*value
)
870 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
874 data
= find_location_expression (dlbaton
, &size
, ax
->scope
);
876 error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol
));
878 dwarf2_tracepoint_var_ref (symbol
, gdbarch
, ax
, value
, data
, size
);
881 /* The set of location functions used with the DWARF-2 expression
882 evaluator and location lists. */
883 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
884 loclist_read_variable
,
885 loclist_read_needs_frame
,
886 loclist_describe_location
,
887 loclist_tracepoint_var_ref