-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_debugger.cpp
More file actions
280 lines (216 loc) ยท 10.3 KB
/
Copy pathdemo_debugger.cpp
File metadata and controls
280 lines (216 loc) ยท 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include "bolt/editor/debugger_interface.hpp"
#include "bolt/editor/debugger_ui.hpp"
#include "bolt/editor/integrated_editor.hpp"
#include "bolt/drawkern/dis_vm.hpp"
#include <iostream>
#include <memory>
using namespace bolt;
using namespace bolt::drawkern;
void print_header() {
std::cout << "\n=====================================" << std::endl;
std::cout << " Bolt C++ Integrated Debugger Demo" << std::endl;
std::cout << "=====================================" << std::endl;
std::cout << std::endl;
}
void demo_basic_debugger() {
std::cout << "๐ฑ Demo: Basic Debugger Functionality" << std::endl;
std::cout << "-------------------------------------" << std::endl;
auto debugger = std::make_unique<DebuggerInterface>();
// Set up event callback
debugger->set_event_callback([](DebugEvent event, const std::string& message) {
std::cout << "๐ Event: " << message << std::endl;
});
// Create a simple Limbo program
std::string program = R"(
print "Starting AI workbench..."
ai_chat "Hello AI"
render_glyph "debug-symbol"
print "Program completed"
halt
)";
std::cout << "๐ Starting debug session with program:" << std::endl;
std::cout << program << std::endl;
// Start debug session
if (debugger->start_debug_session_from_source(program)) {
std::cout << "โ
Debug session started successfully" << std::endl;
// Set some breakpoints
std::cout << "\n๐ด Setting breakpoints..." << std::endl;
debugger->set_breakpoint(2);
debugger->set_breakpoint(4);
auto breakpoints = debugger->get_all_breakpoints();
std::cout << "๐ Active breakpoints: " << breakpoints.size() << std::endl;
for (const auto& bp : breakpoints) {
std::cout << " - PC " << bp.pc << (bp.enabled ? " (enabled)" : " (disabled)") << std::endl;
}
// Step through execution
std::cout << "\n๐ง Stepping through execution..." << std::endl;
std::cout << "Current PC: " << debugger->get_current_pc() << std::endl;
std::cout << "Current instruction: " << debugger->get_current_instruction() << std::endl;
debugger->step_over();
std::cout << "After step - PC: " << debugger->get_current_pc() << std::endl;
debugger->step_over();
std::cout << "After step - PC: " << debugger->get_current_pc() << std::endl;
// Continue execution
std::cout << "\nโถ๏ธ Continuing execution..." << std::endl;
debugger->continue_execution();
std::cout << "Final state: " << static_cast<int>(debugger->get_debug_state()) << std::endl;
// Stop session
debugger->stop_debug_session();
std::cout << "๐ Debug session stopped" << std::endl;
} else {
std::cout << "โ Failed to start debug session" << std::endl;
}
}
void demo_debugger_ui() {
std::cout << "\n๐ฑ Demo: Debugger UI Integration" << std::endl;
std::cout << "--------------------------------" << std::endl;
auto debugger = std::make_shared<DebuggerInterface>();
auto ui = std::make_unique<DebuggerUI>();
// Connect UI to debugger
ui->set_debugger(debugger);
ui->set_visible(true);
// Create a program for debugging
std::string program = "print \"UI Demo\" ai_chat \"Testing UI\" halt";
if (debugger->start_debug_session_from_source(program)) {
std::cout << "โ
UI Debug session started" << std::endl;
// Set breakpoint via UI
ui->handle_breakpoint_toggle(1);
std::cout << "๐ด Breakpoint set via UI" << std::endl;
// Render UI state
std::cout << "\n๐บ Rendering debugger UI:" << std::endl;
ui->render();
// Test UI controls
std::cout << "\n๐ฎ Testing UI controls..." << std::endl;
ui->handle_step_over_clicked();
ui->render_controls();
ui->handle_continue_clicked();
ui->render_controls();
ui->handle_stop_clicked();
std::cout << "๐ Session stopped via UI" << std::endl;
}
ui->set_visible(false);
}
void demo_integrated_editor() {
std::cout << "\n๐ฑ Demo: IntegratedEditor Debugger Integration" << std::endl;
std::cout << "-----------------------------------------------" << std::endl;
auto& editor = IntegratedEditor::getInstance();
// Create a test Limbo file content
std::string testContent = R"(print "Editor integration test"
ai_init "test-model"
ai_chat "Hello from editor"
render_glyph "editor-test"
halt)";
std::cout << "๐ Opening test document in editor..." << std::endl;
editor.openDocument("/tmp/test_debug.limbo", testContent);
// Start debugging from editor
std::cout << "๐ง Starting debug session from editor..." << std::endl;
if (editor.startDebugSessionFromSource(testContent)) {
std::cout << "โ
Editor debug session started" << std::endl;
// Set breakpoints via editor
editor.setBreakpointAtLine("/tmp/test_debug.limbo", 2);
editor.setBreakpointAtLine("/tmp/test_debug.limbo", 4);
auto breakpoints = editor.getAllBreakpoints();
std::cout << "๐ Breakpoints set via editor: " << breakpoints.size() << std::endl;
// Show debugger UI
editor.showDebugger();
std::cout << "๐บ Debugger UI shown: " << (editor.isDebuggerVisible() ? "Yes" : "No") << std::endl;
// Step through via editor
std::cout << "๐ง Stepping through via editor..." << std::endl;
std::cout << "PC: " << editor.getCurrentDebugPC() << std::endl;
editor.debugStepOver();
std::cout << "After step - PC: " << editor.getCurrentDebugPC() << std::endl;
editor.debugContinue();
std::cout << "Debug state: " << static_cast<int>(editor.getDebugState()) << std::endl;
// Clean up
editor.stopDebugSession();
editor.hideDebugger();
std::cout << "๐ Editor debug session stopped" << std::endl;
} else {
std::cout << "โ Failed to start editor debug session" << std::endl;
}
}
void demo_watch_expressions() {
std::cout << "\n๐ฑ Demo: Watch Expressions" << std::endl;
std::cout << "---------------------------" << std::endl;
auto debugger = std::make_unique<DebuggerInterface>();
// Add watch expressions
std::cout << "๐๏ธ Adding watch expressions..." << std::endl;
debugger->add_watch_expression("counter");
debugger->add_watch_expression("message.length");
debugger->add_watch_expression("ai_model_status");
auto watches = debugger->get_watch_expressions();
std::cout << "๐ Watch expressions: " << watches.size() << std::endl;
for (const auto& watch : watches) {
std::cout << " - " << watch.expression << " = " << watch.value
<< " (" << (watch.valid ? "valid" : "invalid") << ")" << std::endl;
}
// Update watch expressions (would happen during debugging)
debugger->update_watch_expressions();
// Remove a watch expression
debugger->remove_watch_expression("message.length");
std::cout << "Removed 'message.length' watch" << std::endl;
watches = debugger->get_watch_expressions();
std::cout << "๐ Remaining watch expressions: " << watches.size() << std::endl;
// Clear all
debugger->clear_watch_expressions();
std::cout << "๐งน Cleared all watch expressions" << std::endl;
}
void demo_vm_integration() {
std::cout << "\n๐ฑ Demo: DIS VM Direct Integration" << std::endl;
std::cout << "-----------------------------------" << std::endl;
auto vm = std::make_unique<DISVM>();
// Create a simple program using the factory
auto program = DISProgramFactory::create_ai_workbench("test-model");
std::cout << "๐ Loading DIS program..." << std::endl;
if (vm->load_program(program)) {
std::cout << "โ
Program loaded successfully" << std::endl;
// Set breakpoints directly on VM
vm->set_breakpoint(2);
vm->set_breakpoint(4);
auto breakpoints = vm->get_breakpoints();
std::cout << "๐ VM breakpoints: " << breakpoints.size() << std::endl;
// Step through execution
std::cout << "๐ง VM stepping:" << std::endl;
std::cout << "PC: " << vm->get_pc() << std::endl;
vm->step_into();
std::cout << "After step - PC: " << vm->get_pc() << std::endl;
// Check if at breakpoint
if (vm->is_at_breakpoint()) {
std::cout << "๐ด Hit breakpoint!" << std::endl;
}
// Continue until breakpoint or completion
vm->continue_execution();
std::cout << "VM running: " << (vm->is_running() ? "Yes" : "No") << std::endl;
std::cout << "Call stack depth: " << vm->get_call_stack_depth() << std::endl;
vm->halt();
std::cout << "๐ VM halted" << std::endl;
} else {
std::cout << "โ Failed to load program" << std::endl;
}
}
int main() {
print_header();
try {
// Run all demos
demo_basic_debugger();
demo_debugger_ui();
demo_integrated_editor();
demo_watch_expressions();
demo_vm_integration();
std::cout << "\n๐ All debugger demos completed successfully!" << std::endl;
std::cout << std::endl;
std::cout << "The integrated debugger interface provides:" << std::endl;
std::cout << "โ
Breakpoint management (set, remove, toggle, enable/disable)" << std::endl;
std::cout << "โ
Step debugging (step over, step into, step out, continue)" << std::endl;
std::cout << "โ
Watch expressions for variable monitoring" << std::endl;
std::cout << "โ
Call stack inspection" << std::endl;
std::cout << "โ
Debug event notifications" << std::endl;
std::cout << "โ
UI integration with the editor" << std::endl;
std::cout << "โ
Direct integration with DIS Virtual Machine" << std::endl;
std::cout << std::endl;
} catch (const std::exception& e) {
std::cerr << "โ Demo failed with exception: " << e.what() << std::endl;
return 1;
}
return 0;
}