Skip to content

Commit 41d3053

Browse files
author
philippe
committed
On platforms that have an accessible redzone below the SP, the unwind logic
should be able to access the redzone. So, when computing fp_min, substract the redzone. Currently, only amd64 and ppc64 have a non 0 redzone. Regtested on amd64 and ppc64le, no regression. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15309 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent 79a59b5 commit 41d3053

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

coregrind/m_stacktrace.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@
7575
} \
7676
}
7777

78-
78+
/* Note about calculation of fp_min : fp_min is the lowest address
79+
which can be accessed during unwinding. This is SP - VG_STACK_REDZONE_SZB.
80+
On most platforms, this will be equal to SP (as VG_STACK_REDZONE_SZB
81+
is 0). However, on some platforms (e.g. amd64), there is an accessible
82+
redzone below the SP. Some CFI unwind info are generated, taking this
83+
into account. As an example, the following is a CFI unwind info on
84+
amd64 found for a 'retq' instruction:
85+
[0x400f7e .. 0x400f7e]: let cfa=oldSP+8 in RA=*(cfa+-8) SP=cfa+0 BP=*(cfa+-16)
86+
0x400f7e: retq
87+
As you can see, the previous BP is found 16 bytes below the cfa, which
88+
is the oldSP+8. So, effectively, the BP is found 8 bytes below the SP.
89+
The fp_min must take this into account, otherwise, VG_(use_CF_info) will
90+
not unwind the BP. */
91+
7992
/* ------------------------ x86 ------------------------- */
8093

8194
#if defined(VGP_x86_linux) || defined(VGP_x86_darwin)
@@ -196,7 +209,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
196209
uregs.xip = (Addr)startRegs->r_pc;
197210
uregs.xsp = (Addr)startRegs->r_sp;
198211
uregs.xbp = startRegs->misc.X86.r_ebp;
199-
Addr fp_min = uregs.xsp;
212+
Addr fp_min = uregs.xsp - VG_STACK_REDZONE_SZB;
200213

201214
/* Snaffle IPs from the client's stack into ips[0 .. max_n_ips-1],
202215
stopping when the trail goes cold, which we guess to be
@@ -479,7 +492,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
479492
uregs.xip = startRegs->r_pc;
480493
uregs.xsp = startRegs->r_sp;
481494
uregs.xbp = startRegs->misc.AMD64.r_rbp;
482-
Addr fp_min = uregs.xsp;
495+
Addr fp_min = uregs.xsp - VG_STACK_REDZONE_SZB;
483496

484497
/* Snaffle IPs from the client's stack into ips[0 .. max_n_ips-1],
485498
stopping when the trail goes cold, which we guess to be
@@ -682,7 +695,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
682695
# elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
683696
Addr lr = startRegs->misc.PPC64.r_lr;
684697
# endif
685-
Addr fp_min = sp;
698+
Addr fp_min = sp - VG_STACK_REDZONE_SZB;
686699

687700
/* Snaffle IPs from the client's stack into ips[0 .. max_n_ips-1],
688701
stopping when the trail goes cold, which we guess to be
@@ -947,7 +960,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
947960
uregs.r12 = startRegs->misc.ARM.r12;
948961
uregs.r11 = startRegs->misc.ARM.r11;
949962
uregs.r7 = startRegs->misc.ARM.r7;
950-
Addr fp_min = uregs.r13;
963+
Addr fp_min = uregs.r13 - VG_STACK_REDZONE_SZB;
951964

952965
/* Snaffle IPs from the client's stack into ips[0 .. max_n_ips-1],
953966
stopping when the trail goes cold, which we guess to be
@@ -1091,7 +1104,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
10911104
uregs.sp = startRegs->r_sp;
10921105
uregs.x30 = startRegs->misc.ARM64.x30;
10931106
uregs.x29 = startRegs->misc.ARM64.x29;
1094-
Addr fp_min = uregs.sp;
1107+
Addr fp_min = uregs.sp - VG_STACK_REDZONE_SZB;
10951108

10961109
/* Snaffle IPs from the client's stack into ips[0 .. max_n_ips-1],
10971110
stopping when the trail goes cold, which we guess to be
@@ -1185,7 +1198,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
11851198
D3UnwindRegs uregs;
11861199
uregs.ia = startRegs->r_pc;
11871200
uregs.sp = startRegs->r_sp;
1188-
Addr fp_min = uregs.sp;
1201+
Addr fp_min = uregs.sp - VG_STACK_REDZONE_SZB;
11891202
uregs.fp = startRegs->misc.S390X.r_fp;
11901203
uregs.lr = startRegs->misc.S390X.r_lr;
11911204

@@ -1268,7 +1281,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
12681281
D3UnwindRegs uregs;
12691282
uregs.pc = startRegs->r_pc;
12701283
uregs.sp = startRegs->r_sp;
1271-
Addr fp_min = uregs.sp;
1284+
Addr fp_min = uregs.sp - VG_STACK_REDZONE_SZB;
12721285

12731286
#if defined(VGP_mips32_linux)
12741287
uregs.fp = startRegs->misc.MIPS32.r30;
@@ -1423,7 +1436,7 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId tid_if_known,
14231436
D3UnwindRegs uregs;
14241437
uregs.pc = startRegs->r_pc;
14251438
uregs.sp = startRegs->r_sp;
1426-
Addr fp_min = uregs.sp;
1439+
Addr fp_min = uregs.sp - VG_STACK_REDZONE_SZB;
14271440

14281441
uregs.fp = startRegs->misc.TILEGX.r52;
14291442
uregs.lr = startRegs->misc.TILEGX.r55;

0 commit comments

Comments
 (0)