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