-
Notifications
You must be signed in to change notification settings - Fork 219
Quick tutorial on debugging the MIEngine
This wiki page will give a quick overview on how you can get started digging into the source code of the MIEngine. In this tutorial, we are going to debug a project in WSL. If you are interested in modifying the MIEngine to target some other platform, this tutorial is still probably useful to you so that you can see how to quickly test your code for the WSL scenario.
-
Follow the instruction in building the MIEngine to install Visual Studio and build this repo. Note that this tutorial requrise the "Linux and embedded development with C++" workload.
-
If you haven't already done so, clone the MIEngine repository.
-
Setup WSL
- Enable the WSL feature in Windows. See https://aka.ms/wslinstall for instructions.
- Open the Microsoft Store, and download a Linux distribution, such as 'Ubuntu 22.04 LTS'.
- Setup your WSL instance by ensuring that a compiler, linker and GDB are installed. For example, on Ubuntu you do this with
sudo apt-get update
andsudo apt-get install build-essential gdb
. - Ensure that an SSH server is installed and running. Example setup for Ubuntu:
- Install it with
sudo apt-get install openssh-server
. - Configure the port number by editing /etc/ssh/sshd_config. You likely want a high number such as '2022' to avoid conflicts. Example:
sudo nano /etc/ssh/sshd_config
, find the port setting and configure it. - Configure authentication by either setting up a pair of SSH keys, or by commenting out
PasswordAuthentication no
in sshd_config - Start ssh with
sudo service ssh start
- Install it with
The version of MIEngine that ships with Visual Studio will keep your new version from loading, so we need to tweak it so that your version is used.
- Open a developer command prompt as an Administrator
cd /d "%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\MDD\Debugger"
notepad Microsoft.MIDebugPackage.pkgdef
- Locate the following lines:
[$RootKey$\BindingPaths\{7A28CEDA-DA3E-4172-B19A-BB9C810046A6}]
"$PackageFolder$"=""
- Comment those lines out by adding a
;
in front of the lines like below:
; [$RootKey$\BindingPaths\{7A28CEDA-DA3E-4172-B19A-BB9C810046A6}]
; "$PackageFolder$"=""
- Open a non-admin Developer Command Prompt and run
devenv.com /updateConfiguration
.
-
Start your main instance of Visual Studio, and open <MIEngine-Repo-Root>\src\MIDebugEngine.sln.
-
Ensure that MIDebugPackage project is set as the startup project.
- Open Solution Explorer
- Find the 'MIDebugPackage' in the list of projects
- Right click, and invoke 'Set as Startup Project'
-
In solution explorer, find the MIDebugEngine project, and open Engine.Impl\DebuggedProcess.cs.
-
Find the
Initialize
method of the class and set a breakpoint. -
Hit F5 to start debugging. This will build the project and launch an experimental instance of Visual Studio.
-
In The experimental instance:
- Click the button to create a new project
- Set the filter to 'C++' and find a 'Console Application'
- Create the project. Your non-experimental Visual Studio instance may stop on an exception while this is happening. If so, ignore it.
- Open Tools->Options
- Find the 'Cross Platform' options and add an entry to connect to your WSL instance. You want a 'Host name' of 'localhost', set the 'Port' to whatever you configured in your WSL instance.
- Open main.cpp from the created project.pkg
- Set a breakpoint in the main method.
- F5 or Debug -> Start Debugging to start debugging.
-
Your breakpoint in
DebuggedProcess.Initialize
will hit. You can step through and see the commands that are being sent to GDB if you like. If you open the output window in your main Visual Studio instance, you can also see all the commands that we sent and the response/events that came back. -
Hit F5 from this breakpoint and see your experimental instance stop at a breakpoint as well.