{"id":1580,"date":"2009-06-14T22:03:00","date_gmt":"2009-06-15T05:03:00","guid":{"rendered":"http:\/\/www.jinmei.org\/blog\/?p=1580"},"modified":"2009-06-15T11:18:09","modified_gmt":"2009-06-15T18:18:09","slug":"gcc-_unwind_backtrace%e3%81%ae%e8%ac%8e","status":"publish","type":"post","link":"https:\/\/www.jinmei.org\/blog\/2009\/06\/14\/1580","title":{"rendered":"gcc _Unwind_Backtrace()\u306e\u8b0e"},"content":{"rendered":"<p>\u3075\u3068\u601d\u3044\u7acb\u3061\u3001gcc\u306e\u79d8\u5bc6(?)\u95a2\u6570<code>_Unwind_Backtrace()<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u884c\u9014\u4e2d\u30d7\u30ed\u30bb\u30b9\u306ebacktrace\u3092\u53d6\u3063\u3066\u307f\u3088\u3046\u3068\u3057\u305f\u3089\u3001\u9a5a\u304f\u307b\u3069\u52d5\u304b\u305a\u3001\u5ef6\u3005\u3068\u8abf\u67fb\u3059\u308b\u306f\u3081\u306b\u3002\u7d50\u5c40\u308f\u304b\u3063\u305f\u3053\u3068\u306f\u4ee5\u4e0b:<\/p>\n<ul>\n<li>C++\u306e\u30b3\u30fc\u30c9\u306e\u4e2d\u304b\u3089\u4f7f\u3063\u305f\u5834\u5408\u306f(\u8a66\u3057\u305f\u7bc4\u56f2\u5185\u3067\u306f)\u3044\u3064\u3067\u3082\u52d5\u304f<\/li>\n<li>C\u306e\u30b3\u30fc\u30c9\u304b\u3089\u4f7f\u3063\u305f\u5834\u5408\u3001x86_64(amd64)\u3084IA64\u3067\u306f\u52d5\u304f\u304c\u3001x86(32\u30d3\u30c3\u30c8)\u3068\u304bsparc\u3067\u306f\u52d5\u304b\u306a\u3044\u3002\u307e\u305f\u3001\u3053\u308c\u3089\u306fOS\u306b\u3082\u4f9d\u5b58\u3057\u306a\u3044<\/li>\n<li>C\u306e\u5834\u5408\u3067\u3001x86_64\u3068x86\u306e\u9055\u3044\u306f\u3001ELF\u306e.eh_frame section\u5185\u306b\u5b9f\u884c\u30b3\u30fc\u30c9\u306eframe\u306b\u95a2\u3059\u308bcall frame information(CFI)\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3002\u542b\u307e\u308c\u3066\u3044\u308c\u3070\u52d5\u304f\u304c\u3001\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u52d5\u304b\u306a\u3044\u3002<\/li>\n<li>x86\u306b\u304a\u3051\u308bC++\u3068C\u306e\u5dee\u3082ELF\u306e.eh_frame section\u306e\u4e2d\u8eab\u306e\u9055\u3044<\/li>\n<li>.eh_frame section\u306b\u5fc5\u8981\u306a\u60c5\u5831\u304c\u306a\u304f\u3066\u3082\u3001.debug_frame section\u306b\u5b9f\u884c\u30b3\u30fc\u30c9\u306eCFI\u304c\u542b\u307e\u308c\u3066\u3044\u308c\u3070\u3001\u305d\u308c\u3092\u3061\u3087\u3063\u3068\u3044\u3058\u3063\u3066<code>__register_frame()<\/code>(\u3055\u3089\u306b\u79d8\u5bc6\u306a\u95a2\u6570\uff1f)\u3067\u767b\u9332\u3059\u308c\u3070\u52d5\u304f\u3088\u3046\u306b\u306a\u308b<\/li>\n<li>IA64\u306e\u5834\u5408\u306f\u4e0a\u8a18\u3068\u306f\u5225\u306a\u6271\u3044\u306b\u306a\u3063\u3066\u3044\u308b\u6a21\u69d8\u3002C\u3067\u3082C++\u3067\u3082\u3001\u305d\u3082\u305d\u3082.eh_frame section\u304c\u5b58\u5728\u3057\u306a\u3044\u304c<code>_Unwind_Backtrace()<\/code>\u306f\u3061\u3083\u3093\u3068\u52d5\u304f<\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.jinmei.org\/download\/unwindtest.c\">C\u3067\u52d5\u304b\u3059\u305f\u3081\u306e\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9<\/a>\u3082\u516c\u958b\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u4e07\u4e00\u3053\u306e\u30da\u30fc\u30b8\u3092\u8aad\u3093\u3060\u65b9\u304c\u3044\u3089\u3063\u3057\u3083\u3044\u307e\u3057\u305f\u3089\u3001(\u3068\u304f\u306bi386\u3084sparc\u4ee5\u5916\u3067)\u52d5\u3044\u305f\u3068\u304b\u52d5\u304b\u306a\u304b\u3063\u305f\u3068\u304b\u3054\u5831\u544a\u3044\u305f\u3060\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u3068\u3063\u3066\u3082\u9577\u3044\u8a73\u7d30\u3002<br \/>\n<!--more--><\/p>\n<h2><code>_Unwind_Backtrace()<\/code>\u306e\u4e0d\u601d\u8b70\u306a\u6319\u52d5<\/h2>\n<p>\u305f\u3068\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u8003\u3048\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\n#ifdef __cplusplus\r\nextern \"C\" {\r\n#endif\t\/* __cplusplus *\/\r\n#include &lt;stdio.h&gt;\r\n\r\nextern int _Unwind_Backtrace(int (*fn)(void *, void *), void *);\r\n\r\nstatic int count = 0;\r\n\r\nstatic int\r\nbtcallback(void *context, void *opq) {\r\n\tcount++;\r\n\treturn (0);\r\n}\r\n\r\nstatic void\r\nfoo() {\r\n\t_Unwind_Backtrace(btcallback, 0);\r\n\tprintf(\"callback counter: %d\\n\", count);\r\n}\r\n\r\nint main() {\r\n\tfoo();\r\n\treturn (0);\r\n}\r\n#ifdef __cplusplus\r\n}\r\n#endif\t\/* __cplusplus *\/\r\n<\/pre>\n<p><code>btcallback()<\/code>\u306f<code>foo()<\/code>\u3068<code>main()<\/code>\u3092\u542b\u3080call frame\u306e\u6570\u3060\u3051\u547c\u3070\u308c\u308b\u306e\u3067\u3001\u5c11\u306a\u304f\u3068\u30822\u56de\u306f\u547c\u3070\u308c\u308b\u306f\u305a\u3060\u304c\u3001x86\u306a\u30de\u30b7\u30f3\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u52d5\u304b\u3059\u3068\u305d\u3046\u306a\u3089\u306a\u3044\u3002<\/p>\n<pre class=\"codefrag\">\r\n% uname -m; .\/bt\r\ni386\r\ncallback counter: 1\r\n<\/pre>\n<p>\u4e00\u65b9\u3001\u540c\u3058\u30b3\u30fc\u30c9\u3092x86_64\u3068\u304bIA64\u3068\u304b\u306e\u4e0a\u3067\u8d70\u3089\u305b\u308b\u3068\u671f\u5f85\u901a\u308a\u306e\u7d50\u679c\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\n% uname -m; .\/bt\r\namd64\r\ncallback counter: 4\r\n<\/pre>\n<p>(\u306a\u304a\u30012\u3067\u306a\u304f\u30664\u306a\u306e\u306f<code>main()<\/code>\u3092\u547c\u3093\u3067\u3044\u308blibc\u5185\u306e\u30b3\u30fc\u30c9\u306e\u5206\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u305f\u3081)<\/p>\n<p>\u307e\u305f\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092C++\u3068\u3057\u3066\u3001\u3064\u307e\u308ag++\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u3068i386\u3067\u3082\u671f\u5f85\u901a\u308a\u52d5\u304f\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\n% g++ -o bt bt.c; uname -m; .\/bt\r\ni386\r\ncallback counter: 3\r\n<\/pre>\n<p>\u3053\u306e\u4e0d\u601d\u8b70\u306a\u73fe\u8c61\u306e\u89e3\u660e\u306b\u304b\u306a\u308a\u6642\u9593\u3092\u8981\u3057\u3066\u3057\u307e\u3063\u305f\u304c\u3001\u7d50\u5c40\u3001\u5b9f\u884c\u30d0\u30a4\u30ca\u30ea\u4e2d\u306b\u3069\u308c\u3060\u3051\u30b9\u30bf\u30c3\u30af\u30d5\u30ec\u30fc\u30e0\u306e\u60c5\u5831\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u306e\u9055\u3044\u3060\u3068\u3044\u3046\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3002\u4ee5\u4e0b\u3067\u306f\u304a\u3082\u306bFreeBSD 6.2(i386) + gcc 3.4.6\u3068FreeBSD7.0(amd64\/x86_64) + gcc 4.2.1\u3092\u4f8b\u306b\u8003\u3048\u308b\u304c\u3001\u8a66\u3057\u305f\u7bc4\u56f2\u3067\u306fLinux\u3084Solaris\u306b\u3082\u5f53\u3066\u306f\u307e\u308b(MacOS X\u3067\u3082\u304b\u306a\u308a\u306e\u90e8\u5206\u306f\u3042\u3066\u306f\u307e\u308b)\u3002\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u7684\u306b\u306fSparc(32bit)\u306b\u3082\u3042\u3066\u306f\u307e\u308b\u3002\u307e\u305f\u3001FreeBSD\u306e\u5834\u5408\u3001\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u306e\u5f62\u5f0f\u306fELF\u306a\u306e\u3067\u3001\u4ee5\u4e0b\u3067\u3082\u304a\u3082\u306bELF\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u4eee\u5b9a\u3059\u308b\u304c\u3001\u8a71\u306e\u672c\u8cea\u306f\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u306e\u5f62\u5f0f\u306b\u306f\u3088\u3089\u306a\u3044(\u5b9f\u969b\u305f\u3068\u3048\u3070\u3001MacOS X\u3067\u3082\u6210\u308a\u7acb\u3064\u90e8\u5206\u306f\u7d50\u69cb\u3042\u308b)\u3002<\/p>\n<p>gcc\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u500b\u6240\u3067\u306f\u304a\u3082\u306b<a href=\"http:\/\/gcc.gnu.org\/viewcvs\/tags\/gcc_3_4_6_release\/gcc\/\">gcc 3.4.6<\/a>\u3092\u7528\u3044\u308b\u304c\u3001\u3056\u3063\u3068\u898b\u305f\u611f\u3058\u3067\u306f\u3001gcc 4\u306e\u6bd4\u8f03\u7684\u6700\u8fd1\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3082\u542b\u3081\u3066\u5927\u4f53\u3069\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306egcc\u3067\u3082\u6210\u308a\u7acb\u3064\u3088\u3046\u3060\u3002<\/p>\n<h2><code>_Unwind_Backtrace()<\/code>\u306e\u52d5\u4f5c<\/h2>\n<p>\u591a\u304f\u306e\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u306b\u304a\u3044\u3066\u3001<code>_Unwind_Backtrace()<\/code>\u306f<a href=\"http:\/\/dwarfstd.org\/\">DWARF2<\/a>(\u3082\u3069\u304d)\u306ecall frame\u60c5\u5831\u3092\u983c\u308a\u306bbacktrace\u306b\u5fc5\u8981\u306a\u60c5\u5831\u3092\u751f\u6210\u3057\u3066\u3044\u308b\u3002\u305d\u306e\u51e6\u7406\u306e\u4e2d\u3067\u3082\u91cd\u8981\u306a\u306e\u304c\u3001<a href=\"http:\/\/gcc.gnu.org\/viewcvs\/tags\/gcc_3_4_6_release\/gcc\/unwind-dw2-fde.c?revision=111785&#038;view=markup\">unwinde-dw2-fde.c<\/a>\u306e\u4e2d\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b<code>_Unwind_Find_FDE()<\/code>\u3068\u3044\u3046\u95a2\u6570\u3002<\/p>\n<pre class=\"codefrag\">\r\nconst fde *\r\n_Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases)\r\n<\/pre>\n<p>\u3053\u306e\u95a2\u6570\u306f\u3001\u5b9f\u884c\u30d7\u30ed\u30bb\u30b9\u306e\u30b3\u30fc\u30c9\u5185\u306e\u4e0e\u3048\u3089\u308c\u305f\u4f4d\u7f6e\u3092\u6307\u3059\u30dd\u30a4\u30f3\u30bf(<code>pc<\/code>)\u3092\u542b\u3080DWARF2(\u3082\u3069\u304d)\u306eFrame Description Entry(FDE)\u3092\u63a2\u3057\u3001\u3042\u308c\u3070\u305d\u308c\u3078\u306e\u30dd\u30a4\u30f3\u30bf\u3092\u8fd4\u3059\u3002\u5404FDE\u306fC\u3067\u3044\u3048\u3070\u305d\u308c\u305e\u308c\u4e00\u3064\u306e\u95a2\u6570\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u3066\u3001\u305d\u306e\u95a2\u6570\u5185\u306e\u3069\u306e\u4f4d\u7f6e\u3067\u3069\u3093\u306a\u30ec\u30b8\u30b9\u30bf\u304c\u3069\u306e\u3088\u3046\u306b\u5909\u66f4\u3055\u308c\u3066\u3044\u308b\u304b\u3068\u3044\u3063\u305f\u60c5\u5831\u304c\u8a18\u9332\u3055\u308c\u3066\u3044\u308b\u3002gcc\u306e<code>_Unwind_Backtrace()<\/code>\u306f\u3001\u307e\u305a\u547c\u3073\u51fa\u3055\u308c\u305f\u4f4d\u7f6e\u304b\u3089\u306e\u623b\u308a\u30a2\u30c9\u30ec\u30b9\u3092builtin\u95a2\u6570\u306e<code>__builtin_return_address(0)<\/code>\u3067\u6c42\u3081\u3001\u305d\u308c\u3092<code>pc<\/code>\u3068\u3057\u3066<code>_Unwind_Find_FDE()<\/code>\u3092\u547c\u3093\u3067\u4e00\u3064\u4e0a\u306e\u30d5\u30ec\u30fc\u30e0\u306b\u5bfe\u5fdc\u3059\u308bFDE\u3092\u6c42\u3081\u3001\u305d\u306e\u60c5\u5831\u3092\u4f7f\u3063\u3066\u30ec\u30b8\u30b9\u30bf\u3092(\u4eee\u60f3\u7684\u306b)\u5fa9\u5143\u3057\u3066\u3055\u3089\u306b\u305d\u306e\u4e0a\u306e\u623b\u308a\u30a2\u30c9\u30ec\u30b9\u3092\u6c42\u3081\u2026\u3068\u3044\u3046\u65b9\u6cd5\u306b\u3088\u3063\u3066backtrace\u306b\u5fc5\u8981\u306a\u547c\u3073\u51fa\u3057\u30a2\u30c9\u30ec\u30b9\u306e\u5217\u3092\u751f\u6210\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u5b9f\u884c\u30b3\u30fc\u30c9\u306b\u5bfe\u3059\u308bFDE\u306f\u3001\u521d\u671f\u5316\u6642\u306b.init section\u306e<code>frame_dummy()<\/code>(<a href=\"http:\/\/gcc.gnu.org\/viewcvs\/tags\/gcc_3_4_6_release\/gcc\/crtstuff.c?revision=111785&#038;view=markup\">crtstuff.c<\/a>\u3067\u5b9a\u7fa9\u3055\u308c\u308b)\u7d4c\u7531\u3067\u3001unwinde-dw2-fde.c\u5185\u306e<code>__register_frame_info()<\/code>\u306b\u3088\u3063\u3066unwinde-dw2-fde.c local\u306astatic\u5909\u6570\u306b\u767b\u9332\u3055\u308c\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\nstatic void __attribute__((used))\r\nframe_dummy (void)\r\n{\r\n...\r\n  if (__register_frame_info)\r\n    __register_frame_info (__EH_FRAME_BEGIN__, &object);\r\n}\r\n<\/pre>\n<p><code>__EH_FRAME_BEGIN__<\/code>\u306e\u4e2d\u8eab\u307e\u3067\u306f\u8ffd\u3044\u304b\u3051\u3066\u306a\u3044\u304c\u3001\u540d\u524d\u304b\u3089\u3057\u3066\u3044\u304b\u306b\u3082ELF\u306e.eh_frame section\u3092\u6307\u3057\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u308b\u3057\u3001\u5b9f\u969b\u306b\u305d\u3046\u3067\u3042\u308b\u3053\u3068\u3082\u30c7\u30d0\u30c3\u30ac\u7d4c\u7531\u3067\u78ba\u8a8d\u3067\u304d\u308b:<\/p>\n<pre class=\"codefrag\">\r\n% gdb bt\r\nGNU gdb 6.1.1 [FreeBSD]\r\n...\r\n(gdb) b __register_frame_info\r\nBreakpoint 1 at 0x8049fa6\r\n(gdb) r\r\nStarting program: \/usr\/home\/jinmei\/tmp\/bt \r\n\r\nBreakpoint 1, 0x08049fa6 in __register_frame_info ()\r\n(gdb) c\r\nContinuing.\r\n\r\nBreakpoint 1, 0x08049fa6 in __register_frame_info ()\r\n(gdb) p ((void **)$ebp)[2]\r\n$1 = (void *) 0x804c318\r\n(gdb) q\r\nThe program is running.  Exit anyway? (y or n) y\r\n\r\n% readelf -S bt | grep .eh_frame\r\n  [12] .eh_frame         PROGBITS        0804c318 003318 0003c8 00   A  0   0  4\r\n<\/pre>\n<p>\u3064\u307e\u308a\u3001<code>__register_frame_info()<\/code>\u3078\u306e\u6700\u521d\u306e\u5f15\u6570\u306f0x804c318\u3067\u3001\u3053\u308c\u306f\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u5185\u306e.eh_frame section\u3078\u306eoffset\u306b\u7b49\u3057\u3044(\u306a\u304a\u3001\u4e0a\u306e\u4f8b\u304c\u793a\u3059\u3088\u3046\u306b\u3001<code>__register_frame_info()<\/code>\u306f\u8907\u6570\u56de\u547c\u3070\u308c\u308b\u5834\u5408\u304c\u3042\u308b\u3002<code>frame_dummy()<\/code>\u304b\u3089\u547c\u3070\u308c\u305f\u3068\u304d\u306e\u5024\u3092\u8abf\u3079\u308b\u5fc5\u8981\u304c\u3042\u308b)\u3002<\/p>\n<h2><code>_Unwind_Backtrace()<\/code>\u306fC\u3067\u306f\u306a\u305c\u52d5\u304b\u306a\u3044\u304b<\/h2>\n<p>\u3068\u3044\u3046\u3068\u3053\u308d\u307e\u3067\u308f\u304b\u308b\u3068\u3001.eh_frame section\u5185\u306e\u9055\u3044\u304c<code>_Unwind_Backtrace()<\/code>\u306e\u6319\u52d5\u306e\u9055\u3044\u306e\u539f\u56e0\u3060\u308d\u3046\u3068\u3044\u3046\u4e88\u6e2c\u304c\u7acb\u3064\u3002\u5b9f\u969b\u306b\u8abf\u3079\u3066\u307f\u308b\u3068\u305d\u306e\u901a\u308a\u3060\u3068\u3044\u3046\u3053\u3068\u304c\u308f\u304b\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\n% readelf --debug-dump=frames bt\r\nThe section .eh_frame contains:\r\n...\r\n00000014 00000018 00000018 FDE cie=00000000 pc=08048968..0804898c\r\n...\r\n00000398 00000028 0000039c FDE cie=00000000 pc=0804ad04..0804ae58\r\n...\r\nThe section .debug_frame contains:\r\n...\r\n0000002c 00000018 00000000 FDE cie=00000000 pc=080486bc..080486ec\r\n...\r\n00000048 00000014 00000000 FDE cie=00000000 pc=080486ec..08048714\r\n<\/pre>\n<p>\u5404FDE\u306e\u884c\u306b\u304a\u3044\u3066\u3001<code>pc<\/code>\u304c\u305d\u306e\u30d5\u30ec\u30fc\u30e0\u306b\u5bfe\u5fdc\u3059\u308b\u30b3\u30fc\u30c9(\u95a2\u6570)\u306e\u30a2\u30c9\u30ec\u30b9\u306e\u7bc4\u56f2\u3092\u6307\u3057\u3066\u3044\u308b\u3002.eh_frame section\u306b\u306f\u4ed6\u306b\u3082\u591a\u6570\u306eFDE\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304c\u3001\u3053\u308c\u3089\u306f<code>pc<\/code>\u306b\u95a2\u3057\u3066\u3059\u3067\u306b\u30bd\u30fc\u30c8(\u6607\u9806)\u3055\u308c\u3066\u3044\u308b\u3002\u3053\u308c\u3089\u304c\u305d\u308c\u305e\u308c\u4f55\u3092\u6307\u3057\u3066\u3044\u308b\u304b\u8abf\u3079\u308b\u3068\u3001<\/p>\n<pre class=\"codefrag\">\r\n% nm -n bt\r\n...\r\n080486ac t btcallback\r\n080486bc t foo\r\n080486ec T main\r\n08048714 T _Unwind_GetTextRelBase\r\n...\r\n08048968 T _Unwind_FindEnclosingFunction\r\n  (\u6ce8: \u3053\u308c\u304c.eh_frame\u5185\u306e\u6700\u521d\u306eFDE)\r\n0804898c t execute_stack_op\r\n...\r\n0804a7cc t search_object\r\n0804ad04 T _Unwind_Find_FDE\r\n  (\u6ce8: \u3053\u308c\u304c.eh_frame\u5185\u306e\u6700\u5f8c\u306eFDE)\r\n<\/pre>\n<p>\u3068\u3044\u3046\u308f\u3051\u3067\u3001\u672c\u4f53\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u5b9a\u7fa9\u3055\u308c\u305f\u95a2\u6570\u306b\u5bfe\u5fdc\u3059\u308bFDE\u306f.eh_frame section\u5185\u306b\u306f\u5b58\u5728\u3057\u306a\u3044\u3053\u3068\u304c\u308f\u304b\u308b\u3002<\/p>\n<p>\u3053\u308c\u306b\u5bfe\u3057\u3001C++\u3068\u3057\u3066\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u7d50\u679c\u306e\u30d0\u30a4\u30ca\u30ea\u306b\u542b\u307e\u308c\u308b.eh_frame section\u306b\u306f<code>main()<\/code>\u3068<code>foo()<\/code>\u306b\u5bfe\u5fdc\u3059\u308bFDE\u3082\u542b\u307e\u308c\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\n% g++ -g -o bt bt.c   \r\n\r\n% readelf --debug-dump=frames bt|grep FDE\r\n0000001c 00000018 00000020 FDE cie=00000000 pc=080485d0..08048600\r\n00000038 00000018 0000003c FDE cie=00000000 pc=08048600..08048628\r\n00000014 00000014 00000000 FDE cie=00000000 pc=080485c0..080485d0\r\n(\u3053\u3053\u307e\u3067.eh_frame section\u306eFDE)\r\n0000002c 00000018 00000000 FDE cie=00000000 pc=080485d0..08048600\r\n00000048 00000014 00000000 FDE cie=00000000 pc=08048600..08048628\r\n\r\n% nm -n bt| egrep (main|foo)\r\n080485d0 t foo  [.eh_frame\u306e\u6700\u521d\u306eFDE]\r\n08048600 T main [.eh_frame\u306e2\u756a\u76ee\u306eFDE]\r\n<\/pre>\n<p>\u307e\u305f\u3001amd64\u306eC\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u7d50\u679c\u306e\u30d0\u30a4\u30ca\u30ea\u3067\u3082\u3001.eh_frame section\u306b\u5fc5\u8981\u306aFDE\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\n% cc -g -o bt bt.c\r\n\r\n% readelf --debug-dump=frames bt|grep FDE\r\n00000018 0000001c 0000001c FDE cie=00000000 pc=004004f0..00400583\r\n00000038 00000014 0000003c FDE cie=00000000 pc=00400590..004005c8\r\n00000050 00000014 00000054 FDE cie=00000000 pc=004005d0..004005f2\r\n00000068 0000001c 0000006c FDE cie=00000000 pc=00400600..00400622\r\n00000088 0000001c 0000008c FDE cie=00000000 pc=00400630..0040065a\r\n000000a8 0000001c 000000ac FDE cie=00000000 pc=00400660..00400675\r\n(\u3053\u3053\u307e\u3067.eh_frame section\u306eFDE)\r\n00000018 0000001c 00000000 FDE cie=00000000 pc=00400600..00400622\r\n00000038 0000001c 00000000 FDE cie=00000000 pc=00400630..0040065a\r\n00000058 0000001c 00000000 FDE cie=00000000 pc=00400660..00400675\r\n\r\n% nm -n bt | egrep (main|foo)\r\n0000000000400630 t foo  [.eh_frame\u306e\u6700\u5f8c\u304b\u30892\u3064\u3081\u306eFDE]\r\n0000000000400660 T main [.eh_frame\u306e\u6700\u5f8c\u306eFDE]\r\n<\/pre>\n<h2><code>_Unwind_Backtrace()<\/code>\u3092C\u3067\u7121\u7406\u3084\u308a\u52d5\u304b\u3059\u305f\u3081\u306e\u30cf\u30c3\u30af<\/h2>\n<p>.eh_frame\u306eeh = exception handling\u3067\u3001\u3053\u308c\u306f\u672c\u6765\u306fC++(\u7b49)\u306e\u4f8b\u5916\u51e6\u7406\u306b\u304a\u3051\u308b\u30b9\u30bf\u30c3\u30af\u5dfb\u623b\u3057\u64cd\u4f5c\u306e\u305f\u3081\u306e\u60c5\u5831\u306e\u3088\u3046\u306a\u306e\u3067\u3001\u8a00\u8a9e\u3068\u3057\u3066\u4f8b\u5916\u306e\u4ed5\u7d44\u307f\u3092\u6301\u305f\u306a\u3044C\u306e\u5834\u5408\u306b\u3053\u306esection\u306e\u4e2d\u8eab\u304c\u4e0d\u5341\u5206\u306a\u306e\u306f\u4ed5\u65b9\u306a\u3044\u3068\u3082\u3044\u3048\u308b(\u306a\u305camd64\u306e\u5834\u5408\u306b\u306fC\u3067\u3082\u3053\u308c\u304c\u751f\u6210\u3055\u308c\u308b\u306e\u304b\u306f\u4e0d\u660e)\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u3055\u3089\u306b\u3088\u304f\u8abf\u3079\u308b\u3068\u3001(\u4e0a\u306e\u4f8b\u3067\u3082\u308f\u304b\u308b\u3088\u3046\u306b)\u307b\u307c\u540c\u7a2e\u304b\u3064\u5fc5\u8981\u306a\u60c5\u5831\u304c.debug_frame\u3068\u3044\u3046section(\u3042\u308c\u3070)\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u3002\u304b\u3064\u3001<code>__register_frame_info()<\/code>\u81ea\u4f53\u306f\u3069\u3053\u304b\u3089\u3067\u3082\u547c\u3079\u308bglobal\u95a2\u6570\u3067\u3001\u5b9f\u88c5\u3092\u898b\u308b\u3068\u5b9f\u884c\u9014\u4e2d\u306bframe\u60c5\u5831\u3092\u8db3\u3057\u3066\u3082\u3046\u307e\u304f\u52d5\u304d\u305d\u3046\u3002\u305d\u3053\u3067\u3001<code>_Unwind_Backtrace()<\/code>\u3092\u4f7f\u3063\u3066\u3044\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u81ea\u8eab\u3067\u81ea\u5206\u306eELF\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u89e3\u6790\u3057\u3066\u3001.debug_frame section\u306e\u4e2d\u8eab\u3092\u6307\u3059\u30dd\u30a4\u30f3\u30bf\u3092<code>__register_frame_info()<\/code>\u3067\u5f8c\u304b\u3089\u6e21\u305b\u3070C\u306e\u30b3\u30fc\u30c9\u304b\u3089\u3067\u3082\u6b63\u3057\u304fbacktrace\u304c\u53d6\u308c\u305d\u3046\u306a\u6c17\u304c\u3057\u3066\u304f\u308b\u3002<\/p>\n<p>\u3067\u3001\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u308b\u3068\u3001\u4e0a\u8a18\u306e\u5358\u7d14\u306a\u65b9\u6cd5\u3067\u306f\u3046\u307e\u304f\u3044\u304b\u306a\u3044\u3002\u3053\u308c\u306f\u3001gcc\u306eunwinde-dw2-fde.c\u304c\u671f\u5f85\u3057\u3066\u3044\u308bFDE\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u304cDWARF2\u3067\u306e\u5b9a\u7fa9(.debug_frame section\u306f\u3053\u3061\u3089\u306b\u6e96\u62e0)\u3068\u5fae\u5999\u306b\u305a\u308c\u3066\u3044\u308b\u305f\u3081(\u308f\u3056\u3068\u306a\u306e\u304b\u30d0\u30b0\u306a\u306e\u304b\u306f\u308f\u304b\u3089\u306a\u3044\u304c\u2026)\u3002\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u90e8\u5206\u304c\u9055\u3063\u3066\u3044\u308b\u3002<\/p>\n<ul>\n<li>CIE (Common Information Entry, \u3042\u308b\u4e00\u9023\u306eFDE\u306e\u30bb\u30c3\u30c8\u306b\u5171\u901a\u3059\u308b\u30eb\u30fc\u30eb\u3092\u6307\u5b9a\u3059\u308b\u7279\u5225\u306a\u30a8\u30f3\u30c8\u30ea\u3002.eh_frame\u3068.debug_frame section\u306f\u3001\u300cCIE 1\u3064\u3001\u305d\u308c\u306b\u7d9a\u304f0\u500b\u4ee5\u4e0a\u306eFDE\u300d\u306e\u30bb\u30c3\u30c8\u304b\u3089\u69cb\u6210\u3055\u308c\u3066\u3044\u308b)\u3092\u793a\u3059ID\u304c\u3001.eh_frame section\u3067\u306f0x00000000\u306a\u306e\u306b\u5bfe\u3057\u3001DWARF2\u4ed5\u69d8\u3067\u306f0xffffffff\u3067\u3042\u308b<\/li>\n<li>FDE\u306eCIE_pointer field(\u305d\u306eFDE\u304c\u5c5e\u3059\u308bCIE\u306e\u4f4d\u7f6e\u3092\u793a\u3059)\u306e\u5024\u304c\u3001.eh_frame section\u3067\u306f\u305d\u306eFDE\u306e\u5148\u982d\u304b\u3089\u306e(\u9006)offset\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u306b\u5bfe\u3057\u3001DWARF2\u4ed5\u69d8\u3067\u306fsection\u306e\u5148\u982d\u304b\u3089CIE\u307e\u3067\u306eoffset\u306b\u306a\u3063\u3066\u3044\u308b<\/li>\n<li>unwinde-dw2-fde.c\u306f\u3001CIE+FDE\u306e\u5217\u306e\u6700\u5f8c\u306b0x00000000\u3068\u3044\u30464\u30d0\u30a4\u30c8\u304b\u3089\u6210\u308b\u7d42\u7aef\u5b50\u304c\u3042\u308b\u3053\u3068\u3092\u671f\u5f85\u3057\u3066\u3044\u308b<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001.debug_frame section\u306e\u4e2d\u8eab\u306b\u5bfe\u3057\u3066\u3001\u4e0a\u306e\u5dee\u5206\u3092\u57cb\u3081\u308b\u4fee\u6b63\u3092\u3057\u305f\u4e0a\u3067<code>__register_frame_info()<\/code>\u306b\u6e21\u3059\u3068\u3088\u3046\u3084\u304f\u52d5\u304f\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<h2>\u691c\u8a3c\u30b3\u30fc\u30c9<\/h2>\n<p>\u4ee5\u4e0a\u3067\u8abf\u3079\u305f\u5185\u5bb9\u3092\u691c\u8a3c\u3059\u308b\u305f\u3081\u306e\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u307f\u305f\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f<a href=\"http:\/\/www.jinmei.org\/download\/unwindtest.c\">\u3053\u3053<\/a>\u306b\u516c\u958b\u3057\u3066\u3044\u308b\u3002\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0(\u4ee5\u4e0b&#8221;unwindtest&#8221;\u3068\u547c\u3076)\u306f\u3001<code>main()<\/code>\u2192<code>foo()<\/code>\u2192<code>bar()<\/code>\u306e\u3088\u3046\u306b\u547c\u3073\u51fa\u3057\u305f\u5f8c\u3001<code>_Unwind_Backtrace()<\/code>\u3067\u3053\u308c\u3089\u306e\u547c\u3073\u51fa\u3057\u5730\u70b9\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97\u3057\u3001\u5404\u30a2\u30c9\u30ec\u30b9\u304c\u8a72\u5f53\u3059\u308b\u95a2\u6570\u306e\u5148\u982d\u30a2\u30c9\u30ec\u30b9\u304b\u3089\u4e00\u5b9a\u306e\u7bc4\u56f2\u5185(256\u30d0\u30a4\u30c8)\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u308b\u3053\u3068\u3067\u3001<code>_Unwind_Backtrace()<\/code>\u306e\u52d5\u4f5c\u3092\u691c\u8a3c\u3057\u3066\u3044\u308b(256\u30d0\u30a4\u30c8\u3068\u3044\u3046\u306e\u306f\u300c\u307b\u3069\u307b\u3069\u306b\u5c0f\u3055\u3044\u300d\u5024\u3068\u3044\u3046\u3053\u3068\u3067\u9069\u5f53\u306b\u9078\u3093\u3060)\u3002<\/p>\n<p>\u3055\u3089\u306b<code>-e<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u308b\u3068\u3001\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u540d(<code>argv[0]<\/code>)\u306e\u4e2d\u8eab\u3092ELF\u3060\u3068\u4eee\u5b9a\u3057\u3066\u8abf\u3079\u3001.debug_frame section\u304c\u3042\u308c\u3070\u305d\u306e\u4e2d\u8eab\u3092\u4e0a\u8a18\u306e\u65b9\u6cd5\u306b\u3088\u3063\u3066gcc\u304c\u671f\u5f85\u3059\u308b\u5f62\u5f0f\u306b\u76f4\u3057\u305f\u4e0a\u3067<code>__register_frame_info()<\/code>\u3092\u4f7f\u3063\u3066\u767b\u9332\u3057\u3001\u305d\u306e\u5f8c\u306b<code>_Unwind_Backtrace()<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3002(\u306a\u304a\u3001ELF\u306e\u4e2d\u8eab\u3092\u8abf\u3079\u308b\u30b3\u30fc\u30c9\u3067\u306fvalidity check\u3092\u304b\u306a\u308a\u3055\u307c\u3063\u3066\u3044\u308b\u3002\u3088\u3044\u5b50\u306f(\u305d\u306e\u307e\u307e)\u30de\u30cd\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044)<\/p>\n<p>i386\u5834\u306eFreeBSD\u3067\u52d5\u304b\u3059\u3068\u3053\u3093\u306a\u611f\u3058:<\/p>\n<pre class=\"codefrag\">\r\n% cc -g -o unwindtest unwindtest.c\r\n\r\n% .\/unwindtest \r\n[1]    6372 exit 1     .\/unwindtest\r\n\r\n% .\/unwindtest -e\r\nframe[0] 0x8048e72: entrance pt=0x8048e44, diff=46\r\nframe[1] 0x8048f23: entrance pt=0x8048f18, diff=11\r\nframe[2] 0x8048f5a: entrance pt=0x8048f28, diff=50\r\n\r\n% nm unwindtest | egrep (main|foo|bar)\r\n08048e44 t bar\r\n08048f18 t foo\r\n08048f28 T main\r\n<\/pre>\n<p>i386\u306a\u306e\u3067\u3001\u4f55\u3082\u6307\u5b9a\u305b\u305a\u306b\u5b9f\u884c\u3059\u308b\u3068\u5931\u6557\u3059\u308b\u3002\u4e00\u65b9\u3001<code>-e<\/code>\u3092\u4ed8\u3051\u308b\u3068\u6b63\u3057\u3044backtrace\u304c\u53d6\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308b\u3002<\/p>\n<p>\u624b\u5143\u3067\u4f7f\u3048\u308b\u74b0\u5883\u3067\u8a66\u3057\u305f\u3068\u3053\u308d\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u74b0\u5883\u3067<code>_Unwind_Backtrace()<\/code>\u304c\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u305f:<\/p>\n<ul>\n<li>FreeBSD (amd64, i386, ia64)<\/li>\n<li>Linux (x86_64, i386)<\/li>\n<li>Solaris 10 (x86_64-\u305f\u3060\u3057gcc\u306f32bit\u7248, sparc)<\/li>\n<\/ul>\n<p>\u306a\u304a\u3001x86_64\/amd64\u3068ia64\u306e\u5834\u5408\u306f<code>-e<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u306a\u3057\u3067\u3082\u52d5\u304f\u3002(\u3068\u3044\u3046\u304b\u3001ia64\u3067\u306f\u3053\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3059\u308b\u3068 .debug_frame section\u304c\u306a\u3044\u305f\u3081\u306b\u52d5\u4f5c\u3057\u306a\u3044)<\/p>\n<p>Mac OS X\u306e\u5834\u5408\u3001\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u5f62\u5f0f\u304cELF\u3067\u306a\u3044\u306e\u3067\u52d5\u304b\u306a\u3044\u2026\u3068\u3044\u3046\u304b\u3001\u5fc5\u8981\u306a\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb\u304c\u306a\u3044\u306e\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3082\u901a\u3089\u306a\u3044\u3002\u305f\u3060\u3057\u3001<code>_Unwind_Backtrace()<\/code>\u306e\u5b9f\u88c5\u81ea\u4f53\u306f\u4ed6\u306eOS\u3068\u540c\u3058\u3082\u306e\u3092\u4f7f\u3063\u3066\u3044\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u5b9f\u884c\u30d0\u30a4\u30ca\u30ea\u3092\u89e3\u6790\u3057\u3066DWARF2\u306eframe\u60c5\u5831\u3092\u751f\u6210\u3057\u3001<code>__register_frame_info()<\/code>\u3067\u767b\u9332\u3059\u308b\u3068\u3044\u3046\u3068\u3053\u308d\u307e\u3067\u3084\u308c\u3070\u52d5\u304d\u305d\u3046\u306a\u6c17\u306f\u3059\u308b\u3002<\/p>\n<p>\u306a\u304a\u3001\u30b3\u30f3\u30d1\u30a4\u30e9\u306eoptimization\u3092\u6709\u52b9\u306b\u3059\u308b\u3068\u3001\u95a2\u6570\u547c\u3073\u51fa\u3057\u304cinline\u5316\u3055\u308c\u3066\u3001\u691c\u8a3c\u30b3\u30fc\u30c9\u304c\u671f\u5f85\u3057\u3066\u3044\u308b\u30c1\u30a7\u30c3\u30af\u3092\u901a\u3089\u306a\u304f\u306a\u308b\u5834\u5408\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f:<\/p>\n<pre class=\"codefrag\">\r\n% cc -g -O2 -o unwindtest unwindtest.c\r\n\r\n% .\/unwindtest -e\r\nframe[0] 0x8048c72: entrance pt=0x8048a20, diff=594\r\nframe[1] 0x80487aa: entrance pt=0x8048acc, diff=-802\r\n[1]    6415 exit 2     .\/unwindtest -e\r\n<\/pre>\n<p>(\u305f\u3060\u3057\u3053\u308c\u306f<code>_Unwind_Backtrace()<\/code>\u81ea\u4f53\u304c\u5931\u6557\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u3044)<\/p>\n<p>\u307e\u305f\u3001\u4e0a\u306e\u4f8b\u3067\u306f-g\u4ed8\u304d\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u3044\u308b\u304c\u3001\u3053\u308c\u3082\u91cd\u8981\u3067\u3001-g\u304c\u306a\u3044\u3068.debug_frame section\u304c\u751f\u6210\u3055\u308c\u305a\u306b\u30c6\u30b9\u30c8\u306b\u5931\u6557\u3057\u305f\u308a\u3001\u751f\u6210\u3055\u308c\u3066\u3044\u3066\u3082OS\u306b\u3088\u3063\u3066\u306f\u306a\u305c\u304b\u3046\u307e\u304f\u52d5\u304b\u306a\u304b\u3063\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3042\u3063\u305f(\u5f8c\u8005\u306e\u7406\u7531\u306f\u8abf\u3079\u3066\u306a\u3044)<\/p>\n<pre class=\"codefrag\">\r\n% cc -o unwindtest unwindtest.c \r\n\r\n% .\/unwindtest -e\r\n.debug_frame section not found\r\n[1]    6399 exit 1     .\/unwindtest -e\r\n\r\n% readelf -S unwindtest | grep frame\r\n  [13] .eh_frame         PROGBITS        0804c018 004018 0003c8 00   A  0   0  4\r\n<\/pre>\n<p>\u540c\u69d8\u306b\u3001strip(1)\u3067\u30c0\u30a4\u30a8\u30c3\u30c8\u3055\u305b\u308b\u3068.debug_frame section\u3082\u6d88\u3048\u3066\u3057\u307e\u3063\u3066\u52d5\u304b\u306a\u304f\u306a\u308b\u3053\u3068\u304c\u591a\u3044\u3088\u3046\u3060\u3002<\/p>\n<pre class=\"codefrag\">\r\n% cc -g -o unwindtest unwindtest.c   \r\n\r\n% strip unwindtest\r\n\r\n% .\/unwindtest -e\r\n.debug_frame section not found\r\n[1]    6424 exit 1     .\/unwindtest -e\r\n<\/pre>\n<h2>IA64\u306e\u5834\u5408<\/h2>\n<p>\u4e0a\u3067\u8ff0\u3079\u305f\u3088\u3046\u306b\u3001IA64\u306e\u5834\u5408\u306fC\u3067\u3082\u7279\u5225\u306a\u30cf\u30c3\u30af\u306a\u3057\u306b<code>_Unwind_Backtrace()<\/code>\u304c\u52d5\u304f\u306e\u3060\u304c\u3001\u3053\u308c\u306f\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u81ea\u4f53\u304c\u9055\u3046\u304b\u3089\u306e\u3088\u3046\u3060\u3002<\/p>\n<p>\u5b9f\u969b\u3001<a href=\"http:\/\/gcc.gnu.org\/viewcvs\/tags\/gcc_3_4_6_release\/gcc\/config\/ia64\/unwind-ia64.c?revision=111785&#038;view=markup\">unwind-ia64.c<\/a>\u3068\u304b\u3044\u3046\u540d\u524d\u306e\u602a\u3057\u3052\u306a\u30bd\u30fc\u30b9\u304c\u3042\u308b\u3057\u3001DWARF2(\u3082\u3069\u304d)\u30d9\u30fc\u30b9\u306e\u4ed6\u306e\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u5834\u5408\u3068\u9055\u3063\u3066(\u5c11\u306a\u304f\u3068\u3082FreeBSD 7\u3067\u306f)\u5b9f\u884c\u30d0\u30a4\u30ca\u30ea\u3092\u898b\u3066\u3082\u305d\u3082\u305d\u3082 .eh_frame section \u3059\u3089\u5b58\u5728\u3057\u306a\u3044:<\/p>\n<pre class=\"codefrag\">\r\n% readelf -S unwindtest | grep frame | wc -l\r\n       0\r\n<\/pre>\n<p>\u3057\u3001<code>__register_frame_info()<\/code>\u307f\u305f\u3044\u306a\u30b0\u30ed\u30fc\u30d0\u30eb\u95a2\u6570\u3082\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u3060\u3002<\/p>\n<p>\u3053\u308c\u4ee5\u4e0a\u306f\u7a76\u660e\u3057\u3066\u306a\u3044\u3051\u3069\u3001\u3044\u307e\u306e\u3068\u3053\u308d\u305d\u3093\u306a\u306b\u983b\u7e41\u306b\u4f7f\u3046\u5fc5\u8981\u306e\u3042\u308b\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3058\u3083\u306a\u3044\u306e\u3067\u3053\u308c\u3067\u3044\u3044\u3053\u3068\u306b\u3057\u3088\u3046\u2026<\/p>\n<h2>\u304a\u307e\u3051: IA64\u306e\u95a2\u6570\u30dd\u30a4\u30f3\u30bf<\/h2>\n<p>\u672c\u984c\u3068\u306f\u95a2\u4fc2\u306a\u3044\u304a\u307e\u3051\u3002\u4e0a\u8a18\u306e\u691c\u8a3c\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u308d\u3044\u308d\u8a66\u3057\u3066\u3044\u305f\u3089\u3001IA64\u306e\u5834\u5408\u3060\u3051\u306a\u305c\u304boffset\u304c\u6975\u7aef\u306b\u305a\u308c\u3066\u3057\u307e\u3046(\u3088\u3046\u306b\u898b\u3048\u308b)\u3068\u3044\u3046\u73fe\u8c61\u306b\u906d\u9047\u3057\u305f:<\/p>\n<pre class=\"codefrag\">\r\nframe[0] 0x2000000000002510: entrance pt=0x2000000000002c50, diff=-1856\r\nframe[1] 0x2000000000002890: entrance pt=0x2000000000002c60, diff=-976\r\nframe[2] 0x2000000000002940: entrance pt=0x2000000000002c20, diff=-736\r\n[1]    13159 exit 2     .\/unwindtest1\r\n<\/pre>\n<p>\u304b\u306a\u308a\u60a9\u3093\u3060\u6319\u3052\u53e5\u3001\u5b9f\u306fIA64\u3067\u306f\u95a2\u6570\u30dd\u30a4\u30f3\u30bf\u81ea\u4f53\u306f\u305d\u306e\u95a2\u6570\u306e\u30b3\u30fc\u30c9\u3078\u306e\u30a8\u30f3\u30c8\u30ea\u30dd\u30a4\u30f3\u30c8\u3092\u76f4\u63a5\u6307\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u304c\u5224\u660e\u3057\u305f\u3002\u30a4\u30f3\u30c6\u30eb\u306e<a href=\"http:\/\/download.intel.com\/jp\/developer\/jpdoc\/24535801_j.pdf\">\u300cIA-64\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u898f\u5247\u304a\u3088\u3073\u30e9\u30f3\u30bf\u30a4\u30e0\u30fb\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u30fb\u30ac\u30a4\u30c9\u300d<\/a>51\u30da\u30fc\u30b8\u3088\u308a:<\/p>\n<blockquote><p>\n  \u95a2\u6570\u30dd\u30a4\u30f3\u30bf: \u95a2\u6570\u30dd\u30a4\u30f3\u30bf\u306f\u3001\u5e38\u306b\u30bf\u30fc\u30b2\u30c3\u30c8\u30fb\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u95a2\u6570\u8a18\u8ff0\u5b50\u306e\u30a2\u30c9\u30ec\u30b9\u3067\u3042\u308b\u3002&#8230;\u95a2\u6570\u8a18\u8ff0\u5b50\u306b\u306f\u3001\u5c11\u306a\u304f\u3068\u30822\u3064\u306e64\u30d3\u30c3\u30c8\u30fb\u30c0\u30d6\u30eb\u30ef\u30fc\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3002 \u7b2c1\u306e\u30c0\u30d6\u30eb\u30ef\u30fc\u30c9\u306f\u5165\u53e3\u70b9\u306e\u30a2\u30c9\u30ec\u30b9\u3067\u3042\u308a\u3001\u7b2c2\u306e\u30c0\u30d6\u30eb\u30ef\u30fc\u30c9\u306f\u30bf\u30fc\u30b2\u30c3\u30c8\u30fb\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306egp\u5024\u3067\u3042\u308b\u3002\n<\/p><\/blockquote>\n<p>\u691c\u8a3c\u30b3\u30fc\u30c9\u306f\u3001\u57fa\u672c\u7684\u306b<code>_Unwind_Backtrace()<\/code>\u7d4c\u7531\u3067\u5f97\u3089\u308c\u305f\u30b3\u30fc\u30c9\u5185\u306e\u30a2\u30c9\u30ec\u30b9\u3068\u3001\u305d\u308c\u3092\u542b\u3093\u3067\u3044\u308b\u306f\u305a\u306e\u95a2\u6570\u30dd\u30a4\u30f3\u30bf\u306e\u5024\u306e\u5dee\u5206\u3092\u6bd4\u8f03\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u306f\u5f53\u7136\u3046\u307e\u304f\u52d5\u304b\u306a\u3044\u3002\u3064\u307e\u308a\u3001<code>foo()<\/code>\u3068\u3044\u3046\u95a2\u6570\u304c\u3042\u3063\u305f\u3068\u304d\u3001<code>(void *)foo<\/code>\u3067\u306f\u306a\u304f\u3001<code>((void **)foo)[0]<\/code>\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<p>\u77e5\u3063\u3066\u308b\u4eba\u306b\u306f\u5f53\u305f\u308a\u524d\u306e\u8a71\u306a\u3093\u3060\u308d\u3046\u3051\u3069\u3001\u306f\u3058\u3081\u3066\u4f53\u9a13\u3057\u305f\u4eba\u9593\u306b\u306f\u304b\u306a\u308a\u65b0\u9bae\u3060\u3063\u305f\u306e\u3067\u4e00\u5fdc\u30e1\u30e2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3075\u3068\u601d\u3044\u7acb\u3061\u3001gcc\u306e\u79d8\u5bc6(?)\u95a2\u6570_Unwind_Backtrace()\u3092\u4f7f\u3063\u3066\u5b9f\u884c\u9014\u4e2d\u30d7\u30ed\u30bb\u30b9\u306ebacktrace\u3092\u53d6\u3063\u3066\u307f\u3088\u3046\u3068\u3057\u305f\u3089\u3001\u9a5a\u304f\u307b\u3069\u52d5\u304b\u305a\u3001\u5ef6\u3005\u3068\u8abf\u67fb\u3059\u308b\u306f\u3081\u306b\u3002\u7d50\u5c40\u308f\u304b\u3063\u305f\u3053\u3068\u306f\u4ee5\u4e0b: C++\u306e\u30b3\u30fc\u30c9\u306e\u4e2d\u304b\u3089\u4f7f\u3063\u305f\u5834\u5408\u306f(\u8a66\u3057\u305f\u7bc4\u56f2\u5185\u3067\u306f)\u3044\u3064\u3067\u3082\u52d5\u304f C\u306e\u30b3\u30fc\u30c9\u304b\u3089\u4f7f\u3063\u305f\u5834\u5408\u3001x86_64(amd64)\u3084IA64\u3067\u306f\u52d5\u304f\u304c\u3001x86(32\u30d3\u30c3\u30c8)\u3068\u304bsparc\u3067\u306f\u52d5\u304b\u306a\u3044\u3002\u307e\u305f\u3001\u3053\u308c\u3089\u306fOS\u306b\u3082\u4f9d\u5b58\u3057\u306a\u3044 C\u306e\u5834\u5408\u3067\u3001x86_64\u3068x86\u306e\u9055\u3044\u306f\u3001ELF\u306e.eh_frame section\u5185\u306b\u5b9f\u884c\u30b3\u30fc\u30c9\u306eframe\u306b\u95a2\u3059\u308bcall frame information(CFI)\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3002\u542b\u307e\u308c\u3066\u3044\u308c\u3070\u52d5\u304f\u304c\u3001\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u52d5\u304b\u306a\u3044\u3002 x86\u306b\u304a\u3051\u308bC++\u3068C\u306e\u5dee\u3082ELF\u306e.eh_frame section\u306e\u4e2d\u8eab\u306e\u9055\u3044 .eh_frame section\u306b\u5fc5\u8981\u306a\u60c5\u5831\u304c\u306a\u304f\u3066\u3082\u3001.debug_frame section\u306b\u5b9f\u884c\u30b3\u30fc\u30c9\u306eCFI\u304c\u542b\u307e\u308c\u3066\u3044\u308c\u3070\u3001\u305d\u308c\u3092\u3061\u3087\u3063\u3068\u3044\u3058\u3063\u3066__register_frame()(\u3055\u3089\u306b\u79d8\u5bc6\u306a\u95a2\u6570\uff1f)\u3067\u767b\u9332\u3059\u308c\u3070\u52d5\u304f\u3088\u3046\u306b\u306a\u308b IA64\u306e\u5834\u5408\u306f\u4e0a\u8a18\u3068\u306f\u5225\u306a\u6271\u3044\u306b\u306a\u3063\u3066\u3044\u308b\u6a21\u69d8\u3002C\u3067\u3082C++\u3067\u3082\u3001\u305d\u3082\u305d\u3082.eh_frame section\u304c\u5b58\u5728\u3057\u306a\u3044\u304c_Unwind_Backtrace()\u306f\u3061\u3083\u3093\u3068\u52d5\u304f C\u3067\u52d5\u304b\u3059\u305f\u3081\u306e\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3082\u516c\u958b\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u4e07\u4e00\u3053\u306e\u30da\u30fc\u30b8\u3092\u8aad\u3093\u3060\u65b9\u304c\u3044\u3089\u3063\u3057\u3083\u3044\u307e\u3057\u305f\u3089\u3001(\u3068\u304f\u306bi386\u3084sparc\u4ee5\u5916\u3067)\u52d5\u3044\u305f\u3068\u304b\u52d5\u304b\u306a\u304b\u3063\u305f\u3068\u304b\u3054\u5831\u544a\u3044\u305f\u3060\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002 \u4ee5\u4e0b\u306f\u3068\u3063\u3066\u3082\u9577\u3044\u8a73\u7d30\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1580","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts\/1580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/comments?post=1580"}],"version-history":[{"count":22,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts\/1580\/revisions"}],"predecessor-version":[{"id":1604,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts\/1580\/revisions\/1604"}],"wp:attachment":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/media?parent=1580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/categories?post=1580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/tags?post=1580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}