Skip to content

Commit fac4d08

Browse files
authored
fix #221 (#223)
1 parent c035479 commit fac4d08

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/formatting.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,19 @@ namespace cpptrace {
208208
const auto yellow = color ? YELLOW : "";
209209
const auto blue = color ? BLUE : "";
210210
if(frame.is_inline) {
211-
microfmt::print(stream, "{<{}}", 2 * sizeof(frame_ptr) + 2, "(inlined)");
212-
} else {
211+
microfmt::print(stream, "{<{}} ", 2 * sizeof(frame_ptr) + 2, "(inlined)");
212+
} else if(options.addresses != address_mode::none) {
213213
auto address = options.addresses == address_mode::raw ? frame.raw_address : frame.object_address;
214-
microfmt::print(stream, "{}0x{>{}:0h}{}", blue, 2 * sizeof(frame_ptr), address, reset);
214+
microfmt::print(stream, "{}0x{>{}:0h}{} ", blue, 2 * sizeof(frame_ptr), address, reset);
215215
}
216216
if(!frame.symbol.empty()) {
217-
microfmt::print(stream, " in {}{}{}", yellow, frame.symbol, reset);
217+
microfmt::print(stream, "in {}{}{}", yellow, frame.symbol, reset);
218218
}
219219
if(!frame.filename.empty()) {
220220
microfmt::print(
221221
stream,
222-
" at {}{}{}",
222+
"{}at {}{}{}",
223+
frame.symbol.empty() ? "" : " ",
223224
green,
224225
options.paths == path_mode::full ? frame.filename : detail::basename(frame.filename, true),
225226
reset

test/unit/lib/formatting.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ TEST(FormatterTest, ObjectAddresses) {
9696
);
9797
}
9898

99+
TEST(FormatterTest, NoAddresses) {
100+
auto formatter = cpptrace::formatter{}
101+
.addresses(cpptrace::formatter::address_mode::none);
102+
auto res = split(formatter.format(make_test_stacktrace()), "\n");
103+
EXPECT_THAT(
104+
res,
105+
ElementsAre(
106+
"Stack trace (most recent call first):",
107+
"#0 in foo() at foo.cpp:20:30",
108+
"#1 in bar() at bar.cpp:30:40",
109+
"#2 in main at foo.cpp:40:25"
110+
)
111+
);
112+
}
113+
99114
TEST(FormatterTest, PathShortening) {
100115
cpptrace::stacktrace trace;
101116
trace.frames.push_back({0x1, 0x1001, {20}, {30}, "/home/foo/foo.cpp", "foo()", false});

0 commit comments

Comments
 (0)