• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ABILITY_RUNTIME_MIX_STACK_DUMPER_H
17 #define OHOS_ABILITY_RUNTIME_MIX_STACK_DUMPER_H
18 
19 #include <signal.h>
20 #include <unistd.h>
21 #include <vector>
22 
23 #include "dfx_dump_catcher.h"
24 #include "event_handler.h"
25 #include "ohos_application.h"
26 #include "runtime.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 class MixStackDumper {
31 public:
32     MixStackDumper() = default;
33     ~MixStackDumper() = default;
34     void InstallDumpHandler(std::shared_ptr<OHOSApplication> application,
35         std::shared_ptr<EventHandler> handler);
36 
37 private:
38     void Init(pid_t pid);
39     void Destroy();
40     bool DumpMixFrame(int fd, pid_t nstid, pid_t tid);
41     void GetThreadList(std::vector<pid_t>& threadList);
42     bool IsJsNativePcEqual(uintptr_t *jsNativePointer, uint64_t nativePc, uint64_t nativeOffset);
43     void BuildJsNativeMixStack(int fd, std::vector<JsFrames>& jsFrames,
44         std::vector<std::shared_ptr<OHOS::HiviewDFX::DfxFrame>>& nativeFrames);
45     std::string GetThreadStackTraceLabel(pid_t tid);
46     void PrintNativeFrames(int fd, std::vector<std::shared_ptr<OHOS::HiviewDFX::DfxFrame>>& nativeFrames);
47     void PrintProcessHeader(int fd, pid_t pid, uid_t uid);
48 
49     static void Dump_SignalHandler(int sig, siginfo_t *si, void *context);
50     static void HandleMixDumpRequest();
51 
52 private:
53     static std::weak_ptr<EventHandler> signalHandler_;
54     static std::weak_ptr<OHOSApplication> application_;
55     std::unique_ptr<OHOS::HiviewDFX::DfxDumpCatcher> catcher_{nullptr};
56 };
57 } // AppExecFwk
58 } // OHOS
59 #endif // OHOS_ABILITY_RUNTIME_MIX_STACK_DUMPER_H
60