OLD | NEW |
1 // Copyright (c) 2012 Google Inc. | 1 // Copyright (c) 2012 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 17 matching lines...) Expand all Loading... |
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_MINIDUMP_DESCRIPTOR_H_ | 30 #ifndef CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ |
31 #define CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ | 31 #define CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ |
32 | 32 |
33 #include <assert.h> | 33 #include <assert.h> |
34 #include <sys/types.h> | 34 #include <sys/types.h> |
35 | 35 |
36 #include <string> | 36 #include <string> |
37 | 37 |
| 38 #include "client/linux/handler/microdump_extra_info.h" |
38 #include "common/using_std_string.h" | 39 #include "common/using_std_string.h" |
39 | 40 |
40 // This class describes how a crash dump should be generated, either: | 41 // This class describes how a crash dump should be generated, either: |
41 // - Writing a full minidump to a file in a given directory (the actual path, | 42 // - Writing a full minidump to a file in a given directory (the actual path, |
42 // inside the directory, is determined by this class). | 43 // inside the directory, is determined by this class). |
43 // - Writing a full minidump to a given fd. | 44 // - Writing a full minidump to a given fd. |
44 // - Writing a reduced microdump to the console (logcat on Android). | 45 // - Writing a reduced microdump to the console (logcat on Android). |
45 namespace google_breakpad { | 46 namespace google_breakpad { |
46 | 47 |
47 class MinidumpDescriptor { | 48 class MinidumpDescriptor { |
48 public: | 49 public: |
49 struct MicrodumpOnConsole {}; | 50 struct MicrodumpOnConsole {}; |
50 static const MicrodumpOnConsole kMicrodumpOnConsole; | 51 static const MicrodumpOnConsole kMicrodumpOnConsole; |
51 | 52 |
52 MinidumpDescriptor() : mode_(kUninitialized), | 53 MinidumpDescriptor() |
53 fd_(-1), | 54 : mode_(kUninitialized), |
54 size_limit_(-1), | 55 fd_(-1), |
55 microdump_build_fingerprint_(NULL), | 56 size_limit_(-1) {} |
56 microdump_product_info_(NULL) {} | |
57 | 57 |
58 explicit MinidumpDescriptor(const string& directory) | 58 explicit MinidumpDescriptor(const string& directory) |
59 : mode_(kWriteMinidumpToFile), | 59 : mode_(kWriteMinidumpToFile), |
60 fd_(-1), | 60 fd_(-1), |
61 directory_(directory), | 61 directory_(directory), |
62 c_path_(NULL), | 62 c_path_(NULL), |
63 size_limit_(-1), | 63 size_limit_(-1) { |
64 microdump_build_fingerprint_(NULL), | |
65 microdump_product_info_(NULL) { | |
66 assert(!directory.empty()); | 64 assert(!directory.empty()); |
67 } | 65 } |
68 | 66 |
69 explicit MinidumpDescriptor(int fd) | 67 explicit MinidumpDescriptor(int fd) |
70 : mode_(kWriteMinidumpToFd), | 68 : mode_(kWriteMinidumpToFd), |
71 fd_(fd), | 69 fd_(fd), |
72 c_path_(NULL), | 70 c_path_(NULL), |
73 size_limit_(-1), | 71 size_limit_(-1) { |
74 microdump_build_fingerprint_(NULL), | |
75 microdump_product_info_(NULL) { | |
76 assert(fd != -1); | 72 assert(fd != -1); |
77 } | 73 } |
78 | 74 |
79 explicit MinidumpDescriptor(const MicrodumpOnConsole&) | 75 explicit MinidumpDescriptor(const MicrodumpOnConsole&) |
80 : mode_(kWriteMicrodumpToConsole), | 76 : mode_(kWriteMicrodumpToConsole), |
81 fd_(-1), | 77 fd_(-1), |
82 size_limit_(-1), | 78 size_limit_(-1) {} |
83 microdump_build_fingerprint_(NULL), | |
84 microdump_product_info_(NULL) {} | |
85 | 79 |
86 explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor); | 80 explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor); |
87 MinidumpDescriptor& operator=(const MinidumpDescriptor& descriptor); | 81 MinidumpDescriptor& operator=(const MinidumpDescriptor& descriptor); |
88 | 82 |
89 static MinidumpDescriptor getMicrodumpDescriptor(); | 83 static MinidumpDescriptor getMicrodumpDescriptor(); |
90 | 84 |
91 bool IsFD() const { return mode_ == kWriteMinidumpToFd; } | 85 bool IsFD() const { return mode_ == kWriteMinidumpToFd; } |
92 | 86 |
93 int fd() const { return fd_; } | 87 int fd() const { return fd_; } |
94 | 88 |
95 string directory() const { return directory_; } | 89 string directory() const { return directory_; } |
96 | 90 |
97 const char* path() const { return c_path_; } | 91 const char* path() const { return c_path_; } |
98 | 92 |
99 bool IsMicrodumpOnConsole() const { | 93 bool IsMicrodumpOnConsole() const { |
100 return mode_ == kWriteMicrodumpToConsole; | 94 return mode_ == kWriteMicrodumpToConsole; |
101 } | 95 } |
102 | 96 |
103 // Updates the path so it is unique. | 97 // Updates the path so it is unique. |
104 // Should be called from a normal context: this methods uses the heap. | 98 // Should be called from a normal context: this methods uses the heap. |
105 void UpdatePath(); | 99 void UpdatePath(); |
106 | 100 |
107 off_t size_limit() const { return size_limit_; } | 101 off_t size_limit() const { return size_limit_; } |
108 void set_size_limit(off_t limit) { size_limit_ = limit; } | 102 void set_size_limit(off_t limit) { size_limit_ = limit; } |
109 | 103 |
110 // TODO(primiano): make this and product info (below) just part of the | 104 MicrodumpExtraInfo* microdump_extra_info() { |
111 // microdump ctor once it is rolled stably into Chrome. ETA: June 2015. | 105 assert(IsMicrodumpOnConsole()); |
112 void SetMicrodumpBuildFingerprint(const char* build_fingerprint); | 106 return µdump_extra_info_; |
113 const char* microdump_build_fingerprint() const { | 107 }; |
114 return microdump_build_fingerprint_; | |
115 } | |
116 | |
117 void SetMicrodumpProductInfo(const char* product_info); | |
118 const char* microdump_product_info() const { | |
119 return microdump_product_info_; | |
120 } | |
121 | 108 |
122 private: | 109 private: |
123 enum DumpMode { | 110 enum DumpMode { |
124 kUninitialized = 0, | 111 kUninitialized = 0, |
125 kWriteMinidumpToFile, | 112 kWriteMinidumpToFile, |
126 kWriteMinidumpToFd, | 113 kWriteMinidumpToFd, |
127 kWriteMicrodumpToConsole | 114 kWriteMicrodumpToConsole |
128 }; | 115 }; |
129 | 116 |
130 // Specifies the dump mode (see DumpMode). | 117 // Specifies the dump mode (see DumpMode). |
131 DumpMode mode_; | 118 DumpMode mode_; |
132 | 119 |
133 // The file descriptor where the minidump is generated. | 120 // The file descriptor where the minidump is generated. |
134 int fd_; | 121 int fd_; |
135 | 122 |
136 // The directory where the minidump should be generated. | 123 // The directory where the minidump should be generated. |
137 string directory_; | 124 string directory_; |
138 | 125 |
139 // The full path to the generated minidump. | 126 // The full path to the generated minidump. |
140 string path_; | 127 string path_; |
141 | 128 |
142 // The C string of |path_|. Precomputed so it can be access from a compromised | 129 // The C string of |path_|. Precomputed so it can be access from a compromised |
143 // context. | 130 // context. |
144 const char* c_path_; | 131 const char* c_path_; |
145 | 132 |
146 off_t size_limit_; | 133 off_t size_limit_; |
147 | 134 |
148 // The product name/version and build fingerprint that should be appended to | 135 // The extra microdump data (e.g. product name/version, build |
149 // the dump (microdump only). Microdumps don't have the ability of appending | 136 // fingerprint, gpu fingerprint) that should be appended to the dump |
150 // extra metadata after the dump is generated (as opposite to minidumps | 137 // (microdump only). Microdumps don't have the ability of appending |
151 // MIME fields), therefore the product details must be provided upfront. | 138 // extra metadata after the dump is generated (as opposite to |
152 // The string pointers are supposed to be valid through all the lifetime of | 139 // minidumps MIME fields), therefore the extra data must be provided |
153 // the process (read: the caller has to guarantee that they are stored in | 140 // upfront. Any memory pointed to by members of the |
154 // global static storage). | 141 // MicrodumpExtraInfo struct must be valid for the lifetime of the |
155 const char* microdump_build_fingerprint_; | 142 // process (read: the caller has to guarantee that it is stored in |
156 const char* microdump_product_info_; | 143 // global static storage.) |
| 144 MicrodumpExtraInfo microdump_extra_info_; |
157 }; | 145 }; |
158 | 146 |
159 } // namespace google_breakpad | 147 } // namespace google_breakpad |
160 | 148 |
161 #endif // CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ | 149 #endif // CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ |
OLD | NEW |