Coverage Report

Created: 2025-07-23 06:46

/src/perfetto/buildtools/android-unwinding/libunwindstack/Demangle.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2023 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include <cxxabi.h>
18
#include <stdlib.h>
19
20
#include <string>
21
22
#include <rustc_demangle.h>
23
24
#include <unwindstack/Demangle.h>
25
26
namespace unwindstack {
27
28
0
std::string DemangleNameIfNeeded(const std::string& name) {
29
0
  if (name.length() < 2 || name[0] != '_') {
30
0
    return name;
31
0
  }
32
33
0
  char* demangled_str = nullptr;
34
0
  if (name[1] == 'Z') {
35
    // Try to demangle C++ name.
36
0
    demangled_str = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, nullptr);
37
0
  } else if (name[1] == 'R') {
38
    // Try to demangle rust name.
39
0
    demangled_str = rustc_demangle(name.c_str(), nullptr, nullptr, nullptr);
40
0
  }
41
42
0
  if (demangled_str == nullptr) {
43
0
    return name;
44
0
  }
45
46
0
  std::string demangled_name(demangled_str);
47
0
  free(demangled_str);
48
0
  return demangled_name;
49
0
}
50
51
}  // namespace unwindstack