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