@@ -110,32 +110,44 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
110110 struct semihosting * semihosting = target -> semihosting ;
111111 assert (semihosting );
112112
113- if (!semihosting -> is_active ) {
114- LOG_TARGET_DEBUG (target , "Semihosting outcome: NONE (semihosting not enabled)" );
115- return SEMIHOSTING_NONE ;
116- }
117-
118113 riscv_reg_t pc ;
119114 int result = riscv_reg_get (target , & pc , GDB_REGNO_PC );
120115 if (result != ERROR_OK ) {
121116 LOG_TARGET_DEBUG (target , "Semihosting outcome: ERROR (failed to read PC)" );
122117 return SEMIHOSTING_ERROR ;
123118 }
124119
125- bool sequence_found ;
120+ bool sequence_found = false ;
126121 * retval = riscv_semihosting_detect_magic_sequence (target , pc , & sequence_found );
127122 if (* retval != ERROR_OK ) {
128123 LOG_TARGET_DEBUG (target , "Semihosting outcome: ERROR (during magic seq. detection)" );
129124 return SEMIHOSTING_ERROR ;
130125 }
131126
127+ if (!semihosting -> is_active ) {
128+ if (sequence_found ) {
129+ // If semihositing is encountered but disabled, provide an additional hint to the user.
130+ LOG_TARGET_WARNING (target , "RISC-V semihosting call encountered in the program "
131+ "but semihosting is disabled!" );
132+ LOG_TARGET_WARNING (target , "The target will remain halted (PC = 0x%" TARGET_PRIxADDR ")." , pc );
133+ LOG_TARGET_WARNING (target , "Hint: Restart your debug session and enable semihosting "
134+ "by command 'arm semihosting enable'." );
135+ // TODO: This can be improved: The ebreak halt cause detection and riscv_semihosting() call
136+ // can be added also to "arm semihosting enable", which would allow the user to continue
137+ // without restart of the debug session.
138+ }
139+
140+ LOG_TARGET_DEBUG (target , "Semihosting outcome: NONE (semihosting not enabled)" );
141+ return SEMIHOSTING_NONE ;
142+ }
143+
132144 if (!sequence_found ) {
133145 LOG_TARGET_DEBUG (target , "Semihosting outcome: NONE (no magic sequence)" );
134146 return SEMIHOSTING_NONE ;
135147 }
136148
137149 /* Otherwise we have a semihosting call (and semihosting is enabled).
138- * Proceed with the semihosting. */
150+ * Proceed with the handling of semihosting. */
139151
140152 /*
141153 * Perform semihosting call if we are not waiting on a fileio
0 commit comments