* dwarf2loc.c (struct piece_closure): New.
[deliverable/binutils-gdb.git] / gdb / dwarf2loc.c
1 /* DWARF 2 location expression support for GDB.
2
3 Copyright (C) 2003, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
4
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22 #include "defs.h"
23 #include "ui-out.h"
24 #include "value.h"
25 #include "frame.h"
26 #include "gdbcore.h"
27 #include "target.h"
28 #include "inferior.h"
29 #include "ax.h"
30 #include "ax-gdb.h"
31 #include "regcache.h"
32 #include "objfiles.h"
33 #include "exceptions.h"
34 #include "block.h"
35
36 #include "dwarf2.h"
37 #include "dwarf2expr.h"
38 #include "dwarf2loc.h"
39 #include "dwarf2-frame.h"
40
41 #include "gdb_string.h"
42 #include "gdb_assert.h"
43
44 /* A helper function for dealing with location lists. Given a
45 symbol baton (BATON) and a pc value (PC), find the appropriate
46 location expression, set *LOCEXPR_LENGTH, and return a pointer
47 to the beginning of the expression. Returns NULL on failure.
48
49 For now, only return the first matching location expression; there
50 can be more than one in the list. */
51
52 static gdb_byte *
53 find_location_expression (struct dwarf2_loclist_baton *baton,
54 size_t *locexpr_length, CORE_ADDR pc)
55 {
56 CORE_ADDR low, high;
57 gdb_byte *loc_ptr, *buf_end;
58 int length;
59 struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
60 struct gdbarch *gdbarch = get_objfile_arch (objfile);
61 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
62 unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
63 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
64 /* Adjust base_address for relocatable objects. */
65 CORE_ADDR base_offset = ANOFFSET (objfile->section_offsets,
66 SECT_OFF_TEXT (objfile));
67 CORE_ADDR base_address = baton->base_address + base_offset;
68
69 loc_ptr = baton->data;
70 buf_end = baton->data + baton->size;
71
72 while (1)
73 {
74 if (buf_end - loc_ptr < 2 * addr_size)
75 error (_("find_location_expression: Corrupted DWARF expression."));
76
77 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
78 loc_ptr += addr_size;
79
80 /* A base-address-selection entry. */
81 if (low == base_mask)
82 {
83 base_address = dwarf2_read_address (gdbarch,
84 loc_ptr, buf_end, addr_size);
85 loc_ptr += addr_size;
86 continue;
87 }
88
89 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
90 loc_ptr += addr_size;
91
92 /* An end-of-list entry. */
93 if (low == 0 && high == 0)
94 return NULL;
95
96 /* Otherwise, a location expression entry. */
97 low += base_address;
98 high += base_address;
99
100 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
101 loc_ptr += 2;
102
103 if (pc >= low && pc < high)
104 {
105 *locexpr_length = length;
106 return loc_ptr;
107 }
108
109 loc_ptr += length;
110 }
111 }
112
113 /* This is the baton used when performing dwarf2 expression
114 evaluation. */
115 struct dwarf_expr_baton
116 {
117 struct frame_info *frame;
118 struct objfile *objfile;
119 };
120
121 /* Helper functions for dwarf2_evaluate_loc_desc. */
122
123 /* Using the frame specified in BATON, return the value of register
124 REGNUM, treated as a pointer. */
125 static CORE_ADDR
126 dwarf_expr_read_reg (void *baton, int dwarf_regnum)
127 {
128 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
129 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
130 CORE_ADDR result;
131 int regnum;
132
133 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
134 result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
135 regnum, debaton->frame);
136 return result;
137 }
138
139 /* Read memory at ADDR (length LEN) into BUF. */
140
141 static void
142 dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
143 {
144 read_memory (addr, buf, len);
145 }
146
147 /* Using the frame specified in BATON, find the location expression
148 describing the frame base. Return a pointer to it in START and
149 its length in LENGTH. */
150 static void
151 dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
152 {
153 /* FIXME: cagney/2003-03-26: This code should be using
154 get_frame_base_address(), and then implement a dwarf2 specific
155 this_base method. */
156 struct symbol *framefunc;
157 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
158
159 /* Use block_linkage_function, which returns a real (not inlined)
160 function, instead of get_frame_function, which may return an
161 inlined function. */
162 framefunc = block_linkage_function (get_frame_block (debaton->frame, NULL));
163
164 /* If we found a frame-relative symbol then it was certainly within
165 some function associated with a frame. If we can't find the frame,
166 something has gone wrong. */
167 gdb_assert (framefunc != NULL);
168
169 if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
170 *start = NULL;
171 else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
172 {
173 struct dwarf2_loclist_baton *symbaton;
174 struct frame_info *frame = debaton->frame;
175
176 symbaton = SYMBOL_LOCATION_BATON (framefunc);
177 *start = find_location_expression (symbaton, length,
178 get_frame_address_in_block (frame));
179 }
180 else
181 {
182 struct dwarf2_locexpr_baton *symbaton;
183 symbaton = SYMBOL_LOCATION_BATON (framefunc);
184 if (symbaton != NULL)
185 {
186 *length = symbaton->size;
187 *start = symbaton->data;
188 }
189 else
190 *start = NULL;
191 }
192
193 if (*start == NULL)
194 error (_("Could not find the frame base for \"%s\"."),
195 SYMBOL_NATURAL_NAME (framefunc));
196 }
197
198 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
199 the frame in BATON. */
200
201 static CORE_ADDR
202 dwarf_expr_frame_cfa (void *baton)
203 {
204 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
205 return dwarf2_frame_cfa (debaton->frame);
206 }
207
208 /* Using the objfile specified in BATON, find the address for the
209 current thread's thread-local storage with offset OFFSET. */
210 static CORE_ADDR
211 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
212 {
213 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
214
215 return target_translate_tls_address (debaton->objfile, offset);
216 }
217
218 struct piece_closure
219 {
220 /* The number of pieces used to describe this variable. */
221 int n_pieces;
222
223 /* The pieces themselves. */
224 struct dwarf_expr_piece *pieces;
225 };
226
227 /* Allocate a closure for a value formed from separately-described
228 PIECES. */
229
230 static struct piece_closure *
231 allocate_piece_closure (int n_pieces, struct dwarf_expr_piece *pieces)
232 {
233 struct piece_closure *c = XZALLOC (struct piece_closure);
234
235 c->n_pieces = n_pieces;
236 c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
237
238 memcpy (c->pieces, pieces, n_pieces * sizeof (struct dwarf_expr_piece));
239
240 return c;
241 }
242
243 static void
244 read_pieced_value (struct value *v)
245 {
246 int i;
247 long offset = 0;
248 gdb_byte *contents;
249 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
250 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (v));
251
252 contents = value_contents_raw (v);
253 for (i = 0; i < c->n_pieces; i++)
254 {
255 struct dwarf_expr_piece *p = &c->pieces[i];
256
257 if (frame == NULL)
258 {
259 memset (contents + offset, 0, p->size);
260 set_value_optimized_out (v, 1);
261 }
262 else if (p->in_reg)
263 {
264 struct gdbarch *arch = get_frame_arch (frame);
265 gdb_byte regval[MAX_REGISTER_SIZE];
266 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->value);
267
268 get_frame_register (frame, gdb_regnum, regval);
269 memcpy (contents + offset, regval, p->size);
270 }
271 else
272 {
273 read_memory (p->value, contents + offset, p->size);
274 }
275 offset += p->size;
276 }
277 }
278
279 static void
280 write_pieced_value (struct value *to, struct value *from)
281 {
282 int i;
283 long offset = 0;
284 gdb_byte *contents;
285 struct piece_closure *c = (struct piece_closure *) value_computed_closure (to);
286 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (to));
287
288 if (frame == NULL)
289 {
290 set_value_optimized_out (to, 1);
291 return;
292 }
293
294 contents = value_contents_raw (from);
295 for (i = 0; i < c->n_pieces; i++)
296 {
297 struct dwarf_expr_piece *p = &c->pieces[i];
298 if (p->in_reg)
299 {
300 struct gdbarch *arch = get_frame_arch (frame);
301 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->value);
302 put_frame_register (frame, gdb_regnum, contents + offset);
303 }
304 else
305 {
306 write_memory (p->value, contents + offset, p->size);
307 }
308 offset += p->size;
309 }
310 }
311
312 static void *
313 copy_pieced_value_closure (struct value *v)
314 {
315 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
316
317 return allocate_piece_closure (c->n_pieces, c->pieces);
318 }
319
320 static void
321 free_pieced_value_closure (struct value *v)
322 {
323 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
324
325 xfree (c->pieces);
326 xfree (c);
327 }
328
329 /* Functions for accessing a variable described by DW_OP_piece. */
330 static struct lval_funcs pieced_value_funcs = {
331 read_pieced_value,
332 write_pieced_value,
333 copy_pieced_value_closure,
334 free_pieced_value_closure
335 };
336
337 /* Evaluate a location description, starting at DATA and with length
338 SIZE, to find the current location of variable VAR in the context
339 of FRAME. */
340 static struct value *
341 dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
342 gdb_byte *data, unsigned short size,
343 struct dwarf2_per_cu_data *per_cu)
344 {
345 struct value *retval;
346 struct dwarf_expr_baton baton;
347 struct dwarf_expr_context *ctx;
348 struct cleanup *old_chain;
349
350 if (size == 0)
351 {
352 retval = allocate_value (SYMBOL_TYPE (var));
353 VALUE_LVAL (retval) = not_lval;
354 set_value_optimized_out (retval, 1);
355 return retval;
356 }
357
358 baton.frame = frame;
359 baton.objfile = dwarf2_per_cu_objfile (per_cu);
360
361 ctx = new_dwarf_expr_context ();
362 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
363
364 ctx->gdbarch = get_objfile_arch (baton.objfile);
365 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
366 ctx->baton = &baton;
367 ctx->read_reg = dwarf_expr_read_reg;
368 ctx->read_mem = dwarf_expr_read_mem;
369 ctx->get_frame_base = dwarf_expr_frame_base;
370 ctx->get_frame_cfa = dwarf_expr_frame_cfa;
371 ctx->get_tls_address = dwarf_expr_tls_address;
372
373 dwarf_expr_eval (ctx, data, size);
374 if (ctx->num_pieces > 0)
375 {
376 struct piece_closure *c;
377 struct frame_id frame_id = get_frame_id (frame);
378
379 c = allocate_piece_closure (ctx->num_pieces, ctx->pieces);
380 retval = allocate_computed_value (SYMBOL_TYPE (var),
381 &pieced_value_funcs,
382 c);
383 VALUE_FRAME_ID (retval) = frame_id;
384 }
385 else if (ctx->in_reg)
386 {
387 struct gdbarch *arch = get_frame_arch (frame);
388 CORE_ADDR dwarf_regnum = dwarf_expr_fetch (ctx, 0);
389 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
390 retval = value_from_register (SYMBOL_TYPE (var), gdb_regnum, frame);
391 }
392 else
393 {
394 CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
395
396 retval = allocate_value (SYMBOL_TYPE (var));
397 VALUE_LVAL (retval) = lval_memory;
398 set_value_lazy (retval, 1);
399 set_value_stack (retval, 1);
400 set_value_address (retval, address);
401 }
402
403 set_value_initialized (retval, ctx->initialized);
404
405 do_cleanups (old_chain);
406
407 return retval;
408 }
409
410
411
412
413 \f
414 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
415
416 struct needs_frame_baton
417 {
418 int needs_frame;
419 };
420
421 /* Reads from registers do require a frame. */
422 static CORE_ADDR
423 needs_frame_read_reg (void *baton, int regnum)
424 {
425 struct needs_frame_baton *nf_baton = baton;
426 nf_baton->needs_frame = 1;
427 return 1;
428 }
429
430 /* Reads from memory do not require a frame. */
431 static void
432 needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
433 {
434 memset (buf, 0, len);
435 }
436
437 /* Frame-relative accesses do require a frame. */
438 static void
439 needs_frame_frame_base (void *baton, gdb_byte **start, size_t * length)
440 {
441 static gdb_byte lit0 = DW_OP_lit0;
442 struct needs_frame_baton *nf_baton = baton;
443
444 *start = &lit0;
445 *length = 1;
446
447 nf_baton->needs_frame = 1;
448 }
449
450 /* CFA accesses require a frame. */
451
452 static CORE_ADDR
453 needs_frame_frame_cfa (void *baton)
454 {
455 struct needs_frame_baton *nf_baton = baton;
456 nf_baton->needs_frame = 1;
457 return 1;
458 }
459
460 /* Thread-local accesses do require a frame. */
461 static CORE_ADDR
462 needs_frame_tls_address (void *baton, CORE_ADDR offset)
463 {
464 struct needs_frame_baton *nf_baton = baton;
465 nf_baton->needs_frame = 1;
466 return 1;
467 }
468
469 /* Return non-zero iff the location expression at DATA (length SIZE)
470 requires a frame to evaluate. */
471
472 static int
473 dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size,
474 struct dwarf2_per_cu_data *per_cu)
475 {
476 struct needs_frame_baton baton;
477 struct dwarf_expr_context *ctx;
478 int in_reg;
479 struct cleanup *old_chain;
480
481 baton.needs_frame = 0;
482
483 ctx = new_dwarf_expr_context ();
484 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
485
486 ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
487 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
488 ctx->baton = &baton;
489 ctx->read_reg = needs_frame_read_reg;
490 ctx->read_mem = needs_frame_read_mem;
491 ctx->get_frame_base = needs_frame_frame_base;
492 ctx->get_frame_cfa = needs_frame_frame_cfa;
493 ctx->get_tls_address = needs_frame_tls_address;
494
495 dwarf_expr_eval (ctx, data, size);
496
497 in_reg = ctx->in_reg;
498
499 if (ctx->num_pieces > 0)
500 {
501 int i;
502
503 /* If the location has several pieces, and any of them are in
504 registers, then we will need a frame to fetch them from. */
505 for (i = 0; i < ctx->num_pieces; i++)
506 if (ctx->pieces[i].in_reg)
507 in_reg = 1;
508 }
509
510 do_cleanups (old_chain);
511
512 return baton.needs_frame || in_reg;
513 }
514
515 static void
516 dwarf2_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
517 struct agent_expr *ax, struct axs_value *value,
518 gdb_byte *data, int size)
519 {
520 if (size == 0)
521 error (_("Symbol \"%s\" has been optimized out."),
522 SYMBOL_PRINT_NAME (symbol));
523
524 if (size == 1
525 && data[0] >= DW_OP_reg0
526 && data[0] <= DW_OP_reg31)
527 {
528 value->kind = axs_lvalue_register;
529 value->u.reg = data[0] - DW_OP_reg0;
530 }
531 else if (data[0] == DW_OP_regx)
532 {
533 ULONGEST reg;
534 read_uleb128 (data + 1, data + size, &reg);
535 value->kind = axs_lvalue_register;
536 value->u.reg = reg;
537 }
538 else if (data[0] == DW_OP_fbreg)
539 {
540 /* And this is worse than just minimal; we should honor the frame base
541 as above. */
542 int frame_reg;
543 LONGEST frame_offset;
544 gdb_byte *buf_end;
545
546 buf_end = read_sleb128 (data + 1, data + size, &frame_offset);
547 if (buf_end != data + size)
548 error (_("Unexpected opcode after DW_OP_fbreg for symbol \"%s\"."),
549 SYMBOL_PRINT_NAME (symbol));
550
551 gdbarch_virtual_frame_pointer (gdbarch,
552 ax->scope, &frame_reg, &frame_offset);
553 ax_reg (ax, frame_reg);
554 ax_const_l (ax, frame_offset);
555 ax_simple (ax, aop_add);
556
557 value->kind = axs_lvalue_memory;
558 }
559 else if (data[0] >= DW_OP_breg0
560 && data[0] <= DW_OP_breg31)
561 {
562 unsigned int reg;
563 LONGEST offset;
564 gdb_byte *buf_end;
565
566 reg = data[0] - DW_OP_breg0;
567 buf_end = read_sleb128 (data + 1, data + size, &offset);
568 if (buf_end != data + size)
569 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
570 reg, SYMBOL_PRINT_NAME (symbol));
571
572 ax_reg (ax, reg);
573 ax_const_l (ax, offset);
574 ax_simple (ax, aop_add);
575
576 value->kind = axs_lvalue_memory;
577 }
578 else
579 error (_("Unsupported DWARF opcode 0x%x in the location of \"%s\"."),
580 data[0], SYMBOL_PRINT_NAME (symbol));
581 }
582 \f
583 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
584 evaluator to calculate the location. */
585 static struct value *
586 locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
587 {
588 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
589 struct value *val;
590 val = dwarf2_evaluate_loc_desc (symbol, frame, dlbaton->data, dlbaton->size,
591 dlbaton->per_cu);
592
593 return val;
594 }
595
596 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
597 static int
598 locexpr_read_needs_frame (struct symbol *symbol)
599 {
600 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
601 return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size,
602 dlbaton->per_cu);
603 }
604
605 /* Print a natural-language description of SYMBOL to STREAM. */
606 static int
607 locexpr_describe_location (struct symbol *symbol, struct ui_file *stream)
608 {
609 /* FIXME: be more extensive. */
610 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
611 int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
612
613 if (dlbaton->size == 1
614 && dlbaton->data[0] >= DW_OP_reg0
615 && dlbaton->data[0] <= DW_OP_reg31)
616 {
617 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
618 struct gdbarch *gdbarch = get_objfile_arch (objfile);
619 int regno = gdbarch_dwarf2_reg_to_regnum (gdbarch,
620 dlbaton->data[0] - DW_OP_reg0);
621 fprintf_filtered (stream,
622 "a variable in register %s",
623 gdbarch_register_name (gdbarch, regno));
624 return 1;
625 }
626
627 /* The location expression for a TLS variable looks like this (on a
628 64-bit LE machine):
629
630 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
631 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
632
633 0x3 is the encoding for DW_OP_addr, which has an operand as long
634 as the size of an address on the target machine (here is 8
635 bytes). 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
636 The operand represents the offset at which the variable is within
637 the thread local storage. */
638
639 if (dlbaton->size > 1
640 && dlbaton->data[dlbaton->size - 1] == DW_OP_GNU_push_tls_address)
641 if (dlbaton->data[0] == DW_OP_addr)
642 {
643 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
644 struct gdbarch *gdbarch = get_objfile_arch (objfile);
645 CORE_ADDR offset = dwarf2_read_address (gdbarch,
646 &dlbaton->data[1],
647 &dlbaton->data[dlbaton->size - 1],
648 addr_size);
649 fprintf_filtered (stream,
650 "a thread-local variable at offset %s in the "
651 "thread-local storage for `%s'",
652 paddress (gdbarch, offset), objfile->name);
653 return 1;
654 }
655
656
657 fprintf_filtered (stream,
658 "a variable with complex or multiple locations (DWARF2)");
659 return 1;
660 }
661
662
663 /* Describe the location of SYMBOL as an agent value in VALUE, generating
664 any necessary bytecode in AX.
665
666 NOTE drow/2003-02-26: This function is extremely minimal, because
667 doing it correctly is extremely complicated and there is no
668 publicly available stub with tracepoint support for me to test
669 against. When there is one this function should be revisited. */
670
671 static void
672 locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
673 struct agent_expr *ax, struct axs_value *value)
674 {
675 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
676
677 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value,
678 dlbaton->data, dlbaton->size);
679 }
680
681 /* The set of location functions used with the DWARF-2 expression
682 evaluator. */
683 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
684 locexpr_read_variable,
685 locexpr_read_needs_frame,
686 locexpr_describe_location,
687 locexpr_tracepoint_var_ref
688 };
689
690
691 /* Wrapper functions for location lists. These generally find
692 the appropriate location expression and call something above. */
693
694 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
695 evaluator to calculate the location. */
696 static struct value *
697 loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
698 {
699 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
700 struct value *val;
701 gdb_byte *data;
702 size_t size;
703
704 data = find_location_expression (dlbaton, &size,
705 frame ? get_frame_address_in_block (frame)
706 : 0);
707 if (data == NULL)
708 {
709 val = allocate_value (SYMBOL_TYPE (symbol));
710 VALUE_LVAL (val) = not_lval;
711 set_value_optimized_out (val, 1);
712 }
713 else
714 val = dwarf2_evaluate_loc_desc (symbol, frame, data, size,
715 dlbaton->per_cu);
716
717 return val;
718 }
719
720 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
721 static int
722 loclist_read_needs_frame (struct symbol *symbol)
723 {
724 /* If there's a location list, then assume we need to have a frame
725 to choose the appropriate location expression. With tracking of
726 global variables this is not necessarily true, but such tracking
727 is disabled in GCC at the moment until we figure out how to
728 represent it. */
729
730 return 1;
731 }
732
733 /* Print a natural-language description of SYMBOL to STREAM. */
734 static int
735 loclist_describe_location (struct symbol *symbol, struct ui_file *stream)
736 {
737 /* FIXME: Could print the entire list of locations. */
738 fprintf_filtered (stream, "a variable with multiple locations");
739 return 1;
740 }
741
742 /* Describe the location of SYMBOL as an agent value in VALUE, generating
743 any necessary bytecode in AX. */
744 static void
745 loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
746 struct agent_expr *ax, struct axs_value *value)
747 {
748 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
749 gdb_byte *data;
750 size_t size;
751
752 data = find_location_expression (dlbaton, &size, ax->scope);
753 if (data == NULL)
754 error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol));
755
756 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value, data, size);
757 }
758
759 /* The set of location functions used with the DWARF-2 expression
760 evaluator and location lists. */
761 const struct symbol_computed_ops dwarf2_loclist_funcs = {
762 loclist_read_variable,
763 loclist_read_needs_frame,
764 loclist_describe_location,
765 loclist_tracepoint_var_ref
766 };
This page took 0.045408 seconds and 5 git commands to generate.