Debugging EOS on Windows
In our previous post, we have shown how to install, compile and run EOS code on Windows 10 by combining Windows Subsystem for Linux with the Visual Studio Code editor.
In this post, assuming the EOS code has been successfully compiled, we present how the code can be run in debug mode and stopped using breakpoints. Visual Studio Code works pretty well for this purpose.
Image source: http://www.edinkapic.com
Set-up
Launch a new Ubuntu shell by either:
-- Typingbash
in the Windows Command Prompt or in the Windows PowerShell, or
-- Using the Bash on Ubuntu on Windows shortcut available from the Start Menu.Inside the Ubuntu shell install the debugger:
sudo apt install gdb
Still inside the Ubuntu shell run the following command to make sure the variable
EOSIO_INSTALL_DIR
has been properly defined:
echo ${EOSIO_INSTALL_DIR}
It should return something like/mnt/x/Workspaces/EOS/eos
, i.e. the location of the EOS source code. If case you need to create it or redefine it, just run:
export EOSIO_INSTALL_DIR=/mnt/x/Workspaces/EOS/eos
echo "export EOSIO_INSTALL_DIR=${EOSIO_INSTALL_DIR}" >> ~/.profile
NOTE: make sure to replacex/Workspaces/EOS
with the appropriate path that matches the workspace location you have chosen on your computer.
Add C/C++ Extension to VSC
Start Visual Studio Code. Inside Visual Studio Code open the folder containing the content of the EOS source code. In our case it's
X:\Workspaces\EOS\eos
.Make sure the
C/C++ for Visual Studio Code
extension by Microsoft is installed. If not, add it and restart Visual Studio Code.
Configure C/C++
In Visual Studio Code navigate to View > Command Palette
and select C/Cpp: Edit Configurations...
to open the c_cpp_properties.json
file. Replace the content of this file with the following text:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"/usr/local/include/openssl",
"${HOME}/opt/boost_1_64_0/include/",
"${EOSIO_INSTALL_DIR}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"/usr/local/include/openssl",
"${HOME}/opt/boost_1_64_0/include",
"${EOSIO_INSTALL_DIR}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"${localappdata}/lxss/rootfs/usr/include",
"${localappdata}/lxss/rootfs/usr/local/include",
"${localappdata}/lxss/rootfs/usr/include/openssl",
"${localappdata}/lxss/home/tokenika/opt/boost_1_64_0/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${localappdata}/lxss/rootfs/usr/include",
"${localappdata}/lxss/rootfs/usr/local/include",
"${localappdata}/lxss/rootfs/usr/include/openssl",
"${localappdata}/lxss/home/tokenika/opt/boost_1_64_0/include",
"${workspaceRoot}/../eos2"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
NOTE1: In the expression ${localappdata}/lxss/home/tokenika/opt/boost_1_64_0/include
make sure to replace our Ubuntu user name (i.e. tokenika
) with the one you have chosen when setting up Ubuntu.
NOTE2: Most probably there is a bug inside the IntelliSenseMode extension. It manifests itself as a never ending loop consuming your processor power, when parsing the source code. To avoid it, just open a Windows command prompt and run the following command to create a link named eos2
pointing at your eos
folder (remember to adjust the paths to suit your local settings):
mklink /d X:\Workspaces\EOS\eos2 X:\Workspaces\EOS\eos
We make use of this link by applying ${workspaceRoot}/../eos2
instead of just ${workspaceRoot}
in the above configuration file, even though it resolves to the same location. This does the trick to fix the IntelliSenseMode bug. You might need to restart your Visual Studio Code for this to take effect. When everything is correct you should see no errors in the Problems panel (View > Problems
).
Configure Debugger
In Visual Studio Code navigate to View > Debug
to switch to the Debug perspective and then click on the Configure icon on the top bar to generate a file named launch.json
for your workspace. Replace the content of this file with the following text:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Bash on Windows Launch",
"type": "cppdbg",
"request": "launch",
"program": "/mnt/x/Workspaces/EOS/eos/build/programs/eosd/eosd",
"args": [],
"stopAtEntry": false,
"cwd": "/mnt/x/Workspaces/EOS/eos",
"environment": [],
"externalConsole": true,
"pipeTransport": {
"debuggerPath": "/usr/bin/gdb",
"pipeProgram": "C:/Windows/sysnative/bash.exe",
"pipeArgs": ["-c"],
"pipeCwd": ""
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"sourceFileMap":
{
"/mnt/x": "X:\\"
}
}
]
}
NOTE: Make sure to replace /mnt/x/Workspaces/EOS
and "/mnt/x": "X:\\"
with appropriate values matching your local settings. Also, make sure to use lower case here: /mnt/x
.
Run in Debug Mode
In Visual Studio Code follow these steps:
Open the
programs\eosd\main.cpp
source file.Navigate to
View > Debug
to switch to the Debug perspective.Set a breakpoint in the
main.cpp
file somewhere close to the beginning of the code, e.g. at this line:app().register_plugin<net_plugin>()
.Now run
Debug > Start Debugging
. If everything goes as expected the code execution should start and then halt at your breakpoint. At this stage you should be able to access the values of local variables in the debug panels on the left-hand side.
Congratulations to Tokenika. You are doing a good job.
That's what im looking for! Thanks for your post