CN101916223A - Program debugging method and system - Google Patents

Program debugging method and system Download PDF

Info

Publication number
CN101916223A
CN101916223A CN 201010250337 CN201010250337A CN101916223A CN 101916223 A CN101916223 A CN 101916223A CN 201010250337 CN201010250337 CN 201010250337 CN 201010250337 A CN201010250337 A CN 201010250337A CN 101916223 A CN101916223 A CN 101916223A
Authority
CN
China
Prior art keywords
program
function
macro definition
file name
self
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN 201010250337
Other languages
Chinese (zh)
Inventor
李志刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuxi Vimicro Corp
Original Assignee
Wuxi Vimicro Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuxi Vimicro Corp filed Critical Wuxi Vimicro Corp
Priority to CN 201010250337 priority Critical patent/CN101916223A/en
Publication of CN101916223A publication Critical patent/CN101916223A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a program debugging method applied to an embedded development platform. The method comprises the following steps of: setting a macro definition or custom library function, wherein the macro definition or custom library function comprises a logic used for judging whether a current valve is an expected value or not when a program is run to a point, and if not, printing a current file name and a line number; and adding the macro definition or custom library function at a program point requiring to be inspected. Based on the method, the invention also provides a program debugging system. The invention simplifies the working steps of system developers during designing debugging information by utilizing the macro definition or custom library function mechanism, realizes compact and unique error information output through directly utilizing a predefined macro in the programming language and realizes the quick positioning of a program error position through the debugging information printed after going wrong.

Description

Program debugging method and system
[technical field]
The present invention relates to the software design field, particularly a kind of program debugging method and system.
[background technology]
In the software design field, debugging is a requisite link in the performance history, and there are tangible difference in general desktop operating system and embedded OS on debugging enironment.The former, debugger and debugged program operate in two processes in the identical operations system of same machine often, and debugged program process is controlled, visited to the calling interface that the debugger process provides specially by operating system (ptrace of early stage unix system calls, process filesystem of today etc.).Latter's (being called remote debugging again), in order to provide flexibly, debug easily the interface to the system development personnel, debugger still runs on the application program of general desktop operating system, and debugged program then runs on the embedded OS (also claiming destination OS) based on particular hardware platform.This just brings following problem: how debugger communicates by letter with debugged program, unusually how debugged program produces in time notifies debugger, debugged program is controlled, visited to debugger how, how debugger is discerned the multitask information of relevant debugged program and is controlled a certain particular task, and how debugger handles some information relevant with target hardware platform (as the register information of target platform, the dis-assembling of machine code etc.).In a word, the exploitation of embedded system debugging is the comparison difficulty.
And the most widely used in the prior art a kind of embedded system development debud mode is exported Debugging message by UART interface on the target machine or USB interface exactly on the computer that the system development personnel use.Personnel are when designing program in these system developments, add check mechanism in the position that program error may occur, serve as Debugging message so that print specific character string after program is made mistakes.But there are following shortcomings in this method: 1. because the place that program run may make mistakes is a lot, and function call each time all might be made mistakes theoretically, therefore rigorous program debug should be judged the rreturn value of function call each time.If but each function call all designs once wrong output information, the workload of design mistake output information has just accounted for a big chunk of whole coding work so; 2. a lot of type of errors all are consistent, and for example dynamic assigning memory failure may all can occur in many places of program run.If mistake of the same type is all exported identical error message, then can't find the Error Location rapidly; If print different information, then not only technical difficulty is higher but also workload is also big; 3. the difficulty that designs well-determined output information during owing to actual design is bigger, so cause the system development personnel often to ignore the mistake that some seldom occurs, can cause program to hide some defectives.Simultaneously, the also bad removing of the wrong output information of design also may be retained in the product after the formal volume production of product.
Therefore, demand proposing technical scheme a kind of advanced person, that can overcome above-mentioned shortcoming urgently.
[summary of the invention]
The object of the present invention is to provide a kind of program debugging method and system, it utilizes the automatic generation error information of compiler, helps quick finder Error Location.
In order to reach purpose of the present invention, according to an aspect of the present invention, the invention provides a kind of program debugging method that is applied to embedded development platform, described method comprises: set a macro definition or self-defined built-in function, comprise a logic in described macro definition or the self-defined built-in function, whether the currency when some is expectation value to certain in this logic determines program run, as not being, then prints current file name and row number; Add described macro definition or self-defined built-in function with program position in the needs check.
Further, described printing current file name is to realize by the predefined macro of programming language with capable number.
Further, except printing current file name and row extra, go back the printf name.
Further, described program adopts C language or C Plus Plus to realize.
Further, described macro definition or self-defined built-in function also comprise stopping the present procedure operation after printing current file name is with capable number.
According to a further aspect in the invention, the present invention also provides a kind of program debug system that is applied to embedded development platform, described system comprises: compiler, compiling comprises the debugged program for the treatment of of predetermined macro definition or self-defined built-in function, comprise in described predetermined macro definition or the self-defined built-in function that determining program runs to whether certain currency when some is expectation value, as not being, then print the logic of current file name and row number; And debugger, if described program run during to described some currency be not expectation value, print residing filename of described point and row number.
Further, described debugger is gone back the printf name except printing current file name and row extra.
Further, described program adopts C language or C Plus Plus to realize.
Further, described debugger also stops the present procedure operation after printing current file name is with capable number.
Compared with prior art, the present invention has simplified the job step of system development personnel when design debug information by utilizing macro definition or self-defined built-in function mechanism; The present invention has realized succinct error message output by directly utilizing the predefined macro of programming language inside; The present invention has realized the quick location of program Error Location by the back Debugging message of printing of makeing mistakes (filename, capable number or function name).
[description of drawings]
In conjunction with reaching ensuing detailed description with reference to the accompanying drawings, the present invention will be more readily understood, the structure member that wherein same Reference numeral is corresponding same, wherein:
Fig. 1 is the method flow diagram of program debugging method among the present invention;
Fig. 2 is the job step of macro definition among the present invention or built-in function; With
Fig. 3 is program debug system block diagram in one embodiment among the present invention.
[embodiment]
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments.
Program debugging method of the present invention is mainly used in embedded-development environment, and the programming language that described embedded-development environment uses can be C language or C++.
Please refer to Fig. 1, it shows the method flow diagram of program debugging method 100 among the present invention.Described program debugging method 100 comprises: step 102, set a macro definition or self-defined built-in function, comprise a logic in described macro definition or the self-defined built-in function, whether the currency when some is expectation value to certain in this logic determines program run, as not being, then print current file name and row number; And step 104, add described macro definition or self-defined built-in function at the program position of needs check.
In the programming language of C language and similar type thereof, grand is a kind of pre-service instruction, and it provides a kind of mechanism, can be used for replacing the character string in the source code, and grand " #define " statement of normally using defines.Popular, the system development personnel can with some character strings of often using, constant or the like at the beginning position of software in advance declaration definition represent with a specific character string, when follow-up software design, represent those character strings that have been declared, constant or the like then by this specific character string.When concrete program was compiled, compiler can automatically that this is specific character string replaces with those character string, constants of being declared.In standard C language, compiler inside comprises predefined macros that some often use, such as _ _ FILE__, _ _ LINE__ and _ _ FUNCTION__._ _ FILE__ is the character string literal of the current source code file name of representative; _ _ LINE__ is the integer constant of the row of representative in the current source code number; _ _ FUNCTION__ represents current place function name.Concrete macro definition, the using method of predefined macro it will be understood by those skilled in the art that this paper does not do deep explanation, and particulars can be with reference to the technical documentation of each standard C language.
Make full use of among the present invention predefined macro _ _ FILE__, _ _ LINE__ and _ _ characteristic of FUNCTION__, design a macro definition that is used for debugged program, described macrodefined job step comprises that determining program runs to whether certain currency when some is expectation value, as not being, then utilize predefined macro _ _ FILE__ and _ _ LINE__ prints current file name and row number.Can certainly utilize predefined macro _ _ FUNCTION__ prints current function name.Whether check program is made mistakes and checked three kinds usually during program debug: prerequisite characteristic before 1, code is carried out must be a positive number before entering function A such as variable a; 2, prerequisite characteristic after code is carried out should be a negative such as the rreturn value b of function B; 3, code is carried out the characteristic that front and back can not change, the needs when transmitting parameter such as some variablees between different functions.No matter any, whether the situation in the time of can coming the check program operation by judgment mechanism matches with situation about designing in advance, provides error message when misfitting.The macro definition that step 102 is set is used for just whether check program make mistakes.
For more detailed description the present invention, Fig. 2 further illustrates the macrodefined job step 200 that step 102 is set.Described macrodefined job step 200 comprises: whether step 202, the currency in check program when operation are the expectation value when designing program, if, then carry out step 204, promptly be left intact; If not, then representative program has been made mistakes, and carry out step 206, promptly print the residing filename of current source code and the row number; Shut down procedure continues operation if desired, carry out step 208, interrupts present procedure.
In a specific embodiment, the setting form of described macro definition MMD_ASSERT can be as follows:
#define MMD_ASSERT (_ X_) if (! _ X_)/* * * judge currency whether be expectation value * * */
VIM_UART_Printf (" n Assert error at%S, Line=%d ", _ _ F1LE__, _ _ LINE__); / * * * printing current file name and row * * */
While (1); / * * * makes program be absorbed in endless loop, interrupt run * * */
Wherein _ X_ is used for judging whether currency is expectation value, _ X_ when currency is expectation value for true; Certainly, _ X_ for false, can equal different Rule of judgment according to concrete enforcement environment order _ X_ when currency is not expectation value.Different technician may have different modifications to described macro definition according to concrete applied environment, also may use similar means to realize described macrodefined function, for example utilize self-defined built-in function to replace described macro definition, for example design a header file vim_assert.h, file content is as follows:
int?MMD_ASSERT1(a)
{if(!a)
Printf(“\n?Assert?error?at%S,Line=%d”,__FILE__,__LINE__);
While(1);}}
/ * * * MMD_ASSERT1 can the print file name and row * * */
int?MMD_ASSERT2(b)
{if(!b)
Printf(“\n?Assert?error?at%S,Function=%S”,__FILE__,__FUNCTION__);
While(1);}}
/ * * * MMD_ASSERT2 can the print file name and function name * * */
int?MMD_ASSERT3(c)
{if(!c)
Printf(“\n?Assert?error?at%S,Function=%S,Line=%d。”,__FILE__,__LINE__,__FUNCTION__);
While(1);}}
/ * * * MMD_ASSERT3 can the print file name, row number and function name * * */
Vim_assert.h is placed on the path that compiler can find with this header file, and adds " include<path vim_assert.h〉" at the program header that needs use and also can reach same effect.
In step 104, the position that the system development personnel only need need to check in program suitably adds macro definition or the self-defined built-in function set in the step 102 and gets final product.For example in the program of having stated macro definition MMD_ASSERT, the rreturn value a of function A among the file xxx.c should equal 3, then the next line (this document 16 row) at function A adds MMD_ASSERT (a=3), when a is not equal to 3, program will be returned error message: Assert error at xxx.c, Line=16.
Will be appreciated that, the direct corresponding Error Location of error message of output when the present invention is applied to the embedded system development debugging, the system development personnel can utilize the error message of output to carry out program debug quickly and easily.And when design, do not need as specific design mistake output information in the prior art and fault processing operation, described program debugging method simple and fast.Work as production debugging at last and finish, only the macro definition of software head need be revised as empty getting final product when not needing error message output, significantly reduced system development personnel's workload.
Based on described program debugging method, the present invention also provides a kind of program debug system, is applied to embedded development platform, please refer to Fig. 3, and it shows program debug system 300 block diagram in one embodiment among the present invention.Described program debug system 300 comprises compiler 302 and debugger 304.
Described compiler 302 compilings comprise the debugged program for the treatment of of predetermined macro definition or self-defined built-in function, comprise in described predetermined macro definition or the self-defined built-in function whether the currency that determining program runs to any is expectation value, as not being, then print the logic of current file name and row number.Because the described debugged program for the treatment of adopts C language or C++ to realize usually, so the compile mode of described compiler 302 also can be identical with the compiler of standard C language or C++, described compile mode also comprises from whole compilation processes of (executables) of source code (sourcecode) → pretreater (preprocessor) → compiler (compiler) → assembly routine (assembler) → object code (object code) → linker (Linker) → executable program, translates into the direct object code (being generally low-level language or machine language) that can be carried out by computing machine or virtual machine up to source code.
If described program run during to described some currency be not expectation value, then described debugger 304 is printed the filename at described some place and row number.Certainly according to different logic in described predetermined macro definition or the self-defined built-in function, described debugger can also the printf name and is stopped the present procedure operation so that the system development personnel debug when program is made mistakes.
Above-mentioned explanation has fully disclosed the specific embodiment of the present invention.It is pointed out that and be familiar with the scope that any change that the person skilled in art does the specific embodiment of the present invention does not all break away from claims of the present invention.Correspondingly, the scope of claim of the present invention also is not limited only to described embodiment.

Claims (9)

1. a program debugging method is applied to embedded development platform, it is characterized in that it comprises:
Set a macro definition or self-defined built-in function, comprise a logic in described macro definition or the self-defined built-in function, whether the currency when some is expectation value to certain in this logic determines program run, as not being, then prints current file name and row number; With
Program position in the needs check adds described macro definition or self-defined built-in function.
2. program debugging method according to claim 1 is characterized in that, described printing current file name is to realize by the predefined macro of programming language with capable number.
3. program debugging method according to claim 1 is characterized in that, except printing current file name and row extra, goes back the printf name.
4. program debugging method according to claim 1 is characterized in that, described program adopts C language or C Plus Plus to realize.
5. program debugging method according to claim 1 is characterized in that, described macro definition or self-defined built-in function also comprise stopping the present procedure operation after printing current file name is with capable number.
6. a program debug system is applied to embedded development platform, it is characterized in that it comprises:
Compiler, compiling comprises the debugged program for the treatment of of predetermined macro definition or self-defined built-in function, comprise in described predetermined macro definition or the self-defined built-in function that determining program runs to whether certain currency when some is expectation value, as not being, then print the logic of current file name and row number; With
Debugger, if described program run during to described some currency be not expectation value, print residing filename of described point and row number.
7. program debug according to claim 6 system is characterized in that, described debugger is gone back the printf name except printing current file name and row extra.
8. program debug according to claim 6 system is characterized in that, described program adopts C language or C Plus Plus to realize.
9. program debug according to claim 6 system is characterized in that, described debugger also stops the present procedure operation after printing current file name and row number.
CN 201010250337 2010-08-11 2010-08-11 Program debugging method and system Pending CN101916223A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 201010250337 CN101916223A (en) 2010-08-11 2010-08-11 Program debugging method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 201010250337 CN101916223A (en) 2010-08-11 2010-08-11 Program debugging method and system

Publications (1)

Publication Number Publication Date
CN101916223A true CN101916223A (en) 2010-12-15

Family

ID=43323740

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 201010250337 Pending CN101916223A (en) 2010-08-11 2010-08-11 Program debugging method and system

Country Status (1)

Country Link
CN (1) CN101916223A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102402478A (en) * 2010-09-08 2012-04-04 康佳集团股份有限公司 Software testing method and device
CN106776293A (en) * 2016-11-29 2017-05-31 天脉聚源(北京)传媒科技有限公司 A kind of method and device of program segment detection
CN106776304A (en) * 2016-12-05 2017-05-31 云鸟(上海)能源科技有限公司 Method based on printout information is controlled in multithreading exploitation under built-in Linux
CN109144849A (en) * 2018-07-23 2019-01-04 武汉虹信通信技术有限责任公司 A kind of embedded software adjusting, measuring method
CN110704306A (en) * 2019-09-09 2020-01-17 平安普惠企业管理有限公司 Assertion processing method, device, equipment and storage medium in test
CN117370214A (en) * 2023-12-01 2024-01-09 珠海格力电器股份有限公司 Program debugging method and device of controller and storage medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101046766A (en) * 2006-04-24 2007-10-03 华为技术有限公司 Debugging method and device for telecommunication service development based on model drive

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101046766A (en) * 2006-04-24 2007-10-03 华为技术有限公司 Debugging method and device for telecommunication service development based on model drive

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
《气象教育与科技》 20001231 林科学 程序调试中的错误捕获方法 31~35 1-9 , 第55期 2 *
《电脑编程技巧与维护》 20051231 一块三毛钱 Win32汇编程序源码级调试 83~87 1-9 , 第11期 2 *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102402478A (en) * 2010-09-08 2012-04-04 康佳集团股份有限公司 Software testing method and device
CN106776293A (en) * 2016-11-29 2017-05-31 天脉聚源(北京)传媒科技有限公司 A kind of method and device of program segment detection
CN106776304A (en) * 2016-12-05 2017-05-31 云鸟(上海)能源科技有限公司 Method based on printout information is controlled in multithreading exploitation under built-in Linux
CN109144849A (en) * 2018-07-23 2019-01-04 武汉虹信通信技术有限责任公司 A kind of embedded software adjusting, measuring method
CN110704306A (en) * 2019-09-09 2020-01-17 平安普惠企业管理有限公司 Assertion processing method, device, equipment and storage medium in test
CN110704306B (en) * 2019-09-09 2024-03-22 武汉安辰鑫信息科技有限公司 Assertion processing method, device, equipment and storage medium in test
CN117370214A (en) * 2023-12-01 2024-01-09 珠海格力电器股份有限公司 Program debugging method and device of controller and storage medium
CN117370214B (en) * 2023-12-01 2024-04-19 珠海格力电器股份有限公司 Program debugging method and device of controller and storage medium

Similar Documents

Publication Publication Date Title
Stallman Using and porting GNU CC
Stallman Using and porting the GNU compiler collection
US9134966B2 (en) Management of mixed programming languages for a simulation environment
US10540262B2 (en) Using edit and continue to dynamically set and unset optimizations in source code while debugging
CN107526625B (en) Java intelligent contract security detection method based on bytecode inspection
US9003367B2 (en) Specific debug trace collecting
Stallman Using the gnu compiler collection
US8645938B2 (en) System and method for replacing code
CN101916223A (en) Program debugging method and system
US8806436B2 (en) Systems and methods for debugging applications using dual code generation
JP2000181725A (en) Method and system for altering executable code and giving addition function
US7721250B2 (en) System and method for interactive and integrated software development process and phases
US20110126179A1 (en) Method and System for Dynamic Patching Software Using Source Code
Wright Automatic generation of C from Event-B
WO2015117434A1 (en) Method and device for manufacturing patch, and method and device for activating patch
CN104298594A (en) Automatic detection and positioning method for source code mid-value miscalculation
CN104035778A (en) Android application program development method
US20080127118A1 (en) Method and system for dynamic patching of software
US10452364B2 (en) Method and system for preparing code to be executed by programmable control devices
Yodaiken How ISO C became unusable for operating systems development
CN109144849B (en) Embedded software debugging method
CN103631585A (en) Method and system for developing application program
WO2023038715A1 (en) Hot reloading a running application with an unsaved source code change
US11921614B2 (en) System and method for developing, testing and debugging software for microcontrollers
Shin et al. Arve: aspect-oriented runtime verification environment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C12 Rejection of a patent application after its publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20101215