js/src/gdb/gdb-tests.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef gdb_gdb_tests_h
michael@0 9 #define gdb_gdb_tests_h
michael@0 10
michael@0 11 // Support for C++ fragments to be used by Python unit tests for SpiderMonkey's
michael@0 12 // GDB support.
michael@0 13 //
michael@0 14 // That is:
michael@0 15 // - js/src/gdb/mozilla holds the actual GDB SpiderMonkey support code.
michael@0 16 // - Each '.py' file in js/src/gdb/tests is a unit test for the above.
michael@0 17 // - Each '.cpp' file in js/src/gdb/tests is C++ code for one of the unit tests
michael@0 18 // to run.
michael@0 19 //
michael@0 20 // (So the .cpp files are two steps removed from being anything one would
michael@0 21 // actually run.)
michael@0 22
michael@0 23 #include "NamespaceImports.h"
michael@0 24
michael@0 25 void breakpoint();
michael@0 26
michael@0 27 struct GDBFragment {
michael@0 28 GDBFragment() {
michael@0 29 next = allFragments;
michael@0 30 allFragments = this;
michael@0 31 }
michael@0 32
michael@0 33 // The name of this fragment. gdb-tests.cpp runs the fragments whose names
michael@0 34 // are passed to it on the command line.
michael@0 35 virtual const char *name() = 0;
michael@0 36
michael@0 37 // Run the fragment code. |argv| is a reference to the pointer into the
michael@0 38 // command-line argument vector, referring to the argument immediately
michael@0 39 // following this fragment's name. The fragment can consume arguments and
michael@0 40 // advance argv if it wishes.
michael@0 41 virtual void run(JSContext *cx, const char **&argv) = 0;
michael@0 42
michael@0 43 // We declare one instance of this type for each fragment to run. The
michael@0 44 // constructor adds each instance to a linked list, of which this is
michael@0 45 // the head.
michael@0 46 static GDBFragment *allFragments;
michael@0 47
michael@0 48 // The link in the list of all instances.
michael@0 49 GDBFragment *next;
michael@0 50 };
michael@0 51
michael@0 52 // Macro for declaring a C++ fragment for some Python unit test to call. Usage:
michael@0 53 //
michael@0 54 // FRAGMENT(<category>, <name>) { <body of fragment function> }
michael@0 55 //
michael@0 56 // where <category> and <name> are identifiers. The gdb-tests executable
michael@0 57 // takes a series of fragment names as command-line arguments and runs them in
michael@0 58 // turn; each fragment is named <category>.<name> on the command line.
michael@0 59 //
michael@0 60 // The body runs in a scope where 'cx' is a usable JSContext *.
michael@0 61
michael@0 62 #define FRAGMENT(category, subname) \
michael@0 63 class FRAGMENT_CLASS_NAME(category, subname): public GDBFragment { \
michael@0 64 void run(JSContext *cx, const char **&argv); \
michael@0 65 const char *name() { return FRAGMENT_STRING_NAME(category, subname); } \
michael@0 66 static FRAGMENT_CLASS_NAME(category, subname) singleton; \
michael@0 67 }; \
michael@0 68 FRAGMENT_CLASS_NAME(category, subname) FRAGMENT_CLASS_NAME(category, subname)::singleton; \
michael@0 69 void FRAGMENT_CLASS_NAME(category, subname)::run(JSContext *cx, const char **&argv)
michael@0 70
michael@0 71 #define FRAGMENT_STRING_NAME(category, subname) (#category "." #subname)
michael@0 72 #define FRAGMENT_CLASS_NAME(category, subname) Fragment_ ## category ## _ ## subname
michael@0 73
michael@0 74 #endif /* gdb_gdb_tests_h */

mercurial