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;
}
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;
}
Exemplo n.º 3
0
	string getParentMethod()
	{
		Backtrace b;
		b.setFramesToCapture(3);
		b.capture();
		return b[0].sym;
	}
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;
}
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
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);
  }
}
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);
    }
  }
}
//-------------------------------------------------------------------------
// 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;
}
Exemplo n.º 10
0
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);
    }
}
Exemplo n.º 11
0
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");
        }
    }
}
Exemplo n.º 12
0
 void visit(Backtrace & backtrace) {
     for (size_t i = 0; i < backtrace.size(); i ++) {
         visit(backtrace[i]);
         os << "\n";
     }
 }
Exemplo n.º 13
0
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;
      }
    }
#endif

    throw std::runtime_error("fatal error; see Log::Fatal output");
  }
}
Exemplo n.º 14
0
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");
  }
}
Exemplo n.º 15
0
	string showBacktrace()
	{
		Backtrace tmp = Backtrace();
		tmp.capture();
		return tmp.dump();
	}