Skip to content

Commit 6590f9c

Browse files
committed
Slightly adapted the README.md
1 parent add6f85 commit 6590f9c

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

README.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ void printCallstack(void) {
115115
116116
printf("The current callstack:\n");
117117
for (size_t i = 0; i < callstack_getFrameCount(callstack); ++i) {
118-
printf("In: (%s) %s (%s:%ld)\n", callstack_frame_getShortestName(&frames[i]),
119-
(frames[i].function == NULL ? "???" : frames[i].function),
120-
callstack_frame_getShortestSourceFileOr(&frames[i], "???"),
121-
frames[i].sourceLine);
118+
printf("# %zu: (%s) %s (%s:%ld)\n", i + 1,
119+
callstack_frame_getShortestName(&frames[i]),
120+
(frames[i].function == NULL ? "???" : frames[i].function),
121+
callstack_frame_getShortestSourceFileOr(&frames[i], "???"),
122+
frames[i].sourceLine);
122123
}
123124
callstack_delete(callstack);
124125
}
@@ -137,13 +138,13 @@ Compiled and linked on macOS with `cc -g main.c -I<path/to/library>/include -L<p
137138
creates the following output:
138139
```
139140
The current callstack:
140-
In: (a.out) printCallstack (main.c:8)
141-
In: (a.out) bar (main.c:21)
142-
In: (a.out) foo (main.c:23)
143-
In: (a.out) bar2 (main.c:24)
144-
In: (a.out) foo2 (main.c:25)
145-
In: (a.out) main (main.c:28)
146-
In: (/usr/lib/dyld) start + 1942 (???:0)
141+
# 1: (a.out) printCallstack (main.c:8)
142+
# 2: (a.out) bar (main.c:22)
143+
# 3: (a.out) foo (main.c:24)
144+
# 4: (a.out) bar2 (main.c:25)
145+
# 5: (a.out) foo2 (main.c:26)
146+
# 6: (a.out) main (main.c:29)
147+
# 7: (/usr/lib/dyld) start + 3056 (???:0)
147148
```
148149
149150
#### C++
@@ -159,12 +160,13 @@ void printCallstack() {
159160
lcs::callstack callstack;
160161
161162
std::cout << "The current callstack:" << std::endl;
163+
std::size_t i = 1;
162164
for (const auto& frame : callstack.translate()) {
163-
std::cout << "In: (" << callstack_frame_getShortestName(&frame)
164-
<< ") " << (frame.function == NULL ? "???" : frame.function)
165-
<< " (" << callstack_frame_getShortestSourceFileOr(&frame, "???")
166-
<< ":" << frame.sourceLine
167-
<< ")" << std::endl;
165+
std::cout << "# " << i++ << ": (" << callstack_frame_getShortestName(&frame)
166+
<< ") " << (frame.function == NULL ? "???" : frame.function)
167+
<< " (" << callstack_frame_getShortestSourceFileOr(&frame, "???")
168+
<< ":" << frame.sourceLine
169+
<< ")" << std::endl;
168170
}
169171
}
170172
@@ -178,20 +180,20 @@ int main() {
178180
foo2();
179181
}
180182
```
181-
Compiled and linked on Debian with `g++ -g -std=c++11 main.cpp -I<path/to/library>/include -L<path/to/library> -lcallstack`
183+
Compiled and linked on Fedora 42 with `g++ -g -std=c++11 main.cpp -I<path/to/library>/include -L<path/to/library> -lcallstack`
182184
and after [enabling **C++** functions][6] of the library the following output is produced:
183185
```
184186
The current callstack:
185-
In: (a.out) lcs::callstack::callstack(bool) (include/callstack.hpp:81)
186-
In: (a.out) printCallstack() (main.cpp:8)
187-
In: (a.out) bar() (main.cpp:21)
188-
In: (a.out) foo() (main.cpp:23)
189-
In: (a.out) bar2() (main.cpp:24)
190-
In: (a.out) foo2() (main.cpp:25)
191-
In: (a.out) main (main.cpp:28)
192-
In: (/usr/lib/x86_64-linux-gnu/libc.so.6) ??? (???:0)
193-
In: (/usr/lib/x86_64-linux-gnu/libc.so.6) __libc_start_main + 133 (???:0)
194-
In: (a.out) _start + 33 (???:0)
187+
# 1: (a.out) lcs::callstack::callstack(bool) (include/callstack.hpp:83)
188+
# 2: (a.out) printCallstack() (main.cpp:8)
189+
# 3: (a.out) bar() (main.cpp:21)
190+
# 4: (a.out) foo() (main.cpp:23)
191+
# 5: (a.out) bar2() (main.cpp:24)
192+
# 6: (a.out) foo2() (main.cpp:25)
193+
# 7: (a.out) main (main.cpp:28)
194+
# 8: (/usr/lib64/libc.so.6) __libc_start_call_main + 117 (???:0)
195+
# 9: (/usr/lib64/libc.so.6) __libc_start_main_alias_2 + 136 (???:0)
196+
# 10: (a.out) _start + 37 (???:0)
195197
```
196198
197199
> [!TIP]

0 commit comments

Comments
 (0)