Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit f19e10b

Browse files
committed
[[ Tools ]] Add support for symbolicating hang reports
Use the command line option --hang to parse the input file as a hang log, which has slightly different structure to a crash log.
1 parent 7b69061 commit f19e10b

File tree

1 file changed

+120
-14
lines changed

1 file changed

+120
-14
lines changed

tools/SymbolicatorScript.livecodescript

Lines changed: 120 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
constant kLiveCodeAppId = "com.runrev.livecode"
33
constant kStagingUrl = "https://downloads.livecode.com/livecode/staging"
44
constant kShortFlags = "v,d,h"
5-
constant kLongFlags = "verbose,debug,help,fetch"
5+
constant kLongFlags = "verbose,debug,help,fetch,hang"
66
constant kValueOptions = "repo,cache-dir,symbol-dir,version,staging-url,edition,output"
77

88
local sDebugging
99
local sVerbose
10+
local sHangReport
1011

1112

1213
---------------------------------------
@@ -33,6 +34,8 @@ on startup
3334
quit 0
3435
end if
3536

37+
if "hang" is among the keys of tArgs then put true into sHangReport
38+
3639
-- Show debugging information?
3740
if "d" or "debug" is among the keys of tArgs then put true into sDebugging
3841

@@ -147,9 +150,9 @@ private command showHelp
147150
return & \
148151
"Usage:" & return & \
149152
" symbolicate.sh --help" & return & \
150-
" symbolicate.sh [-v|--verbose] [-d|--debug] [--repo=...] [--symbol-dir=...]" & return & \
151-
" [--fetch --cache-dir=... [--staging-url=...]] [--version=...]" & return & \
152-
" [--edition=...] [--output=...] input.log" & return & \
153+
" symbolicate.sh [-v|--verbose] [-d|--debug] [--hang] [--repo=...] " & return & \
154+
" [--symbol-dir=...] [--fetch --cache-dir=... [--staging-url=...]] " & return & \
155+
" [--version=...] [--edition=...] [--output=...] input.log" & return & \
153156
return & \
154157
"Options:" & return & \
155158
" --help Displays this message" & return & \
@@ -159,6 +162,9 @@ private command showHelp
159162
" --debug Displays information that may help debug problems with" & return & \
160163
" this script" & return & \
161164
return & \
165+
" --hang Treat the input file as a hang log rather than a crash" & return & \
166+
" log" & return & \
167+
return & \
162168
" --repo=... Path to a current checkout of the LiveCode source code" & return & \
163169
" repository. If not specified, the current directory" & return & \
164170
" will be used." & return & \
@@ -552,11 +558,25 @@ end fetchSymbolsForRevision
552558
---------- SYMBOLICATION ----------
553559
-----------------------------------
554560

561+
private function findLineBeginningWith pWord, pLog
562+
local tFoundLineNumber, tCurrentLine, tNextLine
563+
put lineOffset(pWord, pLog) into tNextLine
564+
repeat while tNextLine is not 0
565+
add tNextLine to tCurrentLine
566+
if line tCurrentLine of pLog begins with pWord then
567+
put tCurrentLine into tFoundLineNumber
568+
exit repeat
569+
end if
570+
put lineOffset(pWord, pLog, tCurrentLine) into tNextLine
571+
end repeat
572+
return tFoundLineNumber
573+
end findLineBeginningWith
574+
555575
-- Guesses the LiveCode engine version and edition from the crash log
556576
private function guessVersionAndEdition pLog, @rVersion, @rEdition
557577
-- Find the line that contains the embedded version information
558578
local tVersionLineNumber
559-
put lineOffset("Version:", pLog) into tVersionLineNumber
579+
put findLineBeginningWith("Version:", pLog) into tVersionLineNumber
560580
if tVersionLineNumber is zero then return false
561581

562582
-- Version line has the form "Version: 8.0.0.13012 [DP 12]"
@@ -575,12 +595,13 @@ private function guessVersionAndEdition pLog, @rVersion, @rEdition
575595

576596
-- Find the line that contains the process name
577597
local tProcessLineNumber
578-
put lineOffset("Process:", pLog) into tProcessLineNumber
598+
put findLineBeginningWith("Process:", pLog) into tProcessLineNumber
579599
if tProcessLineNumber is zero then return false
580600

581601
-- Look for keywords in the line
582602
local tProcessLine
583603
put line tProcessLineNumber of pLog into tProcessLine
604+
584605
switch
585606
case "LiveCode-Community" is among the words of tProcessLine
586607
put "community" into rEdition
@@ -605,7 +626,7 @@ private function guessVersionAndEdition pLog, @rVersion, @rEdition
605626
end guessVersionAndEdition
606627

607628
-- Finds the line range in the given log that corresponds to the stack trace of the crashed thread
608-
private command findStackTraceLineRange pLog, @rStart, @rEnd
629+
private command findCrashStackTraceLineRange pLog, @rStart, @rEnd
609630
-- The stack trace begins after a line with "Thread N Crashed:"
610631
local tStackTraceLineNumber
611632
put lineOffset("Crashed:", pLog) into tStackTraceLineNumber
@@ -620,14 +641,14 @@ private command findStackTraceLineRange pLog, @rStart, @rEnd
620641

621642
put tStackTraceLineNumber+1 into rStart
622643
put tStackTraceLineNumber+tStackTraceLineCount into rEnd
623-
end findStackTraceLineRange
644+
end findCrashStackTraceLineRange
624645

625646
-- Takes an OSX crash log and finds the addresses needing symbolicated
626-
function addressesFromLog pLog
647+
function addressesFromCrashLog pLog
627648
-- Find the range that represents the stack trace needing symbolicated
628649
local tStackTraceStart
629650
local tStackTraceEnd
630-
findStackTraceLineRange pLog, tStackTraceStart, tStackTraceEnd
651+
findCrashStackTraceLineRange pLog, tStackTraceStart, tStackTraceEnd
631652

632653
-- Extract just the stack trace then find the addresses in the trace
633654
local tStackTrace
@@ -640,6 +661,55 @@ function addressesFromLog pLog
640661
end repeat
641662

642663
return tOutput
664+
end addressesFromCrashLog
665+
666+
-- Finds the line range in the given log that corresponds to the stack trace
667+
-- of the
668+
private command findHangStackTraceLineRange pLog, @rStart, @rEnd
669+
-- The stack trace begins after a line with "Thread N Crashed:"
670+
local tStackTraceLineNumber
671+
put lineOffset("Heaviest", pLog) into tStackTraceLineNumber
672+
if tStackTraceLineNumber is zero then throw "Could not find stack trace"
673+
674+
-- Count the number of lines in the stack trace
675+
-- Just keep going until there is a blank line
676+
local tStackTraceLineCount
677+
678+
repeat while word 1 of line (tStackTraceLineNumber+tStackTraceLineCount+1) of pLog is not empty
679+
put tStackTraceLineCount + 1 into tStackTraceLineCount
680+
end repeat
681+
682+
put tStackTraceLineNumber+1 into rStart
683+
put tStackTraceLineNumber+tStackTraceLineCount into rEnd
684+
end findHangStackTraceLineRange
685+
686+
-- Takes an OSX hang report and finds the addresses needing symbolicated
687+
function addressesFromHangReport pLog
688+
-- Find the range that represents the stack trace needing symbolicated
689+
local tStackTraceStart
690+
local tStackTraceEnd
691+
findHangStackTraceLineRange pLog, tStackTraceStart, tStackTraceEnd
692+
693+
-- Extract just the stack trace then find the addresses in the trace
694+
local tStackTrace
695+
put line tStackTraceStart to tStackTraceEnd of pLog into tStackTrace
696+
697+
local tOutput
698+
repeat for each line tLine in tStackTrace
699+
-- The address is enclosed in square brackets as word -1 of each line
700+
put char 2 to -2 of word -1 of tLine & return after tOutput
701+
end repeat
702+
703+
return tOutput
704+
end addressesFromHangReport
705+
706+
-- Finds the addresses needing symbolicated from the given log
707+
function addressesFromLog pLog
708+
if sHangReport then
709+
return addressesFromHangReport(pLog)
710+
else
711+
return addressesFromCrashLog(pLog)
712+
end if
643713
end addressesFromLog
644714

645715
-- Finds the load address of the LiveCode executable in the given crash log
@@ -650,10 +720,15 @@ function loadAddressFromLog pLog
650720
if tHeaderOffset is zero then throw "Couldn't find load addresses list"
651721

652722
-- Find the line containing the LiveCode IDE identifier ("com.runrev.livecode")
653-
local tExeLineOffset
723+
local tExeLineOffset, tCheckAppID
724+
put kLiveCodeAppId into tCheckAppId
725+
if not sHangReport then
726+
put "+" before tCheckAppId
727+
end if
728+
654729
repeat with i = tHeaderOffset+1 to the number of lines of pLog
655730
-- Format of lines is "0xXXXX - 0xYYYY +com.runrev.livecode"
656-
if word 4 of line i of pLog is "+" & kLiveCodeAppId then exit repeat
731+
if word 4 of line i of pLog is tCheckAppId then exit repeat
657732
end repeat
658733
if i > the number of lines of pLog then throw "Could not find LiveCode executable's load offset"
659734
put i into tExeLineOffset
@@ -685,11 +760,11 @@ function symbolsForAddresses pAddresses, pAppBundle, pLoadAddress
685760
return tSymbols
686761
end symbolsForAddresses
687762

688-
function mergeSymbolsIntoLog pLog, pSymbols
763+
function mergeSymbolsIntoCrashLog pLog, pSymbols
689764
-- Find the line range of the stack trace that was symbolicated
690765
local tStackTraceStart
691766
local tStackTraceEnd
692-
findStackTraceLineRange pLog, tStackTraceStart, tStackTraceEnd
767+
findCrashStackTraceLineRange pLog, tStackTraceStart, tStackTraceEnd
693768

694769
-- Sanity check
695770
if the number of lines of pSymbols is not (tStackTraceEnd - tStackTraceStart + 1) then throw "symbolicated trace is different length to original"
@@ -706,6 +781,37 @@ function mergeSymbolsIntoLog pLog, pSymbols
706781

707782
-- Return the modified log
708783
return pLog
784+
end mergeSymbolsIntoCrashLog
785+
786+
function mergeSymbolsIntoHangReport pLog, pSymbols
787+
-- Find the line range of the stack trace that was symbolicated
788+
local tStackTraceStart
789+
local tStackTraceEnd
790+
findHangStackTraceLineRange pLog, tStackTraceStart, tStackTraceEnd
791+
792+
-- Sanity check
793+
if the number of lines of pSymbols is not (tStackTraceEnd - tStackTraceStart + 1) then throw "symbolicated trace is different length to original"
794+
795+
-- Loop through the symbols list and replace where appropriate
796+
repeat with i = 0 to (the number of lines of pSymbols) - 1
797+
-- In the original log, is this a LiveCode symbol?
798+
if line (tStackTraceStart+i) of pLog contains "LiveCode" then
799+
local tSymbol
800+
put line (i+1) of pSymbols into tSymbol
801+
put tSymbol into word 2 of line (tStackTraceStart+i) of pLog
802+
end if
803+
end repeat
804+
805+
-- Return the modified log
806+
return pLog
807+
end mergeSymbolsIntoHangReport
808+
809+
function mergeSymbolsIntoLog pLog, pSymbols
810+
if sHangReport then
811+
return mergeSymbolsIntoHangReport(pLog, pSymbols)
812+
else
813+
return mergeSymbolsIntoCrashLog(pLog, pSymbols)
814+
end if
709815
end mergeSymbolsIntoLog
710816

711817
function symbolicateLog pLog, pAppBundle

0 commit comments

Comments
 (0)