Embodiment
In order to make the object of the invention, technical scheme and advantage clearer, below in conjunction with accompanying drawing and embodiment, the present invention is further elaborated, for the ease of explanation, only show the part relevant with the embodiment of the invention.Should be appreciated that the specific embodiment that this place is described, only be used to explain the present invention, not in order to restriction the present invention.
The present invention moves said target program through in target program, writing soft interrupt number, judges whether the function in the said target program exists said soft interrupt number, if there is the execution stream of then exporting said function.Said execution stream has clearly write down function calling relationship, and can obtain all on-the-spot functions, can be fast, the logic of object observing program actual motion dynamically, reduced research and development of software and maintenance cost, and shortened the time of research and development of software and debugging.When compile source code, compiler generates in the said source code all functions by the stack frame information of compile time, and option is optimized in cancellation simultaneously; At this moment each function has and has only a sub fp, ip, #4 instruction; Through said sub fp, ip, #4 instruction will be instructed mov ip exactly; The machine code of sp is revised as soft interrupt number, and further the execution of output function is flowed exactly.The target program behind the soft interrupt number is revised in operation; Obtain the value of LR register; And obtain 24 bit data of the soft interrupt instruction of SWI in the said address as the address of data access through LR-4, if 24 bit data of being obtained are the soft interrupt number of being revised, then export the value of LR register; Otherwise, jump to the section start of the soft interrupt handling routine of system itself.Through the value of output LR register, can export the full content of R0-R14.In addition, the process of revising the soft interrupt number and the value of output LR register can be encapsulated as PC instrument and soft interrupt routine respectively, further increases work efficiency; And; In the program debug process, target program is in the actual motion state fully, does not influence the operation of soft interrupt routine.
Embodiment one
Fig. 1 is the process flow diagram that a kind of output function of the present invention is carried out first preferred embodiment of stream method.Described method may further comprise the steps:
S101, compile source code generates target program, revises said target program and writes soft interrupt number;
S102 moves said amended target program;
S103 judges whether the function in the said target program exists said soft interrupt number, if there is the execution stream of then exporting said function;
Said " compile source code generation target program " comprising: option is optimized in cancellation, and compile source code generates target program, generates in the said source code all functions by the stack frame information of compile time;
Said " generate in the said source code all functions by the stack frame information of compile time " is specially:
The value of ip register holds sp: mov ip, sp;
Value in the ip register subtracts 4 and is saved in the fp register: sub fp, ip, #4;
Said optimization option is the option parameter of comprising in the compiler-02 ,-01, band " 0 " such as-03.
Embodiment two
Fig. 2 is the process flow diagram that a kind of output function of the present invention is carried out second preferred embodiment of stream method.Described method may further comprise the steps:
S201, option is optimized in cancellation, and compile source code generates target program, and generates in the said source code all functions by the stack frame information of compile time;
Optimize option by compiler cancellation during compile source code, compile said source code and generate target program, and generate in the said source code all functions by the stack frame information of compile time;
S202 searches the binary data of " value in the ip register subtracts 4 and is saved in the fp register " instruction in the target program; Promptly search the sub fp in the target program, ip, the binary data of #4 instruction;
Cancellation is optimized under the situation of option, mov ip, and the sp instruction is article one instruction that compiler gets into each function, said sub fp, ip, #4 is specially for carrying out the initialized sufficient and necessary condition of function:
According to stack frame principle fp register be before function is handled, must preserve the sp register as frame at the bottom of;
Compiler can not be used for other purpose the usefulness of fp register as the stack address storage when function was carried out, and instruction promptly can not occur and deposit new value in for the sp register, otherwise will destroy stack frame standard;
So sub fp, ip, #4 represent to get into a new function and a sub fp, ip, #4 can only be arranged;
S203 is to the binary data that returns inquiry " value in the sp register is saved in the ip register " instruction; Promptly to returning inquiry mov ip, the binary data of sp instruction;
After finding the binary data of said " value in the ip register subtracts 4 and is saved in the fp register " instruction, to returning inquiry up to the binary data that finds " value of sp register is saved in the ip register " instruction; That is, find said sub fp, ip is behind the binary data of #4 instruction, to returning inquiry up to finding mov ip, the binary data of sp instruction;
S204 is revised as soft interrupt number with the corresponding machine code of said " value of sp register is saved in the ip register " instruction, is about to said mov ip, and sp instructs corresponding machine code to be revised as soft interrupt number;
Said soft interrupt number is for can not be by the employed value of system, 0xaaaaaa for example, and said machine code 0xefaaaaaa representes soft interrupt instruction swi 0xaaaaaa;
S205, the target program behind the soft interrupt number is revised in operation;
S206 judges whether the function in the said target program exists said soft interrupt number, if there is the execution stream of then exporting said function.
Embodiment three
Fig. 3 is the process flow diagram that a kind of output function of the present invention is carried out the 3rd preferred embodiment of stream method.Described method may further comprise the steps:
S301, option is optimized in cancellation, and compile source code generates target program, and generates in the said source code all functions by the stack frame information of compile time;
S302 searches the binary data of " value in the ip register subtracts 4 and is saved in the fp register " instruction in the target program; Promptly search the sub fp in the target program, ip, the binary data of #4 instruction;
S303 is to the binary data that returns inquiry " value in the sp register is saved in the ip register " instruction; Promptly to returning inquiry mov ip, the binary data of sp instruction;
S304 is revised as soft interrupt number with the corresponding machine code of said " value in the sp register is saved in the ip register " instruction, is about to said mov ip, and sp instructs corresponding machine code to be revised as soft interrupt number;
S305, the target program behind the soft interrupt number is revised in operation;
S306 obtains the value of LR register; Promptly obtain the currency of LR register;
Said LR register is one of CPU general-purpose register; The currency of LR register has been preserved the return address that gets into after soft interruption and soft Interrupt Process are accomplished; Specifically preserve automatically by CPU core hardware, the address of next bar instruction of carrying out when withdrawing from after just soft Interrupt Process is accomplished, for example:
Swi?0xaaaaaa
Mov?r0,r0(LR)
Next bar instruction that said command M ov r0, r0 (LR) carry out when just withdrawing from after accomplishing for soft Interrupt Process;
S307 with " value in the LR register the subtracts 4 " address as data access, obtains 24 bit data of the soft interrupt instruction of SWI in the said address; Be about to LR-4 obtains the soft interrupt instruction of SWI in the said address as the address of data access 24 bit data;
For example, said 24 bit data are low 24 of said machine code 0xefaaaaaa, i.e. 0xaaaaaa;
SWI (Software Interrupt, soft interruption) is the instruction that cpu instruction is concentrated;
The value of LR register is the address of next bar instruction of carrying out when withdrawing from after soft Interrupt Process is accomplished, the address when LR-4 is exactly the soft interrupt instruction of current executed so;
S308 judges whether 24 bit data of being obtained are soft interrupt number, if not, then get into step S309, if then get into step S310;
If represent that then 24 bit data of being obtained are amended soft interrupt number;
If, do not represent that then 24 bit data of being obtained are the existing soft interrupt instruction of system;
S309 jumps to the section start of the soft interrupt handling routine of system itself;
S310, the value of output LR register;
Export the address of next bar instruction of carrying out when withdrawing from after soft Interrupt Process is accomplished, promptly export the execution stream of current function;
The value of the LR register of being exported can be used to draw function call tree etc., thereby image is expressed the call relation between the function in the program;
S311 is saved in the ip register with the value in the sp register; The mov ip that promptly executes instruction, sp;
S312 turns back to and continues to carry out current function on the value of LR register;
Finish soft Interrupt Process, turn back on the address of next bar instruction of carrying out when withdrawing from after soft Interrupt Process is accomplished and continue to carry out current function.
The further optimization of such scheme is that the process of said " revise said target program and write soft interrupt number " is encapsulated as the PC instrument, revises said target program and writes soft interrupt number through said PC instrument.
Said PC instrument is the application program that develops under the VC IDE, is used to revise the binary object file that compiler generates, and writes soft interrupt number.
The further optimization of such scheme is; The process of said " judging whether the function in the said target program exists said soft interrupt number; if there is the execution stream of then exporting said function " is encapsulated as soft interrupt routine, carries out stream through carrying out said soft interrupt routine output function.
The present invention moves said target program through in target program, writing soft interrupt number, judges whether the function in the said target program exists said soft interrupt number, if there is the execution stream of then exporting said function.Said execution stream has clearly write down function calling relationship, and can obtain all on-the-spot functions, can be fast, the logic of object observing program actual motion dynamically, reduced research and development of software and maintenance cost, and shortened the time of research and development of software and debugging.When compile source code, compiler generates in the said source code all functions by the stack frame information of compile time, and option is optimized in cancellation simultaneously; At this moment each function has and has only a sub fp, ip, #4 instruction; Through said sub fp, ip, #4 instruction will be instructed mov ip exactly; The machine code of sp is revised as soft interrupt number, and further the execution of output function is flowed exactly.The target program behind the soft interrupt number is revised in operation; Obtain the value of LR register; And obtain 24 bit data of the soft interrupt instruction of SWI in the said address as the address of data access through LR-4, if 24 bit data of being obtained are the soft interrupt number of being revised, then export the value of LR register; Otherwise, jump to the section start of the soft interrupt handling routine of system itself.Through the value of output LR register, can export the full content of R0-R14.In addition, the process of revising the soft interrupt number and the value of output LR register can be encapsulated as PC instrument and soft interrupt routine respectively, further increases work efficiency; And; In the program debug process, target program is in the actual motion state fully, does not influence the operation of soft interrupt routine.
Embodiment four
Fig. 4 is the structural representation that a kind of output function of the present invention is carried out first preferred embodiment of streaming system.
Described system comprises: collector, write soft interrupt number module, the operation module, judge module and output module;
Said collector is write soft interrupt number module and is linked to each other with said, is used for compile source code and generates target program;
Saidly write soft interrupt number module, link to each other with the operation module, be used to revise said target program and write soft interrupt number with said collector;
Said operation module is write soft interrupt number module and is linked to each other with judge module with said, is used to move said amended target program;
Said judge module links to each other with output module with said operation module, is used for judging whether the function of said target program exists said soft interrupt number, then notifies said output module if exist;
Said output module links to each other with said judge module, is used to receive the notice of said judge module, and exports the execution stream of said function.
The further optimization of such scheme is that said collector comprises: stack frame information unit, cancellation preferred cell and generation object element are illustrated in figure 5 as the structural representation that a kind of output function of the present invention is carried out second preferred embodiment of streaming system.
Said stack frame information unit links to each other with said cancellation preferred cell, is used for generating all functions of said source code by the stack frame information of compile time, is specially:
The value of ip register holds sp: mov ip, sp
Value in the ip register subtracts 4 and is saved in the fp register: sub fp, ip, #4;
Said cancellation preferred cell links to each other with the generation object element with said stack frame information unit, is used for cancellation and optimizes option;
Said cancellation is optimized option and is referred to cancel the option that parameter in the compiler comprises band " 0 " such as-02 ,-01 ,-03;
Said generation object element, with said cancellation preferred cell with write soft interrupt number module and link to each other, be used to generate target program.
Such scheme further optimized be, saidly write soft interrupt number module and comprise: first searches unit, second searches the unit and revises the unit, is illustrated in figure 6 as the structural representation that a kind of output function of the present invention is carried out the 3rd preferred embodiment of streaming system.
Said first searches the unit, searches the unit and generates object element and link to each other with said second, is used for searching the binary data that target program " value in the ip register subtracts 4 and is saved in the fp register " instructs;
Cancellation is optimized under the situation of option, mov ip, and the sp instruction is article one instruction that compiler gets into function, said sub fp, ip, #4 is specially for carrying out the initialized sufficient and necessary condition of function:
According to stack frame principle fp register be before function is handled, must preserve the sp register as frame at the bottom of;
Compiler can not be used for other purpose the usefulness of fp register as the stack address storage when function was carried out, and instruction promptly can not occur and deposit new value in for the sp register, otherwise will destroy stack frame standard;
So sub fp, ip, #4 represent to get into a new function and a sub fp, ip, #4 can only be arranged;
Said second searches the unit, searches the unit and revises the unit and link to each other with said first, is used for to returning the binary data that inquiry " value of sp register is saved in the ip register " is instructed; Promptly to returning inquiry movip, the binary data of sp instruction;
After finding the binary data of said " value in the ip register subtracts 4 and is saved in the fp register " instruction, to returning inquiry up to the binary data that finds " value of sp register is saved in the ip register " instruction;
Promptly find said sub fp, ip is behind the binary data of #4 instruction, to returning inquiry up to finding movip, the binary data of sp instruction;
Said modification unit; With said second search the unit with the operation module link to each other; Be used for the corresponding machine code of said " value of sp register is saved in the ip register " instruction is revised as soft interrupt number, be about to said mov ip, sp instructs corresponding machine code to be revised as soft interrupt number;
Said soft interrupt number is for can not be by the employed value of system, 0xaaaaaa for example, and said machine code 0xefaaaaaa representes soft interrupt instruction swi 0xaaaaaa.
Such scheme further optimized be, said judge module comprises and obtains the LR value cell, obtains data cell and judging unit, is illustrated in figure 7 as the structural representation that a kind of output function of the present invention is carried out the 4th preferred embodiment of streaming system.
The said LR value cell that obtains links to each other with the operation module with the said data cell of obtaining, and is used to obtain the value of LR register; Promptly obtain the currency of LR register;
Said LR register is one of CPU general-purpose register; The currency of LR register has been preserved the return address that gets into after the soft Interrupt Process of having no progeny in soft is accomplished; Specifically preserve automatically by CPU core hardware, the address of next bar instruction of carrying out when withdrawing from after just soft Interrupt Process is accomplished, for example:
Swi?0xaaaaaa
Mov?r0,r0(LR)
Next bar instruction that said command M ov r0, r0 (LR) carry out when just withdrawing from after accomplishing for soft Interrupt Process;
The said data cell of obtaining links to each other with judging unit with the said LR of obtaining value cell, is used for " value of LR register subtracts 4 " obtaining 24 bit data of the soft interrupt instruction of SWI in the said address as the address of data access; Be about to LR-4 obtains the soft interrupt instruction of SWI in the said address as the address of data access 24 bit data;
For example, said 24 bit data are low 24 of said machine code 0xefaaaaaa, i.e. 0xaaaaaa;
SWI (Software Interrupt, soft interruption) is the instruction that cpu instruction is concentrated;
The value of LR register is the address of next bar instruction of carrying out when withdrawing from after soft Interrupt Process is accomplished, the address when LR-4 is exactly the soft interrupt instruction of current executed so;
Said judging unit links to each other with output module with the said data cell of obtaining, and is used to judge whether 24 bit data of being obtained are soft interrupt number, if then notify output module;
If represent that then 24 bit data of being obtained are amended soft interrupt number;
Said output module also is used to receive the notice of said judging unit, and the value of output LR register;
Export the address of next bar instruction of carrying out when withdrawing from after soft Interrupt Process is accomplished, promptly export the execution stream of current function.
Such scheme further optimized be, said system also comprises and returns module, is illustrated in figure 8 as the structural representation that a kind of output function of the present invention is carried out the 5th preferred embodiment of streaming system;
The said module of returning links to each other with said output module, is used for value with the sp register and is saved in the ip register (the mov ip that promptly executes instruction sp), and turns back on the value of LR register and continues to carry out current function;
Finish soft Interrupt Process, continue to carry out current function on the address of next bar instruction of carrying out when turning back to soft interruption and withdrawing from.
The further optimization of such scheme is that said system also comprises the redirect module, is illustrated in figure 9 as the structural representation that a kind of output function of the present invention is carried out the 6th preferred embodiment of streaming system;
Said judging unit links to each other with said data cell, output module and the redirect module obtained, and also is used to judge the soft interrupt number whether 24 bit data obtained are, if not, then notify said redirect module;
Said redirect module links to each other with said judge module, is used to receive the notice of said judging unit, and jumps to the section start of the soft interrupt handling routine of system itself;
If, do not represent that then 24 bit data of being obtained are the existing soft interrupt number of system.
The present invention generates target program through the collector compile source code; Writing soft interrupt number module revises said target program and writes soft interrupt number; The operation module is moved said target program; Judge module judges whether the function in the said target program exists said soft interrupt number, if there is the execution stream of then being exported said function by output module.Said execution stream has clearly write down function calling relationship, and can obtain all on-the-spot functions, can be fast, the logic of object observing program actual motion dynamically, reduced research and development of software and maintenance cost, and shortened the time of research and development of software and debugging.Further, when compile source code, stack frame information unit generates in the said source code all functions by the stack frame information of compile time; Option is optimized in the cancellation of cancellation preferred cell; At this moment each function has and has only an instruction sub fp, ip, and #4 searches the unit through first and searches the sub fp in the target program, ip, the binary data of #4 instruction; Second searches the unit to returning inquiry mov ip, the binary data of sp instruction; Revise the unit with said mov ip, sp instructs corresponding machine code to be revised as soft interrupt number; Thereby write soft interrupt number to each function exactly.Further, when target program puts into operation, obtain the value that the LR value cell obtains the LR register; Obtain data cell the value in the LR register is subtracted 4 addresses as data access, obtain 24 bit data of the soft interrupt instruction of SWI in the said address; Whether 24 bit data that judgment unit judges is obtained are soft interrupt number, if, then by the value of output module output LR register; If, then do not jump to the section start of the soft interrupt handling routine of system itself by the redirect module.Through the value of output LR register, can export the full content of R0-R14.In addition, the process of revising the soft interrupt number and the value of output LR register can be encapsulated as PC instrument and soft interrupt routine respectively, further increases work efficiency; And; In the program debug process, target program is in the actual motion state fully, does not influence the operation of soft interrupt routine.
The system that output function provided by the invention is carried out stream need can be applied to output function carry out stream terminal device on, for example PC, PDA, mobile phone, server etc.
Those having ordinary skill in the art will appreciate that; All or part of step in realization the foregoing description method can be accomplished through the programmed instruction related hardware; Described program can be stored in the computer read/write memory medium, and described storage medium can be ROM, RAM, disk, CD etc.
The above is merely preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of within spirit of the present invention and principle, being done, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.