Skip to content

Commit 85cc89e

Browse files
committed
Add log output
1 parent a729fe0 commit 85cc89e

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

Sources/IndexStoreDB/IndexStoreDB.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,28 @@ public final class IndexStoreDB {
9797
let delegateFunc = { [weak delegate] (event: indexstoredb_delegate_event_t) -> () in
9898
delegate?.handleEvent(event)
9999
}
100+
fputs("CP 1\n", stderr)
100101
let options = indexstoredb_creation_options_create()
102+
fputs("CP 2\n", stderr)
101103
defer { indexstoredb_creation_options_dispose(options) }
102104
indexstoredb_creation_options_use_explicit_output_units(options, useExplicitOutputUnits)
105+
fputs("CP 3\n", stderr)
103106
indexstoredb_creation_options_wait(options, wait)
107+
fputs("CP 4\n", stderr)
104108
indexstoredb_creation_options_readonly(options, readonly)
109+
fputs("CP 5\n", stderr)
105110
indexstoredb_creation_options_enable_out_of_date_file_watching(options, enableOutOfDateFileWatching)
111+
fputs("CP 6\n", stderr)
106112
indexstoredb_creation_options_listen_to_unit_events(options, listenToUnitEvents)
113+
fputs("CP 7\n", stderr)
107114
for mapping in prefixMappings {
108115
mapping.original.withCString { origCStr in
109116
mapping.replacement.withCString { remappedCStr in
110117
indexstoredb_creation_options_add_prefix_mapping(options, origCStr, remappedCStr)
111118
}
112119
}
113120
}
121+
fputs("CP 8\n", stderr)
114122

115123
var error: indexstoredb_error_t? = nil
116124
guard let index = indexstoredb_index_create(
@@ -121,6 +129,7 @@ public final class IndexStoreDB {
121129
defer { indexstoredb_error_dispose(error) }
122130
throw IndexStoreDBError.create(error?.description ?? "unknown")
123131
}
132+
fputs("CP 9\n", stderr)
124133

125134
impl = index
126135
}

lib/CIndexStoreDB/CIndexStoreDB.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,24 @@ indexstoredb_index_create(const char *storePath, const char *databasePath,
159159
indexstoredb_creation_options_t cOptions,
160160
indexstoredb_error_t *error) {
161161

162+
fputs("CP 8.1\n", stderr);
162163
auto delegate = std::make_shared<BlockIndexSystemDelegate>(delegateCallback);
163164
auto libProviderObj = std::make_shared<BlockIndexStoreLibraryProvider>(libProvider);
164165
auto options = static_cast<CreationOptions *>(cOptions);
165166

167+
fputs("CP 8.2\n", stderr);
166168
std::string errMsg;
167169
if (auto index =
168170
IndexSystem::create(storePath, databasePath, libProviderObj, delegate,
169171
*options, llvm::None, errMsg)) {
170-
172+
fputs("CP 8.3a\n", stderr);
171173
return make_object(index);
172174

173175
} else if (error) {
176+
fputs("CP 8.3b\n", stderr);
174177
*error = (indexstoredb_error_t)new IndexStoreDBError(errMsg);
175178
}
179+
fputs("CP 8.4\n", stderr);
176180
return nullptr;
177181
}
178182

lib/Database/Database.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ Database::Implementation::~Implementation() {
136136

137137
std::shared_ptr<Database::Implementation>
138138
Database::Implementation::create(StringRef path, bool readonly, Optional<size_t> initialDBSize, std::string &error) {
139+
fputs("CP 8.2.2.2.1.5.1\n", stderr);
139140
SmallString<10> versionStr;
140141
llvm::raw_svector_ostream(versionStr) << 'v' << Database::DATABASE_FORMAT_VERSION;
141142
SmallString<128> versionPath = path;
142143
llvm::sys::path::append(versionPath, versionStr);
143144

145+
fputs("CP 8.2.2.2.1.5.2\n", stderr);
144146
SmallString<128> savedPathBuf = versionPath;
145147
llvm::sys::path::append(savedPathBuf, "saved");
146148
SmallString<128> prefixPathBuf = versionPath;
@@ -153,6 +155,7 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
153155
SmallString<128> uniqueDirPath;
154156

155157
bool existingDB = true;
158+
fputs("CP 8.2.2.2.1.5.3\n", stderr);
156159

157160
auto createDirectoriesOrError = [&error](SmallVectorImpl<char> &path) {
158161
if (std::error_code ec = llvm::sys::fs::create_directories(path)) {
@@ -170,8 +173,10 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
170173
return false;
171174
};
172175

176+
fputs("CP 8.2.2.2.1.5.4\n", stderr);
173177
StringRef dbPath;
174178
if (!readonly) {
179+
fputs("CP 8.2.2.2.1.5.5a\n", stderr);
175180
if (createDirectoriesOrError(versionPath))
176181
return nullptr;
177182

@@ -189,25 +194,30 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
189194
}
190195
dbPath = uniqueDirPath;
191196
} else {
197+
fputs("CP 8.2.2.2.1.5.5b\n", stderr);
192198
dbPath = savedPathBuf;
193199
}
194200

195201
retry:
202+
fputs("CP 8.2.2.2.1.5.6\n", stderr);
196203
try {
204+
fputs("CP 8.2.2.2.1.5.7\n", stderr);
197205
auto db = std::make_shared<Database::Implementation>();
198206
db->IsReadOnly = readonly;
199207
db->VersionedPath = versionPath.str();
200208
db->SavedPath = savedPathBuf.str();
201209
db->UniquePath = uniqueDirPath.str();
202210
db->DBEnv = lmdb::env::create();
203211
db->DBEnv.set_max_dbs(14);
212+
fputs("CP 8.2.2.2.1.5.8\n", stderr);
204213

205214
uint64_t dbFileSize = 0;
206215
if (existingDB) {
207216
if (std::error_code ec = llvm::sys::fs::file_size(dbPath + "/data.mdb", dbFileSize)) {
208217
LOG_WARN_FUNC("failed reading database file size " << dbPath << "/data.mdb: " << ec.message());
209218
}
210219
}
220+
fputs("CP 8.2.2.2.1.5.9\n", stderr);
211221
// Start with 64MB.
212222
uint64_t initialSize = initialDBSize.getValueOr(64ULL*1024ULL*1024ULL);
213223

@@ -219,11 +229,14 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
219229
openflags |= MDB_RDONLY;
220230
db->DBEnv.open(dbPath, openflags);
221231
db->MaxKeySize = lmdb::env_get_max_keysize(db->DBEnv);
232+
fputs("CP 8.2.2.2.1.5.10\n", stderr);
222233

223234
unsigned txnflags = lmdb::txn::default_flags;
224235
if (readonly)
225236
txnflags |= MDB_RDONLY;
237+
fputs("CP 8.2.2.2.1.5.11\n", stderr);
226238
auto txn = lmdb::txn::begin(db->DBEnv, /*parent=*/nullptr, txnflags);
239+
fputs("CP 8.2.2.2.1.5.12\n", stderr);
227240
db->DBISymbolProvidersByUSR = lmdb::dbi::open(txn, "usrs", MDB_INTEGERKEY|MDB_DUPSORT|MDB_DUPFIXED|MDB_CREATE);
228241
db->DBISymbolProvidersByUSR.set_dupsort(txn, providersForUSR_compare);
229242
db->DBISymbolProviderNameByCode = lmdb::dbi::open(txn, "providers", MDB_INTEGERKEY|MDB_CREATE);
@@ -240,14 +253,19 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
240253
db->DBIUnitByUnitDependency = lmdb::dbi::open(txn, "unit-by-unit", MDB_INTEGERKEY|MDB_DUPSORT|MDB_DUPFIXED|MDB_INTEGERDUP|MDB_CREATE);
241254
db->DBITargetNameByCode = lmdb::dbi::open(txn, "target-names", MDB_INTEGERKEY|MDB_CREATE);
242255
db->DBIModuleNameByCode = lmdb::dbi::open(txn, "module-names", MDB_INTEGERKEY|MDB_CREATE);
256+
fputs("CP 8.2.2.2.1.5.13\n", stderr);
243257
txn.commit();
258+
fputs("CP 8.2.2.2.1.5.14\n", stderr);
244259

245260
db->cleanupDiscardedDBs();
261+
fputs("CP 8.2.2.2.1.5.15\n", stderr);
246262

247263
return db;
248264

249265
} catch (lmdb::error err) {
266+
fputs("CP 8.2.2.2.1.5.c.1\n", stderr);
250267
if (existingDB) {
268+
fputs("CP 8.2.2.2.1.5.c.2\n", stderr);
251269
// If opening an existing database fails, create a new database. This
252270
// prevents a corrupted database from preventing all progress.
253271

@@ -260,13 +278,16 @@ Database::Implementation::create(StringRef path, bool readonly, Optional<size_t>
260278
LOG_WARN_FUNC("failed opening database: " << err.description() << "\n"
261279
"corrupted database saved at '" << corruptedPathBuf << "'\n"
262280
"creating new database...");
281+
fputs("CP 8.2.2.2.1.5.c.3\n", stderr);
263282

264283
// Recreate the unique database path for the next attempt.
265284
if (!readonly && createUniqueDirOrError())
266285
return nullptr;
286+
fputs("CP 8.2.2.2.1.5.c.3\n", stderr);
267287
existingDB = false;
268288
goto retry;
269289
}
290+
fputs("CP 8.2.2.2.1.5.16\n", stderr);
270291
llvm::raw_string_ostream(error) << "failed opening database: " << err.description();
271292
return nullptr;
272293
}
@@ -436,29 +457,37 @@ void Database::Implementation::printStats(raw_ostream &OS) {
436457
// had the chance to close it.
437458
static std::shared_ptr<Database::Implementation>
438459
getLMDBDatabaseRefForPath(StringRef dbPath, bool readonly, Optional<size_t> initialDBSize, std::string &error) {
460+
fputs("CP 8.2.2.2.1.1\n", stderr);
439461
static llvm::sys::Mutex processDatabasesMtx;
440462
static llvm::StringMap<std::weak_ptr<Database::Implementation>> databasesByPath;
441463

442464
// Note that canonicalization of the path may result in different paths, if the
443465
// path doesn't exist yet vs the path exists. Use the path as given by the client.
444466

467+
fputs("CP 8.2.2.2.1.2\n", stderr);
445468
llvm::sys::ScopedLock L(processDatabasesMtx);
469+
fputs("CP 8.2.2.2.1.3\n", stderr);
446470
std::weak_ptr<Database::Implementation> &dbWeakRef = databasesByPath[dbPath];
471+
fputs("CP 8.2.2.2.1.4\n", stderr);
447472
if (auto dbRef = dbWeakRef.lock()) {
448473
return dbRef;
449474
}
475+
fputs("CP 8.2.2.2.1.5\n", stderr);
450476
auto dbRef = Database::Implementation::create(dbPath, readonly, initialDBSize, error);
477+
fputs("CP 8.2.2.2.1.6\n", stderr);
451478
if (!dbRef)
452479
return nullptr;
453480
dbWeakRef = dbRef;
454481
return dbRef;
455482
}
456483

457484
DatabaseRef Database::create(StringRef dbPath, bool readonly, Optional<size_t> initialDBSize, std::string &error) {
485+
fputs("CP 8.2.2.2.1\n", stderr);
458486
auto impl = getLMDBDatabaseRefForPath(dbPath, readonly, initialDBSize, error);
459487
if (!impl)
460488
return nullptr;
461489

490+
fputs("CP 8.2.2.2.2\n", stderr);
462491
auto db = std::make_shared<Database>();
463492
db->Impl = std::move(impl);
464493
return db;

lib/Index/IndexSystem.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,24 @@ bool IndexSystemImpl::init(StringRef StorePath,
253253
const CreationOptions &options,
254254
Optional<size_t> initialDBSize,
255255
std::string &Error) {
256+
fputs("CP 8.2.2.1\n", stderr);
256257
this->StorePath = StorePath;
257258
this->DBasePath = dbasePath;
258259
this->DelegateWrap = std::make_shared<AsyncIndexDelegate>(Delegate);
259260

261+
fputs("CP 8.2.2.2\n", stderr);
260262
auto dbase = db::Database::create(dbasePath, options.readonly, initialDBSize, Error);
261263
if (!dbase)
262264
return true;
263265

266+
fputs("CP 8.2.2.3\n", stderr);
264267
IndexStoreLibraryRef idxStoreLib = storeLibProvider->getLibraryForStorePath(StorePath);
265268
if (!idxStoreLib) {
266269
Error = "could not determine indexstore library";
267270
return true;
268271
}
269272

273+
fputs("CP 8.2.2.4\n", stderr);
270274
if (!options.readonly) {
271275
// Create the index store path, if it does not already exist.
272276
if (std::error_code EC = llvm::sys::fs::create_directories(StorePath)) {
@@ -275,23 +279,30 @@ bool IndexSystemImpl::init(StringRef StorePath,
275279
}
276280
}
277281

282+
fputs("CP 8.2.2.5\n", stderr);
278283
auto idxStore = indexstore::IndexStore::create(StorePath, idxStoreLib, options.indexStoreOptions, Error);
279284
if (!idxStore)
280285
return true;
281286

287+
fputs("CP 8.2.2.6\n", stderr);
282288
auto canonPathCache = std::make_shared<CanonicalPathCache>();
283289

290+
fputs("CP 8.2.2.7\n", stderr);
284291
this->VisibilityChecker = std::make_shared<FileVisibilityChecker>(dbase, canonPathCache, options.useExplicitOutputUnits);
292+
fputs("CP 8.2.2.8\n", stderr);
285293
this->SymIndex = std::make_shared<SymbolIndex>(dbase, idxStore, this->VisibilityChecker);
294+
fputs("CP 8.2.2.9\n", stderr);
286295
this->PathIndex = std::make_shared<FilePathIndex>(dbase, idxStore, this->VisibilityChecker,
287296
canonPathCache);
297+
fputs("CP 8.2.2.10\n", stderr);
288298
this->IndexStore = IndexDatastore::create(idxStore,
289299
this->SymIndex,
290300
this->DelegateWrap,
291301
canonPathCache,
292302
options,
293303
Error);
294304

305+
fputs("CP 8.2.2.11\n", stderr);
295306
if (!this->IndexStore)
296307
return true;
297308
return false;
@@ -661,14 +672,20 @@ IndexSystem::create(StringRef StorePath,
661672
const CreationOptions &options,
662673
Optional<size_t> initialDBSize,
663674
std::string &Error) {
675+
fputs("CP 8.2.1\n", stderr);
664676
std::unique_ptr<IndexSystemImpl> Impl(new IndexSystemImpl());
677+
fputs("CP 8.2.2\n", stderr);
665678
bool Err = Impl->init(StorePath, dbasePath, std::move(storeLibProvider), std::move(Delegate),
666679
options, initialDBSize, Error);
680+
fputs("CP 8.2.3\n", stderr);
667681
if (Err)
668682
return nullptr;
669683

684+
fputs("CP 8.2.4\n", stderr);
670685
std::shared_ptr<IndexSystem> Index;
686+
fputs("CP 8.2.5\n", stderr);
671687
Index.reset(new IndexSystem(Impl.release()));
688+
fputs("CP 8.2.6\n", stderr);
672689
return Index;
673690
}
674691

0 commit comments

Comments
 (0)