Remove `FindSessionDictionary` and rely on PythonDataObjects.

This had been relegated to a simple forwarding function, so just
delete it in preparation of migrating all of these functions out
of python-wrapper.swig.

llvm-svn: 252803
This commit is contained in:
Zachary Turner 2015-11-11 21:07:29 +00:00
parent 608e436564
commit b8058a5e6e
1 changed files with 140 additions and 190 deletions

View File

@ -26,13 +26,6 @@ private:
bool m_print;
};
static PyObject*
FindSessionDictionary(const char *dict_name)
{
using namespace lldb_private;
return PythonModule::MainModule().ResolveName(dict_name).release();
}
// TODO(zturner): This entire class should be moved to PythonDataObjects.h
// and properly abstracted and unit-tested.
class PyCallable
@ -191,30 +184,27 @@ LLDBSwigPythonBreakpointCallbackFunction
const lldb::BreakpointLocationSP& bp_loc_sp
)
{
using namespace lldb_private;
lldb::SBFrame sb_frame (frame_sp);
lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
bool stop_at_breakpoint = true;
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return stop_at_breakpoint;
if (!pfunc)
return stop_at_breakpoint;
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(sb_frame, sb_bp_loc, session_dict = FindSessionDictionary(session_dictionary_name));
PyObject* pvalue = NULL;
pvalue = pfunc(sb_frame, sb_bp_loc, dict.get());
Py_XINCREF (session_dict);
if (pvalue == Py_False)
stop_at_breakpoint = false;
if (pvalue == Py_False)
stop_at_breakpoint = false;
Py_XDECREF (pvalue);
}
Py_XDECREF (pvalue);
return stop_at_breakpoint;
}
@ -231,30 +221,28 @@ LLDBSwigPythonWatchpointCallbackFunction
const lldb::WatchpointSP& wp_sp
)
{
using namespace lldb_private;
lldb::SBFrame sb_frame (frame_sp);
lldb::SBWatchpoint sb_wp(wp_sp);
bool stop_at_watchpoint = true;
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
if (!pfunc)
return stop_at_watchpoint;
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(sb_frame, sb_wp, session_dict = FindSessionDictionary(session_dictionary_name));
if (!pfunc)
return stop_at_watchpoint;
Py_XINCREF (session_dict);
PyObject* pvalue = NULL;
pvalue = pfunc(sb_frame, sb_wp, dict.get());
if (pvalue == Py_False)
stop_at_watchpoint = false;
if (pvalue == Py_False)
stop_at_watchpoint = false;
Py_XDECREF (pvalue);
}
Py_XDECREF (pvalue);
return stop_at_watchpoint;
}
@ -364,6 +352,7 @@ LLDBSwigPythonCreateSyntheticProvider
const lldb::ValueObjectSP& valobj_sp
)
{
using namespace lldb_private;
PyObject* retval = NULL;
if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@ -378,24 +367,19 @@ LLDBSwigPythonCreateSyntheticProvider
if (ValObj_PyObj == NULL)
Py_RETURN_NONE;
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
Py_INCREF(ValObj_PyObj);
Py_INCREF(ValObj_PyObj);
PyObject* session_dict = NULL;
session_dict = FindSessionDictionary(session_dictionary_name);
retval = pfunc(sb_value, session_dict);
retval = pfunc(sb_value, dict.get());
Py_XINCREF (session_dict);
Py_XINCREF(retval);
}
Py_XINCREF(retval);
if (retval)
return retval;
@ -411,6 +395,7 @@ LLDBSwigPythonCreateCommandObject
const lldb::DebuggerSP debugger_sp
)
{
using namespace lldb_private;
PyObject* retval = NULL;
if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@ -418,22 +403,16 @@ LLDBSwigPythonCreateCommandObject
lldb::SBDebugger debugger_sb(debugger_sp);
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,dict.get());
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,session_dictionary_name);
if (!pfunc)
return retval;
if (!pfunc)
return retval;
retval = pfunc(debugger_sb, dict.get());
PyObject* session_dict = NULL;
session_dict = FindSessionDictionary(session_dictionary_name);
retval = pfunc(debugger_sb, session_dict);
Py_XINCREF (session_dict);
Py_XINCREF(retval);
}
Py_XINCREF(retval);
if (retval)
return retval;
@ -449,6 +428,7 @@ LLDBSwigPythonCreateScriptedThreadPlan
const lldb::ThreadPlanSP& thread_plan_sp
)
{
using namespace lldb_private;
PyObject* retval = NULL;
if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@ -463,27 +443,22 @@ LLDBSwigPythonCreateScriptedThreadPlan
if (ThreadPlan_PyObj == NULL)
Py_RETURN_NONE;
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name, session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name, dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
Py_INCREF(ThreadPlan_PyObj);
Py_INCREF(ThreadPlan_PyObj);
PyObject* session_dict = NULL;
session_dict = FindSessionDictionary(session_dictionary_name);
retval = pfunc(tp_value, session_dict);
retval = pfunc(tp_value, dict.get());
// FIXME: At this point we should check that the class we found supports all the methods
// that we need.
// FIXME: At this point we should check that the class we found supports all the methods
// that we need.
Py_XINCREF (session_dict);
Py_XINCREF(retval);
}
Py_XINCREF(retval);
if (retval)
return retval;
@ -831,7 +806,7 @@ LLDBSwigPythonCallCommand
lldb::ExecutionContextRefSP exe_ctx_ref_sp
)
{
using namespace lldb_private;
lldb::SBCommandReturnObject cmd_retobj_sb(&cmd_retobj);
SBCommandReturnObjectReleaser cmd_retobj_sb_releaser(cmd_retobj_sb);
lldb::SBDebugger debugger_sb(debugger);
@ -839,29 +814,26 @@ LLDBSwigPythonCallCommand
bool retval = false;
{
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PyErr_Cleaner py_err_cleaner(true);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
PyObject* session_dict = NULL;
// pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
// see comment above for SBCommandReturnObjectReleaser for further details
PyObject* pvalue = NULL;
// pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
// see comment above for SBCommandReturnObjectReleaser for further details
PyObject* pvalue = NULL;
PyCallable::argc argc = pfunc.GetNumArguments();
if (argc.num_args == 5 || argc.varargs == true)
pvalue = pfunc(debugger_sb, args, exe_ctx_sb, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
else
pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
PyCallable::argc argc = pfunc.GetNumArguments();
if (argc.num_args == 5 || argc.varargs == true)
pvalue = pfunc(debugger_sb, args, exe_ctx_sb, &cmd_retobj_sb, dict.get());
else
pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, dict.get());
Py_XINCREF (session_dict);
Py_XDECREF (pvalue);
Py_XDECREF (pvalue);
retval = true;
}
retval = true;
return retval;
}
@ -908,6 +880,7 @@ LLDBSWIGPythonCreateOSPlugin
const lldb::ProcessSP& process_sp
)
{
using namespace lldb_private;
PyObject* retval = NULL;
if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@ -922,24 +895,19 @@ LLDBSWIGPythonCreateOSPlugin
if (SBProc_PyObj == NULL)
Py_RETURN_NONE;
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
Py_INCREF(SBProc_PyObj);
Py_INCREF(SBProc_PyObj);
PyObject* session_dict = NULL;
session_dict = session_dict = FindSessionDictionary(session_dictionary_name);
retval = pfunc(SBProc_PyObj);
retval = pfunc(SBProc_PyObj);
Py_XINCREF (session_dict);
Py_XINCREF(retval);
}
Py_XINCREF(retval);
if (retval)
return retval;
@ -979,6 +947,7 @@ lldb::ProcessSP& process,
std::string& output)
{
using namespace lldb_private;
bool retval = false;
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@ -986,25 +955,21 @@ std::string& output)
lldb::SBProcess process_sb(process);
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(process_sb, session_dict = FindSessionDictionary(session_dictionary_name));
PyObject* pvalue = NULL;
pvalue = pfunc(process_sb, dict.get());
Py_XINCREF (session_dict);
if (PyObjectToString(pvalue,output))
retval = true;
if (PyObjectToString(pvalue,output))
retval = true;
Py_XDECREF(pvalue);
}
Py_XDECREF(pvalue);
return retval;
}
@ -1017,6 +982,7 @@ lldb::ThreadSP& thread,
std::string& output)
{
using namespace lldb_private;
bool retval = false;
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@ -1024,25 +990,21 @@ std::string& output)
lldb::SBThread thread_sb(thread);
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(thread_sb, session_dict = FindSessionDictionary(session_dictionary_name));
PyObject* pvalue = NULL;
pvalue = pfunc(thread_sb, dict.get());
Py_XINCREF (session_dict);
if (PyObjectToString(pvalue,output))
retval = true;
if (PyObjectToString(pvalue,output))
retval = true;
Py_XDECREF(pvalue);
}
Py_XDECREF(pvalue);
return retval;
}
@ -1055,6 +1017,7 @@ lldb::TargetSP& target,
std::string& output)
{
using namespace lldb_private;
bool retval = false;
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@ -1062,25 +1025,21 @@ std::string& output)
lldb::SBTarget target_sb(target);
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(target_sb, session_dict = FindSessionDictionary(session_dictionary_name));
PyObject* pvalue = NULL;
pvalue = pfunc(target_sb, dict.get());
Py_XINCREF (session_dict);
if (PyObjectToString(pvalue,output))
retval = true;
if (PyObjectToString(pvalue,output))
retval = true;
Py_XDECREF(pvalue);
}
Py_XDECREF(pvalue);
return retval;
}
@ -1093,6 +1052,7 @@ lldb::StackFrameSP& frame,
std::string& output)
{
using namespace lldb_private;
bool retval = false;
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@ -1100,25 +1060,21 @@ std::string& output)
lldb::SBFrame frame_sb(frame);
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(frame_sb, session_dict = FindSessionDictionary(session_dictionary_name));
PyObject* pvalue = NULL;
pvalue = pfunc(frame_sb, dict.get());
Py_XINCREF (session_dict);
if (PyObjectToString(pvalue,output))
retval = true;
if (PyObjectToString(pvalue,output))
retval = true;
Py_XDECREF(pvalue);
}
Py_XDECREF(pvalue);
return retval;
}
@ -1131,6 +1087,7 @@ lldb::ValueObjectSP& value,
std::string& output)
{
using namespace lldb_private;
bool retval = false;
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@ -1138,25 +1095,21 @@ std::string& output)
lldb::SBValue value_sb(value);
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return retval;
if (!pfunc)
return retval;
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(value_sb, session_dict = FindSessionDictionary(session_dictionary_name));
PyObject* pvalue = NULL;
pvalue = pfunc(value_sb, dict.get());
Py_XINCREF (session_dict);
if (PyObjectToString(pvalue,output))
retval = true;
if (PyObjectToString(pvalue,output))
retval = true;
Py_XDECREF(pvalue);
}
Py_XDECREF(pvalue);
return retval;
}
@ -1169,6 +1122,7 @@ LLDBSwigPythonCallModuleInit
lldb::DebuggerSP& debugger
)
{
using namespace lldb_private;
bool retval = false;
lldb::SBDebugger debugger_sb(debugger);
@ -1177,24 +1131,20 @@ LLDBSwigPythonCallModuleInit
python_function_name_string += ".__lldb_init_module";
const char* python_function_name = python_function_name_string.c_str();
{
PyErr_Cleaner py_err_cleaner(true);
PyErr_Cleaner py_err_cleaner(true);
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
if (!pfunc)
return true;
if (!pfunc)
return true;
PyObject* session_dict = NULL;
PyObject* pvalue = NULL;
pvalue = pfunc(debugger_sb, session_dict = FindSessionDictionary(session_dictionary_name));
PyObject* pvalue = NULL;
pvalue = pfunc(debugger_sb, dict.get());
Py_XINCREF (session_dict);
retval = true;
retval = true;
Py_XDECREF(pvalue);
}
Py_XDECREF(pvalue);
return retval;
}