/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/msw/debughlp.cpp
ViewVC logotype

Diff of /trunk/3rdparty/wxWidgets/src/msw/debughlp.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 61 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 42  static const unsigned MAX_DUMP_DEPTH = 2 Line 42  static const unsigned MAX_DUMP_DEPTH = 2
42  // error message from Init()  // error message from Init()
43  static wxString gs_errMsg;  static wxString gs_errMsg;
44    
45    #if wxUSE_THREADS
46    wxMutex s_mtx_DbgHelp;
47    #endif
48    
49  // ============================================================================  // ============================================================================
50  // wxDbgHelpDLL implementation  // wxDbgHelpDLL implementation
51  // ============================================================================  // ============================================================================
# Line 53  static wxString gs_errMsg; Line 57  static wxString gs_errMsg;
57  #define DEFINE_SYM_FUNCTION(func) wxDbgHelpDLL::func ## _t wxDbgHelpDLL::func = 0  #define DEFINE_SYM_FUNCTION(func) wxDbgHelpDLL::func ## _t wxDbgHelpDLL::func = 0
58    
59  wxDO_FOR_ALL_SYM_FUNCS(DEFINE_SYM_FUNCTION);  wxDO_FOR_ALL_SYM_FUNCS(DEFINE_SYM_FUNCTION);
60    DEFINE_SYM_FUNCTION(SymRefreshModuleList);
61    
62  #undef DEFINE_SYM_FUNCTION  #undef DEFINE_SYM_FUNCTION
63    
# Line 62  wxDO_FOR_ALL_SYM_FUNCS(DEFINE_SYM_FUNCTI Line 67  wxDO_FOR_ALL_SYM_FUNCS(DEFINE_SYM_FUNCTI
67    
68  // load all function we need from the DLL  // load all function we need from the DLL
69    
70  static bool BindDbgHelpFunctions(const wxDynamicLibrary& dllDbgHelp)  bool wxDbgHelpDLL::BindFunctions(const wxDynamicLibrary& dllDbgHelp)
71  {  {
72      #define LOAD_SYM_FUNCTION(name)                                           \      #define LOAD_SYM_FUNCTION(name)                                           \
73          wxDbgHelpDLL::name = (wxDbgHelpDLL::name ## _t)                       \          name = (name ## _t)dllDbgHelp.GetSymbol(_T(#name));                   \
74                                  dllDbgHelp.GetSymbol(_T(#name));              \          if ( !name )                                                          \
         if ( !wxDbgHelpDLL::name )                                            \  
75          {                                                                     \          {                                                                     \
76              gs_errMsg += _T("Function ") _T(#name) _T("() not found.\n");     \              gs_errMsg += _T("Function ") _T(#name) _T("() not found.\n");     \
77              return false;                                                     \              return false;                                                     \
# Line 75  static bool BindDbgHelpFunctions(const w Line 79  static bool BindDbgHelpFunctions(const w
79    
80      wxDO_FOR_ALL_SYM_FUNCS(LOAD_SYM_FUNCTION);      wxDO_FOR_ALL_SYM_FUNCS(LOAD_SYM_FUNCTION);
81    
82      #undef LOAD_SYM_FUNCTION          #undef LOAD_SYM_FUNCTION
83    
84            // SymRefreshModuleList is bound separately since it requires an especially new version
85            // of WinDbgHlp (v6.5 or later).  If it binds as NULL, that's ok.  Its only needed in
86            // order to reload symbols for apps that dynamically unload/reload plugins.
87    
88            SymRefreshModuleList = (SymRefreshModuleList_t)dllDbgHelp.GetSymbol(_T("SymRefreshModuleList"));
89    
90      return true;      return true;
91  }  }
92    
93  // called by Init() if we hadn't done this before  // called by Init() if we hadn't done this before
94  static bool DoInit()  bool wxDbgHelpDLL::DoInit()
95  {  {
96      wxDynamicLibrary dllDbgHelp(_T("dbghelp.dll"), wxDL_VERBATIM);      wxDynamicLibrary dllDbgHelp(_T("dbghelp.dll"), wxDL_VERBATIM);
97      if ( dllDbgHelp.IsLoaded() )      if ( dllDbgHelp.IsLoaded() )
98      {      {
99          if ( BindDbgHelpFunctions(dllDbgHelp) )          if ( BindFunctions(dllDbgHelp) )
100          {          {
101              // turn on default options              // turn on default options
102              DWORD options = wxDbgHelpDLL::SymGetOptions();              DWORD options = SymGetOptions();
103    
104              options |= SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME | SYMOPT_DEBUG;              options |= SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME | SYMOPT_DEBUG;
105    
106              wxDbgHelpDLL::SymSetOptions(options);              SymSetOptions(options);
107    
108              dllDbgHelp.Detach();              dllDbgHelp.Detach();
109              return true;              return true;
# Line 119  static bool DoInit() Line 129  static bool DoInit()
129  /* static */  /* static */
130  bool wxDbgHelpDLL::Init()  bool wxDbgHelpDLL::Init()
131  {  {
132      // this flag is -1 until Init() is called for the first time, then it's set          // this flag is -1 until Init() is called for the first time, then it's set
133      // to either false or true depending on whether we could load the functions          // to either false or true depending on whether we could load the functions
134      static int s_loaded = -1;          static int s_loaded = -1;
135    
136    #if wxUSE_THREADS
137            wxMutexLocker lock(s_mtx_DbgHelp);
138    #endif
139    
140      if ( s_loaded == -1 )      if ( s_loaded == -1 )
141      {      {
# Line 131  bool wxDbgHelpDLL::Init() Line 145  bool wxDbgHelpDLL::Init()
145      return s_loaded != 0;      return s_loaded != 0;
146  }  }
147    
148    bool wxDbgHelpDLL::RefreshModuleList( HANDLE hProcess )
149    {
150            static bool s_syms_initialized = false;
151    
152    #if wxUSE_THREADS
153            wxMutexLocker lock(s_mtx_DbgHelp);
154    #endif
155    
156            if ( !s_syms_initialized )
157            {
158                    if ( !SymInitialize(
159                                    hProcess,
160                                    NULL,   // use default symbol search path
161                                    TRUE    // load symbols for all loaded modules
162                            ) )
163                    {
164                            wxDbgHelpDLL::LogError(_T("SymInitialize"));
165                            return false;
166                    }
167                    
168                    s_syms_initialized = true;
169            }
170            else if ( SymRefreshModuleList && !SymRefreshModuleList( hProcess ) )
171            {
172                    // If winDbgHlp v6.5 or newer, we can use this to reload symbols on-the-fly.
173                    // If not, then the app could have outdated or unloaded symbols if it dynamically
174                    // loads and unloads modules *and* performs multiple stack traces during the course
175                    // of program execution.
176    
177                    wxDbgHelpDLL::LogError(_T("SymRefreshModuleList"));
178                    return false;
179            }
180    
181        return true;
182    }
183    
184  // ----------------------------------------------------------------------------  // ----------------------------------------------------------------------------
185  // error handling  // error handling
186  // ----------------------------------------------------------------------------  // ----------------------------------------------------------------------------

Legend:
Removed from v.61  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22