<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">The example code is:<div class=""><br class=""></div><div class=""><pre class=""><tt class=""><font color="green" class="">#!/usr/bin/python</font>
import lldb
import os
def disassemble_instructions(insts):
for i in insts:
print i
<font color="green" class=""># Set the path to the executable to debug</font>
exe = "./a.out"
<font color="green" class=""># Create a new debugger instance</font>
debugger = lldb.SBDebugger.Create()
<font color="green" class=""># When we step or continue, don't return from the function until the process
# stops. Otherwise we would have to handle the process events ourselves which, while doable is
#a little tricky. We do this by setting the async mode to false.</font>
debugger.SetAsync (False)
<font color="green" class=""># Create a target from a file and arch</font>
print "Creating a target for '%s'" % exe
target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT)
if target:
<font color="green" class=""># If the target is valid set a breakpoint at main</font>
main_bp = target.BreakpointCreateByName ("main", target.GetExecutable().GetFilename());
print main_bp
<font color="green" class=""># Launch the process. Since we specified synchronous mode, we won't return
# from this function until we hit the breakpoint at main</font>
process = target.LaunchSimple (None, None, os.getcwd())
<font color="green" class=""># Make sure the launch went ok</font>
if process:
<font color="green" class=""># Print some simple process info</font>
state = process.GetState ()
print process
if state == lldb.eStateStopped:
<font color="green" class=""># Get the first thread</font>
thread = process.GetThreadAtIndex (0)
if thread:
<font color="green" class=""># Print some simple thread info</font>
print thread
<font color="green" class=""># Get the first frame</font>
frame = thread.GetFrameAtIndex (0)
if frame:
<font color="green" class=""># Print some simple frame info</font>
print frame
function = frame.GetFunction()
<font color="green" class=""># See if we have debug info (a function)</font>
if function:
<font color="green" class=""># We do have a function, print some info for the function</font>
print function
<font color="green" class=""># Now get all instructions for this function and print them</font>
insts = function.GetInstructions(target)
disassemble_instructions (insts)
else:
<font color="green" class=""># See if we have a symbol in the symbol table for where we stopped</font>
symbol = frame.GetSymbol();
if symbol:
<font color="green" class=""># We do have a symbol, print some info for the symbol</font>
print symbol</tt></pre><div class=""><br class=""></div><div class="">We set the async mode to false, so target.LaunchSimple() should not return until the process is stopped or exited. Note in your example it is returning with "state = launching", so this is what is failing. For some reason synchronous mode is not being obeyed.</div><div class=""><br class=""></div><div class="">Greg</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Feb 11, 2017, at 10:07 AM, Roman Popov via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I'm testing example from <a href="https://lldb.llvm.org/python-reference.html" class="">https://lldb.llvm.org/python-reference.html</a> (USING THE LLDB.PY MODULE IN PYTHON) on Ubuntu 16.04</div><div class=""><br class=""></div><div class="">For some reason it works only with LLDB 3.9, is it because LLDB 4.0/5.0 are not stable yet?</div><div class=""><br class=""></div><div class=""><pre style="" class="">#5.0 -- Does not work</pre><pre style="" class="">deb <a href="http://apt.llvm.org/xenial/" class="">http://apt.llvm.org/xenial/</a> llvm-toolchain-xenial main</pre><pre style="" class=""># 3.9 -- Works</pre><pre style="" class="">deb <a href="http://apt.llvm.org/xenial/" class="">http://apt.llvm.org/xenial/</a> llvm-toolchain-xenial-3.9 main</pre><pre style="" class=""># 4.0 -- Does not work</pre><pre style="" class="">deb <a href="http://apt.llvm.org/xenial/" class="">http://apt.llvm.org/xenial/</a> llvm-toolchain-xenial-4.0 main</pre><pre style="" class=""><br class=""></pre><pre class=""><font class="">>clang-5.0 -g test.cpp<br class=""></font></pre><pre class=""><font class="">>./python_example.py</font></pre><pre class=""><font class="">Creating a target for './a.out'
SBBreakpoint: id = 1, name = 'main', locations = 1
SBProcess: pid = 0, state = launching, threads = 0, executable = a.out</font></pre></div>Thanks,<div class="">Roman</div></div>
_______________________________________________<br class="">lldb-dev mailing list<br class=""><a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev<br class=""></div></blockquote></div><br class=""></div></body></html>