pymod.cpp 85.3 KB
Newer Older
1 2
#include "stdafx.h"

3
#include <boost/bind.hpp>
4

SND\EreTIk_cp's avatar
SND\EreTIk_cp committed
5
#include "pykdver.h"
6

7
#include "variant.h"
8
#include "dbgexcept.h"
9
#include "windbgext.h"
10 11

#include "pydbgeng.h"
12
#include "pydbgio.h"
13
#include "pydisasm.h"
14
#include "pyevents.h"
15 16 17 18 19 20 21
#include "pyeventhandler.h"
#include "pymemaccess.h"
#include "pymodule.h"
#include "pysymengine.h"
#include "pytypedvar.h"
#include "pytypeinfo.h"
#include "pycpucontext.h"
22
#include "pyprocess.h"
23
#include "pytagged.h"
24 25 26

using namespace pykd;

27 28
///////////////////////////////////////////////////////////////////////////////

29 30 31 32 33
static const std::string pykdVersion = PYKD_VERSION_BUILD_STR
#ifdef _DEBUG
    " <DBG>"
#endif  // _DEBUG
;
34

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
35
///////////////////////////////////////////////////////////////////////////////
36

37

38
BOOST_PYTHON_FUNCTION_OVERLOADS( startProcess_,  pykd::startProcess, 1, 2 );
ussrhero's avatar
ussrhero committed
39
BOOST_PYTHON_FUNCTION_OVERLOADS( attachProcess_, pykd::attachProcess, 1, 2);
40 41
BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_,  pykd::detachProcess, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( terminateProcess_,  pykd::terminateProcess, 0, 1 );
42
BOOST_PYTHON_FUNCTION_OVERLOADS(closeDump_, pykd::closeDump, 0, 1);
43 44
BOOST_PYTHON_FUNCTION_OVERLOADS( attachKernel_,  pykd::attachKernel, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( evaluate_, pykd::evaluate, 1, 2 );
45
BOOST_PYTHON_FUNCTION_OVERLOADS( debugCommand_, pykd::debugCommand, 1, 2 );
46

47 48
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, pykd::dprint, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, pykd::dprintln, 1, 2 );
49 50 51

//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_findSymbol, Module::getSymbolNameByVa, 1, 2 );

52 53 54 55 56 57 58 59 60 61 62 63 64 65
BOOST_PYTHON_FUNCTION_OVERLOADS( loadChars_, pykd::loadChars, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadWChars_, pykd::loadWChars, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, pykd::loadBytes, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords_, pykd::loadWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords_, pykd::loadDWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords_, pykd::loadQWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes_, pykd::loadSignBytes, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords_, pykd::loadSignWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords_, pykd::loadSignDWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords_, pykd::loadSignQWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadFloats_, pykd::loadFloats, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadDoubles_, pykd::loadDoubles, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemory_, pykd::compareMemory, 3, 4 );

66 67 68 69 70 71 72 73 74 75 76
BOOST_PYTHON_FUNCTION_OVERLOADS( writeBytes_, pykd::writeBytes, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeWords_, pykd::writeWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeDWords_, pykd::writeDWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeQWords_, pykd::writeQWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeSignBytes_, pykd::writeSignBytes, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeSignWords_, pykd::writeSignWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeSignDWords_, pykd::writeSignDWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeSignQWords_, pykd::writeSignQWords, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeFloats_, pykd::writeFloats, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( writeDoubles_, pykd::writeDoubles, 2, 3 );

77
BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceFile_, pykd::getSourceFile, 0, 1 );
78
BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceFileFromSrcSrv_, pykd::getSourceFileFromSrcSrv, 0, 1 );
79 80
BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, pykd::getSourceLine, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( findSymbol_, pykd::findSymbol, 1, 2 );
81
BOOST_PYTHON_FUNCTION_OVERLOADS( getStack_, pykd::getStack, 0, 1);
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
82

83 84
BOOST_PYTHON_FUNCTION_OVERLOADS( getProcessOffset_, pykd::getProcessOffset, 0, 1);
BOOST_PYTHON_FUNCTION_OVERLOADS( getProcessSystemId_, pykd::getProcessSystemId, 0, 1);
85
BOOST_PYTHON_FUNCTION_OVERLOADS( getProcessExecutableName_, pykd::getProcessExecutableName, 0, 1);
86 87 88 89 90 91 92

BOOST_PYTHON_FUNCTION_OVERLOADS( getThreadOffset_, pykd::getThreadOffset, 0, 1);
BOOST_PYTHON_FUNCTION_OVERLOADS( getThreadSystemId_, pykd::getThreadSystemId, 0, 1);
BOOST_PYTHON_FUNCTION_OVERLOADS( getThreadIdBySystemId_, pykd::getThreadIdBySystemId, 0, 1);

BOOST_PYTHON_FUNCTION_OVERLOADS( createStruct_, pykd::defineStruct, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( createUnion_, pykd::defineUnion, 1, 2 );
93
BOOST_PYTHON_FUNCTION_OVERLOADS( defineFunction_, pykd::defineFunction, 1, 2 );
94

95 96
BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBreakpoint_, Breakpoint::setSoftwareBreakpoint, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBreakpoint_, Breakpoint::setHardwareBreakpoint, 3, 4 );
97

98 99
BOOST_PYTHON_FUNCTION_OVERLOADS( TargetHeap_getEntries, TargetHeapAdapter::getEntries, 1, 4);

100 101
BOOST_PYTHON_FUNCTION_OVERLOADS( Module_enumSymbols, ModuleAdapter::enumSymbols, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( Module_findSymbol, ModuleAdapter::findSymbol, 2, 3 );
102
BOOST_PYTHON_FUNCTION_OVERLOADS( Module_enumTypes, ModuleAdapter::enumTypes, 1, 2 );
103

104 105
BOOST_PYTHON_FUNCTION_OVERLOADS( TypeInfo_ptrTo, TypeInfoAdapter::ptrTo, 1, 2 ); 

106
BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeFromSource_, pykd::getTypeFromSource, 2, 3 );
107 108
BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeInfoProviderFromPdb_, pykd::getTypeInfoProviderFromPdb, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeInfoProviderFromSource_, pykd::getTypeInfoProviderFromSource, 1, 2);
109
BOOST_PYTHON_FUNCTION_OVERLOADS(evalExpr_, pykd::evalExpr, 1, 3);
110

111 112
BOOST_PYTHON_FUNCTION_OVERLOADS( addSyntheticModule_, pykd::addSyntheticModule, 3, 4 );

113 114 115 116
namespace pykd {

void initialize()
{
117
    AutoRestorePyState  pystate;
118 119 120
    kdlib::initialize();
}

121 122 123 124 125 126
void remote_initialize( const std::wstring& remoteOptions )
{ 
    AutoRestorePyState  pystate;
    kdlib::remote_initialize(remoteOptions);
}

127 128
void uninitialize()
{
129
    AutoRestorePyState  pystate;
130 131 132 133 134
    kdlib::uninitialize();
}

}

ussrhero's avatar
ussrhero committed
135
void pykd_init()
136
{
137
    python::scope().attr("__version__") = pykdVersion;
138
    python::scope().attr("version") = pykdVersion;
139

140 141
    python::def( "initialize", pykd::initialize,
        "Initialize local debug engine, only for console mode" );
142
    python::def( "remoteConnect",pykd::remote_initialize,
143 144
        "Initialize debug engine for remoting, only for console mode" );
    python::def( "deinitialize", pykd::uninitialize,
145 146
        "Deintialize debug engine, only for console mode" );

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
147
   // DbgEng services 
148
    python::def( "setSymSrvDir", pykd::setSymSrvDir,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
149
        "Set directory of SYMSRV.dll library.\nUsually this is a directory of WinDbg");
150 151
    python::def( "getExtensionSearchPath", pykd::getExtensionSearchPath,
        "Return the extension DLL search path" );
152
    python::def( "loadExt", pykd::loadExtension,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
153
        "Load a WinDBG extension. Return handle of the loaded extension" );
154 155 156 157
    python::def( "removeExt", (void(*)(kdlib::EXTENSION_ID))&pykd::removeExtension,
        "Unload a WinDBG extension. Parameter: handle returned by loadExt" );
    python::def( "removeExt", (void (*)(const std::wstring& ))&pykd::removeExtension,
        "Unload a WinDBG extension. Parameter: extension path" );
158
    python::def( "callExt", pykd::callExtension,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
159
        "Call a WinDBG extension's routine. Parameters: handle returned by loadExt; string command line" );
160

161 162
   // Manage debug target 

163
    python::def( "startProcess", pykd::startProcess, startProcess_( boost::python::args( "commandline", "debugOptions"), 
164
        "Start process for debugging" ) ); 
ussrhero's avatar
ussrhero committed
165 166
    python::def("attachProcess", pykd::attachProcess, attachProcess_(boost::python::args("pid", "debugOptions"),
        "Attach debugger to a exsisting process"));
167
    python::def( "detachProcess", pykd::detachProcess, detachProcess_( boost::python::args( "id" ),
168
        "Stop process debugging") ); 
169
    python::def( "detachAllProcesses", pykd::detachAllProcesses, 
170
        "Detach from all process and resume all their threads" );
171
    python::def( "killProcess", pykd::terminateProcess, terminateProcess_( boost::python::args( "id" ),
172
        "Stop debugging and terminate current process" ) );
173
    python::def( "killAllProcesses", pykd::terminateAllProcesses,
174
        "Detach from all process then terminate them");
175
    python::def( "loadDump", pykd::loadDump,
176
        "Load crash dump");
177 178
    python::def("closeDump", pykd::closeDump, closeDump_(boost::python::args("id"),
        "Close crash dump"));
179
    python::def( "isLocalKernelDebuggerEnabled", pykd::isLocalKernelDebuggerEnabled,
180
        "Check whether kernel debugging is enabled for the local kernel");
181
    python::def( "attachKernel", pykd::attachKernel, attachKernel_( boost::python::args( "connectOptions" ),
182 183
        "Connect the debugger engine to a kernel target.\n"
        "If connectOptions is not specified - attach to the local kernel") );
184
    python::def( "isDumpAnalyzing", pykd::isDumpAnalyzing,
185
        "Check if it is a dump analyzing ( not living debuggee )" );
186
    python::def( "isKernelDebugging", pykd::isKernelDebugging,
187
        "Check if kernel dubugging is running" );
188
    python::def( "isWindbgExt", pykd::isWindbgExt,
189
        "Check if script works in windbg context" );
190
    python::def( "writeDump", pykd::writeDump,
191
        "Create memory dump file" );
192 193
    python::def( "getLocalProcesses", pykd::getLocalProcesses,
        "Return list of runnng processes on the host system" );
194 195
    python::def("getHostProcessPath", pykd::getHostProcessPath,
        "Return image path of the process running python interpreter with a pykd");
196 197 198 199
    python::def( "getDebugOptions", pykd::getDebugOptions,
        "Return debug options" );
    python::def( "changeDebugOptions", pykd::changeDebugOptions,
        "Change debug options" );
ussrhero's avatar
ussrhero committed
200 201 202 203
    python::def("getOutputMask", pykd::getOutputMask,
        "Get output mask");
    python::def("setOutputMask", pykd::setOutputMask,
        "Set output mask");
204

205
    python::def( "breakin", pykd::targetBreak,
206
        "Break into debugger" );
207
    python::def( "expr", pykd::evaluate, evaluate_( python::args( "expression", "cplusplus" ),
208
        "Evaluate windbg expression" ) );
209 210
    python::def( "dbgCommand", &pykd::debugCommand, 
        debugCommand_( python::args( "command", "suppressOutput"), "Run a debugger's command and return it's result as a string" ) );
211
    python::def( "go", pykd::targetGo,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
212
        "Go debugging"  );
213
    python::def( "step", pykd::targetStep,
214
        "The target is executing a single instruction or--if that instruction is a subroutine call--subroutine" );
215
    python::def( "trace", pykd::targetStepIn,
216
        "The target is executing a single instruction" );
217 218 219 220 221 222
    python::def("stepout", pykd::targetStepOut,
        "The traget is executing while not returned from the current subroutine");
    python::def("sourceStep", pykd::sourceStep,
        "The target is executing a single source line");
    python::def("sourceStepOver", pykd::sourceStepOver,
        "The target is executing a single source line");
223
    python::def( "getExecutionStatus", pykd::targetExecutionStatus,
224
        "Return current execution status" );
225 226

   // Debug output
227
    python::def( "dprint", &pykd::dprint, dprint_( python::args( "str", "dml" ), 
228
        "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
229
    python::def( "dprintln", &pykd::dprintln, dprintln_( python::args( "str", "dml" ), 
230
        "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
231 232
    python::def("dinput", &pykd::dinput,
        "Provide input for debugger");
233 234
    python::def("setStatusMessage", &pykd::setStatusMessage,
        "Set message at a windbg status bar");
235

236 237

    // Python debug output console helper classes
238 239
    python::class_<DbgOut>( "dout", "dout", python::no_init )
        .def( "write", &DbgOut::write )
240
        .def( "writedml", &DbgOut::writedml )
241
        .def( "flush", &DbgOut::flush )
242
        .def( "isatty", &DbgOut::isatty )
243 244
        .add_property( "encoding", &DbgOut::encoding )
        .add_property( "closed", &DbgOut::closed );
245 246 247

    python::class_<DbgIn>( "din", "din", python::no_init )
        .def( "readline", &DbgIn::readline )
248 249
        .add_property( "encoding", &DbgIn::encoding )
        .add_property("closed", &DbgIn::closed );
250

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
251
   // system properties
252
    python::def( "ptrSize", pykd::ptrSize,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
253
        "Return effective pointer size" );
254
    python::def( "is64bitSystem", pykd::is64bitSystem,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
255
       "Check if target system has 64 address space" );
256
    python::def( "pageSize", pykd::getPageSize,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
257
        "Get the page size for the currently executing processor context" );
258
    python::def( "systemUptime", pykd::getSystemUptime,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
259
        "Return the number of seconds the computer has been running" );
260
    python::def( "currentTime", pykd::getCurrentTime,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
261
        "Return the number of seconds since the beginning of 1970" );
262
    python::def("getSystemVersion", pykd::getSystemVersion,
263
        "Return systemVersion");
264 265 266
    python::def( "bugCheckData", pykd::getBugCheckData,
        "Function reads the kernel bug check code and related parameters\n"
        "And return tuple: (code, arg1, arg2, arg3, arg4)" );
267

268
    // Manage target memory access
269
    python::def( "addr64", pykd::addr64,
270
        "Extend address to 64 bits formats" );
271
    python::def( "isValid", pykd::isVaValid,
272
        "Check if the virtual address is valid" );
273 274
    python::def("isVaRegionValid", pykd::isVaRegionValid,
        "Check if the virtaul addresses region is valid");
275
    python::def( "compareMemory", pykd::compareMemory, compareMemory_( python::args( "offset1", "offset2", "length", "phyAddr" ),
276
        "Compare two memory buffers by virtual or physical addresses" ) );
277
    python::def( "searchMemory", pykd::searchMemoryLst, 
278
        "Search in virtual memory" );
279
    python::def( "searchMemory", pykd::searchMemoryStr, 
280
        "Search in virtual memory" );
281 282 283 284
    python::def( "findMemoryRegion", pykd::findMemoryRegion,
        "Return address of begining valid memory region nearest to offset" );
    python::def( "getVaProtect", pykd::getVaProtect,
        "Return memory attributes" );
285

286
    python::def( "ptrByte", pykd::ptrByte,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
287
        "Read an unsigned 1-byte integer from the target memory" );
288
    python::def( "ptrWord", pykd::ptrWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
289
        "Read an unsigned 2-byte integer from the target memory" );
290
    python::def( "ptrDWord", pykd::ptrDWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
291
        "Read an unsigned 4-byte integer from the target memory" );
292
    python::def( "ptrQWord", pykd::ptrQWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
293
        "Read an unsigned 8-byte integer from the target memory" );
294
    python::def( "ptrMWord", pykd::ptrMWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
295
        "Read an unsigned mashine's word wide integer from the target memory" );
296
    python::def( "ptrSignByte", pykd::ptrSignByte,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
297
        "Read an signed 1-byte integer from the target memory" );
298
    python::def( "ptrSignWord", pykd::ptrSignWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
299
        "Read an signed 2-byte integer from the target memory" );
300
    python::def( "ptrSignDWord", pykd::ptrSignDWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
301
        "Read an signed 4-byte integer from the target memory" );
302
    python::def( "ptrSignQWord", pykd::ptrSignQWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
303
        "Read an signed 8-byte integer from the target memory" );
304
    python::def( "ptrSignMWord", pykd::ptrSignMWord,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
305
        "Read an signed mashine's word wide integer from the target memory" );
306
    python::def( "ptrFloat", pykd::ptrSingleFloat,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
307
        "Read a float with single precision from the target memory" );
308
   python::def( "ptrDouble", pykd::ptrDoubleFloat,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
309 310
        "Read a float with single precision from the target memory" );

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    python::def( "setByte", pykd::setByte,
        "Write an unsigned 1-byte integer to the target memory" );
    python::def( "setWord", pykd::setWord,
        "Write an unsigned 2-byte integer to the target memory" );
    python::def( "setDWord", pykd::setDWord,
        "Write an unsigned 4-byte integer to the target memory" );
    python::def( "setQWord", pykd::setQWord,
        "Write an unsigned 8-byte integer to the target memory" );
    python::def( "setSignByte", pykd::setSignByte,
        "Write an signed 1-byte integer to the target memory" );
    python::def( "setSignWord", pykd::setSignWord,
        "Write an signed 2-byte integer to the target memory" );
    python::def( "setSignDWord", pykd::setSignDWord,
        "Write an signed 4-byte integer to the target memory" );
    python::def( "setSignQWord", pykd::setSignQWord,
        "Write an signed 8-byte integer to the target memory" );
    python::def( "setFloat", pykd::setSingleFloat,
        "Write a float with single precision to the target memory" );
   python::def( "setDouble", pykd::setDoubleFloat,
        "Write a float with single precision to the target memory" );

332
    python::def( "loadBytes", pykd::loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
333
        "Read the block of the target's memory and return it as list of unsigned bytes" ) );
334
    python::def( "loadWords", pykd::loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
335
        "Read the block of the target's memory and return it as list of unsigned shorts" ) );
336
    python::def( "loadDWords", pykd::loadDWords, loadDWords_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
337
        "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) );
338
    python::def( "loadQWords", pykd::loadQWords, loadQWords_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
339
        "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) );
340
    python::def( "loadSignBytes", pykd::loadSignBytes, loadSignBytes_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
341
        "Read the block of the target's memory and return it as list of signed bytes" ) );
342
    python::def( "loadSignWords", pykd::loadSignWords, loadSignWords_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
343
        "Read the block of the target's memory and return it as list of signed words" ) );
344
    python::def( "loadSignDWords", pykd::loadSignDWords, loadSignDWords_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
345
        "Read the block of the target's memory and return it as list of signed longs" ) );
346
    python::def( "loadSignQWords", pykd::loadSignQWords, loadSignQWords_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
347
        "Read the block of the target's memory and return it as list of signed long longs" ) );
348
    python::def( "loadChars", pykd::loadChars, loadChars_( python::args( "address", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
349
        "Load string from target memory" ) );
350
    python::def( "loadWChars", pykd::loadWChars, loadWChars_( python::args( "address", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
351
        "Load string from target memory" ) );
352
    python::def( "loadCStr", pykd::loadCStr,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
353
        "Load string from the target buffer containing 0-terminated ansi-string" );
354
    python::def( "loadWStr", pykd::loadWStr,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
355
        "Load string from the target buffer containing 0-terminated unicode-string" );
356
    python::def( "loadUnicodeString", pykd::loadUnicodeStr,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
357
        "Return string represention of windows UNICODE_STRING type" );
358
    python::def( "loadAnsiString", pykd::loadAnsiStr,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
359
        "Return string represention of windows ANSI_STRING type" );
360
    python::def( "loadFloats", pykd::loadFloats, loadFloats_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
361
        "Read the block of the target's memory and return it as list of floats" ) );
362
    python::def( "loadDoubles", pykd::loadDoubles, loadDoubles_( python::args( "offset", "count", "phyAddr" ),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
363
        "Read the block of the target's memory and return it as list of doubles" ) );
364

365
    python::def( "writeBytes", pykd::writeBytes, writeBytes_( python::args( "offset", "values", "phyAddr" ),
366
        "Writing a list of unsigned bytes to the target's memory" ) );
367
    python::def( "writeWords", pykd::writeWords, writeWords_( python::args( "offset", "values", "phyAddr" ),
368
        "Writing a list of unsigned shorts to the target's memory" ) );
369
    python::def( "writeDWords", pykd::writeDWords, writeDWords_( python::args( "offset", "values", "phyAddr" ),
370
        "Writing a list of unsigned long ( double word ) to the target's memory" ) );
371
    python::def( "writeQWords", pykd::writeQWords, writeQWords_( python::args( "offset", "values", "phyAddr" ),
372
        "Writing a list of unsigned long long ( quad word ) to the target's memory" ) );
373
    python::def( "writeSignBytes", pykd::writeSignBytes, writeSignBytes_( python::args( "offset", "values", "phyAddr" ),
374
        "Writing a list of signed bytes to the target's memory" ) );
375
    python::def( "writeSignWords", pykd::writeSignWords, writeSignWords_( python::args( "offset", "count", "phyAddr" ),
376
        "Writing a list of signed words to the target's memory" ) );
377
    python::def( "writeSignDWords", pykd::writeSignDWords, writeSignDWords_( python::args( "offset", "values", "phyAddr" ),
378
        "Writing a list of signed longs to the target's memory" ) );
379
    python::def( "writeSignQWords", pykd::writeSignQWords, writeSignQWords_( python::args( "offset", "values", "phyAddr" ),
380
        "Writing a list of signed long longs to the target's memory" ) );
381
    python::def( "writeFloats", pykd::writeFloats, writeFloats_( python::args( "offset", "values", "phyAddr" ),
382
        "Writing a list of floats to the target's memory" ) );
383
    python::def( "writeDoubles", pykd::writeDoubles, writeDoubles_( python::args( "offset", "values", "phyAddr" ),
384
        "Writing a list of doubles to the target's memory" ) );
385 386 387 388 389
    python::def( "writeCStr", pykd::writeCStr,
        "Write string as a 0 terminated ansi string to the buffer");
    python::def( "writeWStr", pykd::writeWStr,
        "Write string as a 0 terminated unicode string to the buffer");

390

391
    python::def( "ptrPtr", pykd::ptrPtr,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
392
        "Read an pointer value from the target memory" );
393
    python::def( "loadPtrList", pykd::loadPtrList,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
394
        "Return list of pointers, each points to next" );
395
    python::def( "loadPtrs", pykd::loadPtrArray,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
396
        "Read the block of the target's memory and return it as a list of pointers" );
397 398 399

    python::def( "setPtr", pykd::setPtr,
        "Write an pointer value to the target memory" );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
400

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
401
    // types and vaiables
402
    python::def( "getSourceFile", pykd::getSourceFile, getSourceFile_( python::args( "offset"),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
403
        "Return source file by the specified offset" ) );
404 405
    python::def("getSourceFileFromSrcSrv", pykd::getSourceFileFromSrcSrv, getSourceFileFromSrcSrv_(python::args("offset"),
        "Load and return source file from source server by the specified offset") );
406
    python::def( "getSourceLine", pykd::getSourceLine, getSourceLine_( python::args( "offset"),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
407
        "Return source file name, line and displacement by the specified offset" ) );
408

409
    python::def( "getOffset", pykd::getSymbolOffset,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
410
        "Return traget virtual address for specified symbol" );
411
    python::def( "findSymbol", pykd::findSymbol, findSymbol_( python::args( "offset", "showDisplacement"),
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
412
        "Find symbol by the target virtual memory offset" ) );
413
    python::def("findSymbolAndDisp", pykd::findSymbolAndDisp,
414
        "Return tuple (module_name, symbol_name, displacement) by virtual address" );
415
    python::def( "sizeof", pykd::getSymbolSize,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
416
        "Return a size of the type or variable" );
417
    python::def("typedVarList", pykd::getTypedVarListByTypeName,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
418
        "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" );
419
    python::def("typedVarList", pykd::getTypedVarListByType,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
420
        "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" );
421
    python::def("typedVarArray", pykd::getTypedVarArrayByTypeName,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
422
        "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" );
423
    python::def("typedVarArray", pykd::getTypedVarArrayByType,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
424
        "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" );
425
    python::def("containingRecord", pykd::containingRecordByName,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
426 427
        "Return instance of the typedVar class. It's value are loaded from the target memory."
        "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" );
428
    python::def("containingRecord", pykd::containingRecordByType,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
429 430
        "Return instance of the typedVar class. It's value are loaded from the target memory."
        "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" );
431 432
    python::def( "createStruct", &pykd::defineStruct, createStruct_( python::args( "name", "align" ),
        "Create custom struct" ) );
433 434
    python::def( "createUnion", &pykd::defineUnion, createUnion_( python::args( "name", "align" ),
        "Create custom union" ) );
435 436
    python::def( "defineFunction", &pykd::defineFunction, defineFunction_( python::args("returnType", "callconv"),
        "Define custom function prototype" ) );
437 438
    python::def( "callFunctionByPtr", python::raw_function(pykd::callFunctionByVar, 1) );
    python::def( "callFunctionByAddr", python::raw_function(pykd::callFunctionByOffset, 2) );
439
    python::def( "callFunctionRaw", python::raw_function(pykd::callFunctionRaw, 1) );
440

441 442
    python::def( "getTypeFromSource", &pykd::getTypeFromSource, getTypeFromSource_( python::args("sourceCode", "typeName", "compileOptions"),
        "Create typeInfo class from C/C++ source code") );
443 444 445 446
    python::def( "getTypeInfoProviderFromSource", &pykd::getTypeInfoProviderFromSource, getTypeInfoProviderFromSource_( python::args("sourceCode", "compileOptions"),
        "Create typeInfo provider from  C/C++ source code") );
    python::def( "getTypeInfoProviderFromPdb", &pykd::getTypeInfoProviderFromPdb, getTypeInfoProviderFromPdb_( python::args("filePath", "baseOffset"),
        "Create typeInfo provider from  pdb file") );
447 448 449
    python::def("evalExpr", &pykd::evalExpr, evalExpr_(python::args("expression", "scope", "typeProvider"),
        "Evaluate C++ expression with typed information"));

450

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
451
    // CPU registers
452
    python::def( "reg", pykd::getRegisterByName,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
453
        "Return a CPU regsiter value by the register's name" );
454 455
    python::def( "reg", pykd::getRegisterByIndex,
        "Return a CPU register value by the register's number");
456 457 458 459
    python::def( "setReg", pykd::setRegisterByName,
        "Set a CPU register value by its name" );
    python::def( "setReg", pykd::setRegisterByIndex,
        "Set a CPU register value by its index" );
460 461
    python::def( "getNumberRegisters", pykd::getNumberRegisters,
        "Return a number of CPU registers");
462 463
    python::def( "getRegisterName", pykd::getRegisterName,
        "Return register name by its index");
464 465 466 467 468 469
    python::def("getIP", pykd::getIP,
        "Return instruction pointer");
    python::def("getSP", pykd::getSP,
        "Return stack pointer");
    python::def("getFP", pykd::getFP,
        "Return frame pointer");
470 471 472 473 474 475
    python::def("setIP", pykd::setIP,
        "Change instruction pointer");
    python::def("setSP", pykd::setSP,
        "Change stack pointer");
    python::def("setFP", pykd::setFP,
        "Change frame pointer");
476
    python::def ( "rdmsr", pykd::loadMSR,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
477
        "Return MSR value" );
478
    python::def( "wrmsr", pykd::setMSR,
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
479
        "Set MSR value" );
480
    python::def( "getCPUMode", pykd::getProcessorMode, 
SND\EreTIk_cp's avatar
SND\EreTIk_cp committed
481
        "Return current processor mode: CPUType" );
482
    python::def( "getCPUType", pykd::getProcessorType,
SND\EreTIk_cp's avatar
SND\EreTIk_cp committed
483
        "Return type of physical processor: CPUType" );
484
    python::def( "setCPUMode",pykd::setProcessorMode,
SND\EreTIk_cp's avatar
SND\EreTIk_cp committed
485
        "Set current processor mode (CPUType)" );
486
    python::def( "switchCPUMode", pykd::switchProcessorMode,
487
        "Switch processor mode ( X86 <-> X64 )" );
488

489
   // stack and local variables
490 491
    python::def( "getStack", pykd::getStack, getStack_(python::args("inlineFrames"),
        "Return a current stack as a list of stackFrame objects" ) );
492
    python::def( "getFrame", pykd::getCurrentFrame,
493
        "Return a current stack frame" );
494 495
    python::def("getFrameNumber", pykd::getCurrentFrameNumber,
        "Return current frame number");
496 497 498 499 500 501
    python::def( "setFrame", pykd::setCurrentFrame,
        "Change current local scope" );
    python::def( "setFrame", pykd::setCurrentFrameByIndex,
        "Change current local scope" );
    python::def( "resetFrame", pykd::resetCurrentFrame,
        "Resets the current local scope to the default scope of the current thread" );
502 503 504 505
    python::def( "getLocals", pykd::getLocals, 
        "Get list of local variables" );
    python::def( "getLocal", pykd::getLocal,
        "Get the fucntion's local variable by name" );
506 507 508 509
    python::def( "getParams", pykd::getParams, 
        "Get list of function arguments as list of tuple (name, value ) " );
    python::def( "getParam", pykd::getParam, 
        "Get the function argument by name" );
510 511 512 513
    python::def( "stackAlloc", pykd::stackAlloc,
        "Allocate bytes of space in the stack in the target process" );
    python::def( "stackFree", pykd::stackFree,
        "Free space in the stack previously allocated by stackAlloc" );
514 515 516 517
    python::def( "pushStack", pykd::pushStack,
        "Push a value into a stack" );
    python::def( "popStack", pykd::popStack,
        "Pop a value from a stack" );
518

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
519
    // breakpoints
520 521 522 523
    python::def( "setBp", &Breakpoint::setSoftwareBreakpoint,
        setSoftwareBreakpoint_( python::args( "offset", "callback" ),"Set software breakpoint on executiont" )[python::return_value_policy<python::manage_new_object>()]);
    python::def( "setBp", &Breakpoint::setHardwareBreakpoint, 
        setHardwareBreakpoint_( python::args( "offset", "size", "accsessType", "callback" ),"Set hardware breakpoint")[python::return_value_policy<python::manage_new_object>()]);
524
    python::def("getNumberBreakpoints", &Breakpoint::getNumberBreakpoints,
525 526 527
        "Return number of breakpoints in the current process" );
    python::def( "getBp", &Breakpoint::getBreakpointByIndex, python::return_value_policy<python::manage_new_object>(), 
        "Return breakpoint object by index");
528 529
    python::def("removeBp", &Breakpoint::removeBreakpointByIndex,
        "Remove breakpoint by index");
530 531
    python::def("removeAllBp", &Breakpoint::removeAllBreakpoints,
        "Remove all breakpoints");
532

533
    // processes and threads
534
    python::def ( "getNumberProcesses", pykd::getNumberProcesses,
535
        "Return number of processes on the target system" );
536 537 538 539 540 541
    python::def( "getProcessId", pykd::getProcessIdByIndex,
        "Return process ID by index" );
    python::def( "getProcessOffset", pykd::getProcessOffset, getProcessOffset_( python::args( "Id" ), 
        "Return the location in the target's memory of the process structure ( PEB )" ) );
    python::def( "getProcessSystemID", pykd::getProcessSystemId, getProcessSystemId_(  python::args( "Id" ), 
        "Return system process ID ( PID )" ) );
542 543 544 545
    python::def("getProcessExeName", pykd::getProcessExecutableName, getProcessExecutableName_(python::args("Id"),
        "Return name of executable file of the process"));
    python::def( "getProcessIdBySystemID", pykd::getProcessIdBySystemId, 
        "Return process ID by the system's process ID ( PID )" );
546 547
    python::def( "getCurrentProcess", pykd::getCurrentProcess, 
        "Return current offset" );
548 549
    python::def( "getCurrentProcessId", pykd::getCurrentProcessId,
        "Return current process ID" );
550
    python::def( "setCurrentProcess", pykd::setCurrentProcess,
551 552 553
        "Set current process" );
    python::def( "setCurrentProcessId", pykd::setCurrentProcessId,
        "Set current process by debug ID" );
554 555 556 557
    python::def( "getImplicitProcess", pykd::getImplicitProcessOffset,
        "Return implicit process" );
    python::def( "setImplicitProcess", pykd::setImplicitProcess,
        "Set implicit process" );
558 559 560 561
    python::def( "getProcessThreads", pykd::getProcessThreads,
        "Get all process's threads " );
    python::def( "getTargetProcesses", pykd::getTargetProcesses,
        "Get all target processes " );
562

563
    python::def ( "getNumberThreads", pykd::getNumberThreads,
564
        "Return number of threads on the current system" );
565 566 567 568 569 570
    python::def( "getThreadId", pykd::getThreadIdByIndex,
        "Return thread id by index");
    python::def( "getThreadOffset", pykd::getThreadOffset, getThreadOffset_( python::args("Id"),
        "Return the location in the target's memory of the thread structure ( TEB )" ) );
    python::def( "getThreadSystemID", pykd::getThreadSystemId, getThreadSystemId_( python::args("Id"),
        "Return system thread ID ( TID )" ) );
571 572
    python::def( "getThreadIdByOffset", pykd::getThreadIdByOffset,
        "Return thread ID by the location in the targ et's memory of the thread structure" );
573 574
    python::def( "getThreadIdBySystemID", pykd::getThreadIdBySystemId, getThreadIdBySystemId_( python::args("Tid"),
        "Return thread ID by the system's thread ID ( TID )" ) );
575 576
    python::def( "getCurrentThread", pykd::getCurrentThread,
        "Return current thread offset" );
577 578
    python::def( "getCurrentThreadId", pykd::getCurrentThreadId,
        "Return current thread ID" );
579 580
    python::def("setCurrentThread", pykd::setCurrentThread,
        "Set current thread" );
581 582
    python::def("setCurrentThreadId",pykd::setCurrentThreadId,
        "Set current thread by debug ID");
583 584 585 586
    python::def( "getImplicitThread", pykd::getImplicitThreadOffset,
        "Return implicit thread" );
    python::def( "setImplicitThread", pykd::setImplicitThread,
        "Set implicit thread" );
587

588 589 590 591
    // modules
    python::def( "getModulesList", pykd::getModuleList,
        "Return list of modules for the current target" );

592 593 594 595 596 597
    // events
    python::def("getLastEvent", pykd::getLastEvent,
        "Get last debug event information");
    python::def("getLastException", pykd::getLastException,
        "Get last exception  information");

598 599 600 601 602 603 604
    // symbol path
    python::def("getSymbolPath", pykd::getSymbolPath,
        "Returns current symbol path");
    python::def("setSymbolPath", pykd::setSymbolPath, 
        "Set current symbol path");
    python::def("appendSymbolPath", pykd::appendSymbolPath, 
        "Append current symbol path");
605

606 607 608 609 610 611 612
    python::def("getSrcPath", pykd::getSrcPath,
        "Return current source server path");
    python::def("setSrcPath", pykd::setSrcPath,
        "Set source path");
    python::def("appendSrcPath", pykd::appendSrcPath,
        "Append current source path");

613 614 615 616 617 618 619
    // synthetic symbol
    python::def("addSyntheticSymbol", pykd::addSyntheticSymbol,
        "The addSyntheticSymbol function adds a synthetic symbol to a module in the current process\n"
        "Note: reloading the symbols for the module deletes all synthetic symbols associated with that module.");
    python::def( "removeSyntheticSymbol", pykd::removeSyntheticSymbol,
        "The removeSyntheticSymbol function removes a synthetic symbol from a module in the current proces" );

620 621 622 623 624 625
    // synthetic module
    python::def("addSyntheticModule", pykd::addSyntheticModule, addSyntheticModule_(python::args("base", "size", "name", "path"),
        "The addSyntheticModule function adds a synthetic module to the module list the debugger maintains for the current process"));
    python::def("removeSyntheticModule", pykd::removeSyntheticModule,
        "The removeSyntheticModule function removes a synthetic module from the module list the debugger maintains for the current process");

626 627 628 629 630 631
    // secondary callback data
    python::def("enumTagged", pykd::enumTagged,
        "Return the list of secondary callback data IDs (as a strings)" );
    python::def("loadTaggedBuffer", pykd::loadTaggedBuffer,
        "Read the buffer of secondary callback data by ID" );

ussrhero's avatar
ussrhero committed
632 633
    python::class_<kdlib::NumConvertable, boost::noncopyable>( "numVariant", "numVariant", python::no_init )
        //.def("__init__", python::make_constructor(&NumVariantAdaptor::getVariant) )
634 635 636 637 638 639 640 641 642 643 644 645
        .def( "__eq__", &NumVariantAdaptor::eq )
        .def( "__ne__", &NumVariantAdaptor::ne)
        .def( "__lt__", &NumVariantAdaptor::lt)
        .def( "__gt__", &NumVariantAdaptor::gt )
        .def( "__le__", &NumVariantAdaptor::le )
        .def( "__ge__", &NumVariantAdaptor::ge )
        .def( "__add__", &NumVariantAdaptor::add )
        .def( "__radd__", &NumVariantAdaptor::add )
        .def( "__sub__", &NumVariantAdaptor::sub )
        .def( "__rsub__", &NumVariantAdaptor::rsub )
        .def( "__mul__", &NumVariantAdaptor::mul )
        .def( "__rmul__", &NumVariantAdaptor::mul )
646
#if PY_VERSION_HEX < 0x03000000
647 648
        .def( "__div__", &NumVariantAdaptor::div )
        .def( "__rdiv__", &NumVariantAdaptor::rdiv )
649 650 651 652 653 654
#else
        .def("__truediv__", &NumVariantAdaptor::truediv)
        .def("__rtruediv__", &NumVariantAdaptor::rtruediv)
#endif
        .def("__floordiv__", &NumVariantAdaptor::div)
        .def("__rfloordiv__", &NumVariantAdaptor::rdiv)
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
        .def( "__mod__", &NumVariantAdaptor::mod )
        .def( "__rmod__", &NumVariantAdaptor::rmod )
        .def( "__rshift__", &NumVariantAdaptor::rshift )
        .def( "__rrshift__", &NumVariantAdaptor::rrshift )
        .def( "__lshift__", &NumVariantAdaptor::lshift )
        .def( "__rlshift__", &NumVariantAdaptor::rlshift )
        .def( "__and__", &NumVariantAdaptor::and )
        .def( "__rand__", &NumVariantAdaptor::and )
        .def( "__or__", &NumVariantAdaptor::or )
        .def( "__ror__", &NumVariantAdaptor::or )
        .def( "__xor__", &NumVariantAdaptor::xor )
        .def( "__rxor__", &NumVariantAdaptor::xor )
        .def( "__neg__", &NumVariantAdaptor::neg )
        .def( "__pos__", &NumVariantAdaptor::pos ) 
        .def( "__invert__", &NumVariantAdaptor::invert ) 
        .def( "__nonzero__", &NumVariantAdaptor::nonzero )
671 672
        .def( "__str__", &NumVariantAdaptor::str )
        .def( "__hex__", &NumVariantAdaptor::hex )
673 674 675 676
        .def( "__long__", &NumVariantAdaptor::long_ )
        .def( "__int__", &NumVariantAdaptor::int_ )
        .def( "__index__", &NumVariantAdaptor::long_ )
        .def( "__hash__", &NumVariantAdaptor::long_ )
677
        .def( "__float__", &NumVariantAdaptor::float_)
678
        .def( "isInteger", &NumVariantAdaptor::isInteger )
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
679 680
        ;

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
681
        NumVariantAdaptor::registerNumConvertion();
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
682

683 684

    python::class_<kdlib::TargetSystem, kdlib::TargetSystemPtr, boost::noncopyable>("targetSystem", "Class representing target system", python::no_init)
685 686
        .def("__init__", python::make_constructor(&TargetSystemAdapter::getCurrent))
        .def("__init__", python::make_constructor(&TargetSystemAdapter::getSystem))
SND\kernelnet_cp's avatar