xref: /openbsd-src/gnu/llvm/lldb/examples/customization/import-python/README (revision 061da546b983eb767bad15e67af1174fb0bcf31c)
1*061da546SpatrickFiles in this directory:
2*061da546Spatrick
3*061da546Spatricko importcmd.py:
4*061da546Spatrick
5*061da546SpatrickPython module which provides implementation for the 'import' command.
6*061da546Spatrick
7*061da546Spatricko README:
8*061da546Spatrick
9*061da546SpatrickThe file you are reading now.
10*061da546Spatrick
11*061da546Spatrick================================================================================
12*061da546SpatrickThe import command defined by importcmd.py can be used in LLDB to load a Python
13*061da546Spatrickmodule given its full pathname.
14*061da546SpatrickThe command works by extending Python's sys.path lookup to include the path to
15*061da546Spatrickthe module to be imported when required, and then going through the language
16*061da546Spatrickordinary 'import' mechanism. In this respect, modules imported from LLDB command
17*061da546Spatrickline should not be distinguishable from those imported using the script interpreter.
18*061da546SpatrickThe following terminal output shows an interaction with lldb using this new command.
19*061da546Spatrick
20*061da546SpatrickEnrico-Granatas-MacBook-Pro:Debug enricogranata$ ./lldb
21*061da546Spatrick(lldb) script import importcmd
22*061da546Spatrick(lldb) command script add import -f importcmd.pyimport_cmd
23*061da546Spatrick(lldb) import ../demo.py
24*061da546Spatrick(lldb) script demo.test_function('hello world')
25*061da546SpatrickI am a Python function that says hello world
26*061da546Spatrick(lldb) quit
27*061da546SpatrickEnrico-Granatas-MacBook-Pro:Debug enricogranata$
28*061da546Spatrick
29*061da546SpatrickOf course, the commands to import the importcmd.py module and to define the import
30*061da546Spatrickcommand, can be included in the .lldbinit file to make this feature available at
31*061da546Spatrickdebugger startup
32*061da546Spatrick
33*061da546SpatrickWARNING: The import command defined by importcmd.py is now obsolete
34*061da546SpatrickIn TOT LLDB, you can say:
35*061da546Spatrick(lldb) command script import ../demo.py
36*061da546Spatrick(lldb) script demo.test_function('hello world')
37*061da546SpatrickI am a Python function that says hello world
38*061da546Spatrick(lldb) quit
39*061da546Spatrick
40*061da546Spatrickusing the native "command script import" command, which offers a superset of what the import command provided by importcmd.py does
41