Skip to content

Commit c998ea3

Browse files
committed
[lldb][TypeSystemClang] Create FileIDs/SourceLocations from DWARF
1 parent 68b3890 commit c998ea3

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9945,3 +9945,33 @@ void TypeSystemClang::LogCreation() const {
99459945
LLDB_LOG(log, "Created new TypeSystem for (ASTContext*){0:x} '{1}'",
99469946
&getASTContext(), getDisplayName());
99479947
}
9948+
9949+
clang::SourceLocation TypeSystemClang::GetLocForDecl(const Declaration &decl) {
9950+
// If the Declaration is invalid there is nothing to do.
9951+
if (!decl.IsValid())
9952+
return {};
9953+
9954+
clang::SourceManager &sm = getASTContext().getSourceManager();
9955+
clang::FileManager &fm = sm.getFileManager();
9956+
9957+
auto fe = fm.getFileRef(decl.GetFile().GetPath());
9958+
if (!fe)
9959+
return {};
9960+
9961+
clang::FileID fid = sm.translateFile(*fe);
9962+
if (fid.isInvalid()) {
9963+
// We see the file for the first time, so create a dummy file for it now.
9964+
9965+
// Connect the new dummy file to the main file via some fake include
9966+
// location. This is necessary as all file's in the SourceManager need to be
9967+
// reachable via an include chain from the main file.
9968+
SourceLocation ToIncludeLocOrFakeLoc;
9969+
assert(sm.getMainFileID().isValid());
9970+
ToIncludeLocOrFakeLoc = sm.getLocForStartOfFile(sm.getMainFileID());
9971+
fid = sm.createFileID(*fe, ToIncludeLocOrFakeLoc, clang::SrcMgr::C_User);
9972+
}
9973+
9974+
// Clang requires column numbers to be >= 1..
9975+
return sm.translateLineCol(fid, decl.GetLine(),
9976+
std::max<uint16_t>(decl.GetColumn(), 1));
9977+
}

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,11 +1196,7 @@ class TypeSystemClang : public TypeSystem {
11961196
///
11971197
/// If no \c FileID could be found/created, returns an empty \c
11981198
/// SourceLocation.
1199-
///
1200-
/// FIXME: currently a no-op.
1201-
clang::SourceLocation GetLocForDecl(const lldb_private::Declaration &decl) {
1202-
return {};
1203-
}
1199+
clang::SourceLocation GetLocForDecl(const lldb_private::Declaration &decl);
12041200

12051201
// Classes that inherit from TypeSystemClang can see and modify these
12061202
std::string m_target_triple;

0 commit comments

Comments
 (0)