Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2739,13 +2739,22 @@ static void DoNotOptimize(const void* p)
--*/
#ifdef HOST_ANDROID
#include <minipal/log.h>
extern "C" void LogCallstackForAndroidNativeCrash() __attribute__((weak));
VOID
PROCCreateCrashDumpIfEnabled(int signal, siginfo_t* siginfo, void* context, bool serialize)
{
// Preserve context pointer to prevent optimization
DoNotOptimize(&context);

// TODO: Dump all managed threads callstacks into logcat and/or file?
if (LogCallstackForAndroidNativeCrash != nullptr)
{
minipal_log_write_fatal("\n=================================================================\n");
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the ======================== separators? We do not use a separators like that anywhere else in CoreCLR.

Copy link
Member Author

@mdh1418 mdh1418 Jan 31, 2026

Choose a reason for hiding this comment

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

No they're not needed, I had initially just used the format that Android Mono was using

g_async_safe_printf ("\n=================================================================\n");
g_async_safe_printf ("\tManaged Stacktrace:\n");
g_async_safe_printf ("=================================================================\n");
mono_walk_stack_full (print_stack_frame_signal_safe, mctx, jit_tls, mono_get_lmf (), MONO_UNWIND_LOOKUP_IL_OFFSET | MONO_UNWIND_SIGNAL_SAFE, NULL);
g_async_safe_printf ("=================================================================\n");

minipal_log_write_fatal("\tManaged Stacktrace:\n");
Copy link
Member

Choose a reason for hiding this comment

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

This should something more self-explanatory than just "Managed stacktrace:". Maybe something like "Crash in native code".

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought PROCCreateCrashDumpIfEnabled also gets hit for unhandled managed exceptions. Would it still be fine to classify that as crash in native code? Maybe also Crash report: would align more given the hope is this would be replaced by real create dump logic.

minipal_log_write_fatal("=================================================================\n");
LogCallstackForAndroidNativeCrash();
minipal_log_write_fatal("=================================================================\n");
}

// TODO: Dump stress log into logcat and/or file when enabled?
minipal_log_write_fatal("Aborting process.\n");
}
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/vm/eepolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,3 +896,17 @@ int NOINLINE EEPolicy::HandleFatalError(UINT exitCode, UINT_PTR address, LPCWSTR
UNREACHABLE();
return -1;
}

#ifdef HOST_ANDROID
// Until Android CoreCLR is able to create dumps, provide a way for PROCCreateCrashDumpIfEnabled to log the managed callstack.
extern "C" void LogCallstackForAndroidNativeCrash()
{
WRAPPER_NO_CONTRACT;

Thread *pThread = GetThreadNULLOk();
if (pThread != NULL)
{
LogCallstackForLogWorker(pThread, NULL);
}
}
#endif // HOST_ANDROID
Loading