Vscode+Qemu+TinyOS Can‘t Using GUI gdb - gdb

I am setting up a tiny OS followed this tutorial under Ubuntu18.04 http://www.jamesmolloy.co.uk/tutorial_html/ .
So far I was able to compile and run the tiny kernel in QEMU. and also being able to connect the gdb-server using the command line gdb.
qemu -S -s -fda floppy.img -boot a &
sleep 1
cgdb -x scripts/gdbinit
But I would like to use Vscode gdb GUI instead of command line gdb, so I search this page https://wiki.osdev.org/User:TheCool1Kevin/VSCode_Debug to set up json file.
Here is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch with GDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/boot/boot.o",
"cwd": "${workspaceRoot}",
"args": [],
"targetArchitecture": "x86",
"MIMode": "gdb",
"miDebuggerPath": "",
"miDebuggerArgs": "",
"customLaunchSetupCommands": [],
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "file ${workspaceRoot}/cmy_kernel",
"description": "Load binary."
},
{
"text": "target remote :1234",
"description": "connect the port"
},
{
"text": "break kern_entry",
"description": "Break on exception handler."
},
],
"preLaunchTask": "Launch QEMU"
}
]
}
And my task.json is
{
"version": "2.0.0",
"tasks": [
{
"label": "Launch QEMU",
"type": "shell",
"windows": {
"command": ""
},
"linux": {
"command": "qemu -S -s -fda floppy.img -boot a &sleep 1 &"
}
}
]
}
I expect to be able to debug the the code under the VScode ,but when I start debug, VScode shows that Unable to connect the server :1234 timeout.
I don't konw how to modify the file .Any suggestion of using extensions is appreciated.

Have you tried this vs extension https://github.com/WebFreak001/code-debug
Since the -s command deploys a server or port:1234
You can use this configuration to attach it.
{
"name": "Debug",
"type": "gdb",
"request": "attach",
"target": "localhost:1234",
"remote": true,
"gdbpath": "gdb",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText",
}

Related

How can I set up debugging C++ programs with command-line arguments in VS Code?

I am having a problem setting up my debugger in VSCode for C++. I wrote some code, then ran into some errors while running it so I decided to debug. I think thats when VSCode created the task.json file. Then I realized I wanted to use command line arguments and google/stackoverflow said to create a launch.json file which I did. It was empty so I pressed the add configuration button and got this.
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
Now I tried to fill the placeholders but I can't do them without getting tons of errors after errors. Could someone please post an example of a working launch.json and how the file paths are supposed to work?
My main goal is to debug my code while using command line arguments.
Here is a sample from a project I currently use:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch Test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/build_amd64/bin/tester_config",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/build_amd64",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": []
}
]
}
If you post your launch.json with the filled in values then I might be able to tell you exactly what's wrong, because assuming you filled out everything correctly, you should be working.
You can find tutorials how to set up Visual Studio Code for C++ here:
https://code.visualstudio.com/docs/cpp/config-msvc
https://code.visualstudio.com/docs/cpp/config-mingw
A valid config should look something like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": ["$msCompile"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
As you can see, it's best to let the available extensions handle the setup, as getting all the compiler switches right can be tricky.
The full reference for tasks.json is found here:
https://code.visualstudio.com/docs/editor/variables-reference

vs code c++: unable to establish a connection to GDB

I'm trying to set up a OpenGL environment in vs code, I'm using MinGW64 with msys for compilation and package management, I wrote a tasks and launch json files for generating builds, but when I run the build that was generated I get an error stating "unable to establish connection to GDB" and my app aborts.
this is my launch.json:
"version": "0.2.0",
"configurations":
[
{
"name": "Lauch OpenGL App",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "Build OpenGL App",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}\\Build\\app",
"stopAtEntry": false,
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands":
[
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
This is my tasks.json:
{
"tasks":
[
{
"label": "Compile source code",
"type": "shell",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args":
[
"-c",
"main.cpp",
"-o",
"Build\\Temp\\main.o"
]
},
{
"label": "Link Libraries",
"type": "shell",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args":
[
"-o",
"Build\\app",
"Build\\Temp\\main.o",
"-L.",
"-lglfw3",
"-lopengl32",
"-lgdi32"
]
},
{
"label": "Cleanup",
"type": "shell",
"command": "Remove-Item",
"args":
[
"Build\\Temp\\*.*"
]
},
{
"label": "Build OpenGL App",
"dependsOrder": "sequence",
"dependsOn": ["Compile source code", "Link Libraries", "Cleanup"]
}
],
"version": "2.0.0"
}
When I run my build tasks everything works until the moment the app launches then the following error is shown:
And this is printed to the console:
No clue what the problem was, but I ended up reinstalling everything (msys, mingw, g++, gdb etc....) and the issue was fixed

"Property console is not allowed" Problem in VSC Ubuntu 20.04

I'm trying to debug my cpp program in Visual Studio Code in ubuntu 20.00. Hence,I'm facing to following problem:
{
"resource": "/home/xxx/Desktop/Project/.vscode/launch.json",
"owner": "_generated_diagnostic_collection_name_#4",
"severity": 4,
"message": "Property console is not allowed.",
"startLineNumber": 17,
"startColumn": 13,
"endLineNumber": 17,
"endColumn": 22
}
That's my launch.json file:
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
I wonder how I handle this problem.
Thanks.
replace "console": "externalTerminal" with "externalTerminal" : true if you would like your code to execute in a external console window. Otherwise remove the line completly

How to setup VSCode debugger to work with cmake?

I found a question here that is pretty close, but the C++ extension has been updated since then and the launch.json file that is created for you is very different and I'm not sure how to set it up. There also isn't a lot of info online to do this, so I'm hoping someone has done this before. My current project structure is like this:
MainProj
./build
CMakeLists.txt
main.cpp
otherClasses.hpp
And the cmake target that shows up in build after running ..cmake and make is called Main.
launch.json
{
// 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": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
This is the tasks.json file from the other question
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cd build && cmake .. && make"
}
]
}

VS code debugger doesn't open terminal

I'm trying to create a cpp environment on vs code. The build works, .exe gets generated, but the debugger doesn't seem to work. When I click on the run debug option, another terminal gets open with a message (attached in the screenshot). The code which I'm running is a simple hello world example. No terminal with Hello World is opened by the debugger. Hello world is supposed to be displayed in the screenshot of terminal 2 but another message gets printed, which I got no clue about.
Terminal 1
Terminal 2
This is the code for the config files:
task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"sample.cpp"
],
"problemMatcher": []
}
]
}
launch.json
{
// 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": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "C:\\Users\\Amey\\Desktop\\work\\Programming\\C++\\a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}