[Pytorch] Fix callstack pointer serialization bug (#63576)
authorKimish Patel <kimishpatel@fb.com>
Thu, 19 Aug 2021 20:32:26 +0000 (13:32 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 19 Aug 2021 20:35:52 +0000 (13:35 -0700)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63576

We serialize function name associated with InlinedCallStackPtr. This is derived
via querying Function* stored in InlinedCallStack. However this is a raw
pointer that is not gauranteed to be valid when we serialization happens. On
the other hand we also store function name separately when constructing
InlinedCallStack anyways. So this change just uniformly relies on function_name
instead of Function*

Test Plan: Internal build's asan failure + CI

Reviewed By: larryliu0820

Differential Revision: D30427029

fbshipit-source-id: de9617482404785920ed2e67b72f38461590fba3

torch/csrc/jit/mobile/debug_info.cpp
torch/csrc/jit/serialization/callstack_debug_info_serialization.cpp

index 9c734f4..41ce3c6 100644 (file)
@@ -49,11 +49,7 @@ std::pair<std::vector<StackEntry>, std::string> getStackTraceWithModuleHierarchy
       // Now add source range info to stack
       entries.emplace_back(
           StackEntry{prev_function_name, callstack_ptr->source_range()});
-      if (callstack_ptr->function()) {
-        prev_function_name = callstack_ptr->function()->name();
-      } else {
-        prev_function_name = callstack_ptr->function_name();
-      }
+      prev_function_name = callstack_ptr->function_name();
       // Function name appended here
       // It is renamed to prev_function_name because for StackEntry
       // it will be appended in the next iteration. This is the format
index c26c7e5..93da38a 100644 (file)
@@ -47,15 +47,11 @@ c10::IValue InlinedCallStackSerializer::serialize(
   } else {
     elements.emplace_back(c10::IValue());
   }
-  if (cs_ptr->function()) {
-    elements.emplace_back(cs_ptr->function()->name());
+  auto fn_name = cs_ptr->function_name();
+  if (!fn_name.empty()) {
+    elements.emplace_back(fn_name);
   } else {
-    auto fn_name = cs_ptr->function_name();
-    if (!fn_name.empty()) {
-      elements.emplace_back(fn_name);
-    } else {
-      elements.emplace_back("FunctionName_UNKNOWN");
-    }
+    elements.emplace_back("FunctionName_UNKNOWN");
   }
   c10::IValue serialized_cs = c10::ivalue::Tuple::create(elements);
   serialized_inlined_callstack_[cs_ptr] = serialized_cs;