Skip to content

Commit 7652923

Browse files
committed
libunwind: Implement the unw_strerror function for better nongnu libunwind compatibility
1 parent 94213a4 commit 7652923

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
@@ -130,6 +130,7 @@ extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
130130
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
131131
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
132132
//extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
133+
extern const char *unw_strerror(int) LIBUNWIND_AVAIL;
133134

134135
extern unw_addr_space_t unw_local_addr_space;
135136

libunwind/src/libunwind.cpp

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

349349
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
350+
351+
/// Maps the UNW_* error code to a textual representation
352+
_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) {
353+
switch (error_code) {
354+
case UNW_ESUCCESS:
355+
return "no error";
356+
case UNW_EUNSPEC:
357+
return "unspecified (general) error";
358+
case UNW_ENOMEM:
359+
return "out of memory";
360+
case UNW_EBADREG:
361+
return "bad register number";
362+
case UNW_EREADONLYREG:
363+
return "attempt to write read-only register";
364+
case UNW_ESTOPUNWIND:
365+
return "stop unwinding";
366+
case UNW_EINVALIDIP:
367+
return "invalid IP";
368+
case UNW_EBADFRAME:
369+
return "bad frame";
370+
case UNW_EINVAL:
371+
return "unsupported operation or bad value";
372+
case UNW_EBADVERSION:
373+
return "unwind info has unsupported version";
374+
case UNW_ENOINFO:
375+
return "no unwind info found";
376+
#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY)
377+
case UNW_ECROSSRASIGNING:
378+
return "return address require authentication";
379+
#endif
380+
}
381+
return "invalid error code";
382+
}
383+
_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror)
384+
350385
#endif // !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
351386

352387
#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)