Ticket #15138: wx_trunk_15138_20130411_core_only.patch

File wx_trunk_15138_20130411_core_only.patch, 36.1 KB (added by suzumizaki, 7 years ago)

Only include/*.h and src/*.cpp fixes, included _all version.

  • include/wx/msw/debughlp.h

     
    22// Name:        wx/msw/debughlp.h
    33// Purpose:     wraps dbghelp.h standard file
    44// Author:      Vadim Zeitlin
    5 // Modified by:
     5// Modified by: Suzumizaki-kimitaka 2013-04-10
    66// Created:     2005-01-08 (extracted from msw/crashrpt.cpp)
    77// RCS-ID:      $Id$
    88// Copyright:   (c) 2003-2005 Vadim Zeitlin <vadim@wxwindows.org>
     
    4343
    4444#if wxUSE_DBGHELP
    4545
     46/*
     47
     48The table below shows which functions are exported by dbghelp.dll.
     49On 64 bit Windows, it looks no difference between 32bit dll and
     5064bit one.
     51Vista-64 and Win8-64 looks same, but in fact, "Ex" and "ExW"
     52versions are exist only in Windows 8.
     53
     54Make sure SymGetLineFromAddrW and EnumerateLoadedModulesW DON'T
     55exists.
     56
     57functions | Windows     | XP-32 Vista-64 Win8-64
     58SymEnumSymbolsW            n/a     v       v
     59SymFromAddrW               n/a     v       v
     60SymInitializeW             n/a     v       v
     61
     62SymEnumSymbols              v      v       v
     63SymFromAddr                 v      v       v
     64SymInitialize               v      v       v
     65
     66SymGetLineFromAddrW64      n/a     v       v
     67SymGetLineFromAddr64        v      v       v
     68SymGetLineFromAddrW        n/a    n/a     n/a
     69SymGetLineFromAddr          v      v       v
     70
     71EnumerateLoadedModulesW64  n/a     v       v
     72EnumerateLoadedModules64    v      v       v
     73EnumerateLoadedModulesW    n/a    n/a     n/a
     74EnumerateLoadedModules      v      v       v
     75
     76*/
     77
     78#ifdef UNICODE
     79#define wxPENUMLOADED_MODULES_CALLBACK64 PENUMLOADED_MODULES_CALLBACKW64
     80#define wxPSYMBOL_INFO PSYMBOL_INFOW
     81#define wxSYMBOL_INFO SYMBOL_INFOW
     82#define wxPIMAGEHLP_LINE PIMAGEHLP_LINEW64
     83#define wxIMAGEHLP_LINE IMAGEHLP_LINEW64
     84#define wxPSYM_ENUMERATESYMBOLS_CALLBACK PSYM_ENUMERATESYMBOLS_CALLBACKW
     85#else
     86#define wxPENUMLOADED_MODULES_CALLBACK64 PENUMLOADED_MODULES_CALLBACK64
     87#define wxPSYMBOL_INFO PSYMBOL_INFO
     88#define wxSYMBOL_INFO SYMBOL_INFO
     89#define wxPIMAGEHLP_LINE PIMAGEHLP_LINE64
     90#define wxIMAGEHLP_LINE IMAGEHLP_LINE64
     91#define wxPSYM_ENUMERATESYMBOLS_CALLBACK PSYM_ENUMERATESYMBOLS_CALLBACK
     92#endif
     93
    4694// ----------------------------------------------------------------------------
    4795// wxDbgHelpDLL: dynamically load dbghelp.dll functions
    4896// ----------------------------------------------------------------------------
     
    142190    // function types
    143191    typedef DWORD (WINAPI *SymGetOptions_t)();
    144192    typedef DWORD (WINAPI *SymSetOptions_t)(DWORD);
    145     typedef BOOL (WINAPI *SymInitialize_t)(HANDLE, LPSTR, BOOL);
    146193    typedef BOOL (WINAPI *StackWalk_t)(DWORD, HANDLE, HANDLE, LPSTACKFRAME,
    147194                                       LPVOID, PREAD_PROCESS_MEMORY_ROUTINE,
    148195                                       PFUNCTION_TABLE_ACCESS_ROUTINE,
    149196                                       PGET_MODULE_BASE_ROUTINE,
    150197                                       PTRANSLATE_ADDRESS_ROUTINE);
    151     typedef BOOL (WINAPI *SymFromAddr_t)(HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO);
    152198    typedef LPVOID (WINAPI *SymFunctionTableAccess_t)(HANDLE, DWORD_PTR);
    153199    typedef DWORD_PTR (WINAPI *SymGetModuleBase_t)(HANDLE, DWORD_PTR);
    154     typedef BOOL (WINAPI *SymGetLineFromAddr_t)(HANDLE, DWORD_PTR,
    155                                                 PDWORD, PIMAGEHLP_LINE);
    156200    typedef BOOL (WINAPI *SymSetContext_t)(HANDLE, PIMAGEHLP_STACK_FRAME,
    157201                                           PIMAGEHLP_CONTEXT);
    158     typedef BOOL (WINAPI *SymEnumSymbols_t)(HANDLE, ULONG64, PCSTR,
    159                                             PSYM_ENUMERATESYMBOLS_CALLBACK, PVOID);
    160202    typedef BOOL (WINAPI *SymGetTypeInfo_t)(HANDLE, DWORD64, ULONG,
    161203                                            IMAGEHLP_SYMBOL_TYPE_INFO, PVOID);
    162204    typedef BOOL (WINAPI *SymCleanup_t)(HANDLE);
    163     typedef BOOL (WINAPI *EnumerateLoadedModules_t)(HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID);
    164205    typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE,
    165206                                               MINIDUMP_TYPE,
    166207                                               CONST PMINIDUMP_EXCEPTION_INFORMATION,
    167208                                               CONST PMINIDUMP_USER_STREAM_INFORMATION,
    168209                                               CONST PMINIDUMP_CALLBACK_INFORMATION);
    169210
     211    typedef BOOL (WINAPI *EnumerateLoadedModules_t)(HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID);
     212    typedef BOOL (WINAPI *SymGetLineFromAddr_t)(HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE);
     213
     214    typedef BOOL (WINAPI *EnumerateLoadedModules64_t)(HANDLE, PENUMLOADED_MODULES_CALLBACK64, PVOID);
     215    typedef BOOL (WINAPI *SymInitialize_t)(HANDLE, LPCSTR, BOOL);
     216    typedef BOOL (WINAPI *SymFromAddr_t)(HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO);
     217    typedef BOOL (WINAPI *SymGetLineFromAddr64_t)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
     218    typedef BOOL (WINAPI *SymEnumSymbols_t)(HANDLE, ULONG64, PCSTR,
     219                                            PSYM_ENUMERATESYMBOLS_CALLBACK, const PVOID);
     220
     221    typedef BOOL (WINAPI *EnumerateLoadedModulesW64_t)(HANDLE, PENUMLOADED_MODULES_CALLBACKW64, PVOID);
     222    typedef BOOL (WINAPI *SymInitializeW_t)(HANDLE, LPCWSTR, BOOL);
     223    typedef BOOL (WINAPI *SymFromAddrW_t)(HANDLE, DWORD64, PDWORD64, PSYMBOL_INFOW);
     224    typedef BOOL (WINAPI *SymGetLineFromAddrW64_t)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINEW64);
     225    typedef BOOL (WINAPI *SymEnumSymbolsW_t)(HANDLE, ULONG64, PCWSTR,
     226                                             PSYM_ENUMERATESYMBOLS_CALLBACKW, const PVOID);
     227   
     228    static BOOL EnumerateLoadedModulesT(HANDLE, wxPENUMLOADED_MODULES_CALLBACK64, PVOID);
     229    static BOOL SymInitializeT(HANDLE, LPCTSTR, BOOL);
     230    static BOOL SymFromAddrT(HANDLE, DWORD64, PDWORD64, wxPSYMBOL_INFO);
     231    static BOOL SymGetLineFromAddrT(HANDLE, DWORD64, PDWORD, wxPIMAGEHLP_LINE);
     232    static BOOL SymEnumSymbolsT(HANDLE, ULONG64, PCTSTR, wxPSYM_ENUMERATESYMBOLS_CALLBACK, const PVOID);
     233
    170234    // The macro called by wxDO_FOR_ALL_SYM_FUNCS() below takes 2 arguments:
    171235    // the name of the function in the program code, which never has "64"
    172236    // suffix, and the name of the function in the DLL which can have "64"
     
    175239    #define wxSYM_CALL(what, name)  what(name, name)
    176240#if defined(_M_AMD64)
    177241    #define wxSYM_CALL_64(what, name)  what(name, name ## 64)
    178 
    179242    // Also undo all the "helpful" definitions done by imagehlp.h that map 32
    180243    // bit functions to 64 bit ones, we don't need this as we do it ourselves.
    181244    #undef StackWalk
     
    187250    #define wxSYM_CALL_64(what, name)  what(name, name)
    188251#endif
    189252
    190     #define wxDO_FOR_ALL_SYM_FUNCS(what)                                      \
    191         wxSYM_CALL_64(what, StackWalk);                                       \
    192         wxSYM_CALL_64(what, SymFunctionTableAccess);                          \
    193         wxSYM_CALL_64(what, SymGetModuleBase);                                \
    194         wxSYM_CALL_64(what, SymGetLineFromAddr);                              \
    195         wxSYM_CALL_64(what, EnumerateLoadedModules);                          \
    196                                                                               \
    197         wxSYM_CALL(what, SymGetOptions);                                      \
    198         wxSYM_CALL(what, SymSetOptions);                                      \
    199         wxSYM_CALL(what, SymInitialize);                                      \
    200         wxSYM_CALL(what, SymFromAddr);                                        \
    201         wxSYM_CALL(what, SymSetContext);                                      \
    202         wxSYM_CALL(what, SymEnumSymbols);                                     \
    203         wxSYM_CALL(what, SymGetTypeInfo);                                     \
    204         wxSYM_CALL(what, SymCleanup);                                         \
     253    #define wxSYM_CALL_ALWAYS_W(what, name)  what(name ## W, name ## W)
     254
     255    #define wxSYM_CALL_ALTERNATIVES(what, name)                \
     256        what(name, name);                                      \
     257        what(name ## 64, name ## 64);                          \
     258        what(name ## W64, name ## W64)
     259
     260    #define wxDO_FOR_ALL_SYM_FUNCS_REQUIRED_PUBLIC(what)       \
     261        wxSYM_CALL_64(what, StackWalk);                        \
     262        wxSYM_CALL_64(what, SymFunctionTableAccess);           \
     263        wxSYM_CALL_64(what, SymGetModuleBase);                 \
     264                                                               \
     265        wxSYM_CALL(what, SymGetOptions);                       \
     266        wxSYM_CALL(what, SymSetOptions);                       \
     267        wxSYM_CALL(what, SymSetContext);                       \
     268        wxSYM_CALL(what, SymGetTypeInfo);                      \
     269        wxSYM_CALL(what, SymCleanup);                          \
    205270        wxSYM_CALL(what, MiniDumpWriteDump)
    206271
     272    #define wxDO_FOR_ALL_SYM_FUNCS_REQUIRED_PRIVATE(what)      \
     273        wxSYM_CALL(what, SymInitialize);                       \
     274        wxSYM_CALL(what, SymFromAddr);                         \
     275        wxSYM_CALL(what, SymEnumSymbols)
     276   
     277    #define wxDO_FOR_ALL_SYM_FUNCS_REQUIRED(what)              \
     278        wxDO_FOR_ALL_SYM_FUNCS_REQUIRED_PRIVATE(what);         \
     279        wxDO_FOR_ALL_SYM_FUNCS_REQUIRED_PUBLIC(what)
     280
     281    // Alternation will work when the following functions are not found,
     282    // therefore they are not included in REQUIRED version.
     283    #define wxDO_FOR_ALL_SYM_FUNCS_OPTIONAL(what)              \
     284        wxSYM_CALL_ALTERNATIVES(what, SymGetLineFromAddr);     \
     285        wxSYM_CALL_ALTERNATIVES(what, EnumerateLoadedModules); \
     286        wxSYM_CALL_ALWAYS_W(what, SymInitialize);              \
     287        wxSYM_CALL_ALWAYS_W(what, SymFromAddr);                \
     288        wxSYM_CALL_ALWAYS_W(what, SymEnumSymbols)
     289
     290    #define wxDO_FOR_ALL_SYM_FUNCS(what)                       \
     291        wxDO_FOR_ALL_SYM_FUNCS_REQUIRED(what);                 \
     292        wxDO_FOR_ALL_SYM_FUNCS_OPTIONAL(what)
     293   
    207294    #define wxDECLARE_SYM_FUNCTION(func, name) static func ## _t func
    208295
    209     wxDO_FOR_ALL_SYM_FUNCS(wxDECLARE_SYM_FUNCTION);
     296    wxDO_FOR_ALL_SYM_FUNCS_REQUIRED_PUBLIC(wxDECLARE_SYM_FUNCTION);
    210297
     298private:
     299    wxDO_FOR_ALL_SYM_FUNCS_REQUIRED_PRIVATE(wxDECLARE_SYM_FUNCTION);
     300    wxDO_FOR_ALL_SYM_FUNCS_OPTIONAL(wxDECLARE_SYM_FUNCTION);
     301
     302public:
     303
    211304    #undef wxDECLARE_SYM_FUNCTION
    212305
    213306    // load all functions from DLL, return true if ok
     
    220313    static void LogError(const wxChar *func);
    221314
    222315    // return textual representation of the value of given symbol
    223     static wxString DumpSymbol(PSYMBOL_INFO pSymInfo, void *pVariable);
     316    static wxString DumpSymbol(wxPSYMBOL_INFO pSymInfo, void *pVariable);
    224317
    225318    // return the name of the symbol with given type index
    226     static wxString GetSymbolName(PSYMBOL_INFO pSymInfo);
     319    static wxString GetSymbolName(wxPSYMBOL_INFO pSymInfo);
    227320
    228321private:
    229322    // dereference the given symbol, i.e. return symbol which is not a
     
    233326    // dereferenced the symbol
    234327    //
    235328    // return the tag of the dereferenced symbol
    236     static SymbolTag DereferenceSymbol(PSYMBOL_INFO pSymInfo, void **ppData);
     329    static SymbolTag DereferenceSymbol(wxPSYMBOL_INFO pSymInfo, void **ppData);
    237330
    238     static wxString DumpField(PSYMBOL_INFO pSymInfo,
     331    static wxString DumpField(wxPSYMBOL_INFO pSymInfo,
    239332                              void *pVariable,
    240333                              unsigned level);
    241334
    242335    static wxString DumpBaseType(BasicType bt, DWORD64 length, void *pVariable);
    243336
    244     static wxString DumpUDT(PSYMBOL_INFO pSymInfo,
     337    static wxString DumpUDT(wxPSYMBOL_INFO pSymInfo,
    245338                            void *pVariable,
    246339                            unsigned level = 0);
     340
     341    static bool BindDbgHelpFunctions(const wxDynamicLibrary& dllDbgHelp);
     342    static bool DoInit();
    247343};
    248344
    249345#endif // wxUSE_DBGHELP
  • include/wx/msw/stackwalk.h

     
    22// Name:        wx/msw/stackwalk.h
    33// Purpose:     wxStackWalker for MSW
    44// Author:      Vadim Zeitlin
    5 // Modified by:
     5// Modified by: Suzumizaki-kimitaka 2013-04-09
    66// Created:     2005-01-08
    77// RCS-ID:      $Id$
    88// Copyright:   (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
     
    2020
    2121// and these in dbghelp.h
    2222struct _SYMBOL_INFO;
     23struct _SYMBOL_INFOW;
    2324
    2425// ----------------------------------------------------------------------------
    2526// wxStackFrame
     
    5354    GetParam(size_t n, wxString *type, wxString *name, wxString *value) const;
    5455
    5556    // callback used by OnGetParam(), don't call directly
    56     void OnParam(_SYMBOL_INFO *pSymInfo);
     57#ifdef UNICODE
     58    void OnParam(_SYMBOL_INFOW * pSymInfo);
     59#else
     60    void OnParam(_SYMBOL_INFO * pSymInfo);
     61#endif
    5762
    5863protected:
    5964    virtual void OnGetName();
  • src/msw/debughlp.cpp

     
    22// Name:        src/msw/debughlp.cpp
    33// Purpose:     various Win32 debug helpers
    44// Author:      Vadim Zeitlin
    5 // Modified by:
     5// Modified by: Suzumizaki-kimitaka 2013-04-10
    66// Created:     2005-01-08 (extracted from crashrpt.cpp)
    77// RCS-ID:      $Id$
    88// Copyright:   (c) 2003-2005 Vadim Zeitlin <vadim@wxwindows.org>
     
    6363
    6464// load all function we need from the DLL
    6565
    66 static bool BindDbgHelpFunctions(const wxDynamicLibrary& dllDbgHelp)
     66/* static */
     67bool wxDbgHelpDLL::BindDbgHelpFunctions(const wxDynamicLibrary& dllDbgHelp)
    6768{
    6869    #define LOAD_SYM_FUNCTION(func, name)                                     \
    6970        wxDbgHelpDLL::func = (wxDbgHelpDLL::func ## _t)                       \
     
    7475            return false;                                                     \
    7576        }
    7677
    77     wxDO_FOR_ALL_SYM_FUNCS(LOAD_SYM_FUNCTION);
     78    wxDO_FOR_ALL_SYM_FUNCS_REQUIRED(LOAD_SYM_FUNCTION);
    7879
    7980    #undef LOAD_SYM_FUNCTION
    8081
     82    #define LOAD_SYM_FUNCTION_OPTIONAL(func, name)                            \
     83        if ( dllDbgHelp.HasSymbol(wxT(#name)) )                               \
     84        {                                                                     \
     85            wxDbgHelpDLL::func = (wxDbgHelpDLL::func ## _t)                   \
     86                dllDbgHelp.GetSymbol(wxT(#name));                             \
     87        }
     88   
     89    wxDO_FOR_ALL_SYM_FUNCS_OPTIONAL(LOAD_SYM_FUNCTION_OPTIONAL);
     90
     91    #undef LOAD_SYM_FUNCTION_CAN_FAIL
     92
    8193    return true;
    8294}
    8395
    8496// called by Init() if we hadn't done this before
    85 static bool DoInit()
     97/* static */
     98bool wxDbgHelpDLL::DoInit()
    8699{
    87100    wxDynamicLibrary dllDbgHelp(wxT("dbghelp.dll"), wxDL_VERBATIM);
    88101    if ( dllDbgHelp.IsLoaded() )
     
    171184
    172185static inline
    173186bool
    174 DoGetTypeInfo(PSYMBOL_INFO pSym, IMAGEHLP_SYMBOL_TYPE_INFO type, void *rc)
     187DoGetTypeInfo(wxPSYMBOL_INFO pSym, IMAGEHLP_SYMBOL_TYPE_INFO type, void *rc)
    175188{
    176189    return DoGetTypeInfo(pSym->ModBase, pSym->TypeIndex, type, rc);
    177190}
    178191
    179192static inline
    180 wxDbgHelpDLL::BasicType GetBasicType(PSYMBOL_INFO pSym)
     193wxDbgHelpDLL::BasicType GetBasicType(wxPSYMBOL_INFO pSym)
    181194{
    182195    wxDbgHelpDLL::BasicType bt;
    183196    return DoGetTypeInfo(pSym, TI_GET_BASETYPE, &bt)
     
    186199}
    187200
    188201/* static */
    189 wxString wxDbgHelpDLL::GetSymbolName(PSYMBOL_INFO pSym)
     202wxString wxDbgHelpDLL::GetSymbolName(wxPSYMBOL_INFO pSym)
    190203{
    191204    wxString s;
    192205
     
    290303}
    291304
    292305wxString
    293 wxDbgHelpDLL::DumpField(PSYMBOL_INFO pSym, void *pVariable, unsigned level)
     306wxDbgHelpDLL::DumpField(wxPSYMBOL_INFO pSym, void *pVariable, unsigned level)
    294307{
    295308    wxString s;
    296309
     
    337350
    338351
    339352                // now pass to the type representing the type of this member
    340                 SYMBOL_INFO sym = *pSym;
     353                wxSYMBOL_INFO sym = *pSym;
    341354                if ( !DoGetTypeInfo(pSym, TI_GET_TYPEID, &sym.TypeIndex) )
    342355                    break;
    343356
     
    388401}
    389402
    390403/* static */ wxString
    391 wxDbgHelpDLL::DumpUDT(PSYMBOL_INFO pSym, void *pVariable, unsigned level)
     404wxDbgHelpDLL::DumpUDT(wxPSYMBOL_INFO pSym, void *pVariable, unsigned level)
    392405{
    393406    wxString s;
    394407
     
    455468        s << wxT(" {\n");
    456469
    457470        // Iterate through all children
    458         SYMBOL_INFO sym;
     471        wxSYMBOL_INFO sym;
    459472        wxZeroMemory(sym);
    460473        sym.ModBase = pSym->ModBase;
    461474        for ( unsigned i = 0; i < dwChildrenCount; i++ )
     
    487500
    488501/* static */
    489502wxDbgHelpDLL::SymbolTag
    490 wxDbgHelpDLL::DereferenceSymbol(PSYMBOL_INFO pSym, void **ppData)
     503wxDbgHelpDLL::DereferenceSymbol(wxPSYMBOL_INFO pSym, void **ppData)
    491504{
    492505    SymbolTag tag = SYMBOL_TAG_NULL;
    493506    for ( ;; )
     
    524537}
    525538
    526539/* static */ wxString
    527 wxDbgHelpDLL::DumpSymbol(PSYMBOL_INFO pSym, void *pVariable)
     540wxDbgHelpDLL::DumpSymbol(wxPSYMBOL_INFO pSym, void *pVariable)
    528541{
    529542    wxString s;
    530     SYMBOL_INFO symDeref = *pSym;
     543    wxSYMBOL_INFO symDeref = *pSym;
    531544    switch ( DereferenceSymbol(&symDeref, &pVariable) )
    532545    {
    533546        default:
     
    554567}
    555568
    556569// ----------------------------------------------------------------------------
     570// do the best functions and structures
     571// ----------------------------------------------------------------------------
     572
     573struct wxMswEnmLddMdlsHelperStruct
     574{
     575public:
     576    wxMswEnmLddMdlsHelperStruct(wxPENUMLOADED_MODULES_CALLBACK64 ptr, PVOID content)
     577        : m_pointer_to_callback(ptr), m_user_content(content)
     578    { }
     579    wxPENUMLOADED_MODULES_CALLBACK64 m_pointer_to_callback;
     580    PVOID m_user_content;
     581};
     582
     583#ifdef UNICODE
     584
     585static BOOL CALLBACK wxMswEnmLddMdlsCallback1(
     586    PCSTR ModuleName, DWORD64 ModuleBase, ULONG ModuleSize, PVOID UserContext)
     587{
     588    wxMswEnmLddMdlsHelperStruct& alternate =
     589        *(wxMswEnmLddMdlsHelperStruct*)(UserContext);
     590
     591    const wxWCharBuffer buf = wxConvLocal.cMB2WC(ModuleName, wxNO_LEN, NULL);
     592    return (*alternate.m_pointer_to_callback)
     593        (buf.data(), ModuleBase, ModuleSize, alternate.m_user_content);
     594}
     595
     596static BOOL CALLBACK wxMswEnmLddMdlsCallback2(
     597    PCSTR ModuleName, DWORD_PTR ModuleBase, ULONG ModuleSize, PVOID UserContext)
     598{
     599    wxMswEnmLddMdlsHelperStruct& alternate =
     600        *(wxMswEnmLddMdlsHelperStruct*)(UserContext);
     601
     602    const wxWCharBuffer buf = wxConvLocal.cMB2WC(ModuleName, wxNO_LEN, NULL);
     603    return (*alternate.m_pointer_to_callback)
     604        (buf.data(), ModuleBase, ModuleSize, alternate.m_user_content);
     605}
     606
     607#else
     608
     609static BOOL CALLBACK wxMswEnmLddMdlsCallback(
     610    PCSTR ModuleName, DWORD_PTR ModuleBase, ULONG ModuleSize, PVOID UserContext)
     611{
     612    wxMswEnmLddMdlsHelperStruct& alternate =
     613        *(wxMswEnmLddMdlsHelperStruct*)(UserContext);
     614
     615    return (*alternate.m_pointer_to_callback)
     616        (ModuleName, ModuleBase, ModuleSize, alternate.m_user_content);
     617}
     618
     619#endif // UNICODE
     620
     621/* static */
     622BOOL wxDbgHelpDLL::EnumerateLoadedModulesT(
     623    HANDLE handle, wxPENUMLOADED_MODULES_CALLBACK64 callback, PVOID pvoid)
     624{
     625#ifdef UNICODE
     626    if (EnumerateLoadedModulesW64)
     627    {
     628        const BOOL retVal = (*EnumerateLoadedModulesW64)(handle, callback, pvoid);
     629        if (retVal)
     630            return retVal;
     631    }
     632    if (EnumerateLoadedModules64)
     633    {
     634        wxMswEnmLddMdlsHelperStruct p(callback, pvoid);
     635        const BOOL retVal =
     636            (*EnumerateLoadedModules64)
     637                (handle, &wxMswEnmLddMdlsCallback1, (PVOID)(&p));
     638        if (retVal)
     639            return retVal;
     640    }
     641    if (EnumerateLoadedModules)
     642    {
     643        wxMswEnmLddMdlsHelperStruct p(callback, pvoid);
     644        const BOOL retVal =
     645            (*EnumerateLoadedModules)
     646                (handle, &wxMswEnmLddMdlsCallback2, (PVOID)(&p));
     647        if (retVal)
     648            return retVal;
     649    }
     650    return FALSE;
     651#else
     652    if (EnumerateLoadedModules64)
     653    {
     654        const BOOL retVal = (*EnumerateLoadedModules64)(handle, callback, pvoid);
     655        if (retVal)
     656            return retVal;
     657    }
     658    if (EnumerateLoadedModules)
     659    {
     660        wxMswEnmLddMdlsHelperStruct p(callback, pvoid);
     661        const BOOL retVal =
     662            (*EnumerateLoadedModules)
     663                (handle, &wxMswEnmLddMdlsCallback, (PVOID)(&p));
     664        if (retVal)
     665            return retVal;
     666    }
     667    return FALSE;
     668#endif
     669}
     670
     671/* static */
     672BOOL wxDbgHelpDLL::SymInitializeT(HANDLE hProcess, LPCTSTR UserSearchPath, BOOL fInvadeProcess)
     673{
     674#ifdef UNICODE
     675    if (SymInitializeW)
     676    {
     677        const BOOL retVal = (*SymInitializeW)(hProcess, UserSearchPath, fInvadeProcess);
     678        if (retVal)
     679            return retVal;
     680    }
     681    if (SymInitialize)
     682    {
     683        BOOL retVal;
     684        if (UserSearchPath)
     685        {
     686            const wxCharBuffer buf = wxConvLocal.cWC2MB(UserSearchPath, wxNO_LEN, NULL);
     687            retVal = (*SymInitialize)(hProcess, buf.data(), fInvadeProcess);
     688        }
     689        else
     690        {
     691            retVal = (*SymInitialize)(hProcess, NULL, fInvadeProcess);
     692        }
     693        return retVal;
     694    }
     695    return FALSE;
     696#else
     697    if (SymInitialize)
     698    {
     699        return (*SymInitialize)(hProcess, UserSearchPath, fInvadeProcess);
     700    }
     701    return FALSE;
     702#endif
     703}
     704
     705/* static */
     706BOOL wxDbgHelpDLL::SymFromAddrT(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, wxPSYMBOL_INFO Symbol)
     707{
     708#ifdef UNICODE
     709    if (SymFromAddrW)
     710    {
     711        const BOOL retVal = (*SymFromAddrW)(hProcess, Address, Displacement, Symbol);
     712        if (retVal)
     713            return retVal;
     714    }
     715    if (SymFromAddr)
     716    {
     717        wxScopedPtr<BYTE> symbolBuffer(new BYTE[sizeof(SYMBOL_INFO) + Symbol->MaxNameLen*sizeof(CHAR)]);
     718        PSYMBOL_INFO data = (SYMBOL_INFO*)(symbolBuffer.get());
     719        wxZeroMemory(*data);
     720        data->SizeOfStruct = sizeof(SYMBOL_INFO);
     721        data->MaxNameLen = Symbol->MaxNameLen;
     722        if (! (*SymFromAddr)(hProcess, Address, Displacement, data))
     723        {
     724            return FALSE;
     725        }
     726
     727        // We can't refer data->NameLen. It seems to be unmodified.
     728        const wxWCharBuffer buf = wxConvLocal.cMB2WC(data->Name, wxNO_LEN, NULL);
     729       
     730        Symbol->TypeIndex = data->TypeIndex;
     731        Symbol->Reserved[0] = data->Reserved[0];
     732        Symbol->Reserved[1] = data->Reserved[1];
     733        Symbol->Index = data->Index;
     734        Symbol->Size = data->Size;
     735        Symbol->ModBase = data->ModBase;
     736        Symbol->Flags = data->Flags;
     737        Symbol->Value = data->Value;
     738        Symbol->Address = data->Address;
     739        Symbol->Register = data->Register;
     740        Symbol->Scope = data->Scope;
     741        Symbol->Tag = data->Tag;
     742        Symbol->NameLen = buf.length();
     743        wxStrncpy(Symbol->Name, buf.data(), Symbol->MaxNameLen);
     744        return TRUE;
     745    }
     746    return FALSE;
     747#else
     748    if (SymFromAddr)
     749    {
     750        return (*SymFromAddr)(hProcess, Address, Displacement, Symbol);
     751    }
     752    return FALSE;
     753#endif
     754}
     755
     756/* static */
     757BOOL wxDbgHelpDLL::SymGetLineFromAddrT(HANDLE hProcess, DWORD64 dwAddr, PDWORD pdrDisplacement, wxPIMAGEHLP_LINE Line)
     758{
     759#ifdef UNICODE
     760    if (SymGetLineFromAddrW64)
     761    {
     762        const BOOL retVal = (*SymGetLineFromAddrW64)(hProcess, dwAddr, pdrDisplacement, Line);
     763        if (retVal)
     764            return retVal;
     765        // TODO: seems always fail with GetLastError() returns 487 with 32bit binary on 64 bit Windows.
     766    }
     767    static WCHAR staticBuf[MAX_PATH];
     768    if (SymGetLineFromAddr64)
     769    {
     770        IMAGEHLP_LINE64 LineAlternate;
     771        LineAlternate.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
     772        if ((*SymGetLineFromAddr64)(hProcess, dwAddr, pdrDisplacement, &LineAlternate))
     773        {
     774            const wxWCharBuffer ConvBuf =
     775                wxConvLocal.cMB2WC(LineAlternate.FileName, wxNO_LEN, NULL);
     776            wxStrncpy(staticBuf, ConvBuf.data(), MAX_PATH);
     777            Line->Key = LineAlternate.Key;
     778            Line->LineNumber = LineAlternate.LineNumber;
     779            Line->FileName = staticBuf;
     780            Line->Address = LineAlternate.Address;
     781            return TRUE;
     782        }
     783    }
     784    if (SymGetLineFromAddr)
     785    {
     786        IMAGEHLP_LINE LineAlternate;
     787        LineAlternate.SizeOfStruct = sizeof(IMAGEHLP_LINE);
     788        if ((*SymGetLineFromAddr)(hProcess, dwAddr, pdrDisplacement, &LineAlternate))
     789        {
     790            const wxWCharBuffer ConvBuf =
     791                wxConvLocal.cMB2WC(LineAlternate.FileName, wxNO_LEN, NULL);
     792            wxStrncpy(staticBuf, ConvBuf.data(), MAX_PATH);
     793            Line->Key = LineAlternate.Key;
     794            Line->LineNumber = LineAlternate.LineNumber;
     795            Line->FileName = staticBuf;
     796            Line->Address = LineAlternate.Address;
     797            return TRUE;
     798        }
     799    }
     800    return FALSE;
     801#else
     802    if (SymGetLineFromAddr64)
     803    {
     804        return (*SymGetLineFromAddr64)(hProcess, dwAddr, pdrDisplacement, Line);
     805    }
     806    if (SymGetLineFromAddr)
     807    {
     808        IMAGEHLP_LINE LineAlternate;
     809        LineAlternate.SizeOfStruct = sizeof(IMAGEHLP_LINE);
     810        if ((*SymGetLineFromAddr)(hProcess, dwAddr, pdrDisplacement, &LineAlternate))
     811        {
     812            Line->Key = LineAlternate.Key;
     813            Line->LineNumber = LineAlternate.LineNumber;
     814            Line->FileName = LineAlternate.FileName;
     815            Line->Address = LineAlternate.Address;
     816            return TRUE;
     817        }
     818    }
     819    return FALSE;
     820#endif
     821}
     822
     823struct wxMswSymEnumSymbolsHelperStruct
     824{
     825public:
     826    wxMswSymEnumSymbolsHelperStruct(PSYM_ENUMERATESYMBOLS_CALLBACKW ptr, PVOID content)
     827        : m_pointer_to_callback(ptr), m_user_content(content)
     828    { }
     829    PSYM_ENUMERATESYMBOLS_CALLBACKW m_pointer_to_callback;
     830    PVOID m_user_content;
     831};
     832
     833#ifdef UNICODE
     834
     835static BOOL CALLBACK wxMswSymEnumSymbolsHelperCallback(
     836    PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)
     837{
     838    wxMswSymEnumSymbolsHelperStruct& alternate =
     839        *(wxMswSymEnumSymbolsHelperStruct*)(UserContext);
     840    const wxWCharBuffer buf = wxConvLocal.cMB2WC(pSymInfo->Name, pSymInfo->MaxNameLen, NULL);
     841    wxScopedPtr<BYTE> symbolBuffer(new BYTE[sizeof(SYMBOL_INFOW) + buf.length()*sizeof(WCHAR)]);
     842    SYMBOL_INFOW* data = (SYMBOL_INFOW*)(symbolBuffer.get());
     843    data->SizeOfStruct = sizeof(SYMBOL_INFOW);
     844    data->TypeIndex = pSymInfo->TypeIndex;
     845    data->Reserved[0] = pSymInfo->Reserved[0];
     846    data->Reserved[1] = pSymInfo->Reserved[1];
     847    data->Index = pSymInfo->Index;
     848    data->Size = pSymInfo->Size;
     849    data->ModBase = pSymInfo->ModBase;
     850    data->Flags = pSymInfo->Flags;
     851    data->Value = pSymInfo->Value;
     852    data->Address = pSymInfo->Address;
     853    data->Register = pSymInfo->Register;
     854    data->Scope = pSymInfo->Scope;
     855    data->Tag = pSymInfo->Tag;
     856    data->NameLen = pSymInfo->NameLen;
     857    data->MaxNameLen = pSymInfo->MaxNameLen;
     858    wxStrncpy(data->Name, buf.data(), buf.length());
     859    BOOL retVal = (*alternate.m_pointer_to_callback)(data, SymbolSize, alternate.m_user_content);
     860    return retVal;
     861}
     862
     863#endif // UNICODE
     864
     865/* static */
     866BOOL wxDbgHelpDLL::SymEnumSymbolsT(HANDLE hProcess, ULONG64 baseOfDll, PCTSTR Mask,
     867                    wxPSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback, const PVOID UserContext)
     868{
     869#ifdef UNICODE
     870    if (SymEnumSymbolsW)
     871    {
     872        const BOOL retVal = (*SymEnumSymbolsW)(hProcess, baseOfDll, Mask, EnumSymbolsCallback, UserContext);
     873        if (retVal)
     874            return retVal;
     875    }
     876    if (SymEnumSymbols)
     877    {
     878        wxMswSymEnumSymbolsHelperStruct p(EnumSymbolsCallback, UserContext);       
     879        const wxCharBuffer buf = wxConvLocal.cWC2MB(Mask ? Mask : L"", wxNO_LEN, NULL);
     880        return (*SymEnumSymbols)(hProcess, baseOfDll, buf.data(),
     881                                 wxMswSymEnumSymbolsHelperCallback, (PVOID)(&p));
     882    }
     883    return FALSE;
     884#else
     885    if (SymEnumSymbols)
     886    {
     887        return (*SymEnumSymbols)(hProcess, baseOfDll, Mask, EnumSymbolsCallback, UserContext);
     888    }
     889    return FALSE;
     890#endif
     891}
     892
     893// ----------------------------------------------------------------------------
    557894// debugging helpers
    558895// ----------------------------------------------------------------------------
    559896
     
    7801117#endif // NDEBUG
    7811118
    7821119#endif // wxUSE_DBGHELP
     1120
  • src/msw/dlmsw.cpp

     
    22// Name:        src/msw/dlmsw.cpp
    33// Purpose:     Win32-specific part of wxDynamicLibrary and related classes
    44// Author:      Vadim Zeitlin
    5 // Modified by:
     5// Modified by: Suzumizaki-kimitaka 2013-04-09
    66// Created:     2005-01-10 (partly extracted from common/dynlib.cpp)
    77// RCS-ID:      $Id$
    88// Copyright:   (c) 1998-2005 Vadim Zeitlin <vadim@wxwindows.org>
     
    8080        wxVersionDLL *verDLL;
    8181    };
    8282
    83     // TODO: fix EnumerateLoadedModules() to use EnumerateLoadedModules64()
    84     #ifdef __WIN64__
    85         typedef DWORD64 DWORD_32_64;
    86     #else
    87         typedef DWORD DWORD_32_64;
    88     #endif
    89 
    9083    static BOOL CALLBACK
    91     EnumModulesProc(PCSTR name, DWORD_32_64 base, ULONG size, void *data);
     84    EnumModulesProc(PCTSTR name, DWORD64 base, ULONG size, PVOID data);
    9285};
    9386
    9487// ============================================================================
     
    116109        #endif // UNICODE/ANSI
    117110
    118111        #define LOAD_VER_FUNCTION(name)                                       \
    119             m_pfn ## name = (name ## _t)m_dll.GetSymbol(wxT(#name SUFFIX));    \
     112            m_pfn ## name = (name ## _t)m_dll.GetSymbol(wxT(#name SUFFIX));   \
    120113        if ( !m_pfn ## name )                                                 \
    121114        {                                                                     \
    122115            m_dll.Unload();                                                   \
     
    175168
    176169/* static */
    177170BOOL CALLBACK
    178 wxDynamicLibraryDetailsCreator::EnumModulesProc(PCSTR name,
    179                                                 DWORD_32_64 base,
     171wxDynamicLibraryDetailsCreator::EnumModulesProc(PCTSTR name,
     172                                                DWORD64 base,
    180173                                                ULONG size,
    181                                                 void *data)
     174                                                PVOID data)
    182175{
    183176    EnumModulesProcParams *params = (EnumModulesProcParams *)data;
    184177
    185178    wxDynamicLibraryDetails *details = new wxDynamicLibraryDetails;
    186179
    187180    // fill in simple properties
     181#ifdef UNICODE
    188182    details->m_name = name;
     183#else
     184    details->m_name = wxString(name, wxConvLocal);
     185#endif
    189186    details->m_address = wxUIntToPtr(base);
    190187    details->m_length = size;
    191188
     
    323320        params.dlls = &dlls;
    324321        params.verDLL = &verDLL;
    325322
    326         // Note that the cast of EnumModulesProc is needed because the type of
    327         // PENUMLOADED_MODULES_CALLBACK changed: in old SDK versions its first
    328         // argument was non-const PSTR while now it's PCSTR. By explicitly
    329         // casting to whatever the currently used headers require we ensure
    330         // that the code compilers in any case.
    331         if ( !wxDbgHelpDLL::EnumerateLoadedModules
     323        if ( !wxDbgHelpDLL::EnumerateLoadedModulesT
    332324                            (
    333325                                ::GetCurrentProcess(),
    334                                 (PENUMLOADED_MODULES_CALLBACK)
    335326                                wxDynamicLibraryDetailsCreator::EnumModulesProc,
    336327                                &params
    337328                            ) )
    338329        {
    339             wxLogLastError(wxT("EnumerateLoadedModules"));
     330            wxLogLastError(wxT("EnumerateLoadedModulesT"));
    340331        }
    341332    }
    342333#endif // wxUSE_DBGHELP
  • src/msw/stackwalk.cpp

     
    22// Name:        src/msw/stackwalk.cpp
    33// Purpose:     wxStackWalker implementation for Win32
    44// Author:      Vadim Zeitlin
    5 // Modified by: Artur Bac 2010-10-01 AMD64 Port
     5// Modified by: Artur Bac 2010-10-01 AMD64 Port,
     6//              Suzumizaki-kimitaka 2013-04-09
    67// Created:     2005-01-08
    78// RCS-ID:      $Id$
    89// Copyright:   (c) 2003-2005 Vadim Zeitlin <vadim@wxwindows.org>
     
    5253
    5354    // get the name of the function for this stack frame entry
    5455    static const size_t MAX_NAME_LEN = 1024;
    55     BYTE symbolBuffer[sizeof(SYMBOL_INFO) + MAX_NAME_LEN];
     56    BYTE symbolBuffer[sizeof(wxSYMBOL_INFO) + MAX_NAME_LEN*sizeof(TCHAR)];
    5657    wxZeroMemory(symbolBuffer);
    5758
    58     PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)symbolBuffer;
    59     pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
     59    wxPSYMBOL_INFO pSymbol = (wxPSYMBOL_INFO)symbolBuffer;
     60    pSymbol->SizeOfStruct = sizeof(wxSYMBOL_INFO);
    6061    pSymbol->MaxNameLen = MAX_NAME_LEN;
    6162
    6263    DWORD64 symDisplacement = 0;
    63     if ( !wxDbgHelpDLL::SymFromAddr
     64    if ( !wxDbgHelpDLL::SymFromAddrT
    6465                        (
    6566                            ::GetCurrentProcess(),
    6667                            GetSymAddr(),
     
    6869                            pSymbol
    6970                        ) )
    7071    {
    71         wxDbgHelpDLL::LogError(wxT("SymFromAddr"));
     72        wxDbgHelpDLL::LogError(wxT("SymFromAddrT"));
    7273        return;
    7374    }
    74 
    75     m_name = wxString::FromAscii(pSymbol->Name);
     75#ifdef UNICODE
     76    m_name = pSymbol->Name;
     77#else
     78    m_name = wxString(pSymbol->Name, wxConvLocal);
     79#endif
    7680    m_offset = symDisplacement;
    7781}
    7882
     
    8488    m_hasLocation = true;
    8589
    8690    // get the source line for this stack frame entry
    87     IMAGEHLP_LINE lineInfo = { sizeof(IMAGEHLP_LINE) };
     91    wxIMAGEHLP_LINE lineInfo = { sizeof(wxIMAGEHLP_LINE) };
    8892    DWORD dwLineDisplacement;
    89     if ( !wxDbgHelpDLL::SymGetLineFromAddr
     93    if ( !wxDbgHelpDLL::SymGetLineFromAddrT
    9094                        (
    9195                            ::GetCurrentProcess(),
    9296                            GetSymAddr(),
     
    96100    {
    97101        // it is normal that we don't have source info for some symbols,
    98102        // notably all the ones from the system DLLs...
    99         //wxDbgHelpDLL::LogError(wxT("SymGetLineFromAddr"));
     103        //wxDbgHelpDLL::LogError(wxT("SymGetLineFromAddr64"));
    100104        return;
    101105    }
    102 
    103     m_filename = wxString::FromAscii(lineInfo.FileName);
     106#ifdef UNICODE
     107    m_filename = lineInfo.FileName;
     108#else
     109    m_filename = wxString(lineInfo.FileName, wxConvLocal);
     110#endif
    104111    m_line = lineInfo.LineNumber;
    105112}
    106113
     
    126133    return true;
    127134}
    128135
    129 void wxStackFrame::OnParam(PSYMBOL_INFO pSymInfo)
     136void wxStackFrame::OnParam(wxPSYMBOL_INFO pSymInfo)
    130137{
    131138    m_paramTypes.Add(wxEmptyString);
    132139
    133     m_paramNames.Add(wxString::FromAscii(pSymInfo->Name));
     140#ifdef UNICODE
     141    m_paramNames.Add(pSymInfo->Name);
     142#else
     143    m_paramNames.Add(wxString(pSymInfo->Name, wxConvLocal));
     144#endif
    134145
    135146    // if symbol information is corrupted and we crash, the exception is going
    136147    // to be ignored when we're called from WalkFromException() because of the
     
    159170}
    160171
    161172BOOL CALLBACK
    162 EnumSymbolsProc(PSYMBOL_INFO pSymInfo, ULONG WXUNUSED(SymSize), PVOID data)
     173EnumSymbolsProc(wxPSYMBOL_INFO pSymInfo, ULONG WXUNUSED(SymSize), PVOID data)
    163174{
    164175    wxStackFrame *frame = static_cast<wxStackFrame *>(data);
    165176
     
    196207        return;
    197208    }
    198209
    199     if ( !wxDbgHelpDLL::SymEnumSymbols
     210    if ( !wxDbgHelpDLL::SymEnumSymbolsT
    200211                        (
    201212                            ::GetCurrentProcess(),
    202213                            NULL,               // DLL base: use current context
     
    205216                            this                // data to pass to it
    206217                        ) )
    207218    {
    208         wxDbgHelpDLL::LogError(wxT("SymEnumSymbols"));
     219        wxDbgHelpDLL::LogError(wxT("SymEnumSymbolsT"));
    209220    }
    210221}
    211222
     
    233244    // below which should be a real handle... so this is what we use
    234245    const HANDLE hProcess = ::GetCurrentProcess();
    235246
    236     if ( !wxDbgHelpDLL::SymInitialize
     247    if ( !wxDbgHelpDLL::SymInitializeT
    237248                        (
    238249                            hProcess,
    239250                            NULL,   // use default symbol search path
    240251                            TRUE    // load symbols for all loaded modules
    241252                        ) )
    242253    {
    243         wxDbgHelpDLL::LogError(wxT("SymInitialize"));
     254        wxDbgHelpDLL::LogError(wxT("SymInitializeT"));
    244255
    245256        return;
    246257    }
     
    383394    return false;
    384395}
    385396
    386 void wxStackFrame::OnParam(_SYMBOL_INFO * WXUNUSED(pSymInfo))
     397void wxStackFrame::OnParam(wxPSYMBOL_INFO WXUNUSED(pSymInfo))
    387398{
    388399}
    389400