| 1 | //===-- SBSaveCoreOptions.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_API_SBSAVECOREOPTIONS_H |
| 10 | #define LLDB_API_SBSAVECOREOPTIONS_H |
| 11 | |
| 12 | #include "lldb/API/SBDefines.h" |
| 13 | #include "lldb/API/SBError.h" |
| 14 | #include "lldb/API/SBFileSpec.h" |
| 15 | #include "lldb/API/SBProcess.h" |
| 16 | #include "lldb/API/SBThread.h" |
| 17 | #include "lldb/API/SBThreadCollection.h" |
| 18 | |
| 19 | namespace lldb { |
| 20 | |
| 21 | class LLDB_API SBSaveCoreOptions { |
| 22 | public: |
| 23 | SBSaveCoreOptions(); |
| 24 | SBSaveCoreOptions(const lldb::SBSaveCoreOptions &rhs); |
| 25 | ~SBSaveCoreOptions(); |
| 26 | |
| 27 | const SBSaveCoreOptions &operator=(const lldb::SBSaveCoreOptions &rhs); |
| 28 | |
| 29 | /// Set the plugin name. Supplying null or empty string will reset |
| 30 | /// the option. |
| 31 | /// |
| 32 | /// \param plugin |
| 33 | /// Name of the object file plugin. |
| 34 | SBError SetPluginName(const char *plugin); |
| 35 | |
| 36 | /// Get the Core dump plugin name, if set. |
| 37 | /// |
| 38 | /// \return |
| 39 | /// The name of the plugin, or null if not set. |
| 40 | const char *GetPluginName() const; |
| 41 | |
| 42 | /// Set the Core dump style. |
| 43 | /// |
| 44 | /// \param style |
| 45 | /// The style of the core dump. |
| 46 | void SetStyle(lldb::SaveCoreStyle style); |
| 47 | |
| 48 | /// Get the Core dump style, if set. |
| 49 | /// |
| 50 | /// \return |
| 51 | /// The core dump style, or undefined if not set. |
| 52 | lldb::SaveCoreStyle GetStyle() const; |
| 53 | |
| 54 | /// Set the output file path |
| 55 | /// |
| 56 | /// \param |
| 57 | /// output_file a \ref SBFileSpec object that describes the output file. |
| 58 | void SetOutputFile(SBFileSpec output_file); |
| 59 | |
| 60 | /// Get the output file spec |
| 61 | /// |
| 62 | /// \return |
| 63 | /// The output file spec. |
| 64 | SBFileSpec GetOutputFile() const; |
| 65 | |
| 66 | /// Set the process to save, or unset if supplied with a default constructed |
| 67 | /// process. |
| 68 | /// |
| 69 | /// \param process |
| 70 | /// The process to save. |
| 71 | /// |
| 72 | /// \return |
| 73 | /// Success if process was set, otherwise an error |
| 74 | /// |
| 75 | /// \note |
| 76 | /// This will clear all process specific options if a different process |
| 77 | /// is specified than the current set process, either explicitly from this |
| 78 | /// api, or implicitly from any function that requires a process. |
| 79 | SBError SetProcess(lldb::SBProcess process); |
| 80 | |
| 81 | /// Add a thread to save in the core file. |
| 82 | /// |
| 83 | /// \param thread |
| 84 | /// The thread to save. |
| 85 | /// |
| 86 | /// \note |
| 87 | /// This will set the process if it is not already set, or return |
| 88 | /// and error if the SBThread is not from the set process. |
| 89 | SBError AddThread(lldb::SBThread thread); |
| 90 | |
| 91 | /// Remove a thread from the list of threads to save. |
| 92 | /// |
| 93 | /// \param thread |
| 94 | /// The thread to remove. |
| 95 | /// |
| 96 | /// \return |
| 97 | /// True if the thread was removed, false if it was not in the list. |
| 98 | bool RemoveThread(lldb::SBThread thread); |
| 99 | |
| 100 | /// Add a memory region to save in the core file. |
| 101 | /// |
| 102 | /// \param region |
| 103 | /// The memory region to save. |
| 104 | /// |
| 105 | /// \returns |
| 106 | /// An empty SBError upon success, or an error if the region is invalid. |
| 107 | /// |
| 108 | /// \note |
| 109 | /// Ranges that overlapped will be unioned into a single region, this also |
| 110 | /// supercedes stack minification. Specifying full regions and a non-custom |
| 111 | /// core style will include the specified regions and union them with all |
| 112 | /// style specific regions. |
| 113 | SBError AddMemoryRegionToSave(const SBMemoryRegionInfo ®ion); |
| 114 | |
| 115 | /// Get an unsorted copy of all threads to save |
| 116 | /// |
| 117 | /// \returns |
| 118 | /// An unsorted copy of all threads to save. If no process is specified |
| 119 | /// an empty collection will be returned. |
| 120 | SBThreadCollection GetThreadsToSave() const; |
| 121 | |
| 122 | /// Get the current total number of bytes the core is expected to have |
| 123 | /// excluding the overhead of the core file format. Requires a Process and |
| 124 | /// Style to be specified. |
| 125 | /// |
| 126 | /// \note |
| 127 | /// This can cause some modification of the underlying data store |
| 128 | /// as regions with no permissions, or invalid permissions will be removed |
| 129 | /// and stacks will be minified up to their stack pointer + the redzone. |
| 130 | /// |
| 131 | /// \returns |
| 132 | /// The expected size of the data contained in the core in bytes. |
| 133 | uint64_t GetCurrentSizeInBytes(SBError &error); |
| 134 | |
| 135 | /// Reset all options. |
| 136 | void Clear(); |
| 137 | |
| 138 | protected: |
| 139 | friend class SBProcess; |
| 140 | friend class SBThreadCollection; |
| 141 | lldb_private::SaveCoreOptions &ref() const; |
| 142 | |
| 143 | private: |
| 144 | std::unique_ptr<lldb_private::SaveCoreOptions> m_opaque_up; |
| 145 | }; // SBSaveCoreOptions |
| 146 | } // namespace lldb |
| 147 | |
| 148 | #endif // LLDB_API_SBSAVECOREOPTIONS_H |
| 149 | |