fix prevent violation
[framework/system/dynamic-analysis-probe.git] / include / dahelper.h
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: 
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  * 
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  * 
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  * 
29  */
30
31 #ifndef _DAHELPER_H_
32 #define _DAHELPER_H_
33
34 #include <stdbool.h>
35 #include <pthread.h>                    // for pthread_mutex_t
36
37 #include <Evas.h>
38
39 #include "daprobe.h"
40
41 #ifdef __cplusplus
42 extern "C"{
43 #endif
44
45 #define MAX_PATH_LENGTH         256
46 #define MAX_STACK_DEPTH         128
47 #define TRIM_STACK_DEPTH        2
48
49 /*
50 #define WIN_RENDER_POST 0
51 #define CONTROLBAR_RENDER_POST 1
52 #define NAVIFRAME_RENDER_POST 2
53 #define PAGER_RENDER_POST 3
54 #define RENDER_POST_COUNT 4
55
56 #define SNAPSHOT_WAIT_TIME_MAX 10000
57 */
58
59 #define TS_NONE                                         0x0000
60 #define TS_PROBE                                        0x0001
61 #define TS_INIT                                         0x0002
62 #define TS_FINIT                                        0x0004
63 #define TS_ENTER_PROBE_BLOCK            0x0008
64 #define TS_SET_PROBE_POINT                      0x0010
65 #define TS_PRINT_LOG                            0x0020
66 #define TS_PRINT_SAMPLE_LOG                     0x0040
67 #define TS_APPEND_TYPE_LOG                      0x0080
68 #define TS_BACKTRACE                            0x0100
69 #define TS_HASHFUNC                                     0x0200
70 #define TS_PROFIL_THREAD                        0x0400
71 #define TS_PROFIL_COUNT                         0x0800
72 #define TS_DETECT_TOUCH                         0x1000
73 #define TS_REGIST_SCREEN_CHANGE         0x2000
74 #define TS_POSSIBLE_CAPTURE                     0x4000
75 #define TRACE_STATE_SET(value)          ((gSTrace) |= (value))
76 #define TRACE_STATE_UNSET(value)        ((gSTrace) &= (~value))
77
78 #define ENABLE_INTERNAL_MALLOC          0x0001
79 #define ENABLE_SNAPSHOT                         0x0002
80
81 #define SCREENSHOT_LOCK()                                                                               \
82         do {                                                                                                            \
83                 int old;                                                                                                \
84                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
85                 old = gTraceInfo.screenshot.state;                                              \
86                 gTraceInfo.screenshot.state = -1;                                               \
87                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
88                 if(old > 0) {                                                                                   \
89                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
90                                 captureScreen();                                                                \
91                 }                                                                                                               \
92         } while(0)
93
94 #define SCREENSHOT_UNLOCK()                                                                             \
95         do {                                                                                                            \
96                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
97                 gTraceInfo.screenshot.state = 1;                                                \
98                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
99         } while(0)
100
101 #define SCREENSHOT_SET()                                                                                \
102         do {                                                                                                            \
103                 int old;                                                                                                \
104                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
105                 old = gTraceInfo.screenshot.state;                                              \
106                 if(gTraceInfo.screenshot.state >= 0)                                    \
107                         gTraceInfo.screenshot.state = 1;                                        \
108                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
109                 if(old == 2) {                                                                                  \
110                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
111                                 captureScreen();                                                                \
112                 }                                                                                                               \
113         } while(0)
114
115 #define SCREENSHOT_UNSET()                                                                              \
116         do {                                                                                                            \
117                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
118                 if(gTraceInfo.screenshot.state >= 0)                                    \
119                         gTraceInfo.screenshot.state = 0;                                        \
120                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
121         } while(0)
122
123 #define SCREENSHOT_DONE()                                                                               \
124         do {                                                                                                            \
125                 int old;                                                                                                \
126                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
127                 old = gTraceInfo.screenshot.state;                                              \
128                 if(gTraceInfo.screenshot.state == 1) {                                  \
129                         gTraceInfo.screenshot.state = 2;                                        \
130                 } else if(gTraceInfo.screenshot.state == 2) {                   \
131                         gTraceInfo.screenshot.state = 0;                                        \
132                 } else {                                                                                                \
133                 }                                                                                                               \
134                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
135                 if(old == 1) {                                                                                  \
136                         activateCaptureTimer();                                                         \
137                 } else if(old == 2) {                                                                   \
138                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
139                                 captureScreen();                                                                \
140                 }                                                                                                               \
141         } while(0)
142
143 #define NUM_ORIGINAL_LIBRARY    9
144
145 typedef enum
146 {
147         LIBC = 0,
148         LIBPTHREAD = 1,
149         LIBELEMENTARY = 2,
150         LIBOSP_UIFW = 3,
151         LIBOSP_APPFW = 4,
152         LIBOSP_WEB = 5,
153         LIBECORE_INPUT_EVAS = 6,
154         LIBDAEMON = 7,
155         LIBCAPI_APPFW_APPLICATION = 8
156 } ORIGINAL_LIBRARY;
157
158 extern char *lib_string[NUM_ORIGINAL_LIBRARY];
159 extern void *lib_handle[NUM_ORIGINAL_LIBRARY];
160
161 // type definition for global variable
162 typedef struct
163 {
164         int eventIndex;
165         pthread_mutex_t eventMutex;
166 } __indexInfo;
167
168 typedef struct
169 {
170         int daemonSock;
171         pthread_mutex_t sockMutex;
172 } __socketInfo;
173
174 typedef struct
175 {
176         char appName[128];
177         unsigned int startTime;
178 } __appInfo;
179
180 typedef struct
181 {
182         int state;
183         pthread_mutex_t ssMutex;
184 } __screenshotInfo;
185
186 typedef struct
187 {
188         void* map_start;
189         void* map_end;
190 } __mapInfo;
191
192 typedef struct
193 {
194         __indexInfo                     index;
195         __socketInfo            socket;
196         __appInfo                       app;
197         __screenshotInfo        screenshot;
198         __mapInfo                       exec_map;
199         int                                     stateTouch;
200         int                                     init_complete;
201         int                                     custom_chart_callback_count;
202         unsigned long           optionflag;
203 } __traceInfo;
204
205 extern __thread unsigned long   gSTrace;
206 extern __traceInfo gTraceInfo;
207
208 char** da_backtrace_symbols (void* const* array, int size);
209 char** cached_backtrace_symbols (void* const* array, int size);
210
211 // profil turned on
212 int __profil(int mode);
213
214 //wchar_t* -> char*
215 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
216
217 // screen capture functions
218 int initialize_screencapture();
219 int finalize_screencapture();
220 int captureScreen();
221 int activateCaptureTimer();
222 void _cb_render_post(void* data, Evas* e, void* eventinfo);
223
224 // event related functions
225 int initialize_event();
226 int finalize_event();
227 int getOrientation();
228 void orientationEnabled();
229 void on_orientation_changed(int angle, bool capi);
230
231 int remove_indir(const char* dirname);
232
233 // query functions
234 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif  // _DAHELPER_H_