Twitterä¸ã§ã@alohakun ãè¨åãã¦ãã GDB ã® reverse debugging ã®æ©è½ã使ã£ã¦ã¿ã¾ããã GDB ã«ãã¬ã¼ã¹ã¨éå®è¡æ©è½å ¥ã£ãã®ãã http://www.gnu.org/software/gdb/news/reversible.html http://twitter.com/alohakun/status/4481139191 ã¾ãã¯ç°¡åãªä½¿ãæ¹ã説æãããã¨ã«ãã¤ã³ã¹ãã¼ã«æ¹æ³ã説æãã¾ãã ãããªã¨ãã«ä¾¿å© ãå¤ãªãã¨ããèµ·ãã¦ãã大ä½ã®å ´æãããã£ã¦ããã¨ã ãããã°ä¸ã«ã大ä½ã©ãã§å¤ãªãã¨ãèµ·ãã¦ãããã¯ããã£ã¦ãããã©ãç´°ããå ´æã¯ç¹å®ã§ãã¦ããªãã¨ããreverse debuggingãå¹æãçºæ®ãã¾ãã GDBã§ã¹ãããå®è¡ããã¦ãã¦ãããã¾ã£ã!è¡ãããã!ãã¨ããçµé¨ã¯ããããã¨æãã¾ããããããã¨ããä»ã¾ã§ã¯ããã°ã©ã ã®å®è¡ãæ
ããã¤ãã®ãã°ãå«ãããªã¼ã½ã¼ãã®ããã°ã©ã ãç¨æãã¾ããã treesort1.c #include <stdio.h> #include <stdlib.h> struct node { int value; struct node *left; struct node *right; }; void treeadd(struct node**, int); void treewalk(struct node*); void treefree(struct node*); int main(int argc, char **argv) { struct node *rootp; int i; int array[15] = {50, 12, 18, 70, 41, 19, 91, 1, 7, 6, 81, 65, 55, 20, 0}; for (i = 0; i < 15; i++)
ãã®åã®Debug Hacks Nightã§å®æ¼ãã¦ããemacs + gdbã®çµã¿åããã¯ä¾¿å©ï¼ï¼ ä»ã¾ã§ã¯ã¿ãã使ããã¿ã¼ããã«ã§ä¸åç®ã®ã¿ãã§emacsã2åç®ã®ã¿ãã§gdbã¨ããæãã§ãã£ã¦ããã©1ç»é¢ã§è¦ãããã gdbã§ã®å®è¡ç¶æ ã¨emacsä¸ã®ã«ã¼ã½ã«ãé£æºãã¦ãããããããã楽ã½( ´âï½)ï¾ å¯ä¸ã®æ¬ ç¹ã¯ç¸¦ã®è¡¨ç¤ºé åãçããªããã¨ããããã ããã®ãããã§gimageviewãã»ã°ãã©ã«ããã件ãç¡çããç´ããã¨ãã§ãã(v^ï½°ï¾)ï¾ï½¯ï¾ï¾!! #ä»ã¾ã§ã¯åçã4ã5æ表示ãããè½ã¡ã¦ããã©ã #ãã¾ã®ã¨ããè½ã¡ã¦ããªãã ãã ãã©ãããã ã§ããæ£ããç´ãæ¹ããã¦ããã¨ã¯æããªãã®ã§ããããéãã®ã¯æ§ãããï½¥ï¾ï½¥(ã¤Ðï½)ï½¥ï¾ï½¥ ウェ ã§ãã§ããåãåãããããã°ã®ã¡ã¢ã¯æ®ããã¨ã«ã é常èªåã¯ãããã±ã¼ã¸ãã¡ããã¨ä½ãã¨ãã¯cowbuilderã§ãã«ããããã§ãããä»å
ã¦ã¡ã®ãã«ã© ã¤ã³ã¿ã¼ãããã®æ代ã«ãªã£ã¦ãå°çè¦æ¨¡ã®ç¥æµã®éç©ã å¯è½ã«ãªã£ããã½ããã¦ã§ã¢éçºã«ããã¦ããªã¼ãã³ã½ã¼ã¹ã½ããã¦ã§ã¢ã®ãã¶ã¼ã«çéçºã注ç®ããã¦ããããã¾ããã¦ãããã®ç¾å®ãç¾å ´ã®è¦ç¹ããè¨ãã¦ããããã å岡 å¼é - ãããã ã²ããã æ¥æ¬OSSæ¨é²ãã©ã¼ã©ã ã¹ãã¢ãªã³ã°ã³ãããã£å§å¡ OSDL Board of Directorsãæ´ä»» ã«ã¼ãã«èªæ¸ä¼ä¸»å®° 2000å¹´6æããã©ã¯ã«ã»ãªããã¯ã¹ã®åµæ¥ã«åå ã 95å¹´ï½98å¹´ãç±³å½Oracleã«ã¦Oracle RDBMSã®éçºããããªã£ã¦ããã 98å¹´ã«Netscapeã®ã½ã¼ã¹ã³ã¼ãå ¬é(Mozilla)ã«è¡æãããããªã¼ãã³ã½ã¼ã¹ã®ä¸çã«é£ã³ãã¿ãã¤ãã«ã¯ä¼ç¤¾ãç«ã¡ä¸ãã¦ãã¾ãã 2008å¹´6æåç· å½¹CTOãéä»»ãä¸ããã°ã©ãã¨ãªã£ãã
Apacheã®Filterã¢ã¸ã¥ã¼ã«ãä½ã£ã話ãããããid:c9katayamaã«æ å ±å ¬éããã¨è¨ãããã¾ã¾ã§ããã®ã§å ¬éãã¾ãã Cè¨èªã®åå¼·ãããããªãApache2.xã®ã¢ã¸ã¥ã¼ã«ãä½ã£ã¦ã¿ããããªãgdb使ã£ã¦ãããã°ãã¦ã¿ããããªã¨èãã¦ã人ã«ãå§ãã§ãã Javaã§ã®Servletã®éçºçµé¨ã®ãã人ã§ããã°ãFilterã®å¦çã®åãããªã¯ã¨ã¹ãã³ã³ããã¹ãã®èãæ¹ã¯åããæãã¯ããªã®ã§ãã¨ã³ããªãèªã¿çµããé ã«ã¯Apacheã®ã¢ã¸ã¥ã¼ã«ãgdbã§ãããã°ããªããä½ãäºãåºæ¥ãã¯ãã§ãã mod_orzãä½æ ä»åã¯mod_orzã¨ããApacheã¢ã¸ã¥ã¼ã«ãä½æãã¾ãã Apacheã¢ã¸ã¥ã¼ã«ãä½æããéã«ã¯ãapxsã¨ããã¢ã¸ã¥ã¼ã«éçºç¨ã®ã³ãã³ãã使ç¨ããã³ãã¬ã¼ããä½ãã¾ãã # apxs -g -n orz Creating [DIR] orz Creating [F
Emacs + GDB ãå©ç¨ããããªãã°ãä½ããã GNU Emacs Manual: Debuggersï¼è±èªï¼ ãèªããã¨ãå¼·ããããããã¾ãã å訳ãåå¨ãã¾ããå 容ãå¤ãããã¦ã¹ãå©ç¨ããæä½ãã°ã©ãã£ã«ã«ãªæ©è½ã«ã¤ãã¦ã®è¨è¿°ãããã¾ããã§ããã ããã¥ã¢ã«ãèªãã§ç解ãããã¨ã¯å®è·µã§è¦ãã¦ããããã§ããã以ä¸ã«ã¾ã¨ãããã¼ãã·ã¼ããå©ç¨ããã°æéãç¯ç´ã§ããããããã¾ããã ããã便å©ãªæ©è½ã«é¢ãã¦æ¼ããããã°æ¯éæãã¦ãã ããã .emacs ;;; GDB é¢é£ ;;; æç¨ãªãããã¡ãéãã¢ã¼ã (setq gdb-many-windows t) ;;; å¤æ°ã®ä¸ã«ãã¦ã¹ã«ã¼ã½ã«ãç½®ãã¨å¤ã表示 (add-hook 'gdb-mode-hook '(lambda () (gud-tooltip-mode t))) ;;; I/O ãããã¡ã表示 (setq gdb-use
ã¤ãã¼æ ªå¼ä¼ç¤¾ã¯ã2023å¹´10æ1æ¥ã«LINEã¤ãã¼æ ªå¼ä¼ç¤¾ã«ãªãã¾ãããLINEã¤ãã¼æ ªå¼ä¼ç¤¾ã®æ°ããããã°ã¯ãã¡ãã§ããLINEã¤ãã¼ Tech Blog ãã²ããã¶ãã§ãããªã¼ã¯ã·ã§ã³æ å½ã®å±±å´ãè³¢ã§ãã ååã¯PHP Serialize ã«ã¤ãã¦ã§ãããã ä»åã¯PHPã§ã®ãããã°ã«é¢ãã¦ã話ãã¾ãã åºæ¬PHPã¯ã¤ã³ã¿ããªã¿(å³å¯ã«ã¯PHPã¯å é¨ã§ä¸åº¦ã³ã³ãã¤ã«ãã¦ãã¾ãã®ã§ã¤ã³ã¿ããªã¿ã¨ã¯è¨ãåãã¾ããã) ã®ãããã°ã§ã¯ãã°åãè¾¼ã¿ãæ軽ã§ãã ããããã¾ãã«SIGSEGVãSIGBUSãªã©ã§PHPã¹ã¯ãªãããè½ã¡ããã¨ããããéæ¹ã«ããã¾ãã å°éã«ãã°ãåãè¾¼ãã§ãããç®æãç¹å®ããã®ãææ³ã®1ã¤ã§ãããä»åã¯gdbãç¨ãããããã°æ¹æ³ãè¨è¼ãããã¨æãã¾ãã â STEP1 ã¾ãã¯ãããã°ã©ã ãè½ã¡ããã¨ãç®çã¨ãã¦ä»¥ä¸ã®ãããªPHP Moduleãä½æãã¾ãã ã» ã»
ãã¾ãã¾è¬èªãã¦ãã php-dev ã¨ããPHPã®å®è£ ãæ¥æ¬èªã§è°è«ããã¡ã¼ãªã³ã°ãªã¹ãã§ãmbstring ã®æ°é¢æ°ãã¨ããã¹ã¬ããããã£ããæ°è¦ã«mb_list_encodings_alias_names()ã¨ããé¢æ°ã追å ãããããã®ã ããæ¢åã®mb_list_encodings()ã¨ã©ãéãã®ãã©ããã¨ããè°è«ãããããã£ã¦ããã ããã§ã¯ãmb_list_encodings()ãé¡æã«ã©ããã£ã¦phpã®å®è£ ãç解ãã¦ãããããã®ããã»ã¹ãè¨è¿°ãã¦ã¿ããããã¡ãããã®æ¹æ³ããã¹ãã§ããã¨ãããã®æ¹æ³ã§ãªããã°ãããªãã¨ãããã¤ã§ããã®æ¹æ³ãé©ç¨å¯è½ã ãªãã¦ãã¨ã主張ããã¤ããã¯ä¸åãªãããä¸ã¤ã®ä¾ã¨ãã¦å¤§è¦æ¨¡ã½ããã¦ã§ã¢ã®å¾®è¦çç解æ¹æ³ãç解ããã ãããã 1) mb_list_encodingsãã©ãã§å©ç¨ããã¦ããããç¥ãã $ cd /usr/src/php-5.1.4 $
ã¢ã»ã³ãã©ã§éã¶æã«ä¾¿å©ãª ~/.gdbinit ãç´¹ä»ãã¾ããã¾ã ~/.gdbinit ã次ã®ããã«è¨è¿°ãã¦ãã ããã # # ~/.gdbinit # # .so ã shlib ã³ãã³ãã§æåã§èªã¿è¾¼ã # set auto-solib-add 0 # ã¹ã¬ããçææã®SIG32ã§ãã¬ã¼ã¯ããªã handle SIG32 nostop # ãã¢ããã¯æ§æã®é¸æ # set disassembly-flavor intel set disassembly-flavor att # ãã©ã°ã¬ã¸ã¹ã¿ã®å¯èªåé¢æ° define pf printf "eflags: %s%s%s%s%s%s%s%s%s (= 0x%08u)\n",\ $eflags & 2048 ? "O":"-",\ $eflags & 1024 ? "D":"-",\ $eflags & 512 ? "I":"-",\
Cã®ããã°ã©ã ã®ä¸ã§ãã¬ã¼ã¯ãã¤ã³ããè¨å®ãã Cã®ããã°ã©ã ããããã°ããéã«ã¯ GDB ãªã©ã®ãããã¬ãå½¹ç«ã¡ã¾ããé常ããã¬ã¼ã¯ãã¤ã³ãã¯ãããã¬ã®ä¸ããè¨å®ãã¾ããããããã°å¯¾è±¡ã®Cã®ããã°ã©ã ã®ä¸ã§è¨å®ãããã¨ãã§ãã¾ãã Linux ãªã #include <signal.h> ãã¦ãä»»æã®ç®æã« raise(SIGTRAP); ãæ¿å ¥ããã° OK ã§ãã raise() é¢æ°ãç¨ã㦠SIGTRAP ã·ã°ãã«ãçºçããã¦ãã¾ãã ããã㯠x86 éå®ãªã __asm__("int3"); ã§ã OK ã§ããããã§ã¯ SIGTRAP ãçºçãããããã« int3 (0xcc) å½ä»¤ãåãè¾¼ãã§ãã¾ããGDB ãã½ããã¦ã§ã¢çã«ãã¬ã¼ã¯ãã¤ã³ããè¨å®ããã¨ãã¯å½è©²ç®æã« int3 ãæ¸ãè¾¼ãã§ããã®ã§ããã£ã¦ãããã¨ã¯å²ã¨ä¼¼ã¦ãã¾ã (GDBã®å ´å㯠int3 ãæ¸ãè¾¼ãé¨åã®
Interfaceèªã®å¥½è©é£è¼ãæ¨æºçãããã¬GDBã®ãã¹ã¦ããä¸å¿ã«ï¼GDBé¢é£æ å ±ãã¾ã¨ããæ¸ç±ã§ãï¼æ¬æ¸ã§ã¯Free Software Foundationããé å¸ããã¦ããï¼ããªã¼ãªãããã¬GDBã使ã£ããããã°ææ³ã解説ãã¾ãï¼GDBã¯ç¾åããã»ã¨ãã©ãã¹ã¦ã®CPUã«å¯¾å¿ãï¼æ°å¤ãã®OSä¸ã§åä½ããããã¨ãã§ãã¾ãï¼ãã®ããï¼çµã¿è¾¼ã¿ã½ããã¦ã§ã¢éçºã§ã¯ãããã¬ã¨ãã¦GDBãæ¨æºçã«ä½¿ããã¦ãã¾ãï¼ãã¹ã¯ãããã»ãã½ã³ã³åãã½ããã¦ã§ã¢éçºè ããçµã¿è¾¼ã¿ã½ããã¦ã§ã¢éçºè ã¾ã§ï¼å¹ åºãæ´»ç¨ãããã¨ãã§ãã¾ãï¼æ¬æ¸ã§ã¯GDBæ¬ä½ã ãã§ãªãï¼GDBã¨é£æºãã¦æ´»ç¨ãããã¼ã«ã¨ãã¦ï¼Emacsï¼Eclipseï¼Cygwinï¼Insightãåãä¸ãã¾ãï¼ ç®æ¬¡ 第1é¨ãGDBã®åºæ¬çãªä½¿ãæ¹ ç¬¬1ç« ãGDBã®ç°¡åãªä½¿ãæ¹ 1 GDBã®æä½ 2 GDBã®ã³ãã³ã 第2ç« ãGDBã®ã»ããã¢ãã
ã大è¦æ¨¡ã½ããã¦ã§ã¢ã®å¹ççãªç解(ãã®1ã2ã3ã4ã5ã6)ããªã©ã¨ãã大è¢è£ãªã¿ã¤ãã«ã§ããã°ãæ¸ããããä»åã¯ä¸æ°ã«å®è·µç·¨ã¨ãããã¨ã§ããªã¼ã½ããã¦ã§ã¢å®çªã®ããã㬠gdb ã®å®è·µç使ãæ¹ã«ã¤ãã¦è¨ãã ããã°ã©ãã®æ¥ã ã«ã¯ãããã°ã©ã ãæ¸ãããã®ã¨ãã£ã¿ãããã°ã©ã ãã³ã³ãã¤ã«(ãããã¯å®è¡)ããããã®ã³ã³ãã¤ã©(ãããã¯ã¤ã³ã¿ããªã¿)ãããã¦ããã°ã©ã ãç解ããããã®ãããã¬ã¨ããä¸ç¨®ã®ç¥å¨ãå¿ é ã§ããã ãã®å®çªã¯ãããã®å ´åxemacs/gcc/gdbã§ãããåã è·(DECã¨ããä¼ç¤¾ã«åãã¦ãã)ã®å ´åããããããããã©ã¤ã¢ããªãªç©ã使ã£ã¦ããã®ã§å¾®å¦ã«ç°ãªãããããã¨ã¯ä¸ç·ã§ããã gdbã¯ä½ã®ããã«å©ç¨ãããã¨ããã¨ãããã°ã©ã ãç解ããããã«å©ç¨ããããããã¬ãªãã ãããããã°ã®ããã«å©ç¨ããã¨ããã®ã¯ãgdbã®åºåã®ååãå©ç¨ãã¦ããªãã¨è¨ã£ã¦ããã¤ãããªãã g
gdbè±ç¥è(d:id:hyoshiok:20080926#p1)ã®ç¶ãã Windowsã®éçºç°å¢ã¯ç¥ããªãã®ã ãã©ãåã«ããã¨ç´ æµãªIDE(çµ±åéçºç°å¢)ãæ´åããã¦ãã¦ããã¦ã¹ã§ããããããã«ããå å®ãç°¡åç°¡åããããããããæ¯ã¹ãã¨ãGNU Emacs+gcc+gdbã¨ããã®ã¯å¾®å¦ã«ã¬ããæããµãããã¨ã¯è¨ããã®ã®ãããã°ã®ããã»ã¹ã¯IDEçãã«ãã¦ã£ã³ãã¦ãGUIã§ã°ãªã°ãªã§ãããã¨ãªãããã¨åºæ¬ã¯å¤ããªãã®ã§ãããã¨ãããã ã³ã³ãã¤ã«æã®ãªãã·ã§ã³ gccã®-gãªãã·ã§ã³ãä»ãããMakefileã®ã³ã³ãã¤ã«ãªãã·ã§ã³ã¯é常CFLAGSãªã®ã§CFLAGS=-gã¨ãã¦ãããæé©åãªãã·ã§ã³(-O)ã¨åæã«ä»ãããã¨ãã§ããã®ã§(ç´ æ´ãã)ãæé©åãªãã·ã§ã³ãé©å½ã«ä»ãã¦ããã æã ããããã°ãªãã·ã§ã³(-g)ãä»ããã¨ãã¯æé©åãªãã·ã§ã³ãã¤ããªãããããã¯-O0(ã¢ã«ãã¡ãã
æå¤ã¨ç¥ã£ã¦ããããã§ããç¥ããªãèªåãæ¥ã 使ãéå ·ãããã§ãgdbã«ã¤ãã¦å¾©ç¿ãã¦ããããã調ã¹ããã¨ã«ããã gdbã¯emacsãã使ã gdbãã³ãã³ãã©ã¤ã³ããç´ ã§ä½¿ãã®ã¯ããããªãã®ããªã¨æãããã£ã±emacsã¨åºãçµåããã¦ããããã ããemacsãã使ãã®ãæ£ãã姿ã§ãããã ããããã ã£ã¦vi使ãã ãããã¨ããç§ä¸¸ããã¯ä½¿ããªããããããã¨ãè¨ããã¤ãããããç§ä¸¸ã£ã¦ãªãã ããã¨ãããã¥ubuntuã§ãå ¥ãã¦ãemacsããã¦ãgdb使ããªããã¨ãæå°ããããªããããããããã説æããããªã£ã¦ã¯ããããããã å æ¥ãããä¼è°ã§ãããã¬ã®è©±ã話é¡ã«ãªã£ãã®ã ãããTCPãªãã¡ããã®ã¹ãã¼ã«åé¡ã®ãããã°æ¹æ³ãªãã§ããã©ãããã¿ãããªè©±é¡ã§ããããã£ã¦ã«ã¼ãã«ã®è©±ï¼ãã¨ããããèãã¨ãããããã¦ã¼ã¶ã©ã³ãã£ããã¨è¥ãããã«ã¼ãããããgdbã§ã»ãã»ãã§ãããã¼ãããããã¼ã£ãã
gdb tips gdb ã使ãä¸ã§ä¾¿å©ãª tips ãç´¹ä»ãã¾ããåºæ¬çãªä½¿ãæ¹ããã¹ã¿ã¼ãã¦ãã人åãã§ãã .gdbinit ã®è¨å® ãã¼ã ãã£ã¬ã¯ããªã« .gdbinit ãç½®ãã¦ããã¨ãgdb ã®èµ·åã®éã«èªã¿è¾¼ã¾ãã¾ããç§ã®å ´åã¯æ¬¡ã®ãããªè¨å®ããã¦ãã¾ãã set history save on set history size 10000 set history filename ~/.gdb_history set print pretty on set print static-members off set charset ASCII set history ããå§ã¾ãæåã® 3è¡ã¯å±¥æ´ã«é¢ããè¨å®ã§ããããããã gdb ã®ã³ãã³ãã©ã¤ã³ã®å±¥æ´ããã¡ã¤ã«ã«ä¿åãããä¿åããè¡ã¯æ大 10000 è¡ããã¡ã¤ã«å㯠~/.gdb_history ãã¨ããæå³ã«ãªãã¾ãã
gdb hacks 第 4 åãåå㯠gdb é»åã§ä½¿ããããã«ãªã£ãæ°å¦é¢æ°ã®ãã£ãæªãã«ã¤ãã¦ä¸æºãè¿°ã¹ã¾ãããããããä¸é¨è§£æ±ºããæ¹æ³ãæãã¤ããã®ã§ã¾ã¨ãã¦ããã¾ãã å½å㯠sqrt ã¨ãã£ãé¢æ°ã·ã³ãã«ã«æ°ããªåæ å ±ãè¨å®ããæ¹æ³ãããã®ã§ã¯ãªããã¨æããgdb ã®ã½ã¼ã¹ãªã©ã調ã¹ã¦ããã®ã§ãããã©ãããããªé½åã®ããæ¹æ³ã¯ãªããããªã®ã§ãããããã¦å¥ã®æ¹æ³ãèãã¾ããã gdb ã§ã¯ convenience variable ã¨ãã $ ã§å§ã¾ãä»»æã®ååã®å¤æ°ã使ããã¨ãã§ãã¾ãã®ã§ãããã«é¢æ°ã·ã³ãã«ã®ã¢ãã¬ã¹ãé¢æ°ãã¤ã³ã¿åã§ãã£ã¹ããã¦ä»£å ¥ãã¦ã¿ã¾ãã (gdb) set $sqrt = (double (*)(double)) sqrt (gdb) set $pow = (double (*)(double, double)) pow (gdb) ptype $s
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}