1 /* Get register location expression for frame.
2 Copyright (C) 2009-2010, 2014 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
37 dwarf_frame_register (Dwarf_Frame *fs, int regno, Dwarf_Op *ops_mem,
38 Dwarf_Op **ops, size_t *nops)
40 /* Maybe there was a previous error. */
44 if (unlikely (regno < 0))
46 __libdw_seterrno (DWARF_E_INVALID_ACCESS);
53 if (unlikely ((size_t) regno >= fs->nregs))
56 const struct dwarf_frame_register *reg = &fs->regs[regno];
62 /* Use the default rule for registers not yet mentioned in CFI. */
63 if (fs->cache->default_same_value)
67 /* The value is known to be unavailable. */
72 /* The location is not known here, but the caller might know it. */
78 ops_mem[(*nops)++] = (Dwarf_Op) { .atom = DW_OP_call_frame_cfa };
80 ops_mem[(*nops)++] = (Dwarf_Op) { .atom = DW_OP_plus_uconst,
81 .number = reg->value };
82 if (reg->rule == reg_val_offset)
83 /* A value, not a location. */
84 ops_mem[(*nops)++] = (Dwarf_Op) { .atom = DW_OP_stack_value };
89 ops_mem[(*nops)++] = (Dwarf_Op) { .atom = DW_OP_regx,
90 .number = reg->value };
93 case reg_val_expression:
96 unsigned int address_size = (fs->cache->e_ident[EI_CLASS] == ELFCLASS32
100 const uint8_t *p = fs->cache->data->d.d_buf + reg->value;
101 const uint8_t *end = (fs->cache->data->d.d_buf
102 + fs->cache->data->d.d_size);
103 get_uleb128 (block.length, p, end);
104 block.data = (void *) p;
106 /* Parse the expression into internal form. */
107 if (__libdw_intern_expression (NULL,
108 fs->cache->other_byte_order,
110 &fs->cache->expr_tree, &block,
111 true, reg->rule == reg_val_expression,
112 ops, nops, IDX_debug_frame) < 0)