Skip to content

Commit 4c133e4

Browse files
committed
libunwind: Implement the unw_strerror function for better nongnu libunwind compatibility
1 parent a4ffa1f commit 4c133e4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

libunwind/include/libunwind.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
234234
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
235235
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
236236
//extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
237+
extern const char *unw_strerror(int) LIBUNWIND_AVAIL;
237238

238239
extern unw_addr_space_t unw_local_addr_space;
239240

libunwind/src/libunwind.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,41 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
389389
}
390390

391391
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
392+
393+
/// Maps the UNW_* error code to a textual representation
394+
_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) {
395+
switch (error_code) {
396+
case UNW_ESUCCESS:
397+
return "no error";
398+
case UNW_EUNSPEC:
399+
return "unspecified (general) error";
400+
case UNW_ENOMEM:
401+
return "out of memory";
402+
case UNW_EBADREG:
403+
return "bad register number";
404+
case UNW_EREADONLYREG:
405+
return "attempt to write read-only register";
406+
case UNW_ESTOPUNWIND:
407+
return "stop unwinding";
408+
case UNW_EINVALIDIP:
409+
return "invalid IP";
410+
case UNW_EBADFRAME:
411+
return "bad frame";
412+
case UNW_EINVAL:
413+
return "unsupported operation or bad value";
414+
case UNW_EBADVERSION:
415+
return "unwind info has unsupported version";
416+
case UNW_ENOINFO:
417+
return "no unwind info found";
418+
#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY)
419+
case UNW_ECROSSRASIGNING:
420+
return "cross unwind with return address signing";
421+
#endif
422+
}
423+
return "invalid error code";
424+
}
425+
_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror)
426+
392427
#endif // !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
393428

394429
#ifdef __APPLE__

libunwind/src/libunwind_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern int __unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *);
4242
extern int __unw_is_fpreg(unw_cursor_t *, unw_regnum_t);
4343
extern int __unw_is_signal_frame(unw_cursor_t *);
4444
extern int __unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *);
45+
extern const char *__unw_strerror(int);
4546

4647
#if defined(_AIX)
4748
extern uintptr_t __unw_get_data_rel_base(unw_cursor_t *);

0 commit comments

Comments
 (0)