HOW-TO:Debug Dynamic Link Libraries

From Official Kodi Wiki
Jump to: navigation, search
Home icon grey.png   ▶ Development ▶ HOW-TO:Debug Dynamic Link Libraries
Cleanup.png This page or section may require cleanup, updating, spellchecking, reformatting and/or updated images. Please improve this page if you can. The discussion page may contain suggestions.

Contents

1 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.

2 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)

2.1 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.

3 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.

4 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
Personal tools
Namespaces

Variants
Actions
Navigation
Wiki help
Toolbox