Skip to content

Commit 636b5f6

Browse files
gottesmmatrick
authored andcommitted
[runtime] Add support for an asserts only debugging routine called swift_dumpTrackedAccesses().
This makes it easy to perform printf debugging in the debugger. I have found it to be useful in understanding programs around exclusivity quickly.
1 parent e58fdc8 commit 636b5f6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

include/swift/Runtime/Exclusivity.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ void swift_endAccess(ValueBuffer *buffer);
5858
SWIFT_RUNTIME_EXPORT
5959
bool _swift_disableExclusivityChecking;
6060

61+
#ifndef NDEBUG
62+
63+
/// Dump all accesses currently tracked by the runtime.
64+
///
65+
/// This is a debug routine that is intended to be used from the debugger and is
66+
/// compiled out when asserts are disabled. The intention is that it allows one
67+
/// to dump the access state to easily see if/when exclusivity violations will
68+
/// happen. This eases debugging.
69+
SWIFT_RUNTIME_EXPORT
70+
void swift_dumpTrackedAccesses();
71+
72+
#endif
73+
6174
} // end namespace swift
6275

6376
#endif

stdlib/public/runtime/Exclusivity.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ class AccessSet {
260260

261261
swift_runtime_unreachable("access not found in set");
262262
}
263+
264+
#ifndef NDEBUG
265+
/// Only available with asserts. Intended to be used with
266+
/// swift_dumpTrackedAccess().
267+
void forEach(std::function<void (Access *)> action) {
268+
for (auto *iter = Head; iter != nullptr; iter = iter->getNext()) {
269+
action(iter);
270+
}
271+
}
272+
#endif
263273
};
264274

265275
} // end anonymous namespace
@@ -348,3 +358,17 @@ void swift::swift_endAccess(ValueBuffer *buffer) {
348358

349359
getAccessSet().remove(access);
350360
}
361+
362+
#ifndef NDEBUG
363+
364+
// Dump the accesses that are currently being tracked by the runtime.
365+
//
366+
// This is only intended to be used in the debugger.
367+
void swift::swift_dumpTrackedAccesses() {
368+
getAccessSet().forEach([](Access *a) {
369+
fprintf(stderr, "Access. Pointer: %p. PC: %p. AccessAction: %s",
370+
a->Pointer, a->PC, getAccessName(a->getAccessAction()));
371+
});
372+
}
373+
374+
#endif

0 commit comments

Comments
 (0)