dart-sdk/runtime/vm/native_symbol_macos.cc
Ryan Macnak f9a6a5bdd2 [vm] Update NULL to nullptr in runtime/vm.
TEST=build
Change-Id: I2834ef7cf7cb7c8770f8167a2438cbedcee5c623
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292063
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-04-10 18:15:12 +00:00

71 lines
1.8 KiB
C++

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/globals.h"
#if defined(DART_HOST_OS_MACOS)
#include "vm/native_symbol.h"
#include "vm/os.h"
#include <cxxabi.h> // NOLINT
#include <dlfcn.h> // NOLINT
namespace dart {
void NativeSymbolResolver::Init() {}
void NativeSymbolResolver::Cleanup() {}
char* NativeSymbolResolver::LookupSymbolName(uword pc, uword* start) {
Dl_info info;
int r = dladdr(reinterpret_cast<void*>(pc), &info);
if (r == 0) {
return nullptr;
}
if (info.dli_sname == nullptr) {
return nullptr;
}
if (start != nullptr) {
*start = reinterpret_cast<uword>(info.dli_saddr);
}
int status;
char* demangled =
abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status);
if (status == 0) {
return demangled;
}
return strdup(info.dli_sname);
}
void NativeSymbolResolver::FreeSymbolName(char* name) {
free(name);
}
bool NativeSymbolResolver::LookupSharedObject(uword pc,
uword* dso_base,
char** dso_name) {
Dl_info info;
int r = dladdr(reinterpret_cast<void*>(pc), &info);
if (r == 0) {
return false;
}
if (dso_base != nullptr) {
*dso_base = reinterpret_cast<uword>(info.dli_fbase);
}
if (dso_name != nullptr) {
*dso_name = strdup(info.dli_fname);
}
return true;
}
void NativeSymbolResolver::AddSymbols(const char* dso_name,
void* buffer,
size_t size) {
OS::PrintErr("warning: Dart_AddSymbols has no effect on MacOS\n");
}
} // namespace dart
#endif // defined(DART_HOST_OS_MACOS)