- int i;
- long offset = 0;
- ULONGEST bits_to_skip;
- const gdb_byte *contents;
- struct piece_closure *c
- = (struct piece_closure *) value_computed_closure (to);
- size_t type_len;
- size_t buffer_size = 0;
- std::vector<gdb_byte> buffer;
- int bits_big_endian
- = gdbarch_bits_big_endian (get_type_arch (value_type (to)));
-
- contents = value_contents (from);
- bits_to_skip = 8 * value_offset (to);
- if (value_bitsize (to))
- {
- bits_to_skip += value_bitpos (to);
- type_len = value_bitsize (to);
- }
- else
- type_len = 8 * TYPE_LENGTH (value_type (to));
-
- for (i = 0; i < c->n_pieces && offset < type_len; i++)
- {
- struct dwarf_expr_piece *p = &c->pieces[i];
- size_t this_size_bits, this_size;
- long dest_offset_bits, source_offset_bits, dest_offset, source_offset;
- int need_bitwise;
- const gdb_byte *source_buffer;
-
- this_size_bits = p->size;
- if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
- {
- bits_to_skip -= this_size_bits;
- continue;
- }
- if (this_size_bits > type_len - offset)
- this_size_bits = type_len - offset;
- if (bits_to_skip > 0)
- {
- dest_offset_bits = bits_to_skip;
- source_offset_bits = 0;
- this_size_bits -= bits_to_skip;
- bits_to_skip = 0;
- }
- else
- {
- dest_offset_bits = 0;
- source_offset_bits = offset;
- }
-
- this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
- source_offset = source_offset_bits / 8;
- dest_offset = dest_offset_bits / 8;
- if (dest_offset_bits % 8 == 0 && source_offset_bits % 8 == 0)
- {
- source_buffer = contents + source_offset;
- need_bitwise = 0;
- }
- else
- {
- if (buffer_size < this_size)
- {
- buffer_size = this_size;
- buffer.reserve (buffer_size);
- }
- source_buffer = buffer.data ();
- need_bitwise = 1;
- }
-
- switch (p->location)
- {
- case DWARF_VALUE_REGISTER:
- {
- struct frame_info *frame = frame_find_by_id (c->frame_id);
- struct gdbarch *arch = get_frame_arch (frame);
- int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, p->v.regno);
- int reg_offset = dest_offset;
-
- if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
- && this_size <= register_size (arch, gdb_regnum))
- {
- /* Big-endian, and we want less than full size. */
- reg_offset = register_size (arch, gdb_regnum) - this_size;
- }
-
- if (need_bitwise)
- {
- int optim, unavail;
-
- if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
- this_size, buffer.data (),
- &optim, &unavail))
- {
- if (optim)
- throw_error (OPTIMIZED_OUT_ERROR,
- _("Can't do read-modify-write to "
- "update bitfield; containing word "
- "has been optimized out"));
- if (unavail)
- throw_error (NOT_AVAILABLE_ERROR,
- _("Can't do read-modify-write to update "
- "bitfield; containing word "
- "is unavailable"));
- }
- copy_bitwise (buffer.data (), dest_offset_bits,
- contents, source_offset_bits,
- this_size_bits,
- bits_big_endian);
- }
-
- put_frame_register_bytes (frame, gdb_regnum, reg_offset,
- this_size, source_buffer);
- }
- break;
- case DWARF_VALUE_MEMORY:
- if (need_bitwise)
- {
- /* Only the first and last bytes can possibly have any
- bits reused. */
- read_memory (p->v.mem.addr + dest_offset, buffer.data (), 1);
- read_memory (p->v.mem.addr + dest_offset + this_size - 1,
- &buffer[this_size - 1], 1);
- copy_bitwise (buffer.data (), dest_offset_bits,
- contents, source_offset_bits,
- this_size_bits,
- bits_big_endian);
- }