1 /*
2 * Copyright (C) 2018 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 "dso.h"
18
19 #include <gtest/gtest.h>
20
21 #include <android-base/file.h>
22 #include <android-base/stringprintf.h>
23 #include <android-base/test_utils.h>
24
25 #include "get_test_data.h"
26 #include "read_apk.h"
27 #include "thread_tree.h"
28 #include "utils.h"
29
30 using namespace simpleperf;
31 using namespace simpleperf_dso_impl;
32
33 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,use_build_id_list)34 TEST(DebugElfFileFinder, use_build_id_list) {
35 // Create a temp symdir with build_id_list.
36 TemporaryDir tmpdir;
37 TemporaryFile tmpfile(tmpdir.path);
38 std::string data;
39 ASSERT_TRUE(android::base::ReadFileToString(GetTestData(ELF_FILE), &data));
40 ASSERT_TRUE(android::base::WriteStringToFile(data, tmpfile.path));
41 BuildId build_id(ELF_FILE_BUILD_ID);
42 std::string build_id_list = android::base::StringPrintf(
43 "%s=%s\n", build_id.ToString().c_str(), android::base::Basename(tmpfile.path).c_str());
44 std::string build_id_list_file = std::string(tmpdir.path) + "/build_id_list";
45 ASSERT_TRUE(android::base::WriteStringToFile(build_id_list, build_id_list_file));
46
47 DebugElfFileFinder finder;
48 ASSERT_TRUE(finder.SetSymFsDir(tmpdir.path));
49 ASSERT_EQ(finder.FindDebugFile("elf", false, build_id), std::string(tmpfile.path));
50 unlink(build_id_list_file.c_str());
51 }
52
ConvertPathSeparator(const std::string & path)53 static std::string ConvertPathSeparator(const std::string& path) {
54 std::string result = path;
55 if (OS_PATH_SEPARATOR != '/') {
56 std::replace(result.begin(), result.end(), '/', OS_PATH_SEPARATOR);
57 }
58 return result;
59 }
60
61 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,concatenating_symfs_dir)62 TEST(DebugElfFileFinder, concatenating_symfs_dir) {
63 DebugElfFileFinder finder;
64 ASSERT_TRUE(finder.SetSymFsDir(GetTestDataDir()));
65 ASSERT_EQ(finder.GetPathInSymFsDir("/system/libc.so"),
66 GetTestDataDir() + "system" + OS_PATH_SEPARATOR + "libc.so");
67 ASSERT_EQ(finder.GetPathInSymFsDir("/data/base.apk!/lib/base.so"),
68 GetTestDataDir() + "data" + OS_PATH_SEPARATOR + "base.apk!/lib/base.so");
69
70 BuildId build_id(ELF_FILE_BUILD_ID);
71 ASSERT_EQ(finder.FindDebugFile(ELF_FILE, false, build_id), GetTestDataDir() + ELF_FILE);
72 std::string native_lib_in_apk = APK_FILE + "!/" + NATIVELIB_IN_APK;
73 std::string apk_path = ConvertPathSeparator(APK_FILE);
74 ASSERT_EQ(finder.FindDebugFile(native_lib_in_apk, false, native_lib_build_id),
75 GetTestDataDir() + apk_path + "!/" + NATIVELIB_IN_APK);
76 }
77
78 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,use_vdso)79 TEST(DebugElfFileFinder, use_vdso) {
80 DebugElfFileFinder finder;
81 std::string fake_vdso32 = "fake_vdso32";
82 std::string fake_vdso64 = "fake_vdso64";
83 finder.SetVdsoFile(fake_vdso32, false);
84 finder.SetVdsoFile(fake_vdso64, true);
85 BuildId build_id;
86 ASSERT_EQ(finder.FindDebugFile("[vdso]", false, build_id), fake_vdso32);
87 ASSERT_EQ(finder.FindDebugFile("[vdso]", true, build_id), fake_vdso64);
88 }
89
90 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,add_symbol_dir)91 TEST(DebugElfFileFinder, add_symbol_dir) {
92 DebugElfFileFinder finder;
93 ASSERT_FALSE(finder.AddSymbolDir(GetTestDataDir() + "dir_not_exist"));
94 ASSERT_EQ(finder.FindDebugFile("elf", false, CHECK_ELF_FILE_BUILD_ID), "elf");
95 std::string symfs_dir = ConvertPathSeparator(GetTestDataDir() + CORRECT_SYMFS_FOR_BUILD_ID_CHECK);
96 ASSERT_TRUE(finder.AddSymbolDir(symfs_dir));
97 ASSERT_EQ(finder.FindDebugFile("elf", false, CHECK_ELF_FILE_BUILD_ID),
98 symfs_dir + OS_PATH_SEPARATOR + "elf_for_build_id_check");
99 }
100
101 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,allow_mismatched_build_id)102 TEST(DebugElfFileFinder, allow_mismatched_build_id) {
103 DebugElfFileFinder finder;
104 std::string symfs_dir = ConvertPathSeparator(GetTestDataDir() + CORRECT_SYMFS_FOR_BUILD_ID_CHECK);
105 ASSERT_TRUE(finder.AddSymbolDir(symfs_dir));
106 // By default, can't find binary with empty or different build ids.
107 BuildId empty_build_id;
108 ASSERT_EQ(finder.FindDebugFile("/data/elf_for_build_id_check", false, empty_build_id),
109 "/data/elf_for_build_id_check");
110 BuildId different_build_id("01234");
111 ASSERT_EQ(finder.FindDebugFile("/data/elf_for_build_id_check", false, different_build_id),
112 "/data/elf_for_build_id_check");
113
114 // With AllowMismatchedBuildId(), can find binary with empty and different build ids.
115 finder.AllowMismatchedBuildId();
116 empty_build_id = BuildId();
117 ASSERT_EQ(finder.FindDebugFile("/data/elf_for_build_id_check", false, empty_build_id),
118 symfs_dir + OS_PATH_SEPARATOR + "elf_for_build_id_check");
119 different_build_id = BuildId("01234");
120 ASSERT_EQ(finder.FindDebugFile("/data/elf_for_build_id_check", false, different_build_id),
121 symfs_dir + OS_PATH_SEPARATOR + "elf_for_build_id_check");
122 }
123
124 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,build_id_list)125 TEST(DebugElfFileFinder, build_id_list) {
126 DebugElfFileFinder finder;
127 // Find file in symfs dir with correct build_id_list.
128 std::string symfs_dir = ConvertPathSeparator(GetTestDataDir() + "data/symfs_with_build_id_list");
129 ASSERT_TRUE(finder.SetSymFsDir(symfs_dir));
130 ASSERT_EQ(finder.FindDebugFile("elf", false, CHECK_ELF_FILE_BUILD_ID),
131 symfs_dir + OS_PATH_SEPARATOR + "elf_for_build_id_check");
132
133 // Find file in symfs_dir with wrong build_id_list.
134 symfs_dir = ConvertPathSeparator(GetTestDataDir() + "data/symfs_with_wrong_build_id_list");
135 finder.Reset();
136 ASSERT_TRUE(finder.SetSymFsDir(symfs_dir));
137 ASSERT_EQ(finder.FindDebugFile("elf", false, CHECK_ELF_FILE_BUILD_ID), "elf");
138 }
139
140 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,no_build_id)141 TEST(DebugElfFileFinder, no_build_id) {
142 DebugElfFileFinder finder;
143 // If not given a build id, we should match an elf in symfs without build id.
144 std::string symfs_dir = ConvertPathSeparator(GetTestDataDir() + "data/symfs_without_build_id");
145 ASSERT_TRUE(finder.SetSymFsDir(symfs_dir));
146 BuildId build_id;
147 ASSERT_EQ(finder.FindDebugFile("elf", false, build_id), symfs_dir + OS_PATH_SEPARATOR + "elf");
148 }
149
150 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,find_basename_in_symfs_dir)151 TEST(DebugElfFileFinder, find_basename_in_symfs_dir) {
152 DebugElfFileFinder finder;
153 // Find normal elf file.
154 finder.SetSymFsDir(GetTestDataDir());
155 BuildId build_id(ELF_FILE_BUILD_ID);
156 ASSERT_EQ(finder.FindDebugFile("random_dir/elf", false, build_id), GetTestData("elf"));
157
158 // Find embedded native library.
159 ASSERT_EQ(finder.FindDebugFile("base.apk!/lib/x86_64/elf", false, build_id), GetTestData("elf"));
160
161 // Find elf file without build id.
162 std::string symfs_dir = ConvertPathSeparator(GetTestDataDir() + "data/symfs_without_build_id");
163 finder.SetSymFsDir(symfs_dir);
164 build_id = BuildId();
165 ASSERT_EQ(finder.FindDebugFile("random_dir/elf", false, build_id),
166 symfs_dir + OS_PATH_SEPARATOR + "elf");
167 }
168
169 // @CddTest = 6.1/C-0-2
TEST(DebugElfFileFinder,build_id_mismatch)170 TEST(DebugElfFileFinder, build_id_mismatch) {
171 DebugElfFileFinder finder;
172 finder.SetSymFsDir(GetTestDataDir());
173 CapturedStderr capture;
174 BuildId mismatch_build_id("0c12a384a9f4a3f3659b7171ca615dbec3a81f71");
175 std::string debug_file = finder.FindDebugFile(ELF_FILE, false, mismatch_build_id);
176 capture.Stop();
177 std::string stderr_output = capture.str();
178 ASSERT_EQ(debug_file, ELF_FILE);
179 ASSERT_NE(stderr_output.find("build id mismatch"), std::string::npos);
180 }
181
182 // @CddTest = 6.1/C-0-2
TEST(dso,dex_file_dso)183 TEST(dso, dex_file_dso) {
184 #if defined(__linux__)
185 for (DsoType dso_type : {DSO_DEX_FILE, DSO_ELF_FILE}) {
186 std::unique_ptr<Dso> dso = Dso::CreateDso(dso_type, GetTestData("base.vdex"));
187 ASSERT_TRUE(dso);
188 dso->AddDexFileOffset(0x28);
189 ASSERT_EQ(DSO_DEX_FILE, dso->type());
190 const Symbol* symbol = dso->FindSymbol(0x6c77e);
191 ASSERT_NE(symbol, nullptr);
192 ASSERT_EQ(symbol->addr, static_cast<uint64_t>(0x6c77e));
193 ASSERT_EQ(symbol->len, static_cast<uint64_t>(0x16));
194 ASSERT_STREQ(symbol->DemangledName(),
195 "com.example.simpleperf.simpleperfexamplewithnative.MixActivity$1.run");
196 uint64_t min_vaddr;
197 uint64_t file_offset_of_min_vaddr;
198 dso->GetMinExecutableVaddr(&min_vaddr, &file_offset_of_min_vaddr);
199 ASSERT_EQ(min_vaddr, 0);
200 ASSERT_EQ(file_offset_of_min_vaddr, 0);
201
202 // Don't crash on not exist zip entry.
203 dso = Dso::CreateDso(dso_type, GetTestData("base.zip!/not_exist_entry"));
204 ASSERT_TRUE(dso);
205 ASSERT_EQ(nullptr, dso->FindSymbol(0));
206 }
207 #else
208 GTEST_LOG_(INFO) << "This test only runs on linux because of libdexfile";
209 #endif // defined(__linux__)
210 }
211
212 // @CddTest = 6.1/C-0-2
TEST(dso,dex_file_offsets)213 TEST(dso, dex_file_offsets) {
214 std::unique_ptr<Dso> dso = Dso::CreateDso(DSO_DEX_FILE, "");
215 ASSERT_TRUE(dso);
216 for (uint64_t offset : {0x3, 0x1, 0x5, 0x4, 0x2, 0x4, 0x3}) {
217 dso->AddDexFileOffset(offset);
218 }
219 ASSERT_EQ(*dso->DexFileOffsets(), std::vector<uint64_t>({0x1, 0x2, 0x3, 0x4, 0x5}));
220 }
221
222 // @CddTest = 6.1/C-0-2
TEST(dso,embedded_elf)223 TEST(dso, embedded_elf) {
224 const std::string file_path = GetUrlInApk(GetTestData(APK_FILE), NATIVELIB_IN_APK);
225 std::unique_ptr<Dso> dso = Dso::CreateDso(DSO_ELF_FILE, file_path);
226 ASSERT_TRUE(dso);
227 ASSERT_EQ(dso->Path(), file_path);
228 ASSERT_EQ(dso->GetDebugFilePath(), file_path);
229 uint64_t min_vaddr;
230 uint64_t file_offset_of_min_vaddr;
231 dso->GetMinExecutableVaddr(&min_vaddr, &file_offset_of_min_vaddr);
232 ASSERT_EQ(min_vaddr, 0);
233 ASSERT_EQ(file_offset_of_min_vaddr, 0);
234 const Symbol* symbol = dso->FindSymbol(0x9a4);
235 ASSERT_TRUE(symbol != nullptr);
236 ASSERT_STREQ(symbol->Name(), "Java_com_example_hellojni_HelloJni_callFunc1");
237 BuildId build_id;
238 ASSERT_TRUE(GetBuildIdFromDsoPath(file_path, &build_id));
239 ASSERT_EQ(build_id, native_lib_build_id);
240 }
241
242 // @CddTest = 6.1/C-0-2
TEST(dso,IpToVaddrInFile)243 TEST(dso, IpToVaddrInFile) {
244 std::unique_ptr<Dso> dso = Dso::CreateDso(DSO_ELF_FILE, GetTestData("libc.so"));
245 ASSERT_TRUE(dso);
246 ASSERT_EQ(0xa5140, dso->IpToVaddrInFile(0xe9201140, 0xe9201000, 0xa5000));
247 }
248
249 // @CddTest = 6.1/C-0-2
TEST(dso,kernel_address_randomization)250 TEST(dso, kernel_address_randomization) {
251 // Use ELF_FILE as a fake kernel vmlinux.
252 const std::string vmlinux_path = GetTestData(ELF_FILE);
253 Dso::SetVmlinux(vmlinux_path);
254 std::unique_ptr<Dso> dso = Dso::CreateDso(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME);
255 ASSERT_TRUE(dso);
256 ASSERT_EQ(dso->GetDebugFilePath(), vmlinux_path);
257 // When map_start = 0, can't fix kernel address randomization. So vmlinux isn't used.
258 ASSERT_EQ(dso->IpToVaddrInFile(0x800500, 0, 0), 0x800500);
259 ASSERT_FALSE(dso->IpToFileOffset(0x800500, 0, 0));
260 ASSERT_TRUE(dso->FindSymbol(0x400510) == nullptr);
261
262 dso = Dso::CreateDso(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME);
263 ASSERT_TRUE(dso);
264 ASSERT_EQ(dso->GetDebugFilePath(), vmlinux_path);
265 // When map_start != 0, can fix kernel address randomization. So vmlinux is used.
266 ASSERT_EQ(dso->IpToVaddrInFile(0x800500, 0x800400, 0), 0x400500);
267 ASSERT_EQ(dso->IpToFileOffset(0x800500, 0x800400, 0).value(), 0x500);
268 const Symbol* symbol = dso->FindSymbol(0x400510);
269 ASSERT_TRUE(symbol != nullptr);
270 ASSERT_STREQ(symbol->Name(), "GlobalFunc");
271 }
272
273 // @CddTest = 6.1/C-0-2
TEST(dso,find_vmlinux_in_symdirs)274 TEST(dso, find_vmlinux_in_symdirs) {
275 // Create a symdir.
276 TemporaryDir tmpdir;
277 std::string vmlinux_path = std::string(tmpdir.path) + OS_PATH_SEPARATOR + "elf";
278 std::string data;
279 ASSERT_TRUE(android::base::ReadFileToString(GetTestData(ELF_FILE), &data));
280 ASSERT_TRUE(android::base::WriteStringToFile(data, vmlinux_path));
281
282 // Find vmlinux in symbol dirs.
283 Dso::SetVmlinux("");
284 Dso::AddSymbolDir(tmpdir.path);
285 Dso::SetBuildIds({std::make_pair(DEFAULT_KERNEL_MMAP_NAME, BuildId(ELF_FILE_BUILD_ID))});
286 std::unique_ptr<Dso> dso = Dso::CreateDso(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME);
287 ASSERT_TRUE(dso);
288 ASSERT_EQ(dso->GetDebugFilePath(), vmlinux_path);
289 ASSERT_EQ(0x400927, dso->IpToVaddrInFile(0x800527, 0x800000, 0));
290
291 // Find vmlinux by CreateDsoWithBuildId.
292 Dso::SetBuildIds({});
293 BuildId build_id(ELF_FILE_BUILD_ID);
294 dso = Dso::CreateDsoWithBuildId(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME, build_id);
295 ASSERT_TRUE(dso);
296 ASSERT_EQ(dso->GetDebugFilePath(), vmlinux_path);
297 ASSERT_EQ(0x400927, dso->IpToVaddrInFile(0x800527, 0x800000, 0));
298 }
299
300 // @CddTest = 6.1/C-0-2
TEST(dso,kernel_module)301 TEST(dso, kernel_module) {
302 // Test finding debug files for kernel modules.
303 Dso::SetSymFsDir(GetTestDataDir());
304 std::vector<std::pair<std::string, BuildId>> build_ids;
305 build_ids.emplace_back(ELF_FILE, BuildId(ELF_FILE_BUILD_ID));
306 Dso::SetBuildIds(build_ids);
307 std::unique_ptr<Dso> kernel_dso = Dso::CreateDso(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME);
308 ASSERT_TRUE(kernel_dso);
309 std::unique_ptr<Dso> dso = Dso::CreateKernelModuleDso(ELF_FILE, 0, 0, kernel_dso.get());
310 ASSERT_EQ(dso->GetDebugFilePath(), GetTestData(ELF_FILE));
311 }
312
313 // @CddTest = 6.1/C-0-2
TEST(dso,kernel_module_CalculateMinVaddr)314 TEST(dso, kernel_module_CalculateMinVaddr) {
315 // Create fake Dso objects.
316 auto kernel_dso = Dso::CreateDso(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME);
317 ASSERT_TRUE(kernel_dso);
318 const uint64_t module_memory_start = 0xffffffa9bc790000ULL;
319 const uint64_t module_memory_size = 0x8d7000ULL;
320 TemporaryFile tmpfile;
321 auto module_dso =
322 Dso::CreateKernelModuleDso(tmpfile.path, module_memory_start,
323 module_memory_start + module_memory_size, kernel_dso.get());
324 ASSERT_TRUE(module_dso);
325
326 // Provide symbol info for calculating min vaddr.
327 std::vector<Symbol> kernel_symbols;
328 kernel_symbols.emplace_back("fake_module_function [fake_module]", 0xffffffa9bc7a64e8ULL, 0x60c);
329 kernel_dso->SetSymbols(&kernel_symbols);
330 std::vector<Symbol> module_symbols;
331 module_symbols.emplace_back("fake_module_function", 0x144e8, 0x60c);
332 module_dso->SetSymbols(&module_symbols);
333
334 // Calculate min vaddr.
335 uint64_t min_vaddr;
336 uint64_t memory_offset;
337 module_dso->GetMinExecutableVaddr(&min_vaddr, &memory_offset);
338 ASSERT_EQ(min_vaddr, 0x144e8);
339 ASSERT_EQ(memory_offset, 0x164e8);
340
341 // Use min vaddr in IpToVaddrInFile().
342 ASSERT_EQ(module_dso->IpToVaddrInFile(0xffffffa9bc7a64e8ULL, module_memory_start, 0), 0x144e8);
343 }
344
345 // @CddTest = 6.1/C-0-2
TEST(dso,symbol_map_file)346 TEST(dso, symbol_map_file) {
347 auto dso = Dso::CreateDso(DSO_SYMBOL_MAP_FILE, "perf-123.map");
348 ASSERT_TRUE(dso);
349 ASSERT_EQ(DSO_SYMBOL_MAP_FILE, dso->type());
350 ASSERT_EQ(0x12345678, dso->IpToVaddrInFile(0x12345678, 0x0, 0x0));
351 ASSERT_EQ(0x12345678, dso->IpToVaddrInFile(0x12345678, 0xe9201000, 0xa5000));
352 }
353
354 // @CddTest = 6.1/C-0-2
TEST(dso,FunctionName)355 TEST(dso, FunctionName) {
356 Symbol symbol = Symbol("void ctep.v(cteo, ctgc, ctbn)", 0x0, 0x1);
357 ASSERT_EQ(symbol.FunctionName(), "ctep.v");
358 symbol = Symbol("ctep.v(cteo, ctgc, ctbn)", 0x0, 0x1);
359 ASSERT_EQ(symbol.FunctionName(), "ctep.v");
360 symbol = Symbol("ctep.v", 0x0, 0x1);
361 ASSERT_EQ(symbol.FunctionName(), "ctep.v");
362 }
363
364 // @CddTest = 6.1/C-0-2
TEST(dso,search_debug_file_only_when_needed)365 TEST(dso, search_debug_file_only_when_needed) {
366 Dso::SetBuildIds({std::make_pair("/elf", BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))});
367 Dso::SetSymFsDir(GetTestDataDir());
368 CapturedStderr capture;
369 auto dso = Dso::CreateDso(DSO_ELF_FILE, "/elf");
370 ASSERT_EQ(capture.str().find("build id mismatch"), std::string::npos);
371 ASSERT_EQ(dso->GetDebugFilePath(), "/elf");
372 ASSERT_NE(capture.str().find("build id mismatch"), std::string::npos);
373 capture.Stop();
374 }
375
376 // @CddTest = 6.1/C-0-2
TEST(dso,read_symbol_warning)377 TEST(dso, read_symbol_warning) {
378 {
379 // Don't warn when the file may not be an ELF file.
380 auto dso = Dso::CreateDso(DSO_ELF_FILE, GetTestData("not_exist_file"));
381 CapturedStderr capture;
382 dso->LoadSymbols();
383 ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos);
384 }
385 {
386 // Don't warn when the file may not be an ELF file.
387 auto dso = Dso::CreateDso(DSO_ELF_FILE, GetTestData("base.vdex"));
388 CapturedStderr capture;
389 dso->LoadSymbols();
390 ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos);
391 }
392 {
393 // Warn when the file is an ELF file (having a build id).
394 std::string file_path = GetTestData("not_exist_file");
395 Dso::SetBuildIds(
396 {std::make_pair(file_path, BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))});
397 auto dso = Dso::CreateDso(DSO_ELF_FILE, file_path);
398 CapturedStderr capture;
399 dso->LoadSymbols();
400 ASSERT_NE(capture.str().find("failed to read symbols"), std::string::npos);
401 }
402 {
403 // Don't warn when we already have symbols.
404 std::string file_path = GetTestData("not_exist_file");
405 Dso::SetBuildIds(
406 {std::make_pair(file_path, BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))});
407 auto dso = Dso::CreateDso(DSO_ELF_FILE, file_path);
408 std::vector<Symbol> symbols;
409 symbols.emplace_back("fake_symbol", 0x1234, 0x60);
410 dso->SetSymbols(&symbols);
411 CapturedStderr capture;
412 dso->LoadSymbols();
413 ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos);
414 }
415 }
416
417 // @CddTest = 6.1/C-0-2
TEST(dso,demangle)418 TEST(dso, demangle) {
419 ASSERT_EQ(Dso::Demangle("main"), "main");
420 ASSERT_EQ(Dso::Demangle("_ZN4main4main17h2a68d4d833d7495aE"), "main::main::h2a68d4d833d7495a");
421 #if defined(__linux__) || defined(__darwin__)
422 // Demangling rust symbol is only supported on linux and darwin.
423 ASSERT_EQ(Dso::Demangle("_RNvC6_123foo3bar"), "123foo::bar");
424 #endif
425 }
426