1/*
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef VMInspector_h
27#define VMInspector_h
28
29#define ENABLE_VMINSPECTOR 0
30
31#include "CallFrame.h"
32#include "JSCJSValue.h"
33#include <stdarg.h>
34#include <stdio.h>
35#include <wtf/text/WTFString.h>
36
37namespace JSC {
38
39#if ENABLE(VMINSPECTOR)
40
41class VMInspector {
42public:
43    static JS_EXPORT_PRIVATE const char* getTypeName(JSValue);
44    static JS_EXPORT_PRIVATE void dumpFrame0(CallFrame*);
45    static JS_EXPORT_PRIVATE void dumpFrame(CallFrame*, const char* prefix = 0, const char* funcName = 0, const char* file = 0, int line = -1);
46    static JS_EXPORT_PRIVATE int countFrames(CallFrame*);
47
48    // Special family of ...printf() functions that support, in addition to the
49    // standard % formats (e.g. %d, %s, etc), the following extra JSC formatting
50    // options, %J<x>, where <x> consists of:
51    //
52    //   +    - verbose mode modifier.
53    //          Used in combination with other options. Must come after the %J.
54    //   s    - WTF::String*
55    //
56    // Examples of usage:
57    //
58    //    WTF::String str("My WTF String");
59    //
60    //    // Printing the string. Will print:
61    //    // The wtf string says: "My WTF String" and is NOT EMPTY.
62    //
63    //    VMInspector::printf("The wtf string says: \"%Js\" and is %s\n",
64    //        &str, str.isEmpty()?"EMPTY":"NOT EMPTY");
65    //
66    //    // Printing the string with verbose mode. Will print:
67    //    // <WTF::String "My WTF String">
68    //
69    //    VMInspector::printf("<%J+s>\n", &str);
70    //
71    // Also added some convenience non-JS formats:
72    //
73    //   %b    - boolean (va_args will look for an int).
74    //           Prints TRUE if non-zero, else prints FALSE.
75    //
76    // Caution: the user is expected to pass the correctly matched arguments
77    // to pair with the corresponding % fomatting.
78
79    static JS_EXPORT_PRIVATE void fprintf(FILE*, const char* format, ...);
80    static JS_EXPORT_PRIVATE void printf(const char* format, ...);
81    static JS_EXPORT_PRIVATE void sprintf(char*, const char* format, ...);
82    static JS_EXPORT_PRIVATE void snprintf(char*, size_t, const char* format, ...);
83};
84
85#endif // ENABLE(VMINSPECTOR)
86
87} // namespace JSC
88
89#endif // VMInspector.h
90