@@ -128,7 +128,8 @@ mod debug {
128
128
/// The first 4 debug registers are used to set the addresses
129
129
/// The 4th and 5th debug registers are obsolete and not used
130
130
/// The 7th debug register is used to enable the breakpoints
131
- /// For more information see: https://en.wikipedia.org/wiki/X86_debug_register
131
+ /// For more information see: DEBUG REGISTERS chapter in the architecture
132
+ /// manual
132
133
fn set_debug_config ( & mut self , vcpu_fd : & VcpuFd , step : bool ) -> Result < ( ) > {
133
134
let addrs = & self . hw_breakpoints ;
134
135
@@ -417,7 +418,7 @@ mod debug {
417
418
let save_data = debug
418
419
. sw_breakpoints
419
420
. remove ( & addr)
420
- . expect ( "Expected the hashmap to contain the address" ) ;
421
+ . ok_or_else ( || new_error ! ( "Expected the hashmap to contain the address" ) ) ? ;
421
422
422
423
( true , Some ( save_data) )
423
424
} else {
@@ -481,19 +482,12 @@ mod debug {
481
482
dbg_mem_access_fn : Arc < Mutex < dyn DbgMemAccessHandlerCaller > > ,
482
483
) -> Result < DebugResponse > {
483
484
match req {
484
- DebugMsg :: AddHwBreakpoint ( addr) => {
485
- let res = self
486
- . add_hw_breakpoint ( addr)
487
- . expect ( "Add hw breakpoint error" ) ;
488
- Ok ( DebugResponse :: AddHwBreakpoint ( res) )
489
- }
490
- DebugMsg :: AddSwBreakpoint ( addr) => {
491
- let res = self
492
- . add_sw_breakpoint ( addr, dbg_mem_access_fn)
493
- . expect ( "Add sw breakpoint error" ) ;
494
-
495
- Ok ( DebugResponse :: AddSwBreakpoint ( res) )
496
- }
485
+ DebugMsg :: AddHwBreakpoint ( addr) => self
486
+ . add_hw_breakpoint ( addr)
487
+ . map ( DebugResponse :: AddHwBreakpoint ) ,
488
+ DebugMsg :: AddSwBreakpoint ( addr) => self
489
+ . add_sw_breakpoint ( addr, dbg_mem_access_fn)
490
+ . map ( DebugResponse :: AddSwBreakpoint ) ,
497
491
DebugMsg :: Continue => {
498
492
self . set_single_step ( false ) ?;
499
493
Ok ( DebugResponse :: Continue )
@@ -520,21 +514,16 @@ mod debug {
520
514
}
521
515
DebugMsg :: ReadRegisters => {
522
516
let mut regs = X86_64Regs :: default ( ) ;
523
- self . read_regs ( & mut regs) . expect ( "Read Regs error" ) ;
524
- Ok ( DebugResponse :: ReadRegisters ( regs) )
525
- }
526
- DebugMsg :: RemoveHwBreakpoint ( addr) => {
527
- let res = self
528
- . remove_hw_breakpoint ( addr)
529
- . expect ( "Remove hw breakpoint error" ) ;
530
- Ok ( DebugResponse :: RemoveHwBreakpoint ( res) )
531
- }
532
- DebugMsg :: RemoveSwBreakpoint ( addr) => {
533
- let res = self
534
- . remove_sw_breakpoint ( addr, dbg_mem_access_fn)
535
- . expect ( "Remove sw breakpoint error" ) ;
536
- Ok ( DebugResponse :: RemoveSwBreakpoint ( res) )
517
+
518
+ self . read_regs ( & mut regs)
519
+ . map ( |_| DebugResponse :: ReadRegisters ( regs) )
537
520
}
521
+ DebugMsg :: RemoveHwBreakpoint ( addr) => self
522
+ . remove_hw_breakpoint ( addr)
523
+ . map ( DebugResponse :: RemoveHwBreakpoint ) ,
524
+ DebugMsg :: RemoveSwBreakpoint ( addr) => self
525
+ . remove_sw_breakpoint ( addr, dbg_mem_access_fn)
526
+ . map ( DebugResponse :: RemoveSwBreakpoint ) ,
538
527
DebugMsg :: Step => {
539
528
self . set_single_step ( true ) ?;
540
529
Ok ( DebugResponse :: Step )
@@ -544,10 +533,9 @@ mod debug {
544
533
545
534
Ok ( DebugResponse :: WriteAddr )
546
535
}
547
- DebugMsg :: WriteRegisters ( regs) => {
548
- self . write_regs ( & regs) . expect ( "Write Regs error" ) ;
549
- Ok ( DebugResponse :: WriteRegisters )
550
- }
536
+ DebugMsg :: WriteRegisters ( regs) => self
537
+ . write_regs ( & regs)
538
+ . map ( |_| DebugResponse :: WriteRegisters ) ,
551
539
}
552
540
}
553
541
@@ -557,9 +545,12 @@ mod debug {
557
545
. as_mut ( )
558
546
. ok_or_else ( || new_error ! ( "Debug is not enabled" ) ) ?;
559
547
560
- gdb_conn
561
- . recv ( )
562
- . map_err ( |e| new_error ! ( "Got an error while waiting to receive a message: {:?}" , e) )
548
+ gdb_conn. recv ( ) . map_err ( |e| {
549
+ new_error ! (
550
+ "Got an error while waiting to receive a message from the gdb thread: {:?}" ,
551
+ e
552
+ )
553
+ } )
563
554
}
564
555
565
556
pub fn send_dbg_msg ( & mut self , cmd : DebugResponse ) -> Result < ( ) > {
@@ -570,9 +561,12 @@ mod debug {
570
561
. as_mut ( )
571
562
. ok_or_else ( || new_error ! ( "Debug is not enabled" ) ) ?;
572
563
573
- gdb_conn
574
- . send ( cmd)
575
- . map_err ( |e| new_error ! ( "Got an error while sending a response message {:?}" , e) )
564
+ gdb_conn. send ( cmd) . map_err ( |e| {
565
+ new_error ! (
566
+ "Got an error while sending a response message to the gdb thread: {:?}" ,
567
+ e
568
+ )
569
+ } )
576
570
}
577
571
}
578
572
}
@@ -854,11 +848,12 @@ impl Hypervisor for KVMDriver {
854
848
}
855
849
}
856
850
#[ cfg( gdb) ]
857
- Ok ( VcpuExit :: Debug ( _) ) => {
858
- let reason = self . get_stop_reason ( ) ?;
859
-
860
- HyperlightExit :: Debug ( reason)
861
- }
851
+ Ok ( VcpuExit :: Debug ( _) ) => match self . get_stop_reason ( ) {
852
+ Ok ( reason) => HyperlightExit :: Debug ( reason) ,
853
+ Err ( e) => {
854
+ log_then_return ! ( "Error getting stop reason: {:?}" , e) ;
855
+ }
856
+ } ,
862
857
Err ( e) => match e. errno ( ) {
863
858
// In case of the gdb feature, the timeout is not enabled, this
864
859
// exit is because of a signal sent from the gdb thread to the
0 commit comments