@@ -16,7 +16,7 @@ use uuid::Uuid;
16
16
use crate :: {
17
17
config:: Config ,
18
18
error:: { AppError , AppResult } ,
19
- models:: { Breakpoint , GDBCommandResponse , GDBSession , GDBSessionStatus , StackFrame , Variable } ,
19
+ models:: { Breakpoint , GDBSession , GDBSessionStatus , StackFrame , Variable } ,
20
20
} ;
21
21
22
22
/// GDB Session Manager
@@ -148,7 +148,7 @@ impl GDBManager {
148
148
& self ,
149
149
session_id : & str ,
150
150
command : & str ,
151
- ) -> AppResult < GDBCommandResponse > {
151
+ ) -> AppResult < String > {
152
152
let sessions = self . sessions . read ( ) . await ;
153
153
let handle = sessions
154
154
. get ( session_id)
@@ -158,24 +158,20 @@ impl GDBManager {
158
158
159
159
// Parse output
160
160
let success = !output. contains ( "^error" ) ;
161
- let error = if !success {
161
+ if !success {
162
162
// Extract error message
163
163
static ERROR_REGEX : LazyLock < Regex > =
164
164
LazyLock :: new ( || Regex :: new ( r#"\^error,msg="(.+)""# ) . unwrap ( ) ) ;
165
165
166
- ERROR_REGEX
166
+ let error = ERROR_REGEX
167
167
. captures ( & output)
168
168
. and_then ( |caps| caps. get ( 1 ) )
169
169
. map ( |m| m. as_str ( ) . to_string ( ) )
170
- } else {
171
- None
172
- } ;
170
+ . unwrap_or_else ( || "Unknown error" . to_string ( ) ) ;
171
+ return Err ( AppError :: GDBError ( error ) ) ;
172
+ }
173
173
174
- Ok ( GDBCommandResponse {
175
- success,
176
- output,
177
- error,
178
- } )
174
+ Ok ( output)
179
175
}
180
176
181
177
/// Send raw command to GDB
@@ -250,66 +246,50 @@ impl GDBManager {
250
246
& self ,
251
247
session_id : & str ,
252
248
command : & str ,
253
- ) -> AppResult < GDBCommandResponse > {
249
+ ) -> AppResult < String > {
254
250
let command_timeout = self . config . command_timeout ;
255
251
match tokio:: time:: timeout (
256
252
Duration :: from_secs ( command_timeout) ,
257
253
self . send_command ( session_id, command) ,
258
254
)
259
255
. await
260
256
{
261
- Ok ( result) => result ,
262
- Err ( _ ) => Err ( AppError :: GDBError ( format ! (
263
- "GDB command '{}' timed out" ,
264
- command
265
- ) ) ) ,
257
+ Ok ( Ok ( result) ) => {
258
+ Ok ( result )
259
+ }
260
+ Ok ( Err ( e ) ) => Err ( e ) ,
261
+ Err ( _ ) => Err ( AppError :: GDBTimeout ) ,
266
262
}
267
263
}
268
264
269
265
/// Start debugging
270
- pub async fn start_debugging ( & self , session_id : & str ) -> AppResult < ( ) > {
266
+ pub async fn start_debugging ( & self , session_id : & str ) -> AppResult < String > {
271
267
let response = self
272
268
. send_command_with_timeout ( session_id, "-exec-run" )
273
269
. await ?;
274
270
275
- if !response. success {
276
- return Err ( AppError :: GDBError (
277
- response
278
- . error
279
- . unwrap_or_else ( || "Failed to start debugging" . to_string ( ) ) ,
280
- ) ) ;
281
- }
282
-
283
271
// Update session status
284
272
let mut sessions = self . sessions . write ( ) . await ;
285
273
if let Some ( handle) = sessions. get_mut ( session_id) {
286
274
handle. info . status = GDBSessionStatus :: Running ;
287
275
}
288
276
289
- Ok ( ( ) )
277
+ Ok ( response )
290
278
}
291
279
292
280
/// Stop debugging
293
- pub async fn stop_debugging ( & self , session_id : & str ) -> AppResult < ( ) > {
281
+ pub async fn stop_debugging ( & self , session_id : & str ) -> AppResult < String > {
294
282
let response = self
295
283
. send_command_with_timeout ( session_id, "-exec-interrupt" )
296
284
. await ?;
297
285
298
- if !response. success {
299
- return Err ( AppError :: GDBError (
300
- response
301
- . error
302
- . unwrap_or_else ( || "Failed to stop debugging" . to_string ( ) ) ,
303
- ) ) ;
304
- }
305
-
306
286
// Update session status
307
287
let mut sessions = self . sessions . write ( ) . await ;
308
288
if let Some ( handle) = sessions. get_mut ( session_id) {
309
289
handle. info . status = GDBSessionStatus :: Stopped ;
310
290
}
311
291
312
- Ok ( ( ) )
292
+ Ok ( response )
313
293
}
314
294
315
295
/// Get breakpoint list
@@ -318,14 +298,6 @@ impl GDBManager {
318
298
. send_command_with_timeout ( session_id, "-break-list" )
319
299
. await ?;
320
300
321
- if !response. success {
322
- return Err ( AppError :: GDBError (
323
- response
324
- . error
325
- . unwrap_or_else ( || "Failed to get breakpoint list" . to_string ( ) ) ,
326
- ) ) ;
327
- }
328
-
329
301
// Parse breakpoint information (simplified version, actually needs more complex parsing)
330
302
let breakpoints = Vec :: new ( ) ;
331
303
@@ -345,14 +317,6 @@ impl GDBManager {
345
317
let command = format ! ( "-break-insert {}:{}" , file, line) ;
346
318
let response = self . send_command_with_timeout ( session_id, & command) . await ?;
347
319
348
- if !response. success {
349
- return Err ( AppError :: GDBError (
350
- response
351
- . error
352
- . unwrap_or_else ( || "Failed to set breakpoint" . to_string ( ) ) ,
353
- ) ) ;
354
- }
355
-
356
320
// Parse breakpoint ID (simplified)
357
321
let breakpoint_id = Uuid :: new_v4 ( ) . to_string ( ) ; // Should actually be extracted from response
358
322
@@ -365,19 +329,15 @@ impl GDBManager {
365
329
}
366
330
367
331
/// Delete breakpoint
368
- pub async fn delete_breakpoint ( & self , session_id : & str , breakpoint_id : & str ) -> AppResult < ( ) > {
332
+ pub async fn delete_breakpoint (
333
+ & self ,
334
+ session_id : & str ,
335
+ breakpoint_id : & str ,
336
+ ) -> AppResult < String > {
369
337
let command = format ! ( "-break-delete {}" , breakpoint_id) ;
370
338
let response = self . send_command_with_timeout ( session_id, & command) . await ?;
371
339
372
- if !response. success {
373
- return Err ( AppError :: GDBError (
374
- response
375
- . error
376
- . unwrap_or_else ( || "Failed to delete breakpoint" . to_string ( ) ) ,
377
- ) ) ;
378
- }
379
-
380
- Ok ( ( ) )
340
+ Ok ( response)
381
341
}
382
342
383
343
/// Get stack frames
@@ -386,14 +346,6 @@ impl GDBManager {
386
346
. send_command_with_timeout ( session_id, "-stack-list-frames" )
387
347
. await ?;
388
348
389
- if !response. success {
390
- return Err ( AppError :: GDBError (
391
- response
392
- . error
393
- . unwrap_or_else ( || "Failed to get stack frames" . to_string ( ) ) ,
394
- ) ) ;
395
- }
396
-
397
349
// Parse stack frame information (simplified)
398
350
let frames = Vec :: new ( ) ; // Actually needs to parse response
399
351
@@ -409,74 +361,42 @@ impl GDBManager {
409
361
let command = format ! ( "-stack-list-variables --frame {} --simple-values" , frame_id) ;
410
362
let response = self . send_command_with_timeout ( session_id, & command) . await ?;
411
363
412
- if !response. success {
413
- return Err ( AppError :: GDBError (
414
- response
415
- . error
416
- . unwrap_or_else ( || "Failed to get local variables" . to_string ( ) ) ,
417
- ) ) ;
418
- }
419
-
420
364
// Parse variable information (simplified)
421
365
let variables = Vec :: new ( ) ; // Actually needs to parse response
422
366
423
367
Ok ( variables)
424
368
}
425
369
426
370
/// Continue execution
427
- pub async fn continue_execution ( & self , session_id : & str ) -> AppResult < ( ) > {
371
+ pub async fn continue_execution ( & self , session_id : & str ) -> AppResult < String > {
428
372
let response = self
429
373
. send_command_with_timeout ( session_id, "-exec-continue" )
430
374
. await ?;
431
375
432
- if !response. success {
433
- return Err ( AppError :: GDBError (
434
- response
435
- . error
436
- . unwrap_or_else ( || "Failed to continue execution" . to_string ( ) ) ,
437
- ) ) ;
438
- }
439
-
440
376
// Update session status
441
377
let mut sessions = self . sessions . write ( ) . await ;
442
378
if let Some ( handle) = sessions. get_mut ( session_id) {
443
379
handle. info . status = GDBSessionStatus :: Running ;
444
380
}
445
381
446
- Ok ( ( ) )
382
+ Ok ( response )
447
383
}
448
384
449
385
/// Step execution
450
- pub async fn step_execution ( & self , session_id : & str ) -> AppResult < ( ) > {
386
+ pub async fn step_execution ( & self , session_id : & str ) -> AppResult < String > {
451
387
let response = self
452
388
. send_command_with_timeout ( session_id, "-exec-step" )
453
389
. await ?;
454
390
455
- if !response. success {
456
- return Err ( AppError :: GDBError (
457
- response
458
- . error
459
- . unwrap_or_else ( || "Failed to step execution" . to_string ( ) ) ,
460
- ) ) ;
461
- }
462
-
463
- Ok ( ( ) )
391
+ Ok ( response)
464
392
}
465
393
466
394
/// Next execution
467
- pub async fn next_execution ( & self , session_id : & str ) -> AppResult < ( ) > {
395
+ pub async fn next_execution ( & self , session_id : & str ) -> AppResult < String > {
468
396
let response = self
469
397
. send_command_with_timeout ( session_id, "-exec-next" )
470
398
. await ?;
471
399
472
- if !response. success {
473
- return Err ( AppError :: GDBError (
474
- response
475
- . error
476
- . unwrap_or_else ( || "Failed to execute next step" . to_string ( ) ) ,
477
- ) ) ;
478
- }
479
-
480
- Ok ( ( ) )
400
+ Ok ( response)
481
401
}
482
402
}
0 commit comments