@@ -36,7 +36,7 @@ type Process struct {
36
36
37
37
// Runtime info for easier lookup.
38
38
rtGlobals map [string ]region
39
- rtConsts map [ string ] int64
39
+ rtConsts constsMap
40
40
41
41
// A module is a loadable unit. Most Go programs have 1, programs
42
42
// which load plugins will have more.
@@ -98,7 +98,7 @@ func Core(proc *core.Process) (p *Process, err error) {
98
98
}
99
99
p .rtTypeByName [name ] = t
100
100
}
101
- p .rtConsts , err = readRuntimeConstants (proc )
101
+ p .rtConsts , err = readConstants (proc )
102
102
if err != nil {
103
103
return nil , err
104
104
}
@@ -201,11 +201,11 @@ func readHeap(p *Process) (*heapTable, *Statistic, error) {
201
201
mheap := p .rtGlobals ["mheap_" ]
202
202
203
203
var arenas []arena
204
- arenaSize := p .rtConsts [ " heapArenaBytes"]
204
+ arenaSize := p .rtConsts . get ( "runtime. heapArenaBytes")
205
205
if arenaSize % heapInfoSize != 0 {
206
206
panic ("arenaSize not a multiple of heapInfoSize" )
207
207
}
208
- arenaBaseOffset := - p .rtConsts [ " arenaBaseOffsetUintptr"]
208
+ arenaBaseOffset := - p .rtConsts . get ( "runtime. arenaBaseOffsetUintptr")
209
209
if p .proc .PtrSize () == 4 && arenaBaseOffset != 0 {
210
210
panic ("arenaBaseOffset must be 0 for 32-bit inferior" )
211
211
}
@@ -312,17 +312,17 @@ func readHeap0(p *Process, mheap region, arenas []arena, arenaBaseOffset int64)
312
312
return nil , nil , errors .New ("weird mapping " + m .Perm ().String ())
313
313
}
314
314
}
315
- pageSize := p .rtConsts [ " _PageSize"]
315
+ pageSize := p .rtConsts . get ( "runtime. _PageSize")
316
316
317
317
// Span types.
318
- spanInUse := uint8 (p .rtConsts [ " mSpanInUse"] )
319
- spanManual := uint8 (p .rtConsts [ " mSpanManual"] )
320
- spanDead := uint8 (p .rtConsts [ " mSpanDead"] )
318
+ spanInUse := uint8 (p .rtConsts . get ( "runtime. mSpanInUse") )
319
+ spanManual := uint8 (p .rtConsts . get ( "runtime. mSpanManual") )
320
+ spanDead := uint8 (p .rtConsts . get ( "runtime. mSpanDead") )
321
321
322
322
// Malloc header constants (go 1.22+)
323
- minSizeForMallocHeader := int64 (p .rtConsts [ " minSizeForMallocHeader"] )
324
- mallocHeaderSize := int64 (p .rtConsts [ " mallocHeaderSize"] )
325
- maxSmallSize := int64 (p .rtConsts [ " maxSmallSize"] )
323
+ minSizeForMallocHeader := int64 (p .rtConsts . get ( "runtime. minSizeForMallocHeader") )
324
+ mallocHeaderSize := int64 (p .rtConsts . get ( "runtime. mallocHeaderSize") )
325
+ maxSmallSize := int64 (p .rtConsts . get ( "runtime. maxSmallSize") )
326
326
327
327
abiType := p .tryFindType ("internal/abi.Type" )
328
328
@@ -402,7 +402,7 @@ func readHeap0(p *Process, mheap region, arenas []arena, arenaBaseOffset int64)
402
402
// Process special records.
403
403
for sp := s .Field ("specials" ); sp .Address () != 0 ; sp = sp .Field ("next" ) {
404
404
sp = sp .Deref () // *special to special
405
- if sp .Field ("kind" ).Uint8 () != uint8 (p .rtConsts [ " _KindSpecialFinalizer"] ) {
405
+ if sp .Field ("kind" ).Uint8 () != uint8 (p .rtConsts . get ( "runtime. _KindSpecialFinalizer") ) {
406
406
// All other specials (just profile records) can't point into the heap.
407
407
continue
408
408
}
@@ -466,7 +466,8 @@ func readHeap0(p *Process, mheap region, arenas []arena, arenaBaseOffset int64)
466
466
}
467
467
typ := region {p : p .proc , a : typeAddr , typ : abiType }
468
468
nptrs := int64 (typ .Field ("PtrBytes" ).Uintptr ()) / int64 (heap .ptrSize )
469
- if typ .Field ("Kind_" ).Uint8 ()& uint8 (p .rtConsts ["kindGCProg" ]) != 0 {
469
+ kindGCProg , hasGCProgs := p .rtConsts .find ("internal/abi.KindGCProg" )
470
+ if hasGCProgs && typ .Field ("Kind_" ).Uint8 ()& uint8 (kindGCProg ) != 0 {
470
471
panic ("unexpected GC prog on small allocation" )
471
472
}
472
473
gcdata := typ .Field ("GCData" ).Address ()
@@ -485,7 +486,8 @@ func readHeap0(p *Process, mheap region, arenas []arena, arenaBaseOffset int64)
485
486
// is in use.
486
487
typ := s .Field ("largeType" ).Deref ()
487
488
nptrs := int64 (typ .Field ("PtrBytes" ).Uintptr ()) / int64 (heap .ptrSize )
488
- if typ .Field ("Kind_" ).Uint8 ()& uint8 (p .rtConsts ["kindGCProg" ]) != 0 {
489
+ kindGCProg , hasGCProgs := p .rtConsts .find ("internal/abi.KindGCProg" )
490
+ if hasGCProgs && typ .Field ("Kind_" ).Uint8 ()& uint8 (kindGCProg ) != 0 {
489
491
panic ("large object's GCProg was not unrolled" )
490
492
}
491
493
gcdata := typ .Field ("GCData" ).Address ()
@@ -513,9 +515,9 @@ func readHeap0(p *Process, mheap region, arenas []arena, arenaBaseOffset int64)
513
515
// Also keep track of how much has been scavenged.
514
516
pages := mheap .Field ("pages" )
515
517
chunks := pages .Field ("chunks" )
516
- pallocChunkBytes := p .rtConsts [ " pallocChunkBytes"]
517
- pallocChunksL1Bits := p .rtConsts [ " pallocChunksL1Bits"]
518
- pallocChunksL2Bits := p .rtConsts [ " pallocChunksL2Bits"]
518
+ pallocChunkBytes := p .rtConsts . get ( "runtime. pallocChunkBytes")
519
+ pallocChunksL1Bits := p .rtConsts . get ( "runtime. pallocChunksL1Bits")
520
+ pallocChunksL2Bits := p .rtConsts . get ( "runtime. pallocChunksL2Bits")
519
521
inuse := pages .Field ("inUse" )
520
522
ranges := inuse .Field ("ranges" )
521
523
for i := int64 (0 ); i < ranges .SliceLen (); i ++ {
@@ -621,24 +623,24 @@ func readGoroutine(p *Process, r region, dwarfVars map[*Func][]dwarfVar) (*Gorou
621
623
}
622
624
st := r .Field ("atomicstatus" ).Field ("value" )
623
625
status := st .Uint32 ()
624
- status &^= uint32 (p .rtConsts [ " _Gscan"] )
626
+ status &^= uint32 (p .rtConsts . get ( "runtime. _Gscan") )
625
627
var sp , pc core.Address
626
628
switch status {
627
- case uint32 (p .rtConsts [ " _Gidle"] ):
629
+ case uint32 (p .rtConsts . get ( "runtime. _Gidle") ):
628
630
return g , nil
629
- case uint32 (p .rtConsts [ " _Grunnable"]) , uint32 (p .rtConsts [ " _Gwaiting"] ):
631
+ case uint32 (p .rtConsts . get ( "runtime. _Grunnable")) , uint32 (p .rtConsts . get ( "runtime. _Gwaiting") ):
630
632
sched := r .Field ("sched" )
631
633
sp = core .Address (sched .Field ("sp" ).Uintptr ())
632
634
pc = core .Address (sched .Field ("pc" ).Uintptr ())
633
- case uint32 (p .rtConsts [ " _Grunning"] ):
635
+ case uint32 (p .rtConsts . get ( "runtime. _Grunning") ):
634
636
sp = osT .SP ()
635
637
pc = osT .PC ()
636
638
// TODO: back up to the calling frame?
637
- case uint32 (p .rtConsts [ " _Gsyscall"] ):
639
+ case uint32 (p .rtConsts . get ( "runtime. _Gsyscall") ):
638
640
sp = core .Address (r .Field ("syscallsp" ).Uintptr ())
639
641
pc = core .Address (r .Field ("syscallpc" ).Uintptr ())
640
642
// TODO: or should we use the osT registers?
641
- case uint32 (p .rtConsts [ " _Gdead"] ):
643
+ case uint32 (p .rtConsts . get ( "runtime. _Gdead") ):
642
644
return nil , nil
643
645
// TODO: copystack, others?
644
646
default :
@@ -874,6 +876,8 @@ func readGoroutine(p *Process, r region, dwarfVars map[*Func][]dwarfVar) (*Gorou
874
876
} else {
875
877
sp = f .max
876
878
pc = core .Address (p .proc .ReadUintptr (sp - 8 )) // TODO:amd64 only
879
+
880
+ isCrashFrame = false
877
881
}
878
882
if pc == 0 {
879
883
// TODO: when would this happen?
@@ -905,7 +909,7 @@ func readFrame(p *Process, sp, pc core.Address) (*Frame, error) {
905
909
906
910
// Find live ptrs in locals
907
911
live := map [core.Address ]bool {}
908
- if x := int (p .rtConsts [ "_FUNCDATA_LocalsPointerMaps" ] ); x < len (f .funcdata ) {
912
+ if x := int (p .rtConsts . get ( "internal/abi.FUNCDATA_LocalsPointerMaps" ) ); x < len (f .funcdata ) {
909
913
addr := f .funcdata [x ]
910
914
// TODO: Ideally we should have the same frame size check as
911
915
// runtime.getStackSize to detect errors when we are missing
@@ -918,7 +922,10 @@ func readFrame(p *Process, sp, pc core.Address) (*Frame, error) {
918
922
if err != nil {
919
923
return nil , fmt .Errorf ("cannot read stack map at pc=%#x: %v" , pc , err )
920
924
}
921
- if idx < 0 {
925
+ if idx < - 1 {
926
+ return nil , fmt .Errorf ("cannot read stack map at pc=%#x: invalid stack map index %d" , pc , idx )
927
+ }
928
+ if idx == - 1 {
922
929
idx = 0
923
930
}
924
931
if idx < int64 (n ) {
@@ -934,7 +941,7 @@ func readFrame(p *Process, sp, pc core.Address) (*Frame, error) {
934
941
}
935
942
}
936
943
// Same for args
937
- if x := int (p .rtConsts [ "_FUNCDATA_ArgsPointerMaps" ] ); x < len (f .funcdata ) {
944
+ if x := int (p .rtConsts . get ( "internal/abi.FUNCDATA_ArgsPointerMaps" ) ); x < len (f .funcdata ) {
938
945
addr := f .funcdata [x ]
939
946
if addr != 0 {
940
947
args := region {p : p .proc , a : addr , typ : p .findType ("runtime.stackmap" )}
@@ -944,11 +951,14 @@ func readFrame(p *Process, sp, pc core.Address) (*Frame, error) {
944
951
if err != nil {
945
952
return nil , fmt .Errorf ("cannot read stack map at pc=%#x: %v" , pc , err )
946
953
}
947
- if idx < 0 {
954
+ if idx < - 1 {
955
+ return nil , fmt .Errorf ("cannot read stack map at pc=%#x: invalid stack map index %d" , pc , idx )
956
+ }
957
+ if idx == - 1 {
948
958
idx = 0
949
959
}
950
960
if idx < int64 (n ) {
951
- bits := args .Field ("bytedata" ).a .Add (int64 (nbit + 7 ) / 8 * idx )
961
+ bits := args .Field ("bytedata" ).a .Add (( int64 (nbit + 7 ) / 8 ) * idx )
952
962
base := frame .max
953
963
// TODO: add to base for LR archs.
954
964
for i := int64 (0 ); i < int64 (nbit ); i ++ {
0 commit comments