[libunwind] [libunwind] Add unw_strerror function (PR #129084)
Tristan Ross via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 27 09:46:13 PST 2025
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/129084
>From 8fed3873f228232081533b614ac534473f6aa996 Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.ross at midstall.com>
Date: Thu, 27 Feb 2025 09:10:22 -0800
Subject: [PATCH] [libunwind] Add unw_strerror function
Co-authored-by: Randy Eckenrode <randy at largeandhighquality.com>
---
libunwind/include/libunwind.h | 1 +
libunwind/src/libunwind.cpp | 34 ++++++++++++++++++++++++++++++++++
libunwind/src/libunwind_ext.h | 1 +
3 files changed, 36 insertions(+)
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3..f75101e030428 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -114,6 +114,7 @@ extern int unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *) LIBUNWIND_
extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t) LIBUNWIND_AVAIL;
extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t) LIBUNWIND_AVAIL;
extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;
+extern const char *unw_strerror(int) LIBUNWIND_AVAIL;
#ifdef __arm__
/* Save VFP registers in FSTMX format (instead of FSTMD). */
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cf39ec5f7dbdf..9f50c43ef10f0 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -260,6 +260,40 @@ _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) {
}
_LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame)
+_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) {
+ switch (error_code) {
+ case UNW_ESUCCESS:
+ return "no error";
+ case UNW_EUNSPEC:
+ return "unspecified (general) error";
+ case UNW_ENOMEM:
+ return "out of memory";
+ case UNW_EBADREG:
+ return "bad register number";
+ case UNW_EREADONLYREG:
+ return "attempt to write read-only register";
+ case UNW_ESTOPUNWIND:
+ return "stop unwinding";
+ case UNW_EINVALIDIP:
+ return "invalid IP";
+ case UNW_EBADFRAME:
+ return "bad frame";
+ case UNW_EINVAL:
+ return "unsupported operation or bad value";
+ case UNW_EBADVERSION:
+ return "unwind info has unsupported version";
+ case UNW_ENOINFO:
+ return "no unwind info found";
+#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY)
+ case UNW_ECROSSRASIGNING:
+ return "cross unwind with return address signing";
+#endif
+ default:
+ return "unknown error occurred";
+ }
+}
+_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror)
+
#ifdef _AIX
_LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) {
_LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)",
diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h
index 28db43a4f6eef..ad9d15237fdc4 100644
--- a/libunwind/src/libunwind_ext.h
+++ b/libunwind/src/libunwind_ext.h
@@ -31,6 +31,7 @@ extern int __unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *);
extern int __unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t);
extern int __unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t);
extern int __unw_resume(unw_cursor_t *);
+extern const char *__unw_strerror(int);
#ifdef __arm__
/* Save VFP registers in FSTMX format (instead of FSTMD). */
More information about the cfe-commits
mailing list