Remote Debugging method with GDB under Android

Source: Internet
Author: User
Tags port number

Host:ubuntu

Target:android ICS

1. Place gdbserver and gdbclient into Target and host respectively. Both can be found in the prebuilt directory of the Android source code.

2. Start Gdbserver on target, execute in ADB shell

$/path/to/gdbserver:1111--attach PID

The PID is the process number of the debug program, which can be obtained through PS. 1111 is the port number and can be customized.

3. Start Gdbclient on host, first pull the library on target to host (such as/HOME/JZJ/DEBUG/GDB)

$CD/home/jzj/debug/gdb

$ADB Pull/system/lib

$ADB pull/system/bin/app_process

Then write the startup script Init.gdb (here assumes that the library that the program is using is placed under/home/jzj/debug/gdb/, and that the Android symbol is placed under/home/jzj/debug/ics/symbols/system/lib/, Android source is placed under/home/jzj/workspace/ics)

File/home/jzj/debug/gdb/app_process

Set solib-absolute-prefix/home/jzj/debug/ics/symbols/

Set Solib-search-path/home/jzj/debug/ics/symbols/system/lib/:/home/jzj/debug/gdb

Dir/home/jzj/workspace/ics

Shell adb forward tcp:1111 tcp:1111

Target remote:1111

Final implementation

$ gdb-x Init.gdb

You can start gdb now. When everything is normal, you can use GDB's basic functions, such as setting breakpoints or viewing memory. Some of the symbol tables for so libraries may not be loaded yet, and can be executed

(GDB) shared

Load these symbol tables.

Finally, attach an official explanation of the two variables in the GDB setup script, generally solib-absolute-prefix before the Solib-search-path lookup.

Solib-absolute-prefix:

If This variable is set, path would be used as a prefix to any absolute shared library paths; Many runtime loaders store the absolute paths to the "Shared library in" The target program ' s memory. If you use ' solib-absolute-prefix ' to find shared libraries, they need to be laid out in the same way that they Target, with e.g. a '/usr/lib ' hierarchy under path. You can set the default value of ' Solib-absolute-prefix ' by using the ' configure-time '--with-sysroot ' option.

Solib-search-path:

If This variable was set, path is a colon-separated list of directories to search for shared libraries. ' solib-search- Path ' used after ' Solib-absolute-prefix ' fails to locate the library, or if the path to the library is relative instead of Absolute. If you are want to use ' solib-search-path ' instead of ' solib-absolute-prefix ', being sure to set ' Solib-absolute-prefix ' to a non Existant directory to prevent GDB from finding your host ' s libraries.

Related Article

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.