1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2006
21 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __avmshell_AvmDebugCLI__
41 #define __avmshell_AvmDebugCLI__
47 * Represents a single breakpoint in the Debugger.
49 class BreakAction
: public MMgc::GCObject
52 GCMember
<BreakAction
> prev
;
53 DWB(BreakAction
*) next
;
54 DWB(SourceFile
*) sourceFile
;
56 DRCWB(Stringp
) filename
;
59 BreakAction(SourceFile
*sourceFile
,
64 this->sourceFile
= sourceFile
;
66 this->filename
= filename
;
67 this->linenum
= linenum
;
70 void print(PrintWriter
& out
);
74 * This can be either an l-value or an r-value.
76 class IValue
: public MMgc::GCFinalizedObject
81 virtual bool isLValue() = 0;
82 virtual Atom
get() = 0;
83 virtual void set(Atom newValue
) = 0;
86 class ConstantValue
: public IValue
89 ConstantValue(Atom value
) : value(value
) { }
91 virtual bool isLValue() { return false; }
92 virtual Atom
get() { return value
; }
93 virtual void set(Atom
/*newValue*/) { AvmAssert(false); }
100 * An IValue representing a local variable.
102 class LocalValue
: public IValue
105 LocalValue(DebugFrame
* frame
, int index
) : frame(frame
), index(index
) { }
107 virtual bool isLValue() { return true; }
112 frame
->locals(locals
, countLocals
);
113 return locals
[index
];
115 virtual void set(Atom newValue
)
117 frame
->setLocal(index
, newValue
);
121 DWB(DebugFrame
*) frame
;
126 * An IValue representing an argument to a function.
128 class ArgumentValue
: public IValue
131 ArgumentValue(DebugFrame
* frame
, int index
) : frame(frame
), index(index
) { }
133 virtual bool isLValue() { return true; }
138 frame
->arguments(arguments
, countArguments
);
139 return arguments
[index
];
141 virtual void set(Atom newValue
)
143 frame
->setArgument(index
, newValue
);
147 DWB(DebugFrame
*) frame
;
152 * An IValue representing a property of an object.
154 class PropertyValue
: public IValue
157 PropertyValue(ScriptObject
* parent
, Multiname
& propertyname
)
158 : parent(parent
), propertyname(propertyname
) { }
160 virtual bool isLValue() { return true; }
163 return parent
->toplevel()->getproperty(parent
->atom(), propertyname
, parent
->vtable
);
165 virtual void set(Atom newValue
)
167 parent
->toplevel()->setproperty(parent
->atom(), propertyname
, newValue
, parent
->vtable
);
171 DRCWB(ScriptObject
*) parent
;
172 HeapMultiname propertyname
;
176 * A simple command line interface for the Debugger.
177 * Supports a gdb-like command line.
179 class GC_CPP_EXACT_IFDEF(DebugCLI
, avmplus::Debugger
, DEBUGGER
)
182 DebugCLI(AvmCore
*core
, Debugger::TraceLevel tracelevel
);
184 /** @name command codes */
204 /** @name info sub commands */
207 INFO_UNKNOWN_CMD
= 100,
218 * StringInt is used to store the command arrays
219 * used to translate command strings into command codes
227 REALLY_INLINE
static DebugCLI
* create(MMgc::GC
* gc
, AvmCore
*core
, Debugger::TraceLevel tracelevel
)
229 return new (gc
, MMgc::kExact
) DebugCLI(core
, tracelevel
);
234 void enterDebugger();
235 void setCurrentSource(Stringp file
);
236 bool filterException(Exception
*exception
, bool willBeCaught
);
237 bool hitWatchpoint() { return false; }
240 * @name command implementations
243 void breakpoint(char *location
);
244 void deleteBreakpoint(char *idstr
);
245 void showBreakpoints();
247 void locals(int frameNumber
);
248 void arguments(int frameNumber
);
251 static bool printFrame(int frameNumber
);
252 static bool debuggerInterruptOnEnter
;
257 void list(const char* line
);
258 void print(char *name
);
262 void activate() { activeFlag
= true; }
264 static MethodInfo
* functionFor(SourceInfo
* src
, int line
);
267 * Formats a value for display to the user. Very similar to
268 * AvmCore::format(), but does a few extra things.
270 Stringp
formatValue(Atom value
);
272 GC_DATA_BEGIN(DebugCLI
)
277 uint32_t currentSourceLen
;
278 DRCWB(Stringp
) GC_POINTER(currentFile
);
280 bool warnMissingSource
;
282 DWB(BreakAction
*) GC_POINTER(firstBreakAction
);
283 DWB(BreakAction
*) GC_POINTER(lastBreakAction
);
285 enum { kMaxCommandLine
= 1024 };
286 char commandLine
[kMaxCommandLine
];
287 char lastCommand
[kMaxCommandLine
];
290 GC_DATA_END(DebugCLI
)
295 void displayLines(int linenum
, int count
);
297 char* lineStart(int linenum
);
298 Atom
ease2Atom(const char* to
, Atom baseline
);
300 void throwUndefinedVarError(const char* name
);
303 * Gets a value. "name" can be either a constant (string,
304 * number, boolean, undefined, null, xml, xmllist), or the
305 * name of a local, argument, or member of a variable on
308 IValue
* getValue(const char *name
);
311 * Evaluates an expression, and returns its value.
312 * *outSawTrailingDot is set to true if the expression has a trailing
313 * dot, e.g. "foo." or "foo.bar."
315 IValue
* evaluate(char *expr
, bool* outSawTrailingDot
);
318 * @name command name arrays and support code
321 int determineCommand(StringInt cmdList
[],
324 const char* commandNumberToCommandName(StringInt cmdList
[],
326 int commandFor(const char *input
) {
327 return determineCommand(commandArray
, input
, CMD_UNKNOWN
);
329 int infoCommandFor(const char *input
) {
330 return determineCommand(infoCommandArray
, input
, INFO_UNKNOWN_CMD
);
333 static StringInt commandArray
[];
334 static StringInt infoCommandArray
[];
339 * Helper class to iterate over all properties of an object (both slots
340 * and dynamic properties).
342 class PropertyIterator
346 * atom: the object whose properties we will iterate over.
348 PropertyIterator(AvmCore
* core
, Atom atom
);
349 virtual ~PropertyIterator() {}
352 * Iterates over all the object's properties, and calls process()
353 * for each one. If process() ever returns false, iteration halts.
359 * Called once for each property that has been found. If process()
360 * ever returns false, iteration halts.
362 virtual bool process(Multiname
* key
, BindingKind bk
) = 0;
365 ScriptObject
* object
;
369 * Helper to find a property with the given name. Since this is for the
370 * debugger, it ignores visibility issues -- e.g. it will match any property
371 * with the given name, even if that property is private and therefore not
372 * visible from the caller's context.
374 * After you call iterate(), 'value' will be the property's value if it was
375 * found, or NULL if it was not found.
377 * This class can only be used on the stack. ('value' does not have a write
378 * barrier around it.)
380 class StPropertyFinder
: public PropertyIterator
384 * atom: The object in which we want to look for a property.
385 * propertyname: The property name to look for.
387 StPropertyFinder(AvmCore
* core
, Atom atom
, const char* propertyname
);
393 * Returns true if the key matches the originally passed-in property name.
395 bool matches(const Multiname
* key
) const;
397 virtual bool process(Multiname
* key
, BindingKind bk
);
399 const char* propertyname
;
403 * Prints all of an object's properties, and their values, to core->console.
405 class PropertyPrinter
: public PropertyIterator
408 PropertyPrinter(AvmCore
* core
, DebugCLI
* debugger
, Atom atom
);
411 virtual bool process(Multiname
* key
, BindingKind bk
);
418 #endif /* __avmshell_AvmDebugCLI__ */