(mut gdbstub: GdbStub, path: &std::path::Path)
| 507 | } |
| 508 | |
| 509 | pub fn gdb_thread(mut gdbstub: GdbStub, path: &std::path::Path) { |
| 510 | let listener = match UnixListener::bind(path) { |
| 511 | Ok(s) => s, |
| 512 | Err(e) => { |
| 513 | error!("Failed to create a Unix domain socket listener: {e}"); |
| 514 | return; |
| 515 | } |
| 516 | }; |
| 517 | info!("Waiting for a GDB connection on {}...", path.display()); |
| 518 | |
| 519 | let (stream, addr) = match listener.accept() { |
| 520 | Ok(v) => v, |
| 521 | Err(e) => { |
| 522 | error!("Failed to accept a connection from GDB: {e}"); |
| 523 | return; |
| 524 | } |
| 525 | }; |
| 526 | info!("GDB connected from {addr:?}"); |
| 527 | |
| 528 | let connection: Box<dyn ConnectionExt<Error = std::io::Error>> = Box::new(stream); |
| 529 | let gdb = gdbstub::stub::GdbStub::new(connection); |
| 530 | |
| 531 | match gdb.run_blocking::<GdbEventLoop>(&mut gdbstub) { |
| 532 | Ok(disconnect_reason) => match disconnect_reason { |
| 533 | DisconnectReason::Disconnect => { |
| 534 | info!("GDB client has disconnected. Running..."); |
| 535 | |
| 536 | if let Err(e) = gdbstub.vm_request(GdbRequestPayload::SetSingleStep(false), 0) { |
| 537 | error!("Failed to disable single step: {e:?}"); |
| 538 | } |
| 539 | |
| 540 | if let Err(e) = |
| 541 | gdbstub.vm_request(GdbRequestPayload::SetHwBreakPoint(Vec::new()), 0) |
| 542 | { |
| 543 | error!("Failed to remove breakpoints: {e:?}"); |
| 544 | } |
| 545 | |
| 546 | if let Err(e) = gdbstub.vm_request(GdbRequestPayload::Resume, 0) { |
| 547 | error!("Failed to resume the VM: {e:?}"); |
| 548 | } |
| 549 | } |
| 550 | _ => { |
| 551 | error!("Target exited or terminated"); |
| 552 | } |
| 553 | }, |
| 554 | Err(e) => { |
| 555 | error!("error occurred in GDB session: {e}"); |
| 556 | } |
| 557 | } |
| 558 | } |
no test coverage detected