1 // Copyright 2012 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 // linux_core_dumper.h: Define the google_breakpad::LinuxCoreDumper 30 // class, which is derived from google_breakpad::LinuxDumper to extract 31 // information from a crashed process via its core dump and proc files. 32 33 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_LINUX_CORE_DUMPER_H_ 34 #define CLIENT_LINUX_MINIDUMP_WRITER_LINUX_CORE_DUMPER_H_ 35 36 #include "client/linux/minidump_writer/linux_dumper.h" 37 #include "common/linux/elf_core_dump.h" 38 #include "common/linux/memory_mapped_file.h" 39 40 namespace google_breakpad { 41 42 class LinuxCoreDumper : public LinuxDumper { 43 public: 44 // Constructs a dumper for extracting information of a given process 45 // with a process ID of |pid| via its core dump file at |core_path| and 46 // its proc files at |procfs_path|. If |procfs_path| is a copy of 47 // /proc/<pid>, it should contain the following files: 48 // auxv, cmdline, environ, exe, maps, status 49 // See LinuxDumper for the purpose of |root_prefix|. 50 LinuxCoreDumper(pid_t pid, const char* core_path, const char* procfs_path, 51 const char* root_prefix = ""); 52 53 // Implements LinuxDumper::BuildProcPath(). 54 // Builds a proc path for a certain pid for a node (/proc/<pid>/<node>). 55 // |path| is a character array of at least NAME_MAX bytes to return the 56 // result.|node| is the final node without any slashes. Return true on 57 // success. 58 // 59 // As this dumper performs a post-mortem dump and makes use of a copy 60 // of the proc files of the crashed process, this derived method does 61 // not actually make use of |pid| and always returns a subpath of 62 // |procfs_path_| regardless of whether |pid| corresponds to the main 63 // process or a thread of the process, i.e. assuming both the main process 64 // and its threads have the following proc files with the same content: 65 // auxv, cmdline, environ, exe, maps, status 66 virtual bool BuildProcPath(char* path, pid_t pid, const char* node) const; 67 68 // Implements LinuxDumper::CopyFromProcess(). 69 // Copies content of |length| bytes from a given process |child|, 70 // starting from |src|, into |dest|. This method extracts the content 71 // the core dump and fills |dest| with a sequence of marker bytes 72 // if the expected data is not found in the core dump. Returns true if 73 // the expected data is found in the core dump. 74 virtual bool CopyFromProcess(void* dest, pid_t child, const void* src, 75 size_t length); 76 77 // Implements LinuxDumper::GetThreadInfoByIndex(). 78 // Reads information about the |index|-th thread of |threads_|. 79 // Returns true on success. One must have called |ThreadsSuspend| first. 80 virtual bool GetThreadInfoByIndex(size_t index, ThreadInfo* info); 81 82 // Implements LinuxDumper::IsPostMortem(). 83 // Always returns true to indicate that this dumper performs a 84 // post-mortem dump of a crashed process via a core dump file. 85 virtual bool IsPostMortem() const; 86 87 // Implements LinuxDumper::ThreadsSuspend(). 88 // As the dumper performs a post-mortem dump via a core dump file, 89 // there is no threads to suspend. This method does nothing and 90 // always returns true. 91 virtual bool ThreadsSuspend(); 92 93 // Implements LinuxDumper::ThreadsResume(). 94 // As the dumper performs a post-mortem dump via a core dump file, 95 // there is no threads to resume. This method does nothing and 96 // always returns true. 97 virtual bool ThreadsResume(); 98 99 protected: 100 // Implements LinuxDumper::EnumerateThreads(). 101 // Enumerates all threads of the given process into |threads_|. 102 virtual bool EnumerateThreads(); 103 104 private: 105 // Path of the core dump file. 106 const char* core_path_; 107 108 // Path of the directory containing the proc files of the given process, 109 // which is usually a copy of /proc/<pid>. 110 const char* procfs_path_; 111 112 // Memory-mapped core dump file at |core_path_|. 113 MemoryMappedFile mapped_core_file_; 114 115 // Content of the core dump file. 116 ElfCoreDump core_; 117 118 // Thread info found in the core dump file. 119 wasteful_vector<ThreadInfo> thread_infos_; 120 }; 121 122 } // namespace google_breakpad 123 124 #endif // CLIENT_LINUX_HANDLER_LINUX_CORE_DUMPER_H_ 125