@@ -79,10 +79,7 @@ type luajitInstance struct {
79
79
traceHashes map [libpf.Address ]uint64
80
80
cycle int
81
81
82
- // In order to symbolize frame n we need to know the caller or frame n+1 so we don't
83
- // symbolize frame n until symbolize is called fo frame n+1.
84
- previousFrame * host.Frame
85
- g2Traces uint16
82
+ g2Traces uint16
86
83
}
87
84
88
85
var (
@@ -349,12 +346,7 @@ func (l *luajitInstance) getGCproto(pt libpf.Address) (*proto, error) {
349
346
350
347
// symbolizeFrame symbolizes the previous (up the stack)
351
348
func (l * luajitInstance ) symbolizeFrame (symbolReporter reporter.SymbolReporter ,
352
- funcName string , trace * libpf.Trace ) error {
353
- if l .previousFrame == nil || l .previousFrame .File == 0 {
354
- return errors .New ("previous frame not set" )
355
- }
356
- ptAddr := libpf .Address (l .previousFrame .File )
357
- pc := uint32 (l .previousFrame .Lineno )
349
+ funcName string , trace * libpf.Trace , ptAddr libpf.Address , pc uint32 ) error {
358
350
var line uint32
359
351
var fileName string
360
352
if ptAddr != C .LUAJIT_FFI_FUNC {
@@ -388,29 +380,25 @@ func (l *luajitInstance) symbolizeFrame(symbolReporter reporter.SymbolReporter,
388
380
return nil
389
381
}
390
382
391
- // Symbolize is a little weird in lua since we need the caller frame to get the name of the
392
- // function being called. So we stash the info for the current frame and each symbolize call
393
- // actually symolizes the previous frame. The unwinder emits a special frame with file 0 to
394
- // indicate the end of the lua stack.
395
383
func (l * luajitInstance ) Symbolize (symbolReporter reporter.SymbolReporter , frame * host.Frame ,
396
384
trace * libpf.Trace ) error {
397
385
if ! frame .Type .IsInterpType (libpf .LuaJIT ) {
398
386
return interpreter .ErrMismatchInterpreterType
399
387
}
400
388
401
- // We need the calling frame to find the name of the current frame so save it and do it on next
402
- // frame. This assumes that the harness calls Symbolize from top to bottom of the stack in
403
- // order!! The final luajit frame will have a 0 frame.File.
404
- if l .previousFrame == nil {
405
- l .previousFrame = frame
406
- logf ("lj: new LuaJIT frame" )
389
+ if frame .File == 0 && frame .Lineno != 0 {
390
+ // The BPF program will stash pointer to "G" when it sees a JIT frame w/o trace information
391
+ // which may fail to unwind, we use it to see if the traces for this VM have changed. When
392
+ // we reach a steady state where there's no new JIT activity this will always be 0.
393
+ g := libpf .Address (frame .Lineno )
394
+ if g != 0 {
395
+ l .mu .Lock ()
396
+ defer l .mu .Unlock ()
397
+ l .vms [g ] = struct {}{}
398
+ }
407
399
return nil
408
400
}
409
401
410
- // The function being invoked at this frame (caller) is the name for the previous
411
- // frame (callee). For the last frame frame.File will be 0 and pt will be nil and funcName
412
- // will be "main". Lua is a real deal dynamic functional language, functions don't have
413
- // inherent names they are just values.
414
402
var funcName string
415
403
if frame .File == C .LUAJIT_FFI_FUNC {
416
404
switch frame .Lineno & 7 {
@@ -431,32 +419,15 @@ func (l *luajitInstance) Symbolize(symbolReporter reporter.SymbolReporter, frame
431
419
funcName = "ff-pcall-hook"
432
420
}
433
421
} else {
434
- ptaddr := libpf .Address (frame .File )
435
- pc := uint32 (frame .Lineno )
436
- pt , err := l .getGCproto (ptaddr )
422
+ callerPT := libpf .Address (frame .Lineno )
423
+ pt , err := l .getGCproto (callerPT )
437
424
if err != nil {
438
425
return err
439
426
}
440
- funcName = pt .getFunctionName (pc )
427
+ funcName = pt .getFunctionName (frame . LJCallerPC )
441
428
}
442
429
443
- err := l .symbolizeFrame (symbolReporter , funcName , trace )
444
-
445
- if frame .File == 0 {
446
- logf ("lj: end LuaJIT frame" )
447
- l .previousFrame = nil
448
- // The BPF program will stash pointer to "G" when it sees a JIT frame w/o trace information
449
- // which may fail to unwind, we use it to see if the traces for this VM have changed. When
450
- // we reach a steady state where there's no new JIT activity this will always be 0.
451
- g := libpf .Address (frame .Lineno )
452
- if g != 0 {
453
- l .mu .Lock ()
454
- defer l .mu .Unlock ()
455
- l .vms [g ] = struct {}{}
456
- }
457
- } else {
458
- l .previousFrame = frame
459
- }
430
+ err := l .symbolizeFrame (symbolReporter , funcName , trace , libpf .Address (frame .File ), frame .LJCalleePC )
460
431
461
432
return err
462
433
}
0 commit comments