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 |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "vm/globals.h" |
6 | #if defined(HOST_OS_MACOS) |
7 | |
8 | #include "vm/native_symbol.h" |
9 | #include "vm/os.h" |
10 | |
11 | #include <cxxabi.h> // NOLINT |
12 | #include <dlfcn.h> // NOLINT |
13 | |
14 | namespace dart { |
15 | |
16 | void NativeSymbolResolver::Init() {} |
17 | |
18 | void NativeSymbolResolver::Cleanup() {} |
19 | |
20 | char* NativeSymbolResolver::LookupSymbolName(uword pc, uword* start) { |
21 | Dl_info info; |
22 | int r = dladdr(reinterpret_cast<void*>(pc), &info); |
23 | if (r == 0) { |
24 | return NULL; |
25 | } |
26 | if (info.dli_sname == NULL) { |
27 | return NULL; |
28 | } |
29 | if (start != NULL) { |
30 | *start = reinterpret_cast<uword>(info.dli_saddr); |
31 | } |
32 | int status; |
33 | char* demangled = abi::__cxa_demangle(info.dli_sname, NULL, NULL, &status); |
34 | if (status == 0) { |
35 | return demangled; |
36 | } |
37 | return strdup(info.dli_sname); |
38 | } |
39 | |
40 | void NativeSymbolResolver::FreeSymbolName(char* name) { |
41 | free(name); |
42 | } |
43 | |
44 | bool NativeSymbolResolver::LookupSharedObject(uword pc, |
45 | uword* dso_base, |
46 | char** dso_name) { |
47 | Dl_info info; |
48 | int r = dladdr(reinterpret_cast<void*>(pc), &info); |
49 | if (r == 0) { |
50 | return false; |
51 | } |
52 | if (dso_base != nullptr) { |
53 | *dso_base = reinterpret_cast<uword>(info.dli_fbase); |
54 | } |
55 | if (dso_name != nullptr) { |
56 | *dso_name = strdup(info.dli_fname); |
57 | } |
58 | return true; |
59 | } |
60 | |
61 | void NativeSymbolResolver::AddSymbols(const char* dso_name, |
62 | void* buffer, |
63 | size_t size) { |
64 | OS::PrintErr("warning: Dart_AddSymbols has no effect on MacOS\n" ); |
65 | } |
66 | |
67 | } // namespace dart |
68 | |
69 | #endif // defined(HOST_OS_MACOS) |
70 | |