How to Use gdb for remote debugging in Android

Source: Internet
Author: User

Host: ubuntu

Target: Android ICS

1. Put 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 and execute

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

PID is the process Number of the debug program, which can be obtained through ps. 1111 is the port number, which can be customized.

3. Start gdbclient On the Host. First, pull the library on the target to the host (for example,/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 (assume that the library used by the program is stored in/home/jzj/debug/gdb, put the android symbol UNDER/home/jzj/debug/ics/symbols/system/lib/, and put the android source code 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

Last executed

$ Gdb-x init. gdb

You can start gdb. If everything is normal, you can use the basic functions of gdb, such as setting breakpoints or viewing memory. In this case, the symbol table of some so databases may not be loaded and can be executed.

(Gdb) shared

Load these symbol tables.

An official explanation of the two variables in the gdb setting script is provided. Generally, solib-absolute-prefix is found prior to solib-search-path.

Solib-absolute-prefix:

If this variable is set, path will be used as a prefix for any absolute shared library paths; then 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 are on the 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 is set, path is a colon-separated list of directories to search for shared libraries. 'solib-search-path' is used after 'solib-absolute-prefix' fails to locate the library, or if the path to the library is relative instead of absolute. if you want to use 'solib-search-path' instead of 'solib-absolute-prefix ', be sure to set 'solib-absolute-prefix' to a nonexistant 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.