Improve compilation times on Windows (#172)
Thank you for the very useful library! Few improvements: - Better header hygiene - Isolate `windows.h` to `.cpp` whenever possible - Use `WIN32_LEAN_AND_MEAN` - Remove unused headers Tested on Windows with ``` cmake .. -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-ftime-trace -Wall -Wextra -Wpedantic -Wno-ignored-attributes" -DCMAKE_COLOR_DIAGNOSTICS=1 -DCPPTRACE_BUILD_TESTING=1 -DCPPTRACE_BUILD_BENCHMARKING=0 ``` There's a lot more that can be improved if you are interested. --------- Co-authored-by: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com>
This commit is contained in:
parent
4ed90c1585
commit
0ddbbf43cb
19
CHANGELOG.md
19
CHANGELOG.md
@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
- [Changelog](#changelog)
|
||||
- [v0.7.1](#v071)
|
||||
- [v0.7.0](#v070)
|
||||
- [v0.6.3](#v063)
|
||||
- [v0.6.2](#v062)
|
||||
@ -20,6 +21,24 @@
|
||||
- [v0.1.1](#v011)
|
||||
- [v0.1](#v01)
|
||||
|
||||
# v0.7.1
|
||||
|
||||
Added
|
||||
- Better support for finding libunwind on macos https://github.com/jeremy-rifkin/cpptrace/pull/162
|
||||
- Support for libbacktrace under mingw https://github.com/jeremy-rifkin/cpptrace/pull/166
|
||||
|
||||
Fixed
|
||||
- Computation of object address for safe object frames https://github.com/jeremy-rifkin/cpptrace/issues/169
|
||||
- Nested microfmt in cpptrace's namespace due to an ODR problem with libassert https://github.com/jeremy-rifkin/libassert/issues/103
|
||||
- Compilation on iOS https://github.com/jeremy-rifkin/cpptrace/pull/167
|
||||
- Compilation on old MSVC https://github.com/jeremy-rifkin/cpptrace/pull/165
|
||||
- Dbghelp use on 32 bit https://github.com/jeremy-rifkin/cpptrace/issues/170
|
||||
- Warning in brand new cmake due to `FetchContent_Populate` being deprecated https://github.com/jeremy-rifkin/cpptrace/issues/171
|
||||
|
||||
Other changes
|
||||
- Bumped the buffer size for execinfo and CaptureStackBackTrace to 400 frames
|
||||
- Switched to execinfo.h for unwinding on clang/apple clang on macos due to `_Unwind` not working with `-fno-exceptions` https://github.com/jeremy-rifkin/cpptrace/issues/161
|
||||
|
||||
# v0.7.0
|
||||
|
||||
Added
|
||||
|
||||
@ -9,7 +9,7 @@ set(package_name "cpptrace")
|
||||
|
||||
project(
|
||||
cpptrace
|
||||
VERSION 0.7.0
|
||||
VERSION 0.7.1
|
||||
DESCRIPTION "Simple, portable, and self-contained stacktrace library for C++11 and newer "
|
||||
HOMEPAGE_URL "https://github.com/jeremy-rifkin/cpptrace"
|
||||
LANGUAGES C CXX
|
||||
@ -246,6 +246,9 @@ target_sources(
|
||||
src/unwind/unwind_with_nothing.cpp
|
||||
src/unwind/unwind_with_unwind.cpp
|
||||
src/unwind/unwind_with_winapi.cpp
|
||||
src/utils/microfmt.cpp
|
||||
src/utils/utils.cpp
|
||||
src/platform/dbghelp_syminit_manager.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
|
||||
14
README.md
14
README.md
@ -134,7 +134,7 @@ include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cpptrace
|
||||
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
|
||||
GIT_TAG v0.7.0 # <HASH or TAG>
|
||||
GIT_TAG v0.7.1 # <HASH or TAG>
|
||||
)
|
||||
FetchContent_MakeAvailable(cpptrace)
|
||||
target_link_libraries(your_target cpptrace::cpptrace)
|
||||
@ -793,7 +793,7 @@ include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cpptrace
|
||||
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
|
||||
GIT_TAG v0.7.0 # <HASH or TAG>
|
||||
GIT_TAG v0.7.1 # <HASH or TAG>
|
||||
)
|
||||
FetchContent_MakeAvailable(cpptrace)
|
||||
target_link_libraries(your_target cpptrace::cpptrace)
|
||||
@ -809,7 +809,7 @@ information.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/jeremy-rifkin/cpptrace.git
|
||||
git checkout v0.7.0
|
||||
git checkout v0.7.1
|
||||
mkdir cpptrace/build
|
||||
cd cpptrace/build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
@ -852,7 +852,7 @@ you when installing new libraries.
|
||||
|
||||
```ps1
|
||||
git clone https://github.com/jeremy-rifkin/cpptrace.git
|
||||
git checkout v0.7.0
|
||||
git checkout v0.7.1
|
||||
mkdir cpptrace/build
|
||||
cd cpptrace/build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
@ -870,7 +870,7 @@ To install just for the local user (or any custom prefix):
|
||||
|
||||
```sh
|
||||
git clone https://github.com/jeremy-rifkin/cpptrace.git
|
||||
git checkout v0.7.0
|
||||
git checkout v0.7.1
|
||||
mkdir cpptrace/build
|
||||
cd cpptrace/build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/wherever
|
||||
@ -953,7 +953,7 @@ make install
|
||||
cd ~/scratch/cpptrace-test
|
||||
git clone https://github.com/jeremy-rifkin/cpptrace.git
|
||||
cd cpptrace
|
||||
git checkout v0.7.0
|
||||
git checkout v0.7.1
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=On -DCPPTRACE_USE_EXTERNAL_LIBDWARF=On -DCMAKE_PREFIX_PATH=~/scratch/cpptrace-test/resources -DCMAKE_INSTALL_PREFIX=~/scratch/cpptrace-test/resources
|
||||
@ -973,7 +973,7 @@ cpptrace and its dependencies.
|
||||
Cpptrace is available through conan at https://conan.io/center/recipes/cpptrace.
|
||||
```
|
||||
[requires]
|
||||
cpptrace/0.7.0
|
||||
cpptrace/0.7.1
|
||||
[generators]
|
||||
CMakeDeps
|
||||
CMakeToolchain
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
#include "binary/module_base.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
@ -17,7 +16,6 @@
|
||||
#include "binary/elf.hpp"
|
||||
#endif
|
||||
#elif IS_WINDOWS
|
||||
#include <windows.h>
|
||||
#include "binary/pe.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#ifndef IMAGE_MODULE_BASE_HPP
|
||||
#define IMAGE_MODULE_BASE_HPP
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "binary/object.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "binary/module_base.hpp"
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <link.h> // needed for dladdr1's link_map info
|
||||
#endif
|
||||
#elif IS_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
#ifndef OBJECT_HPP
|
||||
#define OBJECT_HPP
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "binary/module_base.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace cpptrace {
|
||||
|
||||
struct object_frame;
|
||||
struct safe_object_frame;
|
||||
|
||||
using frame_ptr = std::uintptr_t;
|
||||
|
||||
namespace detail {
|
||||
object_frame get_frame_object_info(frame_ptr address);
|
||||
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
#include "binary/pe.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#if IS_WINDOWS
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
namespace cpptrace {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#ifndef PE_HPP
|
||||
#define PE_HPP
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#if IS_WINDOWS
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <new>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
@ -16,6 +17,7 @@
|
||||
#include "demangle/demangle.hpp"
|
||||
#include "platform/exception_type.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "binary/object.hpp"
|
||||
#include "binary/safe_dl.hpp"
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
|
||||
@ -6,14 +6,12 @@
|
||||
#include <typeinfo>
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <array>
|
||||
#include <string.h>
|
||||
#if IS_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
@ -25,7 +23,7 @@
|
||||
#endif
|
||||
#else
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <ios>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
45
src/platform/dbghelp_syminit_manager.cpp
Normal file
45
src/platform/dbghelp_syminit_manager.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#if IS_WINDOWS
|
||||
|
||||
#include "platform/dbghelp_syminit_manager.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
|
||||
dbghelp_syminit_manager::~dbghelp_syminit_manager() {
|
||||
for(auto handle : set) {
|
||||
if(!SymCleanup(handle)) {
|
||||
ASSERT(false, microfmt::format("Cpptrace SymCleanup failed with code {}\n", GetLastError()).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dbghelp_syminit_manager::init(HANDLE proc) {
|
||||
if(set.count(proc) == 0) {
|
||||
if(!SymInitialize(proc, NULL, TRUE)) {
|
||||
throw internal_error("SymInitialize failed {}", GetLastError());
|
||||
}
|
||||
set.insert(proc);
|
||||
}
|
||||
}
|
||||
|
||||
// Thread-safety: Must only be called from symbols_with_dbghelp while the dbghelp_lock lock is held
|
||||
dbghelp_syminit_manager& get_syminit_manager() {
|
||||
static dbghelp_syminit_manager syminit_manager;
|
||||
return syminit_manager;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,42 +1,21 @@
|
||||
#ifndef DBGHELP_SYMINIT_MANAGER_HPP
|
||||
#define DBGHELP_SYMINIT_MANAGER_HPP
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
struct dbghelp_syminit_manager {
|
||||
std::unordered_set<HANDLE> set;
|
||||
// The set below contains Windows `HANDLE` objects, `void*` is used to avoid
|
||||
// including the (expensive) Windows header here
|
||||
std::unordered_set<void*> set;
|
||||
|
||||
~dbghelp_syminit_manager() {
|
||||
for(auto handle : set) {
|
||||
if(!SymCleanup(handle)) {
|
||||
ASSERT(false, microfmt::format("Cpptrace SymCleanup failed with code {}\n", GetLastError()).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init(HANDLE proc) {
|
||||
if(set.count(proc) == 0) {
|
||||
if(!SymInitialize(proc, NULL, TRUE)) {
|
||||
throw internal_error("SymInitialize failed {}", GetLastError());
|
||||
}
|
||||
set.insert(proc);
|
||||
}
|
||||
}
|
||||
~dbghelp_syminit_manager();
|
||||
void init(void* proc);
|
||||
};
|
||||
|
||||
// Thread-safety: Must only be called from symbols_with_dbghelp while the dbghelp_lock lock is held
|
||||
inline dbghelp_syminit_manager& get_syminit_manager() {
|
||||
static dbghelp_syminit_manager syminit_manager;
|
||||
return syminit_manager;
|
||||
}
|
||||
dbghelp_syminit_manager& get_syminit_manager();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
#ifndef PATH_HPP
|
||||
#define PATH_HPP
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
#if IS_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#if IS_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#define CPPTRACE_MAX_PATH MAX_PATH
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace cpptrace {
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef CPPTRACE_USE_NESTED_LIBDWARF_HEADER_PATH
|
||||
|
||||
@ -10,15 +10,16 @@
|
||||
#include "utils/utils.hpp"
|
||||
#include "platform/path.hpp"
|
||||
#include "platform/program_name.hpp" // For CPPTRACE_MAX_PATH
|
||||
|
||||
#if IS_APPLE
|
||||
#include "binary/mach-o.hpp"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "symbols/symbols.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "binary/object.hpp"
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
|
||||
#include "symbols/symbols.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "binary/object.hpp"
|
||||
|
||||
namespace cpptrace {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "symbols/symbols.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@ -3,14 +3,16 @@
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "symbols/symbols.hpp"
|
||||
#include "platform/dbghelp_syminit_manager.hpp"
|
||||
#include "binary/object.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <regex>
|
||||
#include <stdexcept>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "symbols/symbols.hpp"
|
||||
#include "binary/module_base.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "symbols/symbols.hpp"
|
||||
#include "platform/program_name.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/common.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "dwarf/resolver.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
@ -15,8 +14,6 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include "symbols/symbols.hpp"
|
||||
#include "utils/common.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
#ifndef UNWIND_HPP
|
||||
#define UNWIND_HPP
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
@ -6,10 +6,9 @@
|
||||
#include "utils/utils.hpp"
|
||||
#include "platform/dbghelp_syminit_manager.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <cstddef>
|
||||
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
// Fucking windows headers
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
#ifndef COMMON_HPP
|
||||
#define COMMON_HPP
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define ESC "\033["
|
||||
#define RESET ESC "0m"
|
||||
#define RED ESC "31m"
|
||||
@ -31,8 +29,8 @@ namespace detail {
|
||||
static const stacktrace_frame null_frame {
|
||||
0,
|
||||
0,
|
||||
nullable<uint32_t>::null(),
|
||||
nullable<uint32_t>::null(),
|
||||
nullable<std::uint32_t>::null(),
|
||||
nullable<std::uint32_t>::null(),
|
||||
"",
|
||||
"",
|
||||
false
|
||||
|
||||
@ -2,11 +2,10 @@
|
||||
#define ERROR_HPP
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
|
||||
#if IS_MSVC
|
||||
|
||||
13
src/utils/microfmt.cpp
Normal file
13
src/utils/microfmt.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "utils/microfmt.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
|
||||
std::ostream& get_cout() {
|
||||
return std::cout;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,10 @@
|
||||
#ifndef MICROFMT_HPP
|
||||
#define MICROFMT_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
|
||||
#include <string_view>
|
||||
@ -286,9 +285,11 @@ namespace microfmt {
|
||||
return detail::format<1>(fmt, fmt + std::strlen(fmt), {detail::format_value(1)});
|
||||
}
|
||||
|
||||
std::ostream& get_cout();
|
||||
|
||||
template<typename S, typename... Args>
|
||||
void print(const S& fmt, Args&&... args) {
|
||||
std::cout<<format(fmt, args...);
|
||||
get_cout()<<format(fmt, args...);
|
||||
}
|
||||
|
||||
template<typename S, typename... Args>
|
||||
|
||||
58
src/utils/utils.cpp
Normal file
58
src/utils/utils.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#if IS_WINDOWS
|
||||
#include <io.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
|
||||
bool isatty(int fd) {
|
||||
#if IS_WINDOWS
|
||||
return _isatty(fd);
|
||||
#else
|
||||
return ::isatty(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
int fileno(std::FILE* stream) {
|
||||
#if IS_WINDOWS
|
||||
return _fileno(stream);
|
||||
#else
|
||||
return ::fileno(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
void enable_virtual_terminal_processing_if_needed() noexcept {
|
||||
// enable colors / ansi processing if necessary
|
||||
#if IS_WINDOWS
|
||||
// https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example-of-enabling-virtual-terminal-processing
|
||||
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
||||
constexpr DWORD ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4;
|
||||
#endif
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwMode = 0;
|
||||
if(hOut == INVALID_HANDLE_VALUE) return;
|
||||
if(!GetConsoleMode(hOut, &dwMode)) return;
|
||||
if(dwMode != (dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
|
||||
if(!SetConsoleMode(hOut, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)) return;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool directory_exists(const std::string& path) {
|
||||
#if IS_WINDOWS
|
||||
DWORD dwAttrib = GetFileAttributesA(path.c_str());
|
||||
return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
|
||||
#else
|
||||
struct stat sb;
|
||||
return stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -7,12 +7,8 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <ios>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@ -20,33 +16,13 @@
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/microfmt.hpp"
|
||||
|
||||
#if IS_WINDOWS
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
inline bool isatty(int fd) {
|
||||
#if IS_WINDOWS
|
||||
return _isatty(fd);
|
||||
#else
|
||||
return ::isatty(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int fileno(std::FILE* stream) {
|
||||
#if IS_WINDOWS
|
||||
return _fileno(stream);
|
||||
#else
|
||||
return ::fileno(stream);
|
||||
#endif
|
||||
}
|
||||
bool isatty(int fd);
|
||||
int fileno(std::FILE* stream);
|
||||
|
||||
inline std::vector<std::string> split(const std::string& str, const std::string& delims) {
|
||||
std::vector<std::string> vec;
|
||||
@ -162,21 +138,7 @@ namespace detail {
|
||||
return byte_swapper<T, sizeof(T)>{}(value);
|
||||
}
|
||||
|
||||
inline void enable_virtual_terminal_processing_if_needed() noexcept {
|
||||
// enable colors / ansi processing if necessary
|
||||
#if IS_WINDOWS
|
||||
// https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example-of-enabling-virtual-terminal-processing
|
||||
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
||||
constexpr DWORD ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4;
|
||||
#endif
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwMode = 0;
|
||||
if(hOut == INVALID_HANDLE_VALUE) return;
|
||||
if(!GetConsoleMode(hOut, &dwMode)) return;
|
||||
if(dwMode != (dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
|
||||
if(!SetConsoleMode(hOut, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)) return;
|
||||
#endif
|
||||
}
|
||||
void enable_virtual_terminal_processing_if_needed() noexcept;
|
||||
|
||||
constexpr unsigned n_digits(unsigned value) noexcept {
|
||||
return value < 10 ? 1 : 1 + n_digits(value / 10);
|
||||
@ -455,15 +417,7 @@ namespace detail {
|
||||
}
|
||||
|
||||
// shamelessly stolen from stackoverflow
|
||||
inline bool directory_exists(const std::string& path) {
|
||||
#if IS_WINDOWS
|
||||
DWORD dwAttrib = GetFileAttributesA(path.c_str());
|
||||
return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
|
||||
#else
|
||||
struct stat sb;
|
||||
return stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode);
|
||||
#endif
|
||||
}
|
||||
bool directory_exists(const std::string& path);
|
||||
|
||||
inline std::string basename(const std::string& path) {
|
||||
// Assumes no trailing /'s
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest-matchers.h>
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest-matchers.h>
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest-matchers.h>
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user