mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:19:47 +00:00
[vm, fuchsia] Consume specialized symbols for the Dart VM's profiler.
Bug: FL-238 Change-Id: Ie5e2786aeb47063ea1c534b2169b2547d6693a96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/100200 Reviewed-by: Zach Anderson <zra@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
parent
91e9962699
commit
e7175ac2ed
|
@ -36,9 +36,6 @@ template("build_libdart_builtin") {
|
|||
"..:dart_arch_config",
|
||||
"..:dart_config",
|
||||
] + extra_configs
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
public_configs = [ ":libdart_builtin_config" ]
|
||||
deps = []
|
||||
if (is_fuchsia) {
|
||||
|
@ -90,9 +87,6 @@ static_library("crashpad") {
|
|||
"..:dart_product_config",
|
||||
"..:dart_os_fuchsia_config",
|
||||
]
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
include_dirs = [ ".." ]
|
||||
sources = [
|
||||
"crashpad.cc",
|
||||
|
@ -127,9 +121,6 @@ template("build_gen_snapshot") {
|
|||
"..:dart_config",
|
||||
"..:dart_precompiler_config",
|
||||
] + extra_configs
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
deps = [ ":generate_abi_version_cc_file" ] + extra_deps
|
||||
|
||||
defines = [ "EXCLUDE_CFE_AND_KERNEL_PLATFORM" ]
|
||||
|
@ -263,7 +254,6 @@ template("build_gen_snapshot_dart_io") {
|
|||
public_deps = [
|
||||
"//zircon/public/lib/fdio",
|
||||
]
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
|
||||
deps += [ "//third_party/zlib" ]
|
||||
|
@ -345,9 +335,6 @@ template("dart_io") {
|
|||
"..:dart_os_config",
|
||||
] + extra_configs
|
||||
public_configs = [ "..:dart_public_config" ]
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
custom_sources_filter = [
|
||||
"*_test.cc",
|
||||
"*_test.h",
|
||||
|
@ -698,9 +685,6 @@ template("dart_executable") {
|
|||
"..:dart_os_config",
|
||||
"..:dart_maybe_product_config",
|
||||
] + extra_configs
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
if (target_os != current_os && target_os == "fuchsia") {
|
||||
# We already have these in the standalone build, but Fuchsia doesn't
|
||||
# have them. They are needed for running Fuchsia binaries built for the
|
||||
|
@ -906,9 +890,6 @@ executable("run_vm_tests") {
|
|||
if (dart_target_arch != "ia32") {
|
||||
configs += [ "..:dart_precompiler_config" ]
|
||||
}
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
":crashpad",
|
||||
|
|
|
@ -156,9 +156,6 @@ template("library_for_all_configs") {
|
|||
"extra_deps",
|
||||
"configurable_deps",
|
||||
])
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
configs += conf.configs + extra_configs
|
||||
configured_deps = []
|
||||
foreach(dep, configurable_deps) {
|
||||
|
|
|
@ -975,6 +975,16 @@ DART_EXPORT void Dart_ThreadDisableProfiling();
|
|||
*/
|
||||
DART_EXPORT void Dart_ThreadEnableProfiling();
|
||||
|
||||
/**
|
||||
* Register symbol information for the Dart VM's profiler and crash dumps.
|
||||
*
|
||||
* This consumes the output of //topaz/runtime/dart/profiler_symbols, which
|
||||
* should be treated as opaque.
|
||||
*/
|
||||
DART_EXPORT void Dart_AddSymbols(const char* dso_name,
|
||||
void* buffer,
|
||||
intptr_t buffer_size);
|
||||
|
||||
/**
|
||||
* Exits an isolate. After this call, Dart_CurrentIsolate will
|
||||
* return NULL.
|
||||
|
|
|
@ -8,9 +8,6 @@ source_set("libdouble_conversion") {
|
|||
"../../..:dart_config",
|
||||
"../../..:dart_os_config",
|
||||
]
|
||||
if (is_fuchsia) {
|
||||
configs -= [ "//build/config:symbol_visibility_hidden" ]
|
||||
}
|
||||
sources = [
|
||||
"bignum-dtoa.cc",
|
||||
"bignum-dtoa.h",
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "vm/message.h"
|
||||
#include "vm/message_handler.h"
|
||||
#include "vm/native_entry.h"
|
||||
#include "vm/native_symbol.h"
|
||||
#include "vm/object.h"
|
||||
#include "vm/object_store.h"
|
||||
#include "vm/os.h"
|
||||
|
@ -1280,6 +1281,12 @@ DART_EXPORT void Dart_ThreadEnableProfiling() {
|
|||
os_thread->EnableThreadInterrupts();
|
||||
}
|
||||
|
||||
DART_EXPORT void Dart_AddSymbols(const char* dso_name,
|
||||
void* buffer,
|
||||
intptr_t buffer_size) {
|
||||
NativeSymbolResolver::AddSymbols(dso_name, buffer, buffer_size);
|
||||
}
|
||||
|
||||
DART_EXPORT bool Dart_WriteProfileToTimeline(Dart_Port main_port,
|
||||
char** error) {
|
||||
#if defined(PRODUCT)
|
||||
|
|
|
@ -19,6 +19,7 @@ class NativeSymbolResolver : public AllStatic {
|
|||
static char* LookupSymbolName(uintptr_t pc, uintptr_t* start);
|
||||
static bool LookupSharedObject(uword pc, uword* dso_base, char** dso_name);
|
||||
static void FreeSymbolName(char* name);
|
||||
static void AddSymbols(const char* dso_name, void* buffer, size_t size);
|
||||
};
|
||||
|
||||
} // namespace dart
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#if defined(HOST_OS_ANDROID)
|
||||
|
||||
#include "vm/native_symbol.h"
|
||||
#include "vm/os.h"
|
||||
|
||||
#include <cxxabi.h> // NOLINT
|
||||
#include <dlfcn.h> // NOLINT
|
||||
|
@ -55,6 +56,12 @@ bool NativeSymbolResolver::LookupSharedObject(uword pc,
|
|||
return true;
|
||||
}
|
||||
|
||||
void NativeSymbolResolver::AddSymbols(const char* dso_name,
|
||||
void* buffer,
|
||||
size_t size) {
|
||||
OS::PrintErr("warning: Dart_AddSymbols has no effect on Android\n");
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // defined(HOST_OS_ANDROID)
|
||||
|
|
|
@ -8,14 +8,97 @@
|
|||
#include "platform/memory_sanitizer.h"
|
||||
#include "vm/native_symbol.h"
|
||||
|
||||
#include <cxxabi.h> // NOLINT
|
||||
#include <dlfcn.h> // NOLINT
|
||||
|
||||
namespace dart {
|
||||
|
||||
// On Fuchsia, in lieu of the ELF dynamic symbol table consumed through dladdr,
|
||||
// we consumes symbols produced by //topaz/runtime/dart/profiler_symbols and
|
||||
// provided to the VM by the embedder through Dart_AddSymbols. They have the
|
||||
// format
|
||||
//
|
||||
// struct {
|
||||
// uint32_t num_entries;
|
||||
// struct {
|
||||
// uint32_t offset;
|
||||
// uint32_t size;
|
||||
// uint32_t string_table_offset;
|
||||
// } entries[num_entries];
|
||||
// const char* string_table;
|
||||
// }
|
||||
//
|
||||
// Entries are sorted by offset. String table entries are NUL-terminated.
|
||||
class NativeSymbols {
|
||||
public:
|
||||
NativeSymbols(const char* dso_name, void* buffer, size_t size)
|
||||
: next_(NULL), dso_name_(dso_name) {
|
||||
num_entries_ = *reinterpret_cast<uint32_t*>(buffer);
|
||||
entries_ =
|
||||
reinterpret_cast<Entry*>(reinterpret_cast<uint32_t*>(buffer) + 1);
|
||||
name_table_ = reinterpret_cast<const char*>(entries_ + num_entries_);
|
||||
}
|
||||
|
||||
NativeSymbols* next() const { return next_; }
|
||||
void set_next(NativeSymbols* symbols) { next_ = symbols; }
|
||||
|
||||
bool Lookup(const char* dso_name,
|
||||
uword dso_offset,
|
||||
uword* start_offset,
|
||||
const char** name) {
|
||||
if (strcmp(dso_name, dso_name_) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
intptr_t lo = 0;
|
||||
intptr_t hi = num_entries_ - 1;
|
||||
while (lo <= hi) {
|
||||
intptr_t mid = (hi - lo + 1) / 2 + lo;
|
||||
ASSERT(mid >= lo);
|
||||
ASSERT(mid <= hi);
|
||||
const Entry& entry = entries_[mid];
|
||||
if (dso_offset < entry.offset) {
|
||||
hi = mid - 1;
|
||||
} else if (dso_offset >= (entry.offset + entry.size)) {
|
||||
lo = mid + 1;
|
||||
} else {
|
||||
*start_offset = entry.offset;
|
||||
*name = &name_table_[entry.name_offset];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
uint32_t name_offset;
|
||||
};
|
||||
|
||||
NativeSymbols* next_;
|
||||
const char* const dso_name_;
|
||||
uint32_t num_entries_;
|
||||
Entry* entries_;
|
||||
const char* name_table_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeSymbols);
|
||||
};
|
||||
|
||||
static NativeSymbols* symbols_ = NULL;
|
||||
|
||||
void NativeSymbolResolver::Init() {}
|
||||
|
||||
void NativeSymbolResolver::Cleanup() {}
|
||||
void NativeSymbolResolver::Cleanup() {
|
||||
NativeSymbols* symbols = symbols_;
|
||||
symbols_ = NULL;
|
||||
while (symbols != NULL) {
|
||||
NativeSymbols* next = symbols->next();
|
||||
delete symbols;
|
||||
symbols = next;
|
||||
}
|
||||
}
|
||||
|
||||
char* NativeSymbolResolver::LookupSymbolName(uintptr_t pc, uintptr_t* start) {
|
||||
Dl_info info;
|
||||
|
@ -23,20 +106,25 @@ char* NativeSymbolResolver::LookupSymbolName(uintptr_t pc, uintptr_t* start) {
|
|||
if (r == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (info.dli_sname == NULL) {
|
||||
return NULL;
|
||||
|
||||
const char* dso_name = info.dli_fname;
|
||||
uword dso_base = reinterpret_cast<uword>(info.dli_fbase);
|
||||
uword dso_offset = pc - dso_base;
|
||||
|
||||
for (NativeSymbols* symbols = symbols_; symbols != NULL;
|
||||
symbols = symbols->next()) {
|
||||
uword symbol_start_offset;
|
||||
const char* symbol_name;
|
||||
if (symbols->Lookup(dso_name, dso_offset, &symbol_start_offset,
|
||||
&symbol_name)) {
|
||||
if (start != NULL) {
|
||||
*start = symbol_start_offset + dso_base;
|
||||
}
|
||||
return strdup(symbol_name);
|
||||
}
|
||||
}
|
||||
if (start != NULL) {
|
||||
*start = reinterpret_cast<uintptr_t>(info.dli_saddr);
|
||||
}
|
||||
int status = 0;
|
||||
size_t len = 0;
|
||||
char* demangled = abi::__cxa_demangle(info.dli_sname, NULL, &len, &status);
|
||||
MSAN_UNPOISON(demangled, len);
|
||||
if (status == 0) {
|
||||
return demangled;
|
||||
}
|
||||
return strdup(info.dli_sname);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void NativeSymbolResolver::FreeSymbolName(char* name) {
|
||||
|
@ -56,6 +144,13 @@ bool NativeSymbolResolver::LookupSharedObject(uword pc,
|
|||
return true;
|
||||
}
|
||||
|
||||
void NativeSymbolResolver::AddSymbols(const char* dso_name,
|
||||
void* buffer, size_t size) {
|
||||
NativeSymbols* symbols = new NativeSymbols(dso_name, buffer, size);
|
||||
symbols->set_next(symbols_);
|
||||
symbols_ = symbols;
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // defined(HOST_OS_FUCHSIA)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "platform/memory_sanitizer.h"
|
||||
#include "vm/native_symbol.h"
|
||||
#include "vm/os.h"
|
||||
|
||||
#include <cxxabi.h> // NOLINT
|
||||
#include <dlfcn.h> // NOLINT
|
||||
|
@ -56,6 +57,12 @@ bool NativeSymbolResolver::LookupSharedObject(uword pc,
|
|||
return true;
|
||||
}
|
||||
|
||||
void NativeSymbolResolver::AddSymbols(const char* dso_name,
|
||||
void* buffer,
|
||||
size_t size) {
|
||||
OS::PrintErr("warning: Dart_AddSymbols has no effect on Linux\n");
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // defined(HOST_OS_LINUX)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#if defined(HOST_OS_MACOS)
|
||||
|
||||
#include "vm/native_symbol.h"
|
||||
#include "vm/os.h"
|
||||
|
||||
#include <cxxabi.h> // NOLINT
|
||||
#include <dlfcn.h> // NOLINT
|
||||
|
@ -53,6 +54,12 @@ bool NativeSymbolResolver::LookupSharedObject(uword pc,
|
|||
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(HOST_OS_MACOS)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "vm/lockers.h"
|
||||
#include "vm/native_symbol.h"
|
||||
#include "vm/os.h"
|
||||
#include "vm/os_thread.h"
|
||||
|
||||
#include <dbghelp.h> // NOLINT
|
||||
|
@ -83,6 +84,12 @@ bool NativeSymbolResolver::LookupSharedObject(uword pc,
|
|||
return false;
|
||||
}
|
||||
|
||||
void NativeSymbolResolver::AddSymbols(const char* dso_name,
|
||||
void* buffer,
|
||||
size_t size) {
|
||||
OS::PrintErr("warning: Dart_AddSymbols has no effect on Windows\n");
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // defined(HOST_OS_WINDOWS)
|
||||
|
|
Loading…
Reference in a new issue