NAME=binsym demangling
FILE=bins/mach0/hellocxx-osx-i386
CMDS=!rz-bin -qsD cxx all bins/mach0/hellocxx-osx-i386
EXPECT=<<EOF
0x00002054 0 _NXArgc
0x00002058 0 _NXArgv
0x00001d9a 0 unsigned long const& std::min<unsigned long>(unsigned long const&, unsigned long const&)
0x00002060 0 ___progname
0x00001000 0 __mh_execute_header
0x0000205c 0 _environ
0x00001d52 0 _main
0x00001c10 0 start
0x00001ba0 0 __static_initialization_and_destruction_0(int, int)
0x00001bf2 0 global constructors keyed to main
0x00001c4e 0 std::__verify_grouping(char const*, unsigned long, std::string const&)
0x00001dc1 0 ___tcf_0
0x00001e24 0  stub helpers
0x00002000 0 _pvars
0x00002064 0 std::__ioinit
0x00001dee 0 std::string::size() const
0x00001df4 0 std::string::operator[](unsigned long) const
0x00001dfa 0 std::ostream::operator<<(std::ostream& (*)(std::ostream&))
0x00001e00 0 std::ios_base::Init::Init()
0x00001e06 0 std::ios_base::Init::~Init()
0x00001e12 0 std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
0x00001e18 0 imp.__cxa_atexit
0x00001e1e 0 imp.exit
EOF
RUN

NAME=binsym without demangling
FILE=bins/mach0/hellocxx-osx-i386
ARGS=-M
CMDS=isq
EXPECT=<<EOF
0x00002054 0 _NXArgc
0x00002058 0 _NXArgv
0x00001d9a 0 __ZSt3minImERKT_S2_S2_
0x00002060 0 ___progname
0x00001000 0 __mh_execute_header
0x0000205c 0 _environ
0x00001d52 0 _main
0x00001c10 0 start
0x00001ba0 0 __Z41__static_initialization_and_destruction_0ii
0x00001bf2 0 __GLOBAL__I_main
0x00001c4e 0 __ZStL17__verify_groupingPKcmRKSs
0x00001dc1 0 ___tcf_0
0x00001e24 0  stub helpers
0x00002000 0 _pvars
0x00002064 0 __ZStL8__ioinit
0x00001dee 0 imp._ZNKSs4sizeEv
0x00001df4 0 imp._ZNKSsixEm
0x00001dfa 0 imp._ZNSolsEPFRSoS_E
0x00001e00 0 imp._ZNSt8ios_base4InitC1Ev
0x00001e06 0 imp._ZNSt8ios_base4InitD1Ev
0x00001e12 0 imp._ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
0x00001e18 0 imp.__cxa_atexit
0x00001e1e 0 imp.exit
EOF
RUN

NAME=bin.demangle=true and symbol
FILE=bins/elf/analysis/hello-linux-i386nold
ARGS=-e bin.demangle=true
CMDS=pi 1 @ 0x08048230
EXPECT=<<EOF
call sym.imp.puts
EOF
RUN

NAME=MSVC import symbol demangling
FILE=bins/pe/libzmq-v100-mt-4_0_4.dll
CMDS=f~0x1004e0f4[2]
EXPECT=<<EOF
sym.imp.MSVCP100.dll_public:_void___thiscall_std::basic_ostream_char__struct_std::char_traits_char__::_Osfx_void
EOF
RUN

NAME=C++ demangle relocs
FILE=bins/elf/libstdc++.so.6
CMDS=e asm.bytes=true;pd 1 @0x00091004; 
EXPECT=<<EOF
            0x00091004      488b159d880f.  mov   rdx, qword [reloc.vtable_for_std::bad_alloc] ; new:57 ; [0x1898a8:8]=0
EOF
RUN

NAME=C++ demangle exported GLIBCXX symbols
FILE=bins/elf/libstdc++.so.6
CMDS=iE~0x0008ce50
EXPECT=<<EOF
3770  0x0008ce50 0x0008ce50 GLOBAL FUNC 609      std::istream::ignore(long)
3771  0x0008ce50 0x0008ce50 GLOBAL FUNC 609      std::istream::ignore(long)
5087  0x0008ce50 0x0008ce50 GLOBAL FUNC 609      std::istream::ignore(long)
5345  0x0008ce50 0x0008ce50 GLOBAL FUNC 609      std::istream::ignore(long)
EOF
RUN

NAME=demangle in irj
FILE=bins/elf/demangle-test-cpp
CMDS=irj~{9}
EXPECT=<<EOF
{"name":"_ZSt20__throw_length_errorPKc","demname":"std::__throw_length_error(char const*)","type":"SET_64","vaddr":16424,"paddr":12328,"is_ifunc":false}
EOF
RUN

NAME=demangle obj in pd
FILE=bins/elf/ch25.bin
CMDS=e asm.bytes=true; pd 1 @0x08048aac;
EXPECT=<<EOF
            0x08048aac      c7042460b004.  mov   dword [esp], obj.std::cerr ; sym..bss
                                                                       ; [0x804b060:4]=0
EOF
RUN

NAME=c++ disasm call demangling
FILE=bins/elf/abcde-qt32
CMDS=<<EOF
e asm.demangle=true
e asm.bytes=false
(pd_calls; pd 1 @ 0x0804921a; pd 1 @ 0x08049249; pd 1 @ 0x08049278)
e asm.cmt.right=true
.(pd_calls)
?e
e asm.cmt.right=false
.(pd_calls)
?e
e asm.cmt.right=true
aa
.(pd_calls)
?e
e asm.demangle=false
.(pd_calls)
EOF
EXPECT=<<EOF
            0x0804921a      call  sym.__x86.get_pc_thunk.si
            0x08049249      call  method QFlags<Qt::WindowType>::QFlags(int QFlags<Qt::WindowType>::Private::*) ; method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::
            0x08049278      call  sym QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>) ; sym.imp.QLabel::QLabel_QString_const___QWidget___QFlags_Qt::WindowType

            0x0804921a      call sym.__x86.get_pc_thunk.si
            ; method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::
            0x08049249      call method QFlags<Qt::WindowType>::QFlags(int QFlags<Qt::WindowType>::Private::*)
            ; sym.imp.QLabel::QLabel_QString_const___QWidget___QFlags_Qt::WindowType
            0x08049278      call sym QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>)

|           0x0804921a      call  sym.__x86.get_pc_thunk.si
|           0x08049249      call  method QFlags<Qt::WindowType>::QFlags(int QFlags<Qt::WindowType>::Private::*) ; method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::
|           0x08049278      call  sym QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>) ; sym.imp.QLabel::QLabel_QString_const___QWidget___QFlags_Qt::WindowType

|           0x0804921a      call  sym.__x86.get_pc_thunk.si
|           0x08049249      call  method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::
|           0x08049278      call  sym.imp.QLabel::QLabel_QString_const___QWidget___QFlags_Qt::WindowType
EOF
RUN

NAME=c++ xref demangling (xref from fcn)
FILE=bins/elf/abcde-qt32
CMDS=<<EOF
e asm.var=false
e asm.bytes=false
aa
s sym.__x86.get_pc_thunk.bx
e asm.demangle=true
pd 1
?e
agf
?e
e asm.demangle=false
pd 1
?e
s 0x08049390
e asm.demangle=true
pd 1
?e
e asm.demangle=false
pd 1
EOF
EXPECT=<<EOF
            ; CALL XREF from sym._init @ 0x8049008
            ; CALL XREF from QtPrivate::RefCount::deref() @ 0x8049349 ; method.QtPrivate::RefCount.deref
            ; CALL XREF from QString::QString(char const*) @ 0x804939d ; method.QString.QString_char_const
            ; CALL XREF from QString::~QString() @ 0x80493e5 ; method.QString._QString
            ; CALL XREF from sym._fini @ 0x80495d4
/ 4: sym.__x86.get_pc_thunk.bx ();
|           0x08049140      mov   ebx, dword [esp]

[0x08049140]>  # sym.__x86.get_pc_thunk.bx ();
 --------------------------------------------------------------.
|  0x8049140                                                   |
|   ; CALL XREF from sym._init @ 0x8049008                     |
|   ; CALL XREF from QtPrivate::RefCount::deref() @ 0x8049349  |
|     ; method.QtPrivate::RefCount.deref                       |
|   ; CALL XREF from QString::QString(char const*) @ 0x804939d |
|     ; method.QString.QString_char_const                      |
|   ; CALL XREF from QString::~QString() @ 0x80493e5           |
|     ; method.QString._QString                                |
|   ; CALL XREF from sym._fini @ 0x80495d4                     |
| 4: sym.__x86.get_pc_thunk.bx ();                             |
| mov ebx, dword [esp]                                         |
| ret                                                          |
`--------------------------------------------------------------'

            ; CALL XREF from sym._init @ 0x8049008
            ; CALL XREF from method.QtPrivate::RefCount.deref @ 0x8049349
            ; CALL XREF from method.QString.QString_char_const @ 0x804939d
            ; CALL XREF from method.QString._QString @ 0x80493e5
            ; CALL XREF from sym._fini @ 0x80495d4
/ 4: sym.__x86.get_pc_thunk.bx ();
|           0x08049140      mov   ebx, dword [esp]

|           ; CODE XREFS from QtPrivate::RefCount::deref() @ 0x8049371, 0x804937e
|           0x08049390      mov   ebx, dword [var_4h]

|           ; CODE XREFS from method.QtPrivate::RefCount.deref @ 0x8049371, 0x804937e
|           0x08049390      mov   ebx, dword [var_4h]
EOF
RUN

NAME=c++ xref demangling (xref not from fcn)
FILE=bins/elf/redpill
CMDS=<<EOF
e asm.var=false
e asm.bytes=false
aaa
e asm.demangle=true
pd 1 @ sym.imp._Unwind_Resume
?e
e asm.demangle=false
pd 1 @ sym.imp._Unwind_Resume
EOF
EXPECT=<<EOF
            ; CALL XREF from main @ +0x222
            ; CALL XREF from fcn.00001717 @ +0xbb
            ; CALL XREF from std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<char*, void>(char*, char*, std::allocator<char> const&) @ +0x66 ; sym.std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::basic_string_char___void__char___char___std::allocator_char__const
            ; CALL XREF from void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) @ +0x116 ; sym.void_std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::_M_construct_char___char___char___std::forward_iterator_tag
/ 6: sym.imp._Unwind_Resume ();
\           0x00000f10      jmp   dword [ebx + 0x70]

            ; CALL XREF from main @ +0x222
            ; CALL XREF from fcn.00001717 @ +0xbb
            ; CALL XREF from sym.std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::basic_string_char___void__char___char___std::allocator_char__const @ +0x66
            ; CALL XREF from sym.void_std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::_M_construct_char___char___char___std::forward_iterator_tag @ +0x116
/ 6: sym.imp._Unwind_Resume ();
\           0x00000f10      jmp   dword [ebx + 0x70]
EOF
RUN
