Translate

Chủ Nhật, 4 tháng 12, 2016

Debug and Log system

Created by Clark

1. What is debugging technique
- Debug is a work that eliminate all mistakes in a program to the program works in whatever situation. Usually, fixing a bug requires us to know the reasons it appears

- In common, there are three techniques for finding bugs:
+ Using printf or cout statements
+ Including command lines debug switch (using MACROs)
+ Using a debugger (ex: gdb, ..)

2. Logger in HG700
a. User space API
User space defines 4 levels of log severity (debug, information, error, critical). The macros are:
- LOGF_LOG_CRITICAL(...)
- LOGF_LOG_ERROR(...)
- LOGF_LOG_INFO(...)
- LOG_LOG_DEBUG(...)
One additional macro, LOGF_LOG, is available for developer debugging. Should a developer require a record to be logged beyond any of the proposed levels, this could be used.

Note: To use logging API, modules must include “ulogging.h” in C files and add the following code to global section (in any one of the C files)
?
1
2
3
4
5
6
7
8
9
10
11
12
//#define BENCHMARK
#ifndef LOG_LEVEL
uint16_t LOGLEVEL = SYS_LOG_DEBUG + 1;
#else
uint16_t LOGLEVEL = LOG_LEVEL + 1;
#endif
#else
 
#ifndef LOG_TYPE
uint16_t LOGTYPE = SYS_LOG_TYPE_FILE;
#endif
uint16_t LOGTYPE = LOG_TYPE;
b. Kernel space API
The kernel log API provide a way for the kernel modules to record their logging messages (to a file, show log in a terminal, ...). Refer the API’s provided through the header file “klogging.h” added by kernel patch

c. Usage examples:
Putting log messages
?
1
LOGF_LOG_DEBUG(“Logginf messages\n”);
Putting log messages with integer and string
?
1
LOGF_LOG_DEBUG(“Logging messages, int_var: %d, string_var: %s\n”, int_var, string_var);
(Changing SL Log Level and Type at Run-time)
Modify and print specific Log level(7) and Log type(2)
      slloglevel sl_network 7 2

Modify and print all SL log level and Log type
      slloglevel all 7 2
      slloglevel print all

Note: Log level values [0 .. 7]
          Log type values [0 .. 3]
          Log type 0 -> None, 1 -> File, 2 -> Console, 3 -> File & Console)
d. Guidelines for Log Level Usage
  • DEBUG level includes ALL messages from the module. This is not enabled in normal image. If a problem occurs on the image and you want to debug, this mode can be enabled. Dumping the complete contents of posts, objects list, parameters list are good candidates.
  • INFO level indicates informational messages to the user to know state of the box. Like csd has started, servd started. Service library is initialized successfully. DSL is up. WAN PPPoE is up
  • CRITICAL within a module, shows either module can not start (SL initialization can not be done, a dependent component is missing, a configuration file missing, module is exiting) or can not proceed in abnormal conditions (no memory available)
  • ERROR level is nay other message which does not fit the above three and throws up error conditions in the box
e. Library: ulogging.h , syslog.h
The C library of Intel framework
Define Log level and log type
?
1
2
3
4
5
6
7
8
9
10
11
12
13
//#define SYS_LOG_EMERG     LOG_EMERG
//#define SYS_LOG_ALERT     LOG_ALERT
#define SYS_LOG_CRIT      LOG_CRIT     /*!< critical level   */
#define SYS_LOG_ERR       LOG_ERR    /*!< error level   */
//#define SYS_LOG_WARNING   LOG_WARNING
//#define SYS_LOG_NOTICE    LOG_NOTICE
#define SYS_LOG_INFO      LOG_INFO     /*!< info level   */
#define SYS_LOG_DEBUG     LOG_DEBUG    /*!< debug level   */
 
#define SYS_LOG_TYPE_NONE               0    /*!< log type  */
#define SYS_LOG_TYPE_FILE             (1 << 0)   /*!< log type file  */
#define SYS_LOG_TYPE_CONSOLE          (1 << 1)   /*!< log type console    */
#define SYS_LOG_TYPE_FILE_AND_CONSOLE (SYS_LOG_TYPE_FILE | SYS_LOG_TYPE_CONSOLE)    /*!< log type both console and file    */
LOG Macro function
?
1
2
3
4
5
6
7
8
9
10
11
/* PACKAGE_ID will be provided by relevant package make file.  */
#define LOGF_LOG_ERROR(args...)       PRINTF(ERR, ##args);   /*!< macro to define error level  */
#define LOGF_LOG_EMERG(args...)       PRINTF(EMERG, ##args)   /*!< macro to define emergency level  */
#define LOGF_LOG_ALERT(args...)       PRINTF(ALERT, ##args)    /*!< macro to define alert level  */
#define LOGF_LOG_CRITICAL(args...)    PRINTF(CRIT, ##args)  /*!< macro to define critical level  */
#define LOGF_LOG_WARNING(args...)     PRINTF(WARNING, ##args)  /*!< macro to define warnning  level  */
#define LOGF_LOG_NOTICE(args...)     PRINTF(NOTICE, ##args)  /*!< macro to define notice level  */
#define LOGF_LOG_INFO(args...)      PRINTF(INFO, ##args)  /*!< macro to define info level  */
#define LOGF_LOG_DEBUG(args...)       PRINTF(DEBUG, ##args)   /*!< macro to define debug level  */
#define LOGF_LOG(LEVEL, fmt, args...) SYSLOG_##LEVEL(PACKAGE_ID"{%s, %d}:"fmt, __func__, __LINE__, ##args) /*!< PRINTF Macro */
#define PRINTF(LEVEL, fmt, args...)   SYSLOG_##LEVEL(PACKAGE_ID"{%s, %d}:"fmt, __func__, __LINE__, ##args) /*!< PRINTF Macro */
The C library of Linux
Define priorities
?
1
2
3
4
5
6
7
8
#define LOG_EMERG 0 /* system is unusable */
#define LOG_ALERT 1 /* action must be taken immediately */
#define LOG_CRIT 2 /* critical conditions */
#define LOG_ERR  3 /* error conditions */
#define LOG_WARNING 4 /* warning conditions */
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */

And one C file that use debug and logging technique
cgi.c
Example using debug and logging
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (nRet == UGW_SUCCESS) {
   nRet = cgi_fileDownload(RESTORE);
   if (nRet == UGW_SUCCESS) {
    LOGF_LOG_INFO("Config file download completed !!\n");
   } else {
    LOGF_LOG_ERROR("Config file download failed !! nRet = %d\n", nRet);
    nDBRestore = 0;
    goto returnHandler;
   }
  } else {
   LOGF_LOG_ERROR("Config update Request Failed !! cal_set nRet = %d\n", nRet);
   nFirmwareUpgrade = 0;
   goto returnHandler;
  }

Không có nhận xét nào:

Đăng nhận xét