diff --git a/src/external-reference-table.cc b/src/external-reference-table.cc index 3c32231eb4..276d0ea91e 100644 --- a/src/external-reference-table.cc +++ b/src/external-reference-table.cc @@ -15,6 +15,7 @@ #if defined(DEBUG) && defined(V8_OS_LINUX) && !defined(V8_OS_ANDROID) #define SYMBOLIZE_FUNCTION #include +#include #endif // DEBUG && V8_OS_LINUX && !V8_OS_ANDROID namespace v8 { @@ -49,6 +50,14 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) { AddApiReferences(isolate); } +ExternalReferenceTable::~ExternalReferenceTable() { +#ifdef SYMBOLIZE_FUNCTION + for (char** table : symbol_tables_) { + free(table); + } +#endif +} + #ifdef DEBUG void ExternalReferenceTable::ResetCount() { for (ExternalReferenceEntry& entry : refs_) entry.count = 0; @@ -62,10 +71,12 @@ void ExternalReferenceTable::PrintCount() { } #endif // DEBUG -// static -const char* ExternalReferenceTable::ResolveSymbol(void* address) { +const char* ExternalReferenceTable::ResolveSymbol(void* address, + std::vector* tables) { #ifdef SYMBOLIZE_FUNCTION - return backtrace_symbols(&address, 1)[0]; + char** table = backtrace_symbols(&address, 1); + if (tables) tables->push_back(table); + return table[0]; #else return ""; #endif // SYMBOLIZE_FUNCTION @@ -458,7 +469,11 @@ void ExternalReferenceTable::AddApiReferences(Isolate* isolate) { if (api_external_references != nullptr) { while (*api_external_references != 0) { Address address = reinterpret_cast
(*api_external_references); +#ifdef SYMBOLIZE_FUNCTION + Add(address, ResolveSymbol(address, &symbol_tables_)); +#else Add(address, ResolveSymbol(address)); +#endif api_external_references++; } } diff --git a/src/external-reference-table.h b/src/external-reference-table.h index 76d437c3cc..101d8332fb 100644 --- a/src/external-reference-table.h +++ b/src/external-reference-table.h @@ -5,6 +5,8 @@ #ifndef V8_EXTERNAL_REFERENCE_TABLE_H_ #define V8_EXTERNAL_REFERENCE_TABLE_H_ +#include + #include "src/address-map.h" namespace v8 { @@ -18,6 +20,7 @@ class Isolate; class ExternalReferenceTable { public: static ExternalReferenceTable* instance(Isolate* isolate); + ~ExternalReferenceTable(); uint32_t size() const { return static_cast(refs_.length()); } Address address(uint32_t i) { return refs_[i].address; } @@ -32,7 +35,8 @@ class ExternalReferenceTable { void PrintCount(); #endif // DEBUG - static const char* ResolveSymbol(void* address); + static const char* ResolveSymbol(void* address, + std::vector* = nullptr); private: struct ExternalReferenceEntry { @@ -63,6 +67,9 @@ class ExternalReferenceTable { void AddApiReferences(Isolate* isolate); List refs_; +#ifdef DEBUG + std::vector symbol_tables_; +#endif uint32_t api_refs_start_; DISALLOW_COPY_AND_ASSIGN(ExternalReferenceTable);