1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
Description: Revert^3 "Add rust demangling."
To avoid introduce new dependecy:
- https://android.googlesource.com/platform/external/rust/crates/rustc-demangle-capi
.
This reverts commit a8345a5764ceb0750729396ccfbaa763ae248f21.
Forwarded: not-needed
--- a/system/unwinding/libunwindstack/Android.bp
+++ b/system/unwinding/libunwindstack/Android.bp
@@ -54,7 +54,6 @@ cc_defaults {
libunwindstack_common_src_files = [
"AndroidUnwinder.cpp",
"ArmExidx.cpp",
- "Demangle.cpp",
"DexFiles.cpp",
"DwarfCfa.cpp",
"DwarfEhFrameWithHdr.cpp",
@@ -314,7 +313,6 @@ cc_defaults {
"tests/AndroidUnwinderTest.cpp",
"tests/ArmExidxDecodeTest.cpp",
"tests/ArmExidxExtractTest.cpp",
- "tests/DemangleTest.cpp",
"tests/DexFileTest.cpp",
"tests/DexFilesTest.cpp",
"tests/DwarfCfaLogTest.cpp",
--- a/system/unwinding/libunwindstack/AndroidUnwinder.cpp
+++ b/system/unwinding/libunwindstack/AndroidUnwinder.cpp
@@ -28,7 +28,6 @@
#include <unwindstack/AndroidUnwinder.h>
#include <unwindstack/Arch.h>
-#include <unwindstack/Demangle.h>
#include <unwindstack/DexFiles.h>
#include <unwindstack/Error.h>
#include <unwindstack/JitDebug.h>
@@ -46,11 +45,18 @@ static constexpr int kThreadUnwindSignal = BIONIC_SIGNAL_BACKTRACE;
static int kThreadUnwindSignal = SIGRTMIN;
#endif
+// Use the demangler from libc++.
+extern "C" char* __cxa_demangle(const char*, char*, size_t*, int* status);
+
namespace unwindstack {
void AndroidUnwinderData::DemangleFunctionNames() {
for (auto& frame : frames) {
- frame.function_name = DemangleNameIfNeeded(frame.function_name);
+ char* demangled_name = __cxa_demangle(frame.function_name.c_str(), nullptr, nullptr, nullptr);
+ if (demangled_name != nullptr) {
+ frame.function_name = demangled_name;
+ free(demangled_name);
+ }
}
}
--- a/system/unwinding/libunwindstack/Demangle.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed 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 <cxxabi.h>
-#include <stdlib.h>
-
-#include <string>
-
-#include <rustc_demangle.h>
-
-#include <unwindstack/Demangle.h>
-
-namespace unwindstack {
-
-std::string DemangleNameIfNeeded(const std::string& name) {
- if (name.length() < 2 || name[0] != '_') {
- return name;
- }
-
- char* demangled_str = nullptr;
- if (name[1] == 'Z') {
- // Try to demangle C++ name.
- demangled_str = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, nullptr);
- } else if (name[1] == 'R') {
- // Try to demangle rust name.
- demangled_str = rustc_demangle(name.c_str(), nullptr, nullptr, nullptr);
- }
-
- if (demangled_str == nullptr) {
- return name;
- }
-
- std::string demangled_name(demangled_str);
- free(demangled_str);
- return demangled_name;
-}
-
-} // namespace unwindstack
--- a/system/unwinding/libunwindstack/Unwinder.cpp
+++ b/system/unwinding/libunwindstack/Unwinder.cpp
@@ -25,12 +25,10 @@
#include <algorithm>
#include <memory>
-#include <string>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
-#include <unwindstack/Demangle.h>
#include <unwindstack/DexFiles.h>
#include <unwindstack/Elf.h>
#include <unwindstack/JitDebug.h>
@@ -41,6 +39,9 @@
#include "Check.h"
+// Use the demangler from libc++.
+extern "C" char* __cxa_demangle(const char*, char*, size_t*, int* status);
+
namespace unwindstack {
// Inject extra 'virtual' frame that represents the dex pc data.
@@ -325,7 +326,15 @@ std::string Unwinder::FormatFrame(ArchEnum arch, const FrameData& frame, bool di
}
if (!frame.function_name.empty()) {
- data += " (" + DemangleNameIfNeeded(frame.function_name);
+ char* demangled_name = __cxa_demangle(frame.function_name.c_str(), nullptr, nullptr, nullptr);
+ if (demangled_name == nullptr) {
+ data += " (";
+ data += frame.function_name;
+ } else {
+ data += " (";
+ data += demangled_name;
+ free(demangled_name);
+ }
if (frame.function_offset != 0) {
data += android::base::StringPrintf("+%" PRId64, frame.function_offset);
}
--- a/system/unwinding/libunwindstack/include/unwindstack/Demangle.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed 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.
- */
-
-#pragma once
-
-#include <string>
-
-namespace unwindstack {
-
-std::string DemangleNameIfNeeded(const std::string& name);
-
-} // namespace unwindstack
|