• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 PANDA_LIBPANDABASE_PBASE_OS_NATIVESTACK_H
17 #define PANDA_LIBPANDABASE_PBASE_OS_NATIVESTACK_H
18 
19 #include "os/thread.h"
20 #if defined(PANDA_TARGET_UNIX)
21 #include "platforms/unix/libpandabase/native_stack.h"
22 #endif  // PANDA_TARGET_UNIX
23 
24 #include <csignal>
25 #include <string>
26 #include <set>
27 
28 namespace ark::os::native_stack {
29 
30 #if defined(PANDA_TARGET_UNIX)
31 using FuncUnwindstack = os::unix::native_stack::FuncUnwindstack;
32 const auto g_PandaThreadSigmask = pthread_sigmask;  // NOLINT(readability-identifier-naming)
33 using DumpUnattachedThread = ark::os::unix::native_stack::DumpUnattachedThread;
34 const auto DumpKernelStack = ark::os::unix::native_stack::DumpKernelStack;  // NOLINT(readability-identifier-naming)
35 const auto GetNativeThreadNameForFile =                                     // NOLINT(readability-identifier-naming)
36     ark::os::unix::native_stack::GetNativeThreadNameForFile;
37 const auto ReadOsFile = ark::os::unix::native_stack::ReadOsFile;      // NOLINT(readability-identifier-naming)
38 const auto WriterOsFile = ark::os::unix::native_stack::WriterOsFile;  // NOLINT(readability-identifier-naming)
39 const auto ChangeJaveStackFormat =                                    // NOLINT(readability-identifier-naming)
40     ark::os::unix::native_stack::ChangeJaveStackFormat;
41 #else
42 using FuncUnwindstack = bool (*)(pid_t, std::ostream &, int);
43 class DumpUnattachedThread {
44 public:
45     void AddTid(pid_t tidThread);
46     bool InitKernelTidLists();
47     void Dump(std::ostream &os, bool dumpNativeCrash, FuncUnwindstack callUnwindstack);
48 
49 private:
50     std::set<pid_t> kernelTid_;
51     std::set<pid_t> threadManagerTids_;
52 };
53 void DumpKernelStack(std::ostream &os, pid_t tid, const char *tag, bool count);
54 std::string GetNativeThreadNameForFile(pid_t tid);
55 bool ReadOsFile(const std::string &file_name, std::string *result);
56 bool WriterOsFile(const void *buffer, size_t count, int fd);
57 std::string ChangeJaveStackFormat(const char *descriptor);
58 #endif  // PANDA_TARGET_UNIX
59 
60 }  // namespace ark::os::native_stack
61 #endif  // PANDA_LIBPANDABASE_PBASE_OS_NATIVESTACK_H
62