More SWIG cleanup. Moved the breakpoint callback function back to the

ScriptInterpreterPython class and made a simple callback function that
ScriptInterpreterPython::BreakpointCallbackFunction() now calls so we don't
include any internal API stuff into the cpp file that is generated by SWIG.

Fixed a few build warnings in debugserver.

llvm-svn: 115926
This commit is contained in:
Greg Clayton 2010-10-07 17:14:24 +00:00
parent 82d38df40c
commit c6ed542c90
3 changed files with 88 additions and 82 deletions

View File

@ -94,14 +94,6 @@
#include "lldb/API/SBType.h"
#include "lldb/API/SBValue.h"
#include "lldb/API/SBValueList.h"
#include "lldb/Interpreter/ScriptInterpreterPython.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
%}
/* Various liblldb typedefs that SWIG needs to know about. */
@ -151,96 +143,74 @@
%wrapper %{
// This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...)
// and is used when a script command is attached to a breakpoint for execution.
bool
lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction
SWIGEXPORT bool
LLDBSWIGPythonBreakpointCallbackFunction
(
void *baton,
lldb_private::StoppointCallbackContext *context,
lldb::user_id_t break_id,
lldb::user_id_t break_loc_id
const char *python_function_name,
lldb::SBFrame& sb_frame,
lldb::SBBreakpointLocation& sb_bp_loc
)
{
bool ret_value = true;
bool stop_at_breakpoint = true;
PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0);
PyObject *Bp_Loc_PyObj = SWIG_NewPointerObj ((void *) &sb_bp_loc, SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
lldb_private::BreakpointOptions::CommandData *bp_option_data = (lldb_private::BreakpointOptions::CommandData *) baton;
const char *python_function_name = bp_option_data->script_source.GetStringAtIndex (0);
if (Frame_PyObj == NULL || Bp_Loc_PyObj == NULL)
return stop_at_breakpoint;
PyObject *pmodule, *pdict, *pfunc;
PyObject *pargs, *pvalue;
if (python_function_name != NULL
&& python_function_name[0] != '\0')
pmodule = PyImport_AddModule ("__main__");
if (pmodule != NULL)
{
lldb_private::Thread *thread = context->exe_ctx.thread;
lldb_private::Target *target = context->exe_ctx.target;
const lldb::StackFrameSP stop_frame_sp = thread->GetStackFrameSPForStackFramePtr (context->exe_ctx.frame);
lldb::BreakpointSP breakpoint_sp = target->GetBreakpointByID (break_id);
const lldb::BreakpointLocationSP bp_loc_sp = breakpoint_sp->FindLocationByID (break_loc_id);
lldb::SBFrame sb_frame (stop_frame_sp);
lldb::SBBreakpointLocation sb_bp_loc (bp_loc_sp);
if (!sb_bp_loc.IsValid() || !sb_frame.IsValid())
return ret_value;
PyObject *Frame_PyObj = SWIG_NewPointerObj((void *) &sb_frame, SWIGTYPE_p_lldb__SBFrame, 0);
PyObject *Bp_Loc_PyObj = SWIG_NewPointerObj ((void *) &sb_bp_loc, SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
if (Frame_PyObj == NULL
|| Bp_Loc_PyObj == NULL)
return ret_value;
PyObject *pmodule, *pdict, *pfunc;
PyObject *pargs, *pvalue;
pmodule = PyImport_AddModule ("__main__");
if (pmodule != NULL)
pdict = PyModule_GetDict (pmodule);
if (pdict != NULL)
{
pdict = PyModule_GetDict (pmodule);
if (pdict != NULL)
pfunc = PyObject_GetAttrString (pmodule, python_function_name);
if (pfunc && PyCallable_Check (pfunc))
{
pfunc = PyObject_GetAttrString (pmodule, python_function_name);
if (pfunc && PyCallable_Check (pfunc))
pargs = PyTuple_New (2);
if (pargs == NULL)
{
pargs = PyTuple_New (2);
if (pargs == NULL)
{
if (PyErr_Occurred())
PyErr_Clear();
return ret_value;
}
PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj
PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj
pvalue = PyObject_CallObject (pfunc, pargs);
Py_DECREF (pargs);
if (pvalue != NULL)
{
Py_DECREF (pvalue);
}
else if (PyErr_Occurred ())
{
if (PyErr_Occurred())
PyErr_Clear();
}
Py_DECREF (pfunc);
return stop_at_breakpoint;
}
else if (PyErr_Occurred())
PyTuple_SetItem (pargs, 0, Frame_PyObj); // This "steals" a reference to Frame_PyObj
PyTuple_SetItem (pargs, 1, Bp_Loc_PyObj); // This "steals" a reference to Bp_Loc_PyObj
pvalue = PyObject_CallObject (pfunc, pargs);
Py_DECREF (pargs);
if (pvalue != NULL)
{
Py_DECREF (pvalue);
}
else if (PyErr_Occurred ())
{
PyErr_Clear();
}
Py_DECREF (pfunc);
}
else if (PyErr_Occurred())
{
PyErr_Clear();
}
}
else if (PyErr_Occurred ())
else if (PyErr_Occurred())
{
PyErr_Clear ();
PyErr_Clear();
}
}
return ret_value;
else if (PyErr_Occurred ())
{
PyErr_Clear ();
}
return stop_at_breakpoint;
}
%}

View File

@ -22,6 +22,8 @@
#include <string>
#include "lldb/API/SBFrame.h"
#include "lldb/API/SBBreakpointLocation.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
@ -36,11 +38,20 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
// This function is in the C++ output file generated by SWIG after it is
// run on all of the headers in "lldb/API/SB*.h"
extern "C" void init_lldb (void);
extern "C" bool
LLDBSWIGPythonBreakpointCallbackFunction
(
const char *python_function_name,
lldb::SBFrame& sb_frame,
lldb::SBBreakpointLocation& sb_bp_loc
);
using namespace lldb;
using namespace lldb_private;
@ -282,7 +293,7 @@ ScriptInterpreterPython::InputReaderCallback
(
void *baton,
InputReader &reader,
lldb::InputReaderAction notification,
InputReaderAction notification,
const char *bytes,
size_t bytes_len
)
@ -565,7 +576,7 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
(
void *baton,
InputReader &reader,
lldb::InputReaderAction notification,
InputReaderAction notification,
const char *bytes,
size_t bytes_len
)
@ -764,3 +775,34 @@ ScriptInterpreterPython::GenerateBreakpointCommandCallbackData (StringList &user
return true;
}
bool
ScriptInterpreterPython::BreakpointCallbackFunction
(
void *baton,
StoppointCallbackContext *context,
user_id_t break_id,
user_id_t break_loc_id
)
{
BreakpointOptions::CommandData *bp_option_data = (BreakpointOptions::CommandData *) baton;
const char *python_function_name = bp_option_data->script_source.GetStringAtIndex (0);
if (python_function_name != NULL
&& python_function_name[0] != '\0')
{
Thread *thread = context->exe_ctx.thread;
Target *target = context->exe_ctx.target;
const StackFrameSP stop_frame_sp = thread->GetStackFrameSPForStackFramePtr (context->exe_ctx.frame);
BreakpointSP breakpoint_sp = target->GetBreakpointByID (break_id);
const BreakpointLocationSP bp_loc_sp = breakpoint_sp->FindLocationByID (break_loc_id);
SBFrame sb_frame (stop_frame_sp);
SBBreakpointLocation sb_bp_loc (bp_loc_sp);
if (sb_bp_loc.IsValid() || sb_frame.IsValid())
return LLDBSWIGPythonBreakpointCallbackFunction (python_function_name, sb_frame, sb_bp_loc);
}
// We currently always true so we stop in case anything goes wrong when
// trying to call the script function
return true;
}

View File

@ -457,7 +457,6 @@
);
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 113;
FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
STRIP_INSTALLED_PRODUCT = NO;
@ -477,7 +476,6 @@
);
CURRENT_PROJECT_VERSION = 113;
DEAD_CODE_STRIPPING = YES;
FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
STRIPFLAGS = "-x";
@ -498,7 +496,6 @@
);
CURRENT_PROJECT_VERSION = 113;
DEAD_CODE_STRIPPING = YES;
FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
STRIPFLAGS = "-x";
@ -512,7 +509,6 @@
262419A21198A93E00067686 /* BuildAndIntegration */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist";
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 113;
@ -553,7 +549,6 @@
26CE0596115C31C30022F371 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign;
COPY_PHASE_STRIP = YES;
@ -595,7 +590,6 @@
26CE0597115C31C30022F371 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign;
COPY_PHASE_STRIP = YES;