Separate backtrace formatting from error handling

Signed-off-by: Michal Čihař <michal@cihar.com>
Share code for backtrace formatting

Signed-off-by: Michal Čihař <michal@cihar.com>