Linuxã§ã®ãã®ã¿ã¹ã¯ã¯ã GDBããã³gdbserverããã°ã©ã ã®æšæºãã³ãã«ã«ãã£ãŠè§£æ±ºãããããšãç®çãšããŠããŸãã ã¢ã€ãã¢ã¯ãã³ã³ãã¥ãŒã¿ãŒïŒGDBçšèªã§ã¯ãã¹ãïŒã§ããã°ã©ã ãäœæãããããã³ã³ãã€ã«ããŠãã¿ãŒã²ããããã€ã¹ïŒ target ïŒã«ã¢ããããŒãããããšã§ãã 次ã«ããããã°ããããã¡ã€ã«ãšgdbserverãã¿ãŒã²ããããã€ã¹ïŒ target ïŒã§å®è¡ãã GDBãã¹ãã§å®è¡ããŸãã
ãã®ãããªãããã°ã®çžäºäœçšã¹ããŒã ã¯ã次ã®ããã«ç°¡åã«è¡šãããšãã§ããŸãã
å®è¡å¯èœãã¡ã€ã«ã¯ããªã¢ãŒãã§ãããã°ããããã°ã©ã ã§ãã æ£åžžã«åäœãããã«ã¯ãããã°ã©ã ã€ã³ã¹ã¿ã³ã¹ãã¿ãŒã²ããããã€ã¹ã ãã§ãªãããããã°ãé²è¡äžã®ã³ã³ãã¥ãŒã¿ãŒïŒãã¹ãïŒã«ãé 眮ããå¿ èŠããããŸãã
GDBã¯ããããã°ããã»ã¹ãçŽæ¥å®è¡ããããã°ã©ã ã§ãã éåžžãããã¯GCCããŒã«ãã§ãŒã³ã®äžéšã§ãããã³ã³ãã€ã©ãŒãšåãå Žæã«ãããŸãã
gdbserverã¯GDBã®çžäºéšåã§ããããããã°ã¢ãŒãã§å®è¡å¯èœãã¡ã€ã«ãå®è¡ããŸãã gdbserverã¯ãªã¢ãŒãåŽïŒã¿ãŒã²ããïŒã§å®è¡ããããããã¯ãã¹ã³ã³ãã€ã©ã䜿çšããŠã¿ãŒã²ããããã€ã¹çšã«æ§ç¯ããå¿ èŠããããŸãã å®éããã®èšäºã¯äž»ã«ãœãŒã¹ããã®gdbserverã®ã¢ã»ã³ããªã«çŠç¹ãåœãŠãŠããŸãã
ç§ãèªç±ã«äœ¿ããã®ã¯ã virt2realããŒããšãTI AM335xã·ãªãŒãºã®ããã»ããµãããŒã¹ã«ããããã»ããµã¢ãžã¥ãŒã«ã§ãã 以äžã«virt2realã®äŸã䜿çšããäžé£ã®ã¢ã¯ã·ã§ã³ã瀺ããŸããã AM335xãããã§ç§ãæåããïŒãããŠéèŠãªããš-åæ§ã«ïŒæåããââããšã¯ãã¹ãŠåãã§ãã
泚ïŒãã¹ãã«ã€ã³ã¹ããŒã«ãããŠãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯Ubuntu.12.04ã§ãã
æºåãã
ããŒã ãã£ã¬ã¯ããªã«gdbãã©ã«ããäœæãããã¹ãŠã®æäœãå®è¡ããŸãã å éšã§ã ããŠã³ããŒããµããã©ã«ããŒãäœæããŸãã
mkdir -p ~/gdb/downloads cd ~/gdb/downloads
å¿ èŠãªãœãŒã¹ãããŠã³ããŒãããŠå±éããŸãã GDBèªäœãštermcapã©ã€ãã©ãª ïŒGDBã䜿çšïŒãå¿ èŠã§ãã
wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz wget ftp://ftp.gnu.org/gnu/gdb/gdb-7.8.tar.gz tar xvzf termcap-1.3.1.tar.gz tar xvzf gdb-7.8.tar.gz
éåžžããœãŒã¹ãã©ã«ããŒã«çŽæ¥åéãããŸããããœãŒã¹ããã®ãŸãŸæ®ãããã«ãããè¡ããŸããã ããã¯ãã¿ãŒã²ãããã©ãããã©ãŒã ã1ã€ã§ã¯ãªãè€æ°çš®é¡ããå Žåã«äŸ¿å©ã§ãã ãã®åŸãåãããŠã³ããŒãããããœãŒã¹ãè€æ°å䜿çšã§ããŸãã
termcapã©ã€ãã©ãªãæ§ç¯ãã
ãããã£ãŠãåŸã§gdbserverããã«ããããšãã«å¿ èŠã«ãªãããã termcapã©ã€ãã©ãªããå§ããŸãã ããã°ã©ã ãåéããbuildsãã©ã«ããŒãäœæããŸãã å éšã§ã v2rãã©ã«ããŒãäœæãã virt2realãã©ãããã©ãŒã ã®ãã¹ãŠã®çµæãããã«å ¥ããŸãã ãŸãããã§ã«termcapã©ã€ãã©ãªãæ§ç¯ããããã®termcapãã©ã«ããŒããããŸãã äœæããããã£ã¬ã¯ããªã«ç§»åããŸãã
mkdir -p ~/gdb/builds/v2r/termcap cd ~/gdb/builds/v2r/termcap
䜿çšããã³ã³ãã€ã©ãšranlibãã·ã¹ãã ã«ç€ºããŸãã ç§ã®å Žåãããã¯æ¬¡ã®ãšããã§ãã
export CC=/opt/virt2real-sdk/codesourcery/arm-2013.05/bin/arm-none-linux-gnueabi-gcc export RANLIB=/opt/virt2real-sdk/codesourcery/arm-2013.05/bin/arm-none-linux-gnueabi-ranlib
次ã«æ§æããŸãã --hostããã³--prefixã®2ã€ã®ãã©ã¡ãŒã¿ãŒãæå®ããå¿ èŠããããŸãã
ãã©ã¡ãŒã¿ãŒãšããŠæå®ãããã®
- --hostã§äœãæå®ããããéèŠãã©ããã¯ãŸã ããããŸããã ããããšããå°è±¡ãåããŸããã ãããã«ããããã®ãã©ã¡ãŒã¿ãŒã«æ£ç¢ºã«äœãæå®ããå¿ èŠããããã«ã€ããŠã®æ確ãªèª¬æãèŠã€ãããªãã£ããããã³ã³ãã€ã©ãŒã®ãã¬ãã£ãã¯ã¹ã瀺ããŸããã ã€ãŸã ã³ã³ãã€ã©ã¯arm-none-linux-gnueabi-gccãšåŒã°ããããã-hostãšããŠarm-none-linux-gnueabiãæå®ããŸããã
- --prefixãã©ã¡ãŒã¿ãŒãšããŠãäœæ¥ïŒæ§æïŒã®çµæãä¿åãããã©ã«ããŒãã€ãŸã çŸåšã®ãã©ã«ãã
../../../downloads/termcap-1.3.1/configure --host=arm-none-linux-gnueabi --prefix=~/gdb/builds/v2r/termcap
ãã¹ãŠãæ£ããããšã©ãŒãªãå®è¡ããããšãMakefileãã/ gdb / builds / v2r / termcapãã©ã«ããŒã«äœæãããŸãã
Makefileã確èªãã
å®å
šã«ãã¬ã€ããMakefileãéããŠãå€æ°CCãšRANLIBãäžã§ç€ºãããšããã§ããããšã確èªããããšããå§ãããŸãã å®éãgdbserverãæåã«æ§ç¯ããããšãããšãã«ããã¹ãŠãããŸãããããã«èŠããããçµæã®ãã¡ã€ã«ã¯ã¿ãŒã²ããããŒãäžã§å®è¡ãããããªãããããã®ç¹ã§é·ãéç«ã¡åŸçããŠããŸããã æªç¥ã®çç±ã§ãMakefileã§æšæºã³ã³ãã€ã©ãæ°žç¶çã«äœ¿çšãããŠããããšãå€æããŸããã Makefileå
ã®ã³ã³ãã€ã©ãŒãåãã§ãªãããšãããã£ãå Žåã¯ãåçŽã«æã§çœ®ãæããããšãã§ããŸãïŒç§ãå©ããŠãããŸããïŒã ããããèšäºãæžãåã«ãã¹ãŠã®æé ãç¹°ãè¿ãããšãããã®ãããªåé¡ã¯ãããŸããã§ããã
次ã«ãã©ã€ãã©ãªãåéããŸãã
make make install
gdbserverã®åé
ãµãŒããŒãæ§ç¯ãããã©ã«ããŒãäœæããããã«ç§»åããŸãã
mkdir -p ~/gdb/builds/v2r/gdbserver cd ~/gdb/builds/v2r/gdbserver
termcapã©ã€ãã©ãªã®å ¥æå ãæå®ããŸãã
export LDFLAGS="-static -L~/gdb/builds/v2r/termcap/lib" export CFLAGS="-g -O2 -I~/gdb/builds/v2r/termcap/include"
termcapãšåæ§ã«èšå®ããŸãã ããã§ãGDBã§ã¯ãªãgdbserverãäœæããŠããããšã«æ³šæããããšãéèŠã§ãããããã£ãŠã/ gdb-7.8 / gdb / gdbserverãã©ã«ããŒããæ§æãã¡ã€ã«ãæå®ããŸãã
../../../downloads/gdb-7.8/gdb/gdbserver/configure --host=arm-none-linux-gnueabi --prefix=/home/den1s/gdb/builds/v2r/gdbserver --disable-werror # &&
ã泚æ
ã©ã®ããã«çµ¶å¯Ÿãã¹ãã©ãã«ç€ºããããšããªãã£ããšããŠããåœä»€ãèªåã§èª¿æŽããããšãªã䜿çšã§ããããã«ãç§ã¯æåããŸããã§ããã ãªããªã ãã§å§ãŸããã¹ã--prefixãšããŠæå®ããããšãããšãconfigureãã¡ã€ã«ã¯èªããŸãã ãããã£ãŠãããã§ãŠãŒã¶ãŒåãå
¥åããå¿
èŠããããŸãã
ãã¹ãŠãæ£ãããã°ãMakefileãäœæãããŸãã ããã«æšæºïŒ
make make install
ãè©Šããã ãã
ãããã°ããã»ã¹ããã¹ãããã«ã¯ãçãHello worldãäœæããã¿ãŒã²ãããã©ãããã©ãŒã çšã«ã³ã³ãã€ã«ããŸãã
mkdir -p ~/virt2real/hello_test/ cd ~/virt2real/hello_test/ /opt/virt2real-sdk/codesourcery/arm-2013.05/bin/arm-none-linux-gnueabi-g++ hello.cpp -O0 -g -o hello
ãœãŒã¹ããã±ãŒãžhello.cppãããŠã³ããŒãããŸã ã
#include <iostream> int main(int argc, char* argv[]) { std::cout << "Hello,\n" << std::endl; std::cout << "debugged\n" << std::endl; std::cout << "World!!!" << std::endl; return 0; }
helloå®è¡å¯èœãã¡ã€ã«ãšgdbserverãã¿ãŒã²ããããŒãã«å ¥åããŸãã
SCPã䜿çšããŠ/ usr /ãã©ã«ããŒã«ã¢ããããŒãããŸãã
scp ~/gdb/builds/v2r/gdbserver/bin/gdbserver root@192.168.3.1:/usr/ scp ~/virt2real/hello_test/hello root@192.168.3.1:/usr/
次ã«ãã¿ãŒããã«ã®2çªç®ã®ã€ã³ã¹ã¿ã³ã¹ãå®è¡ããsshãä»ããŠã¿ãŒã²ããããŒãã«æ¥ç¶ãã / usr /ãã©ã«ããŒã«ç§»åããŸãã
ssh root@192.168.3.1 cd /usr/
ã¿ãŒã²ããããŒãäžã§gdbserverãå®è¡ãããããšå ±ã«helloå®è¡å¯èœïŒãããã°æžã¿ïŒãã¡ã€ã«ãå®è¡ããŸãã 次ã«ãæ°ã«å ¥ã£ãããŒãã§ããã¥ãŒã»ãã·ã§ã³ãéããŸãã
[root@virt2real usr]# ./gdbserver :123 hello Process hello created; pid = 5680; listening on port 123
ãã¹ãã«æ»ãã GDBã䜿çšããŠãããã°ãããhelloãã¡ã€ã«ãå®è¡ããŸã
/opt/virt2real-sdk/codesourcery/arm-2013.05/bin/arm-none-linux-gnueabi-gdb hello
èŠåºã
åžžã«GDBãžã®ãã«ãã¹ãæå®ã§ããªãããã«ããã«ã¯ãç°å¢å€æ°ãèšè¿°ã§ããŸãã
export PATH=$PATH:/opt/virt2real-sdk/codesourcery/arm-2013.05/bin/
å¿çãšããŠãGDBããã®æåŸ ã衚瀺ãããŸãã
GNU gdb (Sourcery CodeBench Lite 2013.05-24) 7.4.50.20120716-cvs Copyright (C) 2012 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 "--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi". For bug reporting instructions, please see: <https://sourcery.mentor.com/GNUToolchain/>... Reading symbols from /home/den1s/virt2real/hello_test/hello...done. (gdb)
äžèšã®ããŒãã䜿çšããŠãªã¢ãŒãgdbserverã«æ¥ç¶ããŸãã
(gdb) target remote 192.168.3.1:123
次ã®ã³ãã³ããå ¥åããããã®å¿çãšæåŸ ç¶ãåãåããŸãã
Remote debugging using 192.168.3.1:123 warning: Unable to find dynamic linker breakpoint function. GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code. 0x36fd7e30 in ?? () (gdb)
ãã®å Žåããªã¢ãŒãåŽïŒvirt2realã®åé¢ã«ããã¿ãŒã²ããäžã®gdbserverïŒã¯ããããã°ã»ãã·ã§ã³ã®ã€ã³ã¹ããŒã«ã確èªããå¿ èŠããããŸãã
Remote debugging from host 192.168.3.10 # 192.168.3.10 - IP host'
解説 | ãã¹ã | æšç |
---|---|---|
ã¡ã€ã³ã«ãã¬ãŒã¯ãã€ã³ãã眮ã | | |
ãã¬ãŒã¯ãã€ã³ãã«ç§»å | | |
次ã®è¡ã«ç§»åããŸã | |
|
次ã®è¡ã«ç§»åããŸã | |
|
次ã®è¡ã«ç§»åããŸã | |
|
次ã®è¡ã«ç§»åããŸãïŒãã ããããã§ã¯ãããŸããïŒ | | |
ããã°ã©ã ãæåŸãŸã§å®è¡ãããšãå®äºããŸã |
| |
ããã§ã段éçãªãããã°ã®äŸã¯å®äºã§ãã ç§ã¯æ³šæããŸãïŒ
- ã³ãã³ãã®å®å šãªãªã¹ãã«ã€ããŠã¯ãhelpã³ãã³ãã䜿çšã§ããŸãããŸããGDBã䜿çšãããããã°ã«é¢ããæ¬ãèªãããšãã§ããŸãïŒèšäºã®æåŸã«ãããªã³ã¯ãåç §ïŒ
- GDBã䜿çšãããæåããããã°ã¯éåžžã«éå±ãªã®ã§ãããšãã°Eclipseããããã®ç®çã«äœ¿çšããããšããå§ãããŸãã æ®å¿µãªããããã®èšäºã®ãã¬ãŒã ã¯ãŒã¯å ã§ã®ãã®ãããªãããã°ã®èª¬æã¯ããããäžé©åãªæ¬¡å ã«å¢ãããŸãã èšäºã®æåŸã«ããã®ãããã¯ã«é¢ããéåžžã«åªããè±èªã®èª¬æãžã®ãªã³ã¯ããããŸãã
Sysrootã€ã³ã¹ããŒã«
GDBãæ£ããåäœãããã«ã¯ããªã¢ãŒãOSã©ã€ãã©ãªïŒã¿ãŒã²ããïŒããèªã¿åãããšãã§ããããããããããã°ã·ã³ãã«ãå¿ èŠã§ãã ãããã®äžåšã¯ãäŸãã°ããã®ãããªã¡ãã»ãŒãžã®çç±ã§ãïŒ
(gdb) next Cannot access memory at address 0x0 Cannot access memory at address 0x0 0x36d1f040 in ?? () Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"?
ãŸããä»ã®äžå¿«ãªãããã°åé¡ãåŒãèµ·ããå¯èœæ§ããããŸãã
ãã¹ãäžã®GDBã®åé¡ãä¿®æ£ããã«ã¯ã次ã®ã³ãã³ãã䜿çšããŠããããã®ãŸãã«ã©ã€ãã©ãªãååŸããå Žæãæå®ããå¿ èŠããããŸãã
set sysroot [Directory]
ãã¹ãã®ã©ããã«ã¿ãŒã²ããLinuxã®ã€ã¡ãŒãžããªãŒããŒããŒãããŠããå Žåãã©ã€ãã©ãªãã©ã«ããŒãžã®ãã¹ãæå®ããå¿ èŠããããŸãã
ãŸãã¯ããããã®ã©ã€ãã©ãªããã¹ãã«ããªããŒãããŸãã
mkdir -p ~/virt2real/sysroot cd ~/virt2real/sysroot scp -r root@192.168.3.1:/lib lib
ãããžã§ã¯ãã®ãããã©ã«ããŒã«æ»ããGDBãå床å®è¡ããŠãã©ã€ãã©ãªãŒãžã®ãã¹ã瀺ããŸãã
cd ~/virt2real/hello_test/ arm-none-linux-gnueabi-gdb hello (gdb) set sysroot ~/virt2real/hello_test/
çŸåšã次ã®ãããªã¡ãã»ãŒãžïŒ
Reading symbols from ~/virt2real/sysroot/lib/libgcc_s.s...done.
çŸåšäœ¿çšãããŠããã©ã€ãã©ãªã®ãªã¹ãã¯ã次ã®ããã«è¡šç€ºã§ããŸãã
(gdb) info sharedlibrary From To Syms Read Shared Object Library 0x36fd77a0 0x36ff24d0 Yes (*) ~/virt2real/sysroot/lib/ld-linux.so.3 No /usr/lib/libstdc++.so.6 0x36e70e00 0x36ed107c Yes (*) ~/virt2real/sysroot/lib/libm.so.6 0x36e51028 0x36e63154 Yes (*) ~/virt2real/sysroot/lib/libgcc_s.so.1 0x36d1cb00 0x36e11ae8 Yes (*) ~/virt2real/sysroot/lib/libc.so.6 (*): Shared library is missing debugging information.
䜿çšããããæåŠãã®ãªã¹ã
- çµã¿èŸŒã¿Linuxã®ãããã°æ¹æ³ã ãã·ã¢èªã§
- Gdbserverã¢ã»ã³ããªã®èª¬æã ãã·ã¢èªã§
- Gdbserverã¢ã»ã³ããªã®èª¬æã è±èªã§
- sysrootãã€ã³ã¹ããŒã«ããŸãã è±èªã§
- R.ã¹ããŒã«ãã³ã GDBã䜿çšãããããã°ã è±èªã§
- Code Composer StudioïŒåãEclipseïŒã§GDBãæ§æããŸãã è±èªã§
- åæ±èª¬ææž1ïŒcdã/ gdb /ããŠã³ããŒã
2ïŒwget ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
3ïŒwget ftp.gnu.org/gnu/gdb/gdb-7.8.tar.gz
4ïŒtar xvzf termcap-1.3.1.tar.gz
5ïŒtar xvzf gdb-7.8.tar.gz
6ïŒmkdir -pã/ gdb / builds / v2r / termcap
7ïŒcdã/ gdb / builds / v2r / termcap
8ïŒãšã¯ã¹ããŒãCC = / opt / virt2real-sdk / codesourcery / arm-2013.05 / bin / arm-none-linux-gnueabi-gcc
9ïŒãšã¯ã¹ããŒãRANLIB = / opt / virt2real-sdk / codesourcery / arm-2013.05 / bin / arm-none-linux-gnueabi-ranlib
10ïŒ../../../downloads/termcap-1.3.1/configure --host = arm-none-linux-gnueabi --prefix =ã/ gdb / builds / v2r / termcap
11ïŒäœã
12ïŒã€ã³ã¹ããŒã«ãã
13ïŒmkdir -pã/ gdb / builds / v2r / gdbserver
14ïŒcdã/ gdb / builds / v2r / gdbserver
15ïŒexport LDFLAGS = "-static -Lã/ gdb / builds / v2r / termcap / lib"
16ïŒexport CFLAGS = "-g -O2 -Iã/ gdb / builds / v2r / termcap / include"
17ïŒ../../../downloads/gdb-7.8/gdb/gdbserver/configure --host = arm-none-linux-gnueabi --prefix = / home / den1s / gdb / builds / v2r / gdbserver- -disable-werrorïŒ&&
18ïŒäœã
19ïŒã€ã³ã¹ããŒã«ãã
PSïŒãã®èšäºã¯ç§åŠçãªç®æ°ããã䞻匵ãããã®ã§ã¯ãããŸããããGDB-gdbserverãã³ãã«ã®ã¢ã»ã³ããªãšæ§æã«é¢ãã詳现æ å ±ã1ãæã«éããè©Šã¿ã§ãã é«åºŠãªlinuxoidã®å Žåããã®è³æã¯ãããã§äžåšçšã«èŠãããããããŸããããããŒããŠã§ã¢å¿åã®äººããã€ã¯ãã³ã³ãããŒã©ãŒããã°ã©ããŒã«ãšã£ãŠã¯ãLinuxãžã®åãæ¿ãã¯ããã»ã©ç°¡åã§ã¯ãããŸããïŒç§ã¯èªåã§å€æããŸãïŒã ããã§ãããŸãããã°ãè³æã圹ã«ç«ã€äººã«åœ¹ç«ã€ã§ãããã