32 lines
1004 B
C++
32 lines
1004 B
C++
#pragma once
|
|
#include <Void/Result/Error.hpp>
|
|
#include <Void/Result/Result.hpp>
|
|
#include <ostream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Void::Stacktrace
|
|
{
|
|
struct StackFrame {
|
|
std::string function_name;
|
|
std::string source_file;
|
|
int source_line{0};
|
|
std::string source_snippet;
|
|
};
|
|
|
|
std::vector<StackFrame> capture_stacktrace(unsigned skip_frames = 0,
|
|
unsigned max_frames = 32);
|
|
|
|
/// Read a snippet of source around `line`. On failure (file missing,
|
|
/// not readable, etc.) returns Failure<Error> instead of an empty
|
|
/// string — callers that want the silent fallback can still do
|
|
/// `read_source_snippet(...).value_or("")`.
|
|
Void::Result::Result<std::string, Void::Result::Error>
|
|
read_source_snippet(const std::string& file, int line,
|
|
int context_lines = 3);
|
|
|
|
std::string format_stacktrace(const std::vector<StackFrame>& frames);
|
|
void print_stacktrace(std::ostream& os,
|
|
const std::vector<StackFrame>& frames);
|
|
} // namespace Void::Stacktrace
|