diff --git a/interfaces/innerkits/unwinder/include/dfx_map.h b/interfaces/innerkits/unwinder/include/dfx_map.h index 685670d149ca76857cbb403dbef5bc2953abe49c..f220f4aa9a92b54550c9a12f3f312c63ff2588f3 100644 --- a/interfaces/innerkits/unwinder/include/dfx_map.h +++ b/interfaces/innerkits/unwinder/include/dfx_map.h @@ -29,7 +29,7 @@ class DfxHap; class DfxMap { public: - static std::shared_ptr Create(std::string buf, size_t size); + static std::shared_ptr Create(const std::string& vma); static void PermsToProts(const std::string perms, uint32_t& prots, uint32_t& flag); static void FormatMapName(pid_t pid, std::string& mapName); static std::string UnFormatMapName(const std::string& mapName); @@ -42,7 +42,7 @@ public: uint32_t prots, const std::string& name) : begin(begin), end(end), offset(offset), prots(prots), name(name) {} - bool Parse(char* buf, size_t size); + bool Parse(const char* buf, size_t size); bool IsMapExec(); bool IsArkExecutable(); bool IsJsvmExecutable(); diff --git a/interfaces/innerkits/unwinder/src/maps/dfx_map.cpp b/interfaces/innerkits/unwinder/src/maps/dfx_map.cpp index 92af99a1e566fcb34475b60298c7fb11db9e9dea..57ad90f230e506723f26f27d9b56566c80e37902 100644 --- a/interfaces/innerkits/unwinder/src/maps/dfx_map.cpp +++ b/interfaces/innerkits/unwinder/src/maps/dfx_map.cpp @@ -192,20 +192,20 @@ AT_ALWAYS_INLINE bool PermsToProtsAndFlag(const char* permChs, const size_t sz, #endif } -std::shared_ptr DfxMap::Create(std::string buf, size_t size) +std::shared_ptr DfxMap::Create(const std::string& vma) { - if (buf.empty() || size == 0) { + if (vma.empty()) { return nullptr; } auto map = std::make_shared(); - if (!map->Parse(&buf[0], size)) { - DFXLOGW("Failed to parse map: %{public}s", buf.c_str()); + if (!map->Parse(vma.c_str(), vma.size())) { + DFXLOGW("Failed to parse map: %{public}s", vma.c_str()); return nullptr; } return map; } -bool DfxMap::Parse(char* buf, size_t size) +bool DfxMap::Parse(const char* buf, size_t size) { #if defined(is_ohos) && is_ohos if (buf == nullptr || size == 0) { diff --git a/test/unittest/unwind/maps_test.cpp b/test/unittest/unwind/maps_test.cpp index 057a73313a11678c11138d1f6f2b41fc77a4310d..045c0fbf7c0b9ab9e4bec28e6617f2f43a2038f2 100644 --- a/test/unittest/unwind/maps_test.cpp +++ b/test/unittest/unwind/maps_test.cpp @@ -166,7 +166,7 @@ HWTEST_F(MapsTest, GetRelPcTest, TestSize.Level2) uint64_t pc = 0x7f0ab40016; const uint64_t invalidOffset = 0x16; #endif - shared_ptr map = DfxMap::Create(INVALID_MAP_ITEM, sizeof(INVALID_MAP_ITEM)); + shared_ptr map = DfxMap::Create(INVALID_MAP_ITEM); EXPECT_EQ(true, ((map->GetElf() == nullptr) && (map->GetRelPc(pc) == invalidOffset))); GTEST_LOG_(INFO) << "GetRelPcTest: end."; } @@ -179,7 +179,7 @@ HWTEST_F(MapsTest, GetRelPcTest, TestSize.Level2) HWTEST_F(MapsTest, ToStringTest, TestSize.Level2) { GTEST_LOG_(INFO) << "ToStringTest: start."; - shared_ptr map = DfxMap::Create(VALID_MAP_ITEM, sizeof(VALID_MAP_ITEM)); + shared_ptr map = DfxMap::Create(VALID_MAP_ITEM); GTEST_LOG_(INFO) << map->ToString(); EXPECT_EQ(true, sizeof(map->ToString()) != 0); GTEST_LOG_(INFO) << "ToStringTest: end."; @@ -257,7 +257,7 @@ HWTEST_F(MapsTest, IsArkExecutedMapTest, TestSize.Level2) HWTEST_F(MapsTest, IsVdsoMapTest, TestSize.Level2) { GTEST_LOG_(INFO) << "IsVdsoMapTest: start."; - shared_ptr map = DfxMap::Create(VDSO_MAP_ITEM, VDSO_MAP_ITEM.size()); + shared_ptr map = DfxMap::Create(VDSO_MAP_ITEM); ASSERT_TRUE(map->IsVdsoMap()); GTEST_LOG_(INFO) << "IsVdsoMapTest: end."; } diff --git a/test/unittest/unwind/unwinder_test.cpp b/test/unittest/unwind/unwinder_test.cpp index 405ef38bc091209e5e5167ba3560d01b6b5aff52..b61922361b60f7892eb1ccb5ffbfa0d39cff5d74 100644 --- a/test/unittest/unwind/unwinder_test.cpp +++ b/test/unittest/unwind/unwinder_test.cpp @@ -648,7 +648,7 @@ HWTEST_F(UnwinderTest, FillFrameTest001, TestSize.Level2) GTEST_LOG_(INFO) << " when DfxFrame::map is null, frame.buildId.size() is 0"; ASSERT_EQ(frame.buildId.size(), 0); string testMap = "f6d83000-f6d84000 r--p 00001000 b3:07 1892 /system/lib/init/libinit_context.z.so.noexit"; - auto map = DfxMap::Create(testMap, testMap.size()); + auto map = DfxMap::Create(testMap); frame.map = map; unwinder->FillFrame(frame); GTEST_LOG_(INFO) << " when DfxFrame::map is not null and file not exist, frame.buildId.size() is 0"; @@ -658,7 +658,7 @@ HWTEST_F(UnwinderTest, FillFrameTest001, TestSize.Level2) #else testMap = "7f0ab40000-7f0ab41000 r--p 00000000 b3:07 1882 /system/lib64/init/libinit_context.z.so"; #endif - map = DfxMap::Create(testMap, testMap.size()); + map = DfxMap::Create(testMap); frame.map = map; unwinder->FillFrame(frame); GTEST_LOG_(INFO) << " when DfxFrame::map is not null and file exist, frame.buildId.size() is bigger than 0"; @@ -681,7 +681,7 @@ HWTEST_F(UnwinderTest, FillJsFrameTest001, TestSize.Level2) GTEST_LOG_(INFO) << " when DfxFrame::map is null, frame.map is nullptr"; ASSERT_EQ(frame.map, nullptr); string testMap = "f6d83000-f6d84000 r--p 00001000 b3:07 1892 /system/lib/init/libinit_context.z.so"; - auto map = DfxMap::Create(testMap, testMap.size()); + auto map = DfxMap::Create(testMap); frame.map = map; unwinder->FillJsFrame(frame); GTEST_LOG_(INFO) << " when DfxFrame::map is not null and file exist, frame.map.GetHap is not nullptr"; @@ -706,7 +706,7 @@ HWTEST_F(UnwinderTest, FillFramesTest001, TestSize.Level2) auto unwinder = std::make_shared(); std::vector frames; DfxFrame frame; - auto map = DfxMap::Create(testMap, testMap.size()); + auto map = DfxMap::Create(testMap); frame.map = map; frames.push_back(frame); ASSERT_EQ(frames[0].buildId.size(), 0);