| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009, 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 #ifndef CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ | |
| 31 #define CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ | |
| 32 | |
| 33 #include <sys/types.h> | |
| 34 #include <elf.h> | |
| 35 #include <stdint.h> | |
| 36 #include <sys/user.h> | |
| 37 #include <linux/limits.h> | |
| 38 | |
| 39 #include "breakpad/linux/memory.h" | |
| 40 | |
| 41 namespace google_breakpad { | |
| 42 | |
| 43 typedef typeof(((struct user*) 0)->u_debugreg[0]) debugreg_t; | |
| 44 | |
| 45 // Typedef for our parsing of the auxv variables in /proc/pid/auxv. | |
| 46 #if defined(__i386) | |
| 47 typedef Elf32_auxv_t elf_aux_entry; | |
| 48 #elif defined(__x86_64__) | |
| 49 typedef Elf64_auxv_t elf_aux_entry; | |
| 50 #endif | |
| 51 // When we find the VDSO mapping in the process's address space, this | |
| 52 // is the name we use for it when writing it to the minidump. | |
| 53 // This should always be less than NAME_MAX! | |
| 54 const char kLinuxGateLibraryName[] = "linux-gate.so"; | |
| 55 | |
| 56 // We produce one of these structures for each thread in the crashed process. | |
| 57 struct ThreadInfo { | |
| 58 pid_t tgid; // thread group id | |
| 59 pid_t ppid; // parent process | |
| 60 | |
| 61 // Even on platforms where the stack grows down, the following will point to | |
| 62 // the smallest address in the stack. | |
| 63 const void* stack; // pointer to the stack area | |
| 64 size_t stack_len; // length of the stack to copy | |
| 65 | |
| 66 user_regs_struct regs; | |
| 67 user_fpregs_struct fpregs; | |
| 68 #if defined(__i386) | |
| 69 user_fpxregs_struct fpxregs; | |
| 70 #endif | |
| 71 | |
| 72 #if defined(__i386) || defined(__x86_64) | |
| 73 static const unsigned kNumDebugRegisters = 8; | |
| 74 debugreg_t dregs[8]; | |
| 75 #endif | |
| 76 }; | |
| 77 | |
| 78 // One of these is produced for each mapping in the process (i.e. line in | |
| 79 // /proc/$x/maps). | |
| 80 struct MappingInfo { | |
| 81 uintptr_t start_addr; | |
| 82 size_t size; | |
| 83 size_t offset; // offset into the backed file. | |
| 84 char name[NAME_MAX]; | |
| 85 }; | |
| 86 | |
| 87 class LinuxDumper { | |
| 88 public: | |
| 89 explicit LinuxDumper(pid_t pid); | |
| 90 | |
| 91 // Parse the data for |threads| and |mappings|. | |
| 92 bool Init(); | |
| 93 | |
| 94 // Suspend/resume all threads in the given process. | |
| 95 bool ThreadsSuspend(); | |
| 96 bool ThreadsResume(); | |
| 97 | |
| 98 // Read information about the given thread. Returns true on success. One must | |
| 99 // have called |ThreadsSuspend| first. | |
| 100 bool ThreadInfoGet(pid_t tid, ThreadInfo* info); | |
| 101 | |
| 102 // These are only valid after a call to |Init|. | |
| 103 const wasteful_vector<pid_t> &threads() { return threads_; } | |
| 104 const wasteful_vector<MappingInfo*> &mappings() { return mappings_; } | |
| 105 const MappingInfo* FindMapping(const void* address) const; | |
| 106 | |
| 107 // Find a block of memory to take as the stack given the top of stack pointer. | |
| 108 // stack: (output) the lowest address in the memory area | |
| 109 // stack_len: (output) the length of the memory area | |
| 110 // stack_top: the current top of the stack | |
| 111 bool GetStackInfo(const void** stack, size_t* stack_len, uintptr_t stack_top); | |
| 112 | |
| 113 PageAllocator* allocator() { return &allocator_; } | |
| 114 | |
| 115 // memcpy from a remote process. | |
| 116 static void CopyFromProcess(void* dest, pid_t child, const void* src, | |
| 117 size_t length); | |
| 118 | |
| 119 // Builds a proc path for a certain pid for a node. path is a | |
| 120 // character array that is overwritten, and node is the final node | |
| 121 // without any slashes. | |
| 122 void BuildProcPath(char* path, pid_t pid, const char* node) const; | |
| 123 | |
| 124 // Utility method to find the location of where the kernel has | |
| 125 // mapped linux-gate.so in memory(shows up in /proc/pid/maps as | |
| 126 // [vdso], but we can't guarantee that it's the only virtual dynamic | |
| 127 // shared object. Parsing the auxilary vector for AT_SYSINFO_EHDR | |
| 128 // is the safest way to go.) | |
| 129 void* FindBeginningOfLinuxGateSharedLibrary(const pid_t pid) const; | |
| 130 private: | |
| 131 bool EnumerateMappings(wasteful_vector<MappingInfo*>* result) const; | |
| 132 bool EnumerateThreads(wasteful_vector<pid_t>* result) const; | |
| 133 | |
| 134 const pid_t pid_; | |
| 135 | |
| 136 mutable PageAllocator allocator_; | |
| 137 | |
| 138 bool threads_suspened_; | |
| 139 wasteful_vector<pid_t> threads_; // the ids of all the threads | |
| 140 wasteful_vector<MappingInfo*> mappings_; // info from /proc/<pid>/maps | |
| 141 }; | |
| 142 | |
| 143 } // namespace google_breakpad | |
| 144 | |
| 145 #endif // CLIENT_LINUX_HANDLER_LINUX_DUMPER_H_ | |
| OLD | NEW |