Hello,

I need to resolve function name by its IP, but found
only unw_get_proc_name() which needs cursor and unw_get_proc_info_by_ip()
which doesn't return function name.
After checking source I found src/mi/Gget_proc_name.c:get_proc_name()
static function which does exactly what I need.
Is it ok to export it as unw_get_proc_name_by_ip() ?

I attached patch that does exactly that and it seems to work fine for me
(local unwinding, linux, x86_64).

Thanks!
diff --git a/include/libunwind-common.h.in b/include/libunwind-common.h.in
index fa753ba..30f1908 100644
--- a/include/libunwind-common.h.in
+++ b/include/libunwind-common.h.in
@@ -224,6 +224,7 @@ unw_save_loc_t;
 #define unw_is_signal_frame    UNW_OBJ(is_signal_frame)
 #define unw_handle_signal_frame        UNW_OBJ(handle_signal_frame)
 #define unw_get_proc_name      UNW_OBJ(get_proc_name)
+#define unw_get_proc_name_by_ip        UNW_OBJ(get_proc_name_by_ip)
 #define unw_set_caching_policy UNW_OBJ(set_caching_policy)
 #define unw_regname            UNW_ARCH_OBJ(regname)
 #define unw_flush_cache                UNW_ARCH_OBJ(flush_cache)
@@ -251,6 +252,8 @@ extern int unw_get_save_loc (unw_cursor_t *, int, 
unw_save_loc_t *);
 extern int unw_is_signal_frame (unw_cursor_t *);
 extern int unw_handle_signal_frame (unw_cursor_t *);
 extern int unw_get_proc_name (unw_cursor_t *, char *, size_t, unw_word_t *);
+extern int unw_get_proc_name_by_ip (unw_addr_space_t, unw_word_t, char *,
+                                   size_t, unw_word_t *, void *);
 extern const char *unw_strerror (int);
 extern int unw_backtrace (void **, int);
 
diff --git a/src/mi/Gget_proc_name.c b/src/mi/Gget_proc_name.c
index 7251c59..f658a85 100644
--- a/src/mi/Gget_proc_name.c
+++ b/src/mi/Gget_proc_name.c
@@ -45,9 +45,10 @@ intern_string (unw_addr_space_t as, unw_accessors_t *a,
   return -UNW_ENOMEM;
 }
 
-static inline int
-get_proc_name (unw_addr_space_t as, unw_word_t ip,
-              char *buf, size_t buf_len, unw_word_t *offp, void *arg)
+PROTECTED int
+unw_get_proc_name_by_ip (unw_addr_space_t as, unw_word_t ip,
+                        char *buf, size_t buf_len, unw_word_t *offp,
+                        void *arg)
 {
   unw_accessors_t *a = unw_get_accessors (as);
   unw_proc_info_t pi;
@@ -101,6 +102,6 @@ unw_get_proc_name (unw_cursor_t *cursor, char *buf, size_t 
buf_len,
 {
   struct cursor *c = (struct cursor *) cursor;
 
-  return get_proc_name (tdep_get_as (c), tdep_get_ip (c), buf, buf_len, offp,
+  return unw_get_proc_name_by_ip (tdep_get_as (c), tdep_get_ip (c), buf, 
buf_len, offp,
                        tdep_get_as_arg (c));
 }
diff --git a/tests/check-namespace.sh.in b/tests/check-namespace.sh.in
index d2e6efb..f93994f 100644
--- a/tests/check-namespace.sh.in
+++ b/tests/check-namespace.sh.in
@@ -94,6 +94,7 @@ check_local_unw_abi () {
     match _UL${plat}_get_proc_info
     match _UL${plat}_get_proc_info_by_ip
     match _UL${plat}_get_proc_name
+    match _UL${plat}_get_proc_name_by_ip
     match _UL${plat}_get_reg
     match _UL${plat}_get_save_loc
     match _UL${plat}_init_local
@@ -180,6 +181,7 @@ check_generic_unw_abi () {
     match _U${plat}_get_proc_info
     match _U${plat}_get_proc_info_by_ip
     match _U${plat}_get_proc_name
+    match _U${plat}_get_proc_name_by_ip
     match _U${plat}_get_reg
     match _U${plat}_get_save_loc
     match _U${plat}_init_local
_______________________________________________
Libunwind-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/libunwind-devel

Reply via email to