2 * Copyright (c) 2011 The Chromium 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.
7 // A collection of debugging related interfaces.
9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_
10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_
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 #include "native_client/src/shared/platform/nacl_time.h"
17 #define SRPC_PLUGIN_DEBUG 1
21 // Tests that a string is a valid JavaScript identifier. According to the
22 // ECMAScript spec, this should be done in terms of unicode character
23 // categories. For now, we are simply limiting identifiers to the ASCII
24 // subset of that spec. If successful, it returns the length of the
25 // identifier in the location pointed to by length (if it is not NULL).
26 // TODO(sehr): add Unicode identifier support.
27 bool IsValidIdentifierString(const char* strval
, uint32_t* length
);
29 // Debugging print utility
30 extern int gNaClPluginDebugPrintEnabled
;
31 extern FILE* gNaClPluginLogFile
;
32 extern int NaClPluginPrintLog(const char *format
, ...);
33 extern int NaClPluginDebugPrintCheckEnv();
34 extern FILE* NaClPluginLogFileEnv();
36 #define INIT_PLUGIN_LOGGING() do { \
37 if (-1 == ::plugin::gNaClPluginDebugPrintEnabled) { \
38 ::plugin::gNaClPluginDebugPrintEnabled = \
39 ::plugin::NaClPluginDebugPrintCheckEnv(); \
40 ::plugin::gNaClPluginLogFile = ::plugin::NaClPluginLogFileEnv();\
44 #define PLUGIN_PRINTF(args) do { \
45 INIT_PLUGIN_LOGGING(); \
46 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \
47 ::plugin::NaClPluginPrintLog("PLUGIN %" NACL_PRIu64 ": ", \
48 NaClGetTimeOfDayMicroseconds()); \
49 ::plugin::NaClPluginPrintLog args; \
53 // MODULE_PRINTF is used in the module because PLUGIN_PRINTF uses a
54 // a timer that may not yet be initialized.
55 #define MODULE_PRINTF(args) do { \
56 INIT_PLUGIN_LOGGING(); \
57 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \
58 ::plugin::NaClPluginPrintLog("MODULE: "); \
59 ::plugin::NaClPluginPrintLog args; \
63 # define PLUGIN_PRINTF(args) do { if (0) { printf args; } } while (0)
64 # define MODULE_PRINTF(args) do { if (0) { printf args; } } while (0)
65 /* allows DCE but compiler can still do format string checks */
70 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_