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 microdump_extra_info_() {} |
Lei Zhang
2015/09/10 18:38:19
probably unnecessary, ditto below
Tobias Sargeant
2015/09/11 09:07:49
Done.
| |
57 | 58 |
58 explicit MinidumpDescriptor(const string& directory) | 59 explicit MinidumpDescriptor(const string& directory) |
59 : mode_(kWriteMinidumpToFile), | 60 : mode_(kWriteMinidumpToFile), |
60 fd_(-1), | 61 fd_(-1), |
61 directory_(directory), | 62 directory_(directory), |
62 c_path_(NULL), | 63 c_path_(NULL), |
63 size_limit_(-1), | 64 size_limit_(-1), |
64 microdump_build_fingerprint_(NULL), | 65 microdump_extra_info_() { |
65 microdump_product_info_(NULL) { | |
66 assert(!directory.empty()); | 66 assert(!directory.empty()); |
67 } | 67 } |
68 | 68 |
69 explicit MinidumpDescriptor(int fd) | 69 explicit MinidumpDescriptor(int fd) |
70 : mode_(kWriteMinidumpToFd), | 70 : mode_(kWriteMinidumpToFd), |
71 fd_(fd), | 71 fd_(fd), |
72 c_path_(NULL), | 72 c_path_(NULL), |
73 size_limit_(-1), | 73 size_limit_(-1), |
74 microdump_build_fingerprint_(NULL), | 74 microdump_extra_info_() { |
75 microdump_product_info_(NULL) { | |
76 assert(fd != -1); | 75 assert(fd != -1); |
77 } | 76 } |
78 | 77 |
79 explicit MinidumpDescriptor(const MicrodumpOnConsole&) | 78 explicit MinidumpDescriptor(const MicrodumpOnConsole&) |
80 : mode_(kWriteMicrodumpToConsole), | 79 : mode_(kWriteMicrodumpToConsole), |
81 fd_(-1), | 80 fd_(-1), |
82 size_limit_(-1), | 81 size_limit_(-1), |
83 microdump_build_fingerprint_(NULL), | 82 microdump_extra_info_() {} |
84 microdump_product_info_(NULL) {} | |
85 | 83 |
86 explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor); | 84 explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor); |
87 MinidumpDescriptor& operator=(const MinidumpDescriptor& descriptor); | 85 MinidumpDescriptor& operator=(const MinidumpDescriptor& descriptor); |
88 | 86 |
89 static MinidumpDescriptor getMicrodumpDescriptor(); | 87 static MinidumpDescriptor getMicrodumpDescriptor(); |
90 | 88 |
91 bool IsFD() const { return mode_ == kWriteMinidumpToFd; } | 89 bool IsFD() const { return mode_ == kWriteMinidumpToFd; } |
92 | 90 |
93 int fd() const { return fd_; } | 91 int fd() const { return fd_; } |
94 | 92 |
95 string directory() const { return directory_; } | 93 string directory() const { return directory_; } |
96 | 94 |
97 const char* path() const { return c_path_; } | 95 const char* path() const { return c_path_; } |
98 | 96 |
99 bool IsMicrodumpOnConsole() const { | 97 bool IsMicrodumpOnConsole() const { |
100 return mode_ == kWriteMicrodumpToConsole; | 98 return mode_ == kWriteMicrodumpToConsole; |
101 } | 99 } |
102 | 100 |
103 // Updates the path so it is unique. | 101 // Updates the path so it is unique. |
104 // Should be called from a normal context: this methods uses the heap. | 102 // Should be called from a normal context: this methods uses the heap. |
105 void UpdatePath(); | 103 void UpdatePath(); |
106 | 104 |
107 off_t size_limit() const { return size_limit_; } | 105 off_t size_limit() const { return size_limit_; } |
108 void set_size_limit(off_t limit) { size_limit_ = limit; } | 106 void set_size_limit(off_t limit) { size_limit_ = limit; } |
109 | 107 |
110 // TODO(primiano): make this and product info (below) just part of the | 108 MicrodumpExtraInfo* microdump_extra_info() { |
111 // microdump ctor once it is rolled stably into Chrome. ETA: June 2015. | 109 assert(mode_ == kWriteMicrodumpToConsole); |
Lei Zhang
2015/09/10 18:38:19
just call IsMicrodumpOnConsole() ?
Tobias Sargeant
2015/09/11 09:07:49
Done.
| |
112 void SetMicrodumpBuildFingerprint(const char* build_fingerprint); | 110 return µdump_extra_info_; |
113 const char* microdump_build_fingerprint() const { | 111 }; |
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 | 112 |
122 private: | 113 private: |
123 enum DumpMode { | 114 enum DumpMode { |
124 kUninitialized = 0, | 115 kUninitialized = 0, |
125 kWriteMinidumpToFile, | 116 kWriteMinidumpToFile, |
126 kWriteMinidumpToFd, | 117 kWriteMinidumpToFd, |
127 kWriteMicrodumpToConsole | 118 kWriteMicrodumpToConsole |
128 }; | 119 }; |
129 | 120 |
130 // Specifies the dump mode (see DumpMode). | 121 // Specifies the dump mode (see DumpMode). |
131 DumpMode mode_; | 122 DumpMode mode_; |
132 | 123 |
133 // The file descriptor where the minidump is generated. | 124 // The file descriptor where the minidump is generated. |
134 int fd_; | 125 int fd_; |
135 | 126 |
136 // The directory where the minidump should be generated. | 127 // The directory where the minidump should be generated. |
137 string directory_; | 128 string directory_; |
138 | 129 |
139 // The full path to the generated minidump. | 130 // The full path to the generated minidump. |
140 string path_; | 131 string path_; |
141 | 132 |
142 // The C string of |path_|. Precomputed so it can be access from a compromised | 133 // The C string of |path_|. Precomputed so it can be access from a compromised |
143 // context. | 134 // context. |
144 const char* c_path_; | 135 const char* c_path_; |
145 | 136 |
146 off_t size_limit_; | 137 off_t size_limit_; |
147 | 138 |
148 // The product name/version and build fingerprint that should be appended to | 139 // The extra microdump data (e.g. product name/version, build |
149 // the dump (microdump only). Microdumps don't have the ability of appending | 140 // fingerprint, gpu fingerprint) that should be appended to the dump |
150 // extra metadata after the dump is generated (as opposite to minidumps | 141 // (microdump only). Microdumps don't have the ability of appending |
151 // MIME fields), therefore the product details must be provided upfront. | 142 // extra metadata after the dump is generated (as opposite to |
152 // The string pointers are supposed to be valid through all the lifetime of | 143 // minidumps MIME fields), therefore the extra data must be provided |
153 // the process (read: the caller has to guarantee that they are stored in | 144 // upfront. The string pointers are supposed to be valid through |
Primiano Tucci (use gerrit)
2015/09/10 13:58:31
As you moved this comment to extra info, you could
Tobias Sargeant
2015/09/11 09:07:49
Done.
| |
154 // global static storage). | 145 // all the lifetime of the process (read: the caller has to |
155 const char* microdump_build_fingerprint_; | 146 // guarantee that they are stored in global static storage). |
156 const char* microdump_product_info_; | 147 MicrodumpExtraInfo microdump_extra_info_; |
157 }; | 148 }; |
158 | 149 |
159 } // namespace google_breakpad | 150 } // namespace google_breakpad |
160 | 151 |
161 #endif // CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ | 152 #endif // CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_ |
OLD | NEW |