顯示具有 gdb 標籤的文章。 顯示所有文章
顯示具有 gdb 標籤的文章。 顯示所有文章

2015年6月24日 星期三

[GDB] How to use gdbserver

  1. Upload gdbserver to Embedded Board
  2. Create a c file
  3. #include <stdio.h>
    //This function will cause "Segmentation fault"
    void memory_violation()
    {
        char* ptr = 0;
        for(int i=0; i<10; ++i)
        {
            ptr[i] = i;
        }
    }
    
    int main(int argc, char* argv[])
    {
        memory_violation();
        return 0;
    }


    compile it.
    -ggdb create symbol.
    armeb-unknown-linux-uclibcgnueabi-gcc -ggdb -std=gnu99 -o hello hello.c


  4. Upload program && Execute the gdbserver

  5. ./gdbserver “embedded ip”:”embedded port” “program”
    ./gdbserver 111.6.1.191:12345 ./hello


  6. On the Local Machine

  7. ./armeb-linux-gdb ./hello
    When see (gdb), the type
    target extended-remote 111.6.1.191:12345
    Type run will see result appear on Embedded board
PS. Still can use ddd, but no working.
ddd –debugger /tmp/happy1/bin/armeb-linux-gdb /tmp/test2/hello –eval-command=”target extended-remote 111.6.1.191:12345”
Reference:

2013年6月1日 星期六

[DDD] How debug by using DDD tool


[DDD] How debug by using DDD tool

1. Install DDD tool in the ubuntu 10.04

sudo apt-get install DDD

2.  Create a hello.c

Compile hello.c by using armeb-unknown-linux-uclibcgnueabi-gcc.

armeb-unknown-linux-uclibcgnueabi-gcc -g hello.c -o hello



Put hello to Embedded System.

Type gdbserver 192.168.x.x:12345 happy on the Embedded System.



3. Using DDD tool to debug

DDD  happy

target remote 192.168.x.x:12345



Pre Cont

(gdb) cont

Breakpoint 1, memory_violation () at happy.c:10

 





  %%%%%%%%%%%%%%%%%%%%%%%%%



The content of happy.c

#include <stdio.h>

//This function will cause "Segmentation fault"
void memory_violation()
{
char* ptr = 0;
for(int i=0; i<10; ++i)
{
ptr[i] = i;
}
}

int main(int argc, char* argv[])
{
memory_violation();
return 0;
}


%%%%%%%%%%%%%%%%%%%%%%%%%

Reference :



2013年5月31日 星期五

[GDB] How to build GDB tool into Embedded System

Compile GDB tool for host pc.
Download GDBServer Package
Just download this package, then make it will compile until to finish.

Let GDB support the architecture of ARM.
--enable-tui --> Let the GDB have GUI debug interface after compile.

./configure --target=armeb-unknown-linux-uclibcgnueabi \
--prefix=/home/happy/armgdb \
--exec-prefix=/home/happy/armgdb \
--enable-tui

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Q:
eval.c:1705: error: 'subscript_array' may be used uninitialized in this
function

A:
At eval.c find the below code.
if (nargs != ndimensions)
error (_("Wrong number of subscripts"));

ADD
memset(&subscript_array, 0, sizeof(subscript_array));//new line

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Compile gdbserver for Embedded System.
cd gdb/gdbserver/

#! /bin/sh
export CPPFLAGS=""
export LDFLAGS=""
export CFLAGS=""
export AR=armeb-unknown-linux-uclibcgnueabi-ar
export AS=armeb-unknown-linux-uclibcgnueabi-as
export LD=armeb-unknown-linux-uclibcgnueabi-ld
export RANLIB=armeb-unknown-linux-uclibcgnueabi-ranlib
export CC=armeb-unknown-linux-uclibcgnueabi-gcc
export NM=armeb-unknown-linux-uclibcgnueabi-nm
export ARCH=arm

./configure --target=armeb-unknown-linux-uclibcgnueabi \
--host=armeb-unknown-linux-uclibcgnueabi \
--prefix=/home/happy/armgdb \
--exec-prefix=/home/happy/armgdb

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
After compile gdb package, upload gdbserver to embedded system.
Create a hello.c.
Compile hello.c by using armeb-unknown-linux-uclibcgnueabi-gcc.
Put hello to Embedded System.
Type gdbserver 192.168.x.x:12345 happy on the Embedded System.
Or
Type gdbserver 222.222.222.222:12345 happy on the Embedded System.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
After compile gdb package, execute armeb-linux-gdb on the host PC.
On host pc
go to gdb --> Type gdbtui -q hello --> type target remote 192.168.x.x:12345 (connect to remote host)
Or
./armeb-linux-gdb
Under (gdb) shell, type "target remote 222.222.222.222:12345" will connect to embedded system.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Reference:

2013年1月19日 星期六

[C][gdb][ddd] Split word into two segment. Using ddd to see the variable change


[C][gdb][ddd] Split word into two segment. Using ddd to see the variable change



#include <unistd.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>



#define PATH "./test.txt"

#define BUFF_LEN 4096



int cut(char* src, char* dst1, char* dst2, char* s1)

{

    char *pch;

    int len;

    char tmp[BUFF_LEN]={0};

    

    pch=strstr(src, s1);

    if(!pch) return 0;

    len=pch-src;

    

    strncpy(tmp, src, len);

    strcpy(dst1, tmp);

    

    strncpy(tmp, src+len+1, strlen(src)-len);

    strcpy(dst2, tmp);

    

    return 1;

}





int main(void)

{

    char s1[BUFF_LEN]={0};

    char s2[BUFF_LEN]={0};



    FILE *fp;

    char *line = NULL;

    size_t len = 0;

    ssize_t read;

    fp = fopen("./test.txt", "r");

    if (fp == NULL)

        exit(1);

    while ((read = getline(&line, &len, fp)) != -1) {

        if(strcmp(line, "\n") == 0 )

            break;         

        if(!cut(line, s1, s2, ","))

        {



            printf("ERROR: can not cut =\n");

            break;

        }

        printf("s1=%s  s2=%s", s1,s2);

    }

    if (ferror(fp)) {

        /* handle error */

    }

    free(line);

    fclose(fp);

    return 0;

}



test.txt



one,two

three,four

five,six

 



Result :



s1=one  s2=two

s1=three  s2=four

s1=five  s2=six

 



[gdb][Core Dump] Keep the error state when exe file be executed


[gdb][Core Dump] Keep the error state when exe file be executed



1. Check Core Dump Status

ulimit -c

if show 0 mean no open this function



Open it by using

ulimit -c unlimited



2. Create a C file (name test.c)



#include <stdio.h>



int main(void)

{

    int *b=NULL;

    *b = 0x22;

    return 0;

}





3. gcc -g test.c



4. Execute ./a.out

Then produce a file was called core



5. Use gdb to see what happen when execute the ./a.out

gdb -c core ./a.out



Will show what happen

root@happy-laptop:/home/happy/test/test3# gdb -c core ./a.out

GNU gdb (GDB) 7.1-ubuntu

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

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 "i486-linux-gnu".

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>...

Reading symbols from /home/happy/test/test3/a.out...done.

[New Thread 3443]



warning: Can't read pathname for load map: Input/output error.

Reading symbols from /lib/tls/i686/cmov/libc.so.6...(no debugging symbols found)...done.

Loaded symbols for /lib/tls/i686/cmov/libc.so.6

Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.

Loaded symbols for /lib/ld-linux.so.2

Core was generated by `./a.out'.

Program terminated with signal 11, Segmentation fault.

#0  0x080483c4 in main () at test.c:6

6        *b = 0x22;