From 85485f7bac7c21025718e7f8075fdbd0b25579ce Mon Sep 17 00:00:00 2001 From: "dongbosi@huawei.com" Date: Mon, 26 May 2025 22:29:22 +0800 Subject: [PATCH] dumpcatcherwithtimeout support dump self Signed-off-by: dongbosi@huawei.com --- .../dump_catcher/dfx_dump_catcher.cpp | 5 ++-- .../dump_catcher/dfx_dump_catcher_errno.cpp | 1 + .../dump_catcher/dfx_dump_catcher_errno.h | 1 + .../dumpcatcher_interfaces_test.cpp | 25 ++++++++++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp index 297cf0626..b26f1fd64 100644 --- a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp +++ b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp @@ -560,9 +560,8 @@ std::pair DfxDumpCatcher::Impl::DumpCatchWithTimeout(int pid, std::unique_lock lck(mutex_); int currentPid = getpid(); if (pid == currentPid) { - DFXLOGE("DumpCatchWithTimeout:: param error (don't support dumpcatch self)"); - dumpcatchErrno = DUMPCATCH_EPARAM; - break; + bool ret = DoDumpLocalLocked(pid, tid, msg, DEFAULT_MAX_FRAME_NUM); + dumpcatchErrno = ret ? DUMPCATCH_ESUCCESS : DUMPCATCH_DUMP_SELF_FAIL; } else { DFXLOGI("Receive DumpCatch request for cPid:(%{public}d), pid(%{public}d)", currentPid, pid); dumpcatchErrno = DoDumpRemoteLocked(pid, tid, msg, isJson, timeout); diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.cpp b/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.cpp index f8c22d132..5cd8dbe89 100644 --- a/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.cpp +++ b/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.cpp @@ -49,6 +49,7 @@ const DumpCatchErrInfo ERROR_CODE_MAPS[] = { { DUMPCATCH_KERNELSTACK_NONEED, "no need to dump kernelstack" }, { DUMPCATCH_DUMP_ESYMBOL_NO_PARSE, "no enough time to parse symbol" }, { DUMPCATCH_DUMP_ESYMBOL_PARSE_TIMEOUT, "parse symbol timeout" }, + { DUMPCATCH_DUMP_SELF_FAIL, "dump self fail" }, { DUMPCATCH_UNKNOWN, "unknown reason" } }; diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.h b/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.h index 939d61f3e..7bbac4d92 100644 --- a/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.h +++ b/interfaces/innerkits/dump_catcher/dfx_dump_catcher_errno.h @@ -44,6 +44,7 @@ enum DumpCatchErrorCode : int32_t { DUMPCATCH_DUMP_EMAP, /* failed to find map */ DUMPCATCH_DUMP_ESYMBOL_NO_PARSE, /* no enough time to parse symbol */ DUMPCATCH_DUMP_ESYMBOL_PARSE_TIMEOUT, /* parse symbol timeout */ + DUMPCATCH_DUMP_SELF_FAIL, /* dump self fail */ DUMPCATCH_TIMEOUT_SIGNAL_BLOCK = 301, /* signal has been block by target process */ DUMPCATCH_TIMEOUT_KERNEL_FROZEN, /* target process has been frozen in kernel */ diff --git a/test/unittest/dump_catcher/dumpcatcher_interfaces_test.cpp b/test/unittest/dump_catcher/dumpcatcher_interfaces_test.cpp index 3f0b8f03f..b882ffd75 100644 --- a/test/unittest/dump_catcher/dumpcatcher_interfaces_test.cpp +++ b/test/unittest/dump_catcher/dumpcatcher_interfaces_test.cpp @@ -982,7 +982,6 @@ HWTEST_F(DumpCatcherInterfacesTest, DumpCatcherInterfacesTest039, TestSize.Level ExecuteCommands(startProcessCmd); GTEST_LOG_(INFO) << result.second; ASSERT_TRUE(result.first == 1); - GTEST_LOG_(INFO) << "DumpCatcherInterfacesTest039: end."; } } @@ -1193,5 +1192,29 @@ HWTEST_F(DumpCatcherInterfacesTest, DumpCatcherInterfacesTest043, TestSize.Level #endif GTEST_LOG_(INFO) << "DumpCatcherInterfacesTest043: end."; } + +/** + * @tc.name: DumpCatcherInterfacesTest044 + * @tc.desc: test DumpCatchWithTimeout dump self + * @tc.type: FUNC + * @tc.require: ICAOEX + */ +HWTEST_F(DumpCatcherInterfacesTest, DumpCatcherInterfacesTest044, TestSize.Level2) +{ + GTEST_LOG_(INFO) << "DumpCatcherInterfacesTest044: start."; + std::string res = ExecuteCommands("uname"); + bool isSuccess = res.find("Linux") == std::string::npos; + if (!isSuccess) { + ASSERT_FALSE(isSuccess); + } else { + DfxDumpCatcher dumplog; + std::string msg = ""; + int currentPid = getpid(); + auto result = dumplog.DumpCatchWithTimeout(currentPid, msg); + GTEST_LOG_(INFO) << result.second; + EXPECT_TRUE(result.first == 0); + GTEST_LOG_(INFO) << "DumpCatcherInterfacesTest044: end."; + } +} } // namespace HiviewDFX } // namepsace OHOS -- Gitee