Skip to content

Commit 5465979

Browse files
authored
libunwind: Implement the unw_strerror function for better nongnu libunwind compatibility (llvm#160887)
As it was explained to me in https://discourse.llvm.org/t/libunwinds-raison-detre/88283/2 the LLVM version of libunwind is mostly compatible with nongnu one. This change improves the compatibility a bit further.
1 parent c5aace4 commit 5465979

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
@@ -409,6 +409,41 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
409409
}
410410

411411
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
412+
413+
/// Maps the UNW_* error code to a textual representation
414+
_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) {
415+
switch (error_code) {
416+
case UNW_ESUCCESS:
417+
return "no error";
418+
case UNW_EUNSPEC:
419+
return "unspecified (general) error";
420+
case UNW_ENOMEM:
421+
return "out of memory";
422+
case UNW_EBADREG:
423+
return "bad register number";
424+
case UNW_EREADONLYREG:
425+
return "attempt to write read-only register";
426+
case UNW_ESTOPUNWIND:
427+
return "stop unwinding";
428+
case UNW_EINVALIDIP:
429+
return "invalid IP";
430+
case UNW_EBADFRAME:
431+
return "bad frame";
432+
case UNW_EINVAL:
433+
return "unsupported operation or bad value";
434+
case UNW_EBADVERSION:
435+
return "unwind info has unsupported version";
436+
case UNW_ENOINFO:
437+
return "no unwind info found";
438+
#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY)
439+
case UNW_ECROSSRASIGNING:
440+
return "cross unwind with return address signing";
441+
#endif
442+
}
443+
return "invalid error code";
444+
}
445+
_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror)
446+
412447
#endif // !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
413448

414449
#ifdef __APPLE__

libunwind/src/libunwind_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern int __unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *);
4646
extern int __unw_is_fpreg(unw_cursor_t *, unw_regnum_t);
4747
extern int __unw_is_signal_frame(unw_cursor_t *);
4848
extern int __unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *);
49+
extern const char *__unw_strerror(int);
4950

5051
#if defined(_AIX)
5152
extern uintptr_t __unw_get_data_rel_base(unw_cursor_t *);

0 commit comments

Comments
 (0)