[vm] Make Dart_DumpStackTrace work when there is no current isolate.

Bug: https://github.com/dart-lang/sdk/issues/32391
Change-Id: Idb1b44509a7bf2269e2f2c0dc1f7ffa0a2a4408c
Reviewed-on: https://dart-review.googlesource.com/44804
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This commit is contained in:
Ryan Macnak 2018-03-12 19:59:23 +00:00
parent be916c18ee
commit 180866dc46

View file

@ -419,7 +419,7 @@ static void DumpStackFrame(intptr_t frame_index, uword pc) {
// Only attempt to symbolize Dart frames if we can safely iterate the
// current isolate's heap.
Code& code = Code::Handle(Code::LookupCodeInVmIsolate(pc));
if (!code.IsNull()) {
if (code.IsNull()) {
code = Code::LookupCode(pc); // In current isolate.
}
if (!code.IsNull()) {
@ -934,23 +934,19 @@ static bool ValidateThreadStackBounds(uintptr_t fp,
// Get |thread|'s stack boundary and verify that |sp| and |fp| are within
// it. Return |false| if anything looks suspicious.
static bool GetAndValidateThreadStackBounds(Thread* thread,
static bool GetAndValidateThreadStackBounds(OSThread* os_thread,
Thread* thread,
uintptr_t fp,
uintptr_t sp,
uword* stack_lower,
uword* stack_upper) {
OSThread* os_thread = NULL;
if (thread != NULL) {
os_thread = thread->os_thread();
} else {
os_thread = OSThread::Current();
}
ASSERT(os_thread != NULL);
ASSERT(stack_lower != NULL);
ASSERT(stack_upper != NULL);
#if defined(USING_SIMULATOR)
const bool use_simulator_stack_bounds = thread->IsExecutingDartCode();
const bool use_simulator_stack_bounds =
thread != NULL && thread->IsExecutingDartCode();
if (use_simulator_stack_bounds) {
Isolate* isolate = thread->isolate();
ASSERT(isolate != NULL);
@ -1098,31 +1094,20 @@ void Profiler::DumpStackTrace(uword sp, uword fp, uword pc, bool for_crash) {
}
}
Thread* thread = Thread::Current();
if (thread == NULL) {
OS::PrintErr("Stack dump aborted because no current Dart thread.\n");
return;
}
OSThread* os_thread = thread->os_thread();
OSThread* os_thread = OSThread::Current();
ASSERT(os_thread != NULL);
Isolate* isolate = thread->isolate();
if (!CheckIsolate(isolate)) {
OS::PrintErr("Stack dump aborted because CheckIsolate failed.\n");
return;
}
OS::PrintErr("Dumping native stack trace for thread %" Px "\n",
OSThread::ThreadIdToIntPtr(os_thread->trace_id()));
uword stack_lower = 0;
uword stack_upper = 0;
if (!InitialRegisterCheck(pc, fp, sp)) {
OS::PrintErr("Stack dump aborted because InitialRegisterCheck failed.\n");
return;
}
if (!GetAndValidateThreadStackBounds(thread, fp, sp, &stack_lower,
Thread* thread = Thread::Current(); // NULL if no current isolate.
uword stack_lower = 0;
uword stack_upper = 0;
if (!GetAndValidateThreadStackBounds(os_thread, thread, fp, sp, &stack_lower,
&stack_upper)) {
OS::PrintErr(
"Stack dump aborted because GetAndValidateThreadStackBounds failed.\n");
@ -1130,8 +1115,7 @@ void Profiler::DumpStackTrace(uword sp, uword fp, uword pc, bool for_crash) {
}
ProfilerNativeStackWalker native_stack_walker(
(isolate != NULL) ? isolate->main_port() : ILLEGAL_PORT, NULL, NULL,
stack_lower, stack_upper, pc, fp, sp);
ILLEGAL_PORT, NULL, NULL, stack_lower, stack_upper, pc, fp, sp);
native_stack_walker.walk();
OS::PrintErr("-- End of DumpStackTrace\n");
}
@ -1166,7 +1150,7 @@ void Profiler::SampleAllocation(Thread* thread, intptr_t cid) {
return;
}
if (!GetAndValidateThreadStackBounds(thread, fp, sp, &stack_lower,
if (!GetAndValidateThreadStackBounds(os_thread, thread, fp, sp, &stack_lower,
&stack_upper)) {
// Could not get stack boundary.
return;
@ -1352,7 +1336,7 @@ void Profiler::SampleThread(Thread* thread,
uword stack_lower = 0;
uword stack_upper = 0;
if (!GetAndValidateThreadStackBounds(thread, fp, sp, &stack_lower,
if (!GetAndValidateThreadStackBounds(os_thread, thread, fp, sp, &stack_lower,
&stack_upper)) {
AtomicOperations::IncrementInt64By(
&counters_.single_frame_sample_get_and_validate_stack_bounds, 1);