diff --git a/device/BUILD.gn b/device/BUILD.gn index e8feebeca586621e3b70c259e291ef95255d531a..a75a390d23ef794e75675c2e387f51d1926e076c 100755 --- a/device/BUILD.gn +++ b/device/BUILD.gn @@ -35,10 +35,7 @@ group("hiprofiler_targets") { "services/profiler_service:hiprofilerd", "services/shared_memory:shared_memory", ] - - # do not build native hook target - # if (is_ohos && target_cpu == "arm") { - if (false) { + if (is_ohos) { deps += [ "plugins/native_daemon:native_daemon", "plugins/native_hook:native_hook", @@ -64,10 +61,7 @@ group("unittest") { "services/profiler_service/test:unittest", "services/shared_memory/test:unittest", ] - - # do not build native hook target - # if (is_ohos && target_cpu == "arm") { - if (false) { + if (is_ohos) { deps += [ "plugins/native_daemon/test:unittest", "plugins/native_hook/test:unittest", diff --git a/device/plugins/memory_plugin/src/memory_data_plugin.cpp b/device/plugins/memory_plugin/src/memory_data_plugin.cpp index dda6246123349d121315364bdc6096af0816c5df..826a7a31e3acaf4ca6bc1b38c517499207059f0e 100755 --- a/device/plugins/memory_plugin/src/memory_data_plugin.cpp +++ b/device/plugins/memory_plugin/src/memory_data_plugin.cpp @@ -506,6 +506,7 @@ int32_t MemoryDataPlugin::ReadProcPidFile(int32_t pid, const char* pFileName) err_ = errno; return RET_FAIL; } + buffer_.get()[bytesRead] = '\0'; close(fd); return bytesRead; diff --git a/device/plugins/native_daemon/BUILD.gn b/device/plugins/native_daemon/BUILD.gn index 48713eac74bfc2e5dd8814a0a277f9fbbf6ffb52..b83e2339aa2953d8263f74e07eef6a68769696ff 100755 --- a/device/plugins/native_daemon/BUILD.gn +++ b/device/plugins/native_daemon/BUILD.gn @@ -43,6 +43,7 @@ ohos_executable("native_daemon") { "../api/src/command_poller.cpp", "src/callstack.cpp", "src/debug_logger.cpp", + "src/dwarf_encoding.cpp", "src/elf_file.cpp", "src/elf_header.cpp", "src/elf_symbol.cpp", diff --git a/device/plugins/native_daemon/src/debug_logger.cpp b/device/plugins/native_daemon/src/debug_logger.cpp index d214ea4e365906cb542433a513cfe77df3699ebf..e69f51183b60600e729edca7f47925d557173ecd 100755 --- a/device/plugins/native_daemon/src/debug_logger.cpp +++ b/device/plugins/native_daemon/src/debug_logger.cpp @@ -112,7 +112,7 @@ int DebugLogger::Log(DebugLevel level, const std::string &logTag, const char *fm const auto startWriteTime = steady_clock::now(); #endif milliseconds timeStamp = duration_cast(startTime - timeStamp_); - fprintf(file_, "%05lld ms %s", timeStamp.count(), buffer.data()); // to the file + fprintf(file_, "%05" PRId64 " ms %s", (int64_t)timeStamp.count(), buffer.data()); // to the file #ifdef HIPERF_DEBUG_TIME logWriteTimes_ += duration_cast(steady_clock::now() - startWriteTime); #endif @@ -260,4 +260,4 @@ DebugLogger *DebugLogger::GetInstance() } } // namespace NativeDaemon } // namespace Developtools -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/device/plugins/native_daemon/src/dwarf_encoding.cpp b/device/plugins/native_daemon/src/dwarf_encoding.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4e0894d9f966a7de1337d7775b7cfc9e63f36110 --- /dev/null +++ b/device/plugins/native_daemon/src/dwarf_encoding.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define HILOG_TAG "Dwarf" + +#include "dwarf_encoding.h" + +#include "utilities.h" +namespace OHOS { +namespace Developtools { +namespace NativeDaemon { +DwarfEncoding::DwarfEncoding(dw_encode_t dw, const unsigned char *&data, uint64_t vaddrBase, + uint64_t vaddrPC, uint64_t vaddrText) + : dw_(dw), data_(data), vaddrBase_(vaddrBase), vaddrPC_(vaddrPC), vaddrText_(vaddrText) +{ + value_[0] = ReadValue(data); +} + +const std::string DwarfEncoding::ToString() const +{ + std::string debugString = ApplicationName() + ":" + FormatName() + " format:" + ToHex(dw_) + + " value size:" + std::to_string(GetSize()) + " raw:"; + + size_t size = GetSize(); + const unsigned char *data = data_; + while (size-- > 0) { + debugString.append(ToHex(data[0]) + " "); + data++; + } + + debugString.append(" | " + ToHex(GetValue(), GetSize(), true)); + debugString.append(" applied:" + ToHex(GetAppliedValue(), GetSize())); + return debugString; +} + +const unsigned char *DwarfEncoding::GetEnd() const +{ + return data_ + GetSize(); +} + +const unsigned char *DwarfEncoding::GetData() const +{ + return data_; +} + +size_t DwarfEncoding::GetSize() const +{ + return DWFormatSizeMap.at((dw_encode_t)Format()); +} + +uint64_t DwarfEncoding::GetValue() const +{ + return value_[0]; +} + +uint64_t DwarfEncoding::GetAppliedValue() const +{ + if ((Application() & DW_EH_PE_datarel) == DW_EH_PE_datarel) { + return value_[0] + vaddrBase_; + } else if ((Application() & DW_EH_PE_textrel) == DW_EH_PE_textrel) { + return value_[0] + vaddrText_; + } else if ((Application() & DW_EH_PE_pcrel) == DW_EH_PE_pcrel) { + return value_[0] + vaddrPC_; + } + HLOGM("Application is empty"); + + return value_[0]; +} + +bool DwarfEncoding::IsOmit() const +{ + return (dw_ == DW_EH_PE_omit); +} + +dw_encode_t DwarfEncoding::Format() const +{ + return (dw_ & 0x0F); +} +dw_encode_t DwarfEncoding::Application() const +{ + return (dw_ & 0xF0); +} +uint64_t DwarfEncoding::ReadValue(const unsigned char *&data) const +{ + switch (Format()) { + case DW_EH_PE_udata2: + return dwReadAnyTypeData(data, uint16_t()); + case DW_EH_PE_udata4: + return dwReadAnyTypeData(data, uint32_t()); + case DW_EH_PE_udata8: + return dwReadAnyTypeData(data, uint64_t()); + case DW_EH_PE_sdata2: + return dwReadAnyTypeData(data, int16_t()); + case DW_EH_PE_sdata4: + return dwReadAnyTypeData(data, int32_t()); + case DW_EH_PE_sdata8: + return dwReadAnyTypeData(data, int64_t()); + default: + return -1; + } +} +const std::string DwarfEncoding::FormatName() const +{ + switch (Format()) { + case DW_EH_PE_absptr: + return "DW_EH_PE_absptr"; + case DW_EH_PE_uleb128: + return "DW_EH_PE_uleb128"; + case DW_EH_PE_udata2: + return "DW_EH_PE_udata2"; + case DW_EH_PE_udata4: + return "DW_EH_PE_udata4"; + case DW_EH_PE_udata8: + return "DW_EH_PE_udata8"; + case DW_EH_PE_sleb128: + return "DW_EH_PE_sleb128"; + case DW_EH_PE_sdata2: + return "DW_EH_PE_data2"; + case DW_EH_PE_sdata4: + return "DW_EH_PE_sdata4"; + case DW_EH_PE_sdata8: + return "DW_EH_PE_sdata8"; + case DW_EH_PE_omit: + return "DW_EH_PE_omit"; + default: + return "unknow format"; + } +} +const std::string DwarfEncoding::ApplicationName() const +{ + switch (Application()) { + case DW_EH_PE_pcrel: + return "DW_EH_PE_pcrel"; + case DW_EH_PE_textrel: + return "DW_EH_PE_textrel"; + case DW_EH_PE_datarel: + return "DW_EH_PE_datarel"; + case DW_EH_PE_funcrel: + return "DW_EH_PE_funcrel"; + case DW_EH_PE_aligned: + return "DW_EH_PE_aligned"; + case DW_EH_PE_omit: + return "DW_EH_PE_omit"; + case DW_EH_PE_nothing: + return "DW_EH_PE_empty"; + default: + return "unknow format"; + } +} +} // namespace HiPerf +} // namespace Developtools +} // namespace OHOS \ No newline at end of file diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index c29011d6f6075a26e24245abe403e7b0d2f80d09..18392eb064cff9ed8628905e4311c87c4b195ee0 100755 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -136,7 +136,8 @@ bool HookManager::CreatePluginSession(const std::vector& c HILOG_DEBUG(LOG_CORE, "save file name = %s", hookConfig_.file_name().c_str()); FILE *fp = fopen(hookConfig_.file_name().c_str(), "wb+"); if (fp) { - fpHookData_.reset(fp); + fpHookData_.reset(); + fpHookData_ = std::unique_ptr(fp, fclose); } else { fpHookData_.reset(); } @@ -297,4 +298,4 @@ bool HookManager::CreateWriter(std::string pluginName, uint32_t bufferSize, int bool HookManager::ResetWriter(uint32_t pluginId) { return true; -} \ No newline at end of file +} diff --git a/device/plugins/native_daemon/src/symbols.cpp b/device/plugins/native_daemon/src/symbols.cpp index 49a230cb7d31549409b5c8ffae384d3b990c1aa9..93600e4ad69cc93ff1c1bfc2506c5bb74ac181ec 100755 --- a/device/plugins/native_daemon/src/symbols.cpp +++ b/device/plugins/native_daemon/src/symbols.cpp @@ -863,7 +863,7 @@ public: const auto thisTime = std::chrono::steady_clock::now(); const auto usedTimeMsTick = std::chrono::duration_cast(thisTime - startTime); - printf("Load kernel symbols (total %lld ms)\n", usedTimeMsTick.count()); + printf("Load kernel symbols (total %" PRId64 " ms)\n", (int64_t)usedTimeMsTick.count()); // load complete return true; } @@ -1183,4 +1183,4 @@ uint64_t SymbolsFile::GetVaddrInSymbols(uint64_t ip, uint64_t, uint64_t) const } } // namespace NativeDaemon } // namespace Developtools -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/device/plugins/native_daemon/test/BUILD.gn b/device/plugins/native_daemon/test/BUILD.gn index c80fdf132a261d9fcace6aec2e366d3a356a4459..7d423cfba447ddada8423c33726b44754a48347e 100755 --- a/device/plugins/native_daemon/test/BUILD.gn +++ b/device/plugins/native_daemon/test/BUILD.gn @@ -37,6 +37,7 @@ sources_base = [ "../src/hook_manager.cpp", "../src/callstack.cpp", "../src/debug_logger.cpp", + "../src/dwarf_encoding.cpp", "../src/elf_file.cpp", "../src/elf_header.cpp", "../src/elf_symbol.cpp", diff --git a/device/plugins/native_daemon/test/unittest/common/native/include/virtual_runtime_test.h b/device/plugins/native_daemon/test/unittest/common/native/include/virtual_runtime_test.h index 4eb647afc7605f0cf04c1163ad260dcbad312a3b..9738b3eb1ec5f84fcaa808a8f3a5d420077c3b9e 100755 --- a/device/plugins/native_daemon/test/unittest/common/native/include/virtual_runtime_test.h +++ b/device/plugins/native_daemon/test/unittest/common/native/include/virtual_runtime_test.h @@ -15,7 +15,6 @@ #ifndef HIPERF_VIRTUAL_RUNTIME_TEST_H #define HIPERF_VIRTUAL_RUNTIME_TEST_H -#include "callstack_test.h" #include "debug_logger.h" #include "utilities.h" #include "virtual_runtime.h" diff --git a/device/plugins/process_plugin/src/process_data_plugin.cpp b/device/plugins/process_plugin/src/process_data_plugin.cpp index d22ab528043872f44c0171726f7eef37664037c3..84325706fa08e010b5c60be6bbd91ea42699b4ce 100755 --- a/device/plugins/process_plugin/src/process_data_plugin.cpp +++ b/device/plugins/process_plugin/src/process_data_plugin.cpp @@ -163,6 +163,7 @@ int32_t ProcessDataPlugin::ReadProcPidFile(int32_t pid, const char* pFileName) err_ = errno; return RET_FAIL; } + buffer_.get()[bytesRead] = '\0'; close(fd); return bytesRead;