|
From: <sv...@va...> - 2005-05-01 20:24:12
|
Author: sewardj
Date: 2005-05-01 21:24:06 +0100 (Sun, 01 May 2005)
New Revision: 3585
Modified:
trunk/coregrind/vg_dwarf.c
Log:
* handle DW_CFA_offset_extended_sf
* make --trace-cfi=3Dyes work, to assist in debugging this
Modified: trunk/coregrind/vg_dwarf.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_dwarf.c 2005-05-01 15:14:01 UTC (rev 3584)
+++ trunk/coregrind/vg_dwarf.c 2005-05-01 20:24:06 UTC (rev 3585)
@@ -933,24 +933,25 @@
=20
enum dwarf_cfa_secondary_ops
{
- DW_CFA_nop =3D 0x00,
- DW_CFA_set_loc =3D 0x01,
- DW_CFA_advance_loc1 =3D 0x02,
- DW_CFA_advance_loc2 =3D 0x03,
- DW_CFA_advance_loc4 =3D 0x04,
- DW_CFA_offset_extended =3D 0x05,
- DW_CFA_restore_extended =3D 0x06,
- DW_CFA_undefined =3D 0x07,
- DW_CFA_same_value =3D 0x08,
- DW_CFA_register =3D 0x09,
- DW_CFA_remember_state =3D 0x0a,
- DW_CFA_restore_state =3D 0x0b,
- DW_CFA_def_cfa =3D 0x0c,
- DW_CFA_def_cfa_register =3D 0x0d,
- DW_CFA_def_cfa_offset =3D 0x0e,
- DW_CFA_lo_user =3D 0x1c,
- DW_CFA_GNU_args_size =3D 0x2e,
- DW_CFA_hi_user =3D 0x3f
+ DW_CFA_nop =3D 0x00,
+ DW_CFA_set_loc =3D 0x01,
+ DW_CFA_advance_loc1 =3D 0x02,
+ DW_CFA_advance_loc2 =3D 0x03,
+ DW_CFA_advance_loc4 =3D 0x04,
+ DW_CFA_offset_extended =3D 0x05,
+ DW_CFA_restore_extended =3D 0x06,
+ DW_CFA_undefined =3D 0x07,
+ DW_CFA_same_value =3D 0x08,
+ DW_CFA_register =3D 0x09,
+ DW_CFA_remember_state =3D 0x0a,
+ DW_CFA_restore_state =3D 0x0b,
+ DW_CFA_def_cfa =3D 0x0c,
+ DW_CFA_def_cfa_register =3D 0x0d,
+ DW_CFA_def_cfa_offset =3D 0x0e,
+ DW_CFA_offset_extended_sf =3D 0x11, /* DWARF3 only */
+ DW_CFA_lo_user =3D 0x1c,
+ DW_CFA_GNU_args_size =3D 0x2e,
+ DW_CFA_hi_user =3D 0x3f
};
=20
#define DW_EH_PE_absptr 0x00
@@ -1285,7 +1286,7 @@
vg_assert(0);
}
=20
- if ((encoding & 0x0f) =3D=3D 0x00)
+ if ((encoding & 0x07) =3D=3D 0x00)
encoding |=3D default_address_encoding();
=20
switch (encoding & 0x0f) {
@@ -1308,7 +1309,7 @@
*nbytes +=3D sizeof(Long);
return base + read_Long(data);
default:
- vg_assert(0);
+ vg_assert2(0, "read encoded address %d\n", encoding & 0x0f);
}
}
=20
@@ -1382,27 +1383,38 @@
ctx->cfa_offset =3D off;
break;
=20
- case DW_CFA_def_cfa_register: {
+ case DW_CFA_offset_extended_sf:
+ reg =3D read_leb128( &instr[i], &nleb, 0 );
+ i +=3D nleb;
+ off =3D read_leb128( &instr[i], &nleb, 1 );
+ i +=3D nleb;
+ if (reg < 0 || reg >=3D N_CFI_REGS)=20
+ return 0; /* fail */
+ ctx->reg[reg].tag =3D RR_CFAoff;
+ ctx->reg[reg].coff =3D off * ctx->data_a_f;
+ break; =20
+
+ case DW_CFA_def_cfa_register:
reg =3D read_leb128( &instr[i], &nleb, 0);
i +=3D nleb;
if (reg < 0 || reg >=3D N_CFI_REGS)=20
return 0; /* fail */
ctx->cfa_reg =3D reg;
break;
- }
- case DW_CFA_def_cfa_offset: {
+
+ case DW_CFA_def_cfa_offset:
off =3D read_leb128( &instr[i], &nleb, 0);
i +=3D nleb;
ctx->cfa_offset =3D off;
break;
- }
- case DW_CFA_GNU_args_size: {
+
+ case DW_CFA_GNU_args_size:
/* No idea what is supposed to happen. gdb-6.3 simply
ignores these. */
off =3D read_leb128( &instr[i], &nleb, 0 );
i +=3D nleb;
break;
- }
+
default:=20
VG_(printf)("Unhandled CFI instruction 0:%d\n", (Int)lo6);=20
i =3D 0;
@@ -1569,10 +1581,6 @@
Bool ok;
=20
UChar* current_cie =3D NULL;
-
- if (0&& ehframe_sz !=3D 240) return;
- if (0) VG_(printf)("\n\n\neh_frame %p %d\n", ehframe, ehframe_sz);
-
UChar* data =3D ehframe;
=20
UChar* cie_instrs =3D NULL;
@@ -1580,28 +1588,38 @@
Bool saw_z_augmentation =3D False;
UChar address_encoding =3D default_address_encoding();
=20
+ if (VG_(clo_trace_cfi)) {
+ VG_(printf)("\n-----------------------------------------------\n")=
;
+ VG_(printf)("CFI info: ehframe %p, ehframe_sz %d\n",
+ ehframe, ehframe_sz );
+ VG_(printf)("CFI info: name %s\n",
+ si->filename );
+ }
+
/* Loop over CIEs/FDEs */
=20
while (True) {
=20
- /* Are we done? */
- if (data =3D=3D ehframe + ehframe_sz)
- return;
+ /* Are we done? */
+ if (data =3D=3D ehframe + ehframe_sz)
+ return;
=20
- /* Overshot the end? Means something is wrong */
- if (data > ehframe + ehframe_sz) {
- how =3D "overran the end of .eh_frame";
- goto bad;
- }
+ /* Overshot the end? Means something is wrong */
+ if (data > ehframe + ehframe_sz) {
+ how =3D "overran the end of .eh_frame";
+ goto bad;
+ }
=20
- /* Ok, we must be looking at the start of a new CIE or FDE.
- Figure out which it is. */
+ /* Ok, we must be looking at the start of a new CIE or FDE.
+ Figure out which it is. */
=20
UChar* ciefde_start =3D data;
- if (0) VG_(printf)("\ncie/fde.start =3D %p\n", ciefde_start);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("\ncie/fde.start =3D %p\n", ciefde_start);
=20
UInt ciefde_len =3D read_UInt(data); data +=3D sizeof(UInt);
- if (0) VG_(printf)("cie/fde.length =3D %d\n", ciefde_len);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("cie/fde.length =3D %d\n", ciefde_len);
=20
/* Apparently, if the .length field is zero, we are at the end
of the sequence. ?? Neither the DWARF2 spec not the AMD64
@@ -1614,7 +1632,8 @@
}
=20
UInt cie_pointer =3D read_UInt(data); data +=3D sizeof(UInt);
- if (0) VG_(printf)("cie.pointer =3D %d\n", cie_pointer);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("cie.pointer =3D %d\n", cie_pointer);
=20
/* If cie_pointer is zero, we've got a CIE; else it's an FDE. */
if (cie_pointer =3D=3D 0) {
@@ -1623,12 +1642,21 @@
current_cie =3D ciefde_start + sizeof(UInt);
=20
/* --------- CIE --------- */
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("------ new CIE ------\n");
+
UChar cie_version =3D read_UChar(data); data +=3D sizeof(UChar)=
;
- if (0) VG_(printf)("cie.version =3D %d\n", (Int)cie_version=
);
+ if (VG_(clo_trace_cfi))
+ VG_(printf)("cie.version =3D %d\n", (Int)cie_version);
+ if (cie_version !=3D 1) {
+ how =3D "unexpected CIE version (not 1)";
+ goto bad;
+ }
=20
UChar* cie_augmentation =3D data;
data +=3D 1 + VG_(strlen)(cie_augmentation);
- if (0) VG_(printf)("cie.augment =3D \"%s\"\n", cie_augmenta=
tion);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("cie.augment =3D \"%s\"\n", cie_augmentation=
);
=20
if (cie_augmentation[0] =3D=3D 'e' && cie_augmentation[1] =3D=3D=
'h') {
data +=3D sizeof(Addr);
@@ -1637,14 +1665,17 @@
=20
cie_codeaf =3D read_leb128( data, &nbytes, 0);
data +=3D nbytes;
- if (0) VG_(printf)("cie.code_af =3D %d\n", cie_codeaf);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("cie.code_af =3D %d\n", cie_codeaf);
=20
cie_dataaf =3D read_leb128( data, &nbytes, 1);
data +=3D nbytes;
- if (0) VG_(printf)("cie.data_af =3D %d\n", cie_dataaf);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("cie.data_af =3D %d\n", cie_dataaf);
=20
UChar cie_rareg =3D read_UChar(data); data +=3D sizeof(UChar);
- if (0) VG_(printf)("cie.ra_reg =3D %d\n", (Int)cie_rareg);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("cie.ra_reg =3D %d\n", (Int)cie_rareg);
=20
saw_z_augmentation =3D *cie_augmentation =3D=3D 'z';
if (saw_z_augmentation) {
@@ -1682,12 +1713,15 @@
=20
done_augmentation:
=20
- if (0) VG_(printf)("cie.encoding =3D 0x%x\n", address_encodi=
ng);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("cie.encoding =3D 0x%x\n", address_encoding);
=20
cie_instrs =3D data;
cie_ilen =3D ciefde_start + ciefde_len + sizeof(UInt) - data;
- if (0) VG_(printf)("cie.instrs =3D %p\n", cie_instrs);
- if (0) VG_(printf)("cie.ilen =3D %d\n", (Int)cie_ilen);
+ if (VG_(clo_trace_cfi)) {
+ VG_(printf)("cie.instrs =3D %p\n", cie_instrs);
+ VG_(printf)("cie.ilen =3D %d\n", (Int)cie_ilen);
+ }
=20
if (cie_ilen < 0 || cie_ilen > ehframe_sz) {
how =3D "implausible # cie initial insns";
@@ -1696,7 +1730,8 @@
=20
data +=3D cie_ilen;
=20
- if (0) show_CF_instructions(cie_instrs, cie_ilen);
+ if (VG_(clo_trace_cfi))=20
+ show_CF_instructions(cie_instrs, cie_ilen);
=20
} else {
=20
@@ -1713,15 +1748,19 @@
goto bad;
}
=20
- Addr fde_initloc =3D read_encoded_address(data, address_encodin=
g,
- &nbytes, ehframe, ehfra=
me_addr);
+ Addr fde_initloc=20
+ =3D read_encoded_address(data, address_encoding,
+ &nbytes, ehframe, ehframe_addr);
data +=3D nbytes;
- if (0) VG_(printf)("fde.initloc =3D %p\n", (void*)fde_initl=
oc);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("fde.initloc =3D %p\n", (void*)fde_initloc);
=20
- UWord fde_arange =3D read_encoded_address(data, address_encodin=
g & 0xf,
- &nbytes, ehframe, ehfra=
me_addr);
+ UWord fde_arange=20
+ =3D read_encoded_address(data, address_encoding & 0xf,
+ &nbytes, ehframe, ehframe_addr);
data +=3D nbytes;
- if (0) VG_(printf)("fde.arangec =3D %p\n", (void*)fde_arang=
e);
+ if (VG_(clo_trace_cfi))=20
+ VG_(printf)("fde.arangec =3D %p\n", (void*)fde_arange);
=20
if (saw_z_augmentation) {
data +=3D read_leb128( data, &nbytes, 0);
@@ -1730,16 +1769,19 @@
=20
UChar* fde_instrs =3D data;
Int fde_ilen =3D ciefde_start + ciefde_len + sizeof(UInt) =
- data;
- if (0) VG_(printf)("fde.instrs =3D %p\n", fde_instrs);
- if (0) VG_(printf)("fde.ilen =3D %d\n", (Int)fde_ilen);
+ if (VG_(clo_trace_cfi)) VG_(printf)("fde.instrs =3D %p\n",=
fde_instrs);
+ if (VG_(clo_trace_cfi)) VG_(printf)("fde.ilen =3D %d\n",=
(Int)fde_ilen);
=20
if (fde_ilen < 0 || fde_ilen > ehframe_sz) {
- how =3D "implausible # fde initial insns";
+ how =3D "implausible # fde insns";
goto bad;
}
=20
data +=3D fde_ilen;
=20
+ if (VG_(clo_trace_cfi))=20
+ show_CF_instructions(fde_instrs, fde_ilen);
+
initUnwindContext(&ctx);
ctx.code_a_f =3D cie_codeaf;
ctx.data_a_f =3D cie_dataaf;
|