-
Notifications
You must be signed in to change notification settings - Fork 148
How To Debug Your Plugin
Debugging plugin code requires a few additional steps that are usually not necessary when debugging an application directly. The main reason for this is that the plugin is never executed directly, but loaded at some point at runtime by a host process.
Thus a plugin is never debugged directly, but instead the debugger needs to be attached to the host process, which will then be able to apply any breakpoint settings and allow proper debugging.
This slight increase in debugging difficulty is typical and expected when debugging runtime modules (see also: Steps necessary to debug a VST in digital audio workstations).
The exact steps to debug a plugin with OBS Studio differ between platforms but boil down to this:
- Prepare a local build of OBS Studio built in "Debug" configuration
- Configure the plugin build system to use "Debug" configuration
- Either setup the OBS Studio IDE project or local system to load plugins from custom locations
- Alternatively the plugin can be copied manually into the plugin destination for the local platform
- Launch OBS Studio with a debugger attached
Note
This guide does not contain any guidelines for debugging a plugin on Ubuntu. We encourage maintainers to add this information to the Wiki as well.
Developers have two choices as far as debugging their plugin in Visual Studio is concerned:
- Launch OBS Studio compiled in "Debug" configuration by a separate Visual Studio project, or
- Add the plugin project to the OBS Studio project and launch OBS Studio directly
Both variants have their own benefits and drawbacks:
- Is the easiest to set up but will limit the developer to directly browse plugin source code only
- Is more complex to set up but will allow browsing the plugin source code as well as OBS Studio source code in a single project
Warning
If the Visual Studio solutions are generated by CMake, be aware that re-configuring the project will also make CMake re-build the Visual Studio solution and thus the custom debugging setting might be overwritten with defaults.
This variant requires the developer to manually adjust their plugin solution in Visual Studio to set up a custom command that should be executed for debugging.
- Open plugin solution in Visual Studio
- Open the properties of the solution
- Under "Common Properties", change the "Single Startup Project" under "Configure Startup Projects" to your actual plugin project (it will probably be set to CMake's "ALL_BUILD" meta project by default)
The name of the plugin project should now appear in bold letters in the "Solution Explorer"
- Next, open the properties for the plugin project
- Under "Debugging", change the following values:
- For "Command" browse to the Debug
rundir
of the separate OBS Studio project. This should commonly be in a sub-directorybuild_x64\rundir\Debug
of the separate OBS Studio checkout that was built in "Debug" configuration at least once. Selectobs64.exe
from this directory - For "Working Directory", chose the same
rundir
as above - For "Environment" set up the environment variables
OBS_PLUGINS_PATH
andOBS_PLUGINS_DATA_PATH
to point to the plugin's Debugrundir
. This should also be in a sub-directorybuild_x64\rundir\Debug
of the plugin's checkout directory.- Use the pattern
VARIABLE=VALUE
, with each variable on its own line
- Use the pattern
- For "Command" browse to the Debug
- Finally, just click "Local Windows Debugger" in the toolbar to run OBS Studio and start debugging the plugin:
This setup allows setting up breakpoints in any part of the plugin code and even allows following call stacks back into OBS Studio code. Because a locally compiled version of OBS Studio is used to launch the plugin, which allows Visual Studio to access the debug symbols and thus source code of both OBS Studio as well as the plugin.
Note
In some situations breakpoints set at a very early stage of a plugin's "lifetime" might not be triggered if the Visual Studio debugger takes too long to attach itself to OBS Studio while it's launching. This is an unfortunate side-effect of the way this process works in Visual Studio. If this happens to be the case, one can try variant 2 to fix this.
The second variant requires adding the plugin and plugin-support projects to an existing OBS Studio solution and setting up the environment variables to allow OBS Studio to load the plugin from its own rundir
:
- Open an existing OBS Studio solution
- Add the plugin project and plugin-support project to the solution. The "Solution Explorer" should look similar to this:
- Open the "Debugger" properties of the
frontend\obs-studio
project and change the "Environment" property- Set up the environment variables
OBS_PLUGINS_PATH
andOBS_PLUGINS_DATA_PATH
to point to the plugin's Debugrundir
. This should also be in a sub-directorybuild_x64\rundir\Debug
of your plugin's checkout directory. - Use the pattern
VARIABLE=VALUE
, with each variable on its own line
- Set up the environment variables
- Click "Local Windows Debugger" in the toolbar to run OBS Studio and start debugging the plugin.
This setup allows setting breakpoints in OBS Studio code as well as plugin code, as both code bases are present within the solution.
Note
If desired, the plugin project can be added as a dependency to the obs-studio
project in the solution properties. This would make Visual Studio automatically re-compile the plugin if any source code changes were detected.
Xcode allows developers to either debug their plugin directly (by launching it via a pre-compiled OBS Studio from another local Xcode project) or to add the plugin project to an existing OBS Studio project which allows adding the project as a dependency to the obs-studio
target.
Tip
Ensure that both projects have identical codesigning settings to ensure that macOS will not block loading the plugin if is not signed correctly.
Warning
There is an open Pull-Request for OBS Studio to fix the broken functionality of loading plugins from paths provided via environment variables. Until that bug is fixed, step #X below will have no effect and instead the generated plugin bundle needs to be copied from its rundir to ~/Library/Application Support/obs-studio/plugins
before debugging.
- Open the plugin's Xcode project
- Select the current target from the status area at the top of the window and select "Edit Scheme..."
- In the "Info" tab, change the "Executable" by selecting "Other.." and then choosing OBS.app from a local OBS Studio project.
- The app bundle can be found in the
build_macos/UI/Debug
sub-directory of an OBS Studio checkout
- The app bundle can be found in the
- In the "Arguments" tab, add the "Environment Variables"
OBS_PLUGINS_PATH
andOBS_PLUGINS_DATA_PATH
and change their values to point to the plugin's Debugrundir
. This should be in a sub-directorybuild_macos\rundir\Debug
of the plugin's checkout directory.
- Click the play button or press
CMD+R
to start debugging the plugin
As both the plugin and OBS Studio are built in "Debug" configuration on the same machine, the debugger has no issue to read the debug symbols contained in all binaries and associate them with the source code available on the local machine.
Xcode projects can be added to any other existing project and will retain their internal structure and hierarchy. Their schemes are also added to the current project, which gives the impression of a "merged" project that contains all elements of both original projects.
- IMPORTANT: Ensure that neither the OBS Studio nor plugin Xcode projects are currently opened by Xcode
- Open an existing OBS Studio Xcode project
- Add files to the project via
File -> Add Files to "obs-studio"
- Browse to the plugin repository and select the associated Xcode project from the
build_macos
directory - Choose "Reference files in place" in the following dialog and click "Finish".
- Edit the Scheme for
obs-studio
and add the environment variablesOBS_PLUGINS_PATH
andOBS_PLUGINS_DATA_PATH
in the "Arguments" tab, setting their values to point to the plugin's Debugrundir
. This should be in a sub-directorybuild_macos\rundir\Debug
of the plugin's checkout directory. - Now the
obs-studio
target can be ran and debugged with full access to both project's source code and breakpoints can be freely set in both.
Note
To enable automatic re-compilation of the plugin if any of its source code has been changed, add the plugin target to the "Target Dependencies" of the obs-studio
target. Refer to the Xcode documentation for more information on this.
OBS Studio Developer Resources
Plugin Development | Frontend Development | Graphics Development