* infrun.c (wait_for_inferior): Invalidate registers and overlay
[deliverable/binutils-gdb.git] / gdb / dwarf2loc.c
CommitLineData
4c2df51b 1/* DWARF 2 location expression support for GDB.
feb13ab0 2
0fb0cc75 3 Copyright (C) 2003, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
feb13ab0 4
4c2df51b
DJ
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
a9762ec7
JB
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
4c2df51b 13
a9762ec7
JB
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.
4c2df51b
DJ
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4c2df51b
DJ
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"
a55cc764
DJ
29#include "ax.h"
30#include "ax-gdb.h"
e4adbba9 31#include "regcache.h"
c3228f12 32#include "objfiles.h"
93ad78a7 33#include "exceptions.h"
edb3359d 34#include "block.h"
4c2df51b 35
fa8f86ff 36#include "dwarf2.h"
4c2df51b
DJ
37#include "dwarf2expr.h"
38#include "dwarf2loc.h"
39
40#include "gdb_string.h"
eff4f95e 41#include "gdb_assert.h"
4c2df51b 42
0d53c4c4
DJ
43/* A helper function for dealing with location lists. Given a
44 symbol baton (BATON) and a pc value (PC), find the appropriate
45 location expression, set *LOCEXPR_LENGTH, and return a pointer
46 to the beginning of the expression. Returns NULL on failure.
47
48 For now, only return the first matching location expression; there
49 can be more than one in the list. */
50
852483bc 51static gdb_byte *
0d53c4c4 52find_location_expression (struct dwarf2_loclist_baton *baton,
b6b08ebf 53 size_t *locexpr_length, CORE_ADDR pc)
0d53c4c4 54{
0d53c4c4 55 CORE_ADDR low, high;
852483bc
MK
56 gdb_byte *loc_ptr, *buf_end;
57 int length;
ae0d2f24 58 struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
f7fd4728 59 struct gdbarch *gdbarch = get_objfile_arch (objfile);
e17a4113 60 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
ae0d2f24 61 unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
0d53c4c4 62 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
8edfa926 63 /* Adjust base_address for relocatable objects. */
ae0d2f24
UW
64 CORE_ADDR base_offset = ANOFFSET (objfile->section_offsets,
65 SECT_OFF_TEXT (objfile));
8edfa926 66 CORE_ADDR base_address = baton->base_address + base_offset;
0d53c4c4
DJ
67
68 loc_ptr = baton->data;
69 buf_end = baton->data + baton->size;
70
71 while (1)
72 {
f7fd4728 73 low = dwarf2_read_address (gdbarch, loc_ptr, buf_end, addr_size);
ae0d2f24 74 loc_ptr += addr_size;
f7fd4728 75 high = dwarf2_read_address (gdbarch, loc_ptr, buf_end, addr_size);
ae0d2f24 76 loc_ptr += addr_size;
0d53c4c4
DJ
77
78 /* An end-of-list entry. */
79 if (low == 0 && high == 0)
80 return NULL;
81
82 /* A base-address-selection entry. */
83 if ((low & base_mask) == base_mask)
84 {
85 base_address = high;
86 continue;
87 }
88
89 /* Otherwise, a location expression entry. */
90 low += base_address;
91 high += base_address;
92
e17a4113 93 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
0d53c4c4
DJ
94 loc_ptr += 2;
95
96 if (pc >= low && pc < high)
97 {
98 *locexpr_length = length;
99 return loc_ptr;
100 }
101
102 loc_ptr += length;
103 }
104}
105
4c2df51b
DJ
106/* This is the baton used when performing dwarf2 expression
107 evaluation. */
108struct dwarf_expr_baton
109{
110 struct frame_info *frame;
111 struct objfile *objfile;
112};
113
114/* Helper functions for dwarf2_evaluate_loc_desc. */
115
4bc9efe1 116/* Using the frame specified in BATON, return the value of register
0b2b0195 117 REGNUM, treated as a pointer. */
4c2df51b 118static CORE_ADDR
61fbb938 119dwarf_expr_read_reg (void *baton, int dwarf_regnum)
4c2df51b 120{
4c2df51b 121 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
5e2b427d 122 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
e5192dd8 123 CORE_ADDR result;
0b2b0195 124 int regnum;
e4adbba9 125
5e2b427d
UW
126 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
127 result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
0b2b0195 128 regnum, debaton->frame);
4c2df51b
DJ
129 return result;
130}
131
132/* Read memory at ADDR (length LEN) into BUF. */
133
134static void
852483bc 135dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
4c2df51b
DJ
136{
137 read_memory (addr, buf, len);
138}
139
140/* Using the frame specified in BATON, find the location expression
141 describing the frame base. Return a pointer to it in START and
142 its length in LENGTH. */
143static void
852483bc 144dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
4c2df51b 145{
da62e633
AC
146 /* FIXME: cagney/2003-03-26: This code should be using
147 get_frame_base_address(), and then implement a dwarf2 specific
148 this_base method. */
4c2df51b 149 struct symbol *framefunc;
4c2df51b 150 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
0d53c4c4 151
edb3359d
DJ
152 /* Use block_linkage_function, which returns a real (not inlined)
153 function, instead of get_frame_function, which may return an
154 inlined function. */
155 framefunc = block_linkage_function (get_frame_block (debaton->frame, NULL));
0d53c4c4 156
eff4f95e
JG
157 /* If we found a frame-relative symbol then it was certainly within
158 some function associated with a frame. If we can't find the frame,
159 something has gone wrong. */
160 gdb_assert (framefunc != NULL);
161
edb3359d
DJ
162 if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
163 *start = NULL;
164 else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
0d53c4c4
DJ
165 {
166 struct dwarf2_loclist_baton *symbaton;
22c6caba
JW
167 struct frame_info *frame = debaton->frame;
168
0d53c4c4
DJ
169 symbaton = SYMBOL_LOCATION_BATON (framefunc);
170 *start = find_location_expression (symbaton, length,
22c6caba 171 get_frame_address_in_block (frame));
0d53c4c4
DJ
172 }
173 else
174 {
175 struct dwarf2_locexpr_baton *symbaton;
176 symbaton = SYMBOL_LOCATION_BATON (framefunc);
ebd3bcc1
JK
177 if (symbaton != NULL)
178 {
179 *length = symbaton->size;
180 *start = symbaton->data;
181 }
182 else
183 *start = NULL;
0d53c4c4
DJ
184 }
185
186 if (*start == NULL)
8a3fe4f8 187 error (_("Could not find the frame base for \"%s\"."),
0d53c4c4 188 SYMBOL_NATURAL_NAME (framefunc));
4c2df51b
DJ
189}
190
191/* Using the objfile specified in BATON, find the address for the
192 current thread's thread-local storage with offset OFFSET. */
193static CORE_ADDR
194dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
195{
196 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
4c2df51b 197
9e35dae4 198 return target_translate_tls_address (debaton->objfile, offset);
4c2df51b
DJ
199}
200
201/* Evaluate a location description, starting at DATA and with length
202 SIZE, to find the current location of variable VAR in the context
203 of FRAME. */
204static struct value *
205dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
852483bc 206 gdb_byte *data, unsigned short size,
ae0d2f24 207 struct dwarf2_per_cu_data *per_cu)
4c2df51b 208{
4c2df51b
DJ
209 struct value *retval;
210 struct dwarf_expr_baton baton;
211 struct dwarf_expr_context *ctx;
212
0d53c4c4
DJ
213 if (size == 0)
214 {
215 retval = allocate_value (SYMBOL_TYPE (var));
216 VALUE_LVAL (retval) = not_lval;
feb13ab0 217 set_value_optimized_out (retval, 1);
10fb19b6 218 return retval;
0d53c4c4
DJ
219 }
220
4c2df51b 221 baton.frame = frame;
ae0d2f24 222 baton.objfile = dwarf2_per_cu_objfile (per_cu);
4c2df51b
DJ
223
224 ctx = new_dwarf_expr_context ();
f7fd4728 225 ctx->gdbarch = get_objfile_arch (baton.objfile);
ae0d2f24 226 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4c2df51b
DJ
227 ctx->baton = &baton;
228 ctx->read_reg = dwarf_expr_read_reg;
229 ctx->read_mem = dwarf_expr_read_mem;
230 ctx->get_frame_base = dwarf_expr_frame_base;
231 ctx->get_tls_address = dwarf_expr_tls_address;
232
233 dwarf_expr_eval (ctx, data, size);
87808bd6
JB
234 if (ctx->num_pieces > 0)
235 {
23572eca
EZ
236 int i;
237 long offset = 0;
238 bfd_byte *contents;
239
240 retval = allocate_value (SYMBOL_TYPE (var));
241 contents = value_contents_raw (retval);
242 for (i = 0; i < ctx->num_pieces; i++)
243 {
244 struct dwarf_expr_piece *p = &ctx->pieces[i];
245 if (p->in_reg)
246 {
77a732d9 247 struct gdbarch *arch = get_frame_arch (frame);
23572eca 248 bfd_byte regval[MAX_REGISTER_SIZE];
77a732d9 249 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->value);
23572eca
EZ
250 get_frame_register (frame, gdb_regnum, regval);
251 memcpy (contents + offset, regval, p->size);
252 }
253 else /* In memory? */
254 {
255 read_memory (p->value, contents + offset, p->size);
256 }
257 offset += p->size;
258 }
87808bd6
JB
259 }
260 else if (ctx->in_reg)
051caad9 261 {
77a732d9 262 struct gdbarch *arch = get_frame_arch (frame);
5ca2e327 263 CORE_ADDR dwarf_regnum = dwarf_expr_fetch (ctx, 0);
77a732d9 264 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
5ca2e327 265 retval = value_from_register (SYMBOL_TYPE (var), gdb_regnum, frame);
051caad9 266 }
4c2df51b
DJ
267 else
268 {
5ca2e327
JB
269 CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
270
61fbb938 271 retval = allocate_value (SYMBOL_TYPE (var));
4c2df51b 272 VALUE_LVAL (retval) = lval_memory;
dfa52d88 273 set_value_lazy (retval, 1);
42ae5230 274 set_value_address (retval, address);
4c2df51b
DJ
275 }
276
42be36b3
CT
277 set_value_initialized (retval, ctx->initialized);
278
4c2df51b
DJ
279 free_dwarf_expr_context (ctx);
280
281 return retval;
282}
283
284
285
286
287\f
288/* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
289
290struct needs_frame_baton
291{
292 int needs_frame;
293};
294
295/* Reads from registers do require a frame. */
296static CORE_ADDR
61fbb938 297needs_frame_read_reg (void *baton, int regnum)
4c2df51b
DJ
298{
299 struct needs_frame_baton *nf_baton = baton;
300 nf_baton->needs_frame = 1;
301 return 1;
302}
303
304/* Reads from memory do not require a frame. */
305static void
852483bc 306needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
4c2df51b
DJ
307{
308 memset (buf, 0, len);
309}
310
311/* Frame-relative accesses do require a frame. */
312static void
852483bc 313needs_frame_frame_base (void *baton, gdb_byte **start, size_t * length)
4c2df51b 314{
852483bc 315 static gdb_byte lit0 = DW_OP_lit0;
4c2df51b
DJ
316 struct needs_frame_baton *nf_baton = baton;
317
318 *start = &lit0;
319 *length = 1;
320
321 nf_baton->needs_frame = 1;
322}
323
324/* Thread-local accesses do require a frame. */
325static CORE_ADDR
326needs_frame_tls_address (void *baton, CORE_ADDR offset)
327{
328 struct needs_frame_baton *nf_baton = baton;
329 nf_baton->needs_frame = 1;
330 return 1;
331}
332
333/* Return non-zero iff the location expression at DATA (length SIZE)
334 requires a frame to evaluate. */
335
336static int
ae0d2f24
UW
337dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size,
338 struct dwarf2_per_cu_data *per_cu)
4c2df51b
DJ
339{
340 struct needs_frame_baton baton;
341 struct dwarf_expr_context *ctx;
f630a401 342 int in_reg;
4c2df51b
DJ
343
344 baton.needs_frame = 0;
345
346 ctx = new_dwarf_expr_context ();
f7fd4728 347 ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
ae0d2f24 348 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4c2df51b
DJ
349 ctx->baton = &baton;
350 ctx->read_reg = needs_frame_read_reg;
351 ctx->read_mem = needs_frame_read_mem;
352 ctx->get_frame_base = needs_frame_frame_base;
353 ctx->get_tls_address = needs_frame_tls_address;
354
355 dwarf_expr_eval (ctx, data, size);
356
f630a401
DJ
357 in_reg = ctx->in_reg;
358
87808bd6
JB
359 if (ctx->num_pieces > 0)
360 {
361 int i;
362
363 /* If the location has several pieces, and any of them are in
364 registers, then we will need a frame to fetch them from. */
365 for (i = 0; i < ctx->num_pieces; i++)
366 if (ctx->pieces[i].in_reg)
367 in_reg = 1;
368 }
369
4c2df51b
DJ
370 free_dwarf_expr_context (ctx);
371
f630a401 372 return baton.needs_frame || in_reg;
4c2df51b
DJ
373}
374
0d53c4c4 375static void
505e835d
UW
376dwarf2_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
377 struct agent_expr *ax, struct axs_value *value,
378 gdb_byte *data, int size)
0d53c4c4
DJ
379{
380 if (size == 0)
8a3fe4f8 381 error (_("Symbol \"%s\" has been optimized out."),
0d53c4c4
DJ
382 SYMBOL_PRINT_NAME (symbol));
383
384 if (size == 1
385 && data[0] >= DW_OP_reg0
386 && data[0] <= DW_OP_reg31)
387 {
388 value->kind = axs_lvalue_register;
389 value->u.reg = data[0] - DW_OP_reg0;
390 }
391 else if (data[0] == DW_OP_regx)
392 {
393 ULONGEST reg;
394 read_uleb128 (data + 1, data + size, &reg);
395 value->kind = axs_lvalue_register;
396 value->u.reg = reg;
397 }
398 else if (data[0] == DW_OP_fbreg)
399 {
400 /* And this is worse than just minimal; we should honor the frame base
401 as above. */
402 int frame_reg;
403 LONGEST frame_offset;
852483bc 404 gdb_byte *buf_end;
0d53c4c4
DJ
405
406 buf_end = read_sleb128 (data + 1, data + size, &frame_offset);
407 if (buf_end != data + size)
8a3fe4f8 408 error (_("Unexpected opcode after DW_OP_fbreg for symbol \"%s\"."),
0d53c4c4 409 SYMBOL_PRINT_NAME (symbol));
4c2df51b 410
505e835d 411 gdbarch_virtual_frame_pointer (gdbarch,
c7bb205c 412 ax->scope, &frame_reg, &frame_offset);
0d53c4c4
DJ
413 ax_reg (ax, frame_reg);
414 ax_const_l (ax, frame_offset);
415 ax_simple (ax, aop_add);
4c2df51b 416
9c238357
RC
417 value->kind = axs_lvalue_memory;
418 }
419 else if (data[0] >= DW_OP_breg0
420 && data[0] <= DW_OP_breg31)
421 {
422 unsigned int reg;
423 LONGEST offset;
424 gdb_byte *buf_end;
425
426 reg = data[0] - DW_OP_breg0;
427 buf_end = read_sleb128 (data + 1, data + size, &offset);
428 if (buf_end != data + size)
429 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
430 reg, SYMBOL_PRINT_NAME (symbol));
431
432 ax_reg (ax, reg);
433 ax_const_l (ax, offset);
0d53c4c4 434 ax_simple (ax, aop_add);
9c238357 435
0d53c4c4
DJ
436 value->kind = axs_lvalue_memory;
437 }
438 else
9c238357
RC
439 error (_("Unsupported DWARF opcode 0x%x in the location of \"%s\"."),
440 data[0], SYMBOL_PRINT_NAME (symbol));
0d53c4c4 441}
4c2df51b
DJ
442\f
443/* Return the value of SYMBOL in FRAME using the DWARF-2 expression
444 evaluator to calculate the location. */
445static struct value *
446locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
447{
448 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
449 struct value *val;
450 val = dwarf2_evaluate_loc_desc (symbol, frame, dlbaton->data, dlbaton->size,
ae0d2f24 451 dlbaton->per_cu);
4c2df51b
DJ
452
453 return val;
454}
455
456/* Return non-zero iff we need a frame to evaluate SYMBOL. */
457static int
458locexpr_read_needs_frame (struct symbol *symbol)
459{
460 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
ae0d2f24
UW
461 return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size,
462 dlbaton->per_cu);
4c2df51b
DJ
463}
464
465/* Print a natural-language description of SYMBOL to STREAM. */
466static int
467locexpr_describe_location (struct symbol *symbol, struct ui_file *stream)
468{
469 /* FIXME: be more extensive. */
470 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
ae0d2f24 471 int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
4c2df51b
DJ
472
473 if (dlbaton->size == 1
474 && dlbaton->data[0] >= DW_OP_reg0
475 && dlbaton->data[0] <= DW_OP_reg31)
476 {
5e2b427d
UW
477 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
478 struct gdbarch *gdbarch = get_objfile_arch (objfile);
479 int regno = gdbarch_dwarf2_reg_to_regnum (gdbarch,
480 dlbaton->data[0] - DW_OP_reg0);
4c2df51b 481 fprintf_filtered (stream,
c9f4d572 482 "a variable in register %s",
5e2b427d 483 gdbarch_register_name (gdbarch, regno));
4c2df51b
DJ
484 return 1;
485 }
486
c3228f12
EZ
487 /* The location expression for a TLS variable looks like this (on a
488 64-bit LE machine):
489
490 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
491 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
492
493 0x3 is the encoding for DW_OP_addr, which has an operand as long
494 as the size of an address on the target machine (here is 8
495 bytes). 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
496 The operand represents the offset at which the variable is within
497 the thread local storage. */
498
499 if (dlbaton->size > 1
500 && dlbaton->data[dlbaton->size - 1] == DW_OP_GNU_push_tls_address)
501 if (dlbaton->data[0] == DW_OP_addr)
502 {
ae0d2f24 503 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
f7fd4728
UW
504 struct gdbarch *gdbarch = get_objfile_arch (objfile);
505 CORE_ADDR offset = dwarf2_read_address (gdbarch,
506 &dlbaton->data[1],
c193f044 507 &dlbaton->data[dlbaton->size - 1],
ae0d2f24 508 addr_size);
c3228f12 509 fprintf_filtered (stream,
32ffcbed 510 "a thread-local variable at offset %s in the "
c3228f12 511 "thread-local storage for `%s'",
5af949e3 512 paddress (gdbarch, offset), objfile->name);
c3228f12
EZ
513 return 1;
514 }
515
516
4c2df51b
DJ
517 fprintf_filtered (stream,
518 "a variable with complex or multiple locations (DWARF2)");
519 return 1;
520}
521
a55cc764
DJ
522
523/* Describe the location of SYMBOL as an agent value in VALUE, generating
524 any necessary bytecode in AX.
525
526 NOTE drow/2003-02-26: This function is extremely minimal, because
527 doing it correctly is extremely complicated and there is no
528 publicly available stub with tracepoint support for me to test
529 against. When there is one this function should be revisited. */
530
0d53c4c4 531static void
505e835d
UW
532locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
533 struct agent_expr *ax, struct axs_value *value)
a55cc764
DJ
534{
535 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
536
505e835d
UW
537 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value,
538 dlbaton->data, dlbaton->size);
a55cc764
DJ
539}
540
4c2df51b
DJ
541/* The set of location functions used with the DWARF-2 expression
542 evaluator. */
768a979c 543const struct symbol_computed_ops dwarf2_locexpr_funcs = {
4c2df51b
DJ
544 locexpr_read_variable,
545 locexpr_read_needs_frame,
546 locexpr_describe_location,
a55cc764 547 locexpr_tracepoint_var_ref
4c2df51b 548};
0d53c4c4
DJ
549
550
551/* Wrapper functions for location lists. These generally find
552 the appropriate location expression and call something above. */
553
554/* Return the value of SYMBOL in FRAME using the DWARF-2 expression
555 evaluator to calculate the location. */
556static struct value *
557loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
558{
559 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
560 struct value *val;
852483bc 561 gdb_byte *data;
b6b08ebf 562 size_t size;
0d53c4c4
DJ
563
564 data = find_location_expression (dlbaton, &size,
22c6caba
JW
565 frame ? get_frame_address_in_block (frame)
566 : 0);
0d53c4c4 567 if (data == NULL)
806048c6
DJ
568 {
569 val = allocate_value (SYMBOL_TYPE (symbol));
570 VALUE_LVAL (val) = not_lval;
571 set_value_optimized_out (val, 1);
572 }
573 else
574 val = dwarf2_evaluate_loc_desc (symbol, frame, data, size,
ae0d2f24 575 dlbaton->per_cu);
0d53c4c4
DJ
576
577 return val;
578}
579
580/* Return non-zero iff we need a frame to evaluate SYMBOL. */
581static int
582loclist_read_needs_frame (struct symbol *symbol)
583{
584 /* If there's a location list, then assume we need to have a frame
585 to choose the appropriate location expression. With tracking of
586 global variables this is not necessarily true, but such tracking
587 is disabled in GCC at the moment until we figure out how to
588 represent it. */
589
590 return 1;
591}
592
593/* Print a natural-language description of SYMBOL to STREAM. */
594static int
595loclist_describe_location (struct symbol *symbol, struct ui_file *stream)
596{
597 /* FIXME: Could print the entire list of locations. */
598 fprintf_filtered (stream, "a variable with multiple locations");
599 return 1;
600}
601
602/* Describe the location of SYMBOL as an agent value in VALUE, generating
603 any necessary bytecode in AX. */
604static void
505e835d
UW
605loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
606 struct agent_expr *ax, struct axs_value *value)
0d53c4c4
DJ
607{
608 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
852483bc 609 gdb_byte *data;
b6b08ebf 610 size_t size;
0d53c4c4
DJ
611
612 data = find_location_expression (dlbaton, &size, ax->scope);
613 if (data == NULL)
8a3fe4f8 614 error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol));
0d53c4c4 615
505e835d 616 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value, data, size);
0d53c4c4
DJ
617}
618
619/* The set of location functions used with the DWARF-2 expression
620 evaluator and location lists. */
768a979c 621const struct symbol_computed_ops dwarf2_loclist_funcs = {
0d53c4c4
DJ
622 loclist_read_variable,
623 loclist_read_needs_frame,
624 loclist_describe_location,
625 loclist_tracepoint_var_ref
626};
This page took 0.465269 seconds and 4 git commands to generate.