LLDB  mainline
MinidumpTypes.cpp
Go to the documentation of this file.
1 //===-- MinidumpTypes.cpp -------------------------------------------------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "MinidumpTypes.h"
10 #include <optional>
11 
12 // C includes
13 // C++ includes
14 
15 using namespace lldb_private;
16 using namespace minidump;
17 
18 // MinidumpMiscInfo
19 const MinidumpMiscInfo *MinidumpMiscInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
20  const MinidumpMiscInfo *misc_info;
21  Status error = consumeObject(data, misc_info);
22  if (error.Fail())
23  return nullptr;
24 
25  return misc_info;
26 }
27 
28 std::optional<lldb::pid_t> MinidumpMiscInfo::GetPid() const {
29  uint32_t pid_flag = static_cast<uint32_t>(MinidumpMiscInfoFlags::ProcessID);
30  if (flags1 & pid_flag)
31  return std::optional<lldb::pid_t>(process_id);
32 
33  return std::nullopt;
34 }
35 
36 // Linux Proc Status
37 // it's stored as an ascii string in the file
38 std::optional<LinuxProcStatus>
39 LinuxProcStatus::Parse(llvm::ArrayRef<uint8_t> &data) {
40  LinuxProcStatus result;
41  result.proc_status =
42  llvm::StringRef(reinterpret_cast<const char *>(data.data()), data.size());
43  data = data.drop_front(data.size());
44 
45  llvm::SmallVector<llvm::StringRef, 0> lines;
46  result.proc_status.split(lines, '\n', 42);
47  // /proc/$pid/status has 41 lines, but why not use 42?
48  for (auto line : lines) {
49  if (line.consume_front("Pid:")) {
50  line = line.trim();
51  if (!line.getAsInteger(10, result.pid))
52  return result;
53  }
54  }
55 
56  return std::nullopt;
57 }
58 
60 
61 std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
62 MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) {
63  const llvm::support::ulittle64_t *mem_ranges_count;
64  Status error = consumeObject(data, mem_ranges_count);
65  if (error.Fail() ||
66  *mem_ranges_count * sizeof(MinidumpMemoryDescriptor64) > data.size())
67  return {};
68 
69  const llvm::support::ulittle64_t *base_rva;
70  error = consumeObject(data, base_rva);
71  if (error.Fail())
72  return {};
73 
74  return std::make_pair(
75  llvm::ArrayRef(
76  reinterpret_cast<const MinidumpMemoryDescriptor64 *>(data.data()),
77  *mem_ranges_count),
78  *base_rva);
79 }
lldb_private::minidump::MinidumpMiscInfo
Definition: MinidumpTypes.h:75
lldb_private::minidump::MinidumpMemoryDescriptor64::ParseMemory64List
static std::pair< llvm::ArrayRef< MinidumpMemoryDescriptor64 >, uint64_t > ParseMemory64List(llvm::ArrayRef< uint8_t > &data)
Definition: MinidumpTypes.cpp:62
lldb_private::minidump::MinidumpMiscInfoFlags::ProcessID
@ ProcessID
lldb_private::minidump::MinidumpMiscInfo::process_id
llvm::support::ulittle32_t process_id
Definition: MinidumpTypes.h:79
MinidumpTypes.h
lldb_private::minidump::LinuxProcStatus::Parse
static std::optional< LinuxProcStatus > Parse(llvm::ArrayRef< uint8_t > &data)
Definition: MinidumpTypes.cpp:39
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::minidump::LinuxProcStatus::proc_status
llvm::StringRef proc_status
Definition: MinidumpTypes.h:94
lldb_private::minidump::LinuxProcStatus
Definition: MinidumpTypes.h:92
lldb_private::minidump::MinidumpMiscInfo::GetPid
std::optional< lldb::pid_t > GetPid() const
Definition: MinidumpTypes.cpp:28
lldb_private::minidump::LinuxProcStatus::GetPid
lldb::pid_t GetPid() const
Definition: MinidumpTypes.cpp:59
lldb_private::minidump::MinidumpMiscInfo::flags1
llvm::support::ulittle32_t flags1
Definition: MinidumpTypes.h:78
lldb_private::Status
Definition: Status.h:44
uint32_t
lldb_private::minidump::MinidumpMiscInfo::Parse
static const MinidumpMiscInfo * Parse(llvm::ArrayRef< uint8_t > &data)
Definition: MinidumpTypes.cpp:19
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::minidump::MinidumpMemoryDescriptor64
Definition: MinidumpTypes.h:62
lldb_private::minidump::consumeObject
Status consumeObject(llvm::ArrayRef< uint8_t > &Buffer, const T *&Object)
Definition: MinidumpTypes.h:50
lldb_private::minidump::LinuxProcStatus::pid
lldb::pid_t pid
Definition: MinidumpTypes.h:95
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16