DebugCmdLine.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* DebugCmdLine.qm Copyright 2013 - 2018 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum required Qore version
namespace DebugCmdLine {
class WrapperGetOpt : public GetOpt {
public:
constructor(hash options) ;
split(list<string> args, reference<list<string>> wrp_args, reference<*string> pgm_name, reference<list<string>> pgm_args);
};
class DebugCommandLine : public AbstractDebugControl {
public:
public :
string ln_prompt = 'qdbg> ';
hash cx;
const defaultHistoryFileName = '.qdbg.history';
const defaultIndent = " ";
public:
private :
const fcHelp = 0x01;
const fcExpandUniqueCmd = 0x02;
const fcValidate = 0x04;
const fcFallback = 0x08;
*string historyFileName;
Qore::Thread::RWLock rwlContext();
hash commands = (
'>': (
'help': (
'**': (
'desc': 'help/*',
'enum';
,
'action';
,
),
'desc': 'get help about command',
'action';
,
),
'version': (
'desc': 'get version info. Check "host" key to see if server side is reponding',
'action';
,
),
'history': (
'>': (
'load': (
'desc': 'load command line history from file, args: filename',
'action';
,
),
'save': (
'desc': 'save command line history to file, args: filename',
'action';
,
),
),
'desc': 'load or save history to file. The history is implicitly loaded when program starting and saved when exiting. See command line parameters.',
),
'quit': (
'desc': 'quit debugger',
'action';
,
),
'cmd': (
'desc': 'send a command to the server and show the output',
'action';
,
),
'frame': (
'>': {
'set': (
'desc': 'set current stack frame, args: frameId',
'*': (
'enum';
,
'validate': \DebugCommandLine::validateInt(),
'action';
,
),
),
'get': (
'desc': 'get current stack frame',
'action';
,
),
},
'fallback';
,
'desc': 'Stack frame related commands',
),
'session': (
'desc': 'get list of debugged programs, stopped threads and breakpoint stats',
'action';
,
'>': (
'load': (
'desc': 'load session from file, args: filename',
'action';
,
),
'save': (
'desc': 'save session to file, args: filename',
'action';
,
),
),
),
'program': (
'alias': 'pgm',
),
'pgm': (
'>': (
'load': (
'desc': 'load and run script, args: filename [args..]',
'action';
,
),
'search': (
'desc': 'regex search for a program, args: regex',
'action';
,
),
'list': (
'>': (
'full': (
'desc': 'verbose program listing',
'action';
,
),
),
'desc': 'list programs, [full] for a verbose listing',
'action';
,
),
'set': (
'desc': 'set current program, arg: programId',
'*': (
'enum';
,
'validate': \DebugCommandLine::validateInt(),
'action';
,
),
),
'get': (
'desc': 'get current program',
'action';
,
),
'add': (
'desc': 'add current program for debugging',
'action';
,
),
'remove': (
'desc': 'remove current program from debugging',
'action';
,
),
'stop': (
'desc': 'stop current program, args: [threadId] to stop particular thread',
'action';
,
),
'global': (
'*': (
'enum';
,
'action';
,
),
'action';
,
'desc': 'get/set global variable, args: varName [value]',
),
'define': (
'*': (
'enum';
,
'action';
,
),
'action';
,
'desc': 'get defines, args: [defineName]',
),
'options': (
'desc': 'list parse options',
'action';
,
),
'info': (
'desc': 'get info about current program and list threads',
'action';
,
),
),
'desc': 'program related commands',
/* TODO: what is intended enumeration ?
'enum': list sub(DebugCommandLine dcl, softlist path, softlist args) {
hash data.cmd = 'program//list';
*hash pgm_info = dcl.doCommandImpl(data);
list rv = ();
*string p = shift path;
bool id = p =~ /^[0-9]+$/;
foreach hash h in (pgm_info.pairIterator()) {
if (!p.val())
rv += h.key.toInt();
else {
if (id) {
if (regex(h.key, "^" + p))
rv += h.key.toInt();
}
else if (h.value.scriptName.val() && regex(h.value.scriptName, "^" + p))
rv += h.value.scriptName();
}
}
return rv;
},
*/
'fallback';
,
),
'break': (
'>': (
'list': (
'desc': 'list breakpoints for current program',
'action';
,
'>': (
'all': (
'desc': 'list breakpoints for all programs',
'action';
,
),
),
),
'create': (
'desc': 'create breakpoint and get breakpointId. Optionally assign to particular statement, i.e. code line, or do it later using "statement assign". args: [function([args, ...])] | [file] lineno | //statementId',
'action';
,
),
'delete': (
'*': (
'enum';
,
'action';
,
),
'desc': 'delete breakpoint, args: breakpointId',
),
'enable': (
'*': (
'enum';
,
'action';
,
),
'desc': 'enable breakpoint, args: breakpointId',
),
'disable': (
'*': (
'enum';
,
'action';
,
),
'desc': 'disable breakpoint, args: breakpointId',
),
'policy': (
'*': (
'enum';
,
'*': (
'enum';
,
'action';
,
),
'action';
,
),
'desc': sprintf('get/set breakpoint policy, args: breakpointId [%s]', (keys AbstractDebugControl::policyStrings).join('|')),
),
'thread': (
'*': (
'enum';
,
'action';
,
),
'desc': 'get/set threads assigned to breakpoint, args: breakpointId ["+"/"-" threadId | threadId ..]',
'action';
,
),
'statement': (
'*': (
'enum';
,
'action';
,
),
'desc': 'get statement list assigned to breakpoint, args: breakpointId',
),
),
'desc': 'breakpoint related commands',
),
'statement': (
'alias': 'stmt',
),
'stmt': (
'>': (
'list': (
'*': (
'enum';
,
'action';
,
),
'desc': 'list statements, args: breakpointId', // duplicate to breakpoint/statement
),
'assign': (
'*': (
'enum';
,
'action';
,
),
'desc': 'assign statement to breakpoint, args: breakpointId [function([args, ...])] | [file] lineno | //statementId',
),
'unassign': (
'*': (
'enum';
,
'action';
,
),
'desc': 'unassign statement from breakpoint, args: breakpointId [function([args, ...])] | [file] lineno | //statementId',
),
),
'desc': 'statement related commands',
),
'thread': (
'>': (
'set': (
'*': (
'desc': 'set current thread, args: threadId',
'enum';
,
'validate': \DebugCommandLine::validateInt(),
'action';
,
),
),
'get': (
'desc': 'get current thread',
'action';
,
),
'local': (
'*': (
'enum';
,
'action';
,
),
'action';
,
'desc': 'get/set local variable, args: varName [value]',
),
'debug': (
'*': (
'enum';
,
'action';
,
),
'desc': 'get/set special debug variable, args: varName [value], use "thread debug list" command result to see value list of varNames',
),
'pgmlist': (
'desc': 'show threads and related programs, interrupted programs are marked with \"S\"',
'action';
,
),
'list': (
'desc': 'show list of threads and top level stack position',
'action';
,
)
),
'desc': 'thread related commands',
'fallback';
,
),
'stack': (
'alias': 'bt',
),
'backtrace': (
'alias': 'bt',
),
'bt': (
'desc': 'get stack for current thread',
'action';
,
'>': (
'all': (
'desc': 'show call stack for all threads',
'action';
,
),
),
),
'go': (
'*': (
'enum';
,
'action';
,
),
'desc': sprintf('go thread with specified runstate, arg: %s', (keys AbstractDebugControl::runStateStrings).join('|')),
'action';
,
),
),
);
public:
constructor();
abstract *hash doCommandImpl(hash data);
doCommand(hash data);
showPrograms(hash ph, bool show_interrupted);
showBreakpoints(*list bkpts);
string getThreadStackStr(hash lh);
showThreadStack(softint tid, list stack);
static validateInt(DebugCommandLine dcl, softlist path, softlist val);
auto parseValue();
auto getContextValue(string key);
setContextValue(string key, auto value);
hash getStatementValue(list args);
private:
list splitCmd(string line);
public:
string listVariantCmds(hash v);
*hash findCmd(list args, int opts = 0, *reference<int> last_param) { /* because it is needed from closure */ hash result;
result.path = ();
hash<auto> c = commands;
last_param = 0;
while (args);
result.args = args;
return result;
}
private:
list ln_callback(string line);
public:
runCmdLine();
private:
bool isOneLineArray(list x);
public:
printVar(string name, hash value);
printHuman(hash x, string indent = defaultIndent);
printHuman(list x, string indent = defaultIndent);
printHuman(string x, string indent = defaultIndent);
printHuman(any x, string indent = defaultIndent);
printData(auto data);
printLinenoise(*string outs);
int checkProgramId();
int checkThreadId();
static softlist enumBreakpointId(DebugCommandLine dcl, softlist path, softlist args);
loadSession(*string fn);
init(hash opt);
};
};
sprintf
string sprintf(string fmt,...)
list
list list(...)
split
list< string > split(string sep, string str, bool with_separator=False)
Qore::Thread::RWLock
hash
hash hash(object obj)