Skip to content

[lldb][SymbolFileDWARF] Fall back to using parent DW_AT_LLVM_include_path for submodules #142044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,17 +1188,25 @@ bool SymbolFileDWARF::ParseImportedModules(
SourceModule module;
module.path.push_back(ConstString(name));

const char *include_path = module_die.GetAttributeValueAsString(
DW_AT_LLVM_include_path, nullptr);
DWARFDIE parent_die = module_die;
while ((parent_die = parent_die.GetParent())) {
if (parent_die.Tag() != DW_TAG_module)
break;
if (const char *name =
parent_die.GetAttributeValueAsString(DW_AT_name, nullptr))
module.path.push_back(ConstString(name));

// Inferred submodule declarations may not have a
// DW_AT_LLVM_include_path. Pick the parent (aka umbrella) module's
// include path instead.
if (!include_path)
include_path = parent_die.GetAttributeValueAsString(
DW_AT_LLVM_include_path, nullptr);
}
std::reverse(module.path.begin(), module.path.end());
if (const char *include_path = module_die.GetAttributeValueAsString(
DW_AT_LLVM_include_path, nullptr)) {
if (include_path) {
FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
MakeAbsoluteAndRemap(include_spec, *dwarf_cu,
m_objfile_sp->GetModule());
Expand Down
4 changes: 4 additions & 0 deletions lldb/test/API/lang/cpp/decl-from-submodule/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS = $(MANDATORY_MODULE_BUILD_CFLAGS)

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Test that decl lookup into submodules in C++ works as expected."""

import lldb
import shutil

from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class DeclFromSubmoduleTestCase(TestBase):
def test_expr(self):
self.build()
lldbutil.run_to_source_breakpoint(self, "return 0", lldb.SBFileSpec("main.cpp"))

# FIXME: LLDB finds the decl for 'func' in the submodules correctly and hands it to Clang
# but Sema rejects using the decl during name lookup because it is not marked "Visible".
# However, this assertions still ensures that we at least don't fail to compile the
# submodule (which would cause other errors to appear before the expression error, hence
# we use "startstr").
self.expect(
"expr func(1, 2)",
error=True,
startstr="error: <user expression 0>:1:1: 'func' has unknown return type",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// nodebug to force LLDB to find the decls in modules
[[gnu::nodebug]] inline int func(int x) { return x; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// nodebug to force LLDB to find the decls in modules
[[gnu::nodebug]] inline int func(int x, int y) { return x + y; }
9 changes: 9 additions & 0 deletions lldb/test/API/lang/cpp/decl-from-submodule/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "TopLevel/module1.h"
#include "TopLevel/module2.h"

int main() {
func(1);
func(2, 3);

return 0;
}
6 changes: 6 additions & 0 deletions lldb/test/API/lang/cpp/decl-from-submodule/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module TopLevel {
umbrella "TopLevel"
explicit module * {
export *
}
}
Loading