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