File: | src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp |
Warning: | line 65, column 7 Called C++ object pointer is uninitialized |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | ||||
11 | // C includes | |||
12 | // C++ includes | |||
13 | ||||
14 | using namespace lldb_private; | |||
15 | using namespace minidump; | |||
16 | ||||
17 | // MinidumpMiscInfo | |||
18 | const MinidumpMiscInfo *MinidumpMiscInfo::Parse(llvm::ArrayRef<uint8_t> &data) { | |||
19 | const MinidumpMiscInfo *misc_info; | |||
20 | Status error = consumeObject(data, misc_info); | |||
21 | if (error.Fail()) | |||
22 | return nullptr; | |||
23 | ||||
24 | return misc_info; | |||
25 | } | |||
26 | ||||
27 | llvm::Optional<lldb::pid_t> MinidumpMiscInfo::GetPid() const { | |||
28 | uint32_t pid_flag = static_cast<uint32_t>(MinidumpMiscInfoFlags::ProcessID); | |||
29 | if (flags1 & pid_flag) | |||
30 | return llvm::Optional<lldb::pid_t>(process_id); | |||
31 | ||||
32 | return llvm::None; | |||
33 | } | |||
34 | ||||
35 | // Linux Proc Status | |||
36 | // it's stored as an ascii string in the file | |||
37 | llvm::Optional<LinuxProcStatus> | |||
38 | LinuxProcStatus::Parse(llvm::ArrayRef<uint8_t> &data) { | |||
39 | LinuxProcStatus result; | |||
40 | result.proc_status = | |||
41 | llvm::StringRef(reinterpret_cast<const char *>(data.data()), data.size()); | |||
42 | data = data.drop_front(data.size()); | |||
43 | ||||
44 | llvm::SmallVector<llvm::StringRef, 0> lines; | |||
45 | result.proc_status.split(lines, '\n', 42); | |||
46 | // /proc/$pid/status has 41 lines, but why not use 42? | |||
47 | for (auto line : lines) { | |||
48 | if (line.consume_front("Pid:")) { | |||
49 | line = line.trim(); | |||
50 | if (!line.getAsInteger(10, result.pid)) | |||
51 | return result; | |||
52 | } | |||
53 | } | |||
54 | ||||
55 | return llvm::None; | |||
56 | } | |||
57 | ||||
58 | lldb::pid_t LinuxProcStatus::GetPid() const { return pid; } | |||
59 | ||||
60 | std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t> | |||
61 | MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) { | |||
62 | const llvm::support::ulittle64_t *mem_ranges_count; | |||
| ||||
63 | Status error = consumeObject(data, mem_ranges_count); | |||
64 | if (error.Fail() || | |||
65 | *mem_ranges_count * sizeof(MinidumpMemoryDescriptor64) > data.size()) | |||
| ||||
66 | return {}; | |||
67 | ||||
68 | const llvm::support::ulittle64_t *base_rva; | |||
69 | error = consumeObject(data, base_rva); | |||
70 | if (error.Fail()) | |||
71 | return {}; | |||
72 | ||||
73 | return std::make_pair( | |||
74 | llvm::makeArrayRef( | |||
75 | reinterpret_cast<const MinidumpMemoryDescriptor64 *>(data.data()), | |||
76 | *mem_ranges_count), | |||
77 | *base_rva); | |||
78 | } |
1 | //===-- MinidumpTypes.h -----------------------------------------*- C++ -*-===// |
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 | #ifndef LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H |
10 | #define LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H |
11 | |
12 | #include "lldb/Utility/Status.h" |
13 | |
14 | #include "llvm/ADT/ArrayRef.h" |
15 | #include "llvm/ADT/BitmaskEnum.h" |
16 | #include "llvm/ADT/Optional.h" |
17 | #include "llvm/ADT/SmallVector.h" |
18 | #include "llvm/ADT/StringRef.h" |
19 | #include "llvm/BinaryFormat/Minidump.h" |
20 | #include "llvm/Support/ConvertUTF.h" |
21 | #include "llvm/Support/Endian.h" |
22 | |
23 | // C includes |
24 | // C++ includes |
25 | |
26 | // Reference: |
27 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms679293(v=vs.85).aspx |
28 | // https://chromium.googlesource.com/breakpad/breakpad/ |
29 | |
30 | namespace lldb_private { |
31 | |
32 | namespace minidump { |
33 | |
34 | using namespace llvm::minidump; |
35 | |
36 | LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()using ::llvm::BitmaskEnumDetail::operator~; using ::llvm::BitmaskEnumDetail ::operator|; using ::llvm::BitmaskEnumDetail::operator&; using ::llvm::BitmaskEnumDetail::operator^; using ::llvm::BitmaskEnumDetail ::operator|=; using ::llvm::BitmaskEnumDetail::operator&= ; using ::llvm::BitmaskEnumDetail::operator^=; |
37 | |
38 | enum class CvSignature : uint32_t { |
39 | Pdb70 = 0x53445352, // RSDS |
40 | ElfBuildId = 0x4270454c, // BpEL (Breakpad/Crashpad minidumps) |
41 | }; |
42 | |
43 | enum class MinidumpMiscInfoFlags : uint32_t { |
44 | ProcessID = (1 << 0), |
45 | ProcessTimes = (1 << 1), |
46 | LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ ProcessTimes)LLVM_BITMASK_LARGEST_ENUMERATOR = ProcessTimes |
47 | }; |
48 | |
49 | template <typename T> |
50 | Status consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) { |
51 | Status error; |
52 | if (Buffer.size() < sizeof(T)) { |
53 | error.SetErrorString("Insufficient buffer!"); |
54 | return error; |
55 | } |
56 | |
57 | Object = reinterpret_cast<const T *>(Buffer.data()); |
58 | Buffer = Buffer.drop_front(sizeof(T)); |
59 | return error; |
60 | } |
61 | |
62 | struct MinidumpMemoryDescriptor64 { |
63 | llvm::support::ulittle64_t start_of_memory_range; |
64 | llvm::support::ulittle64_t data_size; |
65 | |
66 | static std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t> |
67 | ParseMemory64List(llvm::ArrayRef<uint8_t> &data); |
68 | }; |
69 | static_assert(sizeof(MinidumpMemoryDescriptor64) == 16, |
70 | "sizeof MinidumpMemoryDescriptor64 is not correct!"); |
71 | |
72 | // TODO misc2, misc3 ? |
73 | // Reference: |
74 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms680389(v=vs.85).aspx |
75 | struct MinidumpMiscInfo { |
76 | llvm::support::ulittle32_t size; |
77 | // flags1 represents what info in the struct is valid |
78 | llvm::support::ulittle32_t flags1; |
79 | llvm::support::ulittle32_t process_id; |
80 | llvm::support::ulittle32_t process_create_time; |
81 | llvm::support::ulittle32_t process_user_time; |
82 | llvm::support::ulittle32_t process_kernel_time; |
83 | |
84 | static const MinidumpMiscInfo *Parse(llvm::ArrayRef<uint8_t> &data); |
85 | |
86 | llvm::Optional<lldb::pid_t> GetPid() const; |
87 | }; |
88 | static_assert(sizeof(MinidumpMiscInfo) == 24, |
89 | "sizeof MinidumpMiscInfo is not correct!"); |
90 | |
91 | // The /proc/pid/status is saved as an ascii string in the file |
92 | class LinuxProcStatus { |
93 | public: |
94 | llvm::StringRef proc_status; |
95 | lldb::pid_t pid; |
96 | |
97 | static llvm::Optional<LinuxProcStatus> Parse(llvm::ArrayRef<uint8_t> &data); |
98 | |
99 | lldb::pid_t GetPid() const; |
100 | |
101 | private: |
102 | LinuxProcStatus() = default; |
103 | }; |
104 | |
105 | } // namespace minidump |
106 | } // namespace lldb_private |
107 | #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H |