Now lets get started…
###############################
1B. Ensure this configured as the default (otherwise later the $defaultWSLPath variable doesn’t work and you may see a Visual Studio error “Could not open windows subsystem shell”)…
C:\Users\Ben>wslconfig /l
Windows Subsystem for Linux Distributions:
Legacy (Default)
kali-linux
Ubuntu-18.04
Ubuntu-16.04
C:\Users\Ben>wslconfig /setdefault Ubuntu-18.04
C:\Users\Ben>wslconfig /l
Windows Subsystem for Linux Distributions:
Ubuntu-18.04 (Default)
Legacy
kali-linux
Ubuntu-16.04
Ref: https://www.howtogeek.com/344688/how-to-set-your-default-linux-distribution-on-windows-10/
1C. Start Ubuntu-18.04, then update/upgrade/install pre-requisites…
“`
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install clang gcc gdb make rsync zip # Visual Studio requirement
sudo apt-get install uuid-dev # Pharo VM build requirement
“`
While that is running…
####################
2A. Download and run the installer for Visual Studio Community 2019 (not Visual Studio Code)
2B. When the “Visual Studio Installer” opens, under its “Workloads” tab, select “Linux development with C++” and click **Install**.
#####################################
Build and run hello-world exercise inside WSL
3A. Start Visual Studio 2019
Then scroll down and choose “CMake Project” and <Next>.
and configure…
Project name: hello-world
then click <Create>.
Ref: https://docs.microsoft.com/en-us/cpp/linux/cmake-linux-project?view=vs-2019
Now it may immediately start the CMake build and get an error because its using the default “x64-Debug” configuration.
3B. From the “Configuration drop-down” (where you see “x64-Debug”)
select “Manage Configurations…”
Delete “x64-Debug”.
Add… “WSL-Debug” and use all defaults then press <CTRL-S> to save.
Inside WSL, Cmake will start generating the makefiles.
3C. After “CMake generation finished”,
pull down “Select Startup Item” and select “hello-world”
then press the green PLAY button.
Inside WSL, the make build will start and after its done the pharo executable will run there.
In the [Output] tab, it was successful if you see “The thread ‘hello-world’ (0x1f7a) has exited with code 0” .
3D. For proof that its running inside WSL, lets write a file!
In the “Solution Explorer” tab, browse to “hello-world.cpp” and change its contents to…
“`
#include <stdio.h>
int main()
{
FILE* fp;
int i;
/* open the file for writing*/
fp = fopen(“/tmp/built-by-visual-studio”, “w”);
fprintf(fp, “It worked.\n”);
fclose(fp);
return 0;
}
“`
then press the green PLAY button.
After you see “thread ‘hello-world’ has exited with code 0”
open a WSL shell and run…
$ cat /tmp/built-by-visual-studio
It worked
3E. To experience debugging Linux from Visual Studio, first remove the test file…
$ rm /tmp/built-by-visual-studio
then put a breakpoint on “fopen” and click the PLAY button.
Check if the file is there…
$ cat /tmp/built-by-visual-studio
cat: /tmp/built-by-visual-studio: No such file or directory
<STEP OVER> fopen
$ cat /tmp/built-by-visual-studio
<STEP OVER> fprintf
$ cat /tmp/built-by-visual-studio
<STEP OVER> fclose
$ cat /tmp/built-by-visual-studio
It worked
3F. All done…
File > Close Folder
#####################################
Build and run Pharo-Headless-VM inside WSL
#####################################
4A. From Visual Studio 2019 opening window, under “Get started” click “Clone or check out code”
Repository location: https://github.com/bencoman/opensmalltalk-vm.git
then click <Clone>.
https://docs.microsoft.com/en-us/visualstudio/get-started/tutorial-open-project-from-repo?view=vs-2019
4B. In the bottom-right status bar, click the “branching” icon and choose “Manage Branches”.
Expand “remotes/origin”,
then right-click “headless-WSL-VisualStudio” and “Checkout”
A fixed “WSL-Debug” configuration is a part of this branch, so its CMake-build should auto-start and complete successfully.
4C. After “CMake generation finished”,
pull down “Select Startup Item” and select “pharo (build/vm/pharo)”
then press the green PLAY button.
Don’t worry if it sits for a long time on “BalloonEnginePlugin>>primitiveAddRect”
The [Error List] tab pops up with 116 Warnings.
Switching back to the [Output] tab, you hopefully see “thread ‘pharo’ (0x4d0d) has exited with code 0”
So the VM just built and ran headless under Windows Subsystem for Linux.
Now lets debug that from Visual Studio.
4D. Browse to src/main.c and put a breakpoint in main() on the call to parseArguments()
Then click the PLAY button.
Once stopped at the breakpoint, <STEP INTO>.
In the [Autos] tab, expand the “parameters” variable. Observe “imageFile” is empty.
Notice “imageFile” becomes “Pharo.image” after <STEP OVER> splitVMAndImageParameters().
So now I leave you to play. I’d be interested in hearing about people’s experiences.
is left as an exercise for the reader.