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