tqchen commented on a change in pull request #7153:
URL: https://github.com/apache/tvm/pull/7153#discussion_r552998444



##########
File path: src/support/logging.cc
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <backtrace.h>
+#include <cxxabi.h>
+#include <tvm/support/logging.h>
+
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <vector>
+
+struct frame {};
+
+struct backtrace_info {
+  std::vector<std::string> lines;
+  size_t max_size;
+  std::string error_message;
+};
+
+static backtrace_state* _backtrace_state = nullptr;
+
+std::string demangle_name(const char* name) {
+  int status = 0;
+  size_t length = std::string::npos;
+  std::unique_ptr<char, void (*)(void* __ptr)> demangled_name = {
+      abi::__cxa_demangle(name, 0, &length, &status), &std::free};
+  if (demangled_name && status == 0 && length > 0) {
+    return demangled_name.get();
+  } else {
+    return name;
+  }
+}
+
+void tvm_backtrace_error(void* data, const char* msg, int errnum) {
+  auto stack_trace = reinterpret_cast<backtrace_info*>(data);
+  stack_trace->error_message = msg;
+}
+
+void tvm_backtrace_syminfo_callback(void* data, uintptr_t pc, const char* 
symname, uintptr_t symval,
+                                    uintptr_t symsize) {
+  auto str = reinterpret_cast<std::string*>(data);
+
+  if (symname != nullptr) {
+    *str = demangle_name(symname);
+  } else {
+    std::ostringstream s;
+    s << "0x" << std::setfill('0') << std::setw(sizeof(uintptr_t) * 2) << 
std::hex << pc;
+    *str = s.str();
+  }
+}
+int tvm_backtrace_full_callback(void* data, uintptr_t pc, const char* 
filename, int lineno,

Review comment:
       A generic comment, use CamelCase as per Google C style. It is OK to wrap 
it in namespace if there is no strict need of a C ABI symbol 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to