@@ -1606,9 +1606,7 @@ update_debug_reason(target* const p_target)
16061606
16071607 if (debug_reason != p_target -> debug_reason ) {
16081608 p_target -> debug_reason = debug_reason ;
1609- LOG_DEBUG ("Target %s New debug reason:"
1610- " 0x%d"
1611- " (%s)" ,
1609+ LOG_DEBUG ("Target %s: New debug reason: %d (%s)" ,
16121610 target_name (p_target ),
16131611 (unsigned )(p_target -> debug_reason ),
16141612 debug_reason_name (p_target ));
@@ -1652,7 +1650,7 @@ update_debug_status(target* const p_target)
16521650
16531651 case TARGET_RUNNING :
16541652 p_target -> debug_reason = DBG_REASON_NOTHALTED ;
1655- LOG_DEBUG ("Target %s: New debug reason: 0x%08X (%s)" ,
1653+ LOG_DEBUG ("Target %s: New debug reason: %d (%s)" ,
16561654 target_name (p_target ), p_target -> debug_reason , debug_reason_name (p_target ));
16571655 target_call_event_callbacks (p_target , TARGET_EVENT_RESUMED );
16581656 break ;
@@ -3225,57 +3223,43 @@ resume_common(target* const p_target,
32253223 assert (!p_pc -> dirty );
32263224 }
32273225
3228- if (handle_breakpoints ) {
3229- if (current ) {
3230- // Find breakpoint for current instruction
3231- sc_error_code__update (p_target , reg_pc__get (p_pc ));
3232- assert (p_pc -> value );
3233- uint32_t const pc = buf_get_u32 (p_pc -> value , 0 , XLEN );
3234- breakpoint * p_breakpoint_at_pc = find_breakpoint_by_address (p_target , pc );
3226+ if (0 != handle_breakpoints && 0 != current ) {
3227+ // Find breakpoint for current instruction
3228+ sc_error_code__update (p_target , reg_pc__get (p_pc ));
3229+ assert (p_pc -> value );
3230+ uint32_t const pc = buf_get_u32 (p_pc -> value , 0 , XLEN );
3231+ breakpoint * p_breakpoint_at_pc = find_breakpoint_by_address (p_target , pc );
32353232
3236- if (p_breakpoint_at_pc ) {
3237- // exec single step without breakpoint
3238- sc_riscv32__Arch const * const p_arch = p_target -> arch_info ;
3239- assert (p_arch );
3240- // remove breakpoint
3241- sc_error_code__update (p_target , target_remove_breakpoint (p_target , p_breakpoint_at_pc ));
3242- // prepare for single step
3243- reg_cache__chain_invalidate (p_target -> reg_cache );
3244- // force single step
3245- set_DEMODE_ENBL (p_target , dmode_enabled | HART_DMODE_ENBL_bit_SStep );
3246- sc_rv32_DAP_CTRL_REG_set (p_target , p_target -> coreid == 0 ? DBGC_unit_id_HART_0 : DBGC_unit_id_HART_1 , DBGC_functional_group_HART_DBGCMD );
3247- // resume for single step
3248- sc_rv32_DAP_CMD_scan (p_target , DBG_CTRL_index , DBG_CTRL_bit_Resume | DBG_CTRL_bit_Sticky_Clr , NULL );
3249- // restore breakpoint
3250- sc_error_code__update (p_target , target_add_breakpoint (p_target , p_breakpoint_at_pc ));
3251-
3252- // If resume/halt already done (by single step)
3253- if (0 != (dmode_enabled & HART_DMODE_ENBL_bit_SStep )) {
3254- // TODO: extra call
3255- reg_cache__chain_invalidate (p_target -> reg_cache );
3256- // set status
3257- p_target -> state = debug_execution ? TARGET_DEBUG_RUNNING : TARGET_RUNNING ;
3258- LOG_DEBUG ("Target %s: Debug_status changed: %d (%s)" ,
3259- target_name (p_target ), p_target -> state , target_state_name (p_target ));
3260- // raise resume event
3261- target_call_event_callbacks (p_target , debug_execution ? TARGET_EVENT_DEBUG_RESUMED : TARGET_EVENT_RESUMED );
3262- // setup debug mode
3263- set_DEMODE_ENBL (p_target , dmode_enabled );
3264- // set debug reason
3265- sc_riscv32__update_status (p_target );
3266-
3267- if (!target_was_examined (p_target )) {
3268- return sc_error_code__get_and_clear (p_target );
3269- }
3270-
3271- p_target -> debug_reason = DBG_REASON_SINGLESTEP ;
3272- LOG_DEBUG ("Target %s: New debug reason: 0x%08X (%s)" ,
3273- target_name (p_target ), p_target -> debug_reason , debug_reason_name (p_target ));
3274- // raise halt event
3275- target_call_event_callbacks (p_target , debug_execution ? TARGET_EVENT_DEBUG_HALTED : TARGET_EVENT_HALTED );
3276- // and exit
3277- return sc_error_code__get_and_clear (p_target );
3278- }
3233+ if (p_breakpoint_at_pc ) {
3234+ // exec single step without breakpoint
3235+ sc_riscv32__Arch const * const p_arch = p_target -> arch_info ;
3236+ assert (p_arch );
3237+ // remove breakpoint
3238+ sc_error_code__update (p_target , target_remove_breakpoint (p_target , p_breakpoint_at_pc ));
3239+ // prepare for single step
3240+ reg_cache__chain_invalidate (p_target -> reg_cache );
3241+ // force single step
3242+ set_DEMODE_ENBL (p_target , dmode_enabled | HART_DMODE_ENBL_bit_SStep );
3243+ sc_rv32_DAP_CTRL_REG_set (p_target , p_target -> coreid == 0 ? DBGC_unit_id_HART_0 : DBGC_unit_id_HART_1 , DBGC_functional_group_HART_DBGCMD );
3244+ // resume for single step
3245+ sc_rv32_DAP_CMD_scan (p_target , DBG_CTRL_index , DBG_CTRL_bit_Resume | DBG_CTRL_bit_Sticky_Clr , NULL );
3246+ // restore breakpoint
3247+ sc_error_code__update (p_target , target_add_breakpoint (p_target , p_breakpoint_at_pc ));
3248+ // setup debug mode
3249+ set_DEMODE_ENBL (p_target , dmode_enabled );
3250+
3251+ // If resume/halt already done (by single step)
3252+ if (0 != (dmode_enabled & HART_DMODE_ENBL_bit_SStep )) {
3253+ LOG_DEBUG ("Target %s: single step done" ,
3254+ target_name (p_target ));
3255+ // set status
3256+ p_target -> state = debug_execution ? TARGET_DEBUG_RUNNING : TARGET_RUNNING ;
3257+ LOG_DEBUG ("Target %s: Debug_status changed: %d (%s)" ,
3258+ target_name (p_target ), p_target -> state , target_state_name (p_target ));
3259+ // raise resume event
3260+ target_call_event_callbacks (p_target , debug_execution ? TARGET_EVENT_DEBUG_RESUMED : TARGET_EVENT_RESUMED );
3261+ // and exit
3262+ return sc_error_code__get_and_clear (p_target );
32793263 }
32803264 }
32813265 }
@@ -3307,8 +3291,6 @@ resume_common(target* const p_target,
33073291 LOG_DEBUG ("Target %s: Debug_status changed: %d (%s)" ,
33083292 target_name (p_target ), p_target -> state , target_state_name (p_target ));
33093293 target_call_event_callbacks (p_target , debug_execution ? TARGET_EVENT_DEBUG_RESUMED : TARGET_EVENT_RESUMED );
3310-
3311- sc_riscv32__update_status (p_target );
33123294 return sc_error_code__get_and_clear (p_target );
33133295}
33143296
@@ -3683,6 +3665,8 @@ error_code
36833665sc_riscv32__poll (target * const p_target )
36843666{
36853667 assert (p_target );
3668+ LOG_DEBUG ("Target %s: poll" ,
3669+ target_name (p_target ));
36863670 invalidate_DAP_CTR_cache (p_target );
36873671 sc_riscv32__update_status (p_target );
36883672 return sc_error_code__get_and_clear (p_target );
0 commit comments