Planeshift

linux_ptrace_dumper.h

Go to the documentation of this file.
00001 // Copyright (c) 2012, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030 // linux_ptrace_dumper.h: Define the google_breakpad::LinuxPtraceDumper
00031 // class, which is derived from google_breakpad::LinuxDumper to extract
00032 // information from a crashed process via ptrace.
00033 // This class was originally splitted from google_breakpad::LinuxDumper.
00034 
00035 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_LINUX_PTRACE_DUMPER_H_
00036 #define CLIENT_LINUX_MINIDUMP_WRITER_LINUX_PTRACE_DUMPER_H_
00037 
00038 #include "client/linux/minidump_writer/linux_dumper.h"
00039 
00040 namespace google_breakpad {
00041 
00042 class LinuxPtraceDumper : public LinuxDumper {
00043  public:
00044   // Constructs a dumper for extracting information of a given process
00045   // with a process ID of |pid|.
00046   explicit LinuxPtraceDumper(pid_t pid);
00047 
00048   // Implements LinuxDumper::BuildProcPath().
00049   // Builds a proc path for a certain pid for a node (/proc/<pid>/<node>).
00050   // |path| is a character array of at least NAME_MAX bytes to return the
00051   // result. |node| is the final node without any slashes. Returns true on
00052   // success.
00053   virtual bool BuildProcPath(char* path, pid_t pid, const char* node) const;
00054 
00055   // Implements LinuxDumper::CopyFromProcess().
00056   // Copies content of |length| bytes from a given process |child|,
00057   // starting from |src|, into |dest|. This method uses ptrace to extract
00058   // the content from the target process.
00059   virtual void CopyFromProcess(void* dest, pid_t child, const void* src,
00060                                size_t length);
00061 
00062   // Implements LinuxDumper::GetThreadInfoByIndex().
00063   // Reads information about the |index|-th thread of |threads_|.
00064   // Returns true on success. One must have called |ThreadsSuspend| first.
00065   virtual bool GetThreadInfoByIndex(size_t index, ThreadInfo* info);
00066 
00067   // Implements LinuxDumper::IsPostMortem().
00068   // Always returns false to indicate this dumper performs a dump of
00069   // a crashed process via ptrace.
00070   virtual bool IsPostMortem() const;
00071 
00072   // Implements LinuxDumper::ThreadsSuspend().
00073   // Suspends all threads in the given process. Returns true on success.
00074   virtual bool ThreadsSuspend();
00075 
00076   // Implements LinuxDumper::ThreadsResume().
00077   // Resumes all threads in the given process. Returns true on success.
00078   virtual bool ThreadsResume();
00079 
00080  protected:
00081   // Implements LinuxDumper::EnumerateThreads().
00082   // Enumerates all threads of the given process into |threads_|.
00083   virtual bool EnumerateThreads();
00084 
00085  private:
00086   // Set to true if all threads of the crashed process are suspended.
00087   bool threads_suspended_;
00088 };
00089 
00090 }  // namespace google_breakpad
00091 
00092 #endif  // CLIENT_LINUX_HANDLER_LINUX_PTRACE_DUMPER_H_