Chinaunix首页 | 论坛 | 博客
  • 博客访问: 390172
  • 博文数量: 39
  • 博客积分: 1771
  • 博客等级: 上尉
  • 技术积分: 1231
  • 用 户 组: 普通用户
  • 注册时间: 2005-05-01 14:21
文章分类

全部博文(39)

文章存档

2013年(1)

2012年(4)

2011年(16)

2010年(6)

2009年(12)

分类: LINUX

2010-09-03 15:21:33

NOTE: Commands beginning with red HOST # prompt are executed in host linux, while commands beginning with blue ARM $ prompt are executed in target linux(arm linux).


HOST # cd gdb-6.3/gdb/gdbserver
HOST # CC=arm_v5t_le-gcc ./configure --host=arm-linux
HOST # make
HOST # arm_v5t_le-ldd gdbserver
        libthread_db.so.1 => /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/target/lib/tls/libthread_db.so.1 (0xdead1000)
        libc.so.6 => /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/target/lib/tls/libc.so.6 (0xdead2000)
        /lib/ld-linux.so.3 => /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/target/lib/ld-linux.so.3 (0xdead3000)
HOST # arm_v5t_le-strip gdbserver // make the binary smaller


#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int global = 0;

//void *print_message_function( void *ptr );

void *contend(void *arg)
{
        int i = 0;

        for (; i < 100000; i++) {
                global++;
        }
}


int quit = 0;

main()
{
        pthread_t thread1, thread2;
        char *message1 = "Thread 1";
        char *message2 = "Thread 2";
        int iret1, iret2;

        printf("pid: %d\n", getpid());
        /* Create independent threads each of which will execute function */

        iret1 = pthread_create( &thread1, NULL, contend, (void*) message1);
        iret2 = pthread_create( &thread2, NULL, contend, (void*) message2);

        /* Wait till threads are complete before main continues. Unless we */
        /* wait we run the risk of executing an exit which will terminate */
        /* the process and all threads before the threads have completed. */

        //sleep(18);

        //quit = 1;

        pthread_join( thread1, NULL);
        pthread_join( thread2, NULL);
        printf("global: %d\n", global);

//pause();

// printf("Thread 1 returns: %d\n",iret1);

// printf("Thread 2 returns: %d\n",iret2);

        exit(0);
}

void *print_message_function( void *ptr )
{
        char *message;
        while (!quit) {
                sleep(1);
        }
        message = (char *) ptr;
        printf("Quiting %s \n", message);
}


< compile, don't forget the -g flag>
HOST # arm_v5t_le-gcc -g pthread.c -lpthread -o thread


< execute following command on target os, you can specify any valid port as you wish>
ARM $ ./gdbserver :1234 ./thread

< back to the host>
HOST # arm_v5t_le-gdb thread
(gdb) target remote :1234

From now on you can set breakpoints and debug remote program in host gdb.

The issue now I observed is that after running every instruction, an error "Cannot access memory at address 0x0" is printed. The error message won't prevent the program from running.


阅读(1446) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~