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