blob: 41dc08b9e6c27a25bbdaf1f0e2409ee5c7f0cea9 [file] [log] [blame]
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +00001//===-- ProcessMinidump.cpp -------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +00006//
7//===----------------------------------------------------------------------===//
8
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +00009#include "ProcessMinidump.h"
Jonas Devlieghere796ac802019-02-11 23:13:08 +000010
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000011#include "ThreadMinidump.h"
12
Greg Clayton48a28c12018-12-18 00:50:11 +000013#include "lldb/Core/DumpDataExtractor.h"
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000014#include "lldb/Core/Module.h"
15#include "lldb/Core/ModuleSpec.h"
16#include "lldb/Core/PluginManager.h"
17#include "lldb/Core/Section.h"
Greg Clayton48a28c12018-12-18 00:50:11 +000018#include "lldb/Interpreter/CommandInterpreter.h"
19#include "lldb/Interpreter/CommandObject.h"
20#include "lldb/Interpreter/CommandObjectMultiword.h"
21#include "lldb/Interpreter/CommandReturnObject.h"
22#include "lldb/Interpreter/OptionArgParser.h"
23#include "lldb/Interpreter/OptionGroupBoolean.h"
Leonard Mosescu40b832e2018-08-23 21:34:33 +000024#include "lldb/Target/JITLoaderList.h"
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000025#include "lldb/Target/MemoryRegionInfo.h"
Leonard Mosescu47196a22018-04-18 23:10:46 +000026#include "lldb/Target/SectionLoadList.h"
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000027#include "lldb/Target/Target.h"
28#include "lldb/Target/UnixSignals.h"
29#include "lldb/Utility/LLDBAssert.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000030#include "lldb/Utility/Log.h"
Pavel Labathd821c992018-08-07 11:07:21 +000031#include "lldb/Utility/State.h"
Pavel Labathf2ffb472019-03-26 13:23:01 +000032#include "llvm/BinaryFormat/Magic.h"
Zachary Turner3f4a4b32017-02-24 18:56:49 +000033#include "llvm/Support/MemoryBuffer.h"
Kamil Rytarowskic5f28e22017-02-06 17:55:02 +000034#include "llvm/Support/Threading.h"
35
Greg Clayton19c8f392018-08-06 16:56:10 +000036#include "Plugins/Process/Utility/StopInfoMachException.h"
Leonard Mosescu0d057902019-01-07 17:55:42 +000037
Jonas Devlieghere796ac802019-02-11 23:13:08 +000038#include <memory>
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000039
Leonard Mosescu47196a22018-04-18 23:10:46 +000040using namespace lldb;
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000041using namespace lldb_private;
42using namespace minidump;
43
Pavel Labathee7ceac2019-03-27 10:54:10 +000044namespace {
45
46/// A minimal ObjectFile implementation providing a dummy object file for the
47/// cases when the real module binary is not available. This allows the module
48/// to show up in "image list" and symbols to be added to it.
49class PlaceholderObjectFile : public ObjectFile {
Leonard Mosescu47196a22018-04-18 23:10:46 +000050public:
Pavel Labathee7ceac2019-03-27 10:54:10 +000051 PlaceholderObjectFile(const lldb::ModuleSP &module_sp,
52 const ModuleSpec &module_spec, lldb::offset_t base,
53 lldb::offset_t size)
54 : ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0,
55 /*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0),
56 m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()),
57 m_base(base), m_size(size) {
Jonas Devliegherea8f3ae72019-08-14 22:19:23 +000058 m_symtab_up = std::make_unique<Symtab>(this);
Leonard Mosescu9fecd372018-05-02 20:06:17 +000059 }
Leonard Mosescu47196a22018-04-18 23:10:46 +000060
Pavel Labathee7ceac2019-03-27 10:54:10 +000061 ConstString GetPluginName() override { return ConstString("placeholder"); }
62 uint32_t GetPluginVersion() override { return 1; }
63 bool ParseHeader() override { return true; }
64 Type CalculateType() override { return eTypeUnknown; }
65 Strata CalculateStrata() override { return eStrataUnknown; }
66 uint32_t GetDependentModules(FileSpecList &file_list) override { return 0; }
67 bool IsExecutable() const override { return false; }
68 ArchSpec GetArchitecture() override { return m_arch; }
69 UUID GetUUID() override { return m_uuid; }
70 Symtab *GetSymtab() override { return m_symtab_up.get(); }
71 bool IsStripped() override { return true; }
72 ByteOrder GetByteOrder() const override { return m_arch.GetByteOrder(); }
73
74 uint32_t GetAddressByteSize() const override {
75 return m_arch.GetAddressByteSize();
76 }
77
78 Address GetBaseAddress() override {
79 return Address(m_sections_up->GetSectionAtIndex(0), 0);
80 }
81
82 void CreateSections(SectionList &unified_section_list) override {
Jonas Devliegherea8f3ae72019-08-14 22:19:23 +000083 m_sections_up = std::make_unique<SectionList>();
Pavel Labathee7ceac2019-03-27 10:54:10 +000084 auto section_sp = std::make_shared<Section>(
85 GetModule(), this, /*sect_id*/ 0, ConstString(".module_image"),
86 eSectionTypeOther, m_base, m_size, /*file_offset*/ 0, /*file_size*/ 0,
87 /*log2align*/ 0, /*flags*/ 0);
88 section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable);
89 m_sections_up->AddSection(section_sp);
90 unified_section_list.AddSection(std::move(section_sp));
91 }
92
93 bool SetLoadAddress(Target &target, addr_t value,
94 bool value_is_offset) override {
95 assert(!value_is_offset);
96 assert(value == m_base);
97
98 // Create sections if they haven't been created already.
99 GetModule()->GetSectionList();
100 assert(m_sections_up->GetNumSections(0) == 1);
101
Leonard Mosescu47196a22018-04-18 23:10:46 +0000102 target.GetSectionLoadList().SetSectionLoadAddress(
Pavel Labathee7ceac2019-03-27 10:54:10 +0000103 m_sections_up->GetSectionAtIndex(0), m_base);
104 return true;
Leonard Mosescu47196a22018-04-18 23:10:46 +0000105 }
106
Pavel Labathee7ceac2019-03-27 10:54:10 +0000107 void Dump(Stream *s) override {
108 s->Format("Placeholder object file for {0} loaded at [{1:x}-{2:x})\n",
109 GetFileSpec(), m_base, m_base + m_size);
Pavel Labath95e29762019-02-19 13:52:31 +0000110 }
Pavel Labathee7ceac2019-03-27 10:54:10 +0000111
112private:
113 ArchSpec m_arch;
114 UUID m_uuid;
115 lldb::offset_t m_base;
116 lldb::offset_t m_size;
Leonard Mosescu47196a22018-04-18 23:10:46 +0000117};
Pavel Labathee7ceac2019-03-27 10:54:10 +0000118} // namespace
Leonard Mosescu47196a22018-04-18 23:10:46 +0000119
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000120ConstString ProcessMinidump::GetPluginNameStatic() {
121 static ConstString g_name("minidump");
122 return g_name;
123}
124
125const char *ProcessMinidump::GetPluginDescriptionStatic() {
126 return "Minidump plug-in.";
127}
128
129lldb::ProcessSP ProcessMinidump::CreateInstance(lldb::TargetSP target_sp,
130 lldb::ListenerSP listener_sp,
131 const FileSpec *crash_file) {
132 if (!crash_file)
133 return nullptr;
134
135 lldb::ProcessSP process_sp;
136 // Read enough data for the Minidump header
Pavel Labathf2ffb472019-03-26 13:23:01 +0000137 constexpr size_t header_size = sizeof(Header);
Jonas Devlieghere87e403a2018-11-12 21:24:50 +0000138 auto DataPtr = FileSystem::Instance().CreateDataBuffer(crash_file->GetPath(),
139 header_size, 0);
Zachary Turner3f4a4b32017-02-24 18:56:49 +0000140 if (!DataPtr)
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000141 return nullptr;
142
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +0000143 lldbassert(DataPtr->GetByteSize() == header_size);
Pavel Labathf2ffb472019-03-26 13:23:01 +0000144 if (identify_magic(toStringRef(DataPtr->GetData())) != llvm::file_magic::minidump)
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000145 return nullptr;
146
Jonas Devlieghere87e403a2018-11-12 21:24:50 +0000147 auto AllData =
148 FileSystem::Instance().CreateDataBuffer(crash_file->GetPath(), -1, 0);
Zachary Turner3f4a4b32017-02-24 18:56:49 +0000149 if (!AllData)
150 return nullptr;
151
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000152 return std::make_shared<ProcessMinidump>(target_sp, listener_sp, *crash_file,
Pavel Labathab86d3d2019-02-22 13:36:01 +0000153 std::move(AllData));
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000154}
155
156bool ProcessMinidump::CanDebug(lldb::TargetSP target_sp,
157 bool plugin_specified_by_name) {
158 return true;
159}
160
161ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
162 lldb::ListenerSP listener_sp,
163 const FileSpec &core_file,
Pavel Labathab86d3d2019-02-22 13:36:01 +0000164 DataBufferSP core_data)
165 : Process(target_sp, listener_sp), m_core_file(core_file),
166 m_core_data(std::move(core_data)), m_is_wow64(false) {}
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000167
168ProcessMinidump::~ProcessMinidump() {
169 Clear();
Adrian Prantl05097242018-04-30 16:49:04 +0000170 // We need to call finalize on the process before destroying ourselves to
171 // make sure all of the broadcaster cleanup goes as planned. If we destruct
172 // this class, then Process::~Process() might have problems trying to fully
173 // destroy the broadcaster.
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000174 Finalize();
175}
176
177void ProcessMinidump::Initialize() {
Kamil Rytarowskic5f28e22017-02-06 17:55:02 +0000178 static llvm::once_flag g_once_flag;
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000179
Kamil Rytarowskic5f28e22017-02-06 17:55:02 +0000180 llvm::call_once(g_once_flag, []() {
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000181 PluginManager::RegisterPlugin(GetPluginNameStatic(),
182 GetPluginDescriptionStatic(),
183 ProcessMinidump::CreateInstance);
184 });
185}
186
187void ProcessMinidump::Terminate() {
188 PluginManager::UnregisterPlugin(ProcessMinidump::CreateInstance);
189}
190
Zachary Turner97206d52017-05-12 04:51:55 +0000191Status ProcessMinidump::DoLoadCore() {
Pavel Labathab86d3d2019-02-22 13:36:01 +0000192 auto expected_parser = MinidumpParser::Create(m_core_data);
193 if (!expected_parser)
194 return Status(expected_parser.takeError());
195 m_minidump_parser = std::move(*expected_parser);
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000196
Pavel Labathab86d3d2019-02-22 13:36:01 +0000197 Status error;
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +0000198
199 // Do we support the minidump's architecture?
200 ArchSpec arch = GetArchitecture();
201 switch (arch.GetMachine()) {
202 case llvm::Triple::x86:
203 case llvm::Triple::x86_64:
Greg Clayton19c8f392018-08-06 16:56:10 +0000204 case llvm::Triple::arm:
205 case llvm::Triple::aarch64:
206 // Any supported architectures must be listed here and also supported in
207 // ThreadMinidump::CreateRegisterContextForFrame().
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +0000208 break;
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +0000209 default:
210 error.SetErrorStringWithFormat("unsupported minidump architecture: %s",
211 arch.GetArchitectureName());
212 return error;
213 }
Greg Clayton19c8f392018-08-06 16:56:10 +0000214 GetTarget().SetArchitecture(arch, true /*set_platform*/);
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +0000215
Pavel Labathab86d3d2019-02-22 13:36:01 +0000216 m_thread_list = m_minidump_parser->GetThreads();
217 m_active_exception = m_minidump_parser->GetExceptionStream();
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000218 ReadModuleList();
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000219
Pavel Labathab86d3d2019-02-22 13:36:01 +0000220 llvm::Optional<lldb::pid_t> pid = m_minidump_parser->GetPid();
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000221 if (!pid) {
222 error.SetErrorString("failed to parse PID");
223 return error;
224 }
225 SetID(pid.getValue());
226
227 return error;
228}
229
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000230ConstString ProcessMinidump::GetPluginName() { return GetPluginNameStatic(); }
231
232uint32_t ProcessMinidump::GetPluginVersion() { return 1; }
233
Zachary Turner97206d52017-05-12 04:51:55 +0000234Status ProcessMinidump::DoDestroy() { return Status(); }
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000235
236void ProcessMinidump::RefreshStateAfterStop() {
237 if (!m_active_exception)
238 return;
239
240 if (m_active_exception->exception_record.exception_code ==
241 MinidumpException::DumpRequested) {
242 return;
243 }
244
245 lldb::StopInfoSP stop_info;
246 lldb::ThreadSP stop_thread;
247
248 Process::m_thread_list.SetSelectedThreadByID(m_active_exception->thread_id);
249 stop_thread = Process::m_thread_list.GetSelectedThread();
250 ArchSpec arch = GetArchitecture();
251
252 if (arch.GetTriple().getOS() == llvm::Triple::Linux) {
253 stop_info = StopInfo::CreateStopReasonWithSignal(
254 *stop_thread, m_active_exception->exception_record.exception_code);
Greg Clayton19c8f392018-08-06 16:56:10 +0000255 } else if (arch.GetTriple().getVendor() == llvm::Triple::Apple) {
256 stop_info = StopInfoMachException::CreateStopReasonWithMachException(
257 *stop_thread, m_active_exception->exception_record.exception_code, 2,
258 m_active_exception->exception_record.exception_flags,
259 m_active_exception->exception_record.exception_address, 0);
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000260 } else {
261 std::string desc;
262 llvm::raw_string_ostream desc_stream(desc);
263 desc_stream << "Exception "
264 << llvm::format_hex(
265 m_active_exception->exception_record.exception_code, 8)
266 << " encountered at address "
267 << llvm::format_hex(
268 m_active_exception->exception_record.exception_address,
269 8);
270 stop_info = StopInfo::CreateStopReasonWithException(
271 *stop_thread, desc_stream.str().c_str());
272 }
273
274 stop_thread->SetStopInfo(stop_info);
275}
276
277bool ProcessMinidump::IsAlive() { return true; }
278
279bool ProcessMinidump::WarnBeforeDetach() const { return false; }
280
281size_t ProcessMinidump::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000282 Status &error) {
Adrian Prantl05097242018-04-30 16:49:04 +0000283 // Don't allow the caching that lldb_private::Process::ReadMemory does since
284 // we have it all cached in our dump file anyway.
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000285 return DoReadMemory(addr, buf, size, error);
286}
287
288size_t ProcessMinidump::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
Zachary Turner97206d52017-05-12 04:51:55 +0000289 Status &error) {
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000290
Pavel Labathab86d3d2019-02-22 13:36:01 +0000291 llvm::ArrayRef<uint8_t> mem = m_minidump_parser->GetMemory(addr, size);
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000292 if (mem.empty()) {
293 error.SetErrorString("could not parse memory info");
294 return 0;
295 }
296
297 std::memcpy(buf, mem.data(), mem.size());
298 return mem.size();
299}
300
301ArchSpec ProcessMinidump::GetArchitecture() {
302 if (!m_is_wow64) {
Pavel Labathab86d3d2019-02-22 13:36:01 +0000303 return m_minidump_parser->GetArchitecture();
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000304 }
305
306 llvm::Triple triple;
307 triple.setVendor(llvm::Triple::VendorType::UnknownVendor);
308 triple.setArch(llvm::Triple::ArchType::x86);
309 triple.setOS(llvm::Triple::OSType::Win32);
310 return ArchSpec(triple);
311}
312
Zachary Turner97206d52017-05-12 04:51:55 +0000313Status ProcessMinidump::GetMemoryRegionInfo(lldb::addr_t load_addr,
314 MemoryRegionInfo &range_info) {
Pavel Labathab86d3d2019-02-22 13:36:01 +0000315 range_info = m_minidump_parser->GetMemoryRegionInfo(load_addr);
Greg Clayton026e1bf2018-12-14 19:36:01 +0000316 return Status();
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000317}
318
Tatyana Krasnukha92e5e362018-12-20 15:05:43 +0000319Status ProcessMinidump::GetMemoryRegions(
320 lldb_private::MemoryRegionInfos &region_list) {
Pavel Labathab86d3d2019-02-22 13:36:01 +0000321 region_list = m_minidump_parser->GetMemoryRegions();
Tatyana Krasnukha92e5e362018-12-20 15:05:43 +0000322 return Status();
323}
324
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000325void ProcessMinidump::Clear() { Process::m_thread_list.Clear(); }
326
Dimitar Vlahovski5a19c0c2016-11-01 15:48:24 +0000327bool ProcessMinidump::UpdateThreadList(ThreadList &old_thread_list,
328 ThreadList &new_thread_list) {
Pavel Labath6d40c292019-05-10 09:36:11 +0000329 for (const minidump::Thread &thread : m_thread_list) {
330 LocationDescriptor context_location = thread.Context;
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000331
Leonard Mosescu0d057902019-01-07 17:55:42 +0000332 // If the minidump contains an exception context, use it
333 if (m_active_exception != nullptr &&
Pavel Labath6d40c292019-05-10 09:36:11 +0000334 m_active_exception->thread_id == thread.ThreadId) {
Leonard Mosescu0d057902019-01-07 17:55:42 +0000335 context_location = m_active_exception->thread_context;
336 }
337
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000338 llvm::ArrayRef<uint8_t> context;
339 if (!m_is_wow64)
Pavel Labathab86d3d2019-02-22 13:36:01 +0000340 context = m_minidump_parser->GetThreadContext(context_location);
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000341 else
Pavel Labathab86d3d2019-02-22 13:36:01 +0000342 context = m_minidump_parser->GetThreadContextWow64(thread);
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000343
Leonard Mosescu0d057902019-01-07 17:55:42 +0000344 lldb::ThreadSP thread_sp(new ThreadMinidump(*this, thread, context));
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000345 new_thread_list.AddThread(thread_sp);
346 }
347 return new_thread_list.GetSize(false) > 0;
348}
349
350void ProcessMinidump::ReadModuleList() {
Pavel Labath139e9f22019-04-10 11:07:28 +0000351 std::vector<const minidump::Module *> filtered_modules =
Pavel Labathab86d3d2019-02-22 13:36:01 +0000352 m_minidump_parser->GetFilteredModuleList();
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000353
Greg Claytonbbc428e2019-04-03 16:30:44 +0000354 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_MODULES));
355
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000356 for (auto module : filtered_modules) {
Pavel Labathff129132019-04-09 08:28:27 +0000357 std::string name = cantFail(m_minidump_parser->GetMinidumpFile().getString(
Pavel Labath139e9f22019-04-10 11:07:28 +0000358 module->ModuleNameRVA));
Pavel Labathff129132019-04-09 08:28:27 +0000359 LLDB_LOG(log, "found module: name: {0} {1:x10}-{2:x10} size: {3}", name,
Pavel Labath139e9f22019-04-10 11:07:28 +0000360 module->BaseOfImage, module->BaseOfImage + module->SizeOfImage,
361 module->SizeOfImage);
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000362
363 // check if the process is wow64 - a 32 bit windows process running on a
364 // 64 bit windows
Pavel Labathff129132019-04-09 08:28:27 +0000365 if (llvm::StringRef(name).endswith_lower("wow64.dll")) {
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000366 m_is_wow64 = true;
367 }
368
Pavel Labathab86d3d2019-02-22 13:36:01 +0000369 const auto uuid = m_minidump_parser->GetModuleUUID(module);
Pavel Labathff129132019-04-09 08:28:27 +0000370 auto file_spec = FileSpec(name, GetArchitecture().GetTriple());
Leonard Mosescu9fecd372018-05-02 20:06:17 +0000371 ModuleSpec module_spec(file_spec, uuid);
Pavel Labathee7ceac2019-03-27 10:54:10 +0000372 module_spec.GetArchitecture() = GetArchitecture();
Zachary Turner97206d52017-05-12 04:51:55 +0000373 Status error;
Greg Claytonbbc428e2019-04-03 16:30:44 +0000374 // Try and find a module with a full UUID that matches. This function will
375 // add the module to the target if it finds one.
Jason Molenda1724a172019-04-08 23:03:02 +0000376 lldb::ModuleSP module_sp = GetTarget().GetOrCreateModule(module_spec,
377 true /* notify */, &error);
Greg Claytonbbc428e2019-04-03 16:30:44 +0000378 if (!module_sp) {
379 // Try and find a module without specifying the UUID and only looking for
380 // the file given a basename. We then will look for a partial UUID match
381 // if we find any matches. This function will add the module to the
382 // target if it finds one, so we need to remove the module from the target
383 // if the UUID doesn't match during our manual UUID verification. This
384 // allows the "target.exec-search-paths" setting to specify one or more
385 // directories that contain executables that can be searched for matches.
386 ModuleSpec basename_module_spec(module_spec);
387 basename_module_spec.GetUUID().Clear();
388 basename_module_spec.GetFileSpec().GetDirectory().Clear();
Jason Molenda1724a172019-04-08 23:03:02 +0000389 module_sp = GetTarget().GetOrCreateModule(basename_module_spec,
390 true /* notify */, &error);
Greg Claytonbbc428e2019-04-03 16:30:44 +0000391 if (module_sp) {
392 // We consider the module to be a match if the minidump UUID is a
393 // prefix of the actual UUID, or if either of the UUIDs are empty.
394 const auto dmp_bytes = uuid.GetBytes();
395 const auto mod_bytes = module_sp->GetUUID().GetBytes();
396 const bool match = dmp_bytes.empty() || mod_bytes.empty() ||
397 mod_bytes.take_front(dmp_bytes.size()) == dmp_bytes;
398 if (!match) {
399 GetTarget().GetImages().Remove(module_sp);
400 module_sp.reset();
401 }
402 }
403 }
404 if (!module_sp) {
Adrian Prantl05097242018-04-30 16:49:04 +0000405 // We failed to locate a matching local object file. Fortunately, the
406 // minidump format encodes enough information about each module's memory
407 // range to allow us to create placeholder modules.
Leonard Mosescu47196a22018-04-18 23:10:46 +0000408 //
409 // This enables most LLDB functionality involving address-to-module
410 // translations (ex. identifing the module for a stack frame PC) and
411 // modules/sections commands (ex. target modules list, ...)
Pavel Labathff129132019-04-09 08:28:27 +0000412 LLDB_LOG(log,
413 "Unable to locate the matching object file, creating a "
414 "placeholder module for: {0}",
415 name);
Leonard Mosescu9ba51572018-08-07 18:00:30 +0000416
Pavel Labathee7ceac2019-03-27 10:54:10 +0000417 module_sp = Module::CreateModuleFromObjectFile<PlaceholderObjectFile>(
Pavel Labath139e9f22019-04-10 11:07:28 +0000418 module_spec, module->BaseOfImage, module->SizeOfImage);
Jason Molenda1724a172019-04-08 23:03:02 +0000419 GetTarget().GetImages().Append(module_sp, true /* notify */);
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000420 }
421
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000422 bool load_addr_changed = false;
Pavel Labath139e9f22019-04-10 11:07:28 +0000423 module_sp->SetLoadAddress(GetTarget(), module->BaseOfImage, false,
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +0000424 load_addr_changed);
425 }
426}
Dimitar Vlahovski5a19c0c2016-11-01 15:48:24 +0000427
428bool ProcessMinidump::GetProcessInfo(ProcessInstanceInfo &info) {
429 info.Clear();
430 info.SetProcessID(GetID());
431 info.SetArchitecture(GetArchitecture());
432 lldb::ModuleSP module_sp = GetTarget().GetExecutableModule();
433 if (module_sp) {
434 const bool add_exe_file_as_first_arg = false;
435 info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(),
436 add_exe_file_as_first_arg);
437 }
438 return true;
439}
Leonard Mosescu40b832e2018-08-23 21:34:33 +0000440
441// For minidumps there's no runtime generated code so we don't need JITLoader(s)
442// Avoiding them will also speed up minidump loading since JITLoaders normally
443// try to set up symbolic breakpoints, which in turn may force loading more
444// debug information than needed.
445JITLoaderList &ProcessMinidump::GetJITLoaders() {
Jonas Devlieghered5b44032019-02-13 06:25:41 +0000446 if (!m_jit_loaders_up) {
Jonas Devliegherea8f3ae72019-08-14 22:19:23 +0000447 m_jit_loaders_up = std::make_unique<JITLoaderList>();
Leonard Mosescu40b832e2018-08-23 21:34:33 +0000448 }
Jonas Devlieghered5b44032019-02-13 06:25:41 +0000449 return *m_jit_loaders_up;
Leonard Mosescu40b832e2018-08-23 21:34:33 +0000450}
Greg Clayton48a28c12018-12-18 00:50:11 +0000451
452#define INIT_BOOL(VAR, LONG, SHORT, DESC) \
453 VAR(LLDB_OPT_SET_1, false, LONG, SHORT, DESC, false, true)
454#define APPEND_OPT(VAR) \
455 m_option_group.Append(&VAR, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1)
456
457class CommandObjectProcessMinidumpDump : public CommandObjectParsed {
458private:
459 OptionGroupOptions m_option_group;
460 OptionGroupBoolean m_dump_all;
461 OptionGroupBoolean m_dump_directory;
462 OptionGroupBoolean m_dump_linux_cpuinfo;
463 OptionGroupBoolean m_dump_linux_proc_status;
464 OptionGroupBoolean m_dump_linux_lsb_release;
465 OptionGroupBoolean m_dump_linux_cmdline;
466 OptionGroupBoolean m_dump_linux_environ;
467 OptionGroupBoolean m_dump_linux_auxv;
468 OptionGroupBoolean m_dump_linux_maps;
469 OptionGroupBoolean m_dump_linux_proc_stat;
470 OptionGroupBoolean m_dump_linux_proc_uptime;
471 OptionGroupBoolean m_dump_linux_proc_fd;
472 OptionGroupBoolean m_dump_linux_all;
Greg Claytoncc6ec692019-02-19 21:48:34 +0000473 OptionGroupBoolean m_fb_app_data;
474 OptionGroupBoolean m_fb_build_id;
475 OptionGroupBoolean m_fb_version;
476 OptionGroupBoolean m_fb_java_stack;
477 OptionGroupBoolean m_fb_dalvik;
478 OptionGroupBoolean m_fb_unwind;
479 OptionGroupBoolean m_fb_error_log;
480 OptionGroupBoolean m_fb_app_state;
481 OptionGroupBoolean m_fb_abort;
482 OptionGroupBoolean m_fb_thread;
483 OptionGroupBoolean m_fb_logcat;
484 OptionGroupBoolean m_fb_all;
Greg Clayton48a28c12018-12-18 00:50:11 +0000485
486 void SetDefaultOptionsIfNoneAreSet() {
487 if (m_dump_all.GetOptionValue().GetCurrentValue() ||
488 m_dump_linux_all.GetOptionValue().GetCurrentValue() ||
Greg Claytoncc6ec692019-02-19 21:48:34 +0000489 m_fb_all.GetOptionValue().GetCurrentValue() ||
Greg Clayton48a28c12018-12-18 00:50:11 +0000490 m_dump_directory.GetOptionValue().GetCurrentValue() ||
491 m_dump_linux_cpuinfo.GetOptionValue().GetCurrentValue() ||
492 m_dump_linux_proc_status.GetOptionValue().GetCurrentValue() ||
493 m_dump_linux_lsb_release.GetOptionValue().GetCurrentValue() ||
494 m_dump_linux_cmdline.GetOptionValue().GetCurrentValue() ||
495 m_dump_linux_environ.GetOptionValue().GetCurrentValue() ||
496 m_dump_linux_auxv.GetOptionValue().GetCurrentValue() ||
497 m_dump_linux_maps.GetOptionValue().GetCurrentValue() ||
498 m_dump_linux_proc_stat.GetOptionValue().GetCurrentValue() ||
499 m_dump_linux_proc_uptime.GetOptionValue().GetCurrentValue() ||
Greg Claytoncc6ec692019-02-19 21:48:34 +0000500 m_dump_linux_proc_fd.GetOptionValue().GetCurrentValue() ||
501 m_fb_app_data.GetOptionValue().GetCurrentValue() ||
502 m_fb_build_id.GetOptionValue().GetCurrentValue() ||
503 m_fb_version.GetOptionValue().GetCurrentValue() ||
504 m_fb_java_stack.GetOptionValue().GetCurrentValue() ||
505 m_fb_dalvik.GetOptionValue().GetCurrentValue() ||
506 m_fb_unwind.GetOptionValue().GetCurrentValue() ||
507 m_fb_error_log.GetOptionValue().GetCurrentValue() ||
508 m_fb_app_state.GetOptionValue().GetCurrentValue() ||
509 m_fb_abort.GetOptionValue().GetCurrentValue() ||
510 m_fb_thread.GetOptionValue().GetCurrentValue() ||
511 m_fb_logcat.GetOptionValue().GetCurrentValue())
Greg Clayton48a28c12018-12-18 00:50:11 +0000512 return;
513 // If no options were set, then dump everything
514 m_dump_all.GetOptionValue().SetCurrentValue(true);
515 }
516 bool DumpAll() const {
517 return m_dump_all.GetOptionValue().GetCurrentValue();
518 }
519 bool DumpDirectory() const {
520 return DumpAll() ||
521 m_dump_directory.GetOptionValue().GetCurrentValue();
522 }
523 bool DumpLinux() const {
524 return DumpAll() || m_dump_linux_all.GetOptionValue().GetCurrentValue();
525 }
526 bool DumpLinuxCPUInfo() const {
527 return DumpLinux() ||
528 m_dump_linux_cpuinfo.GetOptionValue().GetCurrentValue();
529 }
530 bool DumpLinuxProcStatus() const {
531 return DumpLinux() ||
532 m_dump_linux_proc_status.GetOptionValue().GetCurrentValue();
533 }
534 bool DumpLinuxProcStat() const {
535 return DumpLinux() ||
536 m_dump_linux_proc_stat.GetOptionValue().GetCurrentValue();
537 }
538 bool DumpLinuxLSBRelease() const {
539 return DumpLinux() ||
540 m_dump_linux_lsb_release.GetOptionValue().GetCurrentValue();
541 }
542 bool DumpLinuxCMDLine() const {
543 return DumpLinux() ||
544 m_dump_linux_cmdline.GetOptionValue().GetCurrentValue();
545 }
546 bool DumpLinuxEnviron() const {
547 return DumpLinux() ||
548 m_dump_linux_environ.GetOptionValue().GetCurrentValue();
549 }
550 bool DumpLinuxAuxv() const {
551 return DumpLinux() ||
552 m_dump_linux_auxv.GetOptionValue().GetCurrentValue();
553 }
554 bool DumpLinuxMaps() const {
555 return DumpLinux() ||
556 m_dump_linux_maps.GetOptionValue().GetCurrentValue();
557 }
558 bool DumpLinuxProcUptime() const {
559 return DumpLinux() ||
560 m_dump_linux_proc_uptime.GetOptionValue().GetCurrentValue();
561 }
562 bool DumpLinuxProcFD() const {
563 return DumpLinux() ||
564 m_dump_linux_proc_fd.GetOptionValue().GetCurrentValue();
565 }
Greg Claytoncc6ec692019-02-19 21:48:34 +0000566 bool DumpFacebook() const {
567 return DumpAll() || m_fb_all.GetOptionValue().GetCurrentValue();
568 }
569 bool DumpFacebookAppData() const {
570 return DumpFacebook() || m_fb_app_data.GetOptionValue().GetCurrentValue();
571 }
572 bool DumpFacebookBuildID() const {
573 return DumpFacebook() || m_fb_build_id.GetOptionValue().GetCurrentValue();
574 }
575 bool DumpFacebookVersionName() const {
576 return DumpFacebook() || m_fb_version.GetOptionValue().GetCurrentValue();
577 }
578 bool DumpFacebookJavaStack() const {
579 return DumpFacebook() || m_fb_java_stack.GetOptionValue().GetCurrentValue();
580 }
581 bool DumpFacebookDalvikInfo() const {
582 return DumpFacebook() || m_fb_dalvik.GetOptionValue().GetCurrentValue();
583 }
584 bool DumpFacebookUnwindSymbols() const {
585 return DumpFacebook() || m_fb_unwind.GetOptionValue().GetCurrentValue();
586 }
587 bool DumpFacebookErrorLog() const {
588 return DumpFacebook() || m_fb_error_log.GetOptionValue().GetCurrentValue();
589 }
590 bool DumpFacebookAppStateLog() const {
591 return DumpFacebook() || m_fb_app_state.GetOptionValue().GetCurrentValue();
592 }
593 bool DumpFacebookAbortReason() const {
594 return DumpFacebook() || m_fb_abort.GetOptionValue().GetCurrentValue();
595 }
596 bool DumpFacebookThreadName() const {
597 return DumpFacebook() || m_fb_thread.GetOptionValue().GetCurrentValue();
598 }
599 bool DumpFacebookLogcat() const {
600 return DumpFacebook() || m_fb_logcat.GetOptionValue().GetCurrentValue();
601 }
Greg Clayton48a28c12018-12-18 00:50:11 +0000602public:
Greg Clayton48a28c12018-12-18 00:50:11 +0000603 CommandObjectProcessMinidumpDump(CommandInterpreter &interpreter)
604 : CommandObjectParsed(interpreter, "process plugin dump",
Konrad Kleine248a1302019-05-23 11:14:47 +0000605 "Dump information from the minidump file.", nullptr),
Greg Clayton48a28c12018-12-18 00:50:11 +0000606 m_option_group(),
607 INIT_BOOL(m_dump_all, "all", 'a',
608 "Dump the everything in the minidump."),
609 INIT_BOOL(m_dump_directory, "directory", 'd',
610 "Dump the minidump directory map."),
611 INIT_BOOL(m_dump_linux_cpuinfo, "cpuinfo", 'C',
612 "Dump linux /proc/cpuinfo."),
613 INIT_BOOL(m_dump_linux_proc_status, "status", 's',
614 "Dump linux /proc/<pid>/status."),
615 INIT_BOOL(m_dump_linux_lsb_release, "lsb-release", 'r',
616 "Dump linux /etc/lsb-release."),
617 INIT_BOOL(m_dump_linux_cmdline, "cmdline", 'c',
618 "Dump linux /proc/<pid>/cmdline."),
619 INIT_BOOL(m_dump_linux_environ, "environ", 'e',
620 "Dump linux /proc/<pid>/environ."),
621 INIT_BOOL(m_dump_linux_auxv, "auxv", 'x',
622 "Dump linux /proc/<pid>/auxv."),
623 INIT_BOOL(m_dump_linux_maps, "maps", 'm',
624 "Dump linux /proc/<pid>/maps."),
625 INIT_BOOL(m_dump_linux_proc_stat, "stat", 'S',
626 "Dump linux /proc/<pid>/stat."),
627 INIT_BOOL(m_dump_linux_proc_uptime, "uptime", 'u',
628 "Dump linux process uptime."),
629 INIT_BOOL(m_dump_linux_proc_fd, "fd", 'f',
630 "Dump linux /proc/<pid>/fd."),
631 INIT_BOOL(m_dump_linux_all, "linux", 'l',
Greg Claytoncc6ec692019-02-19 21:48:34 +0000632 "Dump all linux streams."),
633 INIT_BOOL(m_fb_app_data, "fb-app-data", 1,
634 "Dump Facebook application custom data."),
635 INIT_BOOL(m_fb_build_id, "fb-build-id", 2,
636 "Dump the Facebook build ID."),
637 INIT_BOOL(m_fb_version, "fb-version", 3,
638 "Dump Facebook application version string."),
639 INIT_BOOL(m_fb_java_stack, "fb-java-stack", 4,
640 "Dump Facebook java stack."),
641 INIT_BOOL(m_fb_dalvik, "fb-dalvik-info", 5,
642 "Dump Facebook Dalvik info."),
643 INIT_BOOL(m_fb_unwind, "fb-unwind-symbols", 6,
644 "Dump Facebook unwind symbols."),
645 INIT_BOOL(m_fb_error_log, "fb-error-log", 7,
646 "Dump Facebook error log."),
647 INIT_BOOL(m_fb_app_state, "fb-app-state-log", 8,
648 "Dump Facebook java stack."),
649 INIT_BOOL(m_fb_abort, "fb-abort-reason", 9,
650 "Dump Facebook abort reason."),
651 INIT_BOOL(m_fb_thread, "fb-thread-name", 10,
652 "Dump Facebook thread name."),
653 INIT_BOOL(m_fb_logcat, "fb-logcat", 11,
654 "Dump Facebook logcat."),
655 INIT_BOOL(m_fb_all, "facebook", 12, "Dump all Facebook streams.") {
Greg Clayton48a28c12018-12-18 00:50:11 +0000656 APPEND_OPT(m_dump_all);
657 APPEND_OPT(m_dump_directory);
658 APPEND_OPT(m_dump_linux_cpuinfo);
659 APPEND_OPT(m_dump_linux_proc_status);
660 APPEND_OPT(m_dump_linux_lsb_release);
661 APPEND_OPT(m_dump_linux_cmdline);
662 APPEND_OPT(m_dump_linux_environ);
663 APPEND_OPT(m_dump_linux_auxv);
664 APPEND_OPT(m_dump_linux_maps);
665 APPEND_OPT(m_dump_linux_proc_stat);
666 APPEND_OPT(m_dump_linux_proc_uptime);
667 APPEND_OPT(m_dump_linux_proc_fd);
668 APPEND_OPT(m_dump_linux_all);
Greg Claytoncc6ec692019-02-19 21:48:34 +0000669 APPEND_OPT(m_fb_app_data);
670 APPEND_OPT(m_fb_build_id);
671 APPEND_OPT(m_fb_version);
672 APPEND_OPT(m_fb_java_stack);
673 APPEND_OPT(m_fb_dalvik);
674 APPEND_OPT(m_fb_unwind);
675 APPEND_OPT(m_fb_error_log);
676 APPEND_OPT(m_fb_app_state);
677 APPEND_OPT(m_fb_abort);
678 APPEND_OPT(m_fb_thread);
679 APPEND_OPT(m_fb_logcat);
680 APPEND_OPT(m_fb_all);
Greg Clayton48a28c12018-12-18 00:50:11 +0000681 m_option_group.Finalize();
682 }
Leonard Mosescu0d057902019-01-07 17:55:42 +0000683
Raphael Isemann17566302019-05-03 10:03:28 +0000684 ~CommandObjectProcessMinidumpDump() override {}
Leonard Mosescu0d057902019-01-07 17:55:42 +0000685
Greg Clayton48a28c12018-12-18 00:50:11 +0000686 Options *GetOptions() override { return &m_option_group; }
687
688 bool DoExecute(Args &command, CommandReturnObject &result) override {
689 const size_t argc = command.GetArgumentCount();
690 if (argc > 0) {
691 result.AppendErrorWithFormat("'%s' take no arguments, only options",
692 m_cmd_name.c_str());
693 result.SetStatus(eReturnStatusFailed);
694 return false;
695 }
696 SetDefaultOptionsIfNoneAreSet();
Leonard Mosescu0d057902019-01-07 17:55:42 +0000697
Greg Clayton48a28c12018-12-18 00:50:11 +0000698 ProcessMinidump *process = static_cast<ProcessMinidump *>(
699 m_interpreter.GetExecutionContext().GetProcessPtr());
700 result.SetStatus(eReturnStatusSuccessFinishResult);
701 Stream &s = result.GetOutputStream();
Pavel Labathab86d3d2019-02-22 13:36:01 +0000702 MinidumpParser &minidump = *process->m_minidump_parser;
Greg Clayton48a28c12018-12-18 00:50:11 +0000703 if (DumpDirectory()) {
Pavel Labathd2b48882019-03-25 14:09:27 +0000704 s.Printf("RVA SIZE TYPE StreamType\n");
Greg Clayton48a28c12018-12-18 00:50:11 +0000705 s.Printf("---------- ---------- ---------- --------------------------\n");
Pavel Labath98edcd92019-04-05 07:56:39 +0000706 for (const auto &stream_desc : minidump.GetMinidumpFile().streams())
707 s.Printf(
708 "0x%8.8x 0x%8.8x 0x%8.8x %s\n", (uint32_t)stream_desc.Location.RVA,
709 (uint32_t)stream_desc.Location.DataSize,
710 (unsigned)(StreamType)stream_desc.Type,
711 MinidumpParser::GetStreamTypeAsString(stream_desc.Type).data());
Greg Clayton48a28c12018-12-18 00:50:11 +0000712 s.Printf("\n");
713 }
Pavel Labathd2b48882019-03-25 14:09:27 +0000714 auto DumpTextStream = [&](StreamType stream_type,
Pavel Labath796984d2018-12-27 09:44:32 +0000715 llvm::StringRef label) -> void {
Greg Clayton48a28c12018-12-18 00:50:11 +0000716 auto bytes = minidump.GetStream(stream_type);
717 if (!bytes.empty()) {
718 if (label.empty())
Pavel Labathf2ffb472019-03-26 13:23:01 +0000719 label = MinidumpParser::GetStreamTypeAsString(stream_type);
Greg Clayton48a28c12018-12-18 00:50:11 +0000720 s.Printf("%s:\n%s\n\n", label.data(), bytes.data());
721 }
722 };
Pavel Labathd2b48882019-03-25 14:09:27 +0000723 auto DumpBinaryStream = [&](StreamType stream_type,
Pavel Labath796984d2018-12-27 09:44:32 +0000724 llvm::StringRef label) -> void {
Greg Clayton48a28c12018-12-18 00:50:11 +0000725 auto bytes = minidump.GetStream(stream_type);
726 if (!bytes.empty()) {
727 if (label.empty())
Pavel Labathf2ffb472019-03-26 13:23:01 +0000728 label = MinidumpParser::GetStreamTypeAsString(stream_type);
Greg Clayton48a28c12018-12-18 00:50:11 +0000729 s.Printf("%s:\n", label.data());
730 DataExtractor data(bytes.data(), bytes.size(), eByteOrderLittle,
731 process->GetAddressByteSize());
732 DumpDataExtractor(data, &s, 0, lldb::eFormatBytesWithASCII, 1,
733 bytes.size(), 16, 0, 0, 0);
734 s.Printf("\n\n");
735 }
736 };
737
738 if (DumpLinuxCPUInfo())
Pavel Labathd2b48882019-03-25 14:09:27 +0000739 DumpTextStream(StreamType::LinuxCPUInfo, "/proc/cpuinfo");
Greg Clayton48a28c12018-12-18 00:50:11 +0000740 if (DumpLinuxProcStatus())
Pavel Labathd2b48882019-03-25 14:09:27 +0000741 DumpTextStream(StreamType::LinuxProcStatus, "/proc/PID/status");
Greg Clayton48a28c12018-12-18 00:50:11 +0000742 if (DumpLinuxLSBRelease())
Pavel Labathd2b48882019-03-25 14:09:27 +0000743 DumpTextStream(StreamType::LinuxLSBRelease, "/etc/lsb-release");
Greg Clayton48a28c12018-12-18 00:50:11 +0000744 if (DumpLinuxCMDLine())
Pavel Labathd2b48882019-03-25 14:09:27 +0000745 DumpTextStream(StreamType::LinuxCMDLine, "/proc/PID/cmdline");
Greg Clayton48a28c12018-12-18 00:50:11 +0000746 if (DumpLinuxEnviron())
Pavel Labathd2b48882019-03-25 14:09:27 +0000747 DumpTextStream(StreamType::LinuxEnviron, "/proc/PID/environ");
Greg Clayton48a28c12018-12-18 00:50:11 +0000748 if (DumpLinuxAuxv())
Pavel Labathd2b48882019-03-25 14:09:27 +0000749 DumpBinaryStream(StreamType::LinuxAuxv, "/proc/PID/auxv");
Greg Clayton48a28c12018-12-18 00:50:11 +0000750 if (DumpLinuxMaps())
Pavel Labathd2b48882019-03-25 14:09:27 +0000751 DumpTextStream(StreamType::LinuxMaps, "/proc/PID/maps");
Greg Clayton48a28c12018-12-18 00:50:11 +0000752 if (DumpLinuxProcStat())
Pavel Labathd2b48882019-03-25 14:09:27 +0000753 DumpTextStream(StreamType::LinuxProcStat, "/proc/PID/stat");
Greg Clayton48a28c12018-12-18 00:50:11 +0000754 if (DumpLinuxProcUptime())
Pavel Labathd2b48882019-03-25 14:09:27 +0000755 DumpTextStream(StreamType::LinuxProcUptime, "uptime");
Greg Clayton48a28c12018-12-18 00:50:11 +0000756 if (DumpLinuxProcFD())
Pavel Labathd2b48882019-03-25 14:09:27 +0000757 DumpTextStream(StreamType::LinuxProcFD, "/proc/PID/fd");
Greg Claytoncc6ec692019-02-19 21:48:34 +0000758 if (DumpFacebookAppData())
Pavel Labathd2b48882019-03-25 14:09:27 +0000759 DumpTextStream(StreamType::FacebookAppCustomData,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000760 "Facebook App Data");
761 if (DumpFacebookBuildID()) {
Pavel Labathd2b48882019-03-25 14:09:27 +0000762 auto bytes = minidump.GetStream(StreamType::FacebookBuildID);
Greg Claytoncc6ec692019-02-19 21:48:34 +0000763 if (bytes.size() >= 4) {
764 DataExtractor data(bytes.data(), bytes.size(), eByteOrderLittle,
765 process->GetAddressByteSize());
766 lldb::offset_t offset = 0;
767 uint32_t build_id = data.GetU32(&offset);
768 s.Printf("Facebook Build ID:\n");
769 s.Printf("%u\n", build_id);
770 s.Printf("\n");
771 }
772 }
773 if (DumpFacebookVersionName())
Pavel Labathd2b48882019-03-25 14:09:27 +0000774 DumpTextStream(StreamType::FacebookAppVersionName,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000775 "Facebook Version String");
776 if (DumpFacebookJavaStack())
Pavel Labathd2b48882019-03-25 14:09:27 +0000777 DumpTextStream(StreamType::FacebookJavaStack,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000778 "Facebook Java Stack");
779 if (DumpFacebookDalvikInfo())
Pavel Labathd2b48882019-03-25 14:09:27 +0000780 DumpTextStream(StreamType::FacebookDalvikInfo,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000781 "Facebook Dalvik Info");
782 if (DumpFacebookUnwindSymbols())
Pavel Labathd2b48882019-03-25 14:09:27 +0000783 DumpBinaryStream(StreamType::FacebookUnwindSymbols,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000784 "Facebook Unwind Symbols Bytes");
785 if (DumpFacebookErrorLog())
Pavel Labathd2b48882019-03-25 14:09:27 +0000786 DumpTextStream(StreamType::FacebookDumpErrorLog,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000787 "Facebook Error Log");
788 if (DumpFacebookAppStateLog())
Pavel Labathd2b48882019-03-25 14:09:27 +0000789 DumpTextStream(StreamType::FacebookAppStateLog,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000790 "Faceook Application State Log");
791 if (DumpFacebookAbortReason())
Pavel Labathd2b48882019-03-25 14:09:27 +0000792 DumpTextStream(StreamType::FacebookAbortReason,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000793 "Facebook Abort Reason");
794 if (DumpFacebookThreadName())
Pavel Labathd2b48882019-03-25 14:09:27 +0000795 DumpTextStream(StreamType::FacebookThreadName,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000796 "Facebook Thread Name");
797 if (DumpFacebookLogcat())
Pavel Labathd2b48882019-03-25 14:09:27 +0000798 DumpTextStream(StreamType::FacebookLogcat,
Greg Claytoncc6ec692019-02-19 21:48:34 +0000799 "Facebook Logcat");
Greg Clayton48a28c12018-12-18 00:50:11 +0000800 return true;
801 }
802};
803
804class CommandObjectMultiwordProcessMinidump : public CommandObjectMultiword {
805public:
806 CommandObjectMultiwordProcessMinidump(CommandInterpreter &interpreter)
807 : CommandObjectMultiword(interpreter, "process plugin",
808 "Commands for operating on a ProcessMinidump process.",
809 "process plugin <subcommand> [<subcommand-options>]") {
810 LoadSubCommand("dump",
811 CommandObjectSP(new CommandObjectProcessMinidumpDump(interpreter)));
812 }
Leonard Mosescu0d057902019-01-07 17:55:42 +0000813
Raphael Isemann17566302019-05-03 10:03:28 +0000814 ~CommandObjectMultiwordProcessMinidump() override {}
Greg Clayton48a28c12018-12-18 00:50:11 +0000815};
816
817CommandObject *ProcessMinidump::GetPluginCommandObject() {
818 if (!m_command_sp)
Jonas Devlieghere796ac802019-02-11 23:13:08 +0000819 m_command_sp = std::make_shared<CommandObjectMultiwordProcessMinidump>(
820 GetTarget().GetDebugger().GetCommandInterpreter());
Greg Clayton48a28c12018-12-18 00:50:11 +0000821 return m_command_sp.get();
822}