Skip to content

Commit

Permalink
cmake: add option ORC_BUILD_BOOST_STACKTRACE
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienfl-orc committed Nov 9, 2020
1 parent 2f53123 commit 3ba448b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Expand Up @@ -11,6 +11,7 @@ option(ORC_BUILD_ORC "Build Orc binary" ON)
option(ORC_BUILD_PARQUET "Build Parquet module" OFF)
option(ORC_BUILD_SSDEEP "Build with ssdeep support" OFF)
option(ORC_BUILD_JSON "Build with JSON StructuredOutput enabled" ON)
option(ORC_BUILD_BOOST_STACKTRACE "Build with stack backtrace enabled" ON)
option(ORC_DOWNLOADS_ONLY "Do not build ORC but only download vcpkg third parties" OFF)
option(ORC_DISABLE_PRECOMPILED_HEADERS "Disable precompiled headers" OFF)

Expand Down Expand Up @@ -79,7 +80,6 @@ if(ORC_VCPKG_ROOT)
boost-multi-index
boost-outcome
boost-scope-exit
boost-stacktrace
fmt
spdlog
tlsh
Expand All @@ -92,6 +92,11 @@ if(ORC_VCPKG_ROOT)
cli11
)

if(ORC_BUILD_BOOST_STACKTRACE)
add_compile_definitions(ORC_BUILD_BOOST_STACKTRACE)
list(APPEND _PACKAGES boost-stacktrace)
endif()

if(ORC_BUILD_APACHE_ORC)
list(APPEND _PACKAGES orc)
endif()
Expand Down
14 changes: 12 additions & 2 deletions src/OrcCommand/UtilitiesMain.h
Expand Up @@ -13,12 +13,16 @@
#include <iostream>
#include <chrono>

#include <concrt.h>

#include <boost/logic/tribool.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/stacktrace.hpp>
#include <concrt.h>

#ifdef ORC_BUILD_BOOST_STACKTRACE
# include <boost/stacktrace.hpp>
#endif

#include "ConfigFile.h"
#include "Archive.h"
Expand Down Expand Up @@ -883,13 +887,19 @@ class ORCLIB_API UtilitiesMain
std::cerr << "std::exception during execution" << std::endl;
std::cerr << "Caught " << e.what() << std::endl;
std::cerr << "Type " << typeid(e).name() << std::endl;

#ifdef ORC_BUILD_BOOST_STACKTRACE
boost::stacktrace::stacktrace();
#endif
return E_ABORT;
}
catch (...)
{
std::cerr << "Exception during during execution" << std::endl;

#ifdef ORC_BUILD_BOOST_STACKTRACE
boost::stacktrace::stacktrace();
#endif
return E_ABORT;
}

Expand Down
8 changes: 7 additions & 1 deletion src/OrcLib/Log/Logger.cpp
Expand Up @@ -18,7 +18,10 @@
#include <fstream>

#include <spdlog/logger.h>
#include <boost/stacktrace.hpp>

#ifdef ORC_BUILD_BOOSTSTACK_TRACE
# include <boost/stacktrace.hpp>
#endif

using namespace Orc;

Expand Down Expand Up @@ -72,8 +75,11 @@ Logger::Logger(std::initializer_list<std::pair<Facility, std::shared_ptr<spdlog:
// This is error handler will help to fix log formatting error
spdlog::set_error_handler([](const std::string& msg) {
std::cerr << msg << std::endl;

#ifdef ORC_BUILD_BOOSTSTACK_TRACE
std::cerr << "Stack trace:" << std::endl;
std::cerr << boost::stacktrace::stacktrace();
#endif
});

// https://github.com/gabime/spdlog/wiki/3.-Custom-formatting
Expand Down

0 comments on commit 3ba448b

Please sign in to comment.