Does the 'command' command work ?
I am trying to record some data via attaching a set of commands to a breakpoint. However when I try and do this from within the debug console of cortex-debug - the entire session is stuck with it asking for input.
I have tried this without cortex-debug and ran gdb straight from commandline, and I attaching command to breakpoints works fine.
Am I missing something ?
Do you have something to show me? I don't know what you are trying to do (gdb or python scripts or something else). and who is asking for input?
And, what is a command command?
My bad - I thought the description was clear but I understand that perhaps its not.
My relevant launch.json
{
"name": "jlink fast rogers debug",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/Rogers Debug Fast/myproject.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "STM32L151RC",
"interface": "swd",
"runToMain": true,
"svdFile": "svd/STM32L151.svd",
// "showDevDebugOutput": true,
"preLaunchCommands": [
"source mygdb.gdbinit"
],
// "preLaunchTask": "Build clean",
},
The gdb command command allows you to attach a series for gdb commands to a breakpoint such that when the breakpoint hits, the commands assigned to that breakpoint get executed.
see: command
When I attach a command to breakpoint 3 to print a variable I would need to enter
command 3
print VAR
end
When I execute within the debug console, I get the following

Not sure what the circled numbers are but there is also no way to exit. I cannot resume debugging, I cannot halt, ctrl+z, ctrl+c, exit, end, do not work. This is true for both console input as well as the physical buttons that appear when debugging. The only exit is to terminate the entire session via the stop button. When I do so, I get the following

Note: The previous image was run at another time, that is why the breakpoint number and circled numbers differ.
The console appears to be waiting for more input but that is only a guess.
When I start JLinkGDBServerCL.exe server and using the same arguments that cortex-debug uses (copy and paste from debug console) and run arm-none-eabi-gdb in a separate terminal window, I am able to attach a command to a breakpoint.
The circled numbers are used by VSCode to indicate there are duplicate lines with identical text
Edited previous post because I shared the same image twice.
The debug console is not a terminal so things like Control-C don't mean a thing. Control-C may actually do a Copy on some platforms.
Every time you press enter in the debug console, VSCode assumes you finished entering the command and tries to refresh all the windows related to the debugger.
During the refresh, some buttons may be disabled and it will/may appear like we hit the breakpoint again and an infinite loop may start. Some of this is a guess why things stop responding.
This is happening while you are entering creating the command callback? You can put the sequence in a text file and source that file.
Please note that this is not an interactive shell and you are not interacting with gdb's stdin/stdout which is already consumed by another process (Cortex-Debug backend). You are actually talking to a window created by VSCode and they set the rules.
I added the command to my gdbinit file and it works there.
Is there a way to interact with gdb while still having the graphical frontend ?
In a very limited way, yes. one-line commands. Commands that modify the status of the program or mess with the stack, etc. can cause things to go out of sync -- there are 5 processes (at least) that are involved. We try to recover from a lot of things but obviously not everything.
I am gonna close this.
I would totally want this feature to be available within cortex-debug. This is one of the most powerful capabilities within gdb along with the python interpreter for scripting and loading gdbinit files and takes basic level debugging to another more advanced level. I would urge the developer(s) to consider adding the ability to use this feature.
Just a note: while sourcing the command file within gdb does "work", it has the same problems as before, where you can't interact with the program anymore and you need to terminate the session.
We don't control that window at all. It is VSCode. VSCode gives it to us, but also initiates a large set of actions by itself. We just pass on whatever was given to gdb's stdin but its stdin is note the same as what you see on gdb-prompt. We have to use machine-interface where there are no multi-line commands. Neither us nor VSCode knows it was a partial command.
It would help me to know what was in the set of commands that you were trying to enter, even to judge/scope anything. Btw, I am the sole developer(s).
We have two problems.
- Inability to enter multi-line commands -- VSCode issue
- Whatever you entered, made the whole system go crazy -- could be anything
I understand that there are limitations within that window. I think it would be a great feature to add (maybe not directly with that window ). This is not my area of expertise, but a few possibilities (no idea difficulty or feasibly) could be to use another window that is not the debug console or to provide another process that can be started that can interact with gdb and feed data back to its stdout. I would think an advanced user would not mind opening up a split screen or another terminal window to execute a program that can interact with gdb and get information from it. I don't know...
It would help me to know what was in the set of commands that you were trying to enter, even to judge/scope anything. Btw, I am the sole developer(s).
I created a breakpoint via debug console and got the breakpoint number (let's say for this, it's 2), and I want to print out the contents of an in-scope variable called foo.
Then I typed out the following. Each new line is me pressing ENTER.
command 2
p foo
c
end
As soon as I hit ENTER at the first line - the system breaks here. After that, the rest of the stuff is irrelevant.
Ooops, you did a 'continue'. That modifies the program/debugger state without them knowing about it. It is probably why things got messy after that. And, that continue happens in the middle of everyone trying to updated themselves because of the breakpoint. All bets are off.
Those commands cannot be entered in the Debug Console. No multi-line commands. Gdb itself is probably confused. You can enable showDevDebugOutput to see what was the last few things that happened.
Any news on this? This issue shall be solved.
Since no multi-line commands allowed in the terminal, I was able to work around this by creating a text file and sourcing it within gdb.
Create an text file with your multi-line commands
command 3
p myvar
c
end
And within the gdb command line, use source your_text_file.
Check that the command took by looking at your gdb breakpoints.
info b
Ok, thanks for the tip!