Automatic Log-based tool for locating code defects

Source: Internet
Author: User
Automatic Log-based tool for locating code defects

A log-based tool for Software Fault Locating

 

Wang Shuyun

Wangshudian # gmail.com, 2011-4-2

 

Keywords:State machine; log analysis; code defects

 

1 Introduction

 

Lazarus is always needed to eat and drink, and Bug Locating is always required for software. There are many ways to locate the problem, one of which is to analyze system logs. Log Analysis usually relies on manual reading to track the change process to find the root cause of the problem. The log information is usually large, which is time-consuming and labor-consuming for analysis. This article draws on the idea of [1] to develop a small tool that automatically locates code defects based on the status conversion table for log analysis.

 

 

2. Function Description

Analyzes event logs based on user-defined state conversion rules, checks whether abnormal state conversion exists during the program running, and outputs fault alarms.

 

 

3. tool usage 3.1 Step 1: object and Status Analysis

(1) determine the check object

(2) determine the object state machine

(3) edit the object state transition configuration file

Example:

[Stateset] <br/> S0 = state0 <br/> S1 = state1 <br/> S2 = state2 </P> <p> [initstate] <br/> S0 </P> <p> [endstate] <br/> S0 </P> <p> [eventset] <br/> e0 = event0 <br/> e1 = event1 <br /> E2 = event2 <br/> E3 = event3 </P> <p> [predictionset] <br/> S-1 = "error: info1... "<br/> S-2 =" error: info2... "<br/> S-3 =" error: info3... "<br/> S-4 =" error: info4... "<br/> S-5 =" error: info5... "<br/> S-6 =" error: info6... "<br/> S-7 =" error: info7... "<br/> S-8 =" error: info8: not expected endstate "</P> <p> [Transition] <br/> from = S0, on = E0, to = S1 <br/> from = S0, on = e1, To = S-1 <br/> from = S0, on = e2, to = S-2 <br/> from = S0, on = E3, To = S-3 <br/> from = S1, on = E0, to = S-4 <br/> from = S1, on = e1, To = S2 <br/> from = S1, on = e2, to = S-5 <br/> from = S1, on = E3, To = S0 <br/> from = S2, on = E0, to = S-6 <br/> from = S2, on = e1, To = S-7 <br/> from = S2, on = e2, to = S1 <br/> from = S2, on = E3, To = S0 <br/>

 

3.2 Step 2: Record Event Logs

 

 

 

Because the log formats of different product codes vary, the parsing format of this tool is as follows:

 

File: file name, line: row number, SM: Object Name, objid: Object ID, event: Event

 

Note: The constraint object name in this tool must be consistent with the INI file name in the first step.

 

You can refer to the following solutions to record logs:

 

Solution 1: Hook method. This method is applicable when the original code is not moved.

Solution 2: macro-style.

 

Example:

 File: Example. CPP, line: 40, SM: statemachine_example, objid: 0x477e22, event: event0 <br/> file: Example. CPP, line: 40, SM: statemachine_example, objid: 0x477e22, event: event1 <br/> file: Example. CPP, line: 40, SM: statemachine_example, objid: 0x477e22, event: event1 <br/>

3.3 Step 3: run the analysis tool

You can directly click logfat.exeto run logfile.txt and reportfile.txt.

You can also execute the command line and specify the log file name and output report name.

 

3.4 Step 4: view the analysis results

Open reportfile.txt.

Example:

 . /Gtest_logfileanalysistool.cpp (40): exception 7: (error: info7 ...) <br/>. /gtest_logfileanalysistool.cpp (40): exception 8: (error: info8: not expected endstate) <br/>

 

 

References

[1] James H. Andrews, Theory and Practice of Log File Analysis, 1998

 

 

Note:

 

The csdn blog does not seem to be able to upload attachments. I put the demo version of this tool into my released download resources. Link:

 

Http://download.csdn.net/source/3155673

 

Welcome to feedback on improvement suggestions :)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.