Background
Embedded systems are typically application specific and have very strict requirements on the execution order and execution time of the logic. The embedded system is suitable for a special system with strict requirements on functions, reliability, cost, volume and power consumption. The software development of the embedded system is also different from general application software, the former requires a developer to have enough knowledge of the hardware of the embedded system, and it is very difficult to develop a good software of the embedded system, so that a debugger suitable for the embedded system is very necessary.
The existing embedded debugging mode mainly has two modes: one is online debugging and the other is offline debugging.
The scheme for online debugging of embedded systems is generally as follows: the deployment debugger server is on the embedded single board (i.e. target board), the deployment debugger client is on the PC, the client and the server are connected through the channel such as network port or serial port. The server is responsible for accessing or controlling resources (such as a memory, a register and the like) of the embedded system, and the client on the PC is responsible for receiving command input of a user, performing command analysis, debugging information analysis, real-time/non-real-time analysis of a debugged program, outputting a debugging analysis result and the like.
The online debugging also comprises a non-real-time debugging mode (namely, a stop debugging mode) and a real-time debugging mode (namely, a non-stop debugging mode). The Stop debugging mode needs to Stop the debuggee program first and then analyze the information and the state of the program. The non-stop debugging mode can acquire the relevant state information of the program in real time and the like. Both of these two online debugging methods have drawbacks, which are as follows:
(1) and if the connection between the client of the debugger and the server of the target board is interrupted at a certain moment, the program is abnormal. At this time, the client of the debugger cannot acquire the real-time condition of the debugged program, and cannot control the state of the debugged program, so that the online debugging mode is invalid.
(2) And because the program abnormity usually has randomness and irreproducibility, the problem is difficult to reproduce, and the failure of online debugging causes the efficiency of problem positioning and analysis to be reduced.
In the off-line testing scheme, because the testing process is finished on the target board, the connection between the target board and the debugger does not exist; therefore, the technical defects can be avoided, and the scheme of off-line debugging is generally as follows: the target board comprises a backup dump file, wherein the backup dump file comprises register information, memory information, operating system information and the like; and the target board acquires debugging information and the backup dump file offline on a debugger, and then analyzes the causes of the program abnormality. However, the offline debugging also has the following defects:
because the variety of the platforms operated by the target board is wide, the backup dump file contains information related to the operating system and the target board platform, and therefore the backup dump file has a difference in format. In addition, in the development phase of the system software of the target board, the version upgrade of the system software is usually fast, however, the corresponding dump file formats of different versions of the system software are different. Therefore, when the debugger client implements dump files supporting different platforms, or dump files supporting different versions of the same platform, the debugger client needs to be modified greatly. Thus, in order to solve the contradiction between the debugger client and the platform in the file format support, the debugger client still needs to be modified, and a great amount of labor and time are needed for modifying the debugger.
In summary, offline debugging requires continuous modification of the debugger client to implement offline debugging, which results in greater difficulty, higher cost, and longer time for implementing offline analysis. In addition, debugging tools for online debugging and offline debugging need to be developed respectively, and the problem of repeated development exists.
Disclosure of Invention
The embodiment of the invention provides a debugging method, a debugging conversion device and a debugging conversion system of an embedded system, which are used for increasing the application range of an online debugging tool, shortening the development time of an offline debugging tool and reducing the development cost.
An embodiment of the present invention provides a method for debugging an embedded system, including:
acquiring a conversion rule from a customized online debugging command to an offline debugging command;
after receiving the source code of the online debugging command, converting the source code of the online debugging command into a code supporting offline debugging according to the conversion rule;
and sending the code supporting the offline debugging to a target board.
With reference to implementation manners of an aspect, in a first optional implementation manner, the converting the source code of the online debugging command into a code supporting offline debugging, and sending the code supporting offline debugging to a target board includes:
converting the source code of the online debugging command into the source code of the offline debugging command; performing secondary compiling on the obtained offline command source code and the current debugger client to generate a debugger client supporting offline debugging, and sending the debugger client supporting offline debugging to a target board; or,
and converting the source code of the online debugging command into a code of the offline debugging command, linking the code into a dynamic library, and sending the dynamic library to a target board.
With reference to the first optional implementation manner, in a second optional implementation manner, the converting the source code of the online debug command into the source code of the offline debug command includes:
converting the source code of the online debugging command into the source code of the offline command by using a compiler; or converting the source code of the online debugging command into the source code of the offline command through a client tool.
With reference to the second optional implementation manner, in a third optional implementation manner, the converting, by using a compiler, the source code of the online debug command into the source code of the offline command includes:
and reading in the source code of the online debugging command, performing rule matching of the character string according to the conversion rule, calling a conversion processing interface to generate a lexical or grammatical unit which can be identified by a compiler if the matching is successful, and then outputting the source code of the offline debugging command.
With reference to the first, second, or third optional implementation manners of an aspect, in a fourth optional implementation manner, the conversion rule includes:
at least one item of symbol table information conversion rules, register and call stack rules, debugging output interface conversion rules and memory distribution rules;
the symbol table information conversion rule is as follows: the address mapping information of the online debugging command service related symbol or the global symbol is converted into a rule of symbol information which can be identified by an online debugger;
the register and call stack rules are: the number of general registers, function return addresses, register configuration of stack pointers or Personal Computer (PC) pointers, and function call stack information;
the conversion rule of the debugging output interface is as follows: a rule that an online debugging command interface is converted into an offline debugging command interface;
the memory distribution rule is as follows: and determining the size and distribution rule of the private memory or the shared memory.
In a second aspect, an embodiment of the present invention provides a debugging conversion apparatus for an embedded system, including:
the rule obtaining unit is used for obtaining a conversion rule from a customized online debugging command to an offline debugging command;
the source code receiving unit is used for receiving the source code of the online debugging command;
the conversion unit is used for converting the source code of the online debugging command into a code supporting offline debugging according to the conversion rule acquired by the rule acquisition unit after the source code receiving unit receives the source code of the online debugging command;
and the sending unit is used for sending the codes supporting the off-line debugging obtained by the conversion unit to the target board.
With reference to the implementation manner of the second aspect, in a first optional implementation manner, the conversion unit is specifically configured to convert a source code of the online debug command into a source code of an offline debug command; performing secondary compiling on the obtained offline command source code and the current debugger client to generate a debugger client supporting offline debugging; or, converting the source code of the online debugging command into the code of the offline debugging command and linking the code into a dynamic library;
the sending unit is specifically configured to send the debugger client supporting offline debugging obtained by the conversion unit to a target board; or sending the dynamic library obtained by the conversion unit to a target board.
With reference to the implementation manner of the second aspect, in a second optional implementation manner, the conversion unit is specifically configured to convert a source code of the online debugging command into a source code of an offline command by using a compiler; or converting the source code of the online debugging command into the source code of the offline command through a client tool.
With reference to the second implementation manner, in a third optional implementation manner, the conversion unit includes:
the reading unit is used for reading the source code of the online debugging command received by the source code receiving unit;
the matching unit is used for matching the rules of the character strings according to the conversion rules acquired by the rule acquisition unit;
and the source code generating unit is used for calling the conversion processing interface to generate a lexical or grammatical unit which can be identified by the compiler if the matching unit is successfully matched, and then outputting the source code of the offline debugging command.
With reference to the one aspect, the first optional implementation manner, the second optional implementation manner, or the third optional implementation manner, in a fourth optional implementation manner, the rule obtaining unit obtains the conversion rule including: at least one item of symbol table information conversion rules, register and call stack rules, debugging output interface conversion rules and memory distribution rules;
the symbol table information conversion rule is as follows: the address mapping information of the online debugging command service related symbol or the global symbol is converted into a rule of symbol information which can be identified by an online debugger;
the register and call stack rules are: the number of general registers, function return addresses, register configuration of stack pointers or Personal Computer (PC) pointers, and function call stack information;
the conversion rule of the debugging output interface is as follows: a rule that an online debugging command interface is converted into an offline debugging command interface;
the memory distribution rule is as follows: and determining the size and distribution rule of the private memory or the shared memory.
The embodiment of the invention provides a debugging system of an embedded system in three aspects, which comprises a debugger and a target board, and also comprises: the debugging conversion device provided by the embodiment of the invention is any one;
and the debugging conversion device receives a source code of an online debugging command from a client of the debugger and outputs a code supporting offline debugging to a server of the target board.
According to the technical scheme, the embodiment of the invention has the following advantages: the online debugging command is converted from the source code of the online debugging command to the code of the offline debugging command, so that the offline debugging of the online debugging command is realized, the repeated development problems of online debugging and offline debugging of embedded system software can be solved, the problem that the client of a debugger needs to be modified when the offline debugging of different platforms is realized or the offline debugging of different versions is realized on the same platform is avoided, the application range of an online debugging tool can be enlarged, the development time of the offline debugging tool is shortened, and the development cost is reduced.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
An embodiment of the present invention provides a method for debugging an embedded system, as shown in fig. 1, including:
101: acquiring a conversion rule from a customized online debugging command to an offline debugging command;
the conversion rule from the online debugging command to the offline debugging command may be any rule that can establish a corresponding relationship from the online debugging command to the offline debugging command, and the conversion rule may be increased or decreased according to actual needs, and the specific form of the embodiment of the present invention provides the following examples: optionally, the conversion rule includes: at least one item of symbol table information conversion rules, register and call stack rules, debugging output interface conversion rules and memory distribution rules; the symbol table information conversion rule is as follows: the address mapping information of the online debugging command service related symbol or the global symbol is converted into a rule of symbol information which can be identified by an online debugger; the register and call stack rules are: the number of general registers, function return addresses, register configuration of stack pointers or Personal Computer (PC) pointers, and function call stack information; the conversion rule of the debugging output interface is as follows: a rule that an online debugging command interface is converted into an offline debugging command interface; the memory distribution rule is as follows: and determining the size and distribution rule of the private memory or the shared memory. It should be noted that the transcoding rules may be of many kinds, and the above examples should not be construed as limiting the embodiments of the present invention.
102: after receiving the source code of the online debugging command, converting the source code of the online debugging command into a code supporting offline debugging according to the conversion rule;
optionally, the embodiment of the present invention provides two optional schemes for supporting offline debugging of a code, which are as follows: the converting the source code of the online debugging command into the code supporting the offline debugging comprises: converting the source code of the online debugging command into the source code of the offline debugging command; performing secondary compiling on the obtained offline command source code and the current debugger client to generate a debugger client supporting offline debugging; or converting the source code of the online debugging command into the code of the offline debugging command and linking the code into a dynamic library.
Optionally, the embodiment of the present invention further provides two implementation schemes for converting a source code into a source code of an online debugging command into an offline debugging command, specifically: the converting the source code of the online debugging command into the source code of the offline debugging command includes: using a compiler to convert the source code of the online debugging command into the source code of the offline command; or, the source code of the online debugging command is converted into the source code of the offline command through the client tool.
Optionally, an embodiment of the present invention further provides a specific implementation manner for implementing conversion from a source code to a source code by using a compiler, where the specific implementation manner is as follows: the converting the source code of the online debugging command into the source code of the offline command by using the compiler comprises: and reading in the source code of the online debugging command, performing rule matching of the character string according to the conversion rule, calling a conversion processing interface to generate a lexical or grammatical unit which can be identified by a compiler if the matching is successful, and outputting the source code of the offline debugging command.
103: and sending the codes supporting the offline debugging to a target board.
According to the scheme, the online debugging command is converted from the source code of the online debugging command to the code of the offline debugging command, the offline debugging of the online debugging command is realized, the repeated development problems of the online debugging and the offline debugging of the embedded system software can be solved, the problem that the debugging client side needs to be modified when the offline debugging of different platforms or different versions of the same platform are realized is avoided, therefore, the application range of the online debugging tool can be enlarged, the development time of the offline debugging tool is shortened, and the development cost is reduced.
Optionally, corresponding to the two optional schemes of the code supporting offline debugging in the foregoing embodiment, the sending the code supporting offline debugging to the target board includes: sending the debugger client supporting the offline debugging to a target board; or sending the dynamic library to the target board.
The following embodiments illustrate the solutions of the above embodiments in more detail in terms of structural composition, debug networking, source code translation, and examples, respectively.
One, the structure is composed
Please refer to fig. 2, which shows: and generating a module structure schematic diagram of the offline command through source-to-source conversion, wherein the arrow direction is a data flow direction.
Both online and offline debuggers developed for embedded systems in this example may use C as the programming language. The online debug command source code (primarily. c and. h files) serves as the input source for the offline command translator.
The offline command converter has three main parts: the device comprises a symbol analysis module, a dump file analysis module and a source-to-source conversion module.
The symbol analysis module obtains the definition of the global symbol, the address mapping table and the symbol description information related to the service from the input source, analyzes and processes the symbol and outputs the symbol to the source-to-source conversion module.
The other input of the source-to-source conversion module comes from a dump file parsing module, and the dump file parsing module mainly completes analysis and processing of offline file registers and call stack rules, which are usually strongly related to the ISA (industry standard architecture bus) of the embedded system.
After the source-to-source conversion module obtains the required information, the output of the final off-line debugging command source code (mainly, the files of.c and.h) can be completed through the internally defined rules. At this time, the off-line debugger already has the service-related symbol table information and address information owned by the on-line debugger module, and the product service-related information can be acquired by using the printing interface of the off-line debugger.
Second, debugging networking
A typical debugger networking diagram as shown in figure 3,
in an online debugging scenario, a debugger client located at a PC (personal computer) end and a debugging server located on a target Board (Board) communicate through channels such as an ETH (Ethernet, internet access) or a serial port. The PC side also includes an Integrated Development Environment (IDE), and the Board side also includes an application program, a system, and a memory/register.
In an offline debugging scenario, a debugger client obtains required register/memory information, operating system information or product service information from a dump file (CoreFileonPC) of a personal computer through file I/O.
Three, source code conversion
Please refer to fig. 4: the flow diagram of converting an online command into an offline command.
401: formulating a conversion rule from the online debugging command to the offline debugging command;
there is a complete set of rules for the conversion of online debug commands to offline commands. The customization of the rules may mainly include the following parts: the symbol table information conversion rule mainly sets up a rule for converting address mapping information of online debugging command service related symbols or global symbols into symbol information which can be identified by an online debugger. The register and call stack rules comprise the number of general registers, the register configuration of function return addresses, stack pointers, PC pointers and the like, and function call stack information and the like. And debugging the conversion rule of the output interface, and making a command interface for online debugging converted into an offline debugging command interface. Memory distribution rules, determining the size and distribution of private memory or shared memory, etc. Certain rules may be added or subtracted depending on the requirements of the actual service.
402: converting the source code of the online debugging command into the source code of the offline debugging command by using a source code conversion compiler;
the basic principle of the conversion of this step may be: and reading in a source code of the online debugging command, and performing rule matching of the character string according to the established conversion rule. If the matching is successful, a conversion processing interface is called to generate a lexical or grammatical unit which can be identified by the compiler, and then the compiler outputs the source code of the final offline debugging command.
403: the source code of the offline debug command generated in 402 is compiled together with the source code of the offline debug that is not architecture and translation related, so that a new offline debugger client can be generated.
Steps 402 and 403 of the above scheme can be replaced in other ways, specifically as follows:
402 in the above flowchart of fig. 4 is a source code conversion compiler used to convert the source code of the online debug command into the source code of the offline debug command. The alternative may be to implement a translation client tool that translates the source code of the online debug command into the source code of the offline debug command separately, without relying on a compiler. That is, the conversion tool can be separated from the compiler, and the client tool has a function of analyzing the flow chart rule to generate the final source code.
Another alternative to 402 in the flow diagram of fig. 4 is to link the code of the converted offline commands (mainly. c and. h files) into a dynamic library (. dll or. so format) by a compiler. Then the second compilation in 403 may be omitted and the off-line debugger client only needs to dynamically load the dynamic library generated in 402 to complete the corresponding debugging function.
Fourth, example
The following is an implementation scenario:
referring to fig. 5, which is a source-to-source conversion process example, taking a CPU (central processing unit) load rate of a current system as an example, fig. 5 is written in C language, and may refer to a relevant specification written in C language, where a left column is a source code of an online debug command, and a right arrow points to a source code of an offline debug command corresponding to the online debug command, and the example converts the source code of the online debug command into the source code of the offline debug command. The method mainly comprises the following three steps:
1. global variables in the command implementation are identified. This is a traffic-related global variable, which is first to have a conversion rule that identifies this traffic symbol. The rules are simple to identify strings within quotation marks (i.e. the bold text in the top dashed box in the upper large box in fig. 5).
The offline command converter continuously reads the input file (i.e. the left code in fig. 5), and when the key word of DSP _ LkAddr is recognized (this is a call interface of the service query symbolic address, and this interface call is configured in the rule for matching the character string at the time of rule making), the offline command converter matches the character string following the key word, which is enclosed by a double quotation mark, in this case gstpu load. The implicit conversion rule is to convert the member call of the original structure into a member call of the recognized character string, such as strucpload. uwcurload- - - - > gstucpload. uload. uwcurload, and the conversion result is used as the input of the following function call conversion interface. The conversion correspondence is shown by the arrows shown in fig. 5.
2. And acquiring the function call of the global variable value, and replacing the function call with the function call in the off-line debugging client.
As shown in fig. 5, the call interface DSP _ CommRead for online query of the service variable address is converted into the corresponding offline call interface getSymAddrSize, and the above strucpuloload.
3. And replacing the function call output by the command return result with the function call of the off-line debugging client.
After the global symbol and the interface conversion for acquiring the global quantity are completed, the conversion of the platform printing output interface in the last step can be realized, and the conversion realizes the function of the output switching of the final debugging result. Such as the online debug interface LBB _ DSP _ Printf in this example, to the offline print interface Printf.
By adopting the scheme, the online debugging and the offline debugging of the embedded system software are applied to different scenes and are indispensable debugging modes. The embodiment of the invention realizes the off-line debugging of the on-line debugging command, can solve the problem of repeated development of the on-line debugging and the off-line debugging of embedded system software, converts the on-line debugging command from a source code of the on-line debugging command to a code of the off-line debugging command which can be used on a PC (personal computer), converts product service information related to the command into an address and a length by using a symbol analysis function, and can acquire system related information by inquiring a corresponding memory address interval by the off-line command. The off-line debugging of the on-line debugging command can avoid the problem that the debugger client needs to be modified when the off-line debugging of different platforms is realized or the off-line debugging of different versions is realized on the same platform, so the method can increase the application range of the on-line debugging tool, shorten the development time of the off-line debugging tool and reduce the development cost.
An embodiment of the present invention further provides a debug conversion apparatus for an embedded system, as shown in fig. 6, including:
a rule obtaining unit 601, configured to obtain a conversion rule from a customized online debugging command to an offline debugging command;
a source code receiving unit 602, configured to receive a source code of an online debugging command;
a conversion unit 603, configured to, after the source code receiving unit 602 receives the source code of the online debugging command, convert the source code of the online debugging command into a code supporting offline debugging according to the conversion rule obtained by the rule obtaining unit 601;
a sending unit 604, configured to send the code supporting offline debugging obtained by the converting unit 603 to a target board.
According to the scheme, the online debugging command is converted from the source code of the online debugging command to the code of the offline debugging command, the offline debugging of the online debugging command is realized, the repeated development problems of the online debugging and the offline debugging of the embedded system software can be solved, the problem that the debugging client side needs to be modified when the offline debugging of different platforms or different versions of the same platform are realized is avoided, therefore, the application range of the online debugging tool can be enlarged, the development time of the offline debugging tool is shortened, and the development cost is reduced.
Optionally, the converting unit 603 is specifically configured to convert the source code of the online debug command into a source code of an offline debug command; performing secondary compiling on the obtained offline command source code and the current debugger client to generate a debugger client supporting offline debugging; or, the source code of the online debugging command is converted into the code of the offline debugging command and linked into a dynamic library;
the sending unit 604 is specifically configured to send the debugger client supporting offline debugging obtained by the converting unit 603 to a target board; or the dynamic library obtained by the conversion unit 603 is sent to the target board.
Optionally, the converting unit 603 is specifically configured to convert the source code of the online debug command into the source code of the offline command by using a compiler; or, the source code of the online debugging command is converted into the source code of the offline command through the client tool.
Alternatively, as shown in fig. 7, the converting unit 603 includes:
a reading unit 701, configured to read in a source code of the online debug command received by the source code receiving unit 602;
a matching unit 702, configured to perform rule matching on the character string according to the conversion rule acquired by the rule acquisition unit 601;
and a source code generating unit 704, configured to, if the matching unit 702 succeeds in matching, invoke a conversion processing interface to generate a lexical or syntactic unit that can be recognized by a compiler, and then output a source code of the offline debugging command.
Optionally, the rule obtaining unit 601 obtains the conversion rule including: at least one item of symbol table information conversion rules, register and call stack rules, debugging output interface conversion rules and memory distribution rules;
the symbol table information conversion rule is as follows: the address mapping information of the online debugging command service related symbol or the global symbol is converted into a rule of symbol information which can be identified by an online debugger;
the register and call stack rules are: the number of general registers, function return addresses, register configuration of stack pointers or Personal Computer (PC) pointers, and function call stack information;
the conversion rule of the debugging output interface is as follows: a rule that an online debugging command interface is converted into an offline debugging command interface;
the memory distribution rule is as follows: and determining the size and distribution rule of the private memory or the shared memory.
An embodiment of the present invention further provides a debugging system of an embedded system, as shown in fig. 8, including a debugger 801 and a target board 803, further including: any one of the debugging conversion devices 802 provided in the embodiments of the present invention; the debug conversion apparatus 802 receives a source code of an online debug command from the client of the debugger 801, and outputs a code supporting offline debug to the server of the target board 803.
It should be noted that, in the embodiment of the debug conversion apparatus, each unit included in the embodiment is only divided according to functional logic, but is not limited to the above division as long as the corresponding function can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
In addition, it is understood by those skilled in the art that all or part of the steps in the above method embodiments may be implemented by related hardware, and the corresponding program may be stored in a computer readable storage medium, where the above mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the embodiment of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.