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