Archive:Debug Dynamic Link Libraries

From Official Kodi Wiki
Revision as of 15:05, 3 October 2011 by >NedBot (moved How-to-TEMP:Debug Dynamic Link Libraries to HOW-TO:Debug Dynamic Link Libraries: Bot: Moved page)
Jump to navigation Jump to search

Preparing

Symbol loading is only supported when a propper debug environment is set up on your xbox. To install one please follow this guide.

You can make xbmc capable of debugging dll's by uncommenting the following line at the beginning of dllloader.cpp

 #define ENABLE_SYMBOL_LOADING 1


This will make it possible to add the dll as a debuggable module to the xbox debug manager.

Configuration properties for the DLL

The DLL must be built with the following project settings:

  • General -> Configuration Type: Dynamic Library (.dll)


  • C/C++ -> General -> Debug Information Format: Program Database (/Zi)


  • C/C++ -> Code Generation -> Runtime Library: Multi-threaded (/MT)


  • Linker -> Debugging -> Generate Debug Info: YES (/DEBUG)


  • Linker -> Debugging -> Generate Program Database File: $(OutDir)/$(ProjectName).pdb


  • You may also want to disable compiler optimizations (though this is often not necessary).


Note that settings 2, 4 and 5 aren't needed for a normal dll for CVS. Also, the Runtime Library setting (3) should be set to Multi-threaded DLL (/MD) to reduce the dll size for CVS.

It is suggested that you configure the project settings for 2 configurations – a release build that will disable debugging and link against the Multi-threaded DLL, and a debug build using the above configuration. Example DLL sources using this configuration are the sources for libmpcdec.dll found in docs/sources/paplayer.

Normal dlls

Dll's are accessed via a wrapper class in xbmc. If you add a new dll please define your own wrapper class. An exception are screensaves and visualisations these dlls have a predefined interface. (See below)

Example declaration of a dll wrapper class

 public:
   virtual void foo (unsigned int type, char* szTest)=0;
   virtual void bar (char* szTest, unsigned int type)=0;
 };
 class DllExample : public DllDynamic, DllExampleInterface
 {
   DECLARE_DLL_WRAPPER(DllExample, Q:\\system\\Example.dll)
   LOAD_SYMBOLS()  // add this if you want to load debug symbols for the dll
   DEFINE_METHOD2(void, foo, (int p1, char* p2))
   DEFINE_METHOD_LINKAGE2(void, __stdcall, bar, (char* p1, int p2))
   BEGIN_METHOD_RESOLVE()
     RESOLVE_METHOD(foo)
     RESOLVE_METHOD_RENAME("_bar@8", bar)
   END_METHOD_RESOLVE()
 };


Just add the LOAD_SYMBOLS() macro to the dll wrapper class, to tell the DllLoader it should try to load symbols for your dll. If you want to find out more about the dll wrapper class see DynamicDll.h for more info.

Visualisations and Screensaver

Screensaver and visualisation dlls have a predefined interface. If you want to enable symbol loading for them, add the LOAD_SYMBOLS() macro to the DllScreensaver / DllVisualisation wrapper class.

Notes

  • At the moment it's only possible to debug “Release” dlls. Please build your release dll with Debug Information (Program Database)
  • To have the “real” debug feeling on release dlls, disable all optimizations when compiling your dll
  • Dll's with loaded symbols can not be unloaded from memory anymore
  • Please don't add a dll wrapper with a LOAD_SYMBOLS() macro to cvs or submit one as patch for the above reason