I've recently installed newest version of Ubuntu on my PC and i wanted to play a bit with stack smashing in VS Code, so i installed it.
GDB version: GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
I've created my task.json :
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build workspace",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"-o",
"${workspaceFolder}/executable",
"-fno-stack-protector",
"${workspaceFolder}/*.c"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/gcc"
}
]
}
and also launch.json for gdb debugger :
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: gcc build && debug workspace",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/executable",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "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
}
],
"preLaunchTask": "C/C++: gcc build workspace",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
Then I wanted to run debugger, so i placed a breakpoint in a function (breakpoint marked with a "->") :
void foo(char* param, long param_length)
->{
long stack1 = 0x123;
long stack2 = 0x456;
...
}
Now, I placed a breakpoint there because i really want to start debugging from a start of a function, when there is only a return address placed on a stack, but when i go to Run > Start Debugging a breakpoint gets moved to the first line of a function :
long stack1 = 0x123;
and debugging starts from there. I don't want that, because if i start from there the stack has already been altered ( ret addres pushed, old basepointer pushed, etc. )
Is this Visual Studio Code or GDB itself? Is there a way to start debugging from where i wanted it, so there is nothing on a stack (besides return address) ?