Update stacktrace api and a couple minor tweaks

This commit is contained in:
Jeremy 2023-07-09 22:43:22 -04:00
parent 57f5cc529c
commit a540803cd9
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
11 changed files with 35 additions and 34 deletions

View File

@ -121,7 +121,7 @@ if(
)
)
# Attempt to auto-config
if(HAS_STACKTRACE AND NOT WIN32)
if(HAS_STACKTRACE AND NOT WIN32) # Our trace is better than msvc's <stacktrace>
set(CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE On)
message(STATUS "Cpptrace auto config: Using C++23 <stacktrace> for the full trace")
elseif(HAS_BACKTRACE)

View File

@ -32,13 +32,13 @@ export information which may require `-rdynamic` or manually marking symbols for
namespace cpptrace {
struct stacktrace_frame {
uintptr_t address;
int line;
int col;
std::uint_least32_t line;
std::uint_least32_t col;
std::string filename;
std::string symbol;
};
std::vector<stacktrace_frame> generate_trace();
void print_trace();
std::vector<stacktrace_frame> generate_trace(std::uint32_t skip = 0);
void print_trace(std::uint32_t skip = 0);
}
```

View File

@ -2,19 +2,20 @@
#define CPPTRACE_HPP
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
namespace cpptrace {
struct stacktrace_frame {
uintptr_t address;
int line;
int col;
std::uint_least32_t line;
std::uint_least32_t col;
std::string filename;
std::string symbol;
};
std::vector<stacktrace_frame> generate_trace();
void print_trace();
std::vector<stacktrace_frame> generate_trace(std::uint32_t skip = 0);
void print_trace(std::uint32_t skip = 0);
}
#endif

View File

@ -14,8 +14,8 @@
namespace cpptrace {
CPPTRACE_FORCE_NO_INLINE
std::vector<stacktrace_frame> generate_trace() {
std::vector<void*> frames = detail::capture_frames(1);
std::vector<stacktrace_frame> generate_trace(std::uint32_t skip) {
std::vector<void*> frames = detail::capture_frames(skip + 1);
detail::symbolizer symbolizer;
std::vector<stacktrace_frame> trace = symbolizer.resolve_frames(frames);
for(auto& frame : trace) {
@ -34,8 +34,8 @@ namespace cpptrace {
namespace cpptrace {
CPPTRACE_FORCE_NO_INLINE
std::vector<stacktrace_frame> generate_trace() {
auto trace = detail::generate_trace(1);
std::vector<stacktrace_frame> generate_trace(std::uint32_t skip) {
auto trace = detail::generate_trace(skip + 1);
for(auto& entry : trace) {
entry.symbol = detail::demangle(entry.symbol);
}
@ -46,10 +46,10 @@ namespace cpptrace {
#endif
namespace cpptrace {
void print_trace() {
void print_trace(std::uint32_t skip) {
std::cerr<<"Stack trace (most recent call first):"<<std::endl;
std::size_t i = 0;
const auto trace = generate_trace();
const auto trace = generate_trace(skip + 1);
// +1 to skip one frame
for(auto it = trace.begin() + 1; it != trace.end(); it++) {
const auto& frame = *it;

View File

@ -27,8 +27,8 @@ namespace cpptrace {
} else {
data.frames.push_back({
address,
line,
-1,
static_cast<std::uint_least32_t>(line),
0,
file ? file : "",
symbol ? symbol : ""
});

View File

@ -17,7 +17,7 @@ namespace cpptrace {
frames.push_back({
entry.native_handle(),
entry.source_line(),
-1,
0,
entry.source_file(),
entry.description()
});

View File

@ -98,7 +98,7 @@ static std::string join(const C& container, const std::string& delim) {
return str;
}
constexpr const char * const ws = " \t\n\r\f\v";
constexpr const char* const ws = " \t\n\r\f\v";
CPPTRACE_MAYBE_UNUSED
static std::string trim(const std::string& s) {

View File

@ -339,8 +339,8 @@ namespace cpptrace {
fprintf(stderr, "Stack trace: Internal error while calling SymSetContext\n");
return {
reinterpret_cast<uintptr_t>(addr),
int(line.LineNumber),
-1,
static_cast<std::uint_least32_t>(line.LineNumber),
0,
line.FileName,
symbol->Name
};
@ -363,16 +363,16 @@ namespace cpptrace {
signature = std::regex_replace(signature, comma_re, ", ");
return {
reinterpret_cast<uintptr_t>(addr),
int(line.LineNumber),
-1,
static_cast<std::uint_least32_t>(line.LineNumber),
0,
line.FileName,
signature
};
} else {
return {
reinterpret_cast<uintptr_t>(addr),
-1,
-1,
0,
0,
"",
symbol->Name
};
@ -380,8 +380,8 @@ namespace cpptrace {
} else {
return {
reinterpret_cast<uintptr_t>(addr),
-1,
-1,
0,
0,
"",
""
};

View File

@ -55,7 +55,7 @@ namespace cpptrace {
struct symbolizer::impl {
stacktrace_frame resolve_frame(void* addr) {
stacktrace_frame frame;
frame.col = -1;
frame.col = 0;
backtrace_pcinfo(
get_backtrace_state(),
reinterpret_cast<uintptr_t>(addr),

View File

@ -14,8 +14,8 @@ namespace cpptrace {
// stacktrace_frame symbolizer::resolve_frame(void*) {
// return {
// 0,
// -1,
// -1,
// 0,
// 0,
// "",
// "",
// };
@ -24,8 +24,8 @@ namespace cpptrace {
std::vector<stacktrace_frame> symbolizer::resolve_frames(const std::vector<void*>& frames) {
return std::vector<stacktrace_frame>(frames.size(), {
0,
-1,
-1,
0,
0,
"",
""
});

View File

@ -26,5 +26,5 @@ D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl||79||invoke_
D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl||288||__scrt_common_main_seh()
D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl||331||__scrt_common_main()
D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp||17||mainCRTStartup(void*)
||-1||BaseThreadInitThunk
||-1||RtlUserThreadStart
||0||BaseThreadInitThunk
||0||RtlUserThreadStart