LLDB  mainline
MinidumpFileBuilder.h
Go to the documentation of this file.
1 //===-- MinidumpFileBuilder.h ---------------------------------------------===//
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 /// \file
10 /// Structure holding data neccessary for minidump file creation.
11 ///
12 /// The class MinidumpFileWriter is used to hold the data that will eventually
13 /// be dumped to the file.
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_MINIDUMP_MINIDUMPFILEBUILDER_H
17 #define LLDB_SOURCE_PLUGINS_OBJECTFILE_MINIDUMP_MINIDUMPFILEBUILDER_H
18 
19 #include <cstddef>
20 
21 #include "lldb/Target/Target.h"
23 #include "lldb/Utility/Status.h"
24 
25 #include "llvm/Object/Minidump.h"
26 
27 // Write std::string to minidump in the UTF16 format(with null termination char)
28 // with the size(without null termination char) preceding the UTF16 string.
29 // Empty strings are also printed with zero length and just null termination
30 // char.
33 
34 /// \class MinidumpFileBuilder
35 /// Minidump writer for Linux
36 ///
37 /// This class provides a Minidump writer that is able to
38 /// snapshot the current process state. For the whole time, it stores all
39 /// the data on heap.
41 public:
42  MinidumpFileBuilder() = default;
43 
44  MinidumpFileBuilder(const MinidumpFileBuilder &) = delete;
46 
47  MinidumpFileBuilder(MinidumpFileBuilder &&other) = default;
49 
50  ~MinidumpFileBuilder() = default;
51 
52  // Add SystemInfo stream, used for storing the most basic information
53  // about the system, platform etc...
54  lldb_private::Status AddSystemInfo(const llvm::Triple &target_triple);
55  // Add ModuleList stream, containing information about all loaded modules
56  // at the time of saving minidump.
58  // Add ThreadList stream, containing information about all threads running
59  // at the moment of core saving. Contains information about thread
60  // contexts.
61  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
62  // Add Exception stream, this contains information about the exception
63  // that stopped the process. In case no thread made exception it return
64  // failed status.
65  lldb_private::Status AddException(const lldb::ProcessSP &process_sp);
66  // Add MemoryList stream, containing dumps of important memory segments
67  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp);
68  // Add MiscInfo stream, mainly providing ProcessId
69  void AddMiscInfo(const lldb::ProcessSP &process_sp);
70  // Add informative files about a Linux process
71  void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
72  // Dump the prepared data into file. In case of the failure data are
73  // intact.
74  lldb_private::Status Dump(lldb::FileUP &core_file) const;
75  // Returns the current number of directories(streams) that have been so far
76  // created. This number of directories will be dumped when calling Dump()
77  size_t GetDirectoriesNum() const;
78 
79 private:
80  // Add directory of StreamType pointing to the current end of the prepared
81  // file with the specified size.
82  void AddDirectory(llvm::minidump::StreamType type, size_t stream_size);
83  size_t GetCurrentDataEndOffset() const;
84 
85  // Stores directories to later put them at the end of minidump file
86  std::vector<llvm::minidump::Directory> m_directories;
87  // Main data buffer consisting of data without the minidump header and
88  // directories
90 };
91 
92 #endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_MINIDUMP_MINIDUMPFILEBUILDER_H
MinidumpFileBuilder::AddMemoryList
lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp)
Definition: MinidumpFileBuilder.cpp:558
MinidumpFileBuilder::AddMiscInfo
void AddMiscInfo(const lldb::ProcessSP &process_sp)
Definition: MinidumpFileBuilder.cpp:628
MinidumpFileBuilder::m_directories
std::vector< llvm::minidump::Directory > m_directories
Definition: MinidumpFileBuilder.h:86
MinidumpFileBuilder::operator=
MinidumpFileBuilder & operator=(const MinidumpFileBuilder &)=delete
WriteString
lldb_private::Status WriteString(const std::string &to_write, lldb_private::DataBufferHeap *buffer)
Definition: MinidumpFileBuilder.cpp:129
lldb_private::Target
Definition: Target.h:451
MinidumpFileBuilder::AddException
lldb_private::Status AddException(const lldb::ProcessSP &process_sp)
Definition: MinidumpFileBuilder.cpp:493
Target.h
MinidumpFileBuilder
Definition: MinidumpFileBuilder.h:40
MinidumpFileBuilder::GetCurrentDataEndOffset
size_t GetCurrentDataEndOffset() const
Definition: MinidumpFileBuilder.cpp:770
MinidumpFileBuilder::~MinidumpFileBuilder
~MinidumpFileBuilder()=default
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
MinidumpFileBuilder::AddThreadList
lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp)
Definition: MinidumpFileBuilder.cpp:404
MinidumpFileBuilder::Dump
lldb_private::Status Dump(lldb::FileUP &core_file) const
Definition: MinidumpFileBuilder.cpp:705
MinidumpFileBuilder::GetDirectoriesNum
size_t GetDirectoriesNum() const
Definition: MinidumpFileBuilder.cpp:766
lldb_private::Status
Definition: Status.h:44
MinidumpFileBuilder::m_data
lldb_private::DataBufferHeap m_data
Definition: MinidumpFileBuilder.h:89
Status.h
MinidumpFileBuilder::AddSystemInfo
lldb_private::Status AddSystemInfo(const llvm::Triple &target_triple)
Definition: MinidumpFileBuilder.cpp:50
MinidumpFileBuilder::MinidumpFileBuilder
MinidumpFileBuilder()=default
MinidumpFileBuilder::AddModuleList
lldb_private::Status AddModuleList(lldb_private::Target &target)
Definition: MinidumpFileBuilder.cpp:194
MinidumpFileBuilder::AddDirectory
void AddDirectory(llvm::minidump::StreamType type, size_t stream_size)
Definition: MinidumpFileBuilder.cpp:37
MinidumpFileBuilder::AddLinuxFileStreams
void AddLinuxFileStreams(const lldb::ProcessSP &process_sp)
Definition: MinidumpFileBuilder.cpp:662
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
DataBufferHeap.h