Debugging Android Java framework services using Eclipse

本文介绍如何使用Eclipse IDE来调试Android平台内部服务,包括创建远程Java应用程序的调试配置,连接Android设备并利用DDMS/Monitor进行代理调试。
Android provides rich SDK and developer environment to build applications targeted for Android devices. An application developer can prototype, test and debug Android SDK applications using Eclipse ADT plugin or Android Studio SDK Debugging page explains various tools and ways of debugging applications. The debugging gets tricky if you are working on Android platform internals. This article explains a way of debugging Android platform services using Eclipse IDE.

Platform Services

Platform services are Android framework services like Activity manager, Window manager, Input manager, WiFi manager etc that run as part of system_process Linux process. 


If you have modified framework classes and like to debug those changes on a live system, the technique described here comes in handy.  If you are working on a fork of Android platform and would like to understand different moving parts in Android framework, you can use this method to step through framework classes.
First you need to create an Eclipse project for Android platform. Please follow the instructions at Using Eclipse to browse/edit AOSP code. You don't need Eclipse ADT plugin for this. The Java project created above is a standard J2SE style java project. What we are going to do is create a debug configuration to debug remote Java applications.

Remote Debug Configuration

Launch Eclipse and open Android platform project created above. 
Select Run->Debug Configurations... menu option. Then select Remote Java Application from the list on left side. 
Then press the icon with + sign from the popup toolbar to create new debug configuration. The port should be changed to 8700, host should be localhost and the project should be Android platform as shown below.

  
Then press Apply to save the configuration.

Debug System_process

Android SDK is needed for remaining steps. If you haven't installed Android SDK, please install it following the instructions at Android SDK installation.

Launch terminal window and add Android sdk tools directory to PATH.
Assuming Android SDK is installed at /opt/android/sdk folder,

$export PATH=/opt/android/sdk/tools: /opt/android/sdk/platform-tools:$PATH

Lets say the IP address of android device is 10.70.77.23. Connect to it using adb.

$adb connect 10.70.77.23

You don't need to do the above step if you are connecting to your device/emulator using USB.
Launch monitor application like below. 

$monitor &

Find the process with name system_process and select it. You should see port 8700 tagged to system_process as shown below.



That means JDWP debugging commands from the Eclipse debugger will be forwarded to the process tagged with port 8700. Minimize monitor application now.
If you are using ADT plugin, you can do the same from DDMS panel. Please keep in mind that you can have either DDMS or monitor running, but not both simultaneously.


Setup Breakpoints and Go!

Lets setup couple of breakpoints in one of platform services. Open WindowManagerService.java fromframeworks/base/services/java->com.android.server.wm package in the Eclipse project.
Navigate to the method finishDrawingWindow and setup a line break point on the first line in this method.
Choose  Run->Debug Configurations... and select Android platform debug configuration created above. PressDebug button. 
Eclipse shows an error popup that there were errors, please click OK to continue. This error is due to the fact that Eclipse failed to build the project which is expected as our project is there merely for editing/browsing and debugging purposes. 
Eclipse debugger should connect to system_process. Eclipse should transition to Java debug perspective. If it didn't, please pick that perspective. It should look like this.


Navigate to different application on your device. That will make system_service hit the breakpoint created above. It should look like this.


You can step through this method using the buttons inside the oval annotation above.
If you disconnect from system_process and then start debugging again, it might fail. Please make suresystem_process is the selected process in DDMS/Monitor window (i.e. so that port 8700 traffic gets delivered to system_process).

Recap

A debug configuration  was created to debug remote Java application at localhost:8700. 
DDMS/Monitor application was used to proxy localhost:8700 traffic to debug agent of selected process on a device.
Standard Java debugging tools that ship with Eclipse JDT were used to connect to localhost:8700 and debug the target process.

This technique can also be used to debug any SDK application on an Android device.

Stay tuned for more debugging tips.



原文地址:http://apienthusiast.blogspot.com/2014/06/debugging-android-java-framework.html

【四旋翼无人机】具备螺旋桨倾斜机构的全驱动四旋翼无人机:建模与控制研究(Matlab代码、Simulink仿真实现)内容概要:本文围绕具备螺旋桨倾斜机构的全驱动四旋翼无人机展开研究,重点探讨其系统建模与控制策略,结合Matlab代码与Simulink仿真实现。文章详细分析了无人机的动力学模型,特别是引入螺旋桨倾斜机构后带来的全驱动特性,使其在姿态与位置控制上具备更强的机动性与自由度。研究涵盖了非线性系统建模、控制器设计(如PID、MPC、非线性控制等)、仿真验证及动态响应分析,旨在提升无人机在复杂环境下的稳定性和控制精度。同时,文中提供的Matlab/Simulink资源便于读者复现实验并进一步优化控制算法。; 适合人群:具备一定控制理论基础和Matlab/Simulink仿真经验的研究生、科研人员及无人机控制系统开发工程师,尤其适合从事飞行器建模与先进控制算法研究的专业人员。; 使用场景及目标:①用于全驱动四旋翼无人机的动力学建模与仿真平台搭建;②研究先进控制算法(如模型预测控制、非线性控制)在无人机系统中的应用;③支持科研论文复现、课程设计或毕业课题开发,推动无人机高机动控制技术的研究进展。; 阅读建议:建议读者结合文档提供的Matlab代码与Simulink模型,逐步实现建模与控制算法,重点关注坐标系定义、力矩分配逻辑及控制闭环的设计细节,同时可通过修改参数和添加扰动来验证系统的鲁棒性与适应性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值