Use jdb to debug Android on Mac

0. hypothesis

Suppose you want to debug apk package called:com.github.androider

And the start of the current app

1. obtain the target app's process ID

Run command line:

$ adb shell ps | grep "com.github.androider"

The results (second column is the process ID):

u0_a1423 4877 619 2613496 603872 0 0000000000 S com.github.androider

2. Set up port forwarding

$ adb -d froward tcp:5005 jdwp:4877

Behind this port tcp arbitrarily set, as long as the occupation is not on the line

3. jdb connection

$ jdb -attach localhost:5005

jdb just set connected to port

Note that win on the link command is: jdb -connect com.sun.jdi.SocketAttach: hostname = 127.0.0.1, port = 5005

4. Set a breakpoint

Through the above operation, jdb debugger has been able to process and communicate on the phone. Now set a breakpoint debugging.

用法: stop at :<line_number> 或 stop in .<method_name>[(argument_type,...)]

//用法: 
stop at <class>:<line_number> 或
//
stop in <class>.<method_name>[(argument_type,...)]
复制代码

E.g: stop in com.github.androider.MainActivity.onCreate

Or parameters: stop in com.github.androider.MainActivity.onCreate(android.os.Bundle)

Remove breakpointsclear com.github.androider.MainActivity.onCreate(android.os.Bundle)

5. Debugging

  • skip the next line (across call)

  • step execution of the current line, if you can enter into the

  • step up the implementation of the current method returns to its caller

  • stepi executing the current instruction, entry method

  • cont After a breakpoint exception or steps, will stay at the next breakpoint

  • where to get the call stack before the break,

  • All locals output current local variables in a stack frame

  • print display native Java objects and values. For primitive types of variables or fields, the actual value will be printed; for the object, a simple description will be printed. See the dump command below for more information about the object.

  • For native dump value, the command is identical to print. For an object, it will print the current value of the object in each defined field. Static fields and instance fields are included

  • run [类 [参数]] Master classes begin execution of the application

Few really difficult to use. . .

Reference article: tinylab.org/use-jdb-to-...

Guess you like

Origin blog.csdn.net/weixin_34038293/article/details/91391210