{"id":5446,"date":"2022-05-24T11:38:19","date_gmt":"2022-05-24T02:38:19","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=5446"},"modified":"2022-05-26T15:45:22","modified_gmt":"2022-05-26T06:45:22","slug":"gdb","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=5446","title":{"rendered":"gdb \uc0ac\uc6a9\ubc95"},"content":{"rendered":"<h1>gdb \uc0ac\uc6a9\ubc95<\/h1>\n<p>Segmentation Fault \uac00 \ubc1c\uc0dd\ud558\uba74, \uc624\ub958\uac00 \ubc1c\uc0dd\ud55c \ud30c\uc77c\uba85\uacfc \uc704\uce58\ub97c \uc54c\ub824\uc900\ub2e4.<\/p>\n<p><a href=\"http:\/\/kwanseob.blogspot.com\/2012\/03\/gdb.html?m=1\">\ucc38\uc8701<\/a><\/p>\n<p><a href=\"https:\/\/m.blog.naver.com\/sera3579\/220970543861\">\ucc38\uc8702<\/a><\/p>\n<h2>\uc804\uc81c\uc870\uac74<\/h2>\n<ol>\n<li>\n<p>\ucef4\ud30c\uc77c\uc2dc g \uc635\uc158\uc744 \ud3ec\ud568\ud574\uc57c \ud55c\ub2e4.<\/p>\n<\/li>\n<li>\n<p>\uc2e4\ud589\ud30c\uc77c\uacfc \uc18c\uc2a4\ud30c\uc77c\uc774 \uac19\uc740 \ud3f4\ub354\uc5d0 \uc788\uc5b4\uc57c \ud55c\ub2e4.<\/p>\n<\/li>\n<\/ol>\n<h2>\ucef4\ud30c\uc77c\ud558\uae30<\/h2>\n<pre><code class=\"language-c\">#include &lt;stdio.h&gt;\n\nint main() {\n    printf(&quot;Hello, World!\\n&quot;);\n}<\/code><\/pre>\n<pre><code class=\"language-bash\">gcc -g -o main main.c<\/code><\/pre>\n<h2>gdb \uc2e4\ud589 \ubc0f \uc885\ub8cc<\/h2>\n<h3>\uc2e4\ud589\ud558\uae30(gdb)<\/h3>\n<pre><code class=\"language-bash\"># gdb [\ud504\ub85c\uadf8\ub7a8\uba85]\ngdb main<\/code><\/pre>\n<p>\uc774\ubbf8 \uc2e4\ud589\uc911\uc778 \ud504\ub85c\uadf8\ub7a8\uc744 \ub514\ubc84\uae45\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\"># gdb [\ud504\ub85c\uadf8\ub7a8\uba85] [\ud504\ub85c\uc138\uc2a4PID]\ngdb main 1928\n\n# or\n\ngdb main\n(gdb) attach 1928\n<\/code><\/pre>\n<h3>\uc885\ub8cc\ud558\uae30(quit \/ q)<\/h3>\n<p>3\uac00\uc9c0 \ubc29\ubc95\uc774 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\">ctrl + d\n(gdb) q\n(gdb) quit<\/code><\/pre>\n<h2>\uc18c\uc2a4\ubcf4\uae30(list \/ l)<\/h2>\n<pre><code class=\"language-bash\">(gdb) l(list)\n(gdb) list 10\n(gdb) list [\ud568\uc218\uba85]\n(gdb) list -  \/\/ \uc774\uc804 10\ub77c\uc778\uc744 \ucd9c\ub825\ud55c\ub2e4.\n(gdb) list [\ud30c\uc77c\uba85]:[\ud568\uc218\uba85]\n(gdb) list [\ud30c\uc77c\uba85]:10<\/code><\/pre>\n<p>\ud45c\uc2dc \ub77c\uc778\uc218\ub294 \ub514\ud3f4\ud2b8\ub85c 10\uac1c\uc774\ub2e4.<br \/>\n\ud45c\uc2dc \ub77c\uc778\uc218\ub97c \ub298\ub9ac\ub824\uba74 \uc544\ub798 \uba85\ub839\uc744 \uc218\ud589\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-bash\">(gdb) set listsize 20<\/code><\/pre>\n<h2>\ud504\ub85c\uadf8\ub7a8 \uc2e4\ud589\ud558\uae30(run \/ r)<\/h2>\n<p>\ube0c\ub798\uc774\ud06c \ud3ec\uc778\ud2b8\uac00 \uc5c6\uae30 \ub54c\ubb38\uc5d0 \uc2e4\ud589 \ud6c4 \uc989\uc2dc \uc885\ub8cc\ub41c\ub2e4.<\/p>\n<pre><code class=\"language-bash\">(gdb) r\nStarting program: \/home\/skyer9\/test\/main\nHello, World!\n[Inferior 1 (process 2941096) exited normally]\n(gdb)<\/code><\/pre>\n<h2>\ud504\ub85c\uadf8\ub7a8 \uc885\ub8cc\ud558\uae30(kill \/ k)<\/h2>\n<pre><code class=\"language-bash\">(gdb) k(kill)<\/code><\/pre>\n<h2>\ube0c\ub808\uc774\ud06c \ud3ec\uc778\ud2b8(break \/ b)<\/h2>\n<h3>\ube0c\ub808\uc774\ud06c \ubaa9\ub85d\ubcf4\uae30(info break \/ i b)<\/h3>\n<pre><code class=\"language-bash\">(gdb) info break<\/code><\/pre>\n<h3>\uae30\ubcf8 \uc0ac\uc6a9\ubc95<\/h3>\n<pre><code class=\"language-bash\">(gdb) b(break) [\ud568\uc218\uba85]\n(gdb) break 10\n(gdb) break [\ud30c\uc77c\uba85]:[\ud568\uc218\uba85]\n(gdb) break [\ud30c\uc77c\uba85]:10\n(gdb) break +2             \/\/ \ud604\uc7ac \ud589\uc5d0\uc11c 2\uac1c \ud589 \uc774\ud6c4 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \uc124\uc815\n(gdb) break -2             \/\/ \ud604\uc7ac \ud589\uc5d0\uc11c 2\uac1c \ud589 \uc774\uc804 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \uc124\uc815\n(gdb) break *0x8049000     \/\/ \uba54\ubaa8\ub9ac\uc8fc\uc18c\uc5d0 \uc124\uc815(\uc5b4\uc148\ube14\ub9ac\ub85c \ub514\ubc84\uae45\uc2dc \uc774\uc6a9)<\/code><\/pre>\n<p>\uc608\uc81c<\/p>\n<pre><code class=\"language-bash\">(gdb) l\n1       #include &lt;stdio.h&gt;\n2\n3       int main() {\n4           printf(&quot;Hello, World!\\n&quot;);\n5       }\n(gdb) b 4\nBreakpoint 1 at 0x555555555151: file main.c, line 4.\n(gdb) r\nStarting program: \/home\/skyer9\/test\/main\n\nBreakpoint 1, main () at main.c:4\n4           printf(&quot;Hello, World!\\n&quot;);<\/code><\/pre>\n<h3>\uc870\uac74\ubd80 \ube0c\ub808\uc774\ud06c<\/h3>\n<p>\ud2b9\uc815 \uc870\uac74\uc5d0\uc11c \ube0c\ub808\uc774\ud06c\uac00 \ubc1c\ub3d9\ud558\ub3c4\ub85d \ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\">(gdb) break 10 if var == 0  \/\/ var \ubcc0\uc218\uc758 \uac12\uc774 0\uc77c\ub54c 10\ubc88 \ud589\uc5d0 \uc124\uc815<\/code><\/pre>\n<p>\uc774\ubbf8 \ud504\ub85c\uadf8\ub7a8\uc774 \uc2e4\ud589\uc911\uc778 \uc0c1\ud0dc\uc5d0\uc11c \ube0c\ub808\uc774\ud06c \ud3ec\uc778\ud2b8\ub97c \ubcc0\uacbd\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\">(gdb) condition [N] var == 0       \/\/ var\ubcc0\uc218\uac00 0\uc77c\ub54c N\ubc88 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \ub3d9\uc791\n(gdb) condition [N] func(i) &gt; 5<\/code><\/pre>\n<p>\uc608\uc81c \ucf54\ub4dc\ub97c \uc544\ub798 \ub0b4\uc6a9\uc73c\ub85c \ubcc0\uacbd\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-c\">\/\/ gcc -g -o main main.c\n#include &lt;stdio.h&gt;\n\nint main() {\n    for (int i = 0; i &lt; 10; i++) {\n        printf(&quot;Hello, World! %d\\n&quot;, i);\n    }\n}<\/code><\/pre>\n<p>\uc608\uc81c<\/p>\n<pre><code class=\"language-bash\">(gdb) l\n1       #include &lt;stdio.h&gt;\n2\n3       int main() {\n4           for (int i = 0; i &lt; 10; i++) {\n5               printf(&quot;Hello, World! %d\\n&quot;, i);\n6           }\n7       }\n(gdb) b 5 if i == 5\nBreakpoint 1 at 0x115e: file main.c, line 5.\n(gdb) r\nStarting program: \/home\/skyer9\/work\/hackrf\/sniffingd\/test\/main\nHello, World! 0\nHello, World! 1\nHello, World! 2\nHello, World! 3\nHello, World! 4\n\nBreakpoint 1, main () at main.c:5\n5               printf(&quot;Hello, World! %d\\n&quot;, i);<\/code><\/pre>\n<p>for \ubb38\uacfc \uac19\uc774 \ube0c\ub808\uc774\ud06c\ub97c \uac78 \uc218 \uc5c6\ub294 \ub77c\uc778\ub3c4 \uc788\ub2e4.<\/p>\n<h3>\ubcc0\uc218 \uc870\ud68c \/ \ube0c\ub808\uc774\ud06c \uc9c4\ud589<\/h3>\n<pre><code class=\"language-bash\">(gdb) whatis [\ubcc0\uc218\uba85]\n(gdb) print [\ubcc0\uc218\uba85]               \/\/ \ubcc0\uc218\uc5d0 \uc800\uc7a5\ub41c \ud604\uc7ac \uac12\uc744 \ud55c\ubc88 \ucd9c\ub825\n(gdb) display [\ubcc0\uc218\uba85]             \/\/ \ubcc0\uc218\uc5d0 \uc800\uc7a5\ub41c \ud604\uc7ac \uac12\uc744 \uc9c0\uc18d\uc801\uc73c\ub85c \ucd9c\ub825\n\n(gdb) next(or n)                  \/\/ \ud604\uc7ac \ud589 \uc218\ud589 \ud6c4 \uc815\uc9c0, \ud568\uc218 \ud638\ucd9c\uc2dc \ud568\uc218 \uc218\ud589 \ub2e4\uc74c \ud589\uc73c\ub85c \ub118\uc5b4\uac10\n(gdb) next(or n) [\ud69f\uc218]           \/\/ next \ub97c \ud69f\uc218\ub9cc\ud07c \ubc18\ubcf5\n\n(gdb) step(or s)                  \/\/ \ud568\uc218\ub97c \ub9cc\ub098\uba74 \ud568\uc218\uc548\uc73c\ub85c \ub4e4\uc5b4\uac00\uc11c \uc2e4\ud589, \ub098\uba38\uc9c0\ub294 next \uc640 \ub3d9\uc77c\n\n(gdb) c(continue)              \/\/ \ub2e4\uc74c \ube0c\ub808\uc774\ud06c\uae4c\uc9c0 \uacc4\uc18d \ud504\ub85c\uadf8\ub7a8 \uc2e4\ud589<\/code><\/pre>\n<h3>\ube0c\ub808\uc774\ud06c \uc0ad\uc81c(delete \/ d) \ub610\ub294 \ube44\ud65c\uc131\ud654(disable \/ ensable)<\/h3>\n<pre><code class=\"language-bash\">(gdb) i b              \/\/ \ube0c\ub808\uc774\ud06c\ubc88\ud638 \uc870\ud68c\n(gdb) d [\ube0c\ub808\uc774\ud06c\ubc88\ud638]\n(gdb) d                \/\/ \ubaa8\ub4e0 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \uc9c0\uc6c0\n\n(gdb) disable br       \/\/ \ubaa8\ub4e0 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \ube44\ud65c\uc131\ud654\n(gdb) disable br 1 3   \/\/ 1\ubc88, 3\ubc88 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \ube44\ud65c\uc131\ud654\n(gdb) ensable br       \/\/ \ubaa8\ub4e0 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \ud65c\uc131\ud654\n(gdb) ensable br 1 3   \/\/ 1\ubc88, 3\ubc88 \ube0c\ub808\uc774\ud06c\ud3ec\uc778\ud2b8 \ud65c\uc131\ud654<\/code><\/pre>\n<p>delete \ub294 \ud2b9\uc815 \ube0c\ub808\uc774\ud06c\ubc88\ud638 \ub610\ub294 \uc804\uccb4\ub97c \uc0ad\uc81c\ud558\uace0,<br \/>\nclear \ub294 \ud2b9\uc815 \ud568\uc218\uc758 \ube0c\ub808\uc774\ud06c \uc804\uccb4\ub97c \uc0ad\uc81c\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\">(gdb) cl(clear) [\ud568\uc218\uba85]\n(gdb) clear 10\n(gdb) clear [\ud30c\uc77c\uba85]:[\ud568\uc218\uba85]\n(gdb) clear [\ud30c\uc77c\uba85]:10<\/code><\/pre>\n<h2>layout \ubcc0\uacbd<\/h2>\n<p>\uc544\ub798 \uba85\ub839\uc73c\ub85c \uc18c\uc2a4\ucf54\ub4dc \ud45c\uc2dc\ucc3d\uc744 \ucd94\uac00\ud560 \uc218 \uc788\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2022\/05\/2022-05-26-01.png\" alt=\"\" \/><\/p>\n<pre><code class=\"language-bash\">(gdb) layout src<\/code><\/pre>\n<p>\ud3ec\ucee4\uc2a4\uac00 \uc18c\uc2a4\ucc3d\uc5d0 \uc788\ub294 \uacbd\uc6b0,<br \/>\n\uc0c1\ud558 \ucee4\uc11c\uac00 \uc18c\uc2a4\ucf54\ub4dc \uc774\ub3d9\uc73c\ub85c \uc791\ub3d9\ud55c\ub2e4.<br \/>\n\uc774\uc804 \uba85\ub839\uc744 \ucc3e\uace0\uc790 \ud55c\ub2e4\uba74 \ud3ec\ucee4\uc2a4\ub97c \uba85\ub839\ucc3d\uc73c\ub85c \uc774\ub3d9\ud574 \uc900\ub2e4.<\/p>\n<pre><code class=\"language-bash\">(gdb) info win\n        SRC     (36 lines)  &lt;has focus&gt;\n        CMD     (18 lines)\n(gdb) fs next\nFocus set to CMD window.\n(gdb) info win\n        SRC     (36 lines)\n        CMD     (18 lines)  &lt;has focus&gt;\n(gdb) fs SRC\nFocus set to SRC window.\n(gdb)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>gdb \uc0ac\uc6a9\ubc95 Segmentation Fault \uac00 \ubc1c\uc0dd\ud558\uba74, \uc624\ub958\uac00 \ubc1c\uc0dd\ud55c \ud30c\uc77c\uba85\uacfc \uc704\uce58\ub97c \uc54c\ub824\uc900\ub2e4. \ucc38\uc8701 \ucc38\uc8702 \uc804\uc81c\uc870\uac74 \ucef4\ud30c\uc77c\uc2dc g \uc635\uc158\uc744 \ud3ec\ud568\ud574\uc57c \ud55c\ub2e4. \uc2e4\ud589\ud30c\uc77c\uacfc \uc18c\uc2a4\ud30c\uc77c\uc774 \uac19\uc740 \ud3f4\ub354\uc5d0 \uc788\uc5b4\uc57c \ud55c\ub2e4. \ucef4\ud30c\uc77c\ud558\uae30 #include &lt;stdio.h&gt; int main() { printf(&quot;Hello, World!\\n&quot;); } gcc -g -o main main.c gdb \uc2e4\ud589 \ubc0f \uc885\ub8cc \uc2e4\ud589\ud558\uae30(gdb) # gdb [\ud504\ub85c\uadf8\ub7a8\uba85] gdb main \uc774\ubbf8 \uc2e4\ud589\uc911\uc778 \ud504\ub85c\uadf8\ub7a8\uc744 \ub514\ubc84\uae45\ud560 \uc218 \uc788\ub2e4.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=5446\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"class_list":["post-5446","post","type-post","status-publish","format-standard","hentry","category-c-c"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5446"}],"version-history":[{"count":17,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5446\/revisions"}],"predecessor-version":[{"id":5479,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5446\/revisions\/5479"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}