{"id":3501,"date":"2012-07-12T10:52:05","date_gmt":"2012-07-12T01:52:05","guid":{"rendered":"http:\/\/nanoappli.com\/blog\/?p=3501"},"modified":"2017-02-11T22:48:25","modified_gmt":"2017-02-11T13:48:25","slug":"gdb%e3%81%ab%e3%82%88%e3%82%8b%e3%83%87%e3%83%90%e3%83%83%e3%82%b0%e3%81%ae%e3%83%81%e3%83%a5%e3%83%bc%e3%83%88%e3%83%aa%e3%82%a2%e3%83%ab-%e3%81%9d%e3%81%ae1","status":"publish","type":"post","link":"http:\/\/nanoappli.com\/blog\/archives\/3501","title":{"rendered":"gdb\u306b\u3088\u308b\u30c7\u30d0\u30c3\u30b0\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u305d\u306e1"},"content":{"rendered":"<p>\ngcc\u3067\u4f5c\u3063\u305fC\u8a00\u8a9e\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u3001gdb\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30c7\u30d0\u30c3\u30b0\u3057\u3066\u307f\u307e\u3059\u3002<br \/>\n<br \/>\n\u4eca\u56de\u306e\u5b9f\u9a13\u74b0\u5883\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\nlinux\u74b0\u5883\u3067\u30c6\u30b9\u30c8\u3057\u3066\u307e\u3059\u304c\u3001cygwin\u3067\u3082\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3059\u308b\u306f\u305a\u3067\u3059&#8230;<br \/>\n<br \/>\n<pre lang=\"x\">\n$ gcc --version\ngcc (Ubuntu\/Linaro 4.6.1-9ubuntu3) 4.6.1\n\n$ gdb --version\nGNU gdb (Ubuntu\/Linaro 7.3-0ubuntu2) 7.3-2011.08\n\n$ uname -a\nLinux linuxmint 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011 i686 i686 i386 GNU\/Linux\n<\/pre>\n<br \/>\n\u4eca\u56de\u5b9f\u9a13\u3067\u4f7f\u3046\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3059\u3002<br \/>\n\u5358\u306a\u308b\u8db3\u3057\u7b97\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"c\">\n\/* test01.c *\/\n#include <stdio.h>\n\nint sum( int a, int b );\n\nint main()\n{\n\n    int a = 10; \n    int b = a  * 2;\n\n    int ans = sum( a, b );\n    printf( \"%d\\n\", ans );\n    return 0;\n}\n\nint sum( int a, int b )\n{\n    int result = a + b;\n    return result;\n}\n<\/pre>\n<br \/>\n\u3053\u308c\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3059\u3002<br \/>\n\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b-g\u3067\u30c7\u30d0\u30c3\u30b0\u60c5\u5831\u3092\u57cb\u3081\u8fbc\u3080\u3068\u5171\u306b\u3001-O0\u3067\u6700\u9069\u5316\u3092\u6291\u5236\u3057\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001-S\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u30a2\u30bb\u30f3\u30d6\u30e9\u306e\u30b3\u30fc\u30c9\u3082\u51fa\u529b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n$ gcc -g -O0 -o test01 test01.c\n\n$ gcc -S -O0 test01.c\n\n$ ls\ntest01  test01.c  test01.s\n<\/pre>\n<br \/>\n\u51fa\u6765\u4e0a\u304c\u3063\u305ftest01.s\u306f\u3053\u3093\u306a\u611f\u3058\u3002<br \/>\n<br \/>\n<pre lang=\"c\">\n        .file   \"test01.c\"\n        .section        .rodata\n.LC0:\n        .string \"%d\\n\"\n        .text\n        .globl  main\n        .type   main, @function\nmain:\n.LFB0:\n        .cfi_startproc\n        pushl   %ebp\n        .cfi_def_cfa_offset 8\n        .cfi_offset 5, -8\n        movl    %esp, %ebp\n        .cfi_def_cfa_register 5\n        andl    $-16, %esp\n        subl    $32, %esp\n        movl    $10, 20(%esp)\n        movl    20(%esp), %eax\n        addl    %eax, %eax\n        movl    %eax, 24(%esp)\n        movl    24(%esp), %eax\n        movl    %eax, 4(%esp)\n        movl    20(%esp), %eax\n        movl    %eax, (%esp)\n        call    sum\n        movl    %eax, 28(%esp)\n        movl    $.LC0, %eax\n        movl    28(%esp), %edx\n        movl    %edx, 4(%esp)\n        movl    %eax, (%esp)\n        call    printf\n        movl    $0, %eax\n        leave\n        .cfi_restore 5\n        .cfi_def_cfa 4, 4\n        ret\n        .cfi_endproc\n.LFE0:\n        .size   main, .-main\n        .globl  sum\n        .type   sum, @function\nsum:\n.LFB1:\n        .cfi_startproc\n        pushl   %ebp\n        .cfi_def_cfa_offset 8\n        .cfi_offset 5, -8\n        movl    %esp, %ebp\n        .cfi_def_cfa_register 5\n        subl    $16, %esp\n        movl    12(%ebp), %eax\n        movl    8(%ebp), %edx\n        addl    %edx, %eax\n        movl    %eax, -4(%ebp)\n        movl    -4(%ebp), %eax\n        leave\n        .cfi_restore 5\n        .cfi_def_cfa 4, 4\n        ret\n        .cfi_endproc\n.LFE1:\n        .size   sum, .-sum\n        .ident  \"GCC: (Ubuntu\/Linaro 4.6.1-9ubuntu3) 4.6.1\"\n        .section        .note.GNU-stack,\"\",@progbits\n<\/pre>\n<br \/>\n\u4f5c\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092gdb\u306b\u8aad\u307f\u8fbc\u307e\u305b\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n$ gdb .\/test01\nGNU gdb (Ubuntu\/Linaro 7.3-0ubuntu2) 7.3-2011.08\nCopyright (C) 2011 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later <http:\/\/gnu.org\/licenses\/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\nThis GDB was configured as \"i686-linux-gnu\".\nFor bug reporting instructions, please see:\n<http:\/\/bugs.launchpad.net\/gdb-linaro\/>...\nReading symbols from \/home\/user\/work\/test01...done.\n<\/pre>\n<br \/>\n\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b-g\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u5fd8\u308c\u308b\u3068\u3001\u6700\u5f8c\u306e\u884c\u304c\u4ee5\u4e0b\u306e\u51fa\u529b\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u30c7\u30d0\u30c3\u30b0\u30b7\u30f3\u30dc\u30eb\u304c\u7121\u3044\u3088\u3002\u3068\u6012\u3089\u308c\u3066\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\nReading symbols from \/home\/user\/work\/test01...(no debugging symbols found)...done.\n<\/pre>\n<br \/>\nlist\u30b3\u30de\u30f3\u30c9\u3067\u30bd\u30fc\u30b9\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<br \/>\n\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u3064\u3051\u308b\u3068\u3001\u884c\u756a\u53f7\u6307\u5b9a\u3084\u95a2\u6570\u540d\u6307\u5b9a\u3067\u8868\u793a\u3059\u308b\u4e8b\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n(gdb) list \n1   #include <stdio.h>\n2   \n3   int sum( int a, int b );\n4   \n5   int main()\n6   {\n7   \n8       int a = 10;\n9       int b = a  * 2;\n10  \n\n(gdb) list 5, 12\n5   int main()\n6   {\n7   \n8       int a = 10;\n9       int b = a  * 2;\n10  \n11      int ans = sum( a, b );\n12      printf( \"%d\\n\", ans );\n\n(gdb) list sum\n12      printf( \"%d\\n\", ans );\n13      return 0;\n14  }\n15  \n16  int sum( int a, int b ) \n17  {\n18      int result = a + b;\n19      return result;\n20  }\n<\/pre>\n<br \/>\nb\u30b3\u30de\u30f3\u30c9(break)\u3067\u3001\u30d6\u30ec\u30fc\u30af\u30dd\u30a4\u30f3\u30c8\u3092\u30bb\u30c3\u30c8\u3067\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n(gdb) b 8\nBreakpoint 1 at 0x80483ed: file test01.c, line 8.\n<\/pre>\n<br \/>\nstart\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u958b\u59cb\u3067\u3059\u3002<br \/>\n\u30d6\u30ec\u30fc\u30af\u30dd\u30a4\u30f3\u30c8\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u305f\u306e\u3067\u30018\u884c\u76ee\u3067\u6b62\u307e\u308a\u307e\u3057\u305f\u3002<br \/>\nnext\u30b3\u30de\u30f3\u30c9\u3067\u3082\u30461\u884c\u3060\u3051\u9032\u3081\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n(gdb) start\nTemporary breakpoint 2 at 0x80483ed: file test01.c, line 8.\nStarting program: \/home\/user1\/work\/test01 \n\nBreakpoint 1, main () at test01.c:8\n8       int a = 10;\n(gdb) next\n9       int b = a  * 2;\n<\/pre>\n<br \/>\ninfo b\u3067\u3001\u30d6\u30ec\u30fc\u30af\u30dd\u30a4\u30f3\u30c8\u4e00\u89a7\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n(gdb) info b\nNum     Type           Disp Enb Address    What\n1       breakpoint     keep y   0x080483ed in main at test01.c:8\n    breakpoint already hit 1 time\n<\/pre>\n<br \/>\nprint\u3067\u5909\u6570\u306e\u4e2d\u8eab\u3092\u8868\u793a\u3057\u307e\u3059\u3002<br \/>\n\u5909\u6570b\u306f\u3001\u307e\u3060\u521d\u671f\u5316\u3055\u308c\u3066\u306a\u3044\u306e\u3067\u4e0d\u5b9a\u5024\u304c\u5165\u3063\u3066\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n(gdb) print a\n$2 = 10\n(gdb) print b\n$3 = 134513753\n<\/pre>\n<br \/>\n\u3082\u3046\u4e00\u884c\u9032\u3081\u305f\u3089\u30bb\u30c3\u30c8\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n(gdb) next\n11      int ans = sum( a, b );\n(gdb) print b\n$4 = 20\n<\/pre>\n<br \/>\n\u5909\u6570\u306e\u30a2\u30c9\u30ec\u30b9\u3082\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n<pre lang=\"x\">\n(gdb) print &a\n$5 = (int *) 0xbffff874\n(gdb) print &b\n$6 = (int *) 0xbffff878\n<\/pre>\n<br \/>\n\u9577\u304f\u306a\u3063\u3066\u304d\u305f\u306e\u3067\u3001\u7d9a\u304d\u306f\u6b21\u306e\u8a18\u4e8b\u3078&#8230;<br \/>\n\u6b21\u8a18\u4e8b -> <a href=\"http:\/\/nanoappli.com\/blog\/archives\/3572\">gdb\u306b\u3088\u308b\u30c7\u30d0\u30c3\u30b0\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u305d\u306e2<\/a><br \/>\n\u7d9a\u304d\u306f\u3067\u306f\u3001\u30ec\u30b8\u30b9\u30bf\u3068\u30b9\u30bf\u30c3\u30af\u9818\u57df\u306e\u4f7f\u308f\u308c\u65b9\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>gcc\u3067\u4f5c\u3063\u305fC\u8a00\u8a9e\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u3001gdb\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30c7\u30d0\u30c3\u30b0\u3057\u3066\u307f\u307e\u3059\u3002 \u4eca\u56de\u306e\u5b9f\u9a13\u74b0\u5883\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002 linux\u74b0\u5883\u3067\u30c6\u30b9\u30c8\u3057\u3066\u307e\u3059\u304c\u3001cygwin\u3067\u3082\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3059\u308b\u306f\u305a\u3067\u3059&#8230; $ gcc &#8211;version gcc (Ubuntu\/Linaro 4.6.1-9ubuntu3) 4.6.1 $ gdb &#8211;version GNU gdb (Ubuntu\/Linaro 7.3-0ubuntu2) 7.3-2011.08 $ uname -a Linux linuxmint 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:50:42\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[1],"tags":[112],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3829,"url":"http:\/\/nanoappli.com\/blog\/archives\/3829","url_meta":{"origin":3501,"position":0},"title":"DDD\u30c7\u30d0\u30c3\u30ac\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30aa\u30fc\u30d7\u30f3\u6642\u306bNo Source\u306e\u30c0\u30a4\u30a2\u30ed\u30b0\u304c\u51fa\u308b\u6642\u306f","date":"2012\u5e748\u67081\u65e5","format":false,"excerpt":"gcc\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30c7\u30d0\u30c3\u30ac\u3067\u3042\u308bddd\u3067\u30c7\u30d0\u30c3\u30b0\u3057\u3088\u3046\u3068\u3057\u305f\u6642\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3572,"url":"http:\/\/nanoappli.com\/blog\/archives\/3572","url_meta":{"origin":3501,"position":1},"title":"gdb\u306b\u3088\u308b\u30c7\u30d0\u30c3\u30b0\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u305d\u306e2","date":"2012\u5e747\u670812\u65e5","format":false,"excerpt":"\u524d\u56de\u306e\u7d9a\u304d\u3067\u3059\u3002 gdb\u306b\u3088\u308b\u30c7\u30d0\u30c3\u30b0\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u305d\u306e1 \u4eca\u56de\u306f\u3001\u30ec\u30b8\u30b9\u30bf\u5024\u306e\u78ba\u8a8d\u65b9\u6cd5\u3068\u3001In\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3835,"url":"http:\/\/nanoappli.com\/blog\/archives\/3835","url_meta":{"origin":3501,"position":2},"title":"[C\u8a00\u8a9e\u5165\u9580]\u30d7\u30ea\u30d7\u30ed\u30bb\u30c3\u30b5\u547d\u4ee4\u3092\u7406\u89e3\u3059\u308b","date":"2012\u5e748\u67081\u65e5","format":false,"excerpt":"\u4eca\u307e\u3067\u306e\u5b66\u7fd2\u3067\u306f\u3001gcc\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u3066\u304d\u307e\u3057\u305f\u3002 gcc\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u3044\u304d\u306a\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3577,"url":"http:\/\/nanoappli.com\/blog\/archives\/3577","url_meta":{"origin":3501,"position":3},"title":"[C\u8a00\u8a9e]printf\u306e\u5f8c\u306e\u5165\u529b\u5f85\u3061\u3067\u5165\u529b\u30d0\u30c3\u30d5\u30a1\u304c\u30af\u30ea\u30a2\u3055\u308c\u308b\u7406\u7531","date":"2012\u5e747\u670812\u65e5","format":false,"excerpt":"C\u8a00\u8a9e\u306e\u5165\u9580\u8005\u5411\u3051\u306b\u66f8\u304b\u308c\u305f\u66f8\u7c4d\u3092\u898b\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u826f\u304f\u6709\u308a\u307e\u3059\u3002 #include \u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3555,"url":"http:\/\/nanoappli.com\/blog\/archives\/3555","url_meta":{"origin":3501,"position":4},"title":"[gcc]if\u6587\u30683\u9805\u6f14\u7b97\u5b50\u3067\u306f,\u51fa\u529b\u3055\u308c\u308b\u30b3\u30fc\u30c9\u304c\u7570\u306a\u308b","date":"2012\u5e747\u670811\u65e5","format":false,"excerpt":"gcc\u306e\u30a2\u30bb\u30f3\u30d6\u30e9\u51fa\u529b\u3092\u898b\u3066\u3044\u3066\u6c17\u306b\u306a\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002 C\u8a00\u8a9e\u3067\u306fif\u6587\u3092\u4f7f\u308f\u306a\u304f\u3066\u3082\u30013\u9805\u6f14\u7b97\u5b50\u3092\u4f7f\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3550,"url":"http:\/\/nanoappli.com\/blog\/archives\/3550","url_meta":{"origin":3501,"position":5},"title":"[C\u8a00\u8a9e]getchar()\u95a2\u6570\u306f,1\u6587\u5b57\u5165\u529b\u3059\u308b\u6bce\u306b\u51e6\u7406\u304c\u8d70\u308b\u8a33\u3067\u306f\u306a\u3044","date":"2012\u5e747\u670817\u65e5","format":false,"excerpt":"C\u8a00\u8a9e\u306e\u5165\u9580\u66f8\u3092\u898b\u308b\u3068getchar()\u95a2\u6570\u306e\u8aac\u660e\u3068\u3057\u3066\u3001\"\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\uff11\u6587\u5b57\u5165\u529b\u3092\u8aad\u307f\u53d6\u308b\"\u3068\u66f8\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/3501"}],"collection":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/comments?post=3501"}],"version-history":[{"count":8,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/3501\/revisions"}],"predecessor-version":[{"id":8033,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/3501\/revisions\/8033"}],"wp:attachment":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/media?parent=3501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/categories?post=3501"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/tags?post=3501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}