c++ Òì³£´¦Àí£¨1£©(Èý)

2014-11-24 10:57:09 ¡¤ ×÷Õß: ¡¤ ä¯ÀÀ: 4
return _URC_FATAL_PHASE1_ERROR;
/* Unwind successful. Run the personality routine, if any. */
if (fs.personality)
{
code = (*fs.personality) (1, _UA_SEARCH_PHASE, exc->exception_class,
exc, &cur_context);
if (code == _URC_HANDLER_FOUND)
break;
else if (code != _URC_CONTINUE_UNWIND)
return _URC_FATAL_PHASE1_ERROR;
}
uw_update_context (&cur_context, &fs);
}
/* Indicate to _Unwind_Resume and associated subroutines that this
is not a forced unwind. Further, note where we found a handler. */
exc->private_1 = 0;
exc->private_2 = uw_identify_context (&cur_context);
cur_context = this_context;
code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
if (code != _URC_INSTALL_CONTEXT)
return code;
uw_install_context (&this_context, &cur_context);
}
static _Unwind_Reason_Code
_Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc,
struct _Unwind_Context *context)
{
_Unwind_Reason_Code code;
while (1)
{
_Unwind_FrameState fs;
int match_handler;
code = uw_frame_state_for (context, &fs);
/* Identify when we've reached the designated handler context. */
match_handler = (uw_identify_context (context) == exc->private_2
_UA_HANDLER_FRAME : 0);
if (code != _URC_NO_REASON)
/* Some error encountered. Usually the unwinder doesn't
diagnose these and merely crashes. */
return _URC_FATAL_PHASE2_ERROR;
/* Unwind successful. Run the personality routine, if any. */
if (fs.personality)
{
code = (*fs.personality) (1, _UA_CLEANUP_PHASE | match_handler,
exc->exception_class, exc, context);
if (code == _URC_INSTALL_CONTEXT)
break;
if (code != _URC_CONTINUE_UNWIND)
return _URC_FATAL_PHASE2_ERROR;
}
/* Don't let us unwind past the handler context. */
if (match_handler)
abort ();
uw_update_context (context, &fs);
}
return code;
}
¸´ÖÆ´úÂë
ÉÏÃæÁ½¸öº¯Êý·Ö±ð¶ÔÓ¦ÁËunwind¹ý³ÌÖеÄÕâÁ½¸ö½×¶Î£¬×¢ÒâÆäÖеģº
uw_init_context()
uw_frame_state_for()
uw_update_context()
Õ⼸¸öº¯ÊýÖ÷ÒªÊÇÓÃÀ´Öؽ¨º¯Êýµ÷ÓÃÏÖ³¡µÄ£¬ËüÃǵÄʵÏÖÉæ¼°µ½Ò»´ó¶ÑµÄϸ½Ú£¬Õâ¶ùÏȲ»Ï¸Ëµ£¬´ó¸ÅÔ­Àí¾ÍÊÇ£¬¶ÔÓÚµ÷ÓÃÁ´Éϵĺ¯ÊýÀ´Ëµ£¬ËüÃǵĺܴóÒ»²¿·ÖÉÏÏÂÎÄÊÇ¿ÉÒÔ´Ó¶ÑÕ»Éϻָ´»ØÀ´µÄ,Èçebp,esp,·µ»ØÖµµÈ¡£±àÒëÆ÷ΪÁË´ÓÕ»ÉÏ»ñÈ¡ÕâЩÐÅÏ¢£¬ËüÔÚ±àÒë´úÂëµÄʱºò£¬½¨Á¢Á˺ܶà±íÏîÓÃÓڼǼÿ¸ö¿ÉÒÔÅ×Òì³£µÄº¯ÊýµÄÏà¹ØÐÅÏ¢£¬ÕâЩÐÅÏ¢¾ÍÔÚÖØ½¨ÉÏÏÂÎÄʱÄܹ»Ö¸µ¼³ÌÐòÔõôȥËÑË÷Õ»ÉϵĶ«Î÷¡£
×öµãÓÐÒâ˼µÄÊÂÇé
˵ÁËÒ»´ó¶Ñ£¬ÏÂÃæÐ´¸ö²âÊԵijÌÐò¼òµ¥»Ø¹ËÒ»ÏÂÇ°ÃæËù˵µÄ¹ØÓÚÒì³£´¦ÀíµÄ´ó¸ÅÁ÷³Ì£º
¸´ÖÆ´úÂë
#include
using namespace std;
void test_func3()
{
throw 3;
cout << "test func3" << endl;
}
void test_func2()
{
cout << "test func2" << endl;
try
{
test_func3();
}
catch (int)
{
cout << "catch 2" << endl;
}
}
void test_func1()
{
cout << "test func1" << endl;
try
{
test_func2();
}
catch (...)
{
cout << "catch 1" << endl;
}
}
int main()
{
test_func1();
return 0;
}
¸´ÖÆ´úÂë
ÉÏÃæµÄ³ÌÐòÔËÐÐÆðÀ´ºó£¬ÎÒÃÇ¿ÉÒÔÔÚ__gxx_personality_v0 ÀïÏÂÒ»¸ö¶Ïµã¡£
¸´ÖÆ´úÂë
Breakpoint 2, 0x00dd0a46 in __gxx_personality_v0 () from /usr/lib/libstdc++.so.6
(gdb) bt
#0 0x00dd0a46 in __gxx_personality_v0 () from /usr/lib/libstdc++.so.6
#1 0x00d2af2c in _Unwind_RaiseException () from /lib/libgcc_s.so.1
#2 0x00dd10e2 in __cxa_throw () from /usr/lib/l