[lldb-dev] python command returns different values in a script and interactively

Ted Woodward ted.woodward at codeaurora.org
Tue Aug 12 15:58:14 PDT 2014


That fixed it, thanks Jim!

My next problem - I want to set a breakpoint at main and continue. This works, but I don't get the lldb prompt back, and can't do debugging. My code is:

def start (debugger, register, result, dict):
    run (debugger, register, result, dict)
    target = debugger.GetSelectedTarget()
    process = target.GetProcess()
    target.BreakpointCreateByName("main")
    process.Continue()

ctrl-c doesn't break. I have to hit ctrl-z and kill lldb.

Ted

-----Original Message-----
From: jingham at apple.com [mailto:jingham at apple.com] 
Sent: Tuesday, August 12, 2014 5:25 PM
To: Ted Woodward
Cc: lldb-dev at cs.uiuc.edu
Subject: Re: [lldb-dev] python command returns different values in a script and interactively

The lldb.{target,process,thread} globals are only set when running the interactive script interpreter in the lldb "script" command.  They aren't available in other environments like the breakpoint commands, or Python based user defined commands, etc.  They are really just for convenience when prototyping scripts.

In some actual Python code you should have some clear way, depending on the environment, what target you mean.  For instance, if you are writing a Python based lldb command, you might want to operate on the currently selected target (which you can look up in the debugger passed in to you) or you might want to look up a target by name, etc.  In a breakpoint command the relevant target will be the one which owns the process that owns the frame that actually hit the breakpoint, etc...

Jim

> On Aug 12, 2014, at 3:15 PM, Ted Woodward <ted.woodward at codeaurora.org> wrote:
> 
> I’m trying to write a python script that will launch a simulator to run the current target. In my script, I’ve got this code:
>     foo = lldb.target.GetExecutable().__get_fullpath__()
>     print foo
>     print type(foo)
>  
> When I run it, I get this:
> None
> <type 'NoneType'>
>  
> But if I run the same commands interactively, I get the right values:
> (lldb) script foo = lldb.target.GetExecutable().__get_fullpath__()
> (lldb) script print foo
> /usr2/ted/lldb_test/factorial
> (lldb) script print type(foo)
> <type 'str'>
>  
> After calling lldb.target.GetExecutable().__get_fullpath__() interactively, my script starts to work.
>  
> Why doesn’t it work in the script if I don’t call it interactively? How can I get it to work?
>  
> Thanks,
>  
> Ted
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev






More information about the lldb-dev mailing list