@@ -1126,8 +1126,7 @@ func (i *v8Instance) getSFI(taggedPtr libpf.Address) (*v8SFI, error) {
11261126 if sodiType == vms .Type .Script {
11271127 sfi .source = i .getSource (sodiAddr )
11281128 if sfi .funcStartPos != sfi .funcEndPos {
1129- sfi .funcStartLine = mapPositionToLine (sfi .source .lineTable ,
1130- int32 (sfi .funcStartPos ))
1129+ sfi .funcStartLine , _ = mapPositionToLine (sfi .source .lineTable , int32 (sfi .funcStartPos ))
11311130 }
11321131 }
11331132
@@ -1451,33 +1450,43 @@ func decodePosition(table []byte, delta uint64) sourcePosition {
14511450 }
14521451}
14531452
1454- // mapPositionToLine maps a file position (byte offset) to a line number. This is
1455- // done against a table containing a offsets where each line ends.
1456- func mapPositionToLine (lineEnds []uint32 , pos int32 ) libpf.SourceLineno {
1453+ // mapPositionToLine maps a file position (byte offset) to a line number and column
1454+ // number. This is done against a table containing offsets where each line ends.
1455+ func mapPositionToLine (lineEnds []uint32 , pos int32 ) ( libpf.SourceLineno , libpf. SourceColumn ) {
14571456 if len (lineEnds ) == 0 || pos < 0 {
1458- return 0
1457+ return 0 , 0
14591458 }
14601459 // Use binary search to locate the line number
14611460 index := sort .Search (len (lineEnds ), func (ndx int ) bool {
14621461 return lineEnds [ndx ] >= uint32 (pos )
14631462 })
1464- return libpf .SourceLineno (index + 1 )
1463+
1464+ // Calculate column: position - start of line
1465+ // The start of line is the end of previous line + 1 (or 0 for first line)
1466+ var lineStart uint32
1467+ if index > 0 {
1468+ lineStart = lineEnds [index - 1 ] + 1
1469+ }
1470+
1471+ column := uint32 (pos ) - lineStart
1472+
1473+ return libpf .SourceLineno (index + 1 ), libpf .SourceColumn (column )
14651474}
14661475
1467- // scriptOffsetToLine maps a sourcePosition to a line number in the corresponding source
1468- func (sfi * v8SFI ) scriptOffsetToLine (position sourcePosition ) libpf.SourceLineno {
1476+ // scriptOffsetToLine maps a sourcePosition to a line and column number in the corresponding source
1477+ func (sfi * v8SFI ) scriptOffsetToLine (position sourcePosition ) ( libpf.SourceLineno , libpf. SourceColumn ) {
14691478 scriptOffset := position .scriptOffset ()
14701479 // The scriptOffset is offset by one, to make kNoSourcePosition zero.
14711480 //nolint:lll
14721481 // https://chromium.googlesource.com/v8/v8.git/+/refs/tags/9.2.230.1/src/codegen/source-position.h#93
14731482 if scriptOffset == 0 {
1474- return sfi .funcStartLine
1483+ return sfi .funcStartLine , 0
14751484 }
14761485 return mapPositionToLine (sfi .source .lineTable , scriptOffset - 1 )
14771486}
14781487
14791488// appendFrame adds a new frame to frames.
1480- func (i * v8Instance ) appendFrame (frames * libpf.Frames , sfi * v8SFI , lineNo libpf.SourceLineno ) {
1489+ func (i * v8Instance ) appendFrame (frames * libpf.Frames , sfi * v8SFI , lineNo libpf.SourceLineno , column libpf. SourceColumn ) {
14811490 funcOffset := uint32 (0 )
14821491 if lineNo > sfi .funcStartLine {
14831492 funcOffset = uint32 (lineNo - sfi .funcStartLine )
@@ -1487,6 +1496,7 @@ func (i *v8Instance) appendFrame(frames *libpf.Frames, sfi *v8SFI, lineNo libpf.
14871496 FunctionName : sfi .funcName ,
14881497 SourceFile : sfi .source .fileName ,
14891498 SourceLine : lineNo ,
1499+ SourceColumn : column ,
14901500 FunctionOffset : funcOffset ,
14911501 })
14921502}
@@ -1505,15 +1515,15 @@ func (i *v8Instance) generateNativeFrame(sourcePos sourcePosition, sfi *v8SFI,
15051515 return
15061516 }
15071517
1508- lineNo := sfi .scriptOffsetToLine (sourcePos )
1509- i .appendFrame (frames , sfi , lineNo )
1518+ lineNo , column := sfi .scriptOffsetToLine (sourcePos )
1519+ i .appendFrame (frames , sfi , lineNo , column )
15101520}
15111521
15121522// appendBytecodeFrame symbolizes and records to a trace a Bytecode based frame.
15131523func (i * v8Instance ) appendBytecodeFrame (sfi * v8SFI , delta uint64 , frames * libpf.Frames ) {
15141524 sourcePos := decodePosition (sfi .bytecodePositionTable , delta )
1515- lineNo := sfi .scriptOffsetToLine (sourcePos )
1516- i .appendFrame (frames , sfi , lineNo )
1525+ lineNo , column := sfi .scriptOffsetToLine (sourcePos )
1526+ i .appendFrame (frames , sfi , lineNo , column )
15171527}
15181528
15191529// symbolizeSFI symbolizes and records to a trace a SharedFunctionInfo based frame.
0 commit comments