Extending LLDB from NDK (Android Studio 3.1.3)

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

I've found a nice plugin for lldb that allows watching memory regions as images: https://github.com/carlodalmutto/ImageWatchLLDB

As I can see, this plugin was developed for Xcode and not for Android. However, it is written in Python and therefore should be cross-platform.

I've found a directory c:\Users\username\.lldb\ on my hard drive. Its size is about 1 Gb.

I've created following files: c:\Users\username\.lldbinit, c:\Users\username\lldbinit, c:\Users\username\.lldb\lldbinit, c:\Users\username\.lldb\.lldbinit, c:\Users\username\.lldb\init

All of them have the similar content:

script print "script print Hi from lldb" echo "echo Hi" 

Unfortunately I don't see any output.

I can open LLDB console and issue these commands:

(lldb) script print "script print Hi from lldb" script print Hi from lldb  (lldb) echo "Hi" error: 'echo' is not a valid command. error: Unrecognized command 'echo'. 

This means that LLDB understands script print command.

Installation directory for Android Studio contains the subdirectory bin\lldb containing python scripts with pretty printers (file jstring_reader.py, gdb\printing.py, etc)

So, it seems possible to extend LLDB from recent NDK.

The question is: how can I add my custom plugins?

UPDATE. After some hacking I've found that LLDB commands, starting with the "script" string, are actually python commands:

(lldb) script print sys.executable C:\Android\sdk\lldb\3.1\bin\LLDBFrontend.exe (lldb) script print sys.version 2.7.10 (default, Feb 24 2016, 14:25:13) [MSC v.1900 64 bit (AMD64)] (lldb) script print sys.path ['C:/Android/sdk/lldb/3.1/bin', 'C:/Android/Android Studio/bin/lldb/shared/jobject_printers', 'C:/Android/sdk/lldb/3.1/lib/site-packages', 'C:\\Android\\sdk\\lldb\\3.1\\bin\\python27.zip', 'C:\\Android\\sdk\\lldb\\3.1\\DLLs', 'C:\\Android\\sdk\\lldb\\3.1\\lib', 'C:\\Android\\sdk\\lldb\\3.1\\lib\\plat-win', 'C:\\Android\\sdk\\lldb\\3.1\\lib\\lib-tk', 'C:\\Android\\sdk\\lldb\\3.1\\bin', 'C:\\Android\\sdk\\lldb\\3.1', 'C:\\Android\\sdk\\lldb\\3.1\\lib\\site-packages', '.', 'C:\\Android\\Android Studio\\bin\\lldb\\shared\\stl_printers', 'C:\\Android\\sdk\\ndk-bundle\\prebuilt\\windows-x86_64\\share\\pretty-printers\\libstdcxx\\gcc-4.9'] (lldb) script import pip Traceback (most recent call last):   File "<input>", line 1, in <module> ImportError: No module named pip 

The first idea of installing missing modules with pip has failed.

I update my question: Are there any official guide on writing python plugins for lldb from NDK?

UPDATE 2. Have tried creating Anaconda virtual environment with the same python version and adding it to sys.path. Also failed.

(lldb) script os.environ['PATH']+= r'C:\Anaconda\envs\ndkpy;' (lldb) script os.environ['PATH']+= r'C:\Anaconda\envs\ndkpy\Library\bin;' (lldb) script import numpy as np Traceback (most recent call last):   File "<input>", line 1, in <module>   File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\__init__.py", line 142, in <module>     from . import add_newdocs   File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\add_newdocs.py", line 13, in <module>     from numpy.lib import add_newdoc   File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\lib\__init__.py", line 8, in <module>     from .type_check import *   File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\lib\type_check.py", line 11, in <module>     import numpy.core.numeric as _nx   File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\core\__init__.py", line 26, in <module>     raise ImportError(msg) ImportError:  Importing the multiarray numpy extension module failed.  Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try `git clean -xdf` (removes all files not under version control).  Otherwise reinstall numpy.  Original error was: DLL load failed: A dynamic link library (DLL) initialization routine failed. 

UPDATE 3. Have found C:\Android\Sdk\lldb\3.1\lib\lib-tk. Tried importing Tkinter, but still no luck:

(lldb) script import Tkinter Traceback (most recent call last):   File "<input>", line 1, in <module>   File "C:\Android\sdk\lldb\3.1\lib\lib-tk\Tkinter.py", line 39, in <module>     import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!