Usage of GDB on Android

Source: Internet
Author: User
Transferred from: blog.163.com/bjtornado@yeah/blog/static/69510484201081181657449/

1) compilation contains debug information
Set the following environment variables:
Target_build_type = debug
Target_strip_module = false (it is found that even if the compilation mode is set to debug, the programs and libraries in the final file system will still be strip. setting this option can avoid being strip) But you also need to modify build/CORE/Combo/linux-arm.mk, which is not valid even if target_strip_module = false
Modify
113: target_strip_module: = true
Is
Ifeq ($ (Strip $ (target_strip_module )),,)
Target_strip_module: = true
Endif

Then make

2) Start GDB server on the board
GDB-Server IP-Address: Port executable program
Or
GDB-Server IP-Address: port -- attach PID of the program
(Note: IP-address is the IP address of the target board. This option can be omitted)

3) on the host side

(Prerequisite: Go to the android directory and run source build/envsetup. Sh)

# Gdbclient program name executed on the board
(The following information has been set by default, and you do not need to set it yourself.
Set solib-absolute-Prefix/absolute-source-path/out/debug/target/product-name/Symbols
Set solib-search-path/absolute-source-path/out/debug/target/product-name/symbols/system/LIB)
(GDB) target remote board IP-Address: Port

(GDB) B Main
(GDB) c
The program stops at the main function.

Supplement:
If you cannot find GDB-server on the board, you can go to the following address to download the already done: http://ortegaalfredo.googlepages.com/android
I believe many developers would like to know how to use GDB in Android development. Today we will use GDB for debugging in Android emulator, so that you can learn about GDB debugging. There are two ways to debug GDB in the emulator of the Android mobile development platform: Use gdbserver directly or use GDB for debugging.
1. Use GDB server for debugging:
A. Download the gdb server http://www.billrocks.org/android_libs/bin/ for Android from the following link
B. Install the downloaded GDB server to your emulator.
1) Start emulator
2) download the gdb server to your emulator
Open a terminal and run:
$ ADB Shell
# CD Data
# Mkdir Bin
Run in another terminal:
$ ADB push gdbserver/data/bin
In this way, the gdbserver is downloaded to the emulator through the android ADB.
C. Run gdbserver:
#/Data/bin/gdbserver 10.0.2.2: 1234 [ARGs...]
D. Return to another terminal and map the Port:
$ Telnet local host 5554
Telnet to emulator and run the following command:
Redir add TCP: 1234: 1234
E. Run GDB on the third terminal:
$ GDB Test
Test is the program you want to debug, and then run it on the gdb command line:
(GDB) target remote localhost: 1234
Then you can debug the program as you did with GDB.
2. Use local GDB for debugging.
A. Download the android debugging package from the following link. It is a binary file compiled using the android toolchain:
Http://ortegaalfredo.googlepages.com/android-debug.tbz
B. decompress the debugging package and download GDB to your emulator. If you have a real mobile phone, you can debug it as follows:
$ ADB push GDB/data/bin
C. Use ADB to connect to emulator
$ ADB Shell
When running GDB, the following information is displayed:
#/Data/bin/GDB
Dlopen failed on 'libthread _ dB. so.1 '-libthread_db.so.1: cannot open shared object file: no such file or directory
GDB will not be able to debug pthreads.
Gnu gdb 6.7
Copyright (c) 2007 Free Software Foundation, Inc.
License gplv3 +: gnu gpl Version 3 or later This is free software: You are free to change and redistribute it.
There is no warranty, to the extent permitted by law. Type "show copying"
And "show warranty" for details.
This GDB was configured as "-- Host = arm-None-Linux-gnueabi -- target = ".
(GDB)
D. Then you can debug the program as you did with GDB.

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.