~~TOC~~
|<100% 25% - >|
^ \\ DATA ANALYTICS REFERENCE DOCUMENT\\ \\ ^^
^ Document Title:|Setting up Cygwin|
^ Document No.:|1570875139|
^ Author(s):|Gerhard van der Linde, Rita Raher|
^ Contributor(s):| |
**REVISION HISTORY**
|< 100% 10% - - 10% 17% 10% >|
^ \\ Revision\\ \\ ^\\ Details of Modification(s)^\\ Reason for modification^ \\ Date ^ \\ By ^
| [[:doku.php?id=help:developer_tools:cygwin&do=revisions|0]] |Draft release|Document the setup of cygwin| 2019/10/12 10:12 | Gerhard van der Linde |
----
====== Cygwin debugger in VS Code ======
* Download and run the Cygwin installer from here https://cygwin.com/install.html
* Follow the [[help:developer_tools:cygwin_full_install|installation instructions]] from here https://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows/
* After installation building is required, **note** that this is done in a newly installed //Cygwin terminal//.
* The module in the course uses gcc instead of g++.
===== Adding the gcc debugger gdb =====
==== Install gdb ====
Rerun the cygwin installer(setup-x86_64.exe), located in downloads or moved to cywin folder in c:\cygwin64
Click through the installer and select gdb, you might have to use search to locate it.
{{ :help:developer_tools:cygwin_add_gdb.jpg?nolink |}}
Click skip to select gdb and click net to complete the installation.
The gdb.exe file will now appear in c:\cygwin64\bin folder.
No set up the debugger extension in VS Code if not already installed.
{{ :help:developer_tools:gcc_vs_code_addon.jpg?nolink&600 |}}
The debugger can now be configured in VS Code.
===== Step by step instructions to set up the debugger in VS Code =====
- Open C file in VS Code
- Set breakpoint in code
- Press F5 or select Start debugging from Debug menu\\ {{:help:developer_tools:vsc_dbg:image1.png?nolink|}}
- Select C++(GDB/LLDB) from popup\\ {{:help:developer_tools:vsc_dbg:image2.png?nolink|}}
- Then select gcc.exe build and debug active file\\ {{:help:developer_tools:vsc_dbg:image2.png?nolink|}}
- The Launch.json window should now pop up, see that this has the right path to your gdb.exe file, save and close.\\ {{:help:developer_tools:vsc_dbg:image4.png?nolink|}}
- G back to the C file and F5 again, ow it should pop up a message about not being able to build the active file, click "Configure Task".\\ {{:help:developer_tools:vsc_dbg:image5.png?nolink|}}
- Select C/C++:gcc.exe build active file
- Now the task,json file should pop up and confirm that "command" points to the right location where the gcc.exe file is located. Save and close\\ {{:help:developer_tools:vsc_dbg:image6.png?nolink|}}
- Go back to the C file again and press F5.
- Now everything should start up and the code should stop at the debugger breakpoint.\\ {{:help:developer_tools:vsc_dbg:image7.png?nolink|}}
==== Sample configuration files for Cygwin gdb to work in VS Code ====
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc.exe build active file"
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:\\cygwin64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\cygwin64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
Right click and save the two json configuration files above into a subfolder named ''.vscode''.
This folder should be in the same folder where your c files that you want to debug resides.
===== Troubleshooting =====
* https://github.com/microsoft/vscode-cpptools/issues/2778
"logging": { "engineLogging": true }
* http://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html
==== UTF-8 Workaround ====
* https://github.com/microsoft/vscode-cpptools/issues/1527
So the issue is caused in gb and the extra escaped character returned on line three in the VS Code debugger window as shown below.
1: (2308) ->(gdb)
1: (2317) <-1001-gdb-set target-async on
1: (2318) ->&"\357\273\2771001-gdb-set target-async on\n"
1: (2319) ->&"Undefined command: \"\". Try \"help\".\n"
1: (2320) ->^error,msg="Undefined command: \"\". Try \"help\"."
1: (2320) ->(gdb)
As a workaround to fix this add a "gdb-with-chcp.cmd" within to your project (eg, "c:\cywin64\bin\gdp-with-chcp.cmd"):
@:: gdb-with-chcp.cmd
@chcp 1257 >NUL 2>&1 && @"gdb.exe" %*
This sets the codepage for GDB and fixes the problem cause above when running the PC set to UTF-8 codepage.
Amend the current json code launching the debugger to point to the cmd file just created.
// use "PATHTO/gdb-with-chcp.cmd" as "miDebuggerPath" within "launch.json"
// eg
// ...
"miDebuggerPath": "${workspaceFolder}/dbin/gdb-with-chcp.cmd",
// ...
This resolved my gcc debugger issues.