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
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef dbg_DebugScript_h
8
#define dbg_DebugScript_h
9
10
#include <stddef.h> // for offsetof
11
#include <stddef.h> // for size_t
12
#include <stdint.h> // for uint32_t
13
14
#include "jsapi.h"
15
#include "jstypes.h"
16
17
namespace JS {
18
class JS_PUBLIC_API Realm;
19
}
20
21
namespace js {
22
23
class JSBreakpointSite;
24
class Debugger;
25
26
// DebugScript manages the internal debugger state for a JSScript, which may be
27
// associated with multiple Debuggers.
28
class DebugScript {
29
friend class DebugAPI;
30
31
/*
32
* If this is a generator script, this is the number of Debugger.Frames
33
* referring to calls to this generator, whether live or suspended. Closed
34
* generators do not contribute a count.
35
*
36
* When greater than zero, this script should be compiled with debug
37
* instrumentation to call Debugger::onResumeFrame at each resumption site, so
38
* that Debugger can reconnect any extant Debugger.Frames with the new
39
* concrete frame.
40
*/
41
uint32_t generatorObserverCount;
42
43
/*
44
* The number of Debugger.Frame objects that refer to frames running this
45
* script and that have onStep handlers. When nonzero, the interpreter and JIT
46
* must arrange to call Debugger::onSingleStep before each bytecode, or at
47
* least at some useful granularity.
48
*/
49
uint32_t stepperCount;
50
51
/*
52
* Number of breakpoint sites at opcodes in the script. This is the number
53
* of populated entries in DebugScript::breakpoints, below.
54
*/
55
uint32_t numSites;
56
57
/*
58
* Breakpoints set in our script. For speed and simplicity, this array is
59
* parallel to script->code(): the JSBreakpointSite for the opcode at
60
* script->code()[offset] is debugScript->breakpoints[offset]. Naturally,
61
* this array's true length is script->length().
62
*/
63
JSBreakpointSite* breakpoints[1];
64
65
/*
66
* True if this DebugScript carries any useful information. If false, it
67
* should be removed from its JSScript.
68
*/
69
bool needed() const {
70
return generatorObserverCount > 0 || stepperCount > 0 || numSites > 0;
71
}
72
73
static size_t allocSize(size_t codeLength) {
74
return offsetof(DebugScript, breakpoints) +
75
codeLength * sizeof(JSBreakpointSite*);
76
}
77
78
void trace(JSTracer* trc, JSScript* owner);
79
void delete_(JSFreeOp* fop, JSScript* owner);
80
81
static DebugScript* get(JSScript* script);
82
static DebugScript* getOrCreate(JSContext* cx, JSScript* script);
83
84
public:
85
static JSBreakpointSite* getBreakpointSite(JSScript* script, jsbytecode* pc);
86
static JSBreakpointSite* getOrCreateBreakpointSite(JSContext* cx,
87
JSScript* script,
88
jsbytecode* pc);
89
static void destroyBreakpointSite(JSFreeOp* fop, JSScript* script,
90
jsbytecode* pc);
91
92
static void clearBreakpointsIn(JSFreeOp* fop, JS::Realm* realm, Debugger* dbg,
93
JSObject* handler);
94
static void clearBreakpointsIn(JSFreeOp* fop, JSScript* script, Debugger* dbg,
95
JSObject* handler);
96
97
#ifdef DEBUG
98
static uint32_t getStepperCount(JSScript* script);
99
#endif
100
101
/*
102
* Increment or decrement the single-step count. If the count is non-zero
103
* then the script is in single-step mode.
104
*
105
* Only incrementing is fallible, as it could allocate a DebugScript.
106
*/
107
static MOZ_MUST_USE bool incrementStepperCount(JSContext* cx,
108
JSScript* script);
109
static void decrementStepperCount(JSFreeOp* fop, JSScript* script);
110
111
/*
112
* Increment or decrement the generator observer count. If the count is
113
* non-zero then the script reports resumptions to the debugger.
114
*
115
* Only incrementing is fallible, as it could allocate a DebugScript.
116
*/
117
static MOZ_MUST_USE bool incrementGeneratorObserverCount(JSContext* cx,
118
JSScript* script);
119
static void decrementGeneratorObserverCount(JSFreeOp* fop, JSScript* script);
120
};
121
122
} /* namespace js */
123
124
#endif /* dbg_DebugScript_h */