20
20
#include " swift/Demangling/Demangler.h"
21
21
#include " swift/Runtime/AccessibleFunction.h"
22
22
#include " swift/Runtime/Concurrent.h"
23
+ #include " swift/Runtime/EnvironmentVariables.h"
23
24
#include " swift/Runtime/Metadata.h"
25
+ #include " swift/Threading/Once.h"
24
26
#include " Tracing.h"
25
27
26
28
#include < cstdint>
@@ -98,6 +100,29 @@ static Lazy<AccessibleFunctionsState> Functions;
98
100
99
101
} // end anonymous namespace
100
102
103
+ LLVM_ATTRIBUTE_UNUSED
104
+ static void _dumpAccessibleFunctionRecords (void *context) {
105
+ auto &S = Functions.get ();
106
+
107
+ fprintf (stderr, " ==== Accessible Function Records ====\n " );
108
+ int count = 0 ;
109
+ for (const auto §ion : S.SectionsToScan .snapshot ()) {
110
+ for (auto &record : section) {
111
+ auto recordName =
112
+ swift::Demangle::makeSymbolicMangledNameStringRef (record.Name .get ());
113
+ auto demangledRecordName =
114
+ swift::Demangle::demangleSymbolAsString (recordName);
115
+ fprintf (stderr, " Record name: %s\n " , recordName.data ());
116
+ fprintf (stderr, " Demangled: %s\n " , demangledRecordName.c_str ());
117
+ fprintf (stderr, " Function Ptr: %p\n " , record.Function .get ());
118
+ fprintf (stderr, " Flags.IsDistributed: %d\n " , record.Flags .isDistributed ());
119
+ ++count;
120
+ }
121
+ }
122
+ fprintf (stderr, " Record count: %d\n " , count);
123
+ fprintf (stderr, " ==== End of Accessible Function Records ====\n " );
124
+ }
125
+
101
126
static void _registerAccessibleFunctions (AccessibleFunctionsState &C,
102
127
AccessibleFunctionsSection section) {
103
128
C.SectionsToScan .push_back (section);
@@ -119,27 +144,6 @@ void swift::addImageAccessibleFunctionsBlockCallback(
119
144
addImageAccessibleFunctionsBlockCallbackUnsafe (baseAddress, functions, size);
120
145
}
121
146
122
- // TODO(distributed): expose dumping records via a flag
123
- LLVM_ATTRIBUTE_UNUSED
124
- static void _dumpAccessibleFunctionRecords () {
125
- auto &S = Functions.get ();
126
-
127
- fprintf (stderr, " ==== Accessible Function Records ====\n " );
128
- int count = 0 ;
129
- for (const auto §ion : S.SectionsToScan .snapshot ()) {
130
- for (auto &record : section) {
131
- auto recordName =
132
- swift::Demangle::makeSymbolicMangledNameStringRef (record.Name .get ());
133
- fprintf (stderr, " Record name: %s\n " , recordName.data ());
134
- fprintf (stderr, " Function Ptr: %p\n " , record.Function .get ());
135
- fprintf (stderr, " Flags.IsDistributed: %d\n " , record.Flags .isDistributed ());
136
- ++count;
137
- }
138
- }
139
- fprintf (stderr, " Record count: %d\n " , count);
140
- fprintf (stderr, " ==== End of Accessible Function Records ====\n " );
141
- }
142
-
143
147
static const AccessibleFunctionRecord *
144
148
_searchForFunctionRecord (AccessibleFunctionsState &S, llvm::StringRef name) {
145
149
auto traceState = runtime::trace::accessible_function_scan_begin (name);
@@ -160,13 +164,19 @@ const AccessibleFunctionRecord *
160
164
swift::runtime::swift_findAccessibleFunction (const char *targetNameStart,
161
165
size_t targetNameLength) {
162
166
auto &S = Functions.get ();
163
-
164
167
llvm::StringRef name{targetNameStart, targetNameLength};
168
+
169
+ if (swift::runtime::environment::SWIFT_DUMP_ACCESSIBLE_FUNCTIONS ()) {
170
+ static swift::once_t dumpAccessibleFunctionsToken;
171
+ swift::once (dumpAccessibleFunctionsToken, _dumpAccessibleFunctionRecords, nullptr );
172
+ }
173
+
165
174
// Look for an existing entry.
166
175
{
167
176
auto snapshot = S.Cache .snapshot ();
168
- if (auto E = snapshot.find (name))
177
+ if (auto E = snapshot.find (name)) {
169
178
return E->getRecord ();
179
+ }
170
180
}
171
181
172
182
// If entry doesn't exist (either record doesn't exist, hasn't been loaded, or
0 commit comments