feat(debug): add GDB-based debug visualizer for linked lists

Replace the custom toDebugGraph() method that generated JSON directly in C++ with a generic GDB Python script (debug_graph.py). The script traverses pointers and structures to build a graph representation for the VS Code Debug Visualizer, enabling external pointer display and more extensible visualization.

Update launch configurations to load the script and to disable array/string truncation (needed for the visualizer JSON). Add a debugAdapterConfigurations entry in settings.json to use the expression template $debug_graph(${expr}) for the cppdbg adapter.
This commit is contained in:
mynameisdeleted
2026-07-09 12:14:27 -04:00
parent 273d4dbf2b
commit a8d105005e
6 changed files with 511 additions and 32 deletions

View File

@@ -1,6 +1,5 @@
#include <iostream>
#include <optional>
#include <sstream>
// A single node containing data and a raw pointer to the next node
template <typename T>
@@ -50,39 +49,10 @@ public:
return head_ ? &head_->data : nullptr;
}
// Build a JSON string describing the list for the VS Code "Debug
// Visualizer" extension's custom "node table" view (see
// vis-plugins/node-table-visualizer.js): watch `list.toDebugGraph()`
// while paused. Each node is rendered as its own address-labeled box
// with a field table -- data as a plain value, next as a hex pointer.
std::string toDebugGraph() const {
std::ostringstream json;
json << "{\"kind\":{\"nodeTable\":true},\"nodes\":[";
for (Node<T>* n = head_; n; n = n->next) {
if (n != head_) json << ",";
json << "{\"id\":\"" << n << "\",\"fields\":["
<< "{\"name\":\"data\",\"value\":\"" << n->data << "\"},"
<< "{\"name\":\"next\",\"value\":\"" << n->next << "\",\"isPointer\":true}"
<< "]}";
}
json << "],\"edges\":[";
for (Node<T>* n = head_; n && n->next; n = n->next) {
if (n != head_) json << ",";
json << "{\"from\":\"" << n << "\",\"to\":\"" << n->next << "\",\"label\":\"next\"}";
}
json << "]}";
return json.str();
}
private:
Node<T>* head_;
};
// Force instantiation of every member, including toDebugGraph(), which
// nothing in this file calls directly -- without this, gdb has no symbol
// to invoke from the debugger's watch expression.
template class LinkedList<int>;
int main() {
LinkedList<int> list;