Skip to content

Commit

Permalink
Merge pull request llvm#4 from cuviper/rust-lldb-fixes
Browse files Browse the repository at this point in the history
[rust-lldb] Adapt to changes in LLDB APIs
  • Loading branch information
cuviper committed Jan 24, 2019
2 parents bf94cf8 + f3baeb6 commit 683d352
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
8 changes: 3 additions & 5 deletions lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ CreateValueInMemory(ExecutionContext &exe_ctx, CompilerType type, Status &error)
}

Process *proc = exe_ctx.GetProcessPtr();
uint64_t size = type.GetByteSize(proc);
uint64_t size = type.GetByteSize(proc).getValueOr(0);
addr_t addr = proc->AllocateMemory(size,
lldb::ePermissionsWritable | lldb::ePermissionsReadable,
error);
Expand Down Expand Up @@ -141,10 +141,9 @@ GetTypeByName(ExecutionContext &exe_ctx, const char *name, Status &error) {
return CompilerType();
}

SymbolContext sc;
TypeList type_list;
llvm::DenseSet<SymbolFile *> searched_symbol_files;
uint32_t num_matches = target->GetImages().FindTypes(sc, ConstString(name), true,
uint32_t num_matches = target->GetImages().FindTypes(nullptr, ConstString(name), true,
2, searched_symbol_files, type_list);
if (num_matches > 0) {
return type_list.GetTypeAtIndex(0)->GetFullCompilerType();
Expand Down Expand Up @@ -518,10 +517,9 @@ RustPath::FindDecl(ExecutionContext &exe_ctx, Status &error,
return true;
}

SymbolContext null_sc;
CompilerDeclContext found_ns;
for (const ConstString &ns_name : fullname) {
found_ns = symbol_file->FindNamespace(null_sc, ns_name, &found_ns);
found_ns = symbol_file->FindNamespace(ns_name, &found_ns);
if (!found_ns) {
break;
}
Expand Down
30 changes: 21 additions & 9 deletions lldb/source/Symbol/RustASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class RustCLikeEnum : public RustType {
}

uint64_t ByteSize() const override {
return m_underlying_type.GetByteSize(nullptr);
return m_underlying_type.GetByteSize(nullptr).getValueOr(0);
}

bool IsSigned() const {
Expand Down Expand Up @@ -337,7 +337,7 @@ class RustArray : public RustType {
}

uint64_t ByteSize() const override {
return m_elem.GetByteSize(nullptr) * m_length;
return m_elem.GetByteSize(nullptr).getValueOr(0) * m_length;
}

std::string GetCABITypeDeclaration(RustASTContext::TypeNameMap *name_map,
Expand Down Expand Up @@ -804,7 +804,7 @@ class RustTypedef : public RustType {
}

uint64_t ByteSize() const override {
return m_type.GetByteSize(nullptr);
return m_type.GetByteSize(nullptr).getValueOr(0);
}

std::string GetCABITypeDeclaration(RustASTContext::TypeNameMap *name_map,
Expand Down Expand Up @@ -1266,7 +1266,7 @@ RustASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type,
RustArray *array = static_cast<RustType *>(type)->AsArray();
if (array) {
if (stride) {
*stride = array->ElementType().GetByteSize(nullptr);
*stride = array->ElementType().GetByteSize(nullptr).getValueOr(0);
}
return array->ElementType();
}
Expand Down Expand Up @@ -1499,8 +1499,11 @@ CompilerType RustASTContext::GetChildCompilerTypeAtIndex(
uint64_t bit_offset;
CompilerType ret =
GetFieldAtIndex(type, idx, child_name, &bit_offset, nullptr, nullptr);
child_byte_size = ret.GetByteSize(
llvm::Optional<uint64_t> size = ret.GetByteSize(
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
if (!size)
return {};
child_byte_size = *size;
child_byte_offset = bit_offset / 8;
return ret;
} else if (RustPointer *ptr = t->AsPointer()) {
Expand All @@ -1525,8 +1528,11 @@ CompilerType RustASTContext::GetChildCompilerTypeAtIndex(

// We have a pointer to an simple type
if (idx == 0 && pointee.GetCompleteType()) {
child_byte_size = pointee.GetByteSize(
llvm::Optional<uint64_t> size = pointee.GetByteSize(
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
if (!size)
return {};
child_byte_size = *size;
child_byte_offset = 0;
return pointee;
}
Expand All @@ -1538,8 +1544,11 @@ CompilerType RustASTContext::GetChildCompilerTypeAtIndex(
char element_name[64];
::snprintf(element_name, sizeof(element_name), "[%zu]", idx);
child_name.assign(element_name);
child_byte_size = element_type.GetByteSize(
llvm::Optional<uint64_t> size = element_type.GetByteSize(
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
if (!size)
return {};
child_byte_size = *size;
child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
return element_type;
}
Expand Down Expand Up @@ -1634,14 +1643,17 @@ bool RustASTContext::DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s,
CompilerType typedef_compiler_type = typ->UnderlyingType();
if (format == eFormatDefault)
format = typedef_compiler_type.GetFormat();
uint64_t typedef_byte_size = typedef_compiler_type.GetByteSize(exe_scope);
llvm::Optional<uint64_t> typedef_byte_size =
typedef_compiler_type.GetByteSize(exe_scope);
if (!typedef_byte_size)
return false;

return typedef_compiler_type.DumpTypeValue(
s,
format, // The format with which to display the element
data, // Data buffer containing all bytes for this type
byte_offset, // Offset into "data" where to grab value from
typedef_byte_size, // Size of this type in bytes
*typedef_byte_size,// Size of this type in bytes
bitfield_bit_size, // Size in bits of a bitfield value, if zero don't
// treat as a bitfield
bitfield_bit_offset, // Offset in bits of a bitfield value if
Expand Down

0 comments on commit 683d352

Please sign in to comment.