Skip to content

Commit a8bb747

Browse files
committed
Frame pointers are not used if erts_frame_layout is undefined
1 parent 64f63b9 commit a8bb747

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

interpreter/beam/beam.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type beamData struct {
4242
the_active_code_index uint64
4343
r uint64
4444
erts_atom_table uint64
45+
frame_pointer_support bool
4546
erts_frame_layout uint64
4647
etp_ptr_mask uint64
4748
etp_header_subtag_mask uint64
@@ -214,22 +215,25 @@ func Loader(ebpf interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpr
214215
return nil, fmt.Errorf("symbol 'etp_heap_bits_subtag' not found: %v", err)
215216
}
216217

217-
erts_frame_layout, _, err := ef.SymbolData("erts_frame_layout", 8)
218-
if err != nil {
219-
return nil, fmt.Errorf("symbol 'erts_frame_layout' not found: %v", err)
220-
}
221-
222218
d := &beamData{
223219
version: otpVersion,
224220
the_active_code_index: uint64(codeIndex.Address),
225221
r: uint64(r),
226222
erts_atom_table: uint64(atomTable.Address),
227-
erts_frame_layout: uint64(erts_frame_layout.Address),
223+
frame_pointer_support: true,
228224
etp_ptr_mask: nopanicslicereader.Uint64(etp_ptr_mask, 0),
229225
etp_header_subtag_mask: nopanicslicereader.Uint64(etp_header_subtag_mask, 0),
230226
etp_heap_bits_subtag: nopanicslicereader.Uint64(etp_heap_bits_subtag, 0),
231227
}
232228

229+
erts_frame_layout, _, err := ef.SymbolData("erts_frame_layout", 8)
230+
if err != nil {
231+
// If erts_frame_layout is not defined, that's OK - it just means that
232+
// frame pointers are not supported and therefore not used.
233+
d.frame_pointer_support = false
234+
}
235+
d.erts_frame_layout = uint64(erts_frame_layout.Address)
236+
233237
vms := &d.vmStructs
234238

235239
// These values are the same on OTP releases 27.2.4 and 28.0.2.
@@ -277,11 +281,17 @@ func Loader(ebpf interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpr
277281
func (d *beamData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID, bias libpf.Address, rm remotememory.RemoteMemory) (interpreter.Instance, error) {
278282
log.Infof("BEAM attaching, bias: 0x%x", bias)
279283

284+
// If frame pointers are not supported, they will not be used
285+
Erts_frame_layout := uint64(0)
286+
if d.frame_pointer_support {
287+
Erts_frame_layout = rm.Uint64(bias + libpf.Address(d.erts_frame_layout))
288+
}
289+
280290
data := support.BEAMProcInfo{
281291
Version: d.version,
282292
R: uint64(bias) + d.r,
283293
The_active_code_index: uint64(bias) + d.the_active_code_index,
284-
Erts_frame_layout: rm.Uint64(bias + libpf.Address(d.erts_frame_layout)),
294+
Erts_frame_layout: Erts_frame_layout,
285295
Ranges_sizeof: uint8(d.vmStructs.ranges.size_of),
286296
Ranges_modules: uint8(d.vmStructs.ranges.modules),
287297
Ranges_n: uint8(d.vmStructs.ranges.n),

0 commit comments

Comments
 (0)