* coffcode.h (coff_write_object_contents): Enclose all occurrences
[deliverable/binutils-gdb.git] / gdb / dwarf2loc.c
CommitLineData
4c2df51b 1/* DWARF 2 location expression support for GDB.
feb13ab0 2
4c38e0a4
JB
3 Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
feb13ab0 5
4c2df51b
DJ
6 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7
8 This file is part of GDB.
9
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
a9762ec7
JB
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
4c2df51b 14
a9762ec7
JB
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.
4c2df51b
DJ
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4c2df51b
DJ
22
23#include "defs.h"
24#include "ui-out.h"
25#include "value.h"
26#include "frame.h"
27#include "gdbcore.h"
28#include "target.h"
29#include "inferior.h"
a55cc764
DJ
30#include "ax.h"
31#include "ax-gdb.h"
e4adbba9 32#include "regcache.h"
c3228f12 33#include "objfiles.h"
93ad78a7 34#include "exceptions.h"
edb3359d 35#include "block.h"
4c2df51b 36
fa8f86ff 37#include "dwarf2.h"
4c2df51b
DJ
38#include "dwarf2expr.h"
39#include "dwarf2loc.h"
e7802207 40#include "dwarf2-frame.h"
4c2df51b
DJ
41
42#include "gdb_string.h"
eff4f95e 43#include "gdb_assert.h"
4c2df51b 44
0936ad1d
SS
45static void
46dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
47 gdb_byte **start, size_t *length);
48
0d53c4c4
DJ
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.
53
54 For now, only return the first matching location expression; there
55 can be more than one in the list. */
56
852483bc 57static gdb_byte *
0d53c4c4 58find_location_expression (struct dwarf2_loclist_baton *baton,
b6b08ebf 59 size_t *locexpr_length, CORE_ADDR pc)
0d53c4c4 60{
0d53c4c4 61 CORE_ADDR low, high;
852483bc
MK
62 gdb_byte *loc_ptr, *buf_end;
63 int length;
ae0d2f24 64 struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
f7fd4728 65 struct gdbarch *gdbarch = get_objfile_arch (objfile);
e17a4113 66 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
ae0d2f24 67 unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
0d53c4c4 68 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
8edfa926 69 /* Adjust base_address for relocatable objects. */
ae0d2f24
UW
70 CORE_ADDR base_offset = ANOFFSET (objfile->section_offsets,
71 SECT_OFF_TEXT (objfile));
8edfa926 72 CORE_ADDR base_address = baton->base_address + base_offset;
0d53c4c4
DJ
73
74 loc_ptr = baton->data;
75 buf_end = baton->data + baton->size;
76
77 while (1)
78 {
b5758fe4
UW
79 if (buf_end - loc_ptr < 2 * addr_size)
80 error (_("find_location_expression: Corrupted DWARF expression."));
0d53c4c4 81
b5758fe4
UW
82 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
83 loc_ptr += addr_size;
0d53c4c4
DJ
84
85 /* A base-address-selection entry. */
b5758fe4 86 if (low == base_mask)
0d53c4c4 87 {
b5758fe4
UW
88 base_address = dwarf2_read_address (gdbarch,
89 loc_ptr, buf_end, addr_size);
90 loc_ptr += addr_size;
0d53c4c4
DJ
91 continue;
92 }
93
b5758fe4
UW
94 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
95 loc_ptr += addr_size;
96
97 /* An end-of-list entry. */
98 if (low == 0 && high == 0)
99 return NULL;
100
0d53c4c4
DJ
101 /* Otherwise, a location expression entry. */
102 low += base_address;
103 high += base_address;
104
e17a4113 105 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
0d53c4c4
DJ
106 loc_ptr += 2;
107
108 if (pc >= low && pc < high)
109 {
110 *locexpr_length = length;
111 return loc_ptr;
112 }
113
114 loc_ptr += length;
115 }
116}
117
4c2df51b
DJ
118/* This is the baton used when performing dwarf2 expression
119 evaluation. */
120struct dwarf_expr_baton
121{
122 struct frame_info *frame;
123 struct objfile *objfile;
124};
125
126/* Helper functions for dwarf2_evaluate_loc_desc. */
127
4bc9efe1 128/* Using the frame specified in BATON, return the value of register
0b2b0195 129 REGNUM, treated as a pointer. */
4c2df51b 130static CORE_ADDR
61fbb938 131dwarf_expr_read_reg (void *baton, int dwarf_regnum)
4c2df51b 132{
4c2df51b 133 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
5e2b427d 134 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
e5192dd8 135 CORE_ADDR result;
0b2b0195 136 int regnum;
e4adbba9 137
5e2b427d
UW
138 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
139 result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
0b2b0195 140 regnum, debaton->frame);
4c2df51b
DJ
141 return result;
142}
143
144/* Read memory at ADDR (length LEN) into BUF. */
145
146static void
852483bc 147dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
4c2df51b
DJ
148{
149 read_memory (addr, buf, len);
150}
151
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. */
155static void
852483bc 156dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
4c2df51b 157{
da62e633
AC
158 /* FIXME: cagney/2003-03-26: This code should be using
159 get_frame_base_address(), and then implement a dwarf2 specific
160 this_base method. */
4c2df51b 161 struct symbol *framefunc;
4c2df51b 162 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
0d53c4c4 163
edb3359d
DJ
164 /* Use block_linkage_function, which returns a real (not inlined)
165 function, instead of get_frame_function, which may return an
166 inlined function. */
167 framefunc = block_linkage_function (get_frame_block (debaton->frame, NULL));
0d53c4c4 168
eff4f95e
JG
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);
173
0936ad1d
SS
174 dwarf_expr_frame_base_1 (framefunc,
175 get_frame_address_in_block (debaton->frame),
176 start, length);
177}
178
179static void
180dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
181 gdb_byte **start, size_t *length)
182{
edb3359d
DJ
183 if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
184 *start = NULL;
185 else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
0d53c4c4
DJ
186 {
187 struct dwarf2_loclist_baton *symbaton;
22c6caba 188
0d53c4c4 189 symbaton = SYMBOL_LOCATION_BATON (framefunc);
0936ad1d 190 *start = find_location_expression (symbaton, length, pc);
0d53c4c4
DJ
191 }
192 else
193 {
194 struct dwarf2_locexpr_baton *symbaton;
195 symbaton = SYMBOL_LOCATION_BATON (framefunc);
ebd3bcc1
JK
196 if (symbaton != NULL)
197 {
198 *length = symbaton->size;
199 *start = symbaton->data;
200 }
201 else
202 *start = NULL;
0d53c4c4
DJ
203 }
204
205 if (*start == NULL)
8a3fe4f8 206 error (_("Could not find the frame base for \"%s\"."),
0d53c4c4 207 SYMBOL_NATURAL_NAME (framefunc));
4c2df51b
DJ
208}
209
e7802207
TT
210/* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
211 the frame in BATON. */
212
213static CORE_ADDR
214dwarf_expr_frame_cfa (void *baton)
215{
216 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
217 return dwarf2_frame_cfa (debaton->frame);
218}
219
4c2df51b
DJ
220/* Using the objfile specified in BATON, find the address for the
221 current thread's thread-local storage with offset OFFSET. */
222static CORE_ADDR
223dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
224{
225 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
4c2df51b 226
9e35dae4 227 return target_translate_tls_address (debaton->objfile, offset);
4c2df51b
DJ
228}
229
052b9502
NF
230struct piece_closure
231{
232 /* The number of pieces used to describe this variable. */
233 int n_pieces;
234
6063c216
UW
235 /* The target address size, used only for DWARF_VALUE_STACK. */
236 int addr_size;
cec03d70 237
052b9502
NF
238 /* The pieces themselves. */
239 struct dwarf_expr_piece *pieces;
240};
241
242/* Allocate a closure for a value formed from separately-described
243 PIECES. */
244
245static struct piece_closure *
cec03d70 246allocate_piece_closure (int n_pieces, struct dwarf_expr_piece *pieces,
6063c216 247 int addr_size)
052b9502
NF
248{
249 struct piece_closure *c = XZALLOC (struct piece_closure);
250
251 c->n_pieces = n_pieces;
6063c216 252 c->addr_size = addr_size;
052b9502
NF
253 c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
254
255 memcpy (c->pieces, pieces, n_pieces * sizeof (struct dwarf_expr_piece));
256
257 return c;
258}
259
260static void
261read_pieced_value (struct value *v)
262{
263 int i;
264 long offset = 0;
265 gdb_byte *contents;
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));
268
269 contents = value_contents_raw (v);
270 for (i = 0; i < c->n_pieces; i++)
271 {
272 struct dwarf_expr_piece *p = &c->pieces[i];
cec03d70 273 switch (p->location)
052b9502 274 {
cec03d70
TT
275 case DWARF_VALUE_REGISTER:
276 {
277 struct gdbarch *arch = get_frame_arch (frame);
cec03d70 278 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch,
44353522 279 p->v.expr.value);
dcbf108f
UW
280 int reg_offset = 0;
281
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;
286
63b4f126
MGD
287 if (gdb_regnum != -1)
288 {
289 get_frame_register_bytes (frame, gdb_regnum, reg_offset,
290 p->size, contents + offset);
291 }
292 else
293 {
294 error (_("Unable to access DWARF register number %s"),
295 paddress (arch, p->v.expr.value));
296 }
cec03d70
TT
297 }
298 break;
299
300 case DWARF_VALUE_MEMORY:
44353522
DE
301 if (p->v.expr.in_stack_memory)
302 read_stack (p->v.expr.value, contents + offset, p->size);
303 else
304 read_memory (p->v.expr.value, contents + offset, p->size);
cec03d70
TT
305 break;
306
307 case DWARF_VALUE_STACK:
308 {
6063c216
UW
309 struct gdbarch *gdbarch = get_type_arch (value_type (v));
310 size_t n = p->size;
311 if (n > c->addr_size)
312 n = c->addr_size;
05566b3b 313 store_unsigned_integer (contents + offset, n,
6063c216 314 gdbarch_byte_order (gdbarch),
05566b3b 315 p->v.expr.value);
cec03d70
TT
316 }
317 break;
318
319 case DWARF_VALUE_LITERAL:
320 {
321 size_t n = p->size;
322 if (n > p->v.literal.length)
323 n = p->v.literal.length;
324 memcpy (contents + offset, p->v.literal.data, n);
325 }
326 break;
327
328 default:
329 internal_error (__FILE__, __LINE__, _("invalid location type"));
052b9502
NF
330 }
331 offset += p->size;
332 }
333}
334
335static void
336write_pieced_value (struct value *to, struct value *from)
337{
338 int i;
339 long offset = 0;
340 gdb_byte *contents;
341 struct piece_closure *c = (struct piece_closure *) value_computed_closure (to);
342 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (to));
343
344 if (frame == NULL)
345 {
346 set_value_optimized_out (to, 1);
347 return;
348 }
349
350 contents = value_contents_raw (from);
351 for (i = 0; i < c->n_pieces; i++)
352 {
353 struct dwarf_expr_piece *p = &c->pieces[i];
cec03d70 354 switch (p->location)
052b9502 355 {
cec03d70
TT
356 case DWARF_VALUE_REGISTER:
357 {
358 struct gdbarch *arch = get_frame_arch (frame);
44353522 359 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.expr.value);
dcbf108f
UW
360 int reg_offset = 0;
361
362 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
363 && p->size < register_size (arch, gdb_regnum))
364 /* Big-endian, and we want less than full size. */
365 reg_offset = register_size (arch, gdb_regnum) - p->size;
366
63b4f126
MGD
367 if (gdb_regnum != -1)
368 {
369 put_frame_register_bytes (frame, gdb_regnum, reg_offset,
370 p->size, contents + offset);
371 }
372 else
373 {
374 error (_("Unable to write to DWARF register number %s"),
375 paddress (arch, p->v.expr.value));
376 }
cec03d70
TT
377 }
378 break;
379 case DWARF_VALUE_MEMORY:
44353522 380 write_memory (p->v.expr.value, contents + offset, p->size);
cec03d70
TT
381 break;
382 default:
383 set_value_optimized_out (to, 1);
384 return;
052b9502
NF
385 }
386 offset += p->size;
387 }
388}
389
390static void *
391copy_pieced_value_closure (struct value *v)
392{
393 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
394
6063c216 395 return allocate_piece_closure (c->n_pieces, c->pieces, c->addr_size);
052b9502
NF
396}
397
398static void
399free_pieced_value_closure (struct value *v)
400{
401 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
402
403 xfree (c->pieces);
404 xfree (c);
405}
406
407/* Functions for accessing a variable described by DW_OP_piece. */
408static struct lval_funcs pieced_value_funcs = {
409 read_pieced_value,
410 write_pieced_value,
411 copy_pieced_value_closure,
412 free_pieced_value_closure
413};
414
4c2df51b
DJ
415/* Evaluate a location description, starting at DATA and with length
416 SIZE, to find the current location of variable VAR in the context
417 of FRAME. */
418static struct value *
419dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
852483bc 420 gdb_byte *data, unsigned short size,
ae0d2f24 421 struct dwarf2_per_cu_data *per_cu)
4c2df51b 422{
4c2df51b
DJ
423 struct value *retval;
424 struct dwarf_expr_baton baton;
425 struct dwarf_expr_context *ctx;
4a227398 426 struct cleanup *old_chain;
4c2df51b 427
0d53c4c4
DJ
428 if (size == 0)
429 {
430 retval = allocate_value (SYMBOL_TYPE (var));
431 VALUE_LVAL (retval) = not_lval;
feb13ab0 432 set_value_optimized_out (retval, 1);
10fb19b6 433 return retval;
0d53c4c4
DJ
434 }
435
4c2df51b 436 baton.frame = frame;
ae0d2f24 437 baton.objfile = dwarf2_per_cu_objfile (per_cu);
4c2df51b
DJ
438
439 ctx = new_dwarf_expr_context ();
4a227398
TT
440 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
441
f7fd4728 442 ctx->gdbarch = get_objfile_arch (baton.objfile);
ae0d2f24 443 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4c2df51b
DJ
444 ctx->baton = &baton;
445 ctx->read_reg = dwarf_expr_read_reg;
446 ctx->read_mem = dwarf_expr_read_mem;
447 ctx->get_frame_base = dwarf_expr_frame_base;
e7802207 448 ctx->get_frame_cfa = dwarf_expr_frame_cfa;
4c2df51b
DJ
449 ctx->get_tls_address = dwarf_expr_tls_address;
450
451 dwarf_expr_eval (ctx, data, size);
87808bd6
JB
452 if (ctx->num_pieces > 0)
453 {
052b9502
NF
454 struct piece_closure *c;
455 struct frame_id frame_id = get_frame_id (frame);
456
6063c216
UW
457 c = allocate_piece_closure (ctx->num_pieces, ctx->pieces,
458 ctx->addr_size);
052b9502
NF
459 retval = allocate_computed_value (SYMBOL_TYPE (var),
460 &pieced_value_funcs,
461 c);
462 VALUE_FRAME_ID (retval) = frame_id;
87808bd6 463 }
4c2df51b
DJ
464 else
465 {
cec03d70
TT
466 switch (ctx->location)
467 {
468 case DWARF_VALUE_REGISTER:
469 {
470 struct gdbarch *arch = get_frame_arch (frame);
471 CORE_ADDR dwarf_regnum = dwarf_expr_fetch (ctx, 0);
472 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
63b4f126
MGD
473 if (gdb_regnum != -1)
474 {
475 retval = value_from_register (SYMBOL_TYPE (var),
476 gdb_regnum, frame);
477 }
478 else
479 {
480 error (_("Unable to access DWARF register number %s"),
481 paddress (arch, dwarf_regnum));
482 }
cec03d70
TT
483 }
484 break;
485
486 case DWARF_VALUE_MEMORY:
487 {
488 CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
44353522 489 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
cec03d70
TT
490
491 retval = allocate_value (SYMBOL_TYPE (var));
492 VALUE_LVAL (retval) = lval_memory;
493 set_value_lazy (retval, 1);
44353522
DE
494 if (in_stack_memory)
495 set_value_stack (retval, 1);
cec03d70
TT
496 set_value_address (retval, address);
497 }
498 break;
499
500 case DWARF_VALUE_STACK:
501 {
cec03d70
TT
502 ULONGEST value = (ULONGEST) dwarf_expr_fetch (ctx, 0);
503 bfd_byte *contents;
504 size_t n = ctx->addr_size;
505
cec03d70
TT
506 retval = allocate_value (SYMBOL_TYPE (var));
507 contents = value_contents_raw (retval);
508 if (n > TYPE_LENGTH (SYMBOL_TYPE (var)))
509 n = TYPE_LENGTH (SYMBOL_TYPE (var));
05566b3b
TT
510 store_unsigned_integer (contents, n,
511 gdbarch_byte_order (ctx->gdbarch),
512 value);
cec03d70
TT
513 }
514 break;
515
516 case DWARF_VALUE_LITERAL:
517 {
518 bfd_byte *contents;
519 size_t n = ctx->len;
520
521 retval = allocate_value (SYMBOL_TYPE (var));
522 contents = value_contents_raw (retval);
523 if (n > TYPE_LENGTH (SYMBOL_TYPE (var)))
524 n = TYPE_LENGTH (SYMBOL_TYPE (var));
525 memcpy (contents, ctx->data, n);
526 }
527 break;
528
529 default:
530 internal_error (__FILE__, __LINE__, _("invalid location type"));
531 }
4c2df51b
DJ
532 }
533
42be36b3
CT
534 set_value_initialized (retval, ctx->initialized);
535
4a227398 536 do_cleanups (old_chain);
4c2df51b
DJ
537
538 return retval;
539}
4c2df51b
DJ
540\f
541/* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
542
543struct needs_frame_baton
544{
545 int needs_frame;
546};
547
548/* Reads from registers do require a frame. */
549static CORE_ADDR
61fbb938 550needs_frame_read_reg (void *baton, int regnum)
4c2df51b
DJ
551{
552 struct needs_frame_baton *nf_baton = baton;
553 nf_baton->needs_frame = 1;
554 return 1;
555}
556
557/* Reads from memory do not require a frame. */
558static void
852483bc 559needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
4c2df51b
DJ
560{
561 memset (buf, 0, len);
562}
563
564/* Frame-relative accesses do require a frame. */
565static void
852483bc 566needs_frame_frame_base (void *baton, gdb_byte **start, size_t * length)
4c2df51b 567{
852483bc 568 static gdb_byte lit0 = DW_OP_lit0;
4c2df51b
DJ
569 struct needs_frame_baton *nf_baton = baton;
570
571 *start = &lit0;
572 *length = 1;
573
574 nf_baton->needs_frame = 1;
575}
576
e7802207
TT
577/* CFA accesses require a frame. */
578
579static CORE_ADDR
580needs_frame_frame_cfa (void *baton)
581{
582 struct needs_frame_baton *nf_baton = baton;
583 nf_baton->needs_frame = 1;
584 return 1;
585}
586
4c2df51b
DJ
587/* Thread-local accesses do require a frame. */
588static CORE_ADDR
589needs_frame_tls_address (void *baton, CORE_ADDR offset)
590{
591 struct needs_frame_baton *nf_baton = baton;
592 nf_baton->needs_frame = 1;
593 return 1;
594}
595
596/* Return non-zero iff the location expression at DATA (length SIZE)
597 requires a frame to evaluate. */
598
599static int
ae0d2f24
UW
600dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size,
601 struct dwarf2_per_cu_data *per_cu)
4c2df51b
DJ
602{
603 struct needs_frame_baton baton;
604 struct dwarf_expr_context *ctx;
f630a401 605 int in_reg;
4a227398 606 struct cleanup *old_chain;
4c2df51b
DJ
607
608 baton.needs_frame = 0;
609
610 ctx = new_dwarf_expr_context ();
4a227398
TT
611 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
612
f7fd4728 613 ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
ae0d2f24 614 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4c2df51b
DJ
615 ctx->baton = &baton;
616 ctx->read_reg = needs_frame_read_reg;
617 ctx->read_mem = needs_frame_read_mem;
618 ctx->get_frame_base = needs_frame_frame_base;
e7802207 619 ctx->get_frame_cfa = needs_frame_frame_cfa;
4c2df51b
DJ
620 ctx->get_tls_address = needs_frame_tls_address;
621
622 dwarf_expr_eval (ctx, data, size);
623
cec03d70 624 in_reg = ctx->location == DWARF_VALUE_REGISTER;
f630a401 625
87808bd6
JB
626 if (ctx->num_pieces > 0)
627 {
628 int i;
629
630 /* If the location has several pieces, and any of them are in
631 registers, then we will need a frame to fetch them from. */
632 for (i = 0; i < ctx->num_pieces; i++)
cec03d70 633 if (ctx->pieces[i].location == DWARF_VALUE_REGISTER)
87808bd6
JB
634 in_reg = 1;
635 }
636
4a227398 637 do_cleanups (old_chain);
4c2df51b 638
f630a401 639 return baton.needs_frame || in_reg;
4c2df51b
DJ
640}
641
08922a10
SS
642/* This struct keeps track of the pieces that make up a multi-location
643 object, for use in agent expression generation. It is
644 superficially similar to struct dwarf_expr_piece, but
645 dwarf_expr_piece is designed for use in immediate evaluation, and
646 does not, for example, have a way to record both base register and
647 offset. */
648
649struct axs_var_loc
0d53c4c4 650{
08922a10
SS
651 /* Memory vs register, etc */
652 enum axs_lvalue_kind kind;
653
654 /* If non-zero, number of bytes in this fragment */
655 unsigned bytes;
656
657 /* (GDB-numbered) reg, or base reg if >= 0 */
658 int reg;
659
660 /* offset from reg */
661 LONGEST offset;
662};
663
664static gdb_byte *
665dwarf2_tracepoint_var_loc (struct symbol *symbol,
666 struct agent_expr *ax,
667 struct axs_var_loc *loc,
668 struct gdbarch *gdbarch,
669 gdb_byte *data, gdb_byte *end)
670{
671 if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
0d53c4c4 672 {
08922a10
SS
673 loc->kind = axs_lvalue_register;
674 loc->reg = gdbarch_dwarf2_reg_to_regnum (gdbarch, data[0] - DW_OP_reg0);
675 data += 1;
0d53c4c4
DJ
676 }
677 else if (data[0] == DW_OP_regx)
678 {
679 ULONGEST reg;
08922a10
SS
680 data = read_uleb128 (data + 1, end, &reg);
681 loc->kind = axs_lvalue_register;
682 loc->reg = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg);
0d53c4c4
DJ
683 }
684 else if (data[0] == DW_OP_fbreg)
685 {
0936ad1d
SS
686 struct block *b;
687 struct symbol *framefunc;
688 int frame_reg = 0;
0d53c4c4 689 LONGEST frame_offset;
0936ad1d
SS
690 gdb_byte *base_data;
691 size_t base_size;
692 LONGEST base_offset = 0;
693
694 b = block_for_pc (ax->scope);
695
696 if (!b)
697 error (_("No block found for address"));
698
699 framefunc = block_linkage_function (b);
700
701 if (!framefunc)
702 error (_("No function found for block"));
703
704 dwarf_expr_frame_base_1 (framefunc, ax->scope,
705 &base_data, &base_size);
706
08922a10 707 if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
0936ad1d 708 {
08922a10
SS
709 gdb_byte *buf_end;
710
0936ad1d 711 frame_reg = base_data[0] - DW_OP_breg0;
08922a10
SS
712 buf_end = read_sleb128 (base_data + 1,
713 base_data + base_size, &base_offset);
0936ad1d
SS
714 if (buf_end != base_data + base_size)
715 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
716 frame_reg, SYMBOL_PRINT_NAME (symbol));
717 }
08922a10
SS
718 else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31)
719 {
720 /* The frame base is just the register, with no offset. */
721 frame_reg = base_data[0] - DW_OP_reg0;
722 base_offset = 0;
723 }
0936ad1d
SS
724 else
725 {
726 /* We don't know what to do with the frame base expression,
727 so we can't trace this variable; give up. */
08922a10
SS
728 error (_("Cannot generate expression to collect symbol \"%s\"; DWARF 2 encoding not handled, first opcode in base data is 0x%x."),
729 SYMBOL_PRINT_NAME (symbol), base_data[0]);
0936ad1d 730 }
0d53c4c4 731
08922a10 732 data = read_sleb128 (data + 1, end, &frame_offset);
4c2df51b 733
08922a10
SS
734 loc->kind = axs_lvalue_memory;
735 loc->reg = gdbarch_dwarf2_reg_to_regnum (gdbarch, frame_reg);
736 loc->offset = base_offset + frame_offset;
9c238357 737 }
08922a10 738 else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31)
9c238357
RC
739 {
740 unsigned int reg;
741 LONGEST offset;
9c238357
RC
742
743 reg = data[0] - DW_OP_breg0;
08922a10 744 data = read_sleb128 (data + 1, end, &offset);
9c238357 745
08922a10
SS
746 loc->kind = axs_lvalue_memory;
747 loc->reg = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg);
748 loc->offset = offset;
0d53c4c4
DJ
749 }
750 else
9c238357
RC
751 error (_("Unsupported DWARF opcode 0x%x in the location of \"%s\"."),
752 data[0], SYMBOL_PRINT_NAME (symbol));
08922a10
SS
753
754 return data;
0d53c4c4 755}
08922a10
SS
756
757/* Given the location of a piece, issue bytecodes that will access it. */
758
759static void
760dwarf2_tracepoint_var_access (struct agent_expr *ax,
761 struct axs_value *value,
762 struct axs_var_loc *loc)
763{
764 value->kind = loc->kind;
765
766 switch (loc->kind)
767 {
768 case axs_lvalue_register:
769 value->u.reg = loc->reg;
770 break;
771
772 case axs_lvalue_memory:
773 ax_reg (ax, loc->reg);
774 if (loc->offset)
775 {
776 ax_const_l (ax, loc->offset);
777 ax_simple (ax, aop_add);
778 }
779 break;
780
781 default:
782 internal_error (__FILE__, __LINE__, _("Unhandled value kind in dwarf2_tracepoint_var_access"));
783 }
784}
785
786static void
787dwarf2_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
788 struct agent_expr *ax, struct axs_value *value,
789 gdb_byte *data, int size)
790{
791 gdb_byte *end = data + size;
792 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
793 /* In practice, a variable is not going to be spread across
794 dozens of registers or memory locations. If someone comes up
795 with a real-world example, revisit this. */
796#define MAX_FRAGS 16
797 struct axs_var_loc fragments[MAX_FRAGS];
798 int nfrags = 0, frag;
799 int length = 0;
800 int piece_ok = 0;
801 int bad = 0;
802 int first = 1;
803
804 if (!data || size == 0)
805 {
806 value->optimized_out = 1;
807 return;
808 }
809
810 while (data < end)
811 {
812 if (!piece_ok)
813 {
814 if (nfrags == MAX_FRAGS)
815 error (_("Too many pieces in location for \"%s\"."),
816 SYMBOL_PRINT_NAME (symbol));
817
818 fragments[nfrags].bytes = 0;
819 data = dwarf2_tracepoint_var_loc (symbol, ax, &fragments[nfrags],
820 gdbarch, data, end);
821 nfrags++;
822 piece_ok = 1;
823 }
824 else if (data[0] == DW_OP_piece)
825 {
826 ULONGEST bytes;
827
828 data = read_uleb128 (data + 1, end, &bytes);
829 /* Only deal with 4 byte fragments for now. */
830 if (bytes != 4)
831 error (_("DW_OP_piece %s not supported in location for \"%s\"."),
832 pulongest (bytes), SYMBOL_PRINT_NAME (symbol));
833 fragments[nfrags - 1].bytes = bytes;
834 length += bytes;
835 piece_ok = 0;
836 }
837 else
838 {
839 bad = 1;
840 break;
841 }
842 }
843
844 if (bad || data > end)
845 error (_("Corrupted DWARF expression for \"%s\"."),
846 SYMBOL_PRINT_NAME (symbol));
847
848 /* If single expression, no pieces, convert to external format. */
849 if (length == 0)
850 {
851 dwarf2_tracepoint_var_access (ax, value, &fragments[0]);
852 return;
853 }
854
855 if (length != TYPE_LENGTH (value->type))
856 error (_("Inconsistent piece information for \"%s\"."),
857 SYMBOL_PRINT_NAME (symbol));
858
859 /* Emit bytecodes to assemble the pieces into a single stack entry. */
860
861 for ((frag = (byte_order == BFD_ENDIAN_BIG ? 0 : nfrags - 1));
862 nfrags--;
863 (frag += (byte_order == BFD_ENDIAN_BIG ? 1 : -1)))
864 {
865 if (!first)
866 {
867 /* shift the previous fragment up 32 bits */
868 ax_const_l (ax, 32);
869 ax_simple (ax, aop_lsh);
870 }
871
872 dwarf2_tracepoint_var_access (ax, value, &fragments[frag]);
873
874 switch (value->kind)
875 {
876 case axs_lvalue_register:
877 ax_reg (ax, value->u.reg);
878 break;
879
880 case axs_lvalue_memory:
881 {
882 extern int trace_kludge; /* Ugh. */
883
884 gdb_assert (fragments[frag].bytes == 4);
885 if (trace_kludge)
886 ax_trace_quick (ax, 4);
887 ax_simple (ax, aop_ref32);
888 }
889 break;
890 }
891
892 if (!first)
893 {
894 /* or the new fragment into the previous */
895 ax_zero_ext (ax, 32);
896 ax_simple (ax, aop_bit_or);
897 }
898 first = 0;
899 }
900 value->kind = axs_rvalue;
901}
902
4c2df51b
DJ
903\f
904/* Return the value of SYMBOL in FRAME using the DWARF-2 expression
905 evaluator to calculate the location. */
906static struct value *
907locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
908{
909 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
910 struct value *val;
911 val = dwarf2_evaluate_loc_desc (symbol, frame, dlbaton->data, dlbaton->size,
ae0d2f24 912 dlbaton->per_cu);
4c2df51b
DJ
913
914 return val;
915}
916
917/* Return non-zero iff we need a frame to evaluate SYMBOL. */
918static int
919locexpr_read_needs_frame (struct symbol *symbol)
920{
921 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
ae0d2f24
UW
922 return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size,
923 dlbaton->per_cu);
4c2df51b
DJ
924}
925
08922a10
SS
926/* Describe a single piece of a location, returning an updated
927 position in the bytecode sequence. */
928
929static gdb_byte *
930locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
931 CORE_ADDR addr, struct objfile *objfile,
932 gdb_byte *data, int size, unsigned int addr_size)
4c2df51b 933{
08922a10
SS
934 struct gdbarch *gdbarch = get_objfile_arch (objfile);
935 int regno;
936
937 if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
938 {
939 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, data[0] - DW_OP_reg0);
940 fprintf_filtered (stream, _("a variable in $%s"),
941 gdbarch_register_name (gdbarch, regno));
942 data += 1;
943 }
944 else if (data[0] == DW_OP_regx)
945 {
946 ULONGEST reg;
4c2df51b 947
08922a10
SS
948 data = read_uleb128 (data + 1, data + size, &reg);
949 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg);
950 fprintf_filtered (stream, _("a variable in $%s"),
951 gdbarch_register_name (gdbarch, regno));
952 }
953 else if (data[0] == DW_OP_fbreg)
4c2df51b 954 {
08922a10
SS
955 struct block *b;
956 struct symbol *framefunc;
957 int frame_reg = 0;
958 LONGEST frame_offset;
959 gdb_byte *base_data;
960 size_t base_size;
961 LONGEST base_offset = 0;
962
963 b = block_for_pc (addr);
964
965 if (!b)
966 error (_("No block found for address for symbol \"%s\"."),
967 SYMBOL_PRINT_NAME (symbol));
968
969 framefunc = block_linkage_function (b);
970
971 if (!framefunc)
972 error (_("No function found for block for symbol \"%s\"."),
973 SYMBOL_PRINT_NAME (symbol));
974
975 dwarf_expr_frame_base_1 (framefunc, addr, &base_data, &base_size);
976
977 if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
978 {
979 gdb_byte *buf_end;
980
981 frame_reg = base_data[0] - DW_OP_breg0;
982 buf_end = read_sleb128 (base_data + 1,
983 base_data + base_size, &base_offset);
984 if (buf_end != base_data + base_size)
985 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
986 frame_reg, SYMBOL_PRINT_NAME (symbol));
987 }
988 else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31)
989 {
990 /* The frame base is just the register, with no offset. */
991 frame_reg = base_data[0] - DW_OP_reg0;
992 base_offset = 0;
993 }
994 else
995 {
996 /* We don't know what to do with the frame base expression,
997 so we can't trace this variable; give up. */
998 error (_("Cannot describe location of symbol \"%s\"; "
999 "DWARF 2 encoding not handled, "
1000 "first opcode in base data is 0x%x."),
1001 SYMBOL_PRINT_NAME (symbol), base_data[0]);
1002 }
1003
1004 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, frame_reg);
1005
1006 data = read_sleb128 (data + 1, data + size, &frame_offset);
1007
1008 fprintf_filtered (stream, _("a variable at frame base reg $%s offset %s+%s"),
1009 gdbarch_register_name (gdbarch, regno),
1010 plongest (base_offset), plongest (frame_offset));
1011 }
1012 else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31)
1013 {
1014 LONGEST offset;
1015
1016 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, data[0] - DW_OP_breg0);
1017
1018 data = read_sleb128 (data + 1, data + size, &offset);
1019
4c2df51b 1020 fprintf_filtered (stream,
08922a10
SS
1021 _("a variable at offset %s from base reg $%s"),
1022 plongest (offset),
5e2b427d 1023 gdbarch_register_name (gdbarch, regno));
4c2df51b
DJ
1024 }
1025
c3228f12
EZ
1026 /* The location expression for a TLS variable looks like this (on a
1027 64-bit LE machine):
1028
1029 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
1030 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
1031
1032 0x3 is the encoding for DW_OP_addr, which has an operand as long
1033 as the size of an address on the target machine (here is 8
1034 bytes). 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
1035 The operand represents the offset at which the variable is within
1036 the thread local storage. */
1037
08922a10
SS
1038 else if (size > 1
1039 && data[size - 1] == DW_OP_GNU_push_tls_address
1040 && data[0] == DW_OP_addr)
1041 {
1042 CORE_ADDR offset = dwarf2_read_address (gdbarch,
1043 data + 1,
1044 data + size - 1,
1045 addr_size);
1046 fprintf_filtered (stream,
1047 _("a thread-local variable at offset %s "
1048 "in the thread-local storage for `%s'"),
1049 paddress (gdbarch, offset), objfile->name);
1050
1051 data += 1 + addr_size + 1;
1052 }
1053 else
1054 fprintf_filtered (stream,
1055 _("a variable with complex or multiple locations (DWARF2)"));
c3228f12 1056
08922a10 1057 return data;
4c2df51b
DJ
1058}
1059
08922a10
SS
1060/* Describe a single location, which may in turn consist of multiple
1061 pieces. */
a55cc764 1062
08922a10
SS
1063static void
1064locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
1065 struct ui_file *stream, gdb_byte *data, int size,
1066 struct objfile *objfile, unsigned int addr_size)
1067{
1068 gdb_byte *end = data + size;
1069 int piece_done = 0, first_piece = 1, bad = 0;
1070
1071 /* A multi-piece description consists of multiple sequences of bytes
1072 each followed by DW_OP_piece + length of piece. */
1073 while (data < end)
1074 {
1075 if (!piece_done)
1076 {
1077 if (first_piece)
1078 first_piece = 0;
1079 else
1080 fprintf_filtered (stream, _(", and "));
1081
1082 data = locexpr_describe_location_piece (symbol, stream, addr, objfile,
1083 data, size, addr_size);
1084 piece_done = 1;
1085 }
1086 else if (data[0] == DW_OP_piece)
1087 {
1088 ULONGEST bytes;
1089
1090 data = read_uleb128 (data + 1, end, &bytes);
1091
1092 fprintf_filtered (stream, _(" [%s-byte piece]"), pulongest (bytes));
1093
1094 piece_done = 0;
1095 }
1096 else
1097 {
1098 bad = 1;
1099 break;
1100 }
1101 }
1102
1103 if (bad || data > end)
1104 error (_("Corrupted DWARF2 expression for \"%s\"."),
1105 SYMBOL_PRINT_NAME (symbol));
1106}
1107
1108/* Print a natural-language description of SYMBOL to STREAM. This
1109 version is for a symbol with a single location. */
a55cc764 1110
08922a10
SS
1111static void
1112locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
1113 struct ui_file *stream)
1114{
1115 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
1116 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
1117 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
1118
1119 locexpr_describe_location_1 (symbol, addr, stream, dlbaton->data, dlbaton->size,
1120 objfile, addr_size);
1121}
1122
1123/* Describe the location of SYMBOL as an agent value in VALUE, generating
1124 any necessary bytecode in AX. */
a55cc764 1125
0d53c4c4 1126static void
505e835d
UW
1127locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
1128 struct agent_expr *ax, struct axs_value *value)
a55cc764
DJ
1129{
1130 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
1131
505e835d
UW
1132 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value,
1133 dlbaton->data, dlbaton->size);
a55cc764
DJ
1134}
1135
4c2df51b
DJ
1136/* The set of location functions used with the DWARF-2 expression
1137 evaluator. */
768a979c 1138const struct symbol_computed_ops dwarf2_locexpr_funcs = {
4c2df51b
DJ
1139 locexpr_read_variable,
1140 locexpr_read_needs_frame,
1141 locexpr_describe_location,
a55cc764 1142 locexpr_tracepoint_var_ref
4c2df51b 1143};
0d53c4c4
DJ
1144
1145
1146/* Wrapper functions for location lists. These generally find
1147 the appropriate location expression and call something above. */
1148
1149/* Return the value of SYMBOL in FRAME using the DWARF-2 expression
1150 evaluator to calculate the location. */
1151static struct value *
1152loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
1153{
1154 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
1155 struct value *val;
852483bc 1156 gdb_byte *data;
b6b08ebf 1157 size_t size;
0d53c4c4
DJ
1158
1159 data = find_location_expression (dlbaton, &size,
22c6caba
JW
1160 frame ? get_frame_address_in_block (frame)
1161 : 0);
0d53c4c4 1162 if (data == NULL)
806048c6
DJ
1163 {
1164 val = allocate_value (SYMBOL_TYPE (symbol));
1165 VALUE_LVAL (val) = not_lval;
1166 set_value_optimized_out (val, 1);
1167 }
1168 else
1169 val = dwarf2_evaluate_loc_desc (symbol, frame, data, size,
ae0d2f24 1170 dlbaton->per_cu);
0d53c4c4
DJ
1171
1172 return val;
1173}
1174
1175/* Return non-zero iff we need a frame to evaluate SYMBOL. */
1176static int
1177loclist_read_needs_frame (struct symbol *symbol)
1178{
1179 /* If there's a location list, then assume we need to have a frame
1180 to choose the appropriate location expression. With tracking of
1181 global variables this is not necessarily true, but such tracking
1182 is disabled in GCC at the moment until we figure out how to
1183 represent it. */
1184
1185 return 1;
1186}
1187
08922a10
SS
1188/* Print a natural-language description of SYMBOL to STREAM. This
1189 version applies when there is a list of different locations, each
1190 with a specified address range. */
1191
1192static void
1193loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
1194 struct ui_file *stream)
0d53c4c4 1195{
08922a10
SS
1196 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
1197 CORE_ADDR low, high;
1198 gdb_byte *loc_ptr, *buf_end;
1199 int length, first = 1;
1200 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
1201 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1202 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1203 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
1204 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
1205 /* Adjust base_address for relocatable objects. */
1206 CORE_ADDR base_offset = ANOFFSET (objfile->section_offsets,
1207 SECT_OFF_TEXT (objfile));
1208 CORE_ADDR base_address = dlbaton->base_address + base_offset;
1209
1210 loc_ptr = dlbaton->data;
1211 buf_end = dlbaton->data + dlbaton->size;
1212
1213 fprintf_filtered (stream, _("multi-location ("));
1214
1215 /* Iterate through locations until we run out. */
1216 while (1)
1217 {
1218 if (buf_end - loc_ptr < 2 * addr_size)
1219 error (_("Corrupted DWARF expression for symbol \"%s\"."),
1220 SYMBOL_PRINT_NAME (symbol));
1221
1222 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
1223 loc_ptr += addr_size;
1224
1225 /* A base-address-selection entry. */
1226 if (low == base_mask)
1227 {
1228 base_address = dwarf2_read_address (gdbarch,
1229 loc_ptr, buf_end, addr_size);
1230 fprintf_filtered (stream, _("[base address %s]"),
1231 paddress (gdbarch, base_address));
1232 loc_ptr += addr_size;
1233 continue;
1234 }
1235
1236 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
1237 loc_ptr += addr_size;
1238
1239 /* An end-of-list entry. */
1240 if (low == 0 && high == 0)
1241 {
1242 /* Indicate the end of the list, for readability. */
1243 fprintf_filtered (stream, _(")"));
1244 return;
1245 }
1246
1247 /* Otherwise, a location expression entry. */
1248 low += base_address;
1249 high += base_address;
1250
1251 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
1252 loc_ptr += 2;
1253
1254 /* Separate the different locations with a semicolon. */
1255 if (first)
1256 first = 0;
1257 else
1258 fprintf_filtered (stream, _("; "));
1259
1260 /* (It would improve readability to print only the minimum
1261 necessary digits of the second number of the range.) */
1262 fprintf_filtered (stream, _("range %s-%s, "),
1263 paddress (gdbarch, low), paddress (gdbarch, high));
1264
1265 /* Now describe this particular location. */
1266 locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
1267 objfile, addr_size);
1268
1269 loc_ptr += length;
1270 }
0d53c4c4
DJ
1271}
1272
1273/* Describe the location of SYMBOL as an agent value in VALUE, generating
1274 any necessary bytecode in AX. */
1275static void
505e835d
UW
1276loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
1277 struct agent_expr *ax, struct axs_value *value)
0d53c4c4
DJ
1278{
1279 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
852483bc 1280 gdb_byte *data;
b6b08ebf 1281 size_t size;
0d53c4c4
DJ
1282
1283 data = find_location_expression (dlbaton, &size, ax->scope);
0d53c4c4 1284
505e835d 1285 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value, data, size);
0d53c4c4
DJ
1286}
1287
1288/* The set of location functions used with the DWARF-2 expression
1289 evaluator and location lists. */
768a979c 1290const struct symbol_computed_ops dwarf2_loclist_funcs = {
0d53c4c4
DJ
1291 loclist_read_variable,
1292 loclist_read_needs_frame,
1293 loclist_describe_location,
1294 loclist_tracepoint_var_ref
1295};
This page took 0.527135 seconds and 4 git commands to generate.