Source code

Revision control

Other Tools

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 AutoSuppressHazardsForTest {
37
int dummy;
38
AutoSuppressHazardsForTest() : dummy(3) {}
39
~AutoSuppressHazardsForTest() {
40
// Need nontrivial destructor.
41
usePointer(&dummy);
42
}
43
} JS_HAZ_GC_SUPPRESSED;
44
45
struct GDBFragment {
46
GDBFragment() {
47
next = allFragments;
48
allFragments = this;
49
}
50
51
// The name of this fragment. gdb-tests.cpp runs the fragments whose names
52
// are passed to it on the command line.
53
virtual const char* name() = 0;
54
55
// Run the fragment code. |argv| is a reference to the pointer into the
56
// command-line argument vector, referring to the argument immediately
57
// following this fragment's name. The fragment can consume arguments and
58
// advance argv if it wishes.
59
virtual void run(JSContext* cx, const char**& argv) = 0;
60
61
// We declare one instance of this type for each fragment to run. The
62
// constructor adds each instance to a linked list, of which this is
63
// the head.
64
static GDBFragment* allFragments;
65
66
// The link in the list of all instances.
67
GDBFragment* next;
68
};
69
70
// Macro for declaring a C++ fragment for some Python unit test to call. Usage:
71
//
72
// FRAGMENT(<category>, <name>) { <body of fragment function> }
73
//
74
// where <category> and <name> are identifiers. The gdb-tests executable
75
// takes a series of fragment names as command-line arguments and runs them in
76
// turn; each fragment is named <category>.<name> on the command line.
77
//
78
// The body runs in a scope where 'cx' is a usable JSContext*.
79
80
#define FRAGMENT(category, subname) \
81
class FRAGMENT_CLASS_NAME(category, subname) : public GDBFragment { \
82
void run(JSContext* cx, const char**& argv) override; \
83
const char* name() override { \
84
return FRAGMENT_STRING_NAME(category, subname); \
85
} \
86
static FRAGMENT_CLASS_NAME(category, subname) singleton; \
87
}; \
88
FRAGMENT_CLASS_NAME(category, subname) \
89
FRAGMENT_CLASS_NAME(category, subname)::singleton; \
90
void FRAGMENT_CLASS_NAME(category, subname)::run(JSContext* cx, \
91
const char**& argv)
92
93
#define FRAGMENT_STRING_NAME(category, subname) (#category "." #subname)
94
#define FRAGMENT_CLASS_NAME(category, subname) Fragment_##category##_##subname
95
96
#endif /* gdb_gdb_tests_h */