I have an embedded project using a STM32F103 (ARM Cortex M3), it is getting a occasionally getting hard fault in release mode. As part of recovery, I would like to retrieve
You should look into the ARM Architecture Reference Manual in the section on Exceptions. You need to register to get it.
Typically a relevant address will be put in the link register LR (R14), but the precise meaning varies according to the exception, and there are varying offsets.
W.r.t. accessing the User/System mode register bank, I think you need to switch the mode to access it.