Skip to content

Commit c5b4cb6

Browse files
committed
quick fixes for the Rust plugin
Whis brings back compilability and linking but there are aa bunch of holes, so probably tests won't pass any more. I shall revisit.
1 parent b1fa644 commit c5b4cb6

File tree

9 files changed

+319
-145
lines changed

9 files changed

+319
-145
lines changed

lldb/include/lldb/Symbol/RustASTContext.h

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class RustDeclContext;
3131
class RustType;
3232

3333
class RustASTContext : public TypeSystem {
34+
// LLVM RTTI support
35+
static char ID;
36+
3437
public:
3538
RustASTContext();
3639
~RustASTContext() override;
@@ -47,10 +50,6 @@ class RustASTContext : public TypeSystem {
4750
static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
4851
Module *module, Target *target);
4952

50-
static void EnumerateSupportedLanguages(
51-
std::set<lldb::LanguageType> &languages_for_types,
52-
std::set<lldb::LanguageType> &languages_for_expressions);
53-
5453
static void Initialize();
5554

5655
static void Terminate();
@@ -62,17 +61,16 @@ class RustASTContext : public TypeSystem {
6261
//------------------------------------------------------------------
6362
// llvm casting support
6463
//------------------------------------------------------------------
65-
static bool classof(const TypeSystem *ts) {
66-
return ts->getKind() == TypeSystem::eKindRust;
67-
}
64+
bool isA(const void *ClassID) const override { return ClassID == &ID; }
65+
static bool classof(const TypeSystem *ts) { return ts->isA(&ID); }
6866

6967
//----------------------------------------------------------------------
7068
// CompilerDecl functions
7169
//----------------------------------------------------------------------
7270
ConstString DeclGetName(void *opaque_decl) override;
7371
ConstString DeclGetMangledName(void *opaque_decl) override;
7472
CompilerDeclContext DeclGetDeclContext(void *opaque_decl) override;
75-
73+
CompilerType GetTypeForDecl(void *opaque_decl) override;
7674

7775
//----------------------------------------------------------------------
7876
// CompilerDeclContext functions
@@ -81,12 +79,14 @@ class RustASTContext : public TypeSystem {
8179
std::vector<CompilerDecl>
8280
DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name,
8381
const bool ignore_imported_decls) override;
84-
bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) override;
82+
/// bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) override;
8583
ConstString DeclContextGetName(void *opaque_decl_ctx) override;
8684
ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override;
8785
bool DeclContextIsClassMethod(void *opaque_decl_ctx, lldb::LanguageType *language_ptr,
8886
bool *is_instance_method_ptr,
8987
ConstString *language_object_name_ptr) override;
88+
bool DeclContextIsContainedInLookup(void *opaque_decl_ctx,
89+
void *other_opaque_decl_ctx) override;
9090

9191
//----------------------------------------------------------------------
9292
// Creating Types
@@ -195,6 +195,8 @@ class RustASTContext : public TypeSystem {
195195

196196
bool SupportsLanguage(lldb::LanguageType language) override;
197197

198+
bool CanPassInRegisters(const CompilerType &type) override;
199+
198200
//----------------------------------------------------------------------
199201
// Type Completion
200202
//----------------------------------------------------------------------
@@ -256,16 +258,20 @@ class RustASTContext : public TypeSystem {
256258
// Exploring the type
257259
//----------------------------------------------------------------------
258260

259-
uint64_t GetBitSize(lldb::opaque_compiler_type_t type,
260-
ExecutionContextScope *exe_scope) override;
261+
const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) override;
262+
263+
llvm::Optional<uint64_t>
264+
GetBitSize(lldb::opaque_compiler_type_t type,
265+
ExecutionContextScope *exe_scope) override;
261266

262267
lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
263268
uint64_t &count) override;
264269

265270
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
266271

267272
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
268-
bool omit_empty_base_classes) override;
273+
bool omit_empty_base_classes,
274+
const ExecutionContext*) override;
269275

270276
lldb::BasicType
271277
GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override;
@@ -334,6 +340,12 @@ class RustASTContext : public TypeSystem {
334340
//----------------------------------------------------------------------
335341
// Dumping types
336342
//----------------------------------------------------------------------
343+
#ifndef NDEBUG
344+
/// Convenience LLVM-style dump method for use in the debugger only.
345+
LLVM_DUMP_METHOD void
346+
dump(lldb::opaque_compiler_type_t type) const override;
347+
#endif
348+
337349
void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
338350
Stream *s, lldb::Format format, const DataExtractor &data,
339351
lldb::offset_t data_offset, size_t data_byte_size,
@@ -361,9 +373,9 @@ class RustASTContext : public TypeSystem {
361373

362374
// Converts "s" to a floating point value and place resulting floating
363375
// point bytes in the "dst" buffer.
364-
size_t ConvertStringToFloatValue(lldb::opaque_compiler_type_t type,
376+
/*size_t ConvertStringToFloatValue(lldb::opaque_compiler_type_t type,
365377
const char *s, uint8_t *dst,
366-
size_t dst_size) override;
378+
size_t dst_size) override;*/
367379

368380
bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type,
369381
CompilerType *pointee_type = nullptr) override;
@@ -373,7 +385,9 @@ class RustASTContext : public TypeSystem {
373385
bool IsCStringType(lldb::opaque_compiler_type_t type,
374386
uint32_t &length) override;
375387

376-
size_t GetTypeBitAlign(lldb::opaque_compiler_type_t type) override;
388+
virtual llvm::Optional<size_t>
389+
GetTypeBitAlign(lldb::opaque_compiler_type_t type,
390+
ExecutionContextScope*) override;
377391

378392
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override;
379393

@@ -455,7 +469,8 @@ class RustASTContextForExpr : public RustASTContext {
455469
GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
456470
lldb::LanguageType language,
457471
Expression::ResultType desired_type,
458-
const EvaluateExpressionOptions &options) override;
472+
const EvaluateExpressionOptions &options,
473+
ValueObject *ctx_obj) override;
459474

460475
private:
461476
lldb::TargetWP m_target_wp;

lldb/source/Plugins/ExpressionParser/Rust/RustAST.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class RustTupleFieldExpression : public RustExpression {
389389
private:
390390

391391
void print(Stream &stream) override {
392-
stream << m_left << "." << int(m_field);
392+
// FOR NOW stream << m_left << "." << int(m_field);
393393
}
394394

395395
RustExpressionUP m_left;
@@ -721,7 +721,7 @@ class RustArrayTypeExpression : public RustTypeExpression {
721721
}
722722

723723
void print(Stream &stream) override {
724-
stream << "[" << m_element << "; " << int64_t(m_len) << "]";
724+
// FOR NOW stream << "[" << m_element << "; " << int64_t(m_len) << "]";
725725
}
726726

727727
CompilerType Evaluate(ExecutionContext &exe_ctx, Status &error) override;

lldb/source/Plugins/ExpressionParser/Rust/RustFunctionCaller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ unsigned RustFunctionCaller::CompileFunction(lldb::ThreadSP thread_to_use_sp,
188188
if (jit_process_sp) {
189189
m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this, true));
190190

191-
num_errors = m_parser->Parse(diagnostic_manager);
191+
num_errors = static_cast<ClangExpressionParser&>(*m_parser).Parse(diagnostic_manager);
192192
} else {
193193
diagnostic_manager.PutString(eDiagnosticSeverityError,
194194
"no process - unable to inject function");

lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ GetASTContext(ValueObjectSP val, Status &error) {
5555
static RustASTContext *
5656
GetASTContext(ExecutionContext &ctxt, Status &error) {
5757
Target *target = ctxt.GetTargetPtr();
58-
TypeSystem *sys = target->GetScratchTypeSystemForLanguage(&error, eLanguageTypeRust);
59-
if (!sys) {
58+
auto sys = target->GetScratchTypeSystemForLanguage(eLanguageTypeRust);
59+
if (!sys) {
6060
return nullptr;
6161
}
62-
RustASTContext *result = llvm::dyn_cast_or_null<RustASTContext>(sys);
62+
auto *result = llvm::dyn_cast_or_null<RustASTContext>(&sys.get());
6363
if (!result) {
6464
error.SetErrorString("not a Rust type!?");
6565
}
@@ -69,7 +69,7 @@ GetASTContext(ExecutionContext &ctxt, Status &error) {
6969
static ValueObjectSP
7070
CreateValueFromScalar(ExecutionContext &exe_ctx, Scalar &scalar, CompilerType type,
7171
Status &error) {
72-
DataExtractor data;
72+
lldb_private::DataExtractor data;
7373
if (!scalar.GetData(data)) {
7474
error.SetErrorString("could not get data from scalar");
7575
return ValueObjectSP();
@@ -89,7 +89,7 @@ CreateValueInMemory(ExecutionContext &exe_ctx, CompilerType type, Status &error)
8989
}
9090

9191
Process *proc = exe_ctx.GetProcessPtr();
92-
uint64_t size = type.GetByteSize(proc);
92+
uint64_t size = *type.GetByteSize(proc);
9393
addr_t addr = proc->AllocateMemory(size,
9494
lldb::ePermissionsWritable | lldb::ePermissionsReadable,
9595
error);
@@ -103,7 +103,7 @@ CreateValueInMemory(ExecutionContext &exe_ctx, CompilerType type, Status &error)
103103
static bool
104104
SetField(const ValueObjectSP &object, const char *name, uint64_t value, Status &error) {
105105
Scalar scalar(value);
106-
DataExtractor data;
106+
lldb_private::DataExtractor data;
107107
if (!scalar.GetData(data)) {
108108
error.SetErrorString("could not get data from scalar");
109109
return false;
@@ -120,7 +120,7 @@ SetField(const ValueObjectSP &object, const char *name, uint64_t value, Status &
120120
static bool
121121
SetField(const ValueObjectSP &object, const char *name, const ValueObjectSP &value,
122122
Status &error) {
123-
DataExtractor data;
123+
lldb_private::DataExtractor data;
124124
if (!value->GetData(data, error)) {
125125
return false;
126126
}
@@ -141,12 +141,11 @@ GetTypeByName(ExecutionContext &exe_ctx, const char *name, Status &error) {
141141
return CompilerType();
142142
}
143143

144-
SymbolContext sc;
145144
TypeList type_list;
146145
llvm::DenseSet<SymbolFile *> searched_symbol_files;
147-
uint32_t num_matches = target->GetImages().FindTypes(sc, ConstString(name), true,
148-
2, searched_symbol_files, type_list);
149-
if (num_matches > 0) {
146+
target->GetImages().FindTypes(nullptr, ConstString(name), true,
147+
2, searched_symbol_files, type_list);
148+
if (type_list.GetSize() > 0) {
150149
return type_list.GetTypeAtIndex(0)->GetFullCompilerType();
151150
}
152151
error.SetErrorStringWithFormat("could not find type \"%s\"", name);
@@ -291,7 +290,7 @@ lldb_private::rust::BinaryOperation (ExecutionContext &exe_ctx, lldb::ValueObjec
291290
type = ast->CreateFloatType(ConstString("f64"), byte_size);
292291
break;
293292
}
294-
/* FALL THROUGH */
293+
LLVM_FALLTHROUGH;
295294

296295
default:
297296
error.SetErrorString("unknown type resulting from binary operation");
@@ -301,7 +300,7 @@ lldb_private::rust::BinaryOperation (ExecutionContext &exe_ctx, lldb::ValueObjec
301300
ValueObjectSP result_obj = CreateValueFromScalar(exe_ctx, result, type, error);
302301

303302
if (ASSIGN) {
304-
DataExtractor data;
303+
lldb_private::DataExtractor data;
305304
result_obj->GetData(data, error);
306305
if (error.Fail()) {
307306
return ValueObjectSP();
@@ -509,7 +508,7 @@ RustPath::FindDecl(ExecutionContext &exe_ctx, Status &error,
509508
const ModuleList &module_list = target->GetImages();
510509
module_list.ForEach(
511510
[&](const ModuleSP &mod) {
512-
TypeSystem *ts = mod->GetTypeSystemForLanguage(eLanguageTypeRust);
511+
auto ts = mod->GetTypeSystemForLanguage(eLanguageTypeRust);
513512
if (!ts) {
514513
return true;
515514
}
@@ -521,7 +520,7 @@ RustPath::FindDecl(ExecutionContext &exe_ctx, Status &error,
521520
SymbolContext null_sc;
522521
CompilerDeclContext found_ns;
523522
for (const ConstString &ns_name : fullname) {
524-
found_ns = symbol_file->FindNamespace(null_sc, ns_name, &found_ns);
523+
found_ns = symbol_file->FindNamespace(ns_name, &found_ns);
525524
if (!found_ns) {
526525
break;
527526
}
@@ -532,7 +531,7 @@ RustPath::FindDecl(ExecutionContext &exe_ctx, Status &error,
532531

533532
SymbolContextList context_list;
534533
mod->FindFunctions(cs_name, &found_ns, eFunctionNameTypeBase, false, false,
535-
true, context_list);
534+
context_list);
536535
for (size_t i = 0; i < context_list.GetSize(); ++i) {
537536
SymbolContext sym_context;
538537
if (context_list.GetContextAtIndex(i, sym_context) && sym_context.function) {
@@ -660,7 +659,7 @@ RustStringLiteral::Evaluate(ExecutionContext &exe_ctx, Status &error) {
660659
}
661660

662661
// Byte order and address size don't matter here.
663-
DataExtractor data(m_value.c_str(), m_value.size(), eByteOrderInvalid, 4);
662+
lldb_private::DataExtractor data(m_value.c_str(), m_value.size(), eByteOrderInvalid, 4);
664663
ValueObjectSP array = CreateValueInMemory(exe_ctx, array_type, error);
665664
if (!array) {
666665
return array;
@@ -866,7 +865,7 @@ RustAssignment::Evaluate(ExecutionContext &exe_ctx, Status &error) {
866865
return right;
867866
}
868867

869-
DataExtractor data;
868+
lldb_private::DataExtractor data;
870869
right->GetData(data, error);
871870
if (error.Fail()) {
872871
return ValueObjectSP();
@@ -917,13 +916,13 @@ RustArrayWithLength::Evaluate(ExecutionContext &exe_ctx, Status &error) {
917916
return ValueObjectSP();
918917
}
919918

920-
DataExtractor data;
919+
lldb_private::DataExtractor data;
921920
value->GetData(data, error);
922921
if (error.Fail()) {
923922
return ValueObjectSP();
924923
}
925924

926-
DataExtractor array_contents;
925+
lldb_private::DataExtractor array_contents;
927926
for (unsigned i = 0; i < slength.UInt(); ++i) {
928927
if (!array_contents.Append(data)) {
929928
error.SetErrorString("could not create array contents");
@@ -983,7 +982,7 @@ RustCall::MaybeEvalTupleStruct(ExecutionContext &exe_ctx, Status &error) {
983982
return init_val;
984983
}
985984

986-
DataExtractor data;
985+
lldb_private::DataExtractor data;
987986
if (!init_val->GetData(data, error)) {
988987
error.SetErrorString("could not get data from value");
989988
return ValueObjectSP();
@@ -1075,7 +1074,7 @@ RustCall::Evaluate(ExecutionContext &exe_ctx, Status &error) {
10751074
return ValueObjectSP();
10761075
}
10771076

1078-
DataExtractor data;
1077+
lldb_private::DataExtractor data;
10791078
if (!results.GetData(data)) {
10801079
error.SetErrorString("could not extract return value");
10811080
return ValueObjectSP();
@@ -1134,7 +1133,7 @@ RustStructExpression::Evaluate(ExecutionContext &exe_ctx, Status &error) {
11341133
return copy;
11351134
}
11361135

1137-
DataExtractor data;
1136+
lldb_private::DataExtractor data;
11381137
copy->GetData(data, error);
11391138
if (error.Fail()) {
11401139
return ValueObjectSP();

0 commit comments

Comments
 (0)