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