Summary of the invention
Fundamental purpose of the present invention provides a kind of on-line debugging system that can dynamically arrange the embedded system of breakpoint in debug process;
Another object of the present invention provides the on-line debugging method that a kind of on-line debugging system that uses above-mentioned embedded system debugs embedded system.
For realizing above-mentioned fundamental purpose, embedded system on-line debugging provided by the invention system comprises embedded system and debug terminal, and this embedded system is connected by connection device with debug terminal.Wherein, this debug terminal comprises Subscriber Interface Module SIM, symbol processing module and target processing module.Subscriber Interface Module SIM receives and explains debug command, and the relevant information of debug command is sent to the symbol processing module, and the symbol processing module is found out the information such as address of relevant variable in the debug command or function according to these information, and is sent to target processing module.
Target processing module comprises execution module and communication module, wherein execution module is carried out the order that Subscriber Interface Module SIM sends, and send the specific instructions information that embedded system is debugged to communication module according to the address information that the symbol processing module provides, communication module sends to connection device with this command information.
Embedded system comprises debugged program and debugging module, and wherein debugged program is to download to before debugging on the embedded device, and debugging module comprises communication module, command processing module and context processing module.Communication module is used to receive the command information that connection device sends, and this command information is sent to command processing module, and command processing module is carried out corresponding operation according to this command information.The context processing module is preserved the current operation information of debugged program when debugged program interrupt, as value of each register etc.
Certainly, stack frame analysis module can also be set in the target processing module of debug terminal, the appropriate address information that information that stack frame analysis module sends according to Subscriber Interface Module SIM and symbol processing module provide, the a certain function calls relation of information analyses such as the address by checking respective function in the embedded system, stack frame pointer, function return value, and pass this call relation back Subscriber Interface Module SIM, Subscriber Interface Module SIM shows call relation.
Because the symbol processing module can be obtained the information such as address of each variable, function, target processing module can be made amendment to debugged program by the debugging module of embedded system in real time, so just can in debugged program, add new breakpoint dynamically, make things convenient for commissioning staff's debugging work greatly.And owing to can dynamically add breakpoint, therefore dynamic single step run also just can realize.
Simultaneously,, therefore an acquiescence breakpoint only need be set in debugged program get final product, reduce the storage space that debugged program takies, avoid causing the waste of storage space because breakpoint dynamically adds when debugging.
In order to realize another above-mentioned purpose, embedded system on-line debugging method provided by the invention is applied in the aforesaid embedded system on-line debugging system, and this adjustment method may further comprise the steps:
Step 1: in debugged program, add the acquiescence breakpoint, and debugged program is downloaded in the embedded system.
Step 2: the debugged program of operation in embedded system, debugged program run operation suspension during to breakpoint, the context processing module is preserved the current operation information of debugged program, the information stores such as value, the value in each register and PC (Program Counter, programmable counter) pointer relative position that are about to each parameter are in appointed positions.
Step 3: the operation information of debugged program is checked and/or revised to debug terminal, judges whether to add new breakpoint in debugged program, if need, then adds new breakpoint in debugged program, otherwise, carry out next step.
Step 4: command processing module sends the order that continues operation to debugged program, and the operation information when the context processing module is recovered debugged program interrupt is about to stored information reverting in the step 2, and debugged program continues operation.
Step 5: if debugged program runs into breakpoint, then return execution in step two, otherwise, continue the debugged program of operation.
When adding new breakpoint, at first the information that needs to add breakpoint is set by Subscriber Interface Module SIM, comprise the position of adding breakpoint, the type of breakpoint etc., and these information are sent to the symbol processing module, the symbol processing module is found out the address that needs to add breakpoint, add address in the embedded system etc. as breakpoint at needs to, then address information is sent to execution module.Execution module receives the information that Subscriber Interface Module SIM sends needs to add breakpoint, and the address information that provides according to the symbol processing module, analysis need be read and is stored in the data in which address in the embedded system, and sends to embedded system by communication module and connection device and to read the command information that is stored in data in this address.Debugging module is back to debug terminal after reading corresponding data according to this command information, and debug terminal is preserved these data.Execution module sends and rewrites the command information be stored in data in this address then, be rewritten as one can exception throw debug command.
By said method as seen, run into the breakpoint operation suspension during debugged program run, and wait for that debug terminal sends debug command.If judging when needing to add new breakpoint, debug terminal can add new breakpoint dynamically.Like this, do not need in debugged program, to be provided with in advance a large amount of breakpoints, make things convenient for the commissioning staff to carry out debugging work greatly.Simultaneously, if need carry out dynamic single step run the time, as long as the instruction of single step run is set in the place that needs single step run.
Embodiment
Referring to Fig. 1, Fig. 1 is the schematic block diagram of embedded system on-line debugging system embodiment of the present invention.Debug system is made up of debug terminal 1, connection device 2 and embedded system 3, and wherein debug terminal 1 is connected with embedded system 3 by connection device 2.
Debug terminal 1 comprises Subscriber Interface Module SIM 11, symbol processing module 12 and target processing module 13.Subscriber Interface Module SIM 11 is connection interfaces of debug terminal 1 and commissioning staff, be used to receive and explain the debug command that the commissioning staff is provided with, comprise the value of adding new breakpoint, checking a certain parameter, check a certain function call relation in debugged program or the like.Simultaneously, Subscriber Interface Module SIM 11 also shows the state of the current operation of debugged program, as program source code, PC pointer information such as be expert at.
Debugging message such as the symbol table that symbol processing module 12 generates when resolving debugged program compilation, row number table, obtain as information such as start of line addresses in types of variables, address of variable, function address scope, the source code, and provide corresponding information to target processing module 13 according to the information that Subscriber Interface Module SIM 11 sends.
Target processing module 13 comprises execution module 15, stack frame analysis module 16 and communication module 17.Execution module 15 can receive Subscriber Interface Module SIM 11 and send information about debug command, and the information such as address of variables corresponding, function in this debug command that provides of receiving symbol processing module, and send corresponding command information to communication module 17 according to these address informations, communication module 17 is sent to connection device 2 with this command information.
Stack frame analysis module 16 is mainly used in information such as analyzing in the debugged program each function calls relation and function parameters, local variable.When stack frame analysis module 16 needs to analyze a certain function calls and concern, need to use the initial address message (IAM), function parameters address etc. of this function that symbol processing module 12 provides from embedded system 3, to obtain the call relation that information such as the relative position of stack frame pointer and stack pointer, function parameters rreturn value are come analytic function.Simultaneously, the Subscriber Interface Module SIM 11 that stack frame analysis module 16 sends analysis result, Subscriber Interface Module SIM 11 are about to this result and show.
Embedded system 3 comprises debugged program 31 and debugging module 32, and wherein debugged program 31 downloads to before debugging in the embedded system 3, and debugging module 32 is debugged debugged program 31 according to the command information that debug terminal 1 sends.
Debugging module 32 comprises communication module 36, command processing module 35 and context processing module 34.Communication module 36 receives the command information that connection device 2 transmits, and these command informations are sent to command processing module 35, command processing module 35 is carried out corresponding operation according to these command informations, as read the value of a certain variable in the debugged program 31, in debugged program 31, add new breakpoint etc., and behind end of operation, return corresponding information to debug terminal 1 by communication module 36, connection device 2, as read variable value, the operation whether successfully wait.
Context processing module 34 is used for preserving the current operation information of debugged program 31 when debugged program 31 is interrupted.Running into breakpoint in debugged program 31 operational processs is operation suspension, and at this moment, context processing module 34 is about to the current operation information of debugged module 31, as data in each register etc., stores appointed positions into.When debugged program 31 needed to continue operation, context processing module 34 was these information revertings, the running status when promptly recovering debugged program 31 and interrupting.
Use process that embedded on-line debugging of the present invention system debugs embedded system as shown in Figure 2, Fig. 2 also is the process flow diagram of embedded system on-line debugging method embodiment of the present invention.When debugging, at first in debugged program, add an acquiescence breakpoint, then debugged program is compiled, and the program after will compiling downloads to (step S1) in the embedded system.The Debugging message that generates when debug terminal is with debugged program compilation then reads in, and communicates by letter with embedded system foundation.
Then, in embedded system, move debugged program (step S2), and the running state information of debugged program is shown on the Subscriber Interface Module SIM of debug terminal.Whether embedded system runs into breakpoint (step S3) when judging debugged program run, if do not run into breakpoint, judge further then whether debugging finishes (step S4), as embedded system outage etc., if debugging finishes, then finish debugging, if debugging does not finish, then return step S2, continue the debugged program of operation.
Owing to be provided with the acquiescence breakpoint in the debugged program, debugged program run when giving tacit consent to breakpoint with operation suspension.At this moment, the context processing module is preserved the current operation information of debugged program (step S5), and value that is about to each register in the debugged program etc. stores an assigned address into.
Then, debug terminal is checked the operation information (step S6) of debugged program, these operation informations comprise the value of each register etc., the commissioning staff judges by judging these information whether debugged program run is normal, thereby judging whether needs to add new breakpoint (step S7), if need to add new breakpoint, debug terminal will send the order (step S8) of adding new breakpoint to debugging module, as not needing to add new breakpoint, then direct execution in step S9.
Debug terminal is provided with breakpoint in debugged program after, debugging module sends the order that continues operation to debugged program.At this moment, the operation information (step S9) when the context processing module is recovered debugged program interrupt, the information such as value of each register write back original position during just with debugged program interrupt, and the operation information that makes debugged program is consistent when interrupting.Like this, debugged program just can be at original running environment relaying reforwarding row.Certainly, if the commissioning staff time changes the running environment of debugged program in debugging, as change the value etc. of a certain parameter, then after the End of Interrupt, debugged program is moved in new running environment.
Debugged program is when operation, and embedded system will continue to judge whether debugged program runs into breakpoint (returning step S3), and circulate until end with this.
Because the breakpoint in the debugged program can dynamically be provided with, the commissioning staff does not just need in advance a large amount of breakpoints to be arranged in the debugged program.The commissioning staff can the ruuning situation according to debugged program judge whether that needs add new breakpoint in debug process, and judges the position of adding new breakpoint, has increased the dirigibility of debugging work so greatly, brings great convenience to the commissioning staff.
Simultaneously, if the commissioning staff need allow debugged program realize dynamic single step run, can send the single step run order of assembly level by debug terminal to embedded system, when the command processing module in the embedded system is handled this order, calculate the next machine instruction address that needs execution of PC pointer, and a breakpoint is set on this address, allow debugged program continue operation then.When debugged program run is interrupted during to this address, and in have no progeny and recover original program, simultaneously PC pointer current location is returned debug terminal, debug terminal judges whether source code moves to next line, if then do not continue to send the single step run order of assembly level.Like this, operation suspension once more after the instruction of next bar of debugged program run, the commissioning staff can check embedded system whether correct execution this instruction.
And because the commissioning staff need not at the default a large amount of breakpoints of debugged program, the storage space that debugged program is taken significantly reduces, and has avoided the waste of storage space.
After the debugging flow process of introducing embedded system on-line debugging method of the present invention, introduce debug terminal in the debug process below and be status information when how to check debugged program interrupt.
Referring to Fig. 3, Fig. 3 is a process flow diagram of checking debugged program run information among the embedded system on-line debugging method embodiment of the present invention.The value of a certain variable when usually, the commissioning staff need check debugged program interrupt.After debugged program runs into breakpoint stop operation, the variable name information (step S11) that the commissioning staff need check variable by the Subscriber Interface Module SIM setting of debug terminal, and the information of this variable name is sent to symbol processing module and execution module.
After the symbol processing module received the information that Subscriber Interface Module SIM sends, the Debugging message that generates during according to debugged program compilation was found out the address (step S12) of this variable in embedded system, and this address information is sent to execution module.Execution module is according to the address information of symbol processing module, know and to read the data that are stored in the embedded system in which address, promptly send and read the command information (step S13) that is stored in data in this address, and this command information sent to the communication module of debug terminal, and this command information is sent in the communication module of embedded system by connection device.
After the communication module of embedded system receives command information, command information is sent to command processing module, command processing module promptly reads the data that are stored in this address according to this command information, and with data back Subscriber Interface Module SIM (step S14), Subscriber Interface Module SIM receives after these data and data presentation come out (step S15).Like this, the commissioning staff can view the value of this variable, thereby judges whether debugged program has problems.
Revise a certain variable value process and above-mentionedly check that the process of a certain variate-value is similar.When the commissioning staff need revise the value of a certain variable, also be the information that needs to revise variable to be set by Subscriber Interface Module SIM, after the symbol processing module finds the address of this variable, execution module can send rewrites the command information that is stored in data in this address, embedded system is carried out corresponding operation after receiving this command information, and returns the information of revising successfully or failing to Subscriber Interface Module SIM.
When the commissioning staff checked or revises the value that is stored in a certain register, as long as information such as this register name is set by Subscriber Interface Module SIM, execution module promptly sent the order of checking or revising this register value by communication module.After embedded system is carried out associative operation, return the value of this register or revise whether successful information to Subscriber Interface Module SIM.
In the on-line debugging method of embedded system, after debug terminal is checked the operation information of embedded system, often need in debugged program, add new breakpoint.Referring to Fig. 4, Fig. 4 is the process flow diagram of the new breakpoint of interpolation of the on-line debugging method of embedded system of the present invention.
When adding new breakpoint, the commissioning staff is provided with the information (step S21) that needs to add new breakpoint by Subscriber Interface Module SIM, comprises position that breakpoint adds, breakpoint type etc.For example, Subscriber Interface Module SIM setting need be added a new breakpoint at the 32nd row of debugged program, then, this information is sent to symbol processing module and execution module.
After the symbol processing module receives this information, the Debugging message that generates during by debugged program compilation is found out the address (step S22) that needs to add breakpoint, as find out memory address in the pairing embedded system of debugged program the 32nd row, for example this address is 0X1844, and the symbol processing module is about to this address and sends to execution module.
Then, execution module is according to the address that the symbol processing module provides, and sends to read to be stored in that the address is the command information (step S23) of the data of 0X1844 in the embedded system, and by communication module and connection device this command information is sent to embedded system.
The communication module of embedded system is sent to command processing module after receiving this command information, and command processing module promptly reads the data that are stored in the 0X1844 of address, and these data are sent back Subscriber Interface Module SIM.After Subscriber Interface Module SIM receives these data, these data are saved to appointed positions (step S24).
Then, execution module sends the command information (step S25) in the readdressing 0X1844 again, a debug command is written in this address, and this command information is sent to embedded system.After embedded system receives this command information,, and return the successful information of whether rewriting to Subscriber Interface Module SIM with the data rewriting in the memory address 0X1844.
After Subscriber Interface Module SIM receives this return message (step S26), judge rewriting whether successfully (step S27), if rewrite successfully, then finish, if rewrite failure, embedded system is returned the information of rewriting failure to Subscriber Interface Module SIM, and Subscriber Interface Module SIM can receive this return message (step S28), and show, the commissioning staff promptly knows and rewrites failure.
Like this, exception throw when debugged program continues operation and runs into this debug command, breakpoint is promptly successfully added in debugged program halt operation.
When debugged program need continue to move, the operation information when the context processing module will be recovered debugged program interrupt.But, because original program at debugged program interrupt point place is modified, will cause debugged program normally to move down, therefore, when recovering the operation information of debugged program, also need the former data at breakpoint place are write back in the debugged program.
In the present embodiment, address, breakpoint place is 0X1844, and the former data in this address have been preserved by Subscriber Interface Module SIM when adding breakpoint, and therefore, Subscriber Interface Module SIM can write back former data in the 0X1844 of address easily, and debugged program can continue operation.
Simultaneously, embedded system on-line debugging method of the present invention can also be checked the call relation of embedded system inner function.When checking function calling relationship, the commissioning staff at first need check the information of function by Subscriber Interface Module SIM setting, and this information is sent to symbol processing module and stack frame analysis module.After the symbol processing module receives this information, find out the information such as start address, function parameters address of this function, and be sent to stack frame analysis module.Stack frame analysis module sends the order of the information such as relative position that read corresponding stack frame pointer and stack pointer according to these address informations to embedded system by communication module and connection device.After embedded system was back to stack frame analysis module with corresponding information, stack frame analysis module was promptly according to these information, and the transfer mode of associative function parameter and rreturn value etc. is analyzed the function calls relation.After analysis finishes, analysis result is sent to Subscriber Interface Module SIM, and Subscriber Interface Module SIM shows the result, and the commissioning staff can view the function calls relation, certainly, also can utilize this function calls relation as analyzing whether in-problem foundation of debugged program run.
This shows, embedded system on-line debugging method of the present invention can dynamically be provided with breakpoint in debugged program debug process, make the commissioning staff check the operation conditions in debugged arbitrary moment of program easily, and can realize single step run as required, make debugging become more flexible.Simultaneously, the commissioning staff need not default a large amount of breakpoint in debugged program, reduces the storage space that debugged program takies.
Concrete application of the on-line debugging system of embedded system and adjustment method is exactly the debugging of smart card, as the debugging of SIM card.When needing the program of debugging SIM card, debug terminal can be a debugging computer, and embedded system is a SIM card, and card reader is then as both connection device.
Certainly, the present invention is not limited only to the debugging of SIM card, and other embedded system as single-chip microcomputer etc., can use the present invention to debug.If use in the debugging of other embedded system, then the commissioning staff should select corresponding debug terminal and connection device according to different embedded systems.
At last, it is emphasized that to the invention is not restricted to above-mentioned embodiment that breakpoint is provided with the change of position, the subtle change such as change of connection device also should be included in protection scope of the present invention such as giving tacit consent to.