This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch refactor-s2
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit c0c3349298044982181cbf5035639d76c16760ed
Author: tqchen <[email protected]>
AuthorDate: Mon Apr 21 19:15:11 2025 -0400

    [FFI] improve traceback
---
 ffi/src/ffi/traceback.cc |  3 +++
 ffi/src/ffi/traceback.h  | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/ffi/src/ffi/traceback.cc b/ffi/src/ffi/traceback.cc
index 897b054d29..7cebc37774 100644
--- a/ffi/src/ffi/traceback.cc
+++ b/ffi/src/ffi/traceback.cc
@@ -99,6 +99,9 @@ int BacktraceFullCallback(void* data, uintptr_t pc, const 
char* filename, int li
   if (stack_trace->ExceedTracebackLimit()) {
     return 1;
   }
+  if (ShouldStopTraceback(filename, symbol)) {
+    return 1;
+  }
   if (ShouldExcludeFrame(filename, symbol)) {
     return 0;
   }
diff --git a/ffi/src/ffi/traceback.h b/ffi/src/ffi/traceback.h
index 0d1c104bf1..c42bd9ca48 100644
--- a/ffi/src/ffi/traceback.h
+++ b/ffi/src/ffi/traceback.h
@@ -103,6 +103,25 @@ inline bool ShouldExcludeFrame(const char* filename, const 
char* symbol) {
   return false;
 }
 
+/**
+ * \brief List frames that should stop the traceback.
+ * \param filename The filename of the frame.
+ * \param symbol The symbol name of the frame.
+ * \return true if the frame should stop the traceback.
+ * \note We stop traceback at the FFI boundary.
+ */
+inline bool ShouldStopTraceback(const char* filename, const char* symbol) {
+  if (symbol != nullptr) {
+    if (strncmp(symbol, "TVMFFIFuncCall", 14) == 0) {
+      return true;
+    }
+    if (strncmp(symbol, "TVMFuncCall", 11) == 0) {
+      return true;
+    }
+  }
+  return false;
+}
+
 /*!
  * \brief storage to store traceback
  */
@@ -115,6 +134,9 @@ struct TracebackStorage {
     // skip frames with empty filename
     if (filename == nullptr) {
       if (func != nullptr) {
+        if (strncmp(func, "0x0", 3) == 0) {
+          return;
+        }
         filename = "<unknown>";
       } else {
         return;

Reply via email to