Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/TraceEvent/TraceEventStacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,17 @@ private bool ReasonableTopFrame(StackSourceCallStackIndex callStackIndex, Thread
return true;
}

// On Linux, threads start from libc's __clone3, __clone, or __libc_start_main.
// Match libc.so.6, libc.so, libc-2.31.so, etc.
string moduleFileName = moduleFile.Name;
if (string.Compare(moduleFileName, "libc", StringComparison.OrdinalIgnoreCase) == 0 ||
moduleFileName.StartsWith("libc.", StringComparison.OrdinalIgnoreCase) ||
moduleFileName.StartsWith("libc-", StringComparison.OrdinalIgnoreCase))
{
m_goodTopModuleIndex = moduleFileIndex;
return true;
}

// The special processes 4 (System) and 0 (Kernel) can stay in the kernel without being broken.
if (moduleFile.FilePath.EndsWith("ntoskrnl.exe", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -873,7 +884,13 @@ public StackSourceCallStackIndex GetCallStack(CallStackIndex callStackIndex, Sta
var bangIdx = frameName.IndexOf('!');
if (0 < bangIdx)
{
if (!(5 <= bangIdx && string.Compare(frameName, bangIdx - 5, "ntdll", 0, 5, StringComparison.OrdinalIgnoreCase) == 0))
// Allow ntdll (Windows) and libc (Linux: libc.so.6, libc-2.31.so, etc.) as valid thread roots.
bool isNtdll = 5 <= bangIdx && string.Compare(frameName, bangIdx - 5, "ntdll", 0, 5, StringComparison.OrdinalIgnoreCase) == 0;
// Match libc, libc.so, libc.so.6, libc-2.31.so, but not libcrypto etc.
bool isLibc = 4 <= bangIdx &&
string.Compare(frameName, 0, "libc", 0, 4, StringComparison.OrdinalIgnoreCase) == 0 &&
(bangIdx == 4 || frameName[4] == '.' || frameName[4] == '-');
if (!isNtdll && !isLibc)
{
var brokenFrame = m_Interner.FrameIntern("BROKEN", m_emptyModuleIdx);
callerIdx = m_Interner.CallStackIntern(brokenFrame, callerIdx);
Expand Down