本文整理汇总了C++中StackTrace类的典型用法代码示例。如果您正苦于以下问题:C++ StackTrace类的具体用法?C++ StackTrace怎么用?C++ StackTrace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StackTrace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stackTraceToBackTrace
Array stackTraceToBackTrace(const StackTrace& st) {
std::vector<void*> bt_pointers;
st.get(bt_pointers);
Array ret;
if (RuntimeOption::FullBacktrace) {
for (unsigned int i = 0; i < bt_pointers.size(); i++) {
StackTrace::FramePtr f = StackTrace::Translate(bt_pointers[i]);
if (RuntimeOption::TranslateSource) {
SourceInfo::TheSourceInfo.translate(f);
}
Array frame;
frame.set("file", String(f->filename));
frame.set("line", f->lineno);
frame.set("function", String(f->funcname));
frame.set("args", "");
frame.set("bt", (int64)bt_pointers[i]);
ret.append(frame);
}
} else {
for (unsigned int i = 0; i < bt_pointers.size(); i++) {
Array frame;
frame.set("file", "");
frame.set("line", 0LL);
frame.set("function", "");
frame.set("args", "");
frame.set("bt", (int64)bt_pointers[i]);
ret.append(frame);
}
ret.set("bts", String(st.hexEncode()));
}
return ret;
}
示例2: simplifyDomain
Logger::LogStream Logger::createStream(const string &_domain, int level,
const std::string &_prefix) {
string domain = simplifyDomain(_domain);
if (enabled(domain, level)) {
// Log date periodically
uint64_t now = Time::now();
if (logDatePeriodically && lastDate + logDatePeriodically <= now) {
write(String::bar(Time(now, "Date: %Y-%m-%d").toString()) +
(logCRLF ? "\r\n" : "\n"));
lastDate = now;
}
string prefix = startColor(level) + getHeader(domain, level) + _prefix;
string suffix = endColor(level);
string trailer;
#ifdef HAVE_DEBUGGER
if (domainTraces.find(domain) != domainTraces.end()) {
StackTrace trace;
Debugger::instance().getStackTrace(trace);
for (int i = 0; i < 3; i++) trace.pop_front();
trailer = SSTR(trace);
}
#endif
return new cb::LogStream(prefix, suffix, trailer);
} else return new NullStream<>;
}
示例3: LogStacktrace
static void LogStacktrace(const int logLevel, StackTrace& stacktrace)
{
int colFileline = 0;
const std::string& exe_path = Platform::GetProcessExecutablePath();
const std::string& cwd_path = Platform::GetOrigCWD();
for (auto fit = stacktrace.begin(); fit != stacktrace.end(); fit++) {
for (auto eit = fit->entries.begin(); eit != fit->entries.end(); eit++) {
eit->abbrev_funcname = eit->funcname;
std::string fileline = eit->fileline;
if (fileline[1] == '?') { // case "??:?", ":?"
fileline = fit->symbol; // print raw backtrace_symbol
}
eit->abbrev_fileline = fileline;
int abbrev_start = 0;
if (fileline[0] == '/') { // See if we can shorten the file/line bit by removing the common path
if (CommonStringLength(fileline, exe_path, &abbrev_start) > 1) { // i.e. one char for first '/'
eit->abbrev_fileline = std::string(".../") + fileline.substr(abbrev_start, std::string::npos);
} else if (CommonStringLength(fileline, cwd_path, &abbrev_start) > 1) {
eit->abbrev_fileline = std::string("./") + fileline.substr(abbrev_start, std::string::npos);
}
}
if (eit->abbrev_funcname.size() > 100) {
eit->abbrev_funcname.resize(94);
eit->abbrev_funcname.append(" [...]");
}
colFileline = std::max(colFileline, (int)eit->abbrev_fileline.length());
}
}
bool hideSignalHandler = true;
// Print out the translated StackTrace
unsigned numLine = 0;
unsigned hiddenLines = 0;
while (numLine == 0) { // outer loop at most twice -- tries to find the signal handler once and if that doesn't work, then just print every frame
for (auto fit = stacktrace.cbegin(); fit != stacktrace.cend(); fit++) {
for (auto eit = fit->entries.begin(); eit != fit->entries.end(); eit++) {
if (hideSignalHandler) {
hiddenLines++;
if (eit->fileline.find("sigaction.c:?") == 0) {
hideSignalHandler = false;
LOG_I(logLevel, "(Signal handler calls suppressed [%d]. Inlined calls denoted by < > brackets.)", hiddenLines);
}
continue;
}
if (eit->inLine) {
LOG_I(logLevel, " <%02u> %*s %s", fit->level, colFileline, eit->abbrev_fileline.c_str(), eit->abbrev_funcname.c_str());
} else {
LOG_I(logLevel, "[%02u] %*s %s", fit->level, colFileline, eit->abbrev_fileline.c_str(), eit->abbrev_funcname.c_str());
}
numLine++;
}
}
hideSignalHandler = false;
}
}
示例4: debug_string_backtrace
String debug_string_backtrace(bool skip) {
if (RuntimeOption::InjectedStackTrace) {
Array bt;
StringBuffer buf;
bt = g_vmContext->debugBacktrace(skip);
int i = 0;
for (ArrayIter it = bt.begin(); !it.end(); it.next(), i++) {
Array frame = it.second().toArray();
buf.append('#');
buf.append(i);
if (i < 10) buf.append(' ');
buf.append(' ');
if (frame.exists(s_class)) {
buf.append(frame->get(s_class).toString());
buf.append(frame->get(s_type).toString());
}
buf.append(frame->get(s_function).toString());
buf.append("()");
if (frame.exists(s_file)) {
buf.append(" called at [");
buf.append(frame->get(s_file).toString());
buf.append(':');
buf.append(frame->get(s_line).toString());
buf.append(']');
}
buf.append('\n');
}
return buf.detach();
} else {
StackTrace st;
return String(st.toString());
}
}
示例5: f_debug_print_backtrace
void f_debug_print_backtrace() {
if (RuntimeOption::InjectedStackTrace) {
Array bt = FrameInjection::GetBacktrace(true);
int i = 0;
for (ArrayIter it = bt.begin(); !it.end(); it.next(), i++) {
Array frame = it.second().toArray();
StringBuffer buf;
buf.append('#');
buf.append(i);
if (i < 10) buf.append(' ');
buf.append(' ');
if (frame.exists("class")) {
buf.append(frame->get("class").toString());
buf.append(frame->get("type").toString());
}
buf.append(frame->get("function").toString());
buf.append("()");
if (frame.exists("file")) {
buf.append(" called at [");
buf.append(frame->get("file").toString());
buf.append(':');
buf.append(frame->get("line").toString());
buf.append(']');
}
buf.append('\n');
echo(buf.detach());
}
} else {
StackTrace st;
echo(String(st.toString()));
}
}
示例6: WindowsExceptionHandler
LONG WINAPI WindowsExceptionHandler(struct _EXCEPTION_POINTERS *exceptionInfo)
{
LD_UNUSED_PARAMETER(exceptionInfo);
LD_LOG(Platform, Error, "~~~~~~~~~~~~ UNHANDLED EXCEPTION OCCURRED ~~~~~~~~~~~");
LD_LOG(Platform, Error, "Stack Trace:");
StackTrace Trace;
if (StackTrace::Generate(Trace, (void*)exceptionInfo).Failed())
{
LD_LOG(Platform, Error, "Failed to generate stack trace.");
return 0;
}
else
{
for (int i = 0; i < Trace.FrameCount(); i++)
{
StackFrame Frame = Trace.GetFrame(i);
if (Frame.Resolve().Failed())
{
LD_LOGF(Platform, Error, "[%i] 0x%p (Symbols Unresolved)", i, Frame.Address);
}
else
{
LD_LOGF(Platform, Error, "[%i] (%s:%i) %s", i, Frame.File.Data(), Frame.Line, Frame.Function.Data());
}
}
}
return EXCEPTION_EXECUTE_HANDLER;
}
示例7: TRACE_CONTROL
bool
ThreadHandler::_HandleSingleStepStep(CpuState* cpuState)
{
TRACE_CONTROL("ThreadHandler::_HandleSingleStepStep(): ip: %llx\n",
cpuState->InstructionPointer());
switch (fStepMode) {
case STEP_INTO:
{
// We continue stepping as long as we're in the statement.
if (fStepStatement->ContainsAddress(cpuState->InstructionPointer())) {
_SingleStepThread(cpuState->InstructionPointer());
return true;
}
StackTrace* stackTrace = fThread->GetStackTrace();
BReference<StackTrace> stackTraceReference(stackTrace);
if (stackTrace == NULL && cpuState != NULL) {
if (fDebuggerInterface->GetArchitecture()->CreateStackTrace(
fThread->GetTeam(), this, cpuState, stackTrace) == B_OK) {
stackTraceReference.SetTo(stackTrace, true);
}
}
if (stackTrace != NULL) {
StackFrame* frame = stackTrace->FrameAt(0);
Image* image = frame->GetImage();
ImageDebugInfo* info = NULL;
if (GetImageDebugInfo(image, info) != B_OK)
return false;
BReference<ImageDebugInfo>(info, true);
if (info->GetAddressSectionType(
cpuState->InstructionPointer())
== ADDRESS_SECTION_TYPE_PLT) {
_SingleStepThread(cpuState->InstructionPointer());
return true;
}
}
return false;
}
case STEP_OVER:
{
// If we have stepped out of the statement, we're done.
if (!fStepStatement->ContainsAddress(cpuState->InstructionPointer()))
return false;
return _DoStepOver(cpuState);
}
case STEP_OUT:
// We never single-step in this case.
default:
return false;
}
}
示例8: wxLogError
//! @brief is called when the app crashes
void SpringLobbyApp::OnFatalException()
{
wxLogError("Fatal exception!");
StackTrace stackTracer;
stackTracer.WalkFromException();
auto trace = stackTracer.GetStackTrace();
wxLogError("Stack trace: " + trace);
}
示例9: print_backtrace
void print_backtrace(std::size_t frames = 32)
{
using namespace backward;
StackTrace stackTrace;
Printer printer;
stackTrace.load_here(frames);
printer.object = true;
printer.color = true;
printer.print(stackTrace, stdout);
}
示例10:
LockProfiler::~LockProfiler() {
if (m_profiling) {
timespec unlockTime;
Timer::GetMonotonicTime(unlockTime);
time_t dsec = unlockTime.tv_sec - m_lockTime.tv_sec;
long dnsec = unlockTime.tv_nsec - m_lockTime.tv_nsec;
int64_t dusec = dsec * 1000000 + dnsec / 1000;
StackTrace st;
s_pfunc_profile(st.hexEncode(3, 9), dusec);
}
}
示例11: sizeof
status_t
DebugReportGenerator::_DumpDebuggedThreadInfo(BString& _output,
::Thread* thread)
{
AutoLocker< ::Team> locker;
if (thread->State() != THREAD_STATE_STOPPED)
return B_OK;
StackTrace* trace = NULL;
for (;;) {
trace = thread->GetStackTrace();
if (trace != NULL)
break;
locker.Unlock();
status_t result = acquire_sem(fTeamDataSem);
if (result != B_OK)
return result;
locker.Lock();
}
_output << "\t\tFrame\t\tIP\t\t\tFunction Name\n";
_output << "\t\t-----------------------------------------------\n";
BString data;
for (int32 i = 0; StackFrame* frame = trace->FrameAt(i); i++) {
char functionName[512];
data.SetToFormat("\t\t%#08" B_PRIx64 "\t%#08" B_PRIx64 "\t%s\n",
frame->FrameAddress(), frame->InstructionPointer(),
UiUtils::FunctionNameForFrame(frame, functionName,
sizeof(functionName)));
_output << data;
}
_output << "\n\t\tRegisters:\n";
CpuState* state = thread->GetCpuState();
BVariant value;
const Register* reg = NULL;
for (int32 i = 0; i < fArchitecture->CountRegisters(); i++) {
reg = fArchitecture->Registers() + i;
state->GetRegisterValue(reg, value);
char buffer[64];
data.SetToFormat("\t\t\t%5s:\t%s\n", reg->Name(),
UiUtils::VariantToString(value, buffer, sizeof(buffer)));
_output << data;
}
return B_OK;
}
示例12: SuspendedStacktrace
/**
*
* This entry point is tailored for the Watchdog module.
* Since the thread to be traced may be running, it requires a ThreadControls object in order to suspend/resume the thread.
* @brief RemoteStacktrace
*/
void SuspendedStacktrace(Threading::ThreadControls* ctls, const std::string& threadName)
{
#if !(DEDICATED || UNIT_TEST)
Watchdog::ClearTimer();
#endif
assert(ctls != nullptr);
assert(ctls->handle != 0);
assert(threadName.size() > 0);
LOG_L(L_WARNING, "Suspended-thread Stacktrace (%s) for Spring %s:", threadName.c_str(), (SpringVersion::GetFull()).c_str());
LOG_L(L_DEBUG, "SuspendedStacktrace[1]");
StackTrace stacktrace;
// Get untranslated stacktrace symbols
{
// process and analyse the raw stack trace
void* iparray[MAX_STACKTRACE_DEPTH];
ctls->Suspend();
const int numLines = thread_unwind(&ctls->ucontext, iparray, stacktrace);
ctls->Resume();
LOG_L(L_DEBUG, "SuspendedStacktrace[2]");
if(numLines > MAX_STACKTRACE_DEPTH) {
LOG_L(L_ERROR, "thread_unwind returned more lines than we allotted space for!");
}
char** lines = backtrace_symbols(iparray, numLines); // give them meaningfull names
ExtractSymbols(lines, stacktrace);
}
if (stacktrace.empty()) {
LOG_L(L_WARNING, " Unable to create suspended stacktrace");
return;
}
LOG_L(L_DEBUG, "SuspendedStacktrace[3]");
// Translate symbols into code line numbers
TranslateStackTrace(NULL, stacktrace, LOG_LEVEL_WARNING);
LOG_L(L_DEBUG, "SuspendedStacktrace[4]");
// Print out the translated StackTrace
LogStacktrace(LOG_LEVEL_WARNING, stacktrace);
}
示例13: debug_string_backtrace
String debug_string_backtrace(bool skip, bool ignore_args /* = false */,
int limit /* = 0 */) {
if (RuntimeOption::InjectedStackTrace) {
Array bt;
StringBuffer buf;
bt = g_context->debugBacktrace(skip, false, false, nullptr,
ignore_args, limit);
int i = 0;
for (ArrayIter it = bt.begin(); !it.end(); it.next(), i++) {
Array frame = it.second().toArray();
buf.append('#');
buf.append(i);
if (i < 10) buf.append(' ');
buf.append(' ');
if (frame.exists(s_class)) {
buf.append(frame->get(s_class).toString());
buf.append(frame->get(s_type).toString());
}
buf.append(frame->get(s_function).toString());
buf.append("(");
if (!ignore_args) {
bool first = true;
for (ArrayIter it = frame->get(s_args).begin(); !it.end(); it.next()) {
if (!first) {
buf.append(", ");
} else {
first = false;
}
try {
buf.append(it.second().toString());
} catch (FatalErrorException& fe) {
buf.append(fe.getMessage());
}
}
}
buf.append(")");
if (frame.exists(s_file)) {
buf.append(" called at [");
buf.append(frame->get(s_file).toString());
buf.append(':');
buf.append(frame->get(s_line).toString());
buf.append(']');
}
buf.append('\n');
}
return buf.detach();
} else {
StackTrace st;
return String(st.toString());
}
}
示例14: malloc
void HeapProfiler::malloc(void *ptr, size_t size, const StackTrace &trace){
std::lock_guard<std::mutex> lk(mutex);
fprintf(data.output, "+ %lx %lx %lx\n", size, trace.index(), reinterpret_cast<uintptr_t>(ptr));
data.tick();
// Store the stracktrace hash of this allocation in the pointers map.
ptrs[ptr] = trace.hash;
}
示例15: ExtractSymbols
/**
* Consumes (and frees) the lines produced by backtrace_symbols and puts these into the StackTrace fields
*/
static void ExtractSymbols(char** lines, StackTrace& stacktrace)
{
int l=0;
auto fit = stacktrace.begin();
while (fit != stacktrace.end()) {
LOG_L(L_DEBUG, "backtrace_symbols: %s", lines[l]);
if (strncmp(lines[l], "[(nil)]", 20) != 0) {
fit->symbol = lines[l];
fit++;
} else {
fit = stacktrace.erase(fit);
}
l++;
}
free(lines);
}