Technology share Android Dynamic Debug program

Source: Internet
Author: User

Write the program, as long as there are ideas, it will not be too difficult to achieve, and we often have to do is to read other people's program, their own program if there is no good comments, after a period of time, but do not know why so write, let alone others write it? In the process of reading other people's programs, it is very important to understand the procedure, the output of the program stack information, to find out the process of the program is extremely helpful.

in Java , by throwing exceptions, such as StartActivity in Android Activitymanagerservice.java , the following results can be obtained from the new Exception ("Print Stack"). Printstacetrace () :

06-15 17:33:55.899 W/system.err (252): Java.lang.Exception:print Trace

06-15 17:33:55.899 W/system.err (252): At Com.android.server.am.ActivityManagerService.startActivity ( activitymanagerservice.java:2493)

06-15 17:33:55.899 W/system.err (252): At Android.app.ActivityManagerNative.onTransact (Activitymanagernative.java : 131)

06-15 17:33:55.899 W/system.err (252): At Com.android.server.am.ActivityManagerService.onTransact ( ACTIVITYMANAGERSERVICE.JAVA:1750)

06-15 17:33:55.899 W/system.err (252): at Android.os.Binder.execTransact (binder.java:338)

06-15 17:33:55.899 W/system.err (252): At Dalvik.system.NativeStart.run (Native Method)

How to make the call process clear, has been thinking, why others can be analyzed, can know where the program went, I think this is a good way to debug Java programs.

for the code in C + + , you can add the following code to the function:

#ifdef _ARM_

LOGW ("Print stack");

Android::callstack Stack;

Stack.update (1, 100);

Stack.dump ("");

#endif

To get the stack information. For example, in InputReader.cpp in the beginning of the dispatchtouches Add the following code, you can see the LOG :

06-15 17:33:16.882 D/inputreader (252): Dump Stack

06-15 17:33:16.882 D/callstack (252): #00 0x0x4c9557ea: <_zn7android16touchinputmapper15dispatchtouche***j>+ 0x0x4c955791

06-15 17:33:16.882 D/callstack (252): #01 0x0x4c95615c: <_zn7android16touchinputmapper4syncex>+0x0x4c955ea5

06-15 17:33:16.882 D/callstack (252): #02 0x0x4c956214: <_zn7android16touchinputmapper7processepkns_8rawevente >+0x0x4c9561e1

06-15 17:33:16.882 D/callstack (252): #03 0x0x4c956226: <_zn7android21multitouchinputmapper7processepkns_ 8rawevente>+0x0x4c956219

06-15 17:33:16.882 D/callstack (252): #04 0x0x4c958758: <_zn7android11inputdevice7processepkns_8raweventej>+ 0x0x4c9586f1

06-15 17:33:16.882 D/callstack (252): #05 0x0x4c9587c0: <_ zn7android11inputreader28processeventsfordevicelockedeipkns_8raweventej>+0x0x4c958779

06-15 17:33:16.882 D/callstack (252): #06 0x0x4c9593ec: <_zn7android11inputreader19processeventslockedepkns_ 8raweventej>+0x0x4c9593b1

06-15 17:33:16.882 D/callstack (252): #07 0X0X4C9595BC: <_zn7android11inputreader8looponceev>+0x0x4c959541

06-15 17:33:16.882 D/callstack (252): #08 0x0x4c94fd0a: <_zn7android17inputreaderthread10threadloopev>+ 0x0x4c94fd01

06-15 17:33:16.883 D/callstack (252): #09 0x0x40151714: <_ZN7ANDROID6THREAD11_THREADLOOPEPV>+0X0X401516A1

06-15 17:33:16.883 D/callstack (252): #10 0x0x401d2de2: <_zn7android14androidruntime15javathreadshellepv>+ 0x0x401d2d9d

06-15 17:33:16.883 D/callstack (252): #11 pc 00023d5a/system/lib/libutils.so

06-15 17:33:16.883 D/callstack (252): #12 0x0x400ee118: <__thread_entry>+0x0x400ee0e4

06-15 17:33:16.883 D/callstack (252): #13 0x0x400edc68: <pthread_create>+0x0x400edbb0

I think if I knew about the JNIof Android , I would like to play the above results can be imagined.

for the kernel stack, you can call Dump_stack ()to make the stack information.

       InAndroid, if you understandAndroidOfJNIGot itLinuxSystem call, knowJavaLayer How toC + +Layer, know the system call, then the entire system call process will understand? Think too naïve, the wholeAndroidSo big, it was so conquered, too boring, but also toss what? The road is still a long way fromAndroidOfC/SArchitecture, it's just a clearCWithSBut the aspect of the really complex, not in this, and in the communication between each other, ifBinderand figured it out, it should be easy to put the wholeAndroidThe system runs through it. May is,Mey not? Who knows, anyway, I haven't.

recently decadent, even the Linux mm have not how to learn, also have not found how to quantify the system method, how do I do performance?

The road long its repair far XI, I will go up and down and quest.

Technology share Android Dynamic Debug program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.