| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/app/breakpad_win.h" | 5 #include "chrome/app/breakpad_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <tchar.h> | 9 #include <tchar.h> |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // These surround the flags that were added by about:flags, it lets | 145 // These surround the flags that were added by about:flags, it lets |
| 146 // you distinguish which flags were added manually via the command | 146 // you distinguish which flags were added manually via the command |
| 147 // line versus those added through about:flags. For the most part | 147 // line versus those added through about:flags. For the most part |
| 148 // we don't care how an option was enabled, so we strip these. | 148 // we don't care how an option was enabled, so we strip these. |
| 149 // (If you need to know can always look at the PEB). | 149 // (If you need to know can always look at the PEB). |
| 150 flag == L"--flag-switches-begin" || | 150 flag == L"--flag-switches-begin" || |
| 151 flag == L"--flag-switches-end"; | 151 flag == L"--flag-switches-end"; |
| 152 } | 152 } |
| 153 | 153 |
| 154 extern "C" void __declspec(dllexport) __cdecl SetCommandLine( | 154 extern "C" void __declspec(dllexport) __cdecl SetCommandLine( |
| 155 const CommandLine* command_line) { | 155 const wchar_t** argv, size_t argc) { |
| 156 if (!g_custom_entries) | 156 if (!g_custom_entries) |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 const CommandLine::StringVector& argv = command_line->argv(); | |
| 160 | |
| 161 // Copy up to the kMaxSwitches arguments into the custom entries array. Skip | 159 // Copy up to the kMaxSwitches arguments into the custom entries array. Skip |
| 162 // past the first argument, as it is just the executable path. | 160 // past the first argument, as it is just the executable path. |
| 163 size_t argv_i = 1; | 161 size_t argv_i = 1; |
| 164 size_t num_added = 0; | 162 size_t num_added = 0; |
| 165 | 163 |
| 166 for (; argv_i < argv.size() && num_added < kMaxSwitches; ++argv_i) { | 164 for (; argv_i < argc && num_added < kMaxSwitches; ++argv_i) { |
| 167 // Don't bother including boring command line switches in crash reports. | 165 // Don't bother including boring command line switches in crash reports. |
| 168 if (IsBoringCommandLineSwitch(argv[argv_i])) | 166 if (IsBoringCommandLineSwitch(argv[argv_i])) |
| 169 continue; | 167 continue; |
| 170 | 168 |
| 171 base::wcslcpy((*g_custom_entries)[g_switches_offset + num_added].value, | 169 base::wcslcpy((*g_custom_entries)[g_switches_offset + num_added].value, |
| 172 argv[argv_i].c_str(), | 170 argv[argv_i], |
| 173 google_breakpad::CustomInfoEntry::kValueMaxLength); | 171 google_breakpad::CustomInfoEntry::kValueMaxLength); |
| 174 num_added++; | 172 num_added++; |
| 175 } | 173 } |
| 176 | 174 |
| 177 // Make note of the total number of switches. This is useful in case we have | 175 // Make note of the total number of switches. This is useful in case we have |
| 178 // truncated at kMaxSwitches, to see how many were unaccounted for. | 176 // truncated at kMaxSwitches, to see how many were unaccounted for. |
| 179 SetIntegerValue(g_num_switches_offset, static_cast<int>(argv.size()) - 1); | 177 SetIntegerValue(g_num_switches_offset, static_cast<int>(argc) - 1); |
| 180 } | 178 } |
| 181 | 179 |
| 182 // Appends the plugin path to |g_custom_entries|. | 180 // Appends the plugin path to |g_custom_entries|. |
| 183 void SetPluginPath(const std::wstring& path) { | 181 void SetPluginPath(const std::wstring& path) { |
| 184 DCHECK(g_custom_entries); | 182 DCHECK(g_custom_entries); |
| 185 | 183 |
| 186 if (path.size() > kMaxPluginPathLength) { | 184 if (path.size() > kMaxPluginPathLength) { |
| 187 // If the path is too long, truncate from the start rather than the end, | 185 // If the path is too long, truncate from the start rather than the end, |
| 188 // since we want to be able to recover the DLL name. | 186 // since we want to be able to recover the DLL name. |
| 189 SetPluginPath(path.substr(path.size() - kMaxPluginPathLength)); | 187 SetPluginPath(path.substr(path.size() - kMaxPluginPathLength)); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 g_switches_offset = g_custom_entries->size(); | 310 g_switches_offset = g_custom_entries->size(); |
| 313 // one-based index for the name suffix. | 311 // one-based index for the name suffix. |
| 314 for (int i = 1; i <= kMaxSwitches; ++i) { | 312 for (int i = 1; i <= kMaxSwitches; ++i) { |
| 315 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( | 313 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( |
| 316 base::StringPrintf(L"switch-%i", i).c_str(), L"")); | 314 base::StringPrintf(L"switch-%i", i).c_str(), L"")); |
| 317 } | 315 } |
| 318 | 316 |
| 319 // Fill in the command line arguments using CommandLine::ForCurrentProcess(). | 317 // Fill in the command line arguments using CommandLine::ForCurrentProcess(). |
| 320 // The browser process may call SetCommandLine() again later on with a command | 318 // The browser process may call SetCommandLine() again later on with a command |
| 321 // line that has been augmented with the about:flags experiments. | 319 // line that has been augmented with the about:flags experiments. |
| 322 SetCommandLine(CommandLine::ForCurrentProcess()); | 320 std::vector<const wchar_t*> switches; |
| 321 StringVectorToCStringVector( |
| 322 CommandLine::ForCurrentProcess()->argv(), &switches); |
| 323 SetCommandLine(&switches[0], switches.size()); |
| 323 | 324 |
| 324 if (type == L"renderer" || type == L"plugin" || type == L"gpu-process") { | 325 if (type == L"renderer" || type == L"plugin" || type == L"gpu-process") { |
| 325 g_num_of_views_offset = g_custom_entries->size(); | 326 g_num_of_views_offset = g_custom_entries->size(); |
| 326 g_custom_entries->push_back( | 327 g_custom_entries->push_back( |
| 327 google_breakpad::CustomInfoEntry(L"num-views", L"")); | 328 google_breakpad::CustomInfoEntry(L"num-views", L"")); |
| 328 // Create entries for the URL. Currently we only allow each chunk to be 64 | 329 // Create entries for the URL. Currently we only allow each chunk to be 64 |
| 329 // characters, which isn't enough for a URL. As a hack we create 8 entries | 330 // characters, which isn't enough for a URL. As a hack we create 8 entries |
| 330 // and split the URL across the g_custom_entries. | 331 // and split the URL across the g_custom_entries. |
| 331 g_url_chunks_offset = g_custom_entries->size(); | 332 g_url_chunks_offset = g_custom_entries->size(); |
| 332 // one-based index for the name suffix. | 333 // one-based index for the name suffix. |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 // Tells breakpad to handle breakpoint and single step exceptions. | 817 // Tells breakpad to handle breakpoint and single step exceptions. |
| 817 // This might break JIT debuggers, but at least it will always | 818 // This might break JIT debuggers, but at least it will always |
| 818 // generate a crashdump for these exceptions. | 819 // generate a crashdump for these exceptions. |
| 819 g_breakpad->set_handle_debug_exceptions(true); | 820 g_breakpad->set_handle_debug_exceptions(true); |
| 820 } | 821 } |
| 821 } | 822 } |
| 822 | 823 |
| 823 void InitDefaultCrashCallback(LPTOP_LEVEL_EXCEPTION_FILTER filter) { | 824 void InitDefaultCrashCallback(LPTOP_LEVEL_EXCEPTION_FILTER filter) { |
| 824 previous_filter = SetUnhandledExceptionFilter(filter); | 825 previous_filter = SetUnhandledExceptionFilter(filter); |
| 825 } | 826 } |
| 827 |
| 828 void StringVectorToCStringVector(const std::vector<std::wstring>& wstrings, |
| 829 std::vector<const wchar_t*>* cstrings) { |
| 830 cstrings->clear(); |
| 831 cstrings->reserve(wstrings.size()); |
| 832 for (size_t i = 0; i < wstrings.size(); ++i) |
| 833 cstrings->push_back(wstrings[i].c_str()); |
| 834 } |
| OLD | NEW |