OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(HOST_OS_ANDROID) | 6 #if defined(HOST_OS_ANDROID) |
7 | 7 |
8 #include "vm/native_symbol.h" | 8 #include "vm/native_symbol.h" |
9 | 9 |
10 #include <cxxabi.h> // NOLINT | 10 #include <cxxabi.h> // NOLINT |
11 #include <dlfcn.h> // NOLINT | 11 #include <dlfcn.h> // NOLINT |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 void NativeSymbolResolver::InitOnce() {} | 15 void NativeSymbolResolver::InitOnce() {} |
16 | 16 |
17 | |
18 void NativeSymbolResolver::ShutdownOnce() {} | 17 void NativeSymbolResolver::ShutdownOnce() {} |
19 | 18 |
20 | |
21 char* NativeSymbolResolver::LookupSymbolName(uintptr_t pc, uintptr_t* start) { | 19 char* NativeSymbolResolver::LookupSymbolName(uintptr_t pc, uintptr_t* start) { |
22 Dl_info info; | 20 Dl_info info; |
23 int r = dladdr(reinterpret_cast<void*>(pc), &info); | 21 int r = dladdr(reinterpret_cast<void*>(pc), &info); |
24 if (r == 0) { | 22 if (r == 0) { |
25 return NULL; | 23 return NULL; |
26 } | 24 } |
27 if (info.dli_sname == NULL) { | 25 if (info.dli_sname == NULL) { |
28 return NULL; | 26 return NULL; |
29 } | 27 } |
30 if (start != NULL) { | 28 if (start != NULL) { |
31 *start = reinterpret_cast<uintptr_t>(info.dli_saddr); | 29 *start = reinterpret_cast<uintptr_t>(info.dli_saddr); |
32 } | 30 } |
33 int status = 0; | 31 int status = 0; |
34 size_t len = 0; | 32 size_t len = 0; |
35 char* demangled = abi::__cxa_demangle(info.dli_sname, NULL, &len, &status); | 33 char* demangled = abi::__cxa_demangle(info.dli_sname, NULL, &len, &status); |
36 MSAN_UNPOISON(demangled, len); | 34 MSAN_UNPOISON(demangled, len); |
37 if (status == 0) { | 35 if (status == 0) { |
38 return demangled; | 36 return demangled; |
39 } | 37 } |
40 return strdup(info.dli_sname); | 38 return strdup(info.dli_sname); |
41 } | 39 } |
42 | 40 |
43 | |
44 void NativeSymbolResolver::FreeSymbolName(char* name) { | 41 void NativeSymbolResolver::FreeSymbolName(char* name) { |
45 free(name); | 42 free(name); |
46 } | 43 } |
47 | 44 |
48 | |
49 bool NativeSymbolResolver::LookupSharedObject(uword pc, | 45 bool NativeSymbolResolver::LookupSharedObject(uword pc, |
50 uword* dso_base, | 46 uword* dso_base, |
51 char** dso_name) { | 47 char** dso_name) { |
52 Dl_info info; | 48 Dl_info info; |
53 int r = dladdr(reinterpret_cast<void*>(pc), &info); | 49 int r = dladdr(reinterpret_cast<void*>(pc), &info); |
54 if (r == 0) { | 50 if (r == 0) { |
55 return false; | 51 return false; |
56 } | 52 } |
57 *dso_base = reinterpret_cast<uword>(info.dli_fbase); | 53 *dso_base = reinterpret_cast<uword>(info.dli_fbase); |
58 *dso_name = strdup(info.dli_fname); | 54 *dso_name = strdup(info.dli_fname); |
59 return true; | 55 return true; |
60 } | 56 } |
61 | 57 |
62 } // namespace dart | 58 } // namespace dart |
63 | 59 |
64 #endif // defined(HOST_OS_ANDROID) | 60 #endif // defined(HOST_OS_ANDROID) |
OLD | NEW |