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

Side by Side Diff: base/debug/debugger_posix.cc

Issue 8329023: OpenBSD patches for base / split from CR #8275005 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: for the buildbot Created 9 years, 2 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
« no previous file with comments | « base/base.gypi ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/debug/debugger.h" 5 #include "base/debug/debugger.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #endif 52 #endif
53 53
54 namespace base { 54 namespace base {
55 namespace debug { 55 namespace debug {
56 56
57 bool SpawnDebuggerOnProcess(unsigned /* process_id */) { 57 bool SpawnDebuggerOnProcess(unsigned /* process_id */) {
58 NOTIMPLEMENTED(); 58 NOTIMPLEMENTED();
59 return false; 59 return false;
60 } 60 }
61 61
62 #if defined(OS_MACOSX) 62 #if defined(OS_MACOSX) || defined(OS_OPENBSD)
63 63
64 // Based on Apple's recommended method as described in 64 // Based on Apple's recommended method as described in
65 // http://developer.apple.com/qa/qa2004/qa1361.html 65 // http://developer.apple.com/qa/qa2004/qa1361.html
66 bool BeingDebugged() { 66 bool BeingDebugged() {
67 // If the process is sandboxed then we can't use the sysctl, so cache the 67 // If the process is sandboxed then we can't use the sysctl, so cache the
68 // value. 68 // value.
69 static bool is_set = false; 69 static bool is_set = false;
70 static bool being_debugged = false; 70 static bool being_debugged = false;
71 71
72 if (is_set) { 72 if (is_set) {
73 return being_debugged; 73 return being_debugged;
74 } 74 }
75 75
76 // Initialize mib, which tells sysctl what info we want. In this case, 76 // Initialize mib, which tells sysctl what info we want. In this case,
77 // we're looking for information about a specific process ID. 77 // we're looking for information about a specific process ID.
78 int mib[] = { 78 int mib[] = {
79 CTL_KERN, 79 CTL_KERN,
80 KERN_PROC, 80 KERN_PROC,
81 KERN_PROC_PID, 81 KERN_PROC_PID,
82 getpid() 82 getpid()
83 #if defined(OS_OPENBSD)
84 , sizeof(struct kinfo_proc),
85 0
86 #endif
83 }; 87 };
84 88
85 // Caution: struct kinfo_proc is marked __APPLE_API_UNSTABLE. The source and 89 // Caution: struct kinfo_proc is marked __APPLE_API_UNSTABLE. The source and
86 // binary interfaces may change. 90 // binary interfaces may change.
87 struct kinfo_proc info; 91 struct kinfo_proc info;
88 size_t info_size = sizeof(info); 92 size_t info_size = sizeof(info);
89 93
94 #if defined(OS_OPENBSD)
95 if (sysctl(mib, arraysize(mib), NULL, &info_size, NULL, 0) < 0)
96 return -1;
97
98 mib[5] = (info_size / sizeof(struct kinfo_proc));
99 #endif
100
90 int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0); 101 int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0);
91 DCHECK_EQ(sysctl_result, 0); 102 DCHECK_EQ(sysctl_result, 0);
92 if (sysctl_result != 0) { 103 if (sysctl_result != 0) {
93 is_set = true; 104 is_set = true;
94 being_debugged = false; 105 being_debugged = false;
95 return being_debugged; 106 return being_debugged;
96 } 107 }
97 108
98 // This process is being debugged if the P_TRACED flag is set. 109 // This process is being debugged if the P_TRACED flag is set.
99 is_set = true; 110 is_set = true;
111 #if defined(OS_OPENBSD)
112 being_debugged = (info.p_flag & P_TRACED) != 0;
113 #else
100 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; 114 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0;
115 #endif
101 return being_debugged; 116 return being_debugged;
102 } 117 }
103 118
104 #elif defined(OS_LINUX) || defined(OS_ANDROID) 119 #elif defined(OS_LINUX) || defined(OS_ANDROID)
105 120
106 // We can look in /proc/self/status for TracerPid. We are likely used in crash 121 // We can look in /proc/self/status for TracerPid. We are likely used in crash
107 // handling, so we are careful not to use the heap or have side effects. 122 // handling, so we are careful not to use the heap or have side effects.
108 // Another option that is common is to try to ptrace yourself, but then we 123 // Another option that is common is to try to ptrace yourself, but then we
109 // can't detach without forking(), and that's not so great. 124 // can't detach without forking(), and that's not so great.
110 // static 125 // static
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 212
198 void BreakDebugger() { 213 void BreakDebugger() {
199 DEBUG_BREAK(); 214 DEBUG_BREAK();
200 #if defined(NDEBUG) 215 #if defined(NDEBUG)
201 _exit(1); 216 _exit(1);
202 #endif 217 #endif
203 } 218 }
204 219
205 } // namespace debug 220 } // namespace debug
206 } // namespace base 221 } // namespace base
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698