使用VSCODE远程调试Android NDK应用
我已经尝试了多种方法来使其正常工作,但到目前为止无济于事。 我的要求如下:
- 能够使用Visual Studio Code& GDB到在Android设备上运行的启用调试的APK进程
- 该设备不必植根
- 于该设备上的C ++ NDK代码的全面调试。 Java代码也很不错,但是C ++是我感兴趣的。
我知道GDB服务器必须在设备上运行。 NDK(NDK-GDB)中的Python脚本可以将其复制到设备并执行它,然后启动自己的外壳,该外壳可用于设置断点,这在捏中很有用,但远不及完整GUI的直观。
因此,鉴于GDB服务器现在正在设备上运行,我应该能够连接到它。
我正在尝试在VS-Code中使用此“启动”调试配置:
{
"name": "Debug App on Device",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program":"${workspaceRoot}\\android-build\\DebugSys\\system\\bin\\app_process64",
"additionalSOLibSearchPath": "${workspaceRoot}\\android-build\\obj\\local\\arm64-v8a",
"miDebuggerServerAddress": "192.168.1.121:5039",
"setupCommands": [{
"text": "set solib-absolute-prefix ${workspaceRoot}/android-build/",
"ignoreFailures": false
}],
"windows": {
"miDebuggerPath": "C:\\Users\\luthe\\AppData\\Local\\Android\\Sdk\\ndk\\23.1.7779620\\prebuilt\\windows-x86_64\\bin\\gdb.exe",
"MIMode": "gdb"
}
},
但是运行它给了我这个错误:
(由于目标机器主动拒绝了目标机器,因此无法建立连接)。
这可能不是防火墙问题,因为我能够连接到我运行的另一台服务器,该应用程序由端口8080上的应用程序启动。
我的“启动”中是否存在错误这完全以错误的方式。 另外,对于我的应用程序而言,启动GDB服务器是否有意义,或者让NDK-GDB这样做更好/中性?
I've tried a number of ways to get this to work but to no avail so far.
My requirements are as follows:
- To be able to connect using visual studio code & gdb to a debug-enabled APK process running on an android device
- The device should not have to be rooted
- I expect full visual debugging of C++ NDK code on that device. Java code would be nice too but C++ is what I'm interested in.
I'm aware that the gdb server must run on the device. A python script in the NDK (ndk-gdb) can copy this to the device and execute it, which then launches its own shell which can be used to set breakpoints, which is useful in a pinch but nowhere near as intuitive as a full GUI.
So, given that the gdb-server is now running on the device, I should be able to connect to it.
I'm trying to use this 'launch.json' debug config in vs-code:
{
"name": "Debug App on Device",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program":"${workspaceRoot}\\android-build\\DebugSys\\system\\bin\\app_process64",
"additionalSOLibSearchPath": "${workspaceRoot}\\android-build\\obj\\local\\arm64-v8a",
"miDebuggerServerAddress": "192.168.1.121:5039",
"setupCommands": [{
"text": "set solib-absolute-prefix ${workspaceRoot}/android-build/",
"ignoreFailures": false
}],
"windows": {
"miDebuggerPath": "C:\\Users\\luthe\\AppData\\Local\\Android\\Sdk\\ndk\\23.1.7779620\\prebuilt\\windows-x86_64\\bin\\gdb.exe",
"MIMode": "gdb"
}
},
But running it gives me this error:
(No connection could be made because the target machine actively refused it).
This probably isn't a firewall issue as I'm able to connect to another server I have running, launched by the app in question on port 8080.
Is there an error in my 'launch.json' or am I going about all of this in entirely the wrong way.
Also, would it make sense for my app to launch the gdb server instead or is it better/neutral to have ndk-gdb do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在那时,我避开了LLDB,转而使用NDK-Debug可以使用的GDB(目前,即使它有效,他们也会贬值它,而LLDB显然不起作用或不需要某种设置,以至工作)如果在ndk-gdb.py中包括“ no_lldb”标志或将“ use_lldb”设置为“ false”。
但是,如果您想进行视觉调试,则不必让NDK-DBG.PY启动本地GDB客户端。我通过创建一个连接到手机的最小批处理文件来完成此操作,这对于将来阅读的人们可能很有用,以便清楚地概述Android设备和本地计算机上的情况。该脚本假设仅附加了一个设备以清楚。
“ Yourorg.yourapp”是您的组织和应用程序的名称,而1234是要在Android设备上调试的过程的PID。
在Visual Studio代码中,您需要安装C ++扩展名和GDB调试器扩展名。
这是“启动”脚本,可在本地启动GDB并连接到Android设备。请注意,客户端需要符号,但在Android设备上不需要符号,因此可以在需要时剥离。
另外,编译器标志对此很重要!
这些是我用于正在处理的库的调试构建的编译器标志:
其中一些可能不需要手头的任务,我确实使用LLDB进行了很多迭代,但没有任何效果。
对于GDB,我相信它需要-gdwarf -5作为调试格式(我收集的是默认值)。当我指定-GDWARF -4作为实验的一部分时,GDB服务器运行了,但断点无效。
In then end, I eschewed lldb in favour of gdb, which ndk-debug can use (for now, they're depreciating it, even though it works and lldb clearly either does not work or requires some setting that it doesn't advertise to work) if you include the 'no_lldb' flag or set 'use_lldb' to 'False' in ndk-gdb.py.
However, if you want visual debugging, you have to not let ndk-dbg.py launch the local gdb client. I've done this by creating a minimal batch file that connects to the phone and this may be useful for people reading this in the future in order to have a clear overview of what's happening on the android device and on the local machine. This script assumes only one device is attached for clarity.
Where 'yourorg.yourapp' is the name of your org and app and 1234 is the PID of the process to be debugged on your android device.
In visual studio code, you will need to have C++ extensions and gdb debugger extensions installed.
This is the 'launch.json' script that launches gdb locally and connects to the android device. Note that symbols are needed on the client side but not on the android device, so they can stripped if needed.
Also, compiler flags are important for this!
These are the compiler flags I used for the debug build of the library I'm working on:
Some of these may be unnecessary for the task at hand, I did really quite a lot of iteration using lldb but nothing worked.
For gdb, I believe it needs -gdwarf-5 as the debugging format (which I gather is the default). When I specified -gdwarf-4 as part of my experimentations, the gdb server ran but breakpoints did not work.
好的,所以我仍然无法调试,但是现在我至少可以运行调试服务器并连接到它。我的c ++库的符号文件似乎存在问题-cant-find-my-symbols“>在这里
我用来在设备上运行此操作的过程是:
其中'1234'是设备上的过程ID
,而'totga.anththracite'是我的软件包姓名。您需要将“ ARM64-LLDB-Server”复制到指示的数据目录(我会事先运行此步骤),并记住要删除“ debug_socket”文件 - 这是以前弄乱的。
在VSCODE侧,将类似的内容添加到“启动”。
这应该连接,但是,如果像我一样,您没有符号,您仍然无法调试。希望一旦解决该问题,这将起作用,我将能够在Android设备上调试本机C ++代码。
Ok, so I still can't debug but I can now at least run the debug server and connect to it. It seems there's a problem with my symbol file for my C++ .so library which I'm trying to resolve here
The process I've used to run this on the device is this:
where '1234' is the process ID on the device
and 'totga.anthracite' is my package name. You need to copy the 'arm64-lldb-server' to the data directory indicated (I'd run this step beforehand) and also remember to delete the 'debug_socket' file - that was messing things up before.
On the VSCode side, add something like this to 'launch.json'
This should connect but, if like me you have no symbols, you still can't debug. Hopefully once that issue is resolved, this will work and I'll be able to debug native C++ code on an android device.