Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit dff41b8

Browse files
author
Johannes Weiss
committed
better distinguish mmap errors & print errno
Motivation: In case SwiftBacktrace fails, we get only very little output. Unfortunately, some crucial information (like the errno) is missing and in case `mmap` fails, we don't know if the problem is file I/O or allocating memory. Modification: - print errnos - distinguish the two mmaps Result: Easier debugging
1 parent 4915cdd commit dff41b8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Sources/Backtrace/Backtrace.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ private let fullCallback: CBacktraceFullCallback? = {
5353
}
5454

5555
private let errorCallback: CBacktraceErrorCallback? = {
56-
_, msg, _ in
56+
_, msg, errNo in
5757
if let msg = msg {
5858
_ = withVaList([msg]) { vaList in
59-
vfprintf(stderr, "%s\n", vaList)
59+
vfprintf(stderr, "SwiftBacktrace ERROR: %s (errno: %d)\n", vaList, errNo)
6060
}
6161
}
6262
}

Sources/CBacktrace/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ backtrace_alloc (struct backtrace_state *state,
170170
if (page == MAP_FAILED)
171171
{
172172
if (error_callback)
173-
error_callback (data, "mmap", errno);
173+
error_callback (data, "mmap for alloc", errno);
174174
}
175175
else
176176
{

Sources/CBacktrace/mmapio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED,
7171
map = mmap (NULL, size, PROT_READ, MAP_PRIVATE, descriptor, pageoff);
7272
if (map == MAP_FAILED)
7373
{
74-
error_callback (data, "mmap", errno);
74+
error_callback (data, "mmap file i/o", errno);
7575
return 0;
7676
}
7777

0 commit comments

Comments
 (0)