• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 DFX_BACKTRACE_LOCAL_H
17 #define DFX_BACKTRACE_LOCAL_H
18 
19 #include <cinttypes>
20 #include <string>
21 #include <vector>
22 #include "dfx_frame.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 
27 /**
28  * @brief Get a thread of backtrace frames by specify tid
29  *
30  * @param frames  backtrace frames(output parameter)
31  * @param tid  the id of thread
32  * @param skipFrameNum the number of frames to skip
33  * @param fast flag for using fp backtrace(true) or dwarf backtrace(false)
34  * @return if succeed return true, otherwise return false
35 */
36 bool GetBacktraceFramesByTid(std::vector<DfxFrame>& frames, int32_t tid, size_t skipFrameNum, bool fast);
37 
38 /**
39  * @brief Get a thread of backtrace string  by specify tid
40  *
41  * @param out  backtrace string(output parameter)
42  * @param tid  the id of thread
43  * @param skipFrameNum the number of frames to skip
44  * @param fast flag for using fp backtrace(true) or dwarf backtrace(false)
45  * @return if succeed return true, otherwise return false
46 */
47 bool GetBacktraceStringByTid(std::string& out, int32_t tid, size_t skipFrameNum, bool fast);
48 
49 /**
50  * @brief Print backtrace information to fd
51  *
52  * @param fd  file descriptor
53  * @param fast flag for using fp backtrace(true) or dwarf backtrace(false)
54  * @return if succeed return true, otherwise return false
55 */
56 bool PrintBacktrace(int32_t fd = -1, bool fast = false);
57 
58 /**
59  * @brief Get backtrace string of the current process
60  *
61  * @param out  backtrace string(output parameter)
62  * @param fast flag for using fp backtrace(true) or dwarf backtrace(false)
63  * @return if succeed return true, otherwise return false
64 */
65 bool GetBacktrace(std::string& out, bool fast = false);
66 
67 /**
68  * @brief Get backtrace string of the current process
69  *
70  * @param out  backtrace string(output parameter)
71  * @param skipFrameNum the number of frames to skip
72  * @param fast flag for using fp backtrace(true) or dwarf backtrace(false)
73  * @return if succeed return true, otherwise return false
74 */
75 bool GetBacktrace(std::string& out, size_t skipFrameNum, bool fast = false);
76 
77 /**
78  * @brief Get formated stacktrace string of current process
79  *
80  * This API is used to get formated stacktrace string of current process
81  *
82  * @return formated stacktrace string
83 */
84 std::string GetProcessStacktrace();
85 
86 extern "C" {
87     /**
88      * @brief Print backtrace information to fd
89      *
90      * @param fd  file descriptor
91      * @return if succeed return true, otherwise return false
92     */
93     bool PrintTrace(int32_t fd = -1);
94 
95     /**
96      * @brief Get backtrace of the current process
97      *
98      * @param skipFrameNum the number of frames to skip
99      * @return backtrace of the current process
100     */
101     const char* GetTrace(size_t skipFrameNum = 0);
102 }
103 
104 } // namespace HiviewDFX
105 } // namespace OHOS
106 #endif
107