Debug system-level Source Code with GDB in Android

Source: Internet
Author: User

Address: http://blog.csdn.net/ariesjzj/article/details/7375048

HOST: Ubuntu
Target: Android ICs

1. Put gdbserver and GDB 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_processset solib-absolute-prefix /home/jzj/debug/ics/symbols/set solib-search-path /home/jzj/debug/ics/symbols/system/lib/:/home/jzj/debug/gdbdir /home/jzj/workspace/icsshell adb forward tcp:1111 tcp:1111target remote :1111

The path can be automatically generated and executed if you are too lazy to create a method. build/envsetup. sh, there will be a gdbclient command, after the execution will generate gdbclient. you can copy the path to cmds.

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, if the symbol table of some so databases is not loaded, you can execute
(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.

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.