Skip to content

Commit 0768e1e

Browse files
debug: Add trace logging to identify out-of-project files (#409)
When investigating a customer issue, we're running into a mysterious bug where seemingly in-project files are being considered out-of-project. We add support for a 'trace' logging level to debug this issue, as this logging shouldn't be needed for most debugging cases. The trace logging level is not yet documented as we may remove it later.
1 parent 631baed commit 0768e1e

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

indexer/IdPathMappings.cc

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "indexer/FileMetadata.h"
1212
#include "indexer/Hash.h"
1313
#include "indexer/IdPathMappings.h"
14+
#include "indexer/LlvmAdapter.h"
1415
#include "indexer/Path.h"
1516

1617
namespace scip_clang {
@@ -127,14 +128,43 @@ bool FileMetadataMap::insert(clang::FileID fileId, AbsolutePathRef absPathRef) {
127128
// projectRoot / relativePath exists, but is actually a symlink to
128129
// inside the build root, rather than an in-project file. So check that
129130
// that real_path is the same.
130-
if (!error && realPath.str() == originalFileSourcePath.asStringRef()) {
131-
return insertRelPath(RootRelativePathRef(buildRootRelPath->asStringView(),
132-
RootKind::Project),
133-
/*isInProject*/ true);
131+
if (!error) {
132+
if (realPath.str() == originalFileSourcePath.asStringRef()) {
133+
return insertRelPath(
134+
RootRelativePathRef(buildRootRelPath->asStringView(),
135+
RootKind::Project),
136+
/*isInProject*/ true);
137+
} else {
138+
spdlog::trace("projectRoot.join(relativePath (= '{}'/'{}')) exists but "
139+
"the real path is '{}",
140+
this->projectRootPath.asRef().asStringView(),
141+
buildRootRelPath->asStringView(),
142+
llvm_ext::toStringView(realPath.str()));
143+
}
144+
} else if (error == std::errc::no_such_file_or_directory) {
145+
spdlog::trace(
146+
"failed to find file in project at '{}' (root: '{}', rel: '{}')",
147+
originalFileSourcePath.asStringRef(),
148+
this->projectRootPath.asRef().asStringView(),
149+
buildRootRelPath->asStringView());
150+
} else {
151+
spdlog::trace("hit error: {} when getting real path for {}",
152+
error.message(), originalFileSourcePath.asStringRef());
134153
}
135154
} else if (auto optProjectRootRelPath =
136155
this->projectRootPath.tryMakeRelative(absPathRef)) {
137156
return insertRelPath(optProjectRootRelPath.value(), /*isInProject*/ true);
157+
} else {
158+
if ((spdlog::default_logger_raw()->level() <= spdlog::level::trace)
159+
&& (absPathRef.asStringView().find("usr/include") == std::string::npos)
160+
&& (absPathRef.asStringView().find("usr/lib/clang")
161+
== std::string::npos)) {
162+
spdlog::trace(
163+
"path {} is neither inside project root {} nor inside build root {}",
164+
absPathRef.asStringView(),
165+
this->projectRootPath.asRef().asStringView(),
166+
this->buildRootPath.asRef().asStringView());
167+
}
138168
}
139169

140170
auto optFileName = absPathRef.fileName();

indexer/main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ static scip_clang::CliOptions parseArguments(int argc, char *argv[]) {
179179
cliOptions.showProgress = result.count("no-progress-report") == 0;
180180

181181
auto level = result["log-level"].as<std::string>();
182-
if (level == "debug") {
182+
if (level == "trace") {
183+
cliOptions.logLevel = spdlog::level::level_enum::trace;
184+
} else if (level == "debug") {
183185
cliOptions.logLevel = spdlog::level::level_enum::debug;
184186
} else if (level == "info") {
185187
cliOptions.logLevel = spdlog::level::level_enum::info;

0 commit comments

Comments
 (0)