Poster of Linux kernelThe best gift for a Linux geek
print_trace.C

print_trace.C

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

print_trace.C -  

SYNOPSIS


 

Functions


std::string abi_demangle (const char *name)

void print_trace (std::ostream &out)

void print_trace (void)
 

Function Documentation

 

std::string abi_demangle (const char *name)

Definition at line 42 of file print_trace.C.

References Quality::name().

Referenced by print_trace().

{
  int status = 0;
  char *d = 0;
  std::string fullname = name;
  size_t namestart = fullname.find('(');
  if (namestart == std::string::npos)
    return fullname;
  else
    namestart++;
  size_t nameend = fullname.find('+');
  if (nameend == std::string::npos ||
      nameend <= namestart)
    return fullname;
  std::string funcname = fullname.substr(namestart, nameend - namestart);
  std::string goodname = funcname;
  try { if ( (d = abi::__cxa_demangle(funcname.c_str(), 0, 0, &status)) ) goodname = d; }
  catch(...) {  }
  std::free(d);
/*
  std::string ret = fullname.substr(0, namestart);
  ret.append(goodname);
  ret.append(fullname.substr(nameend, fullname.length() - nameend));
  return ret;
*/
  return goodname;
}
 

void print_trace (void)

Definition at line 113 of file print_trace.C.

References abi_demangle().

{
std::cerr << 'Trying print_trace()' << std::endl;
    Dl_info info;
    void **frame = static_cast<void **>(__builtin_frame_address(0));
    void **bp = static_cast<void **>(*frame);
    void *ip = frame[1];

    while(bp && ip && dladdr(ip, &info))
    {
        std::cout << ip << ': ' << abi_demangle(info.dli_sname) << ' in ' <<
info.dli_fname << ';

        if(info.dli_sname && !strcmp(info.dli_sname, 'main')) break;

        ip = bp[1];
        bp = static_cast<void**>(bp[0]);
    }
    char *dlerr = dlerror();
    if (dlerr)
      std::cout << 'dlerror() = ' << dlerr << std::endl;
}
 

void print_trace (std::ostream &out)

Definition at line 70 of file print_trace.C.

References abi_demangle().

{
  void *addresses[10];
  char **strings;

  int size = backtrace(addresses, 10);
  strings = backtrace_symbols(addresses, size);
  out << 'Stack frames: ' << size << std::endl;
  for(int i = 0; i < size; i++)
    {
//      out << i << ': ' << (int)addresses[i] << std::endl;
//      out << abi_demangle(strings[i]) << std::endl;
      out << i << ': ' << abi_demangle(strings[i]) << std::endl;
    }
  std::free(strings);
}
 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Functions
Function Documentation
std::string abi_demangle (const char *name)
void print_trace (void)
void print_trace (std::ostream &out)
Author

This document was created by man2html, using the manual pages.
Time: 21:53:02 GMT, April 16, 2011