예를 들어 ls -al을 하려면 아래와 같이 하면 된다.

$ gdb --args ls -al

 

그냥 넣으면 gdb의 옵션으로 해석한다.

$ gdb ls -al
gdb: 인식할 수 없는 옵션 '-al'
Use `gdb --help' for a complete list of options.

 

$ gdb --args executablename arg1 arg2 arg3

[링크 : https://stackoverflow.com/questions/6121094]

Posted by 구차니

댓글을 달아 주세요

귀찮아서 b main 으로만 쓰는건 함정 ㅋㅋ

for 반복문으로 인해서 귀찮아서 결국에는 라인으로 브레이크 잡는법 찾은것도 함정

 

gdb> break filename:line
gdb> b filename:line
gdb> b function

[링크 : https://stackoverflow.com/questions/5276988/]

 

브레이크 목록보기

gdb> info break
gdb> i b

[링크 : https://ccrma.stanford.edu/~jos/stkintro/Useful_commands_gdb.html]

Posted by 구차니

댓글을 달아 주세요

결론만 간단히 내자면, insight 컴파일시 환경설정에 따라서, target/TCP target/Serial이 추가된다.
그러니 신경쓰지 말고
GDBServer/TCP 나 Remote/TCP 둘중에 하나 골라서 쓰면된다.



Selecting a Target
Selecting a target involves choosing a target for debugging and setting connection interface options for the target.

Common targets include: "Exec" for native debuggers, "Remote/Serial" for establishing a connection to a target board via a serial line, "Remote/TCP" for TCP connections, and "Simulator" for connections to the simulator. There may be more depending on the configuration of the debugger being used.

In general, "remote" targets are always serial connections which require the user to specify the serial port and baud rate to be used for the connection and "remote/tcp" targets are always TCP connections which require specifying the hostname and port number of the machine to which to connect. Depending upon configuration, there may be numerous serial- and TCP-based connections. These always follow the naming convention target/Serial and target/TCP.

To select a target, choose one of the available targets from the dropdown menu in the Connection Frame. Then specify the interface options for this target: selecting the baudrate and serial port from the dropdown menus (serial targets only) or entering the hostname and port number (TCP targets only).

[출처 : insight - About GDB - target window]


Posted by 구차니

댓글을 달아 주세요

우분투에서 insight 소스를 받아서 컴파일 하는데 에러를 뱉어낸다 ㄱ-

WARNING: `makeinfo' is missing on your system.  You should only need it if
         you modified a `.texi' or `.texinfo' file, or any other file
         indirectly affecting the aspect of the manual.  The spurious
         call might also be the consequence of using a buggy `make' (AIX,
         DU, IRIX).  You might want to install the `Texinfo' package or
         the `GNU make' package.  Grab either from any GNU archive site.

$ makeinfo
'makeinfo' 프로그램은 현재 설치되어 있지 않습니다.  다음을 입력하여 이를 설치할 수 있습니다:
sudo apt-get install texinfo
머.. texinfo 패지키를 깔면 해결된다.

그리고, make distcelan 이후 다시 configure를 하고 해주니, 요런 에러가 발생한다.
configure: error: no termcap library found
이녀석은 libncurses5-dev 패키지를 설치하면 해결된다.
[링크 : http://leoric99.tistory.com/entry/Ubuntutermcap-라이브러리-해결-방법]

그런데.. 이 에러는 도대체 어떻게 잡아야 하나...
gcc -c -g -O2   -I. -I.././gdb -I.././gdb/config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I.././gdb/../include/opcode -I.././gdb/../readline/.. -I../bfd -I.././gdb/../bfd -I.././gdb/../include -I../libdecnumber -I.././gdb/../libdecnumber   -DMI_OUT=1 -DGDBTK -DTUI=1  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wno-switch -Wno-char-subscripts -Werror linux-nat.c
cc1: warnings being treated as errors
linux-nat.c: In function ‘linux_nat_info_proc_cmd’:
linux-nat.c:2879: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
gdb/Makefile 에서 -Werror 부분을 주석처리 해준다.

WARNING: `bison' missing on your system.  You should only need it if
         you modified a `.y' file.  You may need the `Bison' package
         in order for those modifications to take effect.  You can get
         `Bison' from any GNU archive site.
머.. bison 패키지를 깔면 해결된다.

ada-lex.c missing and flex not available.
... 정말로 파일이 없다.
일단 flex 패키지를 설치해준다.
[링크 : http://kldp.org/node/55249]

그런데.. 또 클린하고 해도..
gcc -g -O2      \
                -o gdb gdb.o libgdb.a \
                   ../readline/libreadline.a ../opcodes/libopcodes.a ../bfd/libbfd.a  ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a    ../libgui/src/libgui.a -L/home/morpheuz/src/insight/itcl/itcl -litcl3.2 -L/home/morpheuz/src/insight/itcl/itk -litk3.2 -L/home/morpheuz/src/insight/tk/unix -ltk8.4 -Wl,-rpath,/usr/local/lib -L/home/morpheuz/src/insight/tcl/unix -ltcl8.4   -lX11 -ldl  -lieee -lm -lncurses -lm   ../libiberty/libiberty.a  -ldl -rdynamic
libgdb.a(ada-lang.o): In function `parse':
/home/morpheuz/src/insight/gdb/ada-lang.c:10972: undefined reference to `ada_parse'
libgdb.a(ada-lang.o):(.rodata+0xda0): undefined reference to `ada_error'

... ada 가 날 열받게 하는구나~ ㄱ-
아놔 안해안해 ㄱ-


+
2016.08.29
[링크 : http://decdream.tistory.com/370] 이분은 성공하셨네 ㅠㅠ


'프로그램 사용 > gdb & insight' 카테고리의 다른 글

gdb break  (0) 2021.04.09
gdb/insight target window  (0) 2010.05.19
gdb / gdbserver 접속명령어  (0) 2010.05.18
insight(gdb) 아키텍쳐별 차이점(?)  (0) 2010.05.18
gdb cross compile 관련  (0) 2010.05.18
Posted by 구차니

댓글을 달아 주세요

gdbserver는 gdb를 돌릴만한 사정이 안되는 시스템을 위한 프로그램으로
단순하게 gdb의 앞단에서 데이터를 TCP나 시리얼 등으로 전송해 주는 역활을 한다.
그런 이유로 gdbserver 만으로는 아무런 것도 할수 없으며

크로스 컴파일 환경이라면, 내부적으로 크로스 환경에 맞추어진 gdb가 별도로 존재해야 한다.
gdbserver는 아래와 같이 host:port 식으로 선언을 하는데 현재까지는 host는 무시를 하고 port만을 받아들인다고 한다.

To use a TCP connection instead of a serial line:

     target> gdbserver host:2345 emacs foo.txt

The only difference from the previous example is the first argument, specifying that you are communicating with the host gdb via TCP. The `host:2345' argument means that gdbserver is to expect a TCP connection from machine `host' to local TCP port 2345. (Currently, the `host' part is ignored.)

[링크 : http://sourceware.org/gdb/current/onlinedocs/gdb/Server.html#Server]

그리고 gdb 쪽에서는 target remote 라는 명령어를 통해 접속이 가능하며, 기본값으로는 TCP로 접속하도록 되어있다.

target remote host:port
target remote tcp:host:port
    Debug using a TCP connection to port on host. The host may be either a host name or a numeric IP address; port must be a decimal number. The host could be the target machine itself, if it is directly connected to the net, or it might be a terminal server which in turn has a serial line to the target.

target remote udp:host:port
    Debug using UDP packets to port on host. For example, to connect to UDP port 2828 on a terminal server named manyfarms:
              target remote udp:manyfarms:2828
    When using a UDP connection for remote debugging, you should keep in mind that the `U' stands for “Unreliable”. UDP can silently drop packets on busy or unreliable networks, which will cause havoc with your debugging session.

[링크 : http://sourceware.org/gdb/current/onlinedocs/gdb/Connecting.html#Connecting]


음.. 그런데 gdb/insight 에서 보이는
GDBserver/TCP , remote/TCP는 멀까?
Posted by 구차니
TAG GDB, gdbserver

댓글을 달아 주세요

테스트 환경
SH4 target board / i686 linux machine

아래의 화면은
./configure --build=i686-linux --host=i686-linux --target=sh4-linux
옵션으로 크로스컴파일된 insight의 Run 메뉴화면이다.


아래의 화면은
./configure
옵션으로 i686용으로 컴파일된 insight의 Run 메뉴화면이다.


음.. 크로스 컴파일 된녀석만 메뉴상에 별도로 Connect to target이 생기고
로컬용으로 컴파일 된녀석은 메뉴상에 Attach to process가 생기는 것으로 보인다.


About GDB 다이얼로그 차이점

<< sh4 , i686 >>
About 다이얼로그의 내용은 gdb 에서 show version으로 나오는 정보이며

가장 아래줄의
This GDB was configured as "i686-pc-linux-gnu".
This GDB was configured as "--host=i686-linux --target=sh4-linux".
만 다르게 나온다.


Attach to Process 메뉴화면

Posted by 구차니
TAG GDB, Insight

댓글을 달아 주세요

검색을 해보니, arm 용으로 크로스 컴파일 하는 문서가 있다.

# ./configure --build=i686-linux --host=arm-linux --target=arm-linux --prefix=/nfsroot/gdb
# ./configure --build=i686-linux --host=i686-linux --target=arm-linux --prefix=$PWD/build
[링크 : http://blog.daum.net/joell/11772014]

일단 gdb는 두번을 컴파일 해야 한다.
target 에서 native 하게 돌아갈 gdb와 (위)
host 에서 target architecture에 맞추어 돌아갈 gdb. (아래)

그리고 prefix 경로는 /usr 을 넣어주는게 좋을듯 하다. (설치를 하면서 보니 prefix가 usr 경로를 의미하는 것으로 보인다)

--- gdb/gdbserver
# ./configure --build=i686-linux --host=sh4-linux --target=sh4-linux --prefix=/home/morpheuz/st7109/target
# make
# make install
n=`echo gdbserver | sed 's,^,sh4-linux-,'`; \
        if [ x$n = x ]; then n=gdbserver; else true; fi; \
        /bin/sh ./../../mkinstalldirs /home/morpheuz/st7109/target/bin; \
        /usr/bin/install -c gdbserver /home/morpheuz/st7109/target/bin/$n; \
        /bin/sh ./../../mkinstalldirs /home/morpheuz/st7109/target/man/man1; \
        /usr/bin/install -c -m 644 ./gdbserver.1 /home/morpheuz/st7109/target/man/man1/$n.1

Posted by 구차니

댓글을 달아 주세요

$ gdb --help
This is the GNU debugger.  Usage:

    gdb [options] [executable-file [core-file or process-id]]
    gdb [options] --args executable-file [inferior-arguments ...]

Options:

  --args             Arguments after executable-file are passed to inferior
  -b BAUDRATE        Set serial port baud rate used for remote debugging.
  --batch            Exit after processing options.
  --batch-silent     As for --batch, but suppress all gdb stdout output.
  --return-child-result
                     GDB exit code will be the child's exit code.
  --cd=DIR           Change current directory to DIR.
  --command=FILE, -x Execute GDB commands from FILE.
  --eval-command=COMMAND, -ex
                     Execute a single GDB command.
                     May be used multiple times and in conjunction
                     with --command.
  --core=COREFILE    Analyze the core dump COREFILE.
  --pid=PID          Attach to running process PID.
  --dbx              DBX compatibility mode.
  --directory=DIR    Search for source files in DIR.
  --epoch            Output information used by epoch emacs-GDB interface.
  --exec=EXECFILE    Use EXECFILE as the executable.
  --fullname         Output information used by emacs-GDB interface.
  --help             Print this message.
  --interpreter=INTERP
                     Select a specific interpreter / user interface
  -l TIMEOUT         Set timeout in seconds for remote debugging.
  --nw             Do not use a window interface.
  --nx               Do not read .gdbinit file.
  --quiet            Do not print version number on startup.
  --readnow          Fully read symbol files on first access.
  --se=FILE          Use FILE as symbol file and executable file.
  --symbols=SYMFILE  Read symbols from SYMFILE.
  --tty=TTY          Use TTY for input/output by the program being debugged.
  --tui              Use a terminal user interface.
  --version          Print version information and then exit.
  -w                 Use a window interface.
  --write            Set writing into executable and core files.
  --xdb              XDB compatibility mode.

For more information, type "help" from within GDB, or consult the
GDB manual (available as on-line info or a printed manual).
Report bugs to "bug-gdb@gnu.org".

스크립트에는 gdb에서 입력하던 명령어들을 넣어주면 된다.

[링크 : http://darkfader.net/arm/files/Example%20GDB%20script.txt]

'프로그램 사용 > gdb & insight' 카테고리의 다른 글

insight(gdb) 아키텍쳐별 차이점(?)  (0) 2010.05.18
gdb cross compile 관련  (0) 2010.05.18
gdb 명령어 - next / step / [엔터]  (0) 2009.07.01
gdb help  (0) 2009.06.26
간단한 gdb/gdbserver/insight 사용법  (0) 2009.06.26
Posted by 구차니

댓글을 달아 주세요

$ more hello.c
#include <unistd.h>

int flag = 0;

void aa()
{
        sleep(1);
}

void bb()
{
        sleep(1);
}

void tt()
{
        if(flag^=1)
                aa();
        else    bb();
}

void main()
{
        int test;
        char str[] = "Hello World!";
        for(test = 0; test < 100; test++)
        {
                printf("Hello World!\n");
                tt();
        }
        test = 1 + 1;

}

위의 소스를
$ gcc -g -o a.out hello.c
로 디버깅이 가능하도록 컴파일을 해준다.

그리고
$ gdb a.out
으로 디버깅을 시작한다.

아무튼~ step과 next 라는 명령어가 있는데
비슷하면서도 다른 역활을 한다.


29                      tt();
(gdb) step
tt () at hello.c:17
17              if(flag^=1)
(gdb) l
12              sleep(1);
13      }
14
15      void tt()
16      {
17              if(flag^=1)
18                      aa();
19              else    bb();
20      }
21
(gdb) next
18                      aa();
(gdb) next
20      }
(gdb)


일단 step은 말그대로 한단계 나아가고, 함수를 만나면 함수 안으로 들어간다. (비쥬얼 스튜디오의 F11)
그리고 next는 다음 줄로 나아가므로, 함수를 만나면 함수 다음줄로 넘어간다. (비쥬얼 스튜디오의 F10)

그리고 어셈블리 레벨에서 진행하려면 ni / si (instruction) 을 입력하면 된다.
Posted by 구차니

댓글을 달아 주세요

gdb 내부 명령어 모음집

가장 눈여겨 볼 만한 부분은
help breakpoints
help running
help stack
으로

gdb에서 한줄 실행, 함수 들어가기, 나가기 등은 running에
함수 불려진 순서등의추적은 stack에
브레이크 포인트 생성/삭제는 breakpoints의 항목에 들어 있다.

일단 Visual Studio에서 많이 쓰는것들로

브레이크 포인트 설정은 break 와 delete breakpoints 이다. (F8)
(gdb) help break
Set breakpoint at specified line or function.
break [LOCATION] [thread THREADNUM] [if CONDITION]
LOCATION may be a line number, function name, or "*" and an address.
If a line number is specified, break at start of code for that line.
If a function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no LOCATION, uses current execution address of selected stack frame.
This is useful for breaking on return to a stack frame.

THREADNUM is the number from "info threads".
CONDITION is a boolean expression.

Multiple breakpoints at one place are permitted, and useful if conditional.

Do "help breakpoints" for info on other commands dealing with breakpoints.
--------------------------------------------------------------------------------
(gdb) help delete breakpoints
Delete some breakpoints or auto-display expressions.
Arguments are breakpoint numbers with spaces in between.
To delete all breakpoints, give no argument.
This command may be abbreviated "delete".

그리고 한줄 실행은 next(행단위 실행 F10) / step(함수단위 실행 F11) 으로
원하는 곳까지 실행은 breakpoint를 잡은후 continue를 하면 된다.

(gdb) help next
Step program, proceeding through subroutine calls.
Like the "step" command as long as subroutine calls do not happen;
when they do, the call is treated as one instruction.
Argument N means do this N times (or till program stops for another reason).

(gdb) help step
Step program until it reaches a different source line.
Argument N means do this N times (or till program stops for another reason).

(gdb) help jump
Continue program being debugged at specified line or address.
Give as argument either LINENUM or *ADDR, where ADDR is an expression for an address to start at.

gdb의 차이점은, 현재 실행중인 라인을 보기가 조금은 힘들다는 것인데,
소스를 보기 위해서는 list를 입력하면 된다.
(gdb) help list
List specified function or line.
With no argument, lists ten more lines after or around previous listing.
"list -" lists the ten lines before a previous ten-line listing.
One argument specifies a line, and ten lines are listed around that line.
Two arguments with comma between specify starting and ending lines to list.
Lines can be specified in these ways:
  LINENUM, to list around that line in current file,
  FILE:LINENUM, to list around that line in that file,
  FUNCTION, to list around beginning of that function,
  FILE:FUNCTION, to distinguish among like-named static functions.
  *ADDRESS, to list around the line containing that address.
With two args if one is empty it stands for ten lines away from the other arg.




Posted by 구차니

댓글을 달아 주세요