Regarding the Implementation of the Live Watch Feature on Eclipse Embed CDT #642
Replies: 3 comments 1 reply
-
I adapted the Live Watch feature for the chips in my lab. For our chips, I use Method 2, which is an asynchronous GDB implementation.
In the debug launch, many custom modifications and configurations are needed... At a minimum, the foundation for implementing this feature is to provide a way for Live Watch to obtain the DsfSession during the debug launch startup process. Additionally, for the debug agent, we also made custom modifications, which can be considered as a way to avoid the protocol confusion issues. QQ2025810-21244-HD.mp4 |
Beta Was this translation helpful? Give feedback.
-
Currently, I am exploring Method 3, which involves starting two GDB instances to connect to OpenOCD to ultimately achieve the live watch feature. However, starting an additional custom session and executing a custom command sequence during the debug session startup in Eclipse is quite cumbersome. It requires implementing a complete debug backend to provide the DsfSession, but I believe this is 100% feasible. However, it will take a significant amount of time. Maybe after I graduate with my master's degree, I will organize a code example and share it. |
Beta Was this translation helpful? Give feedback.
-
Hi, @kairoaraujo |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
1 About the Requirement for Live Watch with Eclipse Embed-CDT
Mentioned in issue:597
The goal is to implement an online debugging feature in Eclipse Embed CDT: during the debugging process, even if no breakpoint is hit, we should still be able to see the changes of debug values in the Embed CDT window.
As stated in issue:597, this is not a simple patch but a complex project. To implement it, the following problems need to be solved:
Enable command interaction between Eclipse Embed CDT and GDB
Allow GDB to send query commands while debugging without stopping execution
Allow debug probes (OpenOCD, J-Link, etc.) to handle memory read commands from GDB (the m packet in the RSP protocol) without stopping debugging
2 Solutions
2.1 Command Interaction Between Eclipse Embed CDT and GDB
At first glance, there seems to be an obvious solution: we could reuse Eclipse’s built-in Expressions view. This view can parse variables very well. If it provided an API to re-evaluate all variables, we might be able to set up a thread in Eclipse to periodically call the evaluation and refresh the UI.
Unfortunately, after spending a lot of effort trying to understand the behavior of Eclipse’s Expression Manager, I did not find such an interface. During debugging, it considers the target to be unavailable, preventing the execution of variable evaluation commands.
Therefore, one feasible way for Embed CDT and GDB to interact is by using CDT-related interfaces.
After obtaining the debug DSF session, using CommandControl + CommandFactory allows sending any desired commands to GDB at any time.
2.2 GDB to the Target Chip
Obviously, when GDB sends a command without hitting a breakpoint, GDB will block, which manifests as the inability to write any characters to GDB’s input stream. This behavior is the same in both GDB’s terminal mode and MI mode.
However, GDB also provides solutions: non-stop mode and asynchronous debugging.
2.2.1 Using GDB’s Non-stop Mode
Unfortunately, this method requires the debugging probe to support non-stop mode, but almost no debug probes fully support it.
Texas Instruments’ debug probe, however, does support it.
Tests have shown that J-Link, OpenOCD, and ST-Link do not support it.
https://forum.segger.com/index.php/Thread/1425-JLink-GDBServer-async-mode/?page=Thread&threadID=1425
Supporting non-stop mode seems to be a rather complex task, requiring complete RSP protocol support in the debugging probe. We may need to consider other approaches.
2.2.2 Using Asynchronous Debugging
set target-async on
orgdb-set mi-async on
This method can solve the problem of sending query commands without stopping execution.
Protocol Confusion:
Since non-stop mode is not fully supported, issuing an
m
query aftercontinue
will cause GDB to fail to recognize subsequent breakpoint hit notifications (s05
cannot be recognized by GDB as a valid response to thec
packet).As a result, GDB will not realize the target has stopped, which means that in the IDE, after clicking Resume, the expected breakpoints will not be hit.
According to the official GDB documentation, if non-stop mode is disabled, no other query commands are allowed between a
step
orcontinue
command and the point when the target stops (reportss05
or another signal) to GDB.https://sourceware.org/gdb/current/onlinedocs/gdb.html/Overview.html
Debug Stop Requests:
For actions like inserting breakpoints or suspending execution, the debugger’s interrupt handling logic must be reconfigured.
The original logic is: send a
Ctrl + C
signal to GDB to trigger suspend, then send the breakpoint insertion request.However, after enabling
target-async
,Ctrl + C
can no longer stop GDB and the target directly — you must first sendinterrupt -a
to stop them, which requires additional handling in Eclipse’s debug backend.Modifying GDB:
In fact, if you only enable async mode without any changes, GDB will still intercept query commands.
To work around this, you need to modify GDB’s source code by commenting out the relevant interception code.
Advantages:
Disadvantages:
2.2.3 Starting Two GDB Debuggers
Marus/cortex-debug#810
It may sound unusual, but thinking it through, this could indeed work.
.cfg
file to support launching two GDB connections.m
requests to query global variables and memory.Protocol Confusion:
This issue does not occur, because the second GDB only sends
m
packets, and the debug probe simply responds to them.There’s no scenario where one GDB sends a
c
packet andm
packets get interleaved to disrupt the protocol — allm
packets go to the second GDB.Debug Stop Requests:
Not an issue here, because the GDB responsible for debugging runs in normal all-stop mode, and the GDB querying variables never sends any target-control commands.
No Need to Modify GDB Source Code:
The GDB responsible for variable queries does not use any control commands and will not consider the target as running, so it can directly perform queries without issue.
Configuring OpenOCD to support multiple GDB connections seems to be possible only with OpenOCD, but OpenOCD supports a wide range of debug probes.
This is totally feasible, and I have already reproduced it
Referencing the TCL script provided by cortex-debug:
3 Demo with Starting Two GDB Debuggers
Second GDB Usage Command Sequence
However, it can only view global variables, static variables, and memory (which is understandable since GDB does not know which function call frame the current target is running on, so it has no way to obtain local variables. Of course, global variables are sufficiently useful).
In the image below, I am using Eclipse Embed-CDT to debug an STM32 development board. During the debugging session, I open GDB and use a second GDB instance in the terminal to connect to the OpenOCD that Eclipse is using for debugging.
It can be seen that the observation of the global variable
s1
is achieved without stopping the program!!!Beta Was this translation helpful? Give feedback.
All reactions