This commit is contained in:
Tsche 2025-02-28 17:55:44 +01:00 committed by GitHub
parent c0354799c7
commit fac4d08fd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 5 deletions

View File

@ -209,7 +209,7 @@ namespace cpptrace {
const auto blue = color ? BLUE : ""; const auto blue = color ? BLUE : "";
if(frame.is_inline) { if(frame.is_inline) {
microfmt::print(stream, "{<{}} ", 2 * sizeof(frame_ptr) + 2, "(inlined)"); microfmt::print(stream, "{<{}} ", 2 * sizeof(frame_ptr) + 2, "(inlined)");
} else { } else if(options.addresses != address_mode::none) {
auto address = options.addresses == address_mode::raw ? frame.raw_address : frame.object_address; auto address = options.addresses == address_mode::raw ? frame.raw_address : frame.object_address;
microfmt::print(stream, "{}0x{>{}:0h}{} ", blue, 2 * sizeof(frame_ptr), address, reset); microfmt::print(stream, "{}0x{>{}:0h}{} ", blue, 2 * sizeof(frame_ptr), address, reset);
} }
@ -219,7 +219,8 @@ namespace cpptrace {
if(!frame.filename.empty()) { if(!frame.filename.empty()) {
microfmt::print( microfmt::print(
stream, stream,
" at {}{}{}", "{}at {}{}{}",
frame.symbol.empty() ? "" : " ",
green, green,
options.paths == path_mode::full ? frame.filename : detail::basename(frame.filename, true), options.paths == path_mode::full ? frame.filename : detail::basename(frame.filename, true),
reset reset

View File

@ -96,6 +96,21 @@ TEST(FormatterTest, ObjectAddresses) {
); );
} }
TEST(FormatterTest, NoAddresses) {
auto formatter = cpptrace::formatter{}
.addresses(cpptrace::formatter::address_mode::none);
auto res = split(formatter.format(make_test_stacktrace()), "\n");
EXPECT_THAT(
res,
ElementsAre(
"Stack trace (most recent call first):",
"#0 in foo() at foo.cpp:20:30",
"#1 in bar() at bar.cpp:30:40",
"#2 in main at foo.cpp:40:25"
)
);
}
TEST(FormatterTest, PathShortening) { TEST(FormatterTest, PathShortening) {
cpptrace::stacktrace trace; cpptrace::stacktrace trace;
trace.frames.push_back({0x1, 0x1001, {20}, {30}, "/home/foo/foo.cpp", "foo()", false}); trace.frames.push_back({0x1, 0x1001, {20}, {30}, "/home/foo/foo.cpp", "foo()", false});