how to use adb and gdbserver with VirtualBox - KVM (qemu)
2016-07-25 08:26
671 查看
http://www.android-x86.org/documents/debug-howto
boot up Android iso image on the VirtualBox.
setup ethernet (normally, it will do DHCP by default)
find the IP address of the android VM, by going to the console <Alt-F1> and then typing:netcfg
you can go back to the UI by pressing <Alt-F7>
on you host machine, cd <android source code root directory>/out/host/linux-x86/bin/
./adb kill-server
./adb connect <VirtualBox IP address>:5555, after this command, you should see something like below
./adb logcat to dump the debug log
The steps above work nicely if you have a VM which is set up to use Bridged or Host-Only adapters
However, if you have a NAT'ed VM you cannot connect to the VM IP from the host
You will need to set up port forwarding for a host port to be forwarded to the VM port 5555 (which is adb)
VBoxManage modifyvm <VMName> --natpf1 adb,tcp,*,<localport>,*,5555
Example from one machine:
VBoxManage modifyvm froyo --natpf1 adb,tcp,*,5555,*,5555
Once this is done, you should see the local port (i.e. 5555 in this case) bound on the host via netstat -a
You can now connect to the VM by adb localhost:5555
2a. using adb with KVM (qemu)
Example of running a iso using kvm:
note
to disconnect simply (you'll need to do this after stopping/restarting
Its
set up host-only network as mentioned earlier
in the terminal emulator, run su
in the terminal emulator, run gdbserver <VirtualBox ip address>:1234 [application binary name with the path] or [--attach pid]
on your host machine, run gdb [path of your application binary]
gdb > target remote <VirtualBox ip address>:1234
gdb > set solib-search-path <the path to all the shared library binaries>
gdb > c
to:
1. use adb:
In the VirtualBox network configuration, it is simplest to configure it for Host-Only or Bridged.boot up Android iso image on the VirtualBox.
setup ethernet (normally, it will do DHCP by default)
find the IP address of the android VM, by going to the console <Alt-F1> and then typing:netcfg
you can go back to the UI by pressing <Alt-F7>
on you host machine, cd <android source code root directory>/out/host/linux-x86/bin/
./adb kill-server
./adb connect <VirtualBox IP address>:5555, after this command, you should see something like below
* daemon not running. starting it now *
* daemon started successfully *
connected to <VirtualBox IP address>:5555
./adb logcat to dump the debug log
2. using adb with a NAT'ed VM
However, if you have a NAT'ed VM you cannot connect to the VM IP from the host
You will need to set up port forwarding for a host port to be forwarded to the VM port 5555 (which is adb)
VBoxManage modifyvm <VMName> --natpf1 adb,tcp,*,<localport>,*,5555
Example from one machine:
VBoxManage modifyvm froyo --natpf1 adb,tcp,*,5555,*,5555
Once this is done, you should see the local port (i.e. 5555 in this case) bound on the host via netstat -a
You can now connect to the VM by adb localhost:5555
2a. using adb with KVM (qemu)
If you are using KVM instead of Virtualbox you may find the following useful.
Example of running a iso using kvm:
kvm -soundhw es1370 -net nic -net user,hostfwd=tcp::4444-:5555 -cdrom buildname.iso
note
the networking arguments: this allows "user networking" which doesn't need root access, while still allowing adb connections, by forwarding them on port 4444 of localhost, so to connect you would use:
adb connect localhost:4444
to disconnect simply (you'll need to do this after stopping/restarting
a VM session):
adb disconnect
Its
also possible to pass-through usb devices from the host to android guest running in kvm by adding the parameters:
-usb -usbdevice host:2.*
where in the above example that would pass through all devices on the number 2 usb host bus.
3. how to use gdb with gdbserver:
Android-x86 comes with a preinstalled gdbserver. And you can find it in /sbin/gdbserver. To use gdb to debug your process, you need to:set up host-only network as mentioned earlier
in the terminal emulator, run su
in the terminal emulator, run gdbserver <VirtualBox ip address>:1234 [application binary name with the path] or [--attach pid]
on your host machine, run gdb [path of your application binary]
gdb > target remote <VirtualBox ip address>:1234
gdb > set solib-search-path <the path to all the shared library binaries>
gdb > c
4. Stop zygote to run automatically:
in the vendor/asus/eeepc/init.rc, change following linesservice zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
socket zygote stream 666
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
to:
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
socket zygote stream 666
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
disabled
oneshot
To start zygote manually just do "start zygote" from the command line.
相关文章推荐
- eclipse中的Console控制台视图脱离主窗口解决办法
- [leetcode] 9. Palindrome Number
- 第一个工程3-代码解释二 ,检查球的的静止和一杆的结束
- 三消游戏死局算法的解析
- 制作一个类似苹果VFL的格式化语言来描述UIStackView
- Spring改版后的下载
- C++中类的静态成员
- iOS对textField进行字符长度限制的办法
- PullToRefresh下拉刷新使用详解
- lucene 过滤
- Intellij打包Maven项目中那些七七八八
- 【杭电】[5748]Bellovin
- CodeForces 540A Combination Lock (水题)
- 国产奶粉的“春天”即将到来
- 国产奶粉的“春天”即将到来
- CentOS的KVM实践(虚拟机创建、网桥配置、Spice)
- NSArray类的分析
- C++ 指针
- 上周热点回顾(7.18-7.24)
- 树状数组 改点求段