Optional fixOffByOneWithPreferSouceMapSymbols arg to make names match align with JS stack (#88)
This commit is contained in:
Родитель
c3706e804c
Коммит
8346f5852f
|
@ -16,12 +16,16 @@ namespace SourcemapToolkit.CallstackDeminifier
|
|||
{
|
||||
_stackFrameDeminifier = stackFrameDeminifier;
|
||||
_stackTraceParser = stackTraceParser;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses and deminifies a string containing a minified stack trace.
|
||||
/// </summary>
|
||||
public DeminifyStackTraceResult DeminifyStackTrace(string stackTraceString, bool preferSourceMapsSymbols = false)
|
||||
/// </summary>
|
||||
/// <param name="stackTraceString">stack trace as string, to deobfuscate</param>
|
||||
/// <param name="preferSourceMapsSymbols">if true, we will use exact sourcemap names for deobfuscation, without guessing the wrapper function name from source code</param>
|
||||
/// <param name="fixOffByOneWithPreferSouceMapSymbols">preferSourceMapsSymbols uses name at call site in deobfuscated frame. Passing this as true fixes that case, to use the caller function name from next frame</param>
|
||||
/// <returns></returns>
|
||||
public DeminifyStackTraceResult DeminifyStackTrace(string stackTraceString, bool preferSourceMapsSymbols = false, bool fixOffByOneWithPreferSouceMapSymbols = false)
|
||||
{
|
||||
var minifiedStackFrames = _stackTraceParser.ParseStackTrace(stackTraceString, out string message);
|
||||
var deminifiedStackFrameResults = new List<StackFrameDeminificationResult>(minifiedStackFrames.Count);
|
||||
|
@ -37,7 +41,26 @@ namespace SourcemapToolkit.CallstackDeminifier
|
|||
}
|
||||
|
||||
deminifiedStackFrameResults.Reverse();
|
||||
|
||||
if (preferSourceMapsSymbols && fixOffByOneWithPreferSouceMapSymbols)
|
||||
{
|
||||
// we want to move all method names by one frame, so each frame will contain caller name and not callee name. To make callstacks more familiar to C# and js debug versions.
|
||||
// However, for first frame we want to keep calee name (if avaliable) as well since this is interesting info we don't want to lose.
|
||||
// However it means that for last frame (N), if have more then 1 frame in callstack, N-1 frame will have the same name.
|
||||
// It is confusing, so lets replace last one with null. This will cause toString to use the obfuscated name
|
||||
for (int i = 0; i < deminifiedStackFrameResults.Count - 1; i++)
|
||||
{
|
||||
string updatedMethodName = deminifiedStackFrameResults[i + 1].DeminifiedStackFrame.MethodName;
|
||||
if (i == 0 && deminifiedStackFrameResults[i].DeminifiedStackFrame.MethodName != null)
|
||||
{
|
||||
updatedMethodName = updatedMethodName + "=>" + deminifiedStackFrameResults[i].DeminifiedStackFrame.MethodName;
|
||||
}
|
||||
deminifiedStackFrameResults[i].DeminifiedStackFrame.MethodName = updatedMethodName;
|
||||
}
|
||||
if (deminifiedStackFrameResults.Count > 1)
|
||||
{
|
||||
deminifiedStackFrameResults[deminifiedStackFrameResults.Count - 1].DeminifiedStackFrame.MethodName = null;
|
||||
}
|
||||
}
|
||||
var result = new DeminifyStackTraceResult(message, minifiedStackFrames, deminifiedStackFrameResults);
|
||||
|
||||
return result;
|
||||
|
|
Загрузка…
Ссылка в новой задаче