OpenClovis Logo

clDebugApi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2012 OpenClovis Solutions Inc. All Rights Reserved.
3  *
4  * This file is available under a commercial license from the
5  * copyright holder or the GNU General Public License Version 2.0.
6  *
7  * The source code for this program is not published or otherwise
8  * divested of its trade secrets, irrespective of what has been
9  * deposited with the U.S. Copyright office.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * For more information, see the file COPYING provided with this
17  * material.
18  */
19 /*******************************************************************************
20 * ModuleName : debug
21 * File : clDebugApi.h
22 *******************************************************************************/
23 
24 /*******************************************************************************
25 * Description :
26 * This This module contains common DEBUG definitions
27 ******************************************************************************/
28 
41 #ifndef _CL_DEBUG_API_H_
42 #define _CL_DEBUG_API_H_
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include <clCommon.h>
49 #include <clDebugErrors.h>
50 #include <clHandleApi.h>
51 #include <clLogApi.h>
52 #include <clRmdIpi.h>
53 #ifndef __KERNEL__
54 #include <stdio.h>
55 #include <unistd.h>
56 #include <time.h>
57 #endif
58 
59 #ifdef SOLARIS_BUILD
60 #include <ucontext.h>
61 #include <stdlib.h>
62 #include <string.h>
63 int backtrace(void **buffer, int count);
64 char **backtrace_symbols(void *const *array, int size);
65 void backtrace_symbols_fd(void *const *array, int size, int fd);
66 #endif /* SOLARIS_BUILD */
67 
68 /******************************************************************************
69  * Constant and Macro Definitions
70  *****************************************************************************/
71 
80 #define CL_DEBUG_CRITICAL 3
81 
85 #define CL_DEBUG_ERROR 4
86 
90 #define CL_DEBUG_WARN 5
91 
95 #define CL_DEBUG_INFO 7
96 
100 #define CL_DEBUG_TRACE 0xc
101 
107 #if !defined(CL_DEBUG_LEVEL_THRESHOLD)
108 #define CL_DEBUG_LEVEL_THRESHOLD CL_DEBUG_ERROR
109 #endif
110 
117 #ifndef CL_DEBUG
118 #define CL_DEBUG
119 #endif
120 
121 #ifdef CL_DEBUG
122 #ifndef __KERNEL__
123 #include <clEoApi.h>
124 #include <clDbg.h>
125 
126 #define CL_DEBUG_SP(...) __VA_ARGS__
127 
128 #define clCompStatLog(...) clLog(CL_LOG_SEV_DEBUG,"COMP","STAT", __VA_ARGS__)
129 
130 
131 
132 enum
133  {
134  clDebugTimeStrMaxLen = 128
135  };
136 
137 #define CL_DEBUG_PRINT(x,y) \
138  do \
139  { \
140  char __str[256]; \
141  if(x <= CL_DEBUG_LEVEL_THRESHOLD) \
142  {\
143  snprintf(__str,256,CL_DEBUG_SP y); \
144  clLog((ClLogSeverityT)x, CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED,\
145  __str);\
146  }\
147  if (1) \
148  { \
149  snprintf(__str,256,CL_DEBUG_SP y); \
150  clDbgMsg((int)getpid(),__FILE__, __LINE__, __FUNCTION__,x,__str); \
151  } \
152  }while (0)
153 
154 #define CL_DEBUG_PRINT_CONSOLE(x,y) \
155  do \
156  { \
157  char __str[256]; \
158  if(x <= CL_DEBUG_LEVEL_THRESHOLD) \
159  { \
160  snprintf(__str,256,CL_DEBUG_SP y); \
161  clLogConsole((ClLogSeverityT)x, CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED, \
162  "%s", __str); \
163  } \
164  if (1) \
165  { \
166  snprintf(__str,256,CL_DEBUG_SP y); \
167  clDbgMsg((int)getpid(),__FILE__, __LINE__, __FUNCTION__,x,__str); \
168  } \
169  }while (0)
170 
171 #else /* __KERNEL__ */
172 
173 #define CL_DEBUG_PRINT(x,y) \
174  do \
175  { \
176  if(x <= CL_DEBUG_LEVEL_THRESHOLD) \
177  {\
178  printk("file:%s,func:%s,line:%d: ", __FILE__, __FUNCTION__, __LINE__);\
179  printk y; \
180  }\
181  }while (0)
182 
183 #define CL_DEBUG_PRINT_CONSOLE CL_DEBUG_PRINT
184 
185 #endif
186 
187 #else /* CL_DEBUG */
188 #define CL_DEBUG_PRINT(x,y)
189 #define CL_DEBUG_PRINT_CONSOLE(x, y)
190 #endif
191 
195 #define CL_FUNC_ENTER()
196 
197 
201 #define CL_FUNC_EXIT()
202 
203 
207 #ifndef __KERNEL__
208 #include <assert.h>
209 #define CL_ASSERT(expr) \
210 do \
211 { \
212  ClBoolT val = (expr)?CL_TRUE:CL_FALSE; \
213  if (clDbgPauseOnCodeError && !val ) \
214  clDbgCodeError(0,("Assertion failed")); \
215  else \
216  assert(val); \
217 } while(0)
218 #endif /* __KERNEL__ */
219 
220 struct clEoExecutionObj;
221 
225 #define CL_DEBUG_COMP_PROMPT_LEN 15
226 
227 
231 #define CL_DEBUG_COMP_NAME_LEN 128
232 
233 
237 #define CL_DEBUG_FUNC_NAME_LEN 41
238 
242 #define CL_DEBUG_FUNC_HELP_LEN 201
243 
250 
254  ClUint32T argc,
255 
259  ClCharT** argv,
260 
264  ClCharT** ret);
265 
269 typedef struct ClDebugFuncEntryT
270 {
275 
280 
286 
290 typedef struct ClDebugModEntryT {
291 
295  char modName[80];
296 
300  char modPrompt[20];
301 
306  char help[80];
308 
312 typedef ClPtrT ClDebugPrintHandleT;
313 
314 /*****************************************************************************
315  * Debug APIs
316  *****************************************************************************/
317 
340  CL_IN ClCharT *nprompt /*this string is incorporated into the debug CLI prompt*/);
341 
342 
367 
368 
369 
394 
420  ClRcT clDebugPromptSet(CL_IN const ClCharT *pCompPrompt);
421 
446  CL_IN ClUint32T funcArrayLen,
447  CL_OUT ClHandleT *phDebugReg);
448 
449 ClRcT clDebugRegisterConstBuf(CL_IN ClDebugFuncEntryT *funcArray,
450  CL_IN ClUint32T funcArrayLen,
451  CL_OUT ClHandleT *phDebugReg);
452 
453 
454 
479 ClRcT clDebugDeregister(CL_IN ClHandleT hReg);
480 
505 
506 
533  CL_IN const char* fmtStr,
534  ...) CL_PRINTF_FORMAT(2, 3);
535 
536 
563  CL_OUT char** buf);
564 
565 
589 
613 
614 ClRcT clDebugResponseSend(ClRmdResponseContextHandleT responseHandle,
615  ClBufferHandleT *pOutMsgHandle,
616  ClCharT *respBuffer,
617  ClRcT retCode);
618 ClRcT clDebugResponseDefer(ClRmdResponseContextHandleT *pResponseHandle, ClBufferHandleT *pOutMsgHandle);
619 
620 ClRcT
621 clDebugPrintExtended(ClCharT **retstr, ClInt32T *maxBytes, ClInt32T *curBytes,
622  const ClCharT *format, ...) CL_PRINTF_FORMAT(4, 5);
623 
624 #ifdef __cplusplus
625 }
626 #endif
627 
628 #endif /* _CL_DEBUG_API_H_ */
629 
Typical defines found in any software project.
Header file of Debug Error Codes.
Header file of EO related APIs.
Header file of Log Service related APIs.
Header file of Handle Management related APIs.
ClPtrT ClBufferHandleT
The type of the handle for the buffer messages.
Definition: clBufferApi.h:82
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_INOUT
CL_INOUT macro assists in clearly defining arguments of an API, but has no actual meaning.
Definition: clCommon.h:108
#define CL_OUT
CL_OUT macro assists in clearly defining arguments of an API, but has no actual meaning.
Definition: clCommon.h:110
#define CL_IN
CL_IN macro assists in clearly defining arguments of an API, but has no actual meaning.
Definition: clCommon.h:106
struct ClDebugModEntryT ClDebugModEntryT
This structure is used to register the module with the CLI library.
#define CL_DEBUG_FUNC_HELP_LEN
The maximum length of the help for a command of the component in the debug CLI.
Definition: clDebugApi.h:242
ClRcT clDebugRegister(CL_IN ClDebugFuncEntryT *funcArray, CL_IN ClUint32T funcArrayLen, CL_OUT ClHandleT *phDebugReg)
Registers the component name.
ClRcT clDebugPrint(CL_INOUT ClDebugPrintHandleT msg, CL_IN const char *fmtStr,...) CL_PRINTF_FORMAT(2
Prints a string into the handle.
ClRcT clDebugLibFinalize(void)
Finalizes the Debug CLI library.
ClRcT clDebugCli(CL_IN ClCharT *nprompt)
Invokes the library based local debug CLI.
ClRcT clDebugDeregister(CL_IN ClHandleT hReg)
De-registers the debug CLI information from the EO.
ClRcT clDebugPrintInitialize(CL_OUT ClDebugPrintHandleT *msg)
Retrieve a handle for printing.
ClRcT clDebugPrintDestroy(CL_INOUT ClDebugPrintHandleT *msg)
Frees the print handle.
ClRcT clDebugPromptSet(CL_IN const ClCharT *pCompPrompt)
Sets the name and prompt of the component.
#define CL_DEBUG_FUNC_NAME_LEN
The maximum length of a command of the component in the debug CLI.
Definition: clDebugApi.h:237
ClRcT(* ClDebugCallbackT)(ClUint32T argc, ClCharT **argv, ClCharT **ret)
This is the signature of the callback invoked by the debug CLI in response to a command entered.
Definition: clDebugApi.h:249
ClRcT ClRcT clDebugPrintFinalize(CL_IN ClDebugPrintHandleT *msg, CL_OUT char **buf)
Cleans up the print handle.
struct ClDebugFuncEntryT ClDebugFuncEntryT
The structure contains the entry for the debug CLI information that needs the component has to provid...
ClRcT clDebugVersionCheck(CL_INOUT ClVersionT *pVersion)
Check the given version is supported or not.
ClPtrT ClDebugPrintHandleT
The type of the handle clDebugPrint APIs.
Definition: clDebugApi.h:312
ClRcT clDebugLibInitialize(void)
Initializes the Debug CLI library.
Version Information for various services.
Definition: clCommon.h:250
The structure contains the entry for the debug CLI information that needs the component has to provid...
Definition: clDebugApi.h:270
ClCharT funcName[CL_DEBUG_FUNC_NAME_LEN]
Name of the command used while invoking the command.
Definition: clDebugApi.h:279
ClDebugCallbackT fpCallback
Function to be invoked upon a command entered on the CLI.
Definition: clDebugApi.h:274
ClCharT funcHelp[CL_DEBUG_FUNC_HELP_LEN]
One line help for the command.
Definition: clDebugApi.h:284
This structure is used to register the module with the CLI library.
Definition: clDebugApi.h:290
char modName[80]
Module name.
Definition: clDebugApi.h:295
char modPrompt[20]
Module prompt.
Definition: clDebugApi.h:300
ClDebugFuncEntryT * cmdList
List of commands and their functions.
Definition: clDebugApi.h:305

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen