diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp index 297cf06266cb7f7b1e2ff50f0de211edf0b4ef9a..b26f1fd645e498eda915557d1a170d4dd6b9febf 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 f8c22d132dc4bef7677b3f65ec8d3c920f0def6f..5cd8dbe899800dcb46ee097a4395403dfc8a9ffd 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 939d61f3e6807ccbbcd10e32d35ea75810b24722..7bbac4d92cbdc9a3c98bc6098afd5d0529b16ca1 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 3f0b8f03f5ff2ab8aa5776da48b93ba911707b30..b882ffd75005e5ee7e771a37a5d21d341e8ed35b 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