[PATCH] D131709: [libunwind][AIX] Implement _Unwind_FindEnclosingFunction() using traceback table on AIX

Xing Xue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 15:09:37 PDT 2022


This revision was automatically updated to reflect the committed changes.
xingxue marked 3 inline comments as done.
Closed by commit rG2366c6adfc95: [libunwind][AIX] Implement _Unwind_FindEnclosingFunction() using traceback… (authored by xingxue).

Changed prior to commit:
  https://reviews.llvm.org/D131709?vs=452220&id=452312#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131709/new/

https://reviews.llvm.org/D131709

Files:
  libunwind/src/UnwindLevel1-gcc-ext.c
  libunwind/src/Unwind_AIXExtras.cpp


Index: libunwind/src/Unwind_AIXExtras.cpp
===================================================================
--- libunwind/src/Unwind_AIXExtras.cpp
+++ libunwind/src/Unwind_AIXExtras.cpp
@@ -38,7 +38,7 @@
   if (TBTable->tb.fixedparms || TBTable->tb.floatparms)
     p++;
 
-  // If the tb_offset field exisits, get the offset from the start of
+  // If the tb_offset field exists, get the offset from the start of
   // the function to pc. Skip the field.
   if (TBTable->tb.has_tboff) {
     unw_word_t StartIp =
Index: libunwind/src/UnwindLevel1-gcc-ext.c
===================================================================
--- libunwind/src/UnwindLevel1-gcc-ext.c
+++ libunwind/src/UnwindLevel1-gcc-ext.c
@@ -22,6 +22,10 @@
 #include "Unwind-EHABI.h"
 #include "unwind.h"
 
+#if defined(_AIX)
+#include <sys/debug.h>
+#endif
+
 #if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS)
 
 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
@@ -82,6 +86,32 @@
 /// specified code address "pc".
 _LIBUNWIND_EXPORT void *_Unwind_FindEnclosingFunction(void *pc) {
   _LIBUNWIND_TRACE_API("_Unwind_FindEnclosingFunction(pc=%p)", pc);
+#if defined(_AIX)
+  if (pc == NULL)
+    return NULL;
+
+  // Get the start address of the enclosing function from the function's
+  // traceback table.
+  uint32_t *p = (uint32_t *)pc;
+
+  // Keep looking forward until a word of 0 is found. The traceback
+  // table starts at the following word.
+  while (*p)
+    ++p;
+  struct tbtable *TBTable = (struct tbtable *)(p + 1);
+
+  // Get the address of the traceback table extension.
+  p = (uint32_t *)&TBTable->tb_ext;
+
+  // Skip field parminfo if it exists.
+  if (TBTable->tb.fixedparms || TBTable->tb.floatparms)
+    ++p;
+
+  if (TBTable->tb.has_tboff)
+    // *p contains the offset from the function start to traceback table.
+    return (void *)((uintptr_t)TBTable - *p - sizeof(uint32_t));
+  return NULL;
+#else
   // This is slow, but works.
   // We create an unwind cursor then alter the IP to be pc
   unw_cursor_t cursor;
@@ -94,6 +124,7 @@
     return (void *)(intptr_t) info.start_ip;
   else
     return NULL;
+#endif
 }
 
 /// Walk every frame and call trace function at each one.  If trace function


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131709.452312.patch
Type: text/x-patch
Size: 2191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220812/85b734c6/attachment.bin>


More information about the llvm-commits mailing list