• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_core_dumper.h: Define the google_breakpad::LinuxCoreDumper
31 // class, which is derived from google_breakpad::LinuxDumper to extract
32 // information from a crashed process via its core dump and proc files.
33 
34 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_LINUX_CORE_DUMPER_H_
35 #define CLIENT_LINUX_MINIDUMP_WRITER_LINUX_CORE_DUMPER_H_
36 
37 #include "client/linux/minidump_writer/linux_dumper.h"
38 #include "common/linux/elf_core_dump.h"
39 #include "common/linux/memory_mapped_file.h"
40 
41 namespace google_breakpad {
42 
43 class LinuxCoreDumper : public LinuxDumper {
44  public:
45   // Constructs a dumper for extracting information of a given process
46   // with a process ID of |pid| via its core dump file at |core_path| and
47   // its proc files at |procfs_path|. If |procfs_path| is a copy of
48   // /proc/<pid>, it should contain the following files:
49   //     auxv, cmdline, environ, exe, maps, status
50   // See LinuxDumper for the purpose of |root_prefix|.
51   LinuxCoreDumper(pid_t pid, const char* core_path, const char* procfs_path,
52                   const char* root_prefix = "");
53 
54   // Implements LinuxDumper::BuildProcPath().
55   // Builds a proc path for a certain pid for a node (/proc/<pid>/<node>).
56   // |path| is a character array of at least NAME_MAX bytes to return the
57   // result.|node| is the final node without any slashes. Return true on
58   // success.
59   //
60   // As this dumper performs a post-mortem dump and makes use of a copy
61   // of the proc files of the crashed process, this derived method does
62   // not actually make use of |pid| and always returns a subpath of
63   // |procfs_path_| regardless of whether |pid| corresponds to the main
64   // process or a thread of the process, i.e. assuming both the main process
65   // and its threads have the following proc files with the same content:
66   //     auxv, cmdline, environ, exe, maps, status
67   virtual bool BuildProcPath(char* path, pid_t pid, const char* node) const;
68 
69   // Implements LinuxDumper::CopyFromProcess().
70   // Copies content of |length| bytes from a given process |child|,
71   // starting from |src|, into |dest|. This method extracts the content
72   // the core dump and fills |dest| with a sequence of marker bytes
73   // if the expected data is not found in the core dump. Returns true if
74   // the expected data is found in the core dump.
75   virtual bool CopyFromProcess(void* dest, pid_t child, const void* src,
76                                size_t length);
77 
78   // Implements LinuxDumper::GetThreadInfoByIndex().
79   // Reads information about the |index|-th thread of |threads_|.
80   // Returns true on success. One must have called |ThreadsSuspend| first.
81   virtual bool GetThreadInfoByIndex(size_t index, ThreadInfo* info);
82 
83   // Implements LinuxDumper::IsPostMortem().
84   // Always returns true to indicate that this dumper performs a
85   // post-mortem dump of a crashed process via a core dump file.
86   virtual bool IsPostMortem() const;
87 
88   // Implements LinuxDumper::ThreadsSuspend().
89   // As the dumper performs a post-mortem dump via a core dump file,
90   // there is no threads to suspend. This method does nothing and
91   // always returns true.
92   virtual bool ThreadsSuspend();
93 
94   // Implements LinuxDumper::ThreadsResume().
95   // As the dumper performs a post-mortem dump via a core dump file,
96   // there is no threads to resume. This method does nothing and
97   // always returns true.
98   virtual bool ThreadsResume();
99 
100  protected:
101   // Implements LinuxDumper::EnumerateThreads().
102   // Enumerates all threads of the given process into |threads_|.
103   virtual bool EnumerateThreads();
104 
105  private:
106   // Path of the core dump file.
107   const char* core_path_;
108 
109   // Path of the directory containing the proc files of the given process,
110   // which is usually a copy of /proc/<pid>.
111   const char* procfs_path_;
112 
113   // Memory-mapped core dump file at |core_path_|.
114   MemoryMappedFile mapped_core_file_;
115 
116   // Content of the core dump file.
117   ElfCoreDump core_;
118 
119   // Thread info found in the core dump file.
120   wasteful_vector<ThreadInfo> thread_infos_;
121 };
122 
123 }  // namespace google_breakpad
124 
125 #endif  // CLIENT_LINUX_HANDLER_LINUX_CORE_DUMPER_H_
126