[Lldb-commits] [lldb] [LLDB] Add type casting to DIL. (PR #159500)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 19 10:29:23 PDT 2025
================
@@ -42,6 +44,83 @@ DILDiagnosticError::DILDiagnosticError(llvm::StringRef expr,
m_detail.rendered = std::move(rendered_msg);
}
+llvm::Expected<lldb::TypeSystemSP>
+DILGetTypeSystemFromCU(std::shared_ptr<StackFrame> ctx) {
+ SymbolContext symbol_context =
+ ctx->GetSymbolContext(lldb::eSymbolContextCompUnit);
+ lldb::LanguageType language = symbol_context.comp_unit->GetLanguage();
+
+ symbol_context = ctx->GetSymbolContext(lldb::eSymbolContextModule);
+ return symbol_context.module_sp->GetTypeSystemForLanguage(language);
+}
+
+CompilerType
+ResolveTypeByName(const std::string &name,
+ std::shared_ptr<ExecutionContextScope> ctx_scope) {
+ // Internally types don't have global scope qualifier in their names and
+ // LLDB doesn't support queries with it too.
+ llvm::StringRef name_ref(name);
+
+ if (name_ref.starts_with("::"))
+ name_ref = name_ref.drop_front(2);
+
+ std::vector<CompilerType> result_type_list;
+ lldb::TargetSP target_sp = ctx_scope->CalculateTarget();
+ const char *type_name = name_ref.data();
+ if (type_name && type_name[0] && target_sp) {
+ ModuleList &images = target_sp->GetImages();
+ ConstString const_type_name(type_name);
+ TypeQuery query(type_name);
+ TypeResults results;
+ images.FindTypes(nullptr, query, results);
+ for (const lldb::TypeSP &type_sp : results.GetTypeMap().Types())
+ if (type_sp)
+ result_type_list.push_back(type_sp->GetFullCompilerType());
+
+ if (auto process_sp = target_sp->GetProcessSP()) {
+ for (auto *runtime : process_sp->GetLanguageRuntimes()) {
+ if (auto *vendor = runtime->GetDeclVendor()) {
+ auto types = vendor->FindTypes(const_type_name, UINT32_MAX);
+ for (auto type : types)
+ result_type_list.push_back(type);
+ }
+ }
+ }
+
+ if (result_type_list.empty()) {
+ for (auto type_system_sp : target_sp->GetScratchTypeSystems())
+ if (auto compiler_type =
+ type_system_sp->GetBuiltinTypeByName(const_type_name))
+ result_type_list.push_back(compiler_type);
+ }
----------------
kuilpd wrote:
This should be the first step before everything else, and use `DILGetTypeSystemFromCU` as well
```
auto type_system = DILGetTypeSystemFromCU(ctx_scope);
if (!type_system)
return {};
CompilerType type = type_system.get()->GetBuiltinTypeByName(ConstString(const_type_name));
```
https://github.com/llvm/llvm-project/pull/159500
More information about the lldb-commits
mailing list