Issue with Launch API

Hi,

I’m using the SBTarget.Launch() API in Python:

process = target.Launch(self.dbg.GetListener(), [‘a’,‘b’], env, stdin, 'stdour.txt, ‘stderr.txt’, os.getcwd(), 0 , True, err)

I got the following error:


File “/home/media/llvm/lib/python2.7/site-packages/lldb/init.py”, line 7973, in Launch
return _lldb.SBTarget_Launch(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function ‘SBTarget_Launch’.
Possible C/C++ prototypes are:
lldb::SBTarget::Launch(lldb::SBListener &,char const **,char const **,char const *,char const *,char const *,char const *,uint32_t,bool,lldb::SBError &)
lldb::SBTarget::Launch(lldb::SBLaunchInfo &,lldb::SBError &)

If I replace the string list [‘a’,‘b’] with None, it works.

I find that all the tests and samples uses None.

It looks the problem stems from overloaded Launch in SBTarget.i.

In LLDBWrapPython.cpp:

_wrap_SBTarget_Launch__SWIG_0 () { …} // wrapper for Launch(lldb::SBListener &…)

_wrap_SBTarget_Launch__SWIG_1 () { …} // wrapper for Launch (lldb::SBLaunchInfo &…);

SWIGINTERN PyObject *_wrap_SBTarget_Launch(PyObject *self, PyObject *args) {


if (argc == 3) {

}
if (argc == 11) {
int _v;
void *vptr = 0;
int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_lldb__SBTarget, 0);
_v = SWIG_CheckState(res);
if (_v) {
void vptr = 0;
int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_lldb__SBListener, 0);
_v = SWIG_CheckState(res);
if (_v) {
void vptr = 0;
int res = SWIG_ConvertPtr(argv[2], &vptr, SWIGTYPE_p_p_char, 0); // ===================== Fails here. unable to cast to char

_v = SWIG_CheckState(res);
if (_v) {

if (_v) {
return _wrap_SBTarget_Launch__SWIG_0(self, args); ================> real check here

}

fail:
SWIG_SetErrorMsg(PyExc_NotImplementedError,“Wrong number or type of arguments for overloaded function ‘SBTarget_Launch’.\n”
" Possible C/C++ prototypes are:\n"
" lldb::SBTarget::Launch(lldb::SBListener &,char const **,char const **,char const *,char const *,char const *,char const *,uint32_t,bool,lldb::SBError &)\n"
" lldb::SBTarget::Launch(lldb::SBLaunchInfo &,lldb::SBError &)\n");
return 0;

It seems to me the swig code does some unnecessary check before it goes into the real wrapper.
Any inputs?

Thanks,
Zephyr

Hi Zephyr

I too have seen similar issue with this API.

I noticed that the file scripts/Python/python-swigsafecast.swig has no
entry for SBListener, and wondered if this was relevant.

Matt

No I don't really know swig, either.

If you don't have commit access then I could try to test out your patch
some more and then commit it.

Matt

What is your type for 'env' below?

process = target.Launch(self.dbg.GetListener(), ['a','b'], env, stdin, 'stdout.txt, 'stderr.txt', os.getcwd(), 0 , True, err)

It must be a list like ['FOO=BAR', 'STUFF=COOL']:

process = target.Launch(self.dbg.GetListener(), ['a','b'], ['FOO=BAR', 'STUFF=COOL'], stdin, 'stdout.txt', 'stderr.txt', os.getcwd(), 0 , True, err)

Also how did you create "err"? You should create it first like this:

err = lldb.SBError()
env = ['FOO=BAR', 'STUFF=COOL']
process = target.Launch(self.dbg.GetListener(), ['a','b'], env, stdin, 'stdout.txt', 'stderr.txt', os.getcwd(), 0 , True, err)

'stdin' must be a string, and you probably want to make a full path to stdin and stdout.txt and stderr.txt just to be safe.

I think Enrico’s patch r220306 fixes it

Thanks!

I think Patch r220306 fixes it

Thanks!