"printf("line: %d \n", __LINE__);" does not work on System Workbench
I’ve tried using semihosting in the past and ran into similar problems - crashes the target if no debugger is connected, along with the fact that I/O blocks and is SLOW.
My personal preference is to use a free USART channel for debug I/O. The trick in doing this is that you need a decent USART I/O library (preferably one that supports nonblocking, buffered operation) and need to know how to create and set up (at a minimum) the _read() and _write() functions that will redirect stdin/stdout/stderr output to the USART.