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 ãã¨ããæå³ã«ãªãã¾ãã
sample2ã§ã¯ãsample1.c ã¨åããã確å®ã«ã»ã°ã¡ã³ãã¼ã·ã§ã³ã»ãã©ã«ããèµ·ããããã« sub2 é¢æ°ã§æ示çã« 0 ãè¿ãããã«ãã¦ãã¾ããæ¬æ¥ã¯ããã®ç´åã®ã³ã¡ã³ãã¢ã¦ããã¦ããé¨åã®ããã«ããªãããã®ã¢ãã¬ã¹ã確ä¿ãã¦è¿ãé¢æ°ã sample2.c ã¾ãã-g ãªãã·ã§ã³ãä»ãã¦ã³ã³ãã¤ã«ããå®è¡å½¢å¼ãå®è¡ãã¦ã³ã¢ãã³ãããããããã¦ãgdb ãèµ·åãã¦ã¹ã¿ãã¯ãã¬ã¼ã¹ã確èªããã å®è¡çµæ ä»åã¯ãlibc.so.6 ã¨ããã©ã¤ãã©ãªã®ä¸ã® _IO_str_overflow_internal ã¨ããé¢æ°ã§ã¨ã©ã¼ãçºçãã¦ããããã§ããã backtrace ã³ãã³ã ãã®é¢æ°ãã©ã®ããã«å¼ã³åºããã¦ããã®ããè¦ã¦ã¿ãã (gdb) bt #0 0x42070fa4 in _IO_str_overflow_internal () from /lib/tls/libc.so
ãã¨ãã°ãå¤æ° var ã®å¤ã2é²æ°ã§è¡¨ç¤ºãããå ´åã¯ã次ã®ããã«æå®ãã¾ãã (gdb) p/t var ä¸è¦§è¡¨ç¤º whatis å¤æ°ã®åã調ã¹ãã info b ä»è¨å®ãã¦ãããã¬ã¼ã¯ãã¤ã³ãã®ä¸è¦§ã表示 ã»ã°ã¡ã³ããã©ã«ããããå¾ã«å©ç¨ããã°ãã©ã®é¢æ°ã§çºçããã確èªã§ãã¾ãã info stack é¢æ°ã®å¼ã³åºãã¹ã¿ãã¯ã®ä¸è¦§ã表示 info Thread åå¨ãã¦ããã¹ã¬ããã®ä¸è¦§ã表示 ç°ãªãã¢ãã¬ã¹ã«ãããå¦çç¶ç¶ 以ä¸ã®ã³ãã³ãã使ç¨ãããã¨ã§ãã¦ã¼ã¶ãé¸æããã¢ãã¬ã¹ã«ããã¦å®è¡ãç¶ç¶ããããã¨ãã§ãã¾ã jump linespec linespecã§æå®ãããè¡ã«ããã¦ãå®è¡ãåé jump *address addressã§æå®ãããã¢ãã¬ã¹ã«ããå½ä»¤ãããå®è¡ãåé ã¢ãã¬ã¹ãåãã£ã¦ããå ´åã®ã¡ã¢ãªãªã¼ã¯åºå xã¯hexã®æå³ã§ãã (gdb) p (char*)
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
run ããã°ã©ã ãå®è¡ãã¾ãã run ä½ãå¼æ°ã渡ããã«å®è¡ãã¾ãã run arguments argumentsãå¼æ°ã«æå®ãã¦å®è¡ãã¾ãã ä¾ãã°ã-v -o filenameããå¼æ°ã¨ãã¦èµ·åãããå ´åã¯run -v -o filenameã¨ãã¾ãã runã§ã¯ããã°ã©ã ã®æ¨æºå ¥åºåããªãã¤ã¬ã¯ããããã¨ãå¯è½ã§ãã æ¨æºåºåããã¡ã¤ã«ã«ãªãã¤ã¬ã¯ãããã«ã¯ run > filename æ¨æºå ¥åããã¡ã¤ã«ããèªã¿è¾¼ãã«ã¯ run < filename æ¨æºåºåããã¡ã¤ã«ã«æ¨æºå ¥åããã¡ã¤ã«ããèªãè¾¼ãã«ã¯ run < infile > outfile â quit GDBãçµäºãã¾ãã quit GDBãçµäºãã¾ã â shell ã·ã§ã«ã³ãã³ããå®è¡ãã¾ãã shell ã·ã§ã«(é常 /bin/sh)ãèµ·åãã¾ãã ã·ã§ã«ãçµäºããã¨GDBã«æ»ãã¾ã
Apacheãã·ã³ã°ã«ããã»ã¹ã§ç«ã¡ä¸ãã Apache ãã³ãã©ã¼ãéçºãã¦ããã¨ããªã©ãhttpd ã ç´æ¥ gdbã«ããããå ´åãã·ã³ã°ã«ããã»ã¹ã§èµ·åããã¨ãããã°ããããã å ·ä½çã«ã¯ä¸è¨ã®ããã«ãã-Xããªãã·ã§ã³ãã¤ãã¦ãapacheãèµ·åãã¾ãã ãã¬ã¼ã¯ãã¤ã³ããã½ã¼ã¹ä¸ã«è¨å®ãã gdbã§ãââbreak 30ââã¨ããã£ã¦ãããããã½ã¼ã¹ä¸ã§break pointãè¨å®ãããã¨ãã§ããã ç¹å®ã®æ¡ä»¶ä¸ã®å ´åã®ã¿breakããããå ´åãªã©ã«ä¾¿å©ã signal.hãincludeãã¦SIGTRAPãæããã¨breakããã ãµã³ãã«ã³ã¼ã #include <stdio.h> #include <signal.h> int main() { printf("a\n"); raise(SIGTRAP); printf("b\n"); return 0; } åèæ¸ç±
ã¯ããã« ååã«å¼ãç¶ããPHPæé©åTipsã«ã¤ãã¦æ¤è¨¼ãã¦ããã¾ãã ä»åã¯æååç½®æé¢æ°ã®æ¯è¼ã§ããã¾ãgdbãç¨ããPHPã³ã¼ãã®èªã¿æ¹ã«ã¤ãã¦ãç´¹ä»ãã¾ãã strtr ï¼ str_replace ï¼ preg_replace ã®é ã«éã ãã®3ã¤ã®é¢æ°ã¯ç´°ããªåãã«éãã¯ãããã®ã®ãæååãç½®ãæããé¢æ°ã§ãããã®ããã«åãåããããé¢æ°ãå¤ãåå¨ããã®ã¯è¯ããæªããPHPã®ç¹å¾´ã§ããã¨ããã¾ãã ä¸è¨ã®ãã³ããã¼ã¯ç¨ã®ã³ã¼ããç¨æãã¦ãè¨æ¸¬ãè¡ãã¾ãã benchmark_strtr.php <?php $t = microtime(true); $i = 0; while($i < 1000) { $a = strtr('abcdefghijklmn', 'abc', 'ABC'); ++$i; } $tmp = microtime(true) - $t; var_dump
ã¤ãã¼æ ªå¼ä¼ç¤¾ã¯ã2023å¹´10æ1æ¥ã«LINEã¤ãã¼æ ªå¼ä¼ç¤¾ã«ãªãã¾ãããLINEã¤ãã¼æ ªå¼ä¼ç¤¾ã®æ°ããããã°ã¯ãã¡ãã§ããLINEã¤ãã¼ Tech Blog ãã²ããã¶ãã§ãããªã¼ã¯ã·ã§ã³æ å½ã®å±±å´ãè³¢ã§ãã ååã¯PHP Serialize ã«ã¤ãã¦ã§ãããã ä»åã¯PHPã§ã®ãããã°ã«é¢ãã¦ã話ãã¾ãã åºæ¬PHPã¯ã¤ã³ã¿ããªã¿(å³å¯ã«ã¯PHPã¯å é¨ã§ä¸åº¦ã³ã³ãã¤ã«ãã¦ãã¾ãã®ã§ã¤ã³ã¿ããªã¿ã¨ã¯è¨ãåãã¾ããã) ã®ãããã°ã§ã¯ãã°åãè¾¼ã¿ãæ軽ã§ãã ããããã¾ãã«SIGSEGVãSIGBUSãªã©ã§PHPã¹ã¯ãªãããè½ã¡ããã¨ããããéæ¹ã«ããã¾ãã å°éã«ãã°ãåãè¾¼ãã§ãããç®æãç¹å®ããã®ãææ³ã®1ã¤ã§ãããä»åã¯gdbãç¨ãããããã°æ¹æ³ãè¨è¼ãããã¨æãã¾ãã â STEP1 ã¾ãã¯ãããã°ã©ã ãè½ã¡ããã¨ãç®çã¨ãã¦ä»¥ä¸ã®ãããªPHP Moduleãä½æãã¾ãã ã» ã»
GDBï¼GDBserverã«ããã¯ãã¹ã¿ã¼ã²ããã®ãªã¢ã¼ããããã°ï¼Programing Bibleï¼1/3 ãã¼ã¸ï¼ Linuxãã¼ã¹ã®çµã¿è¾¼ã¿ã·ã¹ãã ã§åãã¢ããªã±ã¼ã·ã§ã³ã®ãããã°ã¯åä»ãªä»äºã ããGDBã使ãã°ç°¡åã«çä»ãããããããã§ã¯ãGDBã使ãä¸ã§æåã®é£é¢ã¨ãªãã»ããã¢ããå¨ãã«ã¤ãã¦è§£èª¬ããã Linuxãã¼ã¹ã®çµã¿è¾¼ã¿ã·ã¹ãã ã§åãã¢ããªã±ã¼ã·ã§ã³ã®ãããã°ã¯åä»ãªä»äºã ããçè«ä¸ã¯GDBï¼GNUãããã¬ï¼ã使ãã°ããã¨ãã§çä»ããããã¯ãã§ãããã ãå®éã«ã¯ããã®ããã®GDBã®ã»ããã¢ãããããé£é¢ã¨ãªããç¾å®ã«ä½æ¥ãçºçããããå æãã¹ãæè¡çãªé害ãåå¨ããããã ãã¨ã¯ãããå½ã¦æ¨éã«é ¼ããããã°ã©ã ãä¸å®ã®æ¹æ³ã§ç³»çµ±çã«ãããã°ãããã¨ã®ã¡ãªããã¯ããã®ä½æ¥ã«æããæéãè£ã£ã¦ãã¾ãããããã®ä½æ¥ã§çããå°é£ã軽æ¸ãããã³ããå¹¾ã¤ãç´¹ä»ãããã ã¿ã¼ã²ãããã©
PHPã¯ã½ã¼ã¹ã³ã¼ããèªãã°ãããã¨ããCè¨èªã§æ¸ãã¦ããã¾ãã ãã®Cè¨èªã®ä¸ã§PHPãã©ããªå¦çããã¦ããã®ãããããã¬ã§ããgdbãç¨ãã¦è¦ããã¨ãã§ããã®ã§ãããç´¹ä»ãã¾ããã¾ãæ®éã®gdbã®ä½¿ãæ¹ãªãã§ãã:p ã½ã¼ã¹ããã¦ã³ãã¼ããã¦ã³ã³ãã¤ã« PHP-5.2.6ã®ã½ã¼ã¹ããã¦ã³ãã¼ããã¾ãã ã¾ã./configureããã¨ã®Makefileãã§ãã¾ãã ãã®Makefileã®ä¸ã§-gãªãã·ã§ã³ãã¤ãã¦ãããã¨ã確èªãã¾ãããã*1 ããããããã¬(gdb)ç¨ã®ãªãã·ã§ã³ã§ãã³ã³ãã¤ã«ããããã¤ããªãã¡ã¤ã«ã«ã½ã¼ã¹ã³ã¼ãã¨ã®å¯¾å¿ä»ããã§ãã¾ãã 次ã«makeãã¾ããæéããããã¾ãã ãµã³ãã«ãã¡ã¤ã« makeãã¦ããéã«æ¬¡ã®ãããªPHPãã¡ã¤ã«ãä½æãã¾ãããã <?php $i = "12"; $k = intval($i); ?> ããã¯æååã®"12"ãintvalé¢
ããã¤ãã®ãã°ãå«ãããªã¼ã½ã¼ãã®ããã°ã©ã ãç¨æãã¾ããã 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++)
gdbã¨ã¯ gdb㯠The GNU Project Debuggerã®ãã¨ã§ãã ãããã°ã®ããã®ãã¼ã«ã§ãã ããã°ã©ã ãã¨ã©ã¼çµäºããããã©ããæªãã®ãããããªã⦠ã¨ãããããªæã«ä¾¿å©ã§ãã æºå ãããã°å¯¾è±¡ããã°ã©ã ã®ã³ã³ãã¤ã« ã³ã³ãã¤ã«ããããã°ã©ã ã«ãããã°æ å ±ãå«ãã¦ããã¨ã ãããã¬ã§ããã°ã©ã ã®ã½ã¼ã¹ãåç §ã§ãããªã©ã ãããã°ãé常ã«æ¥½ã«ãªãã¾ãã gccãUNIXã®ccã§ã¯ãã³ã³ãã¤ã«æã«ã-gããªãã·ã§ã³ãä»å ãã㨠ãããã°æ å ±ãçæãã¾ãã æé©åãªãã·ã§ã³ã-Oã㨠ãããã°ãªãã·ã§ã³ã-gãã®ä¸¡æ¹ã¯ åæã«æå®ã§ããªãã³ã³ãã¤ã©ãããã®ã§æ³¨æãã¦ãã ããã gccã¯åæã«ææã§ãã¾ãã ãªããFreeBSDãRedHat Linuxã®ccã®æ£ä½ã¯gccãªã®ã§ã ã-Oãã¨ã-gããåæã«æå®ã§ãã¾ãã makeã§ã³ã³ãã¤ã«ãã¦ããå ´åã«ã¯ã ã-gããª
ãã¾ãã¾è¬èªãã¦ãã 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 $
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}