Ticket #15138: 20130417_for_library.patch

File 20130417_for_library.patch, 35.9 KB (added by suzumizaki, 7 years ago)

New patch for fix stack tracing codes

  • 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        BYTE* symbolBuffer = new BYTE[sizeof(SYMBOL_INFO) + Symbol->MaxNameLen*sizeof(CHAR)];
     718        PSYMBOL_INFO data = (SYMBOL_INFO*)(symbolBuffer);
     719        wxZeroMemory(*data);
     720        data->SizeOfStruct = sizeof(SYMBOL_INFO);
     721        data->MaxNameLen = Symbol->MaxNameLen;
     722        if (! (*SymFromAddr)(hProcess, Address, Displacement, data))
     723        {
     724                delete [] symbolBuffer;
     725            return FALSE;
     726        }
     727
     728        // We can't refer data->NameLen. It seems to be unmodified.
     729        const wxWCharBuffer buf = wxConvLocal.cMB2WC(data->Name, wxNO_LEN, NULL);
     730       
     731        // FIXME: I know too brute but some header names SYMBOL_INFO::Index
     732        // and the other one defines it as SYMBOL_INFO::info.
     733        const ULONG dstSize = Symbol->SizeOfStruct;
     734        CopyMemory(Symbol, data, sizeof(SYMBOL_INFO)-sizeof(CHAR));
     735        Symbol->SizeOfStruct = dstSize;
     736        Symbol->NameLen = buf.length();
     737        wxStrncpy(Symbol->Name, buf.data(), Symbol->MaxNameLen);
     738        delete [] symbolBuffer;
     739        return TRUE;
     740    }
     741    return FALSE;
     742#else
     743    if (SymFromAddr)
     744    {
     745        return (*SymFromAddr)(hProcess, Address, Displacement, Symbol);
     746    }
     747    return FALSE;
     748#endif
     749}
     750
     751/* static */
     752BOOL wxDbgHelpDLL::SymGetLineFromAddrT(HANDLE hProcess, DWORD64 dwAddr, PDWORD pdrDisplacement, wxPIMAGEHLP_LINE Line)
     753{
     754#ifdef UNICODE
     755    if (SymGetLineFromAddrW64)
     756    {
     757        const BOOL retVal = (*SymGetLineFromAddrW64)(hProcess, dwAddr, pdrDisplacement, Line);
     758        if (retVal)
     759            return retVal;
     760        // TODO: seems always fail with GetLastError() returns 487 with 32bit binary on 64 bit Windows.
     761    }
     762    static WCHAR staticBuf[MAX_PATH];
     763    if (SymGetLineFromAddr64)
     764    {
     765        IMAGEHLP_LINE64 LineAlternate;
     766        LineAlternate.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
     767        if ((*SymGetLineFromAddr64)(hProcess, dwAddr, pdrDisplacement, &LineAlternate))
     768        {
     769            const wxWCharBuffer ConvBuf =
     770                wxConvLocal.cMB2WC(LineAlternate.FileName, wxNO_LEN, NULL);
     771            wxStrncpy(staticBuf, ConvBuf.data(), MAX_PATH);
     772            Line->Key = LineAlternate.Key;
     773            Line->LineNumber = LineAlternate.LineNumber;
     774            Line->FileName = staticBuf;
     775            Line->Address = LineAlternate.Address;
     776            return TRUE;
     777        }
     778    }
     779    if (SymGetLineFromAddr)
     780    {
     781        IMAGEHLP_LINE LineAlternate;
     782        LineAlternate.SizeOfStruct = sizeof(IMAGEHLP_LINE);
     783        if ((*SymGetLineFromAddr)(hProcess, dwAddr, pdrDisplacement, &LineAlternate))
     784        {
     785            const wxWCharBuffer ConvBuf =
     786                wxConvLocal.cMB2WC(LineAlternate.FileName, wxNO_LEN, NULL);
     787            wxStrncpy(staticBuf, ConvBuf.data(), MAX_PATH);
     788            Line->Key = LineAlternate.Key;
     789            Line->LineNumber = LineAlternate.LineNumber;
     790            Line->FileName = staticBuf;
     791            Line->Address = LineAlternate.Address;
     792            return TRUE;
     793        }
     794    }
     795    return FALSE;
     796#else
     797    if (SymGetLineFromAddr64)
     798    {
     799        return (*SymGetLineFromAddr64)(hProcess, dwAddr, pdrDisplacement, Line);
     800    }
     801    if (SymGetLineFromAddr)
     802    {
     803        IMAGEHLP_LINE LineAlternate;
     804        LineAlternate.SizeOfStruct = sizeof(IMAGEHLP_LINE);
     805        if ((*SymGetLineFromAddr)(hProcess, dwAddr, pdrDisplacement, &LineAlternate))
     806        {
     807            Line->Key = LineAlternate.Key;
     808            Line->LineNumber = LineAlternate.LineNumber;
     809            Line->FileName = LineAlternate.FileName;
     810            Line->Address = LineAlternate.Address;
     811            return TRUE;
     812        }
     813    }
     814    return FALSE;
     815#endif
     816}
     817
     818struct wxMswSymEnumSymbolsHelperStruct
     819{
     820public:
     821    wxMswSymEnumSymbolsHelperStruct(PSYM_ENUMERATESYMBOLS_CALLBACKW ptr, PVOID content)
     822        : m_pointer_to_callback(ptr), m_user_content(content)
     823    { }
     824    PSYM_ENUMERATESYMBOLS_CALLBACKW m_pointer_to_callback;
     825    PVOID m_user_content;
     826};
     827
     828#ifdef UNICODE
     829
     830static BOOL CALLBACK wxMswSymEnumSymbolsHelperCallback(
     831    PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)
     832{
     833    wxMswSymEnumSymbolsHelperStruct& alternate =
     834        *(wxMswSymEnumSymbolsHelperStruct*)(UserContext);
     835    const wxWCharBuffer buf = wxConvLocal.cMB2WC(pSymInfo->Name, pSymInfo->MaxNameLen, NULL);
     836    BYTE* symbolBuffer = new BYTE[sizeof(SYMBOL_INFOW) + buf.length()*sizeof(WCHAR)];
     837    SYMBOL_INFOW* data = (SYMBOL_INFOW*)(symbolBuffer);
     838   
     839    // FIXME: I know too brute but some header names SYMBOL_INFO::Index
     840    // and the other one defines it as SYMBOL_INFO::info.
     841    CopyMemory(data, pSymInfo, sizeof(SYMBOL_INFO)-sizeof(CHAR));
     842    data->SizeOfStruct = sizeof(SYMBOL_INFOW);
     843    wxStrncpy(data->Name, buf.data(), buf.length());
     844    BOOL retVal = (*alternate.m_pointer_to_callback)(data, SymbolSize, alternate.m_user_content);
     845    delete [] symbolBuffer;
     846    return retVal;
     847}
     848
     849#endif // UNICODE
     850
     851/* static */
     852BOOL wxDbgHelpDLL::SymEnumSymbolsT(HANDLE hProcess, ULONG64 baseOfDll, PCTSTR Mask,
     853                    wxPSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback, const PVOID UserContext)
     854{
     855#ifdef UNICODE
     856    if (SymEnumSymbolsW)
     857    {
     858        const BOOL retVal = (*SymEnumSymbolsW)(hProcess, baseOfDll, Mask, EnumSymbolsCallback, UserContext);
     859        if (retVal)
     860            return retVal;
     861    }
     862    if (SymEnumSymbols)
     863    {
     864        wxMswSymEnumSymbolsHelperStruct p(EnumSymbolsCallback, UserContext);       
     865        const wxCharBuffer buf = wxConvLocal.cWC2MB(Mask ? Mask : L"", wxNO_LEN, NULL);
     866        return (*SymEnumSymbols)(hProcess, baseOfDll, buf.data(),
     867                                 wxMswSymEnumSymbolsHelperCallback, (PVOID)(&p));
     868    }
     869    return FALSE;
     870#else
     871    if (SymEnumSymbols)
     872    {
     873        return (*SymEnumSymbols)(hProcess, baseOfDll, Mask, EnumSymbolsCallback, UserContext);
     874    }
     875    return FALSE;
     876#endif
     877}
     878
     879// ----------------------------------------------------------------------------
    557880// debugging helpers
    558881// ----------------------------------------------------------------------------
    559882
     
    7801103#endif // NDEBUG
    7811104
    7821105#endif // wxUSE_DBGHELP
     1106
  • 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>
     
    2929#include "wx/msw/debughlp.h"
    3030#include "wx/filename.h"
    3131
     32// defined for TDM's GCC/mingw32
     33#ifndef PCTSTR
     34#define PCTSTR LPCTSTR
     35#endif
     36
    3237const wxString wxDynamicLibrary::ms_dllext(wxT(".dll"));
    3338
    3439// ----------------------------------------------------------------------------
     
    8085        wxVersionDLL *verDLL;
    8186    };
    8287
    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 
    9088    static BOOL CALLBACK
    91     EnumModulesProc(PCSTR name, DWORD_32_64 base, ULONG size, void *data);
     89    EnumModulesProc(PCTSTR name, DWORD64 base, ULONG size, PVOID data);
    9290};
    9391
    9492// ============================================================================
     
    116114        #endif // UNICODE/ANSI
    117115
    118116        #define LOAD_VER_FUNCTION(name)                                       \
    119             m_pfn ## name = (name ## _t)m_dll.GetSymbol(wxT(#name SUFFIX));    \
     117            m_pfn ## name = (name ## _t)m_dll.GetSymbol(wxT(#name SUFFIX));   \
    120118        if ( !m_pfn ## name )                                                 \
    121119        {                                                                     \
    122120            m_dll.Unload();                                                   \
     
    175173
    176174/* static */
    177175BOOL CALLBACK
    178 wxDynamicLibraryDetailsCreator::EnumModulesProc(PCSTR name,
    179                                                 DWORD_32_64 base,
     176wxDynamicLibraryDetailsCreator::EnumModulesProc(PCTSTR name,
     177                                                DWORD64 base,
    180178                                                ULONG size,
    181                                                 void *data)
     179                                                PVOID data)
    182180{
    183181    EnumModulesProcParams *params = (EnumModulesProcParams *)data;
    184182
    185183    wxDynamicLibraryDetails *details = new wxDynamicLibraryDetails;
    186184
    187185    // fill in simple properties
     186#ifdef UNICODE
    188187    details->m_name = name;
     188#else
     189    details->m_name = wxString(name, wxConvLocal);
     190#endif
    189191    details->m_address = wxUIntToPtr(base);
    190192    details->m_length = size;
    191193
     
    323325        params.dlls = &dlls;
    324326        params.verDLL = &verDLL;
    325327
    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
     328        if ( !wxDbgHelpDLL::EnumerateLoadedModulesT
    332329                            (
    333330                                ::GetCurrentProcess(),
    334                                 (PENUMLOADED_MODULES_CALLBACK)
    335331                                wxDynamicLibraryDetailsCreator::EnumModulesProc,
    336332                                &params
    337333                            ) )
    338334        {
    339             wxLogLastError(wxT("EnumerateLoadedModules"));
     335            wxLogLastError(wxT("EnumerateLoadedModulesT"));
    340336        }
    341337    }
    342338#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