From 9e6819d920756e287b6f060c81d9235d54524302 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 24 Jan 2019 10:27:54 -0800 Subject: [PATCH 1/3] [rust-lldb] CompilerType::GetByteSize() now returns an optional Reference: https://reviews.llvm.org/D56688 --- .../ExpressionParser/Rust/RustParse.cpp | 2 +- lldb/source/Symbol/RustASTContext.cpp | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp b/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp index 671429977cd57..6d64ab5e27a7f 100644 --- a/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp +++ b/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp @@ -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); diff --git a/lldb/source/Symbol/RustASTContext.cpp b/lldb/source/Symbol/RustASTContext.cpp index 1dcafa8b0f8cf..6adf144db6533 100644 --- a/lldb/source/Symbol/RustASTContext.cpp +++ b/lldb/source/Symbol/RustASTContext.cpp @@ -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 { @@ -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, @@ -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, @@ -1266,7 +1266,7 @@ RustASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type, RustArray *array = static_cast(type)->AsArray(); if (array) { if (stride) { - *stride = array->ElementType().GetByteSize(nullptr); + *stride = array->ElementType().GetByteSize(nullptr).getValueOr(0); } return array->ElementType(); } @@ -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 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()) { @@ -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 size = pointee.GetByteSize( exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); + if (!size) + return {}; + child_byte_size = *size; child_byte_offset = 0; return pointee; } @@ -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 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; } @@ -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 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 From 6f74a0ba50c3caf9ba769d78b4cceb2d4cb89c10 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 24 Jan 2019 10:31:08 -0800 Subject: [PATCH 2/3] [rust-lldb] FindNamespace no longer takes a SymbolContext Reference: https://reviews.llvm.org/rLLDB351132 --- lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp b/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp index 6d64ab5e27a7f..9dc6de2ddab4b 100644 --- a/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp +++ b/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp @@ -518,10 +518,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; } From f3baeb6bcc7f3a1af373026d5579dc5727dbaa67 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 24 Jan 2019 10:32:48 -0800 Subject: [PATCH 3/3] [rust-lldb] FindTypes no longer takes a SymbolContext Reference: https://reviews.llvm.org/rLLDB351133 --- lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp b/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp index 9dc6de2ddab4b..c9d3ab92b19f7 100644 --- a/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp +++ b/lldb/source/Plugins/ExpressionParser/Rust/RustParse.cpp @@ -141,10 +141,9 @@ GetTypeByName(ExecutionContext &exe_ctx, const char *name, Status &error) { return CompilerType(); } - SymbolContext sc; TypeList type_list; llvm::DenseSet 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();