static PyObject *cdbext_listOfLocals(PyObject *, PyObject *args) // -> [ Value ] { char *partialVariablesC; if (!PyArg_ParseTuple(args, "s", &partialVariablesC)) Py_RETURN_NONE; const std::string partialVariable(partialVariablesC); IDebugSymbolGroup2 *symbolGroup = nullptr; auto locals = PyList_New(0); if (partialVariable.empty()) { symbolGroup = CurrentSymbolGroup::create(); if (symbolGroup == nullptr) return locals; } else { symbolGroup = CurrentSymbolGroup::get(); if (symbolGroup == nullptr) return locals; ULONG scopeEnd; if (FAILED(symbolGroup->GetNumberSymbols(&scopeEnd))) return locals; std::vector<std::string> inameTokens; split(partialVariable, '.', std::back_inserter(inameTokens)); auto currentPartialIname = inameTokens.begin(); ++currentPartialIname; // skip "local" part ULONG symbolGroupIndex = 0; for (;symbolGroupIndex < scopeEnd; ++symbolGroupIndex) { const PyValue value(symbolGroupIndex, symbolGroup); if (value.name() == *currentPartialIname) { PyList_Append(locals, createPythonObject(value)); return locals; } } } ULONG symbolCount; if (FAILED(symbolGroup->GetNumberSymbols(&symbolCount))) return locals; for (ULONG index = 0; index < symbolCount; ++index) { DEBUG_SYMBOL_PARAMETERS params; if (SUCCEEDED(symbolGroup->GetSymbolParameters(index, 1, ¶ms))) { if ((params.Flags & DEBUG_SYMBOL_IS_ARGUMENT) || (params.Flags & DEBUG_SYMBOL_IS_LOCAL)) PyList_Append(locals, createPythonObject(PyValue(index, symbolGroup))); } } return locals; }
PY_FUNC_DECL_WITH_ARGS(childFromIndex, PY_OBJ_NAME) { PY_IMPL_GUARD; unsigned int index; if (!PyArg_ParseTuple(args, "I", &index)) Py_RETURN_NONE; return createPythonObject(self->impl->childFromIndex(index)); }
PY_FUNC_DECL_WITH_ARGS(childFromField, PY_OBJ_NAME) { PY_IMPL_GUARD; FieldPythonObject *field; if (!PyArg_ParseTuple(args, "O", &field)) Py_RETURN_NONE; return createPythonObject(self->impl->childFromField(*(field->impl))); }
PY_FUNC_DECL_WITH_ARGS(childFromName, PY_OBJ_NAME) { PY_IMPL_GUARD; char *name; if (!PyArg_ParseTuple(args, "s", &name)) Py_RETURN_NONE; return createPythonObject(self->impl->childFromName(name)); }
static PyObject *cdbext_lookupType(PyObject *, PyObject *args) // -> Type { char *type; ULONG64 module; if (!PyArg_ParseTuple(args, "sK", &type, &module)) Py_RETURN_NONE; return createPythonObject(PyType::lookupType(type, module)); }
static PyObject *cdbext_createValue(PyObject *, PyObject *args) { ULONG64 address = 0; TypePythonObject *type = 0; if (!PyArg_ParseTuple(args, "KO", &address, &type)) Py_RETURN_NONE; if (!type->impl) Py_RETURN_NONE; return createPythonObject(PyValue::createValue(address, *(type->impl))); }
// cdbext python module static PyObject *cdbext_parseAndEvaluate(PyObject *, PyObject *args) // -> Value { char *expr; if (!PyArg_ParseTuple(args, "s", &expr)) Py_RETURN_NONE; if (debugPyCdbextModule) DebugPrint() << "evaluate expression: " << expr; CIDebugControl *control = ExtensionCommandContext::instance()->control(); ULONG oldExpressionSyntax; control->GetExpressionSyntax(&oldExpressionSyntax); control->SetExpressionSyntax(DEBUG_EXPR_CPLUSPLUS); IDebugSymbolGroup2 *symbolGroup = CurrentSymbolGroup::get(); ULONG index = DEBUG_ANY_ID; HRESULT hr = symbolGroup->AddSymbol(expr, &index); control->SetExpressionSyntax(oldExpressionSyntax); if (FAILED(hr)) Py_RETURN_NONE; return createPythonObject(PyValue(index, symbolGroup)); }
static PyObject *cdbext_call(PyObject *, PyObject *args) { char *function; if (!PyArg_ParseTuple(args, "s", &function)) return NULL; std::wstring woutput; std::string error; if (!ExtensionContext::instance().call(function, 0, &woutput, &error)) { DebugPrint() << "Failed to call function '" << function << "' error: " << error; Py_RETURN_NONE; } CIDebugRegisters *registers = ExtensionCommandContext::instance()->registers(); ULONG retRegIndex; if (FAILED(registers->GetPseudoIndexByName("$callret", &retRegIndex))) Py_RETURN_NONE; ULONG64 module; ULONG typeId; if (FAILED(registers->GetPseudoDescription(retRegIndex, NULL, 0, NULL, &module, &typeId))) Py_RETURN_NONE; DEBUG_VALUE value; if (FAILED(registers->GetPseudoValues(DEBUG_REGSRC_EXPLICIT, 1, NULL, retRegIndex, &value))) Py_RETURN_NONE; ULONG index = DEBUG_ANY_ID; const std::string name = SymbolGroupValue::pointedToSymbolName( value.I64, PyType(module, typeId).name()); if (debugPyCdbextModule) DebugPrint() << "Call ret value expression: " << name; IDebugSymbolGroup2 *symbolGroup = CurrentSymbolGroup::get(); if (FAILED(symbolGroup->AddSymbol(name.c_str(), &index))) Py_RETURN_NONE; return createPythonObject(PyValue(index, symbolGroup)); }