GDB remote debugging of the android process

Source: Internet
Author: User

What is GDB?

It is a powerful Unix developed by the GNU organization. ProgramDebugging tool, which can be used to debug C and C ++ on Android Code.
It can mainly do four things:

  1. Start your program as you like.
  2. When a breakpoint is set, the program stops running at the breakpoint. (The breakpoint can be an expression)
  3. After the program is stopped, you can view what happens in the program.
  4. Dynamically change the execution environment of the program.

GDB remote debugging schematic

As shown in, we need to use gdbserver to attach to the process we want to debug. GDB uses adbd to communicate with the gdbserver on the mobile phone through socket.

Remote debugging practices

  • Start gdbserver on your mobile phone, attach the process you want to debug, and specify the port for listening to Debugging commands (this port is the port on your mobile phone)
$ ADB shell # ps # view the PID of the process to be debugged # gdbserver: 1234 -- attach 96 #: 1234 is the port number, 96 is the process ID
  • Use ADB for port ing to direct the port on the PC to the port listened by gdbserver on the mobile phone
 
$ ADB forward TCP: 1234 TCP: 1234 # port ing: maps port 1234 of the PC to port 1234 of the mobile phone
  • Start GDB and send messages to the specified PC port to start debugging.
 
Android _ project_root/prebuilt/linux-x86/arm-eabi-4.4.3/$. /ARM-Eabi-GDB # Use the gdb client in the project to connect to gdbserver. The GDB type must be set to the mobile phone platform. The version must be consistent with that of gdbserver.
<GDB> target remote: 1234 # connect to the local port 1234. The port has been mapped to port 1234 of the mobile phone. <GDB> file xxx/out/target/XX... XX/symbols/system/bin/mediaserver # load the executable program. Select the program under symbols. If the debugging process is an app process, select app_process. <GDB> set solib-search-path xxx/out/target/XX... XX/symbols/system/lib # Load all dynamic connection libraries. Select symbols. <GDB> BT # view the call stack <GDB> List xxx/XXX .. xxx/xxx. CPP # view related files <GDB> B 100 # Break a breakpoint in line 100th of the file <GDB> C # continue to execute the program

Use gdbclient to simplify the debugging process

  • go to the source code project directory, configure the environment, and run envsetup In the build folder. SH and choosecombo xx commands, then you can use gdbclient.
  • the ADB shell enters the mobile phone and enables gdbserver as before.
  • in the PC source code root directory, run gdbclient-e mediaserver-P 1234 # debug mediaserver from Port 1234
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.