OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 // A collection of debugging related interfaces. | |
8 | |
9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_ | |
10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_ | |
11 | |
12 #include "native_client/src/include/nacl_macros.h" | |
13 #include "native_client/src/include/portability.h" | |
14 #include "native_client/src/shared/platform/nacl_threads.h" | |
15 | |
16 #define SRPC_PLUGIN_DEBUG 1 | |
17 | |
18 namespace plugin { | |
19 | |
20 // Tests that a string is a valid JavaScript identifier. According to the | |
21 // ECMAScript spec, this should be done in terms of unicode character | |
22 // categories. For now, we are simply limiting identifiers to the ASCII | |
23 // subset of that spec. If successful, it returns the length of the | |
24 // identifier in the location pointed to by length (if it is not NULL). | |
25 // TODO(sehr): add Unicode identifier support. | |
26 bool IsValidIdentifierString(const char* strval, uint32_t* length); | |
27 | |
28 // Debugging print utility | |
29 extern int gNaClPluginDebugPrintEnabled; | |
30 extern FILE* gNaClPluginLogFile; | |
31 extern int NaClPluginPrintLog(const char *format, ...); | |
32 extern int NaClPluginDebugPrintCheckEnv(); | |
33 extern FILE* NaClPluginLogFileEnv(); | |
34 #if SRPC_PLUGIN_DEBUG | |
35 # define PLUGIN_PRINTF(args) do { \ | |
36 if (-1 == ::plugin::gNaClPluginDebugPrintEnabled) { \ | |
37 ::plugin::gNaClPluginDebugPrintEnabled = \ | |
38 ::plugin::NaClPluginDebugPrintCheckEnv(); \ | |
39 ::plugin::gNaClPluginLogFile = ::plugin::NaClPluginLogFileEnv();\ | |
40 } \ | |
41 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \ | |
42 ::plugin::NaClPluginPrintLog("%08"NACL_PRIx32": ", \ | |
43 NaClThreadId()); \ | |
44 ::plugin::NaClPluginPrintLog args; \ | |
45 } \ | |
46 } while (0) | |
47 #else | |
48 # define PLUGIN_PRINTF(args) do { if (0) { printf args; } } while (0) | |
49 /* allows DCE but compiler can still do format string checks */ | |
50 #endif | |
51 | |
52 } // namespace plugin | |
53 | |
54 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_ | |
OLD | NEW |