android-native-debug icon indicating copy to clipboard operation
android-native-debug copied to clipboard

Q: 不能调试其它进程么?

Open wbo4958 opened this issue 8 years ago • 13 comments

今晚上试着调试下inputsurfaceflinger

但是怎么都不成功!

猜想: inputsurfaceflinger 运行在system_process, 而博文的是调试一个app进程的 ,垃圾回收机制运行于JVM中,所以能调试??

而如果想调试一些其它的比较 Media/SurfaceFlinger这些module 貌似不行了??

wbo4958 avatar Jun 29 '17 14:06 wbo4958

可以。

说出具体问题

tiann avatar Jun 30 '17 02:06 tiann

赞!

我还是用博主的那个Debug工程,然后

1. 设置了两个断点

(lldb) br s -n dispatchOnceInnerLocked
Breakpoint 2: where = libinputflinger.so`android::InputDispatcher::dispatchOnceInnerLocked(long long*), address = 0xa7f6d724
(lldb) br s -n processEventsLocked
Breakpoint 3: where = libinputflinger.so`android::InputReader::processEventsLocked(android::RawEvent const*, unsigned int), address = 0xa7f76534

2. 加入 libinputflinger.so 并且源码映射, 这些应该都没有问题

3. 查看下断点

(lldb) br list 2
2: name = 'dispatchOnceInnerLocked', locations = 1, resolved = 1, hit count = 0
  2.1: where = libinputflinger.so`android::InputDispatcher::dispatchOnceInnerLocked(long long*) at InputDispatcher.cpp:259, address = 0xa7f6d724, resolved, hit count = 0 

(lldb) br list 3
3: name = 'processEventsLocked', locations = 1, resolved = 1, hit count = 0
  3.1: where = libinputflinger.so`android::InputReader::processEventsLocked(android::RawEvent const*, unsigned int) at InputReader.cpp:379, address = 0xa7f76534, resolved, hit count = 0 

这些也没什么问题。

4. resume program(F8)

这时也没什么问题。。

接着我触摸屏幕想触发断点,点击里面的DEBUG button, 但是程序没有停下下, 更别说看到inputflinger的源码了。

wbo4958 avatar Jun 30 '17 02:06 wbo4958

你调试的哪个进程?

tiann avatar Jun 30 '17 02:06 tiann

直接在Android Studio上调试的,App进程,

wbo4958 avatar Jun 30 '17 03:06 wbo4958

所以这里应该选择 system_process进程? 但是这个怎么选呢?这是个问题!

wbo4958 avatar Jun 30 '17 03:06 wbo4958

那就对了,你明知道inputsurfaceflinger是运行在system_process进程的,却在app进程下断点,咋可能断呢?

仔细看看这篇文章 如何调适Android Framework ,文章重点强调这个了已经。

tiann avatar Jun 30 '17 03:06 tiann

恩, 用 Android Studio 调试 Android java framework是可以的,但是这个貌似不能调试 native的代码吧,比如 inputflinger.

我现在是想调试 native的 framework,比如 inputflinger.

现在我不通过 android studio,直接在通过 "无源码调试" 是可以调试 system_server的.

wbo4958 avatar Jun 30 '17 06:06 wbo4958

可以,选进程的时候选native。

tiann avatar Jun 30 '17 07:06 tiann

image

在attach debugger to android process 后 选择system_process后, 提示如下错误了

6/30/2017
4:28 PM	RuntimeException: Cannot find module by package name

我一般是新建 remote 并选择8700端口, 并在DDMS 里选择调试进程,这样是可以调试 system_process的。

wbo4958 avatar Jun 30 '17 08:06 wbo4958

补充: lldb可以调试system_server native code,如libinputflinger.so了,也能正确显示源码了,非常棒,要是 android studio 也能调试 system_server native code就完美了。

wbo4958 avatar Jul 03 '17 04:07 wbo4958

Android Studio目前有bug:https://issuetracker.google.com/issues/37124749 坐等修复

tiann avatar Jul 06 '17 10:07 tiann

您好,非常感谢!我已经可以调试java层源码了,但是在尝试调试native层时出现错误:RuntimeException: Cannot find module by package name。看您的回复说这是个bug,那请问有什么别的办法可以调试吗?比如我想调试dalivk部分的源码。谢谢!

Youlor avatar Jul 13 '17 14:07 Youlor

@Youlor 看文章和楼上的回复。IDE的bug仅限于你在本App需要调试别的进程的代码,如果是dalvik那么就是运行在你自己进程的,这个是没问题的。调试别的进程,可以直接用LLDB,文中也已经说明了。

tiann avatar Jul 14 '17 04:07 tiann