| OLD | NEW |
| 1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 #ifndef CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ | 30 #ifndef CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ |
| 31 #define CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ | 31 #define CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ |
| 32 | 32 |
| 33 #include <elf.h> |
| 33 #include <stdint.h> | 34 #include <stdint.h> |
| 34 #include <sys/user.h> | 35 #include <sys/user.h> |
| 35 #include <linux/limits.h> | 36 #include <linux/limits.h> |
| 36 | 37 |
| 37 #include "breakpad/linux/memory.h" | 38 #include "breakpad/linux/memory.h" |
| 38 | 39 |
| 39 namespace google_breakpad { | 40 namespace google_breakpad { |
| 40 | 41 |
| 41 typedef typeof(((struct user *) 0)->u_debugreg[0]) debugreg_t; | 42 typedef typeof(((struct user*) 0)->u_debugreg[0]) debugreg_t; |
| 43 |
| 44 // Typedef for our parsing of the auxv variables in /proc/pid/auxv. |
| 45 #if defined(__i386) |
| 46 typedef Elf32_auxv_t elf_aux_entry; |
| 47 #elif defined(__x86_64__) |
| 48 typedef Elf64_auxv_t elf_aux_entry; |
| 49 #endif |
| 50 // When we find the VDSO mapping in the process's address space, this |
| 51 // is the name we use for it when writing it to the minidump. |
| 52 // This should always be less than NAME_MAX! |
| 53 const char kLinuxGateLibraryName[] = "linux-gate.so"; |
| 42 | 54 |
| 43 // We produce one of these structures for each thread in the crashed process. | 55 // We produce one of these structures for each thread in the crashed process. |
| 44 struct ThreadInfo { | 56 struct ThreadInfo { |
| 45 pid_t tgid; // thread group id | 57 pid_t tgid; // thread group id |
| 46 pid_t ppid; // parent process | 58 pid_t ppid; // parent process |
| 47 | 59 |
| 48 // Even on platforms where the stack grows down, the following will point to | 60 // Even on platforms where the stack grows down, the following will point to |
| 49 // the smallest address in the stack. | 61 // the smallest address in the stack. |
| 50 const void *stack; // pointer to the stack area | 62 const void* stack; // pointer to the stack area |
| 51 size_t stack_len; // length of the stack to copy | 63 size_t stack_len; // length of the stack to copy |
| 52 | 64 |
| 53 user_regs_struct regs; | 65 user_regs_struct regs; |
| 54 user_fpregs_struct fpregs; | 66 user_fpregs_struct fpregs; |
| 55 #if defined(__i386) || defined(__x86_64) | 67 #if defined(__i386) || defined(__x86_64) |
| 56 user_fpxregs_struct fpxregs; | 68 user_fpxregs_struct fpxregs; |
| 57 | 69 |
| 58 static const unsigned kNumDebugRegisters = 8; | 70 static const unsigned kNumDebugRegisters = 8; |
| 59 debugreg_t dregs[8]; | 71 debugreg_t dregs[8]; |
| 60 #endif | 72 #endif |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 | 87 |
| 76 // Parse the data for |threads| and |mappings|. | 88 // Parse the data for |threads| and |mappings|. |
| 77 bool Init(); | 89 bool Init(); |
| 78 | 90 |
| 79 // Suspend/resume all threads in the given process. | 91 // Suspend/resume all threads in the given process. |
| 80 bool ThreadsSuspend(); | 92 bool ThreadsSuspend(); |
| 81 bool ThreadsResume(); | 93 bool ThreadsResume(); |
| 82 | 94 |
| 83 // Read information about the given thread. Returns true on success. One must | 95 // Read information about the given thread. Returns true on success. One must |
| 84 // have called |ThreadsSuspend| first. | 96 // have called |ThreadsSuspend| first. |
| 85 bool ThreadInfoGet(pid_t tid, ThreadInfo *info); | 97 bool ThreadInfoGet(pid_t tid, ThreadInfo* info); |
| 86 | 98 |
| 87 // These are only valid after a call to |Init|. | 99 // These are only valid after a call to |Init|. |
| 88 const wasteful_vector<pid_t> &threads() { return threads_; } | 100 const wasteful_vector<pid_t> &threads() { return threads_; } |
| 89 const wasteful_vector<MappingInfo*> &mappings() { return mappings_; } | 101 const wasteful_vector<MappingInfo*> &mappings() { return mappings_; } |
| 90 const MappingInfo *FindMapping(const void *address) const; | 102 const MappingInfo* FindMapping(const void* address) const; |
| 91 | 103 |
| 92 // Find a block of memory to take as the stack given the top of stack pointer. | 104 // Find a block of memory to take as the stack given the top of stack pointer. |
| 93 // stack: (output) the lowest address in the memory area | 105 // stack: (output) the lowest address in the memory area |
| 94 // stack_len: (output) the length of the memory area | 106 // stack_len: (output) the length of the memory area |
| 95 // stack_top: the current top of the stack | 107 // stack_top: the current top of the stack |
| 96 bool GetStackInfo(const void** stack, size_t* stack_len, uintptr_t stack_top); | 108 bool GetStackInfo(const void** stack, size_t* stack_len, uintptr_t stack_top); |
| 97 | 109 |
| 98 PageAllocator *allocator() { return &allocator_; } | 110 PageAllocator* allocator() { return &allocator_; } |
| 99 | 111 |
| 100 // memcpy from a remote process. | 112 // memcpy from a remote process. |
| 101 static void CopyFromProcess(void* dest, pid_t child, const void* src, | 113 static void CopyFromProcess(void* dest, pid_t child, const void* src, |
| 102 size_t length); | 114 size_t length); |
| 103 | 115 |
| 116 // Builds a proc path for a certain pid for a node. path is a |
| 117 // character array that is overwritten, and node is the final node |
| 118 // without any slashes. |
| 119 void BuildProcPath(char* path, pid_t pid, const char* node) const; |
| 120 |
| 121 // Utility method to find the location of where the kernel has |
| 122 // mapped linux-gate.so in memory(shows up in /proc/pid/maps as |
| 123 // [vdso], but we can't guarantee that it's the only virtual dynamic |
| 124 // shared object. Parsing the auxilary vector for AT_SYSINFO_EHDR |
| 125 // is the safest way to go.) |
| 126 void* FindBeginningOfLinuxGateSharedLibrary(const pid_t pid) const; |
| 104 private: | 127 private: |
| 105 bool EnumerateMappings(wasteful_vector<MappingInfo*> *result) const; | 128 bool EnumerateMappings(wasteful_vector<MappingInfo*>* result) const; |
| 106 bool EnumerateThreads(wasteful_vector<pid_t> *result) const; | 129 bool EnumerateThreads(wasteful_vector<pid_t>* result) const; |
| 107 | 130 |
| 108 const pid_t pid_; | 131 const pid_t pid_; |
| 109 | 132 |
| 110 mutable PageAllocator allocator_; | 133 mutable PageAllocator allocator_; |
| 111 | 134 |
| 112 bool threads_suspened_; | 135 bool threads_suspened_; |
| 113 wasteful_vector<pid_t> threads_; // the ids of all the threads | 136 wasteful_vector<pid_t> threads_; // the ids of all the threads |
| 114 wasteful_vector<MappingInfo*> mappings_; // info from /proc/<pid>/maps | 137 wasteful_vector<MappingInfo*> mappings_; // info from /proc/<pid>/maps |
| 115 }; | 138 }; |
| 116 | 139 |
| 117 } // namespace google_breakpad | 140 } // namespace google_breakpad |
| 118 | 141 |
| 119 #endif // CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ | 142 #endif // CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ |
| OLD | NEW |