Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeAOT createdump fork/exec for crash dump generation #89203

Merged
merged 15 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/coreclr/debug/createdump/crashinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CrashInfo::CrashInfo(const CreateDumpOptions& options) :
m_gatherFrames(options.CrashReport),
m_crashThread(options.CrashThread),
m_signal(options.Signal),
m_exceptionRecord(options.ExceptionRecord),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be m_exceptionRecordAddr

m_moduleInfos(&ModuleInfoCompare),
m_mainModule(nullptr),
m_cbModuleMappings(0),
Expand All @@ -39,7 +40,7 @@ CrashInfo::CrashInfo(const CreateDumpOptions& options) :
m_siginfo.si_signo = options.Signal;
m_siginfo.si_code = options.SignalCode;
m_siginfo.si_errno = options.SignalErrno;
m_siginfo.si_addr = options.SignalAddress;
m_siginfo.si_addr = (void*)options.SignalAddress;
}

CrashInfo::~CrashInfo()
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/debug/createdump/crashinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CrashInfo : public ICLRDataEnumMemoryRegionsCallback, public ICLRDataLoggi
bool m_gatherFrames; // if true, add the native and managed stack frames to the thread info
pid_t m_crashThread; // crashing thread id or 0 if none
uint32_t m_signal; // crash signal code or 0 if none
uint64_t m_exceptionRecord; // exception record address or 0 if none
std::string m_name; // exe name
siginfo_t m_siginfo; // signal info (if any)
std::string m_coreclrPath; // the path of the coreclr module or empty if none
Expand Down Expand Up @@ -115,6 +116,7 @@ class CrashInfo : public ICLRDataEnumMemoryRegionsCallback, public ICLRDataLoggi
inline const bool GatherFrames() const { return m_gatherFrames; }
inline const pid_t CrashThread() const { return m_crashThread; }
inline const uint32_t Signal() const { return m_signal; }
inline const uint64_t ExceptionRecord () const { return m_exceptionRecord; }
inline const std::string& Name() const { return m_name; }
inline const ModuleInfo* MainModule() const { return m_mainModule; }
inline const uint64_t RuntimeBaseAddress() const { return m_runtimeBaseAddress; }
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/debug/createdump/createdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ typedef struct
int Signal;
int SignalCode;
int SignalErrno;
void* SignalAddress;
uint64_t SignalAddress;
uint64_t ExceptionRecord;
} CreateDumpOptions;

#ifdef HOST_UNIX
Expand Down
11 changes: 7 additions & 4 deletions src/coreclr/debug/createdump/createdumpmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ int createdump_main(const int argc, const char* argv[])
options.Signal = 0;
options.CrashThread = 0;
options.Pid = 0;
#if defined(HOST_UNIX) && !defined(HOST_OSX)
options.SignalCode = 0;
options.SignalErrno = 0;
options.SignalAddress = nullptr;
#endif
options.SignalAddress = 0;
options.ExceptionRecord = 0;
bool help = false;
int exitCode = 0;

Expand Down Expand Up @@ -141,7 +140,11 @@ int createdump_main(const int argc, const char* argv[])
}
else if (strcmp(*argv, "--address") == 0)
{
options.SignalAddress = (void*)atoll(*++argv);
options.SignalAddress = atoll(*++argv);
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
}
else if (strcmp(*argv, "--exception-record") == 0)
{
options.ExceptionRecord = atoll(*++argv);
}
#endif
else if ((strcmp(*argv, "-d") == 0) || (strcmp(*argv, "--diag") == 0))
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/RuntimeInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool ShouldHijackForGcStress(uintptr_t CallsiteIP, HijackType ht);
#include "shash.inl"

#define MAX_CRASHINFOBUFFER_SIZE 8192
uint8_t g_CrashInfoBuffer[MAX_CRASHINFOBUFFER_SIZE];
uint8_t g_CrashInfoBuffer[MAX_CRASHINFOBUFFER_SIZE] = { 0 };

ThreadStore * RuntimeInstance::GetThreadStore()
{
Expand Down
21 changes: 17 additions & 4 deletions src/coreclr/nativeaot/Runtime/unix/PalCreateDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,12 @@ CreateCrashDump(
Parameters:
signal - POSIX signal number or 0
siginfo - signal info or nullptr
exceptionRecord - address of exception record or nullptr

(no return value)
--*/
void
PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo)
PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* exceptionRecord)
{
// If enabled, launch the create minidump utility and wait until it completes
if (g_argvCreateDump[0] != nullptr)
Expand All @@ -358,6 +359,7 @@ PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo)
char* signalCodeArg = nullptr;
char* signalErrnoArg = nullptr;
char* signalAddressArg = nullptr;
char* exceptionRecordArg = nullptr;

// Copy the createdump argv
int argc = 0;
Expand Down Expand Up @@ -388,7 +390,7 @@ PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo)
argv[argc++] = crashThreadArg;
}

if (siginfo != nullptr)
if (siginfo != nullptr && argc < MAX_ARGV_ENTRIES)
{
signalCodeArg = FormatInt(siginfo->si_code);
if (signalCodeArg != nullptr)
Expand All @@ -410,6 +412,16 @@ PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo)
}
}

if (exceptionRecord != nullptr && argc < MAX_ARGV_ENTRIES)
{
exceptionRecordArg = FormatInt64((uint64_t)exceptionRecord);
if (exceptionRecordArg != nullptr)
{
argv[argc++] = "--exception-record";
argv[argc++] = exceptionRecordArg;
}
}

argv[argc++] = nullptr;
assert(argc < MAX_ARGV_ENTRIES);
}
Expand All @@ -421,19 +433,20 @@ PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo)
free(signalCodeArg);
free(signalErrnoArg);
free(signalAddressArg);
free(exceptionRecordArg);
}
}

void
PalCreateCrashDumpIfEnabled()
{
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr);
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr, nullptr);
}

void
PalCreateCrashDumpIfEnabled(void* pExceptionRecord, void* pExContext)
{
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr);
PalCreateCrashDumpIfEnabled(SIGABRT, nullptr, pExceptionRecord);
}

/*++
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/unix/PalCreateDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

extern bool PalCreateDumpInitialize();
extern void PalCreateCrashDumpIfEnabled();
extern void PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo);
extern void PalCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo = nullptr, void* exceptionRecord = nullptr);
extern void PalCreateCrashDumpIfEnabled(void* pExceptionRecord, void* pExContext);