[RFA] dwarf2-frame.c sign extension patch

Martin M. Hunt
2004-07-20T19:11:34Z

[-- Attachment #1: Type: text/plain, Size: 637 bytes --]

This patch fixes some dwarf2 problems with sign-extension.

2004-07-20 Kevin Buettner and Martin Hunt <hunt@redhat.com>

* dwarf2-frame.c (execute_cfa_program): Fix typo in which the
alignment was being added to the offset instead of multiplied.

(struct comp_unit): Add new field ``signed_addr_p''.

(encoding_for_size): Add new parameter ``signed_addr_p''.
Adjust all callers. Add code for handling signed encodings.

(dwarf2_build_frame_info): Initialize ``unit.signed_addr_p''.

(dwarf2_build_frame_info): Set unit.addr_size.

--
Martin M. Hunt <hunt@redhat.com>
Red Hat Inc.

[-- Attachment #2: cfi_patch --]
[-- Type: text/x-patch, Size: 2606 bytes --]

Index: dwarf2-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v
retrieving revision 1.36
diff -w -u -r1.36 dwarf2-frame.c
--- dwarf2-frame.c 15 Jun 2004 01:04:19 -0000 1.36
+++ dwarf2-frame.c 20 Jul 2004 18:54:54 -0000
@@ -426,7 +428,7 @@
case DW_CFA_offset_extended_sf:
insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
- offset += fs->data_align;
+ offset *= fs->data_align;
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
fs->regs.reg[reg].loc.offset = offset;
@@ -893,6 +895,9 @@
/* Address size for this unit - from unit header. */
unsigned char addr_size;

+ /* Are addresses signed? */
+ unsigned char signed_addr_p;
+
/* Pointer to the .debug_frame section loaded into memory. */
char *dwarf_frame_buffer;

@@ -1021,15 +1026,24 @@
should be dereferenced. */

static unsigned char
-encoding_for_size (unsigned int size)
+encoding_for_size (unsigned int size, int signed_addr_p)
{
switch (size)
{
case 2:
+ if (signed_addr_p)
+ return DW_EH_PE_sdata2;
+ else
return DW_EH_PE_udata2;
case 4:
+ if (signed_addr_p)
+ return DW_EH_PE_sdata4;
+ else
return DW_EH_PE_udata4;
case 8:
+ if (signed_addr_p)
+ return DW_EH_PE_sdata8;
+ else
return DW_EH_PE_udata8;
default:
internal_error (__FILE__, __LINE__, "Unsupported address size");
@@ -1110,7 +1124,7 @@
}

if ((encoding & 0x0f) == 0x00)
- encoding |= encoding_for_size (ptr_len);
+ encoding |= encoding_for_size (ptr_len, unit->signed_addr_p);

switch (encoding & 0x0f)
{
@@ -1286,7 +1300,7 @@
/* The encoding for FDE's in a normal .debug_frame section
depends on the target address size as specified in the
Compilation Unit Header. */
- cie->encoding = encoding_for_size (unit->addr_size);
+ cie->encoding = encoding_for_size (unit->addr_size, unit->signed_addr_p);

/* Check version number. */
cie_version = read_1_byte (unit->abfd, buf);
@@ -1557,7 +1571,8 @@
/* Build a minimal decoding of the DWARF2 compilation unit. */
unit.abfd = objfile->obfd;
unit.objfile = objfile;
- unit.addr_size = objfile->obfd->arch_info->bits_per_address / 8;
+ unit.addr_size = TYPE_LENGTH (builtin_type_void_data_ptr);
+ unit.signed_addr_p = bfd_get_sign_extend_vma (unit.abfd);
unit.dbase = 0;
unit.tbase = 0;