Solved lldb python scripting

Hi there,

I'm currently experimenting with lldb and wanted to try out its python-API.
So, I followed the tutorial on the lldb website.
However, when trying to import the script into the python interpreter, I'm getting an error message:

Python:
>>> import tree_utils
[string "buffer"]:1: syntax error near 'tree_utils'

This is the complete session:

Bash:
➜  romeo lldb -- ./dictionary romeo-and-juliet.txt
(lldb) target create "./dictionary"
Current executable set to '/usr/home/lukeh/software/playground/lldb/romeo/dictionary' (x86_64).
(lldb) settings set -- target.run-args  "romeo-and-juliet.txt"
(lldb) b find_word
Breakpoint 1: where = dictionary`find_word + 16 at dictionary.c:107:8, address = 0x00000000002021a0
(lldb) r
Process 50573 launching
Process 50573 launched: '/usr/home/lukeh/software/playground/lldb/romeo/dictionary' (x86_64)
Dictionary loaded.
Enter search word: Romeo
Process 50573 stopped
* thread #1, name = 'dictionary', stop reason = breakpoint 1.1
    frame #0: 0x00000000002021a0 dictionary`find_word(dictionary=0x0000000800a2a000, word="romeo") at dictionary.c:107:8
   104     in the binary search tree.  */
   105
   106  int find_word(tree_node *dictionary, char *word) {
-> 107    if (!word || !dictionary)
   108      return 0;
   109
   110    int compare_value = strcmp(word, dictionary->word);
(lldb) script
>>> import tree_utils
[string "buffer"]:1: syntax error near 'tree_utils'

The code can be found within the lldb-examples.

So far I've tried different shells, but that didn't change anything.
The only obvious thing I've noticed, is the lacking python greeting message after entering (lldb)script.
Therefore my only guess is, that the python environment is not loaded correctly.
However, this is a little above my skill level, so I'm not sure where to look next.
Any pointers would be greatly appreciated.

versions:
  • freebsd: 13.0-RELEASE-p7
  • lldb: 11.0.1 (git@github.com:llvm/llvm-project.git revision llvmorg-11.0.1-0-g43ff75f2c3fe)

I'm posting this here because it's working in a linux vm, so I'm thinking that it might be be related to freebsd.
Sorry, if this is not the right place to ask.

Thanks in advance,
lukeh
 

Attachments

  • romeo-and-juliet.txt
    165.3 KB · Views: 94
Code:
[20:44:46] [host!user]/usr/src$grep -r LLDB_ENABLE_PYTHON lib/clang/include/
lib/clang/include/lldb/Host/Config.h:#define LLDB_ENABLE_PYTHON 0
try to build llvm/lldb from ports
 
First, let's look at the Python code you wrote. and then we have to see what values were assigned to them.
LLDB Python
 
Code:
[20:44:46] [host!user]/usr/src$grep -r LLDB_ENABLE_PYTHON lib/clang/include/
lib/clang/include/lldb/Host/Config.h:#define LLDB_ENABLE_PYTHON 0
try to build llvm/lldb from ports
Thanks, that did the trick!

Just to make sure, I understood your code snippet - you searched within the BSD source code and found, that the lldb that comes with the os has python scripting disabled by default. Is that correct?
 
Thanks, that did the trick!

Just to make sure, I understood your code snippet - you searched within the BSD source code and found, that the lldb that comes with the os has python scripting disabled by default. Is that correct?
yes, but first i checked the lldb docs on building, enabling python
 
Back
Top