Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: components/browser_watcher/stability_debugging.cc

Issue 2927653003: Stability instrumentation: add a Vectored Exception Handler (Closed)
Patch Set: merge Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browser_watcher/stability_debugging.h" 5 #include "components/browser_watcher/stability_debugging.h"
6 6
7 #include <windows.h>
8
9 #include <memory>
10
7 #include "base/debug/activity_tracker.h" 11 #include "base/debug/activity_tracker.h"
12 #include "build/build_config.h"
8 13
9 namespace browser_watcher { 14 namespace browser_watcher {
10 15
16 namespace {
17
18 struct VehUnregisterer {
19 void operator()(void* handle) const {
20 ::RemoveVectoredExceptionHandler(handle);
21 }
22 };
23
24 using VehHandle = std::unique_ptr<void, VehUnregisterer>;
25
26 uintptr_t GetProgramCounter(const CONTEXT& context) {
27 #if defined(ARCH_CPU_X86)
28 return context.Eip;
29 #elif defined(ARCH_CPU_X86_64)
30 return context.Rip;
31 #endif
32 }
33
34 LONG CALLBACK VectoredExceptionHandler(EXCEPTION_POINTERS* exception_pointers) {
35 base::debug::GlobalActivityTracker* tracker =
36 base::debug::GlobalActivityTracker::Get();
37 if (tracker) {
38 EXCEPTION_RECORD* record = exception_pointers->ExceptionRecord;
39 uintptr_t pc = GetProgramCounter(*exception_pointers->ContextRecord);
40 tracker->RecordException(reinterpret_cast<void*>(pc),
41 record->ExceptionAddress, record->ExceptionCode);
42 }
43
44 return EXCEPTION_CONTINUE_SEARCH; // Continue to the next handler.
45 }
46
47 } // namespace
48
11 void SetStabilityDataBool(base::StringPiece name, bool value) { 49 void SetStabilityDataBool(base::StringPiece name, bool value) {
12 base::debug::GlobalActivityTracker* global_tracker = 50 base::debug::GlobalActivityTracker* global_tracker =
13 base::debug::GlobalActivityTracker::Get(); 51 base::debug::GlobalActivityTracker::Get();
14 if (!global_tracker) 52 if (!global_tracker)
15 return; // Activity tracking isn't enabled. 53 return; // Activity tracking isn't enabled.
16 54
17 global_tracker->process_data().SetBool(name, value); 55 global_tracker->process_data().SetBool(name, value);
18 } 56 }
19 57
20 void SetStabilityDataInt(base::StringPiece name, int64_t value) { 58 void SetStabilityDataInt(base::StringPiece name, int64_t value) {
21 base::debug::GlobalActivityTracker* global_tracker = 59 base::debug::GlobalActivityTracker* global_tracker =
22 base::debug::GlobalActivityTracker::Get(); 60 base::debug::GlobalActivityTracker::Get();
23 if (!global_tracker) 61 if (!global_tracker)
24 return; // Activity tracking isn't enabled. 62 return; // Activity tracking isn't enabled.
25 63
26 global_tracker->process_data().SetInt(name, value); 64 global_tracker->process_data().SetInt(name, value);
27 } 65 }
28 66
67 void RegisterStabilityVEH() {
68 // Register a vectored exception handler and request it be first. Note that
69 // subsequent registrations may also request to be first, in which case this
70 // one will be bumped.
71 // TODO(manzagop): Depending on observations, it may be necessary to
72 // consider refreshing the registration, either periodically or at opportune
73 // (e.g. risky) times.
74 static VehHandle veh_handler(
75 ::AddVectoredExceptionHandler(1, &VectoredExceptionHandler));
76 DCHECK(veh_handler);
77 }
78
29 } // namespace browser_watcher 79 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/stability_debugging.h ('k') | components/browser_watcher/stability_debugging_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698