Use Gdbserver to debug C programs in Android

Source: Internet
Author: User

First of all, this article may be flawed, because I do not have the conditions to test the dynamic library debugging. (mainly because it is their own mobile phones do not want to put all kinds of so)

So I can only say that if I have time, I will go to the test, this is the first.

1. Test Code GDB-TEST.C

#include <stdio.h>

int main () {

printf ("This is the GDB test!!! \ n ");

}

2, Android.mk

Local_path: = $ (call My-dir)

Include $ (clear_vars)

Local_cflags: =-G

Local_strip_module: = flase #禁止对最终生成的gdb-test for STRIP processing

Local_moule_tags: = Optional
Local_src_files: = gdb-test.c
Local_module: = Gdb-test
Include $ (build_executable)

3, copy gdb-test gdbserver to device Data directory (here just for simplicity)

4. Enter in the shell

# adb Shell

into the shell in device

# CD Data

#./gdbserver:2000./gdb-test (Note: Gdb-test can be sent here)

The port we used for Gdbserver was 2000.

If you succeed, you will see

# Listening on Port 2000

Description successfully opened the service

5, on the PC to perform

ADB forward tcp:2000 tcp:2000

6, in the running of the GDB on the PC, the specific path is

#arm-linux-androideabi-gdb./gdb-test

Note that the position of the gdb-test here is very important because you can see that there is a gdb-test under Libs, also under OBJ, in order to ensure that the symbol table

Can be successfully loaded, this must be used in the gdb-test under OBJ, because Libs is always generated by removing the symbol table, only the OBJS in the real can be debugged.

After successful entry into GDB, enter

# (GDB) Target remote:2000

Use Gdbserver to debug C programs in Android

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.