- 论坛徽章:
- 0
|
linux下的cpp和try,catch还真不会写,网上搜了一个
- #include <iostream>
- using namespace std ;
- class A {
- public:
- A() {
- }
- } ;
- void
- f( void )
- {
- throw A( ) ;
- }
- int
- main( int argc, char *argv[] )
- {
- try {
- f( ) ;
- }
- catch( A &e ) {
- cout << "Exception occured!" << endl ;
- }
- return 0 ;
- }
复制代码 [root@mail ~]# gcc -lstdc++ 1.cpp
[root@mail ~]# ./a.out
Exception occured!
看了一下它的反汇编代码,看不懂
- .file "1.cpp"
- .local _ZSt8__ioinit
- .comm _ZSt8__ioinit,1,1
- .text
- .align 2
- .globl _Z1fv
- .type _Z1fv,@function
- _Z1fv:
- .LFB1485:
- pushl %ebp
- .LCFI0:
- movl %esp, %ebp
- .LCFI1:
- pushl %ebx
- .LCFI2:
- subl $4, %esp
- .LCFI3:
- subl $12, %esp
- leal -5(%ebp), %eax
- pushl %eax
- .LCFI4:
- call _ZN1AC1Ev
- addl $16, %esp
- subl $12, %esp
- pushl $1
- call __cxa_allocate_exception
- addl $16, %esp
- movl %eax, %ebx
- subl $8, %esp
- leal -5(%ebp), %eax
- pushl %eax
- pushl %ebx
- call _ZN1AC1ERKS_
- addl $16, %esp
- subl $4, %esp
- pushl $0
- pushl $_ZTI1A
- pushl %ebx
- call __cxa_throw
- .LFE1485:
- .Lfe1:
- .size _Z1fv,.Lfe1-_Z1fv
- .globl _Unwind_Resume
- .section .rodata
- .LC0:
- .string "Exception occured!"
- .text
- .align 2
- .globl main
- .type main,@function
- main:
- .LFB1487:
- pushl %ebp
- .LCFI5:
- movl %esp, %ebp
- .LCFI6:
- pushl %ebx
- .LCFI7:
- subl $20, %esp
- .LCFI8:
- andl $-16, %esp
- movl $0, %eax
- subl %eax, %esp
- .LEHB0:
- call _Z1fv
- .LEHE0:
- jmp .L5
- .L13:
- movl %eax, -12(%ebp)
- cmpl $1, %edx
- je .L6
- subl $12, %esp
- pushl -12(%ebp)
- .LEHB1:
- .LCFI9:
- call _Unwind_Resume
- .LEHE1:
- .L6:
- subl $12, %esp
- pushl -12(%ebp)
- call __cxa_begin_catch
- addl $16, %esp
- movl %eax, -8(%ebp)
- subl $8, %esp
- pushl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
- subl $12, %esp
- pushl $.LC0
- pushl $_ZSt4cout
- .LEHB2:
- .LCFI10:
- call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
- addl $20, %esp
- pushl %eax
- .LCFI11:
- call _ZNSolsEPFRSoS_E
- .LEHE2:
- addl $16, %esp
- jmp .L8
- .L12:
- movl %eax, -12(%ebp)
- movl -12(%ebp), %ebx
- .LCFI12:
- call __cxa_end_catch
- movl %ebx, -12(%ebp)
- subl $12, %esp
- pushl -12(%ebp)
- .LEHB3:
- .LCFI13:
- call _Unwind_Resume
- .LEHE3:
- .L8:
- .LCFI14:
- call __cxa_end_catch
- .L5:
- movl $0, %eax
- movl -4(%ebp), %ebx
- leave
- ret
- .LFE1487:
- .Lfe2:
- .size main,.Lfe2-main
- .section .gcc_except_table,"a",@progbits
- .align 4
- .LLSDA1487:
- .byte 0xff
- .byte 0x0
- .uleb128 .LLSDATT1487-.LLSDATTD1487
- .LLSDATTD1487:
- .byte 0x1
- .uleb128 .LLSDACSE1487-.LLSDACSB1487
- .LLSDACSB1487:
- .uleb128 .LEHB0-.LFB1487
- .uleb128 .LEHE0-.LEHB0
- .uleb128 .L13-.LFB1487
- .uleb128 0x1
- .uleb128 .LEHB1-.LFB1487
- .uleb128 .LEHE1-.LEHB1
- .uleb128 0x0
- .uleb128 0x0
- .uleb128 .LEHB2-.LFB1487
- .uleb128 .LEHE2-.LEHB2
- .uleb128 .L12-.LFB1487
- .uleb128 0x0
- .uleb128 .LEHB3-.LFB1487
- .uleb128 .LEHE3-.LEHB3
- .uleb128 0x0
- .uleb128 0x0
- .LLSDACSE1487:
- .byte 0x1
- .byte 0x0
- .align 4
- .long _ZTI1A
- .LLSDATT1487:
- .text
- .align 2
- .type _Z41__static_initialization_and_destruction_0ii,@function
- _Z41__static_initialization_and_destruction_0ii:
- .LFB1498:
- pushl %ebp
- .LCFI15:
- movl %esp, %ebp
- .LCFI16:
- subl $8, %esp
- .LCFI17:
- cmpl $65535, 12(%ebp)
- jne .L14
- cmpl $1, 8(%ebp)
- jne .L14
- subl $12, %esp
- pushl $_ZSt8__ioinit
- .LCFI18:
- call _ZNSt8ios_base4InitC1Ev
- addl $16, %esp
- subl $4, %esp
- pushl $__dso_handle
- pushl $0
- pushl $__tcf_0
- call __cxa_atexit
- addl $16, %esp
- .L14:
- leave
- ret
- .LFE1498:
- .Lfe3:
- .size _Z41__static_initialization_and_destruction_0ii,.Lfe3-_Z41__static_initialization_and_destruction_0ii
- .section .gnu.linkonce.t._ZN1AC1ERKS_,"ax",@progbits
- .align 2
- .weak _ZN1AC1ERKS_
- .type _ZN1AC1ERKS_,@function
- _ZN1AC1ERKS_:
- .LFB1499:
- pushl %ebp
- .LCFI19:
- movl %esp, %ebp
- .LCFI20:
- leave
- ret
- .LFE1499:
- .Lfe4:
- .size _ZN1AC1ERKS_,.Lfe4-_ZN1AC1ERKS_
- .section .gnu.linkonce.t._ZN1AC1Ev,"ax",@progbits
- .align 2
- .weak _ZN1AC1Ev
- .type _ZN1AC1Ev,@function
- _ZN1AC1Ev:
- .LFB1500:
- pushl %ebp
- .LCFI21:
- movl %esp, %ebp
- .LCFI22:
- leave
- ret
- .LFE1500:
- .Lfe5:
- .size _ZN1AC1Ev,.Lfe5-_ZN1AC1Ev
- .text
- .align 2
- .type __tcf_0,@function
- __tcf_0:
- .LFB1501:
- pushl %ebp
- .LCFI23:
- movl %esp, %ebp
- .LCFI24:
- subl $8, %esp
- .LCFI25:
- subl $12, %esp
- pushl $_ZSt8__ioinit
- .LCFI26:
- call _ZNSt8ios_base4InitD1Ev
- addl $16, %esp
- leave
- ret
- .LFE1501:
- .Lfe6:
- .size __tcf_0,.Lfe6-__tcf_0
- .weak _ZTI1A
- .section .gnu.linkonce.d._ZTI1A,"aw",@progbits
- .align 4
- .type _ZTI1A,@object
- .size _ZTI1A,8
- _ZTI1A:
- .long _ZTVN10__cxxabiv117__class_type_infoE+8
- .long _ZTS1A
- .weak _ZTS1A
- .section .gnu.linkonce.r._ZTS1A,"a",@progbits
- .type _ZTS1A,@object
- .size _ZTS1A,3
- _ZTS1A:
- .string "1A"
- .text
- .align 2
- .type _GLOBAL__I__Z1fv,@function
- _GLOBAL__I__Z1fv:
- .LFB1503:
- pushl %ebp
- .LCFI27:
- movl %esp, %ebp
- .LCFI28:
- subl $8, %esp
- .LCFI29:
- subl $8, %esp
- pushl $65535
- pushl $1
- .LCFI30:
- call _Z41__static_initialization_and_destruction_0ii
- addl $16, %esp
- leave
- ret
- .LFE1503:
- .Lfe7:
- .size _GLOBAL__I__Z1fv,.Lfe7-_GLOBAL__I__Z1fv
- .section .ctors,"aw",@progbits
- .align 4
- .long _GLOBAL__I__Z1fv
- .weak pthread_mutex_unlock
- .weak pthread_mutex_trylock
- .weak pthread_mutex_lock
- .weak pthread_create
- .weak pthread_setspecific
- .weak pthread_getspecific
- .weak pthread_key_delete
- .weak pthread_key_create
- .weak pthread_once
- .section .eh_frame,"a",@progbits
- .Lframe1:
- .long .LECIE1-.LSCIE1
- .LSCIE1:
- .long 0x0
- .byte 0x1
- .string "zPL"
- .uleb128 0x1
- .sleb128 -4
- .byte 0x8
- .uleb128 0x6
- .byte 0x0
- .long __gxx_personality_v0
- .byte 0x0
- .byte 0xc
- .uleb128 0x4
- .uleb128 0x4
- .byte 0x88
- .uleb128 0x1
- .align 4
- .LECIE1:
- .LSFDE1:
- .long .LEFDE1-.LASFDE1
- .LASFDE1:
- .long .LASFDE1-.Lframe1
- .long .LFB1485
- .long .LFE1485-.LFB1485
- .uleb128 0x4
- .long 0x0
- .byte 0x4
- .long .LCFI0-.LFB1485
- .byte 0xe
- .uleb128 0x8
- .byte 0x85
- .uleb128 0x2
- .byte 0x4
- .long .LCFI1-.LCFI0
- .byte 0xd
- .uleb128 0x5
- .byte 0x4
- .long .LCFI3-.LCFI1
- .byte 0x83
- .uleb128 0x3
- .byte 0x4
- .long .LCFI4-.LCFI3
- .byte 0x2e
- .uleb128 0x10
- .align 4
- .LEFDE1:
- .LSFDE3:
- .long .LEFDE3-.LASFDE3
- .LASFDE3:
- .long .LASFDE3-.Lframe1
- .long .LFB1487
- .long .LFE1487-.LFB1487
- .uleb128 0x4
- .long .LLSDA1487
- .byte 0x4
- .long .LCFI5-.LFB1487
- .byte 0xe
- .uleb128 0x8
- .byte 0x85
- .uleb128 0x2
- .byte 0x4
- .long .LCFI6-.LCFI5
- .byte 0xd
- .uleb128 0x5
- .byte 0x4
- .long .LCFI8-.LCFI6
- .byte 0x83
- .uleb128 0x3
- .byte 0x4
- .long .LCFI9-.LCFI8
- .byte 0x2e
- .uleb128 0x10
- .byte 0x4
- .long .LCFI10-.LCFI9
- .byte 0x2e
- .uleb128 0x14
- .byte 0x4
- .long .LCFI11-.LCFI10
- .byte 0x2e
- .uleb128 0x10
- .byte 0x4
- .long .LCFI12-.LCFI11
- .byte 0x2e
- .uleb128 0x0
- .byte 0x4
- .long .LCFI13-.LCFI12
- .byte 0x2e
- .uleb128 0x10
- .byte 0x4
- .long .LCFI14-.LCFI13
- .byte 0x2e
- .uleb128 0x0
- .align 4
- .LEFDE3:
- .LSFDE5:
- .long .LEFDE5-.LASFDE5
- .LASFDE5:
- .long .LASFDE5-.Lframe1
- .long .LFB1498
- .long .LFE1498-.LFB1498
- .uleb128 0x4
- .long 0x0
- .byte 0x4
- .long .LCFI15-.LFB1498
- .byte 0xe
- .uleb128 0x8
- .byte 0x85
- .uleb128 0x2
- .byte 0x4
- .long .LCFI16-.LCFI15
- .byte 0xd
- .uleb128 0x5
- .byte 0x4
- .long .LCFI18-.LCFI16
- .byte 0x2e
- .uleb128 0x10
- .align 4
- .LEFDE5:
- .LSFDE11:
- .long .LEFDE11-.LASFDE11
- .LASFDE11:
- .long .LASFDE11-.Lframe1
- .long .LFB1501
- .long .LFE1501-.LFB1501
- .uleb128 0x4
- .long 0x0
- .byte 0x4
- .long .LCFI23-.LFB1501
- .byte 0xe
- .uleb128 0x8
- .byte 0x85
- .uleb128 0x2
- .byte 0x4
- .long .LCFI24-.LCFI23
- .byte 0xd
- .uleb128 0x5
- .byte 0x4
- .long .LCFI26-.LCFI24
- .byte 0x2e
- .uleb128 0x10
- .align 4
- .LEFDE11:
- .LSFDE13:
- .long .LEFDE13-.LASFDE13
- .LASFDE13:
- .long .LASFDE13-.Lframe1
- .long .LFB1503
- .long .LFE1503-.LFB1503
- .uleb128 0x4
- .long 0x0
- .byte 0x4
- .long .LCFI27-.LFB1503
- .byte 0xe
- .uleb128 0x8
- .byte 0x85
- .uleb128 0x2
- .byte 0x4
- .long .LCFI28-.LCFI27
- .byte 0xd
- .uleb128 0x5
- .byte 0x4
- .long .LCFI30-.LCFI28
- .byte 0x2e
- .uleb128 0x10
- .align 4
- .LEFDE13:
- .ident "GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)"
复制代码 |
|