2018-12-15 03:36:01 +08:00
|
|
|
//===-- MinidumpParser.h -----------------------------------------*- C++-*-===//
|
2016-09-01 19:29:53 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-09-01 19:29:53 +08:00
|
|
|
//
|
2016-10-06 02:11:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2016-09-01 19:29:53 +08:00
|
|
|
|
2020-02-18 07:57:45 +08:00
|
|
|
#ifndef LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
|
|
|
|
#define LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
|
2016-09-01 19:29:53 +08:00
|
|
|
|
|
|
|
#include "MinidumpTypes.h"
|
|
|
|
|
2018-12-20 23:05:43 +08:00
|
|
|
#include "lldb/Target/MemoryRegionInfo.h"
|
2017-11-14 00:16:33 +08:00
|
|
|
#include "lldb/Utility/ArchSpec.h"
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "lldb/Utility/DataBuffer.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2018-05-03 04:06:17 +08:00
|
|
|
#include "lldb/Utility/UUID.h"
|
2016-09-01 19:29:53 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/Optional.h"
|
2016-09-13 23:54:38 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2019-04-05 15:56:39 +08:00
|
|
|
#include "llvm/Object/Minidump.h"
|
2016-09-01 19:29:53 +08:00
|
|
|
|
|
|
|
// C includes
|
2016-10-06 02:11:45 +08:00
|
|
|
|
2016-09-01 19:29:53 +08:00
|
|
|
// C++ includes
|
2016-10-06 02:11:45 +08:00
|
|
|
#include <cstring>
|
|
|
|
#include <unordered_map>
|
2016-09-01 19:29:53 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
|
|
|
|
namespace minidump {
|
|
|
|
|
2016-10-19 22:14:18 +08:00
|
|
|
// Describes a range of memory captured in the Minidump
|
|
|
|
struct Range {
|
|
|
|
lldb::addr_t start; // virtual address of the beginning of the range
|
|
|
|
// range_ref - absolute pointer to the first byte of the range and size
|
|
|
|
llvm::ArrayRef<uint8_t> range_ref;
|
|
|
|
|
|
|
|
Range(lldb::addr_t start, llvm::ArrayRef<uint8_t> range_ref)
|
|
|
|
: start(start), range_ref(range_ref) {}
|
2019-05-20 16:22:59 +08:00
|
|
|
|
|
|
|
friend bool operator==(const Range &lhs, const Range &rhs) {
|
|
|
|
return lhs.start == rhs.start && lhs.range_ref == rhs.range_ref;
|
|
|
|
}
|
2016-10-19 22:14:18 +08:00
|
|
|
};
|
|
|
|
|
2016-09-01 19:29:53 +08:00
|
|
|
class MinidumpParser {
|
|
|
|
public:
|
2019-02-22 21:36:01 +08:00
|
|
|
static llvm::Expected<MinidumpParser>
|
2016-09-01 19:29:53 +08:00
|
|
|
Create(const lldb::DataBufferSP &data_buf_sp);
|
|
|
|
|
2016-09-28 03:05:55 +08:00
|
|
|
llvm::ArrayRef<uint8_t> GetData();
|
2016-09-01 19:29:53 +08:00
|
|
|
|
2019-03-25 22:09:27 +08:00
|
|
|
llvm::ArrayRef<uint8_t> GetStream(StreamType stream_type);
|
2016-09-01 19:29:53 +08:00
|
|
|
|
2019-04-10 19:07:28 +08:00
|
|
|
UUID GetModuleUUID(const minidump::Module *module);
|
2018-05-03 04:06:17 +08:00
|
|
|
|
2019-05-10 17:36:11 +08:00
|
|
|
llvm::ArrayRef<minidump::Thread> GetThreads();
|
2016-09-01 19:29:53 +08:00
|
|
|
|
2019-03-26 21:23:01 +08:00
|
|
|
llvm::ArrayRef<uint8_t> GetThreadContext(const LocationDescriptor &location);
|
2019-01-08 01:55:42 +08:00
|
|
|
|
2019-05-10 17:36:11 +08:00
|
|
|
llvm::ArrayRef<uint8_t> GetThreadContext(const minidump::Thread &td);
|
2016-10-19 22:14:18 +08:00
|
|
|
|
2019-05-10 17:36:11 +08:00
|
|
|
llvm::ArrayRef<uint8_t> GetThreadContextWow64(const minidump::Thread &td);
|
Minidump plugin: Adding ProcessMinidump, ThreadMinidump and register the plugin in SystemInitializerFull
Summary:
This plugin resembles the already existing Windows-only Minidump plugin.
The WinMinidumpPlugin uses the Windows API for parsing Minidumps
while this plugin is cross-platform because it includes a Minidump
parser (which is already commited)
It is able to produce a backtrace, to read the general puprose regiters,
inspect local variables, show image list, do memory reads, etc.
For now the only arches that this supports are x86_32 and x86_64.
This is because I have only written register contexts for those.
Others will come in next CLs.
I copied the WinMinidump tests and adapted them a little bit for them to
work with the new plugin (and they pass)
I will add more tests, aiming for better code coverage.
There is still functionality to be added, see TODOs in code.
Reviewers: labath, zturner
Subscribers: beanz, mgorny, modocache, lldb-commits, amccarth
Differential Revision: https://reviews.llvm.org/D25905
llvm-svn: 285587
2016-10-31 23:35:18 +08:00
|
|
|
|
2016-09-01 19:29:53 +08:00
|
|
|
ArchSpec GetArchitecture();
|
|
|
|
|
|
|
|
const MinidumpMiscInfo *GetMiscInfo();
|
|
|
|
|
2016-09-13 23:54:38 +08:00
|
|
|
llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
|
|
|
|
|
|
|
|
llvm::Optional<lldb::pid_t> GetPid();
|
|
|
|
|
2019-04-10 19:07:28 +08:00
|
|
|
llvm::ArrayRef<minidump::Module> GetModuleList();
|
2016-09-13 23:54:38 +08:00
|
|
|
|
2016-10-19 22:14:18 +08:00
|
|
|
// There are cases in which there is more than one record in the ModuleList
|
|
|
|
// for the same module name.(e.g. when the binary has non contiguous segments)
|
|
|
|
// So this function returns a filtered module list - if it finds records that
|
|
|
|
// have the same name, it keeps the copy with the lowest load address.
|
2019-04-10 19:07:28 +08:00
|
|
|
std::vector<const minidump::Module *> GetFilteredModuleList();
|
2016-10-19 22:14:18 +08:00
|
|
|
|
2019-10-18 22:59:10 +08:00
|
|
|
const llvm::minidump::ExceptionStream *GetExceptionStream();
|
2016-09-13 23:54:38 +08:00
|
|
|
|
2016-10-19 22:14:18 +08:00
|
|
|
llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
|
|
|
|
|
|
|
|
llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
|
|
|
|
|
2019-10-26 06:18:51 +08:00
|
|
|
/// Returns a list of memory regions and a flag indicating whether the list is
|
|
|
|
/// complete (includes all regions mapped into the process memory).
|
|
|
|
std::pair<MemoryRegionInfos, bool> BuildMemoryRegions();
|
2018-12-20 23:05:43 +08:00
|
|
|
|
2019-03-26 21:23:01 +08:00
|
|
|
static llvm::StringRef GetStreamTypeAsString(StreamType stream_type);
|
2018-12-18 08:50:11 +08:00
|
|
|
|
2019-04-05 15:56:39 +08:00
|
|
|
llvm::object::MinidumpFile &GetMinidumpFile() { return *m_file; }
|
2018-12-18 08:50:11 +08:00
|
|
|
|
2020-08-22 05:40:21 +08:00
|
|
|
static MemoryRegionInfo GetMemoryRegionInfo(const MemoryRegionInfos ®ions,
|
|
|
|
lldb::addr_t load_addr);
|
|
|
|
|
2018-07-13 01:27:18 +08:00
|
|
|
private:
|
2019-03-26 21:23:01 +08:00
|
|
|
MinidumpParser(lldb::DataBufferSP data_sp,
|
2019-04-05 15:56:39 +08:00
|
|
|
std::unique_ptr<llvm::object::MinidumpFile> file);
|
2018-07-13 01:27:18 +08:00
|
|
|
|
2016-09-01 19:29:53 +08:00
|
|
|
lldb::DataBufferSP m_data_sp;
|
2019-04-05 15:56:39 +08:00
|
|
|
std::unique_ptr<llvm::object::MinidumpFile> m_file;
|
2018-08-07 00:56:10 +08:00
|
|
|
ArchSpec m_arch;
|
2016-09-01 19:29:53 +08:00
|
|
|
};
|
|
|
|
|
2016-09-28 03:05:55 +08:00
|
|
|
} // end namespace minidump
|
|
|
|
} // end namespace lldb_private
|
2020-02-18 07:57:45 +08:00
|
|
|
#endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
|