Some formatting consistency tweaks
This commit is contained in:
parent
a3e3916daa
commit
8f9e8c5c1b
@ -125,7 +125,9 @@ CTRACE_FORMAT_EPILOGUE
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cpptrace::stacktrace cpp_convert(const ctrace_stacktrace* ptrace) {
|
static cpptrace::stacktrace cpp_convert(const ctrace_stacktrace* ptrace) {
|
||||||
if(!ptrace || !ptrace->frames) return { };
|
if(!ptrace || !ptrace->frames) {
|
||||||
|
return { };
|
||||||
|
}
|
||||||
std::vector<cpptrace::stacktrace_frame> new_frames;
|
std::vector<cpptrace::stacktrace_frame> new_frames;
|
||||||
new_frames.reserve(ptrace->count);
|
new_frames.reserve(ptrace->count);
|
||||||
for(std::size_t i = 0; i < ptrace->count; ++i) {
|
for(std::size_t i = 0; i < ptrace->count; ++i) {
|
||||||
@ -152,7 +154,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ctrace_free_owning_string(ctrace_owning_string* string) {
|
void ctrace_free_owning_string(ctrace_owning_string* string) {
|
||||||
if(!string) return;
|
if(!string) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ctrace::free_owning_string(*string);
|
ctrace::free_owning_string(*string);
|
||||||
string->data = nullptr;
|
string->data = nullptr;
|
||||||
}
|
}
|
||||||
@ -200,7 +204,9 @@ extern "C" {
|
|||||||
|
|
||||||
// ctrace::freeing:
|
// ctrace::freeing:
|
||||||
void ctrace_free_raw_trace(ctrace_raw_trace* trace) {
|
void ctrace_free_raw_trace(ctrace_raw_trace* trace) {
|
||||||
if(!trace) return;
|
if(!trace) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ctrace_frame_ptr* frames = trace->frames;
|
ctrace_frame_ptr* frames = trace->frames;
|
||||||
delete[] frames;
|
delete[] frames;
|
||||||
trace->frames = nullptr;
|
trace->frames = nullptr;
|
||||||
@ -208,7 +214,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ctrace_free_object_trace(ctrace_object_trace* trace) {
|
void ctrace_free_object_trace(ctrace_object_trace* trace) {
|
||||||
if(!trace || !trace->frames) return;
|
if(!trace || !trace->frames) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ctrace_object_frame* frames = trace->frames;
|
ctrace_object_frame* frames = trace->frames;
|
||||||
for(std::size_t i = 0; i < trace->count; ++i) {
|
for(std::size_t i = 0; i < trace->count; ++i) {
|
||||||
const char* path = frames[i].obj_path;
|
const char* path = frames[i].obj_path;
|
||||||
@ -221,7 +229,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ctrace_free_stacktrace(ctrace_stacktrace* trace) {
|
void ctrace_free_stacktrace(ctrace_stacktrace* trace) {
|
||||||
if(!trace || !trace->frames) return;
|
if(!trace || !trace->frames) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ctrace_stacktrace_frame* frames = trace->frames;
|
ctrace_stacktrace_frame* frames = trace->frames;
|
||||||
for(std::size_t i = 0; i < trace->count; ++i) {
|
for(std::size_t i = 0; i < trace->count; ++i) {
|
||||||
ctrace::free_owning_string(frames[i].filename);
|
ctrace::free_owning_string(frames[i].filename);
|
||||||
@ -235,7 +245,9 @@ extern "C" {
|
|||||||
|
|
||||||
// ctrace::resolve:
|
// ctrace::resolve:
|
||||||
ctrace_stacktrace ctrace_raw_trace_resolve(const ctrace_raw_trace* trace) {
|
ctrace_stacktrace ctrace_raw_trace_resolve(const ctrace_raw_trace* trace) {
|
||||||
if(!trace || !trace->frames) return { nullptr, 0 };
|
if(!trace || !trace->frames) {
|
||||||
|
return { nullptr, 0 };
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
std::vector<cpptrace::frame_ptr> frames(trace->count, 0);
|
std::vector<cpptrace::frame_ptr> frames(trace->count, 0);
|
||||||
std::copy(trace->frames, trace->frames + trace->count, frames.begin());
|
std::copy(trace->frames, trace->frames + trace->count, frames.begin());
|
||||||
@ -248,7 +260,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctrace_object_trace ctrace_raw_trace_resolve_object_trace(const ctrace_raw_trace* trace) {
|
ctrace_object_trace ctrace_raw_trace_resolve_object_trace(const ctrace_raw_trace* trace) {
|
||||||
if(!trace || !trace->frames) return { nullptr, 0 };
|
if(!trace || !trace->frames) {
|
||||||
|
return { nullptr, 0 };
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
std::vector<cpptrace::frame_ptr> frames(trace->count, 0);
|
std::vector<cpptrace::frame_ptr> frames(trace->count, 0);
|
||||||
std::copy(trace->frames, trace->frames + trace->count, frames.begin());
|
std::copy(trace->frames, trace->frames + trace->count, frames.begin());
|
||||||
@ -261,7 +275,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctrace_stacktrace ctrace_object_trace_resolve(const ctrace_object_trace* trace) {
|
ctrace_stacktrace ctrace_object_trace_resolve(const ctrace_object_trace* trace) {
|
||||||
if(!trace || !trace->frames) return { nullptr, 0 };
|
if(!trace || !trace->frames) {
|
||||||
|
return { nullptr, 0 };
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
std::vector<cpptrace::frame_ptr> frames(trace->count, 0);
|
std::vector<cpptrace::frame_ptr> frames(trace->count, 0);
|
||||||
std::transform(
|
std::transform(
|
||||||
@ -293,7 +309,9 @@ extern "C" {
|
|||||||
|
|
||||||
// ctrace::io:
|
// ctrace::io:
|
||||||
ctrace_owning_string ctrace_stacktrace_to_string(const ctrace_stacktrace* trace, ctrace_bool use_color) {
|
ctrace_owning_string ctrace_stacktrace_to_string(const ctrace_stacktrace* trace, ctrace_bool use_color) {
|
||||||
if(!trace || !trace->frames) return ctrace::generate_owning_string("<empty trace>");
|
if(!trace || !trace->frames) {
|
||||||
|
return ctrace::generate_owning_string("<empty trace>");
|
||||||
|
}
|
||||||
auto cpp_trace = ctrace::cpp_convert(trace);
|
auto cpp_trace = ctrace::cpp_convert(trace);
|
||||||
std::string trace_string = cpp_trace.to_string(bool(use_color));
|
std::string trace_string = cpp_trace.to_string(bool(use_color));
|
||||||
return ctrace::generate_owning_string(trace_string);
|
return ctrace::generate_owning_string(trace_string);
|
||||||
@ -305,7 +323,9 @@ extern "C" {
|
|||||||
(to == stdout && cpptrace::isatty(cpptrace::stdout_fileno)) ||
|
(to == stdout && cpptrace::isatty(cpptrace::stdout_fileno)) ||
|
||||||
(to == stderr && cpptrace::isatty(cpptrace::stderr_fileno))
|
(to == stderr && cpptrace::isatty(cpptrace::stderr_fileno))
|
||||||
)
|
)
|
||||||
) cpptrace::detail::enable_virtual_terminal_processing_if_needed();
|
) {
|
||||||
|
cpptrace::detail::enable_virtual_terminal_processing_if_needed();
|
||||||
|
}
|
||||||
ctrace::ffprintf(to, "Stack trace (most recent call first):\n");
|
ctrace::ffprintf(to, "Stack trace (most recent call first):\n");
|
||||||
if(trace->count == 0 || !trace->frames) {
|
if(trace->count == 0 || !trace->frames) {
|
||||||
ctrace::ffprintf(to, "<empty trace>\n");
|
ctrace::ffprintf(to, "<empty trace>\n");
|
||||||
@ -366,7 +386,9 @@ extern "C" {
|
|||||||
|
|
||||||
// utility::demangle:
|
// utility::demangle:
|
||||||
ctrace_owning_string ctrace_demangle(const char* mangled) {
|
ctrace_owning_string ctrace_demangle(const char* mangled) {
|
||||||
if(!mangled) return ctrace::generate_owning_string("");
|
if(!mangled) {
|
||||||
|
return ctrace::generate_owning_string("");
|
||||||
|
}
|
||||||
std::string demangled = cpptrace::demangle(mangled);
|
std::string demangled = cpptrace::demangle(mangled);
|
||||||
return ctrace::generate_owning_string(demangled);
|
return ctrace::generate_owning_string(demangled);
|
||||||
}
|
}
|
||||||
@ -391,7 +413,9 @@ extern "C" {
|
|||||||
// utility::cache:
|
// utility::cache:
|
||||||
void ctrace_set_cache_mode(ctrace_cache_mode mode) {
|
void ctrace_set_cache_mode(ctrace_cache_mode mode) {
|
||||||
static constexpr auto cache_max = cpptrace::cache_mode::prioritize_speed;
|
static constexpr auto cache_max = cpptrace::cache_mode::prioritize_speed;
|
||||||
if(mode > unsigned(cache_max)) return;
|
if(mode > unsigned(cache_max)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto cache_mode = static_cast<cpptrace::cache_mode>(mode);
|
auto cache_mode = static_cast<cpptrace::cache_mode>(mode);
|
||||||
cpptrace::experimental::set_cache_mode(cache_mode);
|
cpptrace::experimental::set_cache_mode(cache_mode);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user