xref: /aosp_15_r20/external/google-breakpad/src/client/linux/minidump_writer/linux_ptrace_dumper.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
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_ptrace_dumper.h: Define the google_breakpad::LinuxPtraceDumper
30 // class, which is derived from google_breakpad::LinuxDumper to extract
31 // information from a crashed process via ptrace.
32 // This class was originally splitted from google_breakpad::LinuxDumper.
33 
34 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_LINUX_PTRACE_DUMPER_H_
35 #define CLIENT_LINUX_MINIDUMP_WRITER_LINUX_PTRACE_DUMPER_H_
36 
37 #include "client/linux/minidump_writer/linux_dumper.h"
38 
39 namespace google_breakpad {
40 
41 class LinuxPtraceDumper : public LinuxDumper {
42  public:
43   // Constructs a dumper for extracting information of a given process
44   // with a process ID of |pid|.
45   explicit LinuxPtraceDumper(pid_t pid);
46 
47   // Implements LinuxDumper::BuildProcPath().
48   // Builds a proc path for a certain pid for a node (/proc/<pid>/<node>).
49   // |path| is a character array of at least NAME_MAX bytes to return the
50   // result. |node| is the final node without any slashes. Returns true on
51   // success.
52   virtual bool BuildProcPath(char* path, pid_t pid, const char* node) const;
53 
54   // Implements LinuxDumper::CopyFromProcess().
55   // Copies content of |length| bytes from a given process |child|,
56   // starting from |src|, into |dest|. This method uses ptrace to extract
57   // the content from the target process. Always returns true.
58   virtual bool CopyFromProcess(void* dest, pid_t child, const void* src,
59                                size_t length);
60 
61   // Implements LinuxDumper::GetThreadInfoByIndex().
62   // Reads information about the |index|-th thread of |threads_|.
63   // Returns true on success. One must have called |ThreadsSuspend| first.
64   virtual bool GetThreadInfoByIndex(size_t index, ThreadInfo* info);
65 
66   // Implements LinuxDumper::IsPostMortem().
67   // Always returns false to indicate this dumper performs a dump of
68   // a crashed process via ptrace.
69   virtual bool IsPostMortem() const;
70 
71   // Implements LinuxDumper::ThreadsSuspend().
72   // Suspends all threads in the given process. Returns true on success.
73   virtual bool ThreadsSuspend();
74 
75   // Implements LinuxDumper::ThreadsResume().
76   // Resumes all threads in the given process. Returns true on success.
77   virtual bool ThreadsResume();
78 
79  protected:
80   // Implements LinuxDumper::EnumerateThreads().
81   // Enumerates all threads of the given process into |threads_|.
82   virtual bool EnumerateThreads();
83 
84  private:
85   // Set to true if all threads of the crashed process are suspended.
86   bool threads_suspended_;
87 
88   // Read the tracee's registers on kernel with PTRACE_GETREGSET support.
89   // Returns false if PTRACE_GETREGSET is not defined.
90   // Returns true on success.
91   bool ReadRegisterSet(ThreadInfo* info, pid_t tid);
92 
93   // Read the tracee's registers on kernel with PTRACE_GETREGS support.
94   // Returns true on success.
95   bool ReadRegisters(ThreadInfo* info, pid_t tid);
96 };
97 
98 }  // namespace google_breakpad
99 
100 #endif  // CLIENT_LINUX_HANDLER_LINUX_PTRACE_DUMPER_H_
101