A kind of Fault Locating Method of program state
Technical field
The present invention relates to a kind of Fault Locating Method of program state.
Background of invention
Along with development of Communication Technique, the technology of data communications equipment is more and more advanced at present, and function makes that from strength to strength their system program is day by day huge and complicated.Therefore, in the system program running, tend to occur some abnormal conditions, but but very complicated to the location of abnormal conditions.At present, the location of program exception is used two kinds of methods usually, they are respectively:
1, utilizes simulator or real time operating system, adopt single step to follow the tracks of or the operation of breaking trace routine in program, determine whether program is moved normally.It is exactly that manual control program is carried out that single step is followed the tracks of, and every one step of execution all can be seen the situation etc. of the variable that situation, the situation of storehouse, each content of registers, the user of program are provided with from simulator or real time operating system, comes fault location with this.The method of breaking has been established breakpoint exactly in advance in program in program, the every execution of program once stops to the breakpoint place, can see the situation etc. of the variable that situation, the situation of storehouse, each content of registers, the user of program at that time are provided with equally from simulator or real time operating system, come fault location with this.When this method is used program development in the early stage and test, location to abnormal conditions is very effective, but owing to be not to move at full speed and at full capacity, the abnormal conditions that occur when moving in full speed and at full capacity often die and no longer reproduction slightly in wink, thereby being difficult to capture abnormal conditions, the program mal location efficiency during for the test of later development or finished product is not high.
2, utilize program stack to locate, this method needs the support of simulator or real time operating system equally, in memory, set up special-purpose stack area exactly, when program running, during the value of the variable that pointer, pointer to stack, each content of registers, the user of program is provided with is isobaric stacked.Occur when unusual in program, the content in the stack is checked in the operation of shut down procedure, comes fault location with this.This method program occur unusual after during very fast inspection stack area, can very fast fault location.But tend to occur this situation: program occur unusual after, or the monitor for a long time just discovery procedure occurred unusually, at this time storehouse become changed beyond recognition, be difficult to date back to abnormity point, also just very difficult fault location.
This shows, the various information in the logging program running that these two kinds of Fault Locating Methods commonly used can not be complete in the prior art, the abnormal conditions that occur when therefore moving in full speed and at full capacity for program are difficult to make fault location.
Summary of the invention
In view of this, main purpose of the present invention be to provide a kind of program at full speed, the running status of logging program under the full-load conditions, the parameter of calling, using and the parameter value that comprise program, and can be according to the method for the fault in the quick finder running of record result.
For achieving the above object, technical scheme of the present invention is such:
A kind of Fault Locating Method of program state is characterized by this method and comprises following step at least:
A, black box logging program that is used for logging program running status and fault location of design;
B, respectively the not maskable interrupt routine of system and can be by the subprogram of the system of system call respectively implant a black box logging program with rearmost end foremost;
C, black box logging program write down the running status of subprogram when the subprogram of system is called, generate the single-track link table of the record corresponding with subprogram, and are filled in the end to end belt chained list of the static storage area that sets in advance;
D, when the black box logging program reinitializes the output channel of system, output is used for the record result of fault location.
Wherein the maskable interrupt routine can not be set to the external condition triggering, for example regularly triggers or manual triggers.
The single-track link table of the described record of step c, its structure can be set to comprise at least gauge outfit, chained list content and table tail, and its chained list content has comprised variable name and the variate-value thereof that is provided with by the subroutine pointer of system call, stack pointer, content of registers and at least one user.
The structure of the belt chained list described in this method can be set to: comprise a belt chain table entry that is used for the single-track link table of record is inserted the chained list that goes in ring, single-track link table with record more than, the gauge outfit of the single-track link table of each record order successively links to each other, and the gauge outfit of the single-track link table of last record links to each other with the gauge outfit of the single-track link table of first record.
Steps d wherein can be after having triggered not the maskable interrupt routine, by being implanted in the output channel that the black box logging program of maskable interrupt routine not reinitializes system, finishes record result's output; Its record result can be the content of the single-track link table of all records of being filled into the chained list that goes in ring by the black box logging program or all the elements of system stack; This record is the result export with document form, after the record result output, empties belt chained list.
Black box logging program described in this method, every execution once generate a program state record, and can be filled in the chained list that goes in ring by the sequencing that generates, when belt chained list is filled, from program state recording start covering at first.
By such scheme as can be seen, key of the present invention is: the not maskable interrupt routine of system and each can be by the subprogram of system call add the black box logging program with rearmost end foremost, black box logging program logging program pointer in program running, stack pointer, stack content, each content of registers, the user is provided with the variable name that needs record and variate-value etc., by triggering not maskable interrupt routine, reinitialize the output channel of system by implantation black box logging program wherein, output record result, the monitor staff is according to exporting fault location as a result.
The Fault Locating Method of this program state provided by the present invention, realized program at full speed, the running status and the fault location fast of logging program under the oepration at full load condition, it has following characteristics and advantage:
1, the running status of the present invention program's logging program under program full speed, oepration at full load condition, therefore record accurately, in time.
2, it is end to end that belt chained list is arranged in dedicated memory of the present invention, can the non-volatile recording running state of programs.
3, the present invention program each can be by the subprogram of system call added the black box logging program with rearmost end foremost, make each subprogram be called once just can to generate two and call record, so just write down before this subroutine call and the situation after calling, when fault location, can very clearly see the front and back situation of subroutine call, make the monitor staff find the abnormity point of program very soon, therefore improved the efficient of program exception location, saved the development time.
4, the present invention program adds the black box logging program in systems soft ware, and the black box logging program is not controlled the hardware of system, does not therefore influence the normal operation of program substantially.
5, the present invention program can program at full speed, the running status of complete logging program under the oepration at full load condition, so the present invention program also can be used in the system test before the product export, the tester determines by the analytic record result whether product qualified.
Description of drawings
Fig. 1 is a black box recording processing schematic flow sheet.
Fig. 2 is the structure of the single-track link table of record.
Fig. 3 is the structural representation of the record chained list that goes in ring.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, by the following examples, and with reference to accompanying drawing, the present invention is described in more detail.
The function class that technical scheme of the present invention is finished is similar to the black box that is used for the record-setting flight state on the aircraft, so claim that the technology of the present invention is the black box recording technique, the program that title is used for the logging program running status is the black box logging program.A specific embodiment of the present invention is that it is applied in a kind of program mal location of router.Its concrete implementation content is such:
1, black box logging program of design, this program realizes following function:
When 1) moving in system, the running status of logging program, and will write down the result and insert the static storage area that sets in advance;
2) output channel of initialization system, output record result.
2, the memory block that is exclusively used in the stored program state is set,, half memory size of router after the expansion is still distributed to router use, later half capacity configuration is become the static storage area one times of router memory expansion, and end to end with the chain sheet form that goes in ring.
The dedicated memory that is used for stored record in the present embodiment is half of Installed System Memory.Big like this internal memory makes the recorded information of storage complete, enough is used to the abnormity point of the program that dates back to.Certainly, the capacity of dedicated memory needn't one be decided to be half of Installed System Memory, can be according to the actual conditions setting of system, as long as guarantee that the recorded information of storage is complete, the abnormity point that enough is used to the program that dates back to gets final product.
3, add the black box logging program that is used for the logging program state in the systems soft ware, in the not maskable interrupt routine of router, implant the black box logging program, be used for output record result; Each can by the subprogram of system call foremost and rearmost end, add the black box logging program, be used for the running status of logging program.
4, with the implantation of router the not maskable interrupt routine of black box logging program be arranged to manual triggering.Because router is in when in service, do not detect itself and whether be in malfunction, therefore need external condition to trigger, external condition triggers and comprises manual triggering, regularly triggers and external condition that other can cause that maskable interrupt routine triggers triggers.After finding fault, adopt manual trigger method the simplest, direct, so present embodiment has adopted manual triggering.Adopting the manual purpose that triggers is to guarantee that router data preservation under the situation of not power down is complete.Data also can be stored in the data mediums such as FLASH, like this, though guaranteed that data are not lost under the situation of power down, but data medium capacity such as FLASH are less usually and writing speed is slow, the data volume of record does not enough date back to abnormity point, and the situation of router generation powered-off fault seldom, and therefore, the present invention does not adopt data mediums such as FLASH to store data; Simultaneously, the manual triggering (perhaps regularly triggering) be the maskable interrupt routine not, can also guarantee in unit exception, and the program commentaries on classics flies or is under the endless loop state, and the black box logging program can correct execution.
5, when program compilation, to determine to carry out the black box logging program, the systems soft ware after the compiling is the systems soft ware of commissioning version.
6, router is installed the systems soft ware of commissioning version, when router moves, the black box logging program writes down the running status of each invoked subprogram, with the record result be filled in the end to end belt chained list of the static storage area that sets in advance, its process specifically:
Each can by the subprogram of system call foremost and rearmost end, added the black box logging program, its flow chart is referring to Fig. 1.As shown in Figure 1, elder generation's execution in step 101 was called the black box logging program when subprogram began to call, and execution in step 102 then, the runtime subroutine body, and execution in step 103 before subroutine call finishes is called the black box logging program.Before coming logging program to call with this and program pointer, stack pointer, content of registers, user after calling the variable name and the variate-value thereof of record are set.Since each can by the subprogram of system call all added the black box logging program with rearmost end foremost, therefore, each subprogram is called and once just carries out the black box logging program twice, also just generates the single-track link table of two records.Can be clearly seen that situation before and after the subroutine call from the single-track link table of these two records, can accelerate the speed of fault location.
The structure of the single-track link table of the record of present embodiment is referring to Fig. 2.210 " calling record 1 " are the gauge outfit of this chained list among Fig. 2,230 " NULL " are the table tail of chained list, other parts 220 are chained list contents, and the chained list content has comprised that individual 224 users of 221 program pointers, 222 stack pointers, 223 content of registers and n are provided with the variable name and the variate-value of record.The single-track link table of each record generates the back and is filled in the chained list that goes in ring by the sequencing that generates, and promptly is filled into the static storage area that sets in advance.
Go in ring list structure referring to Fig. 3.As shown in Figure 3, illustrate the gauge outfit of N single-track link table that writes down with N 210 " calling record " among the figure.The table tail of the single-track link table of every record of 230 among the figure " NULL " signal.220 chained list contents among the figure are the chained list content of the single-track link table of every record.As seen from Figure 3, the content of belt chained list is the single-track link table of each record, be about to every record single-track link table gauge outfit successively order link to each other, and the gauge outfit of the single-track link table of last record links to each other with the gauge outfit of the single-track link table of first record and becomes belt chained list.In addition, belt chained list also comprises one 300 belt chain table entry, and the single-track link table that is used for writing down is filled into the chained list that goes in ring.
The purpose of belt chained list is arranged in the static storage area, mainly is can work long hours for the black box logging program.Because some faults need long time integration just can show, but the capacity of internal memory is limited, as is designed to single-track link table record a period of time and will overflows, so be arranged to the chained list that goes in ring.Because the single-track link table of each record is filled in the chained list that goes in ring by the sequencing that generates, therefore when belt chain table record fills up,, can guarantee so up-to-date event is noted from recording start covering the earliest.
When 7, the monitor staff noted abnormalities, by the manual not maskable interrupt routine that triggers, implantation black box logging program wherein reinitialized the output channel of route system, output record result; The record result is the content of all single-track link tables of being filled into the chained list that goes in ring by the black box logging program or all the elements of system stack; What present embodiment was exported is the content of belt chained list, and this record is the result export with document form, after the record result output, empties belt chained list.
The monitor staff is according to the record fault location as a result in the file of output.
Present embodiment according to the data of record, has navigated to the abnormity point of program very soon in the unusual position fixing process of router program operation, saved the development time.
The present invention program's embodiment implements on router, but it not only limits the use of in router, on the more data communications equipment of other application communication agreement, can use as equipment such as Ethernet switches.
The present invention program has realized the running status and the quick fault location of logging program under program full speed, oepration at full load condition.Therefore, the present invention program is applicable to the huge and complicated data communications equipment of system program such as router, have the program recorded information complete, do not influence the normal operation and the high advantage of program exception location efficiency of program substantially.
More than lift preferred embodiment; the purpose, technical solutions and advantages of the present invention are further described; institute is understood that; the above only is preferred embodiment of the present invention; not in order to restriction the present invention; within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.