OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/crash/core/common/crash_keys.h" | 5 #include "components/crash/core/common/crash_keys.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/callback.h" | |
9 #include "base/command_line.h" | |
7 #include "base/debug/crash_logging.h" | 10 #include "base/debug/crash_logging.h" |
8 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/logging.h" | |
9 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
10 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | |
12 | 17 |
13 namespace crash_keys { | 18 namespace crash_keys { |
14 | 19 |
15 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
16 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID | 21 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID |
17 // carried in a distinct "metrics_client_id" field. | 22 // carried in a distinct "metrics_client_id" field. |
18 const char kMetricsClientId[] = "metrics_client_id"; | 23 const char kMetricsClientId[] = "metrics_client_id"; |
19 #else | 24 #else |
20 const char kClientId[] = "guid"; | 25 const char kClientId[] = "guid"; |
21 #endif | 26 #endif |
22 | 27 |
23 const char kChannel[] = "channel"; | 28 const char kChannel[] = "channel"; |
24 | 29 |
25 const char kNumVariations[] = "num-experiments"; | 30 const char kNumVariations[] = "num-experiments"; |
26 const char kVariations[] = "variations"; | 31 const char kVariations[] = "variations"; |
27 | 32 |
33 const char kSwitch[] = "switch-%" PRIuS; | |
34 const char kNumSwitches[] = "num-switches"; | |
35 | |
28 const char kBug464926CrashKey[] = "bug-464926-info"; | 36 const char kBug464926CrashKey[] = "bug-464926-info"; |
29 | 37 |
30 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
31 namespace mac { | 39 namespace mac { |
32 | 40 |
33 const char kZombie[] = "zombie"; | 41 const char kZombie[] = "zombie"; |
34 const char kZombieTrace[] = "zombie_dealloc_bt"; | 42 const char kZombieTrace[] = "zombie_dealloc_bt"; |
35 | 43 |
36 } // namespace mac | 44 } // namespace mac |
37 #endif | 45 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // Do not truncate an individual experiment. | 93 // Do not truncate an individual experiment. |
86 if (variations_string.size() + variation.size() >= kLargeSize) | 94 if (variations_string.size() + variation.size() >= kLargeSize) |
87 break; | 95 break; |
88 variations_string += variation; | 96 variations_string += variation; |
89 variations_string += ","; | 97 variations_string += ","; |
90 } | 98 } |
91 | 99 |
92 base::debug::SetCrashKeyValue(kVariations, variations_string); | 100 base::debug::SetCrashKeyValue(kVariations, variations_string); |
93 } | 101 } |
94 | 102 |
103 void GetCrashKeysForCommandLineSwitches( | |
104 std::vector<base::debug::CrashKey>* keys) { | |
105 DCHECK(keys); | |
106 base::debug::CrashKey crash_key = { kNumSwitches, kSmallSize }; | |
107 keys->push_back(crash_key); | |
108 | |
109 // The fixed_keys names are string constants. Use static storage for | |
110 // formatted key names as well, since they will persist for the duration of | |
111 // the program. | |
112 static char formatted_keys[kSwitchesMaxCount][sizeof(kSwitch) + 1] = {{ 0 }}; | |
grt (UTC plus 2)
2015/11/27 18:51:21
oh my. this is an accident waiting to happen. size
Joe Mason
2015/11/27 21:16:47
Done.
| |
113 const size_t formatted_key_len = sizeof(formatted_keys[0]); | |
114 for (size_t i = 0; i < kSwitchesMaxCount; ++i) { | |
115 // Name the keys using 1-based indexing. | |
116 int n = base::snprintf(formatted_keys[i], formatted_key_len, kSwitch, | |
117 i + 1); | |
118 DCHECK_GT(n, 0); | |
119 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; | |
120 keys->push_back(crash_key); | |
121 } | |
122 } | |
123 | |
124 namespace { | |
125 | |
126 bool PassThroughFilter(const std::string &) { | |
127 // By default do not reject any switches. | |
128 return false; | |
129 } | |
130 | |
131 } // namespace | |
132 | |
133 void SetSwitchesFromCommandLine(const base::CommandLine& command_line) { | |
134 SetSwitchesFromCommandLine(command_line, base::Bind(&PassThroughFilter)); | |
135 } | |
136 | |
137 void SetSwitchesFromCommandLine(const base::CommandLine& command_line, | |
138 const base::Callback<bool(const std::string &)>& skip_filter) { | |
139 const base::CommandLine::StringVector& argv = command_line.argv(); | |
140 | |
141 // Set the number of switches in case size > kNumSwitches. | |
142 base::debug::SetCrashKeyValue(kNumSwitches, | |
143 base::StringPrintf("%" PRIuS, argv.size() - 1)); | |
144 | |
145 size_t key_i = 1; // Key names are 1-indexed. | |
146 | |
147 // Go through the argv, skipping the exec path. | |
148 for (size_t i = 1; i < argv.size(); ++i) { | |
149 #if defined(OS_WIN) | |
150 std::string switch_str = base::WideToUTF8(argv[i]); | |
151 #else | |
152 std::string switch_str = argv[i]; | |
153 #endif | |
154 | |
155 // Skip uninteresting switches. | |
156 if (skip_filter.Run(switch_str)) | |
157 continue; | |
158 | |
159 // Stop if there are too many switches. | |
160 if (i > crash_keys::kSwitchesMaxCount) | |
grt (UTC plus 2)
2015/11/27 18:51:21
i -> key_i
Joe Mason
2015/11/27 21:16:47
Good catch! Fixed.
| |
161 break; | |
162 | |
163 std::string key = base::StringPrintf(kSwitch, key_i++); | |
164 base::debug::SetCrashKeyValue(key, switch_str); | |
165 } | |
166 | |
167 // Clear any remaining switches. | |
168 for (; key_i <= kSwitchesMaxCount; ++key_i) { | |
grt (UTC plus 2)
2015/11/27 18:51:21
nit: omit braces. :-)
Joe Mason
2015/11/27 21:16:47
Done.
| |
169 base::debug::ClearCrashKey(base::StringPrintf(kSwitch, key_i)); | |
170 } | |
171 } | |
172 | |
95 } // namespace crash_keys | 173 } // namespace crash_keys |
OLD | NEW |