summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/minidump
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-04-09 08:28:27 +0000
committerPavel Labath <pavel@labath.sk>2019-04-09 08:28:27 +0000
commitff12913b638e58b7a64d7ad819bac4367f49bc3f (patch)
treeef8e568d654cd7106e36cb8e1b4b6c4e3f1691f0 /lldb/source/Plugins/Process/minidump
parentc60d09597c6bf7fac3db64f0ebf7d408607aa15a (diff)
downloadbcm5719-llvm-ff12913b638e58b7a64d7ad819bac4367f49bc3f.tar.gz
bcm5719-llvm-ff12913b638e58b7a64d7ad819bac4367f49bc3f.zip
Minidump: use string parsing functionality from llvm
llvm-svn: 357977
Diffstat (limited to 'lldb/source/Plugins/Process/minidump')
-rw-r--r--lldb/source/Plugins/Process/minidump/MinidumpParser.cpp42
-rw-r--r--lldb/source/Plugins/Process/minidump/MinidumpParser.h2
-rw-r--r--lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp37
-rw-r--r--lldb/source/Plugins/Process/minidump/MinidumpTypes.h5
-rw-r--r--lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp38
5 files changed, 30 insertions, 94 deletions
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index 605e56e0529..d4d29f2ee45 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -63,14 +63,6 @@ llvm::ArrayRef<uint8_t> MinidumpParser::GetStream(StreamType stream_type) {
.getValueOr(llvm::ArrayRef<uint8_t>());
}
-llvm::Optional<std::string> MinidumpParser::GetMinidumpString(uint32_t rva) {
- auto arr_ref = m_data_sp->GetData();
- if (rva > arr_ref.size())
- return llvm::None;
- arr_ref = arr_ref.drop_front(rva);
- return parseMinidumpString(arr_ref);
-}
-
UUID MinidumpParser::GetModuleUUID(const MinidumpModule *module) {
auto cv_record =
GetData().slice(module->CV_record.RVA, module->CV_record.DataSize);
@@ -244,13 +236,17 @@ ArchSpec MinidumpParser::GetArchitecture() {
break;
default: {
triple.setOS(llvm::Triple::OSType::UnknownOS);
- std::string csd_version;
- if (auto s = GetMinidumpString(system_info->CSDVersionRVA))
- csd_version = *s;
- if (csd_version.find("Linux") != std::string::npos)
- triple.setOS(llvm::Triple::OSType::Linux);
- break;
+ auto ExpectedCSD = m_file->getString(system_info->CSDVersionRVA);
+ if (!ExpectedCSD) {
+ LLDB_LOG_ERROR(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS),
+ ExpectedCSD.takeError(),
+ "Failed to CSD Version string: {0}");
+ } else {
+ if (ExpectedCSD->find("Linux") != std::string::npos)
+ triple.setOS(llvm::Triple::OSType::Linux);
}
+ break;
+ }
}
m_arch.SetTriple(triple);
return m_arch;
@@ -305,24 +301,22 @@ std::vector<const MinidumpModule *> MinidumpParser::GetFilteredModuleList() {
std::vector<const MinidumpModule *> filtered_modules;
- llvm::Optional<std::string> name;
- std::string module_name;
-
for (const auto &module : modules) {
- name = GetMinidumpString(module.module_name_rva);
-
- if (!name)
+ auto ExpectedName = m_file->getString(module.module_name_rva);
+ if (!ExpectedName) {
+ LLDB_LOG_ERROR(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES),
+ ExpectedName.takeError(),
+ "Failed to module name: {0}");
continue;
-
- module_name = name.getValue();
-
+ }
+
MapType::iterator iter;
bool inserted;
// See if we have inserted this module aready into filtered_modules. If we
// haven't insert an entry into module_name_to_filtered_index with the
// index where we will insert it if it isn't in the vector already.
std::tie(iter, inserted) = module_name_to_filtered_index.try_emplace(
- module_name, filtered_modules.size());
+ *ExpectedName, filtered_modules.size());
if (inserted) {
// This module has not been seen yet, insert it into filtered_modules at
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 5cff646b5c3..5df2d74466a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -52,8 +52,6 @@ public:
llvm::ArrayRef<uint8_t> GetStream(StreamType stream_type);
- llvm::Optional<std::string> GetMinidumpString(uint32_t rva);
-
UUID GetModuleUUID(const MinidumpModule* module);
llvm::ArrayRef<MinidumpThread> GetThreads();
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp b/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
index 221f715af86..ba1f102c53a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
@@ -14,43 +14,6 @@
using namespace lldb_private;
using namespace minidump;
-// Minidump string
-llvm::Optional<std::string>
-lldb_private::minidump::parseMinidumpString(llvm::ArrayRef<uint8_t> &data) {
- std::string result;
-
- const llvm::support::ulittle32_t *source_length;
- Status error = consumeObject(data, source_length);
-
- if (error.Fail() || *source_length > data.size() || *source_length % 2 != 0)
- return llvm::None;
-
- auto *source_start =
- reinterpret_cast<const llvm::support::ulittle16_t *>(data.data());
- // source_length is the length of the string in bytes we need the length of
- // the string in UTF-16 characters/code points (16 bits per char) that's why
- // it's divided by 2
- uint32_t utf16_length = *source_length / 2;
-
- // Correct the endianness and alignment of the string.
- llvm::SmallVector<llvm::UTF16, 64> utf16(utf16_length, 0);
- std::copy_n(source_start, utf16_length, utf16.begin());
-
- const llvm::UTF16 *utf16_start = utf16.begin();
-
- // resize to worst case length
- result.resize(UNI_MAX_UTF8_BYTES_PER_CODE_POINT * utf16_length);
- auto result_start = reinterpret_cast<llvm::UTF8 *>(&result[0]);
- const auto result_end = result_start + result.size();
- llvm::ConvertUTF16toUTF8(&utf16_start, utf16.end(), &result_start, result_end,
- llvm::strictConversion);
- const auto result_size =
- std::distance(reinterpret_cast<llvm::UTF8 *>(&result[0]), result_start);
- result.resize(result_size); // shrink to actual length
-
- return result;
-}
-
// MinidumpThread
const MinidumpThread *MinidumpThread::Parse(llvm::ArrayRef<uint8_t> &data) {
const MinidumpThread *thread = nullptr;
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpTypes.h b/lldb/source/Plugins/Process/minidump/MinidumpTypes.h
index 67cda5de5b1..ac69066ead0 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpTypes.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpTypes.h
@@ -70,11 +70,6 @@ Status consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) {
return error;
}
-// parse a MinidumpString which is with UTF-16
-// Reference:
-// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680395(v=vs.85).aspx
-llvm::Optional<std::string> parseMinidumpString(llvm::ArrayRef<uint8_t> &data);
-
// Reference:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680384(v=vs.85).aspx
struct MinidumpMemoryDescriptor {
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 3da103b9064..79de4aaabeb 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -354,34 +354,21 @@ void ProcessMinidump::ReadModuleList() {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_MODULES));
for (auto module : filtered_modules) {
- llvm::Optional<std::string> name =
- m_minidump_parser->GetMinidumpString(module->module_name_rva);
-
- if (!name)
- continue;
-
- if (log) {
- log->Printf("ProcessMinidump::%s found module: name: %s %#010" PRIx64
- "-%#010" PRIx64 " size: %" PRIu32,
- __FUNCTION__, name.getValue().c_str(),
- uint64_t(module->base_of_image),
- module->base_of_image + module->size_of_image,
- uint32_t(module->size_of_image));
- }
+ std::string name = cantFail(m_minidump_parser->GetMinidumpFile().getString(
+ module->module_name_rva));
+ LLDB_LOG(log, "found module: name: {0} {1:x10}-{2:x10} size: {3}", name,
+ module->base_of_image,
+ module->base_of_image + module->size_of_image,
+ module->size_of_image);
// check if the process is wow64 - a 32 bit windows process running on a
// 64 bit windows
- if (llvm::StringRef(name.getValue()).endswith_lower("wow64.dll")) {
+ if (llvm::StringRef(name).endswith_lower("wow64.dll")) {
m_is_wow64 = true;
}
- if (log) {
- log->Printf("ProcessMinidump::%s load module: name: %s", __FUNCTION__,
- name.getValue().c_str());
- }
-
const auto uuid = m_minidump_parser->GetModuleUUID(module);
- auto file_spec = FileSpec(name.getValue(), GetArchitecture().GetTriple());
+ auto file_spec = FileSpec(name, GetArchitecture().GetTriple());
FileSystem::Instance().Resolve(file_spec);
ModuleSpec module_spec(file_spec, uuid);
module_spec.GetArchitecture() = GetArchitecture();
@@ -424,11 +411,10 @@ void ProcessMinidump::ReadModuleList() {
// This enables most LLDB functionality involving address-to-module
// translations (ex. identifing the module for a stack frame PC) and
// modules/sections commands (ex. target modules list, ...)
- if (log) {
- log->Printf("Unable to locate the matching object file, creating a "
- "placeholder module for: %s",
- name.getValue().c_str());
- }
+ LLDB_LOG(log,
+ "Unable to locate the matching object file, creating a "
+ "placeholder module for: {0}",
+ name);
module_sp = Module::CreateModuleFromObjectFile<PlaceholderObjectFile>(
module_spec, module->base_of_image, module->size_of_image);
OpenPOWER on IntegriCloud