help for lldb command like gdb info sources & info source

Hi,

Could anyone let me know what is the lldb command

to show all source files like gdb info sources and

the command to show the source file info of the

current $pc location?

Thanks,

Yin

There isn't an equivalent of "info sources" yet.

There is a rough equivalent of "info line" (listed in the gdb->lldb cheat sheet at http://lldb.llvm.org/lldb-gdb.html), which is to do:

(lldb) image lookup -va $pc
     ...
     LineEntry: [0x000000010001a98e-0x000000010001a99f): /Work/Foo.c:11
     ...

It isn't as good as "info line" because it only gives the address range from the given source line that surrounds the address passed to the lookup command. It doesn't answer the question "what are ALL the address ranges that contribute to the implementation of this source line?"

Hope this helps,

Jim

Hi Jim,

Thank you for your help.

I tried image lookup -va $pc on my lldb.
I got
error: invalid address string '$pc'

I am using lldb-179.3, is your version much higher than mine?

Do you know any method that I can retrieve the source file list
from lldb?

Yin

For this old of an LLDB you will need to put back ticks around the $pc:

(lldb) image lookup -va `$pc`

To get the file list, we can turn to python:

sources.py (1.09 KB)

Hi Jim,

Thank you for your help.

I tried image lookup -va $pc on my lldb.
I got
error: invalid address string '$pc'

I am using lldb-179.3, is your version much higher than mine?

Yes. The -a option values were changed to be "address expressions" rather than just straight addresses, certainly in the current LLDB TOT, but also in the lldb from any of the Xcode 5 beta's as well.

Do you know any method that I can retrieve the source file list
from lldb?

If you don't mind writing some Python, you can do something like:

def PrintCompUnitNames (target):
    num_modules = target.GetNumModules()
    for mod_idx in range(num_modules):
  module = lldb.target.GetModuleAtIndex(mod_idx)
  print "Module: ", module
   num_comp_units = module.GetNumCompileUnits()
   for idx in range(num_comp_units):
     print module.GetCompileUnitAtIndex(idx)

That's pretty rough, you probably don't care about printing modules without compile units. This also won't print .h files that get inlined into your code. You can get the "support files" from an SBCompileUnit, which should list all the included files, but that will have lots of duplication so you should maybe put them in a unique list. But something like this should do.

Jim

Ooh, Greg's version is much nicer...

Jim

Hi Greg,

Thank you for sending sources.py. However, I still
Cannot get it work on my Mac machine. I got this error
After I do
(lldb) command script import ~/sources.py
(lldb) info_sources

Traceback (most recent call last):
  File "/Users/yin/sources.py", line 22, in info_sources
    
  File "/Users/yin/sources.py", line 8, in dump_module_sources
    print >> result, "Module: %s" % (module.file)
  File "/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/__init__.py", line 1653, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, SBCommandReturnObject, name)
  File "/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/__init__.py", line 78, in _swig_getattr
    raise AttributeError(name)
AttributeError: write

I upgraded my system from snow leopard to the latest mountain lion.
And I also upgraded lldb to 179.5. I got all same error like this.
Could you help me to figure out how to fix it?

Thanks,

Yin

Hi Yin,

it looks like you have an older version of LLDB
In order to make the “print >>result, …” syntax work, in ToT LLDB, there is a Python method write() implemented on the class SBCommandReturnObject
That function is probably not there in your version of LLDB

If you can, you could download open source ToT and build it yourself. Then, everything should work
Failing that, an alternative is to replace the print >> result, “foo" idiom with either just print “foo” or you could try one of result.PutCString(“foo”) / result.AppendMessage(“foo”) [1]

[1] unfortunately I can’t recall which one(s) was(were) available in LLDB-179, so you might have to give it a try

Enrico Granata
:envelope_with_arrow: egranata@.com
:phone: 27683

The LLDB in Xcode 4.6.3 doesn't have the SBCommandReturnObject output redirection built in..

Change any "print >> result, "

result.AppendMessage(

So the line:

   print >> result, "Module: %s" % (module.file)

Will need to be changed to:

   result.AppendMessage("Module: %s" % (module.file))

Hello,

We are developing our Debugger GUI to support lldb.
Does lldb have an enable mode for GUI mode?
like gdb -fullname, it will emit a string that
indicates source code location instead of printing
source line to stdout?

Thanks,

Yin

cli wrappers suck - Doesn't lldb have an API interface similar to GDB's MI that allows you to control it?

Hi Christopher,

Nice to see you here.

Yes, the python interface from lldb is nice and powerful.
What I am looking for is a reduced output
from lldb to make parsing easier and less overhead
in communication.

Yin

Hi Christopher,

Nice to see you here.

:slight_smile:

Yes, the python interface from lldb is nice and powerful.
What I am looking for is a reduced output
from lldb to make parsing easier and less overhead
in communication.

Oh - it's python.. I thought there was a c++ API - I've never looked at the code and just assuming...

There is no MI interface, but LLDB can be driven from Python and C++:

- Python API Documentation
<http://lldb.llvm.org/python_reference/index.html>
- C++ API Documentation
<http://lldb.llvm.org/cpp_reference/html/index.html>

Also, see the examples in the source tree and in the Python docs.

For getting filenames, use an SBFileSpec object and call GetPath() on it,
or use GetDirectory() and GetFilename(). To see actual source code, use a
SBSourceManager object.

Dan

Not sure if you have already seen this :-

https://github.com/snarez/voltron (A half-arsed UI module for GDB & LLDB).

Thanks

Shankar Easwaran

As everyone has already indicated, you will want to link to the LLDB.framework (on MacOSX), "lldb.so" (linux, unixes), or "lldb.dll" on windows. We export a C++ interface that allows you to run LLDB through full API. Xcode on MacOSX links to LLDB.framework in order to do its debugging so we know the API is complete and works for GUI debuggers.

The C++ API reference is available at:
http://lldb.llvm.org/cpp_reference/html/index.html