init_mod()
	{
		bool ok = _initialize();
		assert(ok);
		auto stk = get_stack_list(1, 0, true, true);
		string moduleName;
		if (!stk.empty())
		{
			moduleName = &stk.front().module[stk.front().module.find_last_of('\\') + 1];
		}
		_mkdir((moduleName + " stack_log\\").c_str());
		_stackLogFile.open(moduleName + " stack_log\\" + get_time_string_s_file() + ".log");
		if (_stackLogFile.good())
		{
			_stackLogIos = new boost::asio::io_service;
			_stackLogWork = new boost::asio::io_service::work(*_stackLogIos);
			_thread = new boost::thread([&]
			{
				boost::system::error_code ec;
				_stackLogIos->run(ec);
			});
		}
		else
		{
			_stackLogIos = NULL;
			_stackLogWork = NULL;
			_thread = NULL;
		}
	}
Esempio n. 2
0
// SEH 's filter function.
static int seh_filter(LPEXCEPTION_POINTERS exinfo)
{
  auto& ctx = context::get();
  size_t stack_depth = ctx.stack_depth_;
  bool brief = ctx.brief_;
  handler_t h = std::move(ctx.h_);
  auto ecd = exinfo->ExceptionRecord->ExceptionCode;

#ifdef _WIN64
  auto stack_list =
    get_stack_list(
      (void*)exinfo->ContextRecord->Rbp,
      (void*)exinfo->ContextRecord->Rsp,
      (void*)exinfo->ContextRecord->Rip,
      stack_depth, 0, true, true, brief
      );
#else
  auto stack_list =
    get_stack_list(
      (void*)exinfo->ContextRecord->Ebp,
      (void*)exinfo->ContextRecord->Esp,
      (void*)exinfo->ContextRecord->Eip,
      stack_depth, 0, true, true, brief
      );
#endif

  if (h)
  {
    h(stack_list);
  }
  else
  {
    for (auto& ele : stack_list)
    {
      std::cerr << ele << std::endl;
    }
    std::cerr << std::endl << std::flush;
  }

  if (ecd == EXCEPTION_ACCESS_VIOLATION)
  {
    //std::cout << "access violation" << std::endl;
    return EXCEPTION_EXECUTE_HANDLER;
  }
  return EXCEPTION_CONTINUE_SEARCH;
}