1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/gdb/gdb-tests.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#ifndef gdb_gdb_tests_h 1.12 +#define gdb_gdb_tests_h 1.13 + 1.14 +// Support for C++ fragments to be used by Python unit tests for SpiderMonkey's 1.15 +// GDB support. 1.16 +// 1.17 +// That is: 1.18 +// - js/src/gdb/mozilla holds the actual GDB SpiderMonkey support code. 1.19 +// - Each '.py' file in js/src/gdb/tests is a unit test for the above. 1.20 +// - Each '.cpp' file in js/src/gdb/tests is C++ code for one of the unit tests 1.21 +// to run. 1.22 +// 1.23 +// (So the .cpp files are two steps removed from being anything one would 1.24 +// actually run.) 1.25 + 1.26 +#include "NamespaceImports.h" 1.27 + 1.28 +void breakpoint(); 1.29 + 1.30 +struct GDBFragment { 1.31 + GDBFragment() { 1.32 + next = allFragments; 1.33 + allFragments = this; 1.34 + } 1.35 + 1.36 + // The name of this fragment. gdb-tests.cpp runs the fragments whose names 1.37 + // are passed to it on the command line. 1.38 + virtual const char *name() = 0; 1.39 + 1.40 + // Run the fragment code. |argv| is a reference to the pointer into the 1.41 + // command-line argument vector, referring to the argument immediately 1.42 + // following this fragment's name. The fragment can consume arguments and 1.43 + // advance argv if it wishes. 1.44 + virtual void run(JSContext *cx, const char **&argv) = 0; 1.45 + 1.46 + // We declare one instance of this type for each fragment to run. The 1.47 + // constructor adds each instance to a linked list, of which this is 1.48 + // the head. 1.49 + static GDBFragment *allFragments; 1.50 + 1.51 + // The link in the list of all instances. 1.52 + GDBFragment *next; 1.53 +}; 1.54 + 1.55 +// Macro for declaring a C++ fragment for some Python unit test to call. Usage: 1.56 +// 1.57 +// FRAGMENT(<category>, <name>) { <body of fragment function> } 1.58 +// 1.59 +// where <category> and <name> are identifiers. The gdb-tests executable 1.60 +// takes a series of fragment names as command-line arguments and runs them in 1.61 +// turn; each fragment is named <category>.<name> on the command line. 1.62 +// 1.63 +// The body runs in a scope where 'cx' is a usable JSContext *. 1.64 + 1.65 +#define FRAGMENT(category, subname) \ 1.66 +class FRAGMENT_CLASS_NAME(category, subname): public GDBFragment { \ 1.67 + void run(JSContext *cx, const char **&argv); \ 1.68 + const char *name() { return FRAGMENT_STRING_NAME(category, subname); } \ 1.69 + static FRAGMENT_CLASS_NAME(category, subname) singleton; \ 1.70 +}; \ 1.71 +FRAGMENT_CLASS_NAME(category, subname) FRAGMENT_CLASS_NAME(category, subname)::singleton; \ 1.72 +void FRAGMENT_CLASS_NAME(category, subname)::run(JSContext *cx, const char **&argv) 1.73 + 1.74 +#define FRAGMENT_STRING_NAME(category, subname) (#category "." #subname) 1.75 +#define FRAGMENT_CLASS_NAME(category, subname) Fragment_ ## category ## _ ## subname 1.76 + 1.77 +#endif /* gdb_gdb_tests_h */