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