OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DEBUG_H__ | |
6 #define DEBUG_H__ | |
7 | |
8 #include <map> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <string> | |
12 #include <string.h> | |
13 | |
14 #include "sandbox_impl.h" | |
15 | |
16 namespace playground { | |
17 | |
18 class Debug { | |
19 public: | |
20 // If debugging is enabled, write a message to stderr. | |
21 static void message(const char* msg) | |
22 #ifndef NDEBUG | |
23 asm("playground$debugMessage") | |
24 #if defined(__x86_64__) | |
25 __attribute__((visibility("internal"))) | |
26 #endif | |
27 ; | |
28 #else | |
29 { } | |
30 #endif | |
31 | |
32 // If debugging is enabled, write the name of the syscall and an optional | |
33 // message to stderr. | |
34 static void syscall(long long* tm, int sysnum, | |
35 const char* msg, int call = -1) | |
36 #ifndef NDEBUG | |
37 ; | |
38 #else | |
39 { } | |
40 #endif | |
41 | |
42 // Print how much wall-time has elapsed since the last call to syscall() | |
43 static void elapsed(long long tm, int sysnum, int call = -1) | |
44 #ifndef NDEBUG | |
45 ; | |
46 #else | |
47 { | |
48 } | |
49 #endif | |
50 | |
51 // Check whether debugging is enabled. | |
52 static bool isEnabled() { | |
53 #ifndef NDEBUG | |
54 return enabled_; | |
55 #else | |
56 return false; | |
57 #endif | |
58 } | |
59 | |
60 private: | |
61 #ifndef NDEBUG | |
62 Debug(); | |
63 static bool enter(); | |
64 static bool leave(); | |
65 static void _message(const char* msg); | |
66 static void gettimeofday(long long* tm); | |
67 static char* itoa(char* s, int n); | |
68 | |
69 static Debug debug_; | |
70 | |
71 static bool enabled_; | |
72 static int numSyscallNames_; | |
73 static const char **syscallNames_; | |
74 static std::map<int, std::string> syscallNamesMap_; | |
75 #endif | |
76 }; | |
77 | |
78 } // namespace | |
79 | |
80 #endif // DEBUG_H__ | |
OLD | NEW |