本文整理汇总了C++中Backtrace类的典型用法代码示例。如果您正苦于以下问题:C++ Backtrace类的具体用法?C++ Backtrace怎么用?C++ Backtrace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Backtrace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: backtrace_read_word
bool backtrace_read_word(const backtrace_context_t* context, uintptr_t ptr, uint32_t* value) {
if (context->data) {
Backtrace* backtrace = reinterpret_cast<Backtrace*>(context->data);
return backtrace->ReadWord(ptr, value);
}
return true;
}
示例2: backtrace_get_map_name
const char* backtrace_get_map_name(const backtrace_context_t* context, uintptr_t pc, uintptr_t* map_start) {
if (context->data) {
Backtrace* backtrace = reinterpret_cast<Backtrace*>(context->data);
return backtrace->GetMapName(pc, map_start);
}
return NULL;
}
示例3: getParentMethod
string getParentMethod()
{
Backtrace b;
b.setFramesToCapture(3);
b.capture();
return b[0].sym;
}
示例4: backtrace_get_data
const backtrace_t* backtrace_get_data(backtrace_context_t* context) {
if (context && context->data) {
Backtrace* backtrace = reinterpret_cast<Backtrace*>(context->data);
return backtrace->GetBacktrace();
}
return NULL;
}
示例5: backtrace_get_func_name
char* backtrace_get_func_name(const backtrace_context_t* context, uintptr_t pc, uintptr_t* func_offset) {
if (context->data) {
Backtrace* backtrace = reinterpret_cast<Backtrace*>(context->data);
std::string func_name = backtrace->GetFunctionName(pc, func_offset);
if (!func_name.empty()) {
return strdup(func_name.c_str());
}
}
return NULL;
}
示例6: saveBacktrace
static inline Backtrace saveBacktrace()
{
static const int maxFrames = 32;
Backtrace stacktrace;
stacktrace.resize(sizeof(void*) * maxFrames);
int stack_size = backtrace((void**)stacktrace.data(), maxFrames);
stacktrace.resize(sizeof(void*) * stack_size);
return stacktrace;
}
示例7: Assert
void Log::Assert(bool condition, const std::string& message)
{
if (!condition)
{
#ifdef HAS_BFD_DL
Backtrace bt;
Log::Debug << bt.ToString();
#endif
Log::Debug << message << std::endl;
throw std::runtime_error("Log::Assert() failed: " + message);
}
}
示例8: backtrace_format_frame_data
void backtrace_format_frame_data(
const backtrace_context_t* context, size_t frame_num, char* buf,
size_t buf_size) {
if (buf_size == 0 || buf == NULL) {
BACK_LOGW("bad call buf %p buf_size %zu", buf, buf_size);
} else if (context->data) {
Backtrace* backtrace = reinterpret_cast<Backtrace*>(context->data);
std::string line = backtrace->FormatFrameData(frame_num);
if (line.size() > buf_size) {
memcpy(buf, line.c_str(), buf_size-1);
buf[buf_size] = '\0';
} else {
memcpy(buf, line.c_str(), line.size()+1);
}
}
}
示例9: backtrace_create_context_with_map
//-------------------------------------------------------------------------
// Common interface functions.
//-------------------------------------------------------------------------
bool backtrace_create_context_with_map(
backtrace_context_t* context, pid_t pid, pid_t tid, size_t num_ignore_frames,
backtrace_map_info_t* map_info) {
Backtrace* backtrace = Backtrace::Create(pid, tid, map_info);
if (!backtrace) {
return false;
}
if (!backtrace->Unwind(num_ignore_frames)) {
delete backtrace;
return false;
}
context->data = backtrace;
context->backtrace = backtrace->GetBacktrace();
return true;
}
示例10: printBacktrace
static void printBacktrace(Backtrace stacktrace)
{
void *const *stack = (void *const *)stacktrace.constData();
int stack_size = stacktrace.size() / sizeof(void*);
char **stack_symbols = backtrace_symbols(stack, stack_size);
int filter[2];
pid_t child = -1;
if (pipe(filter) != -1)
child = fork();
if (child == 0) {
// child process
dup2(fileno(stderr), fileno(stdout));
dup2(filter[0], fileno(stdin));
close(filter[0]);
close(filter[1]);
execlp("c++filt", "c++filt", "-n", NULL);
// execlp failed
execl("/bin/cat", "/bin/cat", NULL);
_exit(127);
}
// parent process
close(filter[0]);
FILE *output;
if (child == -1) {
// failed forking
close(filter[1]);
output = stderr;
} else {
output = fdopen(filter[1], "w");
}
fprintf(stderr, "Backtrace of the first creation (most recent frame first):\n");
for (int i = 0; i < stack_size; ++i) {
if (strlen(stack_symbols[i]))
fprintf(output, "#%-2d %s\n", i, stack_symbols[i]);
else
fprintf(output, "#%-2d %p\n", i, stack[i]);
}
if (child != -1) {
fclose(output);
waitpid(child, 0, 0);
}
}
示例11: track_sp
extern "C" void track_sp (void *sp_this, void *ptr, long use_count)
{
typedef std::pair<void *, Backtrace> PtrBacktracePair;
typedef std::map<void *, PtrBacktracePair> PtrToBacktraceMap;
static lldb_private::Mutex g_mutex(lldb_private::Mutex::eMutexTypeNormal);
lldb_private::Mutex::Locker locker (g_mutex);
static PtrToBacktraceMap g_map;
if (sp_this)
{
printf ("sp(%p) -> %p %lu\n", sp_this, ptr, use_count);
if (ptr)
{
Backtrace bt;
bt.GetFrames();
g_map[sp_this] = std::make_pair(ptr, bt);
}
else
{
g_map.erase (sp_this);
}
}
else
{
if (ptr)
printf ("Searching for shared pointers that are tracking %p: ", ptr);
else
printf ("Dump all live shared pointres: ");
uint32_t matches = 0;
PtrToBacktraceMap::iterator pos, end = g_map.end();
for (pos = g_map.begin(); pos != end; ++pos)
{
if (ptr == NULL || pos->second.first == ptr)
{
++matches;
printf ("\nsp(%p): %p\n", pos->first, pos->second.first);
pos->second.second.Dump();
}
}
if (matches == 0)
{
printf ("none.\n");
}
}
}
示例12: visit
void visit(Backtrace & backtrace) {
for (size_t i = 0; i < backtrace.size(); i ++) {
visit(backtrace[i]);
os << "\n";
}
}
示例13: PrefixIfNeeded
typename std::enable_if<!arma::is_arma_type<T>::value>::type
PrefixedOutStream::BaseLogic(const T& val)
{
// We will use this to track whether or not we need to terminate at the end of
// this call (only for streams which terminate after a newline).
bool newlined = false;
std::string line;
// If we need to, output the prefix.
PrefixIfNeeded();
std::ostringstream convert;
// Sync flags and precision with destination stream
convert.setf(destination.flags());
convert.precision(destination.precision());
convert << val;
if (convert.fail())
{
PrefixIfNeeded();
if (!ignoreInput)
{
destination << "Failed type conversion to string for output; output not "
"shown." << std::endl;
newlined = true;
}
}
else
{
line = convert.str();
// If the length of the casted thing was 0, it may have been a stream
// manipulator, so send it directly to the stream and don't ask questions.
if (line.length() == 0)
{
// The prefix cannot be necessary at this point.
if (!ignoreInput) // Only if the user wants it.
destination << val;
return;
}
// Now, we need to check for newlines in the output and print it.
size_t nl;
size_t pos = 0;
while ((nl = line.find('\n', pos)) != std::string::npos)
{
PrefixIfNeeded();
// Only output if the user wants it.
if (!ignoreInput)
{
destination << line.substr(pos, nl - pos);
destination << std::endl;
}
newlined = true; // Ensure this is set for the fatal exception if needed.
carriageReturned = true; // Regardless of whether or not we display it.
pos = nl + 1;
}
if (pos != line.length()) // We need to display the rest.
{
PrefixIfNeeded();
if (!ignoreInput)
destination << line.substr(pos);
}
}
// If we displayed a newline and we need to throw afterwards, do that.
if (fatal && newlined)
{
if (!ignoreInput)
destination << std::endl;
// Print a backtrace, if we can.
#ifdef HAS_BFD_DL
if (fatal && !ignoreInput && backtrace)
{
size_t nl;
size_t pos = 0;
Backtrace bt;
std::string btLine = bt.ToString();
while ((nl = btLine.find('\n', pos)) != std::string::npos)
{
PrefixIfNeeded();
if (!ignoreInput)
{
destination << btLine.substr(pos, nl - pos);
destination << std::endl;
}
carriageReturned = true; // Regardless of whether or not we display it.
pos = nl + 1;
}
}
//.........这里部分代码省略.........
示例14: PrefixIfNeeded
void PrefixedOutStream::BaseLogic(const T& val)
{
// We will use this to track whether or not we need to terminate at the end of
// this call (only for streams which terminate after a newline).
bool newlined = false;
std::string line;
// If we need to, output the prefix.
PrefixIfNeeded();
std::ostringstream convert;
convert << val;
if (convert.fail())
{
PrefixIfNeeded();
if (!ignoreInput)
{
destination << "Failed lexical_cast<std::string>(T) for output; output"
" not shown." << std::endl;
newlined = true;
}
}
else
{
line = convert.str();
// If the length of the casted thing was 0, it may have been a stream
// manipulator, so send it directly to the stream and don't ask questions.
if (line.length() == 0)
{
// The prefix cannot be necessary at this point.
if (!ignoreInput) // Only if the user wants it.
destination << val;
return;
}
// Now, we need to check for newlines in retrieved backtrace.
//If we find one, output up until the newline, then output the newline
//and the prefix and continue looking.
size_t nl;
size_t pos = 0;
#ifdef HAS_BFD_DL
if(fatal)
{
Backtrace bt;
std::string btLine = bt.ToString();
while ((nl = btLine.find('\n', pos)) != std::string::npos)
{
PrefixIfNeeded();
destination << btLine.substr(pos, nl - pos);
destination << std::endl;
newlined = true;
carriageReturned = true; // Regardless of whether or not we display it.
pos = nl + 1;
}
pos = 0;
}
#endif
//The same logic like above, but this time for 'line'.
while ((nl = line.find('\n', pos)) != std::string::npos)
{
PrefixIfNeeded();
// Only output if the user wants it.
if (!ignoreInput)
{
destination << line.substr(pos, nl - pos);
destination << std::endl;
newlined = true;
}
carriageReturned = true; // Regardless of whether or not we display it.
pos = nl + 1;
}
if (pos != line.length()) // We need to display the rest.
{
PrefixIfNeeded();
if (!ignoreInput)
destination << line.substr(pos);
}
}
// If we displayed a newline and we need to throw afterwards, do that.
if (fatal && newlined)
{
std::cout << std::endl;
throw std::runtime_error("fatal error; see Log::Fatal output");
}
}
示例15: showBacktrace
string showBacktrace()
{
Backtrace tmp = Backtrace();
tmp.capture();
return tmp.dump();
}