Summary of the invention
It is excessive to the objective of the invention is to overcome in the prior art orientation range to errors present, is unfavorable for the shortcoming that location of mistake realizes, a kind of method that mistake in the compiler is located automatically is provided, and realizes searching fast and automatically the compiler mistake.
To achieve these goals, the invention provides a kind of method that mistake in the compiler is located automatically, may further comprise the steps:
1), utilize the source file of compiler compiling application program, the file destination of the program that is applied, resulting all file destinations are formed file destinations set;
2), file destination set that step 1) is obtained, utilize dichotomy and method of substitution location to realize location to the false target file in the file destination set;
3), to step 2) the resulting file destination of makeing mistakes, utilize the optimization switch option of the function that compiler provides, in conjunction with dichotomy, the alignment error function;
4), the optimization option switches of from the resulting function of makeing mistakes of step 3), utilizing compiler to provide, in conjunction with dichotomy, the location may cause the wrong optimizing phase, reduces the seek scope of wrong region, the optimization option that optimizing phase that is led to errors at first and compiler lead to errors.
In the technique scheme, in the described step 1), do compiling with the source file of correct compiler and compiler application programs to be detected respectively during the source file of compiler compiling application program, obtain file destination set separately, the set of correct compiler compiling gained file destination is designated as correct file set, compiler compiling gained file destination to be detected set is designated as the wrong file set.
In the technique scheme, described step 2) in, described dichotomy and the method for substitution of utilizing realized location to the false target file specifically comprising:
Set is placed under the different catalogues with wrong file for 2-1, correct file set that step 1) is obtained;
2-2, in each file set, the initial survey scope of file is set, file is sorted according to letter, the value of the minimum point of the scope of investigation is set to 1, corresponding to first file, the value of peak is set to total number of file in this document set, corresponding to last file, the intermediate value of minimum point and peak is set to the value of intermediate point, the file in the middle of corresponding minimum point and the peak;
2-3, judge that whether the value of minimum point is less than the value of peak and 1 difference, if Rule of judgment is false, then alternative document in the file of minimum point representative in the wrong file set and the correct file set is linked and moves, if operation result mistake, then the minimum point file is exactly the wrong file of asking, if operation result is correct, then the peak file is finished the wrong file position fixing process by asking wrong file; If Rule of judgment is set up, to be linked into object code to the file destination between peak behind the intermediate point in file destination between minimum point and the intermediate point in the wrong file set and the correct file set, observe operation result, if operation result is correct, change step 2-4 over to, if the operation result mistake changes step 2-5 over to;
2-4, reset the value of minimum point, the value of former intermediate point is composed to minimum point, and recomputate the value of intermediate point, according to step 2-3 the file between minimum point and peak is judged again then according to the value of the value of peak and new minimum point;
2-5, reset the value of peak, the value of former intermediate point is composed to peak, and recomputate the value of intermediate point, according to step 2-3 the file between minimum point and peak is judged again then according to the value of the value of minimum point and new peak.
In the technique scheme, in the described step 3), the described optimization switch option of utilizing the function that compiler provides, in conjunction with dichotomy, the alignment error function specifically comprises:
3-1, to step 2) resulting error file, set the initial survey scope of function, the order of all functions in the file according to compiling sorted, the value of investigating the minimum point of scope is made as 1, corresponding to the 1st function, the value of peak is identical with function number in this error file, corresponding to last function, the value of intermediate point is set to the intermediate value of highs and lows, corresponding to the function in the middle of peak and the minimum point;
3-2, judge that whether the value of minimum point is less than the value of peak and 1 difference, if Rule of judgment is false, then open the optimization switch of minimum point function, close the optimization switch of its complementary function simultaneously, move the file destination at function place then, if mistake appears in operation, then the function of minimum point is exactly the error functions of asking, if operation is correct, then the function of peak is withdrawed from the position fixing process of error functions by asking error functions; If Rule of judgment is set up, then open the optimization switch of minimum point to function between intermediate point, close behind the error file intermediate point optimization switch of function between peak, again compile, and the file that compiling is come out is linked into object code again, whether the operation result of object observing code is correct, if correctly change step 3-3 over to, otherwise forwards step 3-4 to;
3-3, reset the value of minimum point, the value of former intermediate point is composed to minimum point, and recomputate the value of intermediate point, according to step 2-3 the file between minimum point and peak is judged again then according to the value of the value of peak and new minimum point;
3-4, reset the value of peak, the value of former intermediate point is composed to peak, and recomputate the value of intermediate point, according to step 2-3 the file between minimum point and peak is judged again then according to the value of the value of minimum point and new peak.
In the technique scheme, in the described step 4), the described optimization option switches of utilizing compiler to provide in conjunction with dichotomy, is searched the optimizing phase and the relevant option of optimizing that lead to errors at first and is made up, and specifically comprises:
4-1, the optimizing phase of a certain appointment is checked, closed the optimization option in this optimizing phase one by one,, think that then the optimizing phase of this appointment is the optimizing phase that leads to errors at first when certain Push And Release of optimizing option wherein causes run-time error;
4-2, setting option list file include the Compiler Optimization option that will do switching manipulation in this document;
4-3, will be after the content resolution of the every line command in the option list file deposit in the corresponding array, generate the option Assembly Listing by class;
4-4, utilize the optimization option of the difference control granularity in the option Assembly Listing that function is investigated;
4-5, according to the result who investigates, obtain one and optimize the option combination, described optimization option combination is the set of the optimization option that possible lead to errors.
Among the described step 4-3, described with after the content resolution of the every line command in the option list file by class deposit in corresponding array be meant with the content in the option list file by optimizing phase title, optimization of region gauge tap, fundamental block optimize switch, instruction optimal control switch deposits in the array.
Among the described step 4-4, described control granularity comprises zone, fundamental block and instruction.
Among the described step 4-4, the described optimization option that utilizes the zones of different control granularity in the option Assembly Listing is investigated function and is meant by the order of zone, fundamental block, instruction and respectively the function zone of makeing mistakes is investigated, and each investigation all is based on the basis of last time investigating the gained option, forms new investigation option by increasing new control granularity option.
The invention has the advantages that:
1, by the method that the mistake in the compiler is located automatically of the present invention, can realize the quick location of the initial error phase in the file destination and searching fast of wrong optimization option, help the realization of technician, reduced the shared time of analyzing subsequent analysis work.
2, the present invention has good modularity, can be applied in the automatic test course at large software, in the process of performance test or correctness test, need not manual intervention, directly the software that run-time error occurs is analyzed timely, improve testing efficiency, save test and analysis time.
Embodiment
With reference to the accompanying drawings and embodiment, method of the present invention is elaborated.
The method that mistake in the compiler is located automatically of the present invention has realized producing when testing employed large-scale application program operation the make mistakes quick location in stage of wrong Error Location and compiler, as shown in Figure 1, comprising:
1) file destination of makeing mistakes in the position-location application.This step is will realize when passing through the application program generation run-time error of compiling the file that makes a mistake being positioned.
Before the location, prepare two catalogues, one is used for depositing correct file destination set, and another is used for depositing wrong file destination set.Here said correct file destination set is that application program uses known correct compiler version and correct optimization option to compile the resulting file destination set in back, and the file destination set of mistake is to utilize current compiler to be detected and optimize option to compile the resulting file destination set that makes mistakes.
Integrated use dichotomy and method of substitution when the location, with the file destination in the wrong file set file destination of the same name in the correct file set is substituted and moves successively, if a certain file destination in the wrong file set to the file of the same name in the correct file set do substitute after, file destination operation in the correct file set makes a mistake, and then this file destination in the wrong file set comprises mistake.
In the present embodiment, the concrete operations of localizing objects file can be undertaken by document alignment function locate_file, and its execution in step comprises as shown in Figure 2:
Step 10, compile with the source file of correct compiler version application programs, obtain correct file destination set, source file with compiler application programs to be detected compiles, and obtains wrong file destination set, and two file sets are placed on respectively under separately the catalogue;
Step 11, because correct file set and wrong file set are to obtain after the compiler compiling of source file through different editions by identical application software, the number of the file destination in therefore correct file set and the wrong file set is identical, and corresponding one by one.In two file sets, establishing the file number respectively is N, sets initial survey scope point [low, high], and the initial value of low is 1, and the initial value of high is N, intermediate point mid is set is (high+low)/2.
Step 12, judge low value whether less than the value of high-1, if Rule of judgment is false, then alternative document in the file of low representative in the wrong file set and the correct file set is linked and moves, if run-time error, then the file of low representative is by being asked wrong file, if operation is correct, then the file of high representative is by being asked wrong file, obtain withdrawing from current function locate_file, end operation behind institute's wrong file of asking; Otherwise according to dichotomy, [mid+1, high] set in [low, mid] part in the wrong file set and the correct file is linked into object code, observes operation result, if correctly change step 13 over to, if mistake changes step 14 over to.
Step 13, reset the value of low, its value is set to mid, and recomputates mid according to formula (high+low)/2, changes over to then in the step 12 file between [low, high] is investigated.
Step 14, reset the value of high, its value is set to mid, and recomputates mid according to formula (high+low)/2, changes over to then in the step 12 file between [low, high] is investigated.
In the wrong file set, more than one of the file destination possibility that makes a mistake utilizes dichotomy and method of substitution once can only find an error file.Dichotomy and method of substitution are used the location one by one that can realize the file destination of makeing mistakes repeatedly.
2) alignment error function.After determining error file, in most of the cases still can't determine where be the position of makeing mistakes, therefore also need to dwindle the regional scope of makeing mistakes, just will search the function of makeing mistakes.
The make mistakes location of function is to utilize the optimization switch option of the function that compiler provides to realize carry out switch by whether some function being done optimize, and the zone that will make mistakes narrows down to a function from a file, and analytical work is contracted in the function body.Also will use dichotomy in the process of alignment error function, the optimization switch option to function of utilizing compiler to provide simultaneously positions, and has increased repeatedly compilation process.The option that function is optimized switch that compiler provides comprises: the function of specified scope is closed middle-end and the rear end is optimized and the function of specified scope is closed the rear end optimize two kinds.In position fixing process, middle-end and rear end are optimized the option of controlling simultaneously as long as use, it comprises: close optimization (Wb from function n,-OPT:skip_a=n), begin to be optimized (Wb from function n,-OPT:skip_b=n), to function n close optimization (Wb ,-OPT:skip_e=n) wait three kinds.
In the present embodiment, can realize by mapping function locate_PU the position fixing process of the function of makeing mistakes.The concrete operations of locate_PU function comprise:
The error file that step 20, setting position obtain has N function, and setting initial survey scope point is [low, high], and the initial value of low is 1, and the initial value of high is N, intermediate point mid is set is (high+low)/2.
Step 21, judge low value whether less than the value of high-1, if Rule of judgment is false, then open the optimization switch of low representative function, close other function optimization switches, operation this document, if run-time error, then the function of low representative is exactly the error functions of asking, if operation is correct, then the function of high representative is exactly the error functions of asking, withdraw from current function locate_PU, otherwise press dichotomy, open the optimization of [low, mid] partial function, close the optimization of [mid+1, high] partial function.The file that compiling is come out is linked into object code again, and whether observe operation result correct, if correctly then change step 22 over to, if mistake then changes step 23 over to.
Step 22, reset the value of low, its value is set to mid, and recomputates mid according to formula (high+low)/2, changes step 21 then over to, and the function between [low, high] is investigated.
Step 23, reset the value of high, its value is set to mid, and recomputates mid according to formula (high+low)/2, changes step 21 then over to, and the function between [low, high] is investigated.
The optimization switch option of function has three kinds, and the locate_PU function is repeatedly called, and selects different optimization switch option at every turn for use when calling, thereby locates errors function.
3) the wrong optimizing phase of location.
At the function of makeing mistakes, the various optimization option switches that can utilize compiler to provide are carried out the trial of various optimal combinations to this function.These combination options comprise the multiple optimizing phase option of middle-end and rear end, as loop nesting optimization, control flow-optimized, instruction scheduling etc.The multiple optimization option that provides in the compiler is closed one by one,, just think that the optimizing phase of option correspondence is the optimizing phase that leads to errors at first when certain Push And Release of optimizing option has caused run-time error.Corresponding one or more optimization options of optimizing phase, optimizing option for one can exert an influence to the specific optimizing phase, therefore, found the optimization option of makeing mistakes also just can find the optimizing phase that leads to errors at first.
Because the result of the normally multiple optimization option of run-time error combined action, the optimizing phase that leads to errors at first might not be exactly the reason that finally leads to errors, therefore also need further to analyze, analyze the control granularity that can deeply then depend on the optimization option of this kind optimizing phase correspondence.In the method, can specify the optimizing phase of a needs inspection, judge whether it is the stage that leads to errors at first, thereby simplifying aspect the compile option location by the user.Perhaps, the object that the option combination conduct of directly using function and option file to provide is further investigated, the switch that the zone of control in the particle size range is optimized by dichotomy, when whether the optimization in certain piece zone has determined that operation is whether correct, just can be with the object of this zone as further investigation.Different options can be selected different control granularities is optimized, and the control granularity is divided into function, control stream zone, fundamental block, instruction.Can the control granularity of option have determined continue the zone of makeing mistakes is dwindled, and then reduce the workload of back manual analysis.If the control granularity of an option is fundamental block or instruction, then finally can will make mistakes region limits within fundamental block, on the contrary,, then be difficult to the zone of makeing mistakes is further dwindled if one is optimized option and is merely able to control function.This part work mainly realizes that by calling the locate_area function concrete steps comprise:
Step 30, the optimizing phase of appointment is checked, close the option of these optimizing phase correspondences one by one, when certain Push And Release of optimizing option has caused run-time error, just think that the optimizing phase of its correspondence is the optimizing phase that leads to errors at first, thereby determine initial error phase.
Step 31, setting option list file, include the Compiler Optimization option that will do switching manipulation in the option list file, each row in the option list file comprises that optimizing phase title, optimizing phase gauge tap, optimization of region gauge tap, fundamental block are optimized switch, the respective options such as switch are optimized in instruction.
Step 32, to the content in the option list file according to optimizing phase title (phase_name), optimizing phase gauge tap (id), optimization of region gauge tap (rg_flag), fundamental block is optimized switch (bb_flag), instruction is optimized switch (op_flag) and is resolved, and with optimizing phase title, optimization of region gauge tap, fundamental block optimize switch, instruction optimal control switch deposits array phase_array, rg_flag_array, bb_flag_array, op_flag_array respectively in, generates the option Assembly Listing.
The initial error phase of the error functions that step 33, the error functions that mapping function is obtained or step 30 obtain utilizes the option Assembly Listing further to handle as investigating object.For example,, find that controlling flow-optimized is the optimizing phase that leads to errors at first in the function, then in this step, will control the flow-optimized residing optimizing phase as investigating object if in step 30.
Step 34, to the determined investigation object of step 33, determine the control granularity of current investigation according to the array in the option Assembly Listing that produces in the step 32, described control granularity is respectively zone, fundamental block, instruction etc.The optimization option that utilizes the difference control granularity in the option Assembly Listing is investigated function and is meant by the order of zone, fundamental block, instruction and respectively the function zone of makeing mistakes is investigated, and each investigation all is based on the basis of last time investigating the gained option, forms new investigation option by increasing new control granularity option.The concrete operations step is as follows.
A: when the control granularity is zone (Region), need call the option combination that area_option (" rg ") produces the zone.Wherein, parameter " rg " represent that the scope of checking at present is unit with the zone.The area_option function can with in the option array in option switches that should the stage and the option the option of the control in zone being added to come in, thereby realize the optimization range in the zone under certain option control is checked.With a specific embodiment is example, the order behavior of using in compiler :], it comprises two parts, is respectively option names part and assignment part before and after the equal sign.Wherein, $rg_flag_array is whole option array, $rg_flag_array[$n] be used for specifying certain to control option names, $skip_flag be used for specifying be used in this option the suboption-name of control area scope and respectively specified function sequence number and specify the regional sequence number be optimized switch.As " Wb ;-SKIP:glos_skip_rgn_a=fullGtU:4 ", the option names of this option is-Wb,-SKIP:glos_skip_rgn_a, the optimization of expression global command scheduling part (glos), skip and a among the glos_skip_rgn_a (expression after) the global command optimizing scheduling that the back, appointed area is closed in expression, the appointed area here is exactly the 4th zone among the function f ullGtU.
B: when the granularity of investigating is fundamental block, call the option combination that area_option (" bb ") produces fundamental block.Wherein, the present scope of checking of parameter " bb " expression is unit with the fundamental block.The effect of function area_option and aforesaid area_option function are similar, also be will with in the array in option switches that should the stage and the option the option of the control of fundamental block being added to come in, the optimization range of fundamental block is controlled.In a specific embodiment, Ming Linghang $bb_flag_array[$n] $skip_flag=$pu_num%$skip_num is added compile option.Wherein, $bb_flag_array[$n] be used for the control option of fundamental block of specified phases correspondence, $skip_flag be used for specifying be used to control the option of fundamental block scope and respectively specified function sequence number and specify the regional sequence number that is optimized switch.As order line " Wb ;-SKIP:locs_skip_bb_e=fullGtU:3 ", the option names of this option is-Wb,-SKIP:locs_skip_bb_e, the optimizing phase of its expression is the local instruction scheduling optimizing phase (locs), wherein bb represents that the base unit of optimizing is a fundamental block, and the local instruction scheduling optimization of the fundamental block of appointment is closed in skip and e (expression equal) expression, and the appointment fundamental block here is the 3rd fundamental block in the fullGtU function.
C: when the granularity of investigating is instruction, call the option combination that area_option (" op ") produces instruction.Wherein, the present scope of checking of parameter " op " expression is unit with the instruction.The effect of function area_option and aforesaid area_option function are similar, but must add optimal control to fundamental block simultaneously to the inspection of range of instructions, and promptly must specify is the inspection of instructing in which scope.If in the option array that the user provides, do not specify certain fundamental block for investigating object (promptly comprising-the bb option) without any option, the fundamental block that then needs to find among the step b is as specifying fundamental block, $bb_flag_array[$n] $AFTER=$find_bb and $op_flag_array[$n] $skip_flag=$pu_num%$skip_num are added compile option, this group option is made up of two parts, a preceding part is used to refer to decides fundamental block, and a back part has then been specified range of instructions to be looked into.If in the option array that the user provides, specified the fundamental block that needs investigation, then can in fundamental block, specify a certain section investigation scope, the relevant optimization Close All that other fundamental blocks are excellent, as " $bb_flag_array[$n] $AFTER=$find_bb and $bb_flag_array[$n] $BEFORE=$find_bb$op_flag_array[$n] $skip_flag=$pu_num%$skip_num; herein, close the optimization of specifying fundamental block front and back scope with $AFTER and $BEFORE respectively.$op_flag_array[$n] be used for specifying range of instructions is carried out the option that switch is controlled.
After step 35, a by above-mentioned, b, c produce the corresponding option result, can determine the optimization option combination that leads to errors.
The error range of application program can be dwindled by the method for the invention, and provide an option combination, it all is the optimization option that possible lead to errors that each in this option combination optimized option.Person skilled is according to the resulting result of the method for the invention, directly the fault domain and the option of application programs are analyzed, seek the final reason that leads to errors of compiler, also just can find the mistake of compiler itself, thereby save the time that a large amount of mechanization analytic processes take.