本文整理汇总了C++中Thread::GetStackTrace方法的典型用法代码示例。如果您正苦于以下问题:C++ Thread::GetStackTrace方法的具体用法?C++ Thread::GetStackTrace怎么用?C++ Thread::GetStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::GetStackTrace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: teamLocker
void
CliStackTraceCommand::Execute(int argc, const char* const* argv,
CliContext& context)
{
// get the current thread
Team* team = context.GetTeam();
AutoLocker<Team> teamLocker(team);
Thread* thread = context.CurrentThread();
if (thread == NULL) {
printf("no current thread\n");
return;
}
if (thread->State() != THREAD_STATE_STOPPED) {
printf("Current thread is not stopped. Can't get stack trace.\n");
return;
}
// get its stack trace
StackTrace* stackTrace = thread->GetStackTrace();
while (stackTrace == NULL) {
context.WaitForEvents(CliContext::EVENT_THREAD_STACK_TRACE_CHANGED);
if (context.IsTerminating())
return;
stackTrace = thread->GetStackTrace();
}
BReference<StackTrace> stackTraceReference(stackTrace);
// hold a reference until we're done
teamLocker.Unlock();
// print the stack trace
int32 frameCount = stackTrace->CountFrames();
for (int32 i = 0; i < frameCount; i++) {
StackFrame* frame = stackTrace->FrameAt(i);
printf("%3" B_PRId32 " %#" B_PRIx64 " %#" B_PRIx64, i,
(uint64)frame->FrameAddress(), (uint64)frame->InstructionPointer());
char functionName[512];
UiUtils::FunctionNameForFrame(frame, functionName,
sizeof(functionName));
printf(" %s\n", functionName);
}
}
示例2: teamLocker
void
CliContext::ProcessPendingEvents()
{
AutoLocker<Team> teamLocker(fTeam);
for (;;) {
// get the next event
AutoLocker<BLocker> locker(fLock);
Event* event = fPendingEvents.RemoveHead();
locker.Unlock();
if (event == NULL)
break;
ObjectDeleter<Event> eventDeleter(event);
// process the event
Thread* thread = event->GetThread();
switch (event->Type()) {
case EVENT_QUIT:
case EVENT_DEBUG_REPORT_CHANGED:
case EVENT_USER_INTERRUPT:
break;
case EVENT_THREAD_ADDED:
printf("[new thread: %" B_PRId32 " \"%s\"]\n", thread->ID(),
thread->Name());
break;
case EVENT_THREAD_REMOVED:
printf("[thread terminated: %" B_PRId32 " \"%s\"]\n",
thread->ID(), thread->Name());
break;
case EVENT_THREAD_STOPPED:
printf("[thread stopped: %" B_PRId32 " \"%s\"]\n",
thread->ID(), thread->Name());
break;
case EVENT_THREAD_STACK_TRACE_CHANGED:
if (thread == fCurrentThread) {
fCurrentStackTrace = thread->GetStackTrace();
fCurrentStackTrace->AcquireReference();
SetCurrentStackFrameIndex(0);
}
break;
case EVENT_TEAM_MEMORY_BLOCK_RETRIEVED:
if (fCurrentBlock != NULL) {
fCurrentBlock->ReleaseReference();
fCurrentBlock = NULL;
}
fCurrentBlock = event->GetMemoryBlock();
break;
case EVENT_EXPRESSION_EVALUATED:
fExpressionResult = event->GetExpressionResult();
if (fExpressionValue != NULL) {
fExpressionValue->ReleaseReference();
fExpressionValue = NULL;
}
fExpressionValue = event->GetExpressionValue();
if (fExpressionValue != NULL)
fExpressionValue->AcquireReference();
break;
}
}
}