1 // Copyright (c) 2012, Google Inc. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following disclaimer 12 // in the documentation and/or other materials provided with the 13 // distribution. 14 // * Neither the name of Google Inc. nor the names of its 15 // contributors may be used to endorse or promote products derived from 16 // this software without specific prior written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 // linux_ptrace_dumper.h: Define the google_breakpad::LinuxPtraceDumper 31 // class, which is derived from google_breakpad::LinuxDumper to extract 32 // information from a crashed process via ptrace. 33 // This class was originally splitted from google_breakpad::LinuxDumper. 34 35 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_LINUX_PTRACE_DUMPER_H_ 36 #define CLIENT_LINUX_MINIDUMP_WRITER_LINUX_PTRACE_DUMPER_H_ 37 38 #include "client/linux/minidump_writer/linux_dumper.h" 39 40 namespace google_breakpad { 41 42 class LinuxPtraceDumper : public LinuxDumper { 43 public: 44 // Constructs a dumper for extracting information of a given process 45 // with a process ID of |pid|. 46 explicit LinuxPtraceDumper(pid_t pid); 47 48 // Implements LinuxDumper::BuildProcPath(). 49 // Builds a proc path for a certain pid for a node (/proc/<pid>/<node>). 50 // |path| is a character array of at least NAME_MAX bytes to return the 51 // result. |node| is the final node without any slashes. Returns true on 52 // success. 53 virtual bool BuildProcPath(char* path, pid_t pid, const char* node) const; 54 55 // Implements LinuxDumper::CopyFromProcess(). 56 // Copies content of |length| bytes from a given process |child|, 57 // starting from |src|, into |dest|. This method uses ptrace to extract 58 // the content from the target process. Always returns true. 59 virtual bool CopyFromProcess(void* dest, pid_t child, const void* src, 60 size_t length); 61 62 // Implements LinuxDumper::GetThreadInfoByIndex(). 63 // Reads information about the |index|-th thread of |threads_|. 64 // Returns true on success. One must have called |ThreadsSuspend| first. 65 virtual bool GetThreadInfoByIndex(size_t index, ThreadInfo* info); 66 67 // Implements LinuxDumper::IsPostMortem(). 68 // Always returns false to indicate this dumper performs a dump of 69 // a crashed process via ptrace. 70 virtual bool IsPostMortem() const; 71 72 // Implements LinuxDumper::ThreadsSuspend(). 73 // Suspends all threads in the given process. Returns true on success. 74 virtual bool ThreadsSuspend(); 75 76 // Implements LinuxDumper::ThreadsResume(). 77 // Resumes all threads in the given process. Returns true on success. 78 virtual bool ThreadsResume(); 79 80 protected: 81 // Implements LinuxDumper::EnumerateThreads(). 82 // Enumerates all threads of the given process into |threads_|. 83 virtual bool EnumerateThreads(); 84 85 private: 86 // Set to true if all threads of the crashed process are suspended. 87 bool threads_suspended_; 88 }; 89 90 } // namespace google_breakpad 91 92 #endif // CLIENT_LINUX_HANDLER_LINUX_PTRACE_DUMPER_H_ 93