Changeset View
Changeset View
Standalone View
Standalone View
libraries/source/spidermonkey/include-win32-debug/js/Debug.h
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- | ||||
* vim: set ts=8 sts=4 et sw=4 tw=99: | * vim: set ts=8 sts=4 et sw=4 tw=99: | ||||
* This Source Code Form is subject to the terms of the Mozilla Public | * This Source Code Form is subject to the terms of the Mozilla Public | ||||
* License, v. 2.0. If a copy of the MPL was not distributed with this | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||||
// Interfaces by which the embedding can interact with the Debugger API. | // Interfaces by which the embedding can interact with the Debugger API. | ||||
#ifndef js_Debug_h | #ifndef js_Debug_h | ||||
#define js_Debug_h | #define js_Debug_h | ||||
#include "mozilla/Assertions.h" | #include "mozilla/Assertions.h" | ||||
#include "mozilla/Attributes.h" | #include "mozilla/Attributes.h" | ||||
#include "mozilla/MemoryReporting.h" | #include "mozilla/MemoryReporting.h" | ||||
#include "mozilla/UniquePtr.h" | |||||
#include "jsapi.h" | #include "jsapi.h" | ||||
#include "jspubtd.h" | #include "jspubtd.h" | ||||
#include "js/GCAPI.h" | #include "js/GCAPI.h" | ||||
#include "js/RootingAPI.h" | #include "js/RootingAPI.h" | ||||
#include "js/TypeDecls.h" | #include "js/TypeDecls.h" | ||||
namespace js { | namespace js { | ||||
class Debugger; | class Debugger; | ||||
} // namespace js | } // namespace js | ||||
namespace JS { | namespace JS { | ||||
using mozilla::UniquePtr; | |||||
namespace dbg { | namespace dbg { | ||||
// Helping embedding code build objects for Debugger | // Helping embedding code build objects for Debugger | ||||
// ------------------------------------------------- | // ------------------------------------------------- | ||||
// | // | ||||
// Some Debugger API features lean on the embedding application to construct | // Some Debugger API features lean on the embedding application to construct | ||||
// their result values. For example, Debugger.Frame.prototype.scriptEntryReason | // their result values. For example, Debugger.Frame.prototype.scriptEntryReason | ||||
// calls hooks provided by the embedding to construct values explaining why it | // calls hooks provided by the embedding to construct values explaining why it | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | class BuiltThing { | ||||
protected: | protected: | ||||
// The Builder to which this trusted thing belongs. | // The Builder to which this trusted thing belongs. | ||||
Builder& owner; | Builder& owner; | ||||
// A rooted reference to our value. | // A rooted reference to our value. | ||||
PersistentRooted<T> value; | PersistentRooted<T> value; | ||||
BuiltThing(JSContext* cx, Builder& owner_, T value_ = js::GCMethods<T>::initial()) | BuiltThing(JSContext* cx, Builder& owner_, T value_ = GCPolicy<T>::initial()) | ||||
: owner(owner_), value(cx, value_) | : owner(owner_), value(cx, value_) | ||||
{ | { | ||||
owner.assertBuilt(value_); | owner.assertBuilt(value_); | ||||
} | } | ||||
// Forward some things from our owner, for convenience. | // Forward some things from our owner, for convenience. | ||||
js::Debugger* debugger() const { return owner.debugger; } | js::Debugger* debugger() const { return owner.debugger; } | ||||
JSObject* debuggerObject() const { return owner.debuggerObject; } | JSObject* debuggerObject() const { return owner.debuggerObject; } | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | |||||
// Finding the size of blocks allocated with malloc | // Finding the size of blocks allocated with malloc | ||||
// ------------------------------------------------ | // ------------------------------------------------ | ||||
// | // | ||||
// Debugger.Memory wants to be able to report how many bytes items in memory are | // Debugger.Memory wants to be able to report how many bytes items in memory are | ||||
// consuming. To do this, it needs a function that accepts a pointer to a block, | // consuming. To do this, it needs a function that accepts a pointer to a block, | ||||
// and returns the number of bytes allocated to that block. SpiderMonkey itself | // and returns the number of bytes allocated to that block. SpiderMonkey itself | ||||
// doesn't know which function is appropriate to use, but the embedding does. | // doesn't know which function is appropriate to use, but the embedding does. | ||||
// Tell Debuggers in |runtime| to use |mallocSizeOf| to find the size of | // Tell Debuggers in |cx| to use |mallocSizeOf| to find the size of | ||||
// malloc'd blocks. | // malloc'd blocks. | ||||
JS_PUBLIC_API(void) | JS_PUBLIC_API(void) | ||||
SetDebuggerMallocSizeOf(JSRuntime* runtime, mozilla::MallocSizeOf mallocSizeOf); | SetDebuggerMallocSizeOf(JSContext* cx, mozilla::MallocSizeOf mallocSizeOf); | ||||
// Get the MallocSizeOf function that the given runtime is using to find the | // Get the MallocSizeOf function that the given context is using to find the | ||||
// size of malloc'd blocks. | // size of malloc'd blocks. | ||||
JS_PUBLIC_API(mozilla::MallocSizeOf) | JS_PUBLIC_API(mozilla::MallocSizeOf) | ||||
GetDebuggerMallocSizeOf(JSRuntime* runtime); | GetDebuggerMallocSizeOf(JSContext* cx); | ||||
␌ | ␌ | ||||
// Debugger and Garbage Collection Events | // Debugger and Garbage Collection Events | ||||
// -------------------------------------- | // -------------------------------------- | ||||
// | // | ||||
// The Debugger wants to report about its debuggees' GC cycles, however entering | // The Debugger wants to report about its debuggees' GC cycles, however entering | ||||
// JS after a GC is troublesome since SpiderMonkey will often do something like | // JS after a GC is troublesome since SpiderMonkey will often do something like | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
// | // | ||||
// Construct an instance of this class on the stack, providing a JSContext | // Construct an instance of this class on the stack, providing a JSContext | ||||
// belonging to the runtime in which execution will occur. Each time we enter | // belonging to the runtime in which execution will occur. Each time we enter | ||||
// JavaScript --- specifically, each time we push a JavaScript stack frame that | // JavaScript --- specifically, each time we push a JavaScript stack frame that | ||||
// has no older JS frames younger than this AutoEntryMonitor --- we will | // has no older JS frames younger than this AutoEntryMonitor --- we will | ||||
// call the appropriate |Entry| member function to indicate where we've begun | // call the appropriate |Entry| member function to indicate where we've begun | ||||
// execution. | // execution. | ||||
class MOZ_STACK_CLASS AutoEntryMonitor { | class MOZ_STACK_CLASS JS_PUBLIC_API(AutoEntryMonitor) { | ||||
JSRuntime* runtime_; | JSRuntime* runtime_; | ||||
AutoEntryMonitor* savedMonitor_; | AutoEntryMonitor* savedMonitor_; | ||||
public: | public: | ||||
explicit AutoEntryMonitor(JSContext* cx); | explicit AutoEntryMonitor(JSContext* cx); | ||||
~AutoEntryMonitor(); | ~AutoEntryMonitor(); | ||||
// SpiderMonkey reports the JavaScript entry points occuring within this | // SpiderMonkey reports the JavaScript entry points occuring within this | ||||
// AutoEntryMonitor's scope to the following member functions, which the | // AutoEntryMonitor's scope to the following member functions, which the | ||||
// embedding is expected to override. | // embedding is expected to override. | ||||
// | |||||
// It is important to note that |asyncCause| is owned by the caller and its | |||||
// lifetime must outlive the lifetime of the AutoEntryMonitor object. It is | |||||
// strongly encouraged that |asyncCause| be a string constant or similar | |||||
// statically allocated string. | |||||
// We have begun executing |function|. Note that |function| may not be the | // We have begun executing |function|. Note that |function| may not be the | ||||
// actual closure we are running, but only the canonical function object to | // actual closure we are running, but only the canonical function object to | ||||
// which the script refers. | // which the script refers. | ||||
virtual void Entry(JSContext* cx, JSFunction* function, | virtual void Entry(JSContext* cx, JSFunction* function, | ||||
HandleValue asyncStack, | HandleValue asyncStack, | ||||
HandleString asyncCause) = 0; | const char* asyncCause) = 0; | ||||
// Execution has begun at the entry point of |script|, which is not a | // Execution has begun at the entry point of |script|, which is not a | ||||
// function body. (This is probably being executed by 'eval' or some | // function body. (This is probably being executed by 'eval' or some | ||||
// JSAPI equivalent.) | // JSAPI equivalent.) | ||||
virtual void Entry(JSContext* cx, JSScript* script, | virtual void Entry(JSContext* cx, JSScript* script, | ||||
HandleValue asyncStack, | HandleValue asyncStack, | ||||
HandleString asyncCause) = 0; | const char* asyncCause) = 0; | ||||
// Execution of the function or script has ended. | // Execution of the function or script has ended. | ||||
virtual void Exit(JSContext* cx) { } | virtual void Exit(JSContext* cx) { } | ||||
}; | }; | ||||
} // namespace dbg | } // namespace dbg | ||||
} // namespace JS | } // namespace JS | ||||
#endif /* js_Debug_h */ | #endif /* js_Debug_h */ |
Wildfire Games · Phabricator