Summary of the invention
In view of this, the embodiment of the invention provides the detection method and terminal device of a kind of pair of uninitialized variable, it can
Method to pass through script automatic detection realizes the global variable of no initializtion in quickly detection embedded software.
The first aspect of the embodiment of the present invention provides the detection method of a kind of pair of uninitialized variable, comprising:
System under test (SUT) is resetted, pointer is made to be directed toward the principal function of the system under test (SUT);
It is stored in the system under test (SUT) and fills specified data in the application heap of global variable;
So that pointer is run to the function position that initialization of variable finishes, reads the memory segment data, obtain the overall situation
The corresponding internal storage location sum of the title of variable and the unit of specified data sum;
When the corresponding internal storage location sum of the title of the global variable and the identical unit of specified data sum,
Then determine that the global variable is the global variable of no initializtion.
In one embodiment, in the reset system under test (SUT), it is directed toward pointer before the principal function of the system under test (SUT), also
Include:
The Integrated Development Environment IDE of embeded processor has debugging server script DSS kit;
It calls and executes the DSS kit;
The reset system under test (SUT), makes pointer be directed toward the principal function of the system under test (SUT), comprising:
Script debugging reset instruction is called, system under test (SUT) is resetted, pointer is made to be directed toward the principal function of the system under test (SUT).
In one embodiment, it is stored in the system under test (SUT) and fills specified data in the application heap of global variable, comprising:
The filling instruction of script debugging memory is called, in the system under test (SUT) in .ebss sections of random access memory ram
All internal storage locations fill specified data.
In one embodiment, it fills and instructs in the calling script debugging memory .ebss sections in the system under test (SUT)
In random access memory ram after all specified data of internal storage locations filling, further includes:
Script debugging break-poing instruction is called, initialization function the latter sentence setting in the tested software system is disconnected
Point;
Call script debugging full speed running instruction, tested software system described in full speed running to breakpoint sentence.
In one embodiment, described to read the application heap, obtain the corresponding internal storage location of title of the global variable
The unit sum of the total and described specified data, comprising:
Script debugging memory read instruction is called, all specified data of the .ebss sections of memory ram unit are read;
It calls script debugging variable to read instruction, reads the title of the corresponding global variable of the .ebss sector address;
When getting the title of the global variable, the title pair of the accumulative global variable of the first counter is obtained
The internal storage location sum answered, and obtain the unit sum of the accumulative specified data of the second counter.
In one embodiment, described when the corresponding internal storage location sum of the title of the global variable and the specified data
Unit sum it is identical when, it is determined that the global variable be no initializtion global variable, comprising:
Detect whether to read the title of next global variable;
When reading the title of next global variable, then the corresponding internal storage location of title of the global variable is detected
Whether the unit sum of the total and described specified data is identical;
When the corresponding internal storage location sum of the title of the global variable and the identical unit of specified data sum,
Determine that the corresponding global variable in the memory field of current detection is the global variable of no initializtion.
In one embodiment, the method also includes:
It, will be described when the corresponding global variable in the memory field for determining current detection is the global variable of no initializtion
The global variable of no initializtion is sent to the corresponding control unit of control window, and first counter and described second are counted
Number device is assigned a value of 0;
When the unread title to next global variable, or when the corresponding interior deposit receipt of the title of the global variable
When first total not identical with the unit sum of the specified data, or first counter and second counter are assigned
After value is 0, detect whether .ebss sections of the address is the last one unit;
When .ebss sections of the address is the last one unit, script debugging reset instruction is called, to the tested system
System is resetted.
The second aspect of the embodiment of the present invention provides the detection device of a kind of pair of uninitialized variable, comprising:
Reseting module makes pointer be directed toward the principal function of the system under test (SUT) for resetting system under test (SUT);
Module is filled, specified data are filled in the application heap for storing global variable in the system under test (SUT);
Read module reads the memory segment data for making pointer run to the function position that initialization of variable finishes,
Obtain the corresponding internal storage location sum of title of the global variable and the unit sum of the specified data;
Determining module, the list for title corresponding internal storage location sum and the specified data when the global variable
When first total identical, it is determined that the global variable is the global variable of no initializtion.
The third aspect of the embodiment of the present invention provides a kind of terminal device, including memory, processor and is stored in
In the memory and the computer program that can run on the processor, when the processor executes the computer program
Realize provided in above-described embodiment to the detection method of uninitialized variable the step of.
The fourth aspect of the embodiment of the present invention provides a kind of computer readable storage medium, the computer-readable storage
Media storage has a computer program, the computer program realized when being executed by processor provided in above-described embodiment to not just
The step of detection method of beginningization variable.
Existing beneficial effect is the embodiment of the present invention compared with prior art: the embodiment of the present invention is by resetting tested system
System, makes pointer be directed toward the principal function of the system under test (SUT);It stores in the system under test (SUT) and is filled in the application heap of global variable
Specified data;So that pointer is run to the function position that initialization of variable finishes, reads the memory segment data, obtain the overall situation
The corresponding internal storage location sum of the title of variable and the unit of specified data sum;When the title of the global variable is corresponding
Internal storage location sum and the specified data unit sum it is identical when, it is determined that the global variable be no initializtion it is complete
The global variable for quickly detecting no initializtion in embedded software may be implemented in office's variable.And entire detection process, is not required to volume
Outer occupancy resources of chip, testing result is accurate and fireballing feature.
Specific embodiment
In being described below, for illustration and not for limitation, the tool of such as particular system structure, technology etc is proposed
Body details, to understand thoroughly the embodiment of the present invention.However, it will be clear to one skilled in the art that there is no these specific
The present invention also may be implemented in the other embodiments of details.In other situations, it omits to well-known system, device, electricity
The detailed description of road and method, in case unnecessary details interferes description of the invention.
In order to illustrate technical solutions according to the invention, the following is a description of specific embodiments.
The embodiment of the present invention provides the detection method of a kind of pair of uninitialized variable, as shown in Figure 1, this method includes following
Step:
Step 101, system under test (SUT) is resetted, pointer is made to be directed toward the principal function of the system under test (SUT).
Optionally, before resetting system under test (SUT), importing debugging server script (Debug Server Scripting,
DSS) kit creates script environment object, obtains debugging server and starts debugging server dialogue.It is automatic to call script tune
Reset instruction is tried, system under test (SUT) is resetted, pointer is made to be directed toward system under test (SUT) main principal function.
The executing subject of this method can be computer terminal, can be computer readable storage medium, and this method is simultaneously unlimited
It is set to above-mentioned executing subject, the above is only illustrate.
Optionally, the test carrier that this method requires is the integrated of embedded chip minimum system plate and embeded processor
It develops environment (Integrated development environment, IDE), the two uses emulator (Joint Test
Action Group, JTAG) it connects and carries out in-circuit emulation.Software development environment has DSS functional interface, and scripting language is general
Support the high-level languages such as Java or Javasript, Perl, Python, TCL.DSS kit, can be in software development environment
Replaced using directive script and be manually operated, such as software reset, setting breakpoint, full speed running, single step run, memory filling, memory
It reads and memory address is to functions such as the readings of dependent variable.Therefore, shell script is write by certain logical order, it can be most
Automatic test is realized under mini system plate simulated environment.For example, calling script debugging reset instruction in this step automatically, quilt is resetted
Examining system makes pointer be directed toward system under test (SUT) main principal function.
Step 102, it is stored in the system under test (SUT) and fills specified data in the application heap of global variable.
It is automatic to call the filling instruction of script debugging memory .ebss sections of the random access memory in the system under test (SUT)
All internal storage locations fill specified data in (random access memory, RAM).
Optionally, specified data can be the data such as 0x55AA..ebss section in embedded software is for global variable
Storage.
It optionally, further include automatic calling script debugging break-poing instruction after this step, in the tested software system
In initialization function the latter sentence be arranged breakpoint;
It is automatic to call script debugging full speed running instruction, tested software system described in full speed running to breakpoint sentence.
Step 103, so that pointer is run to the function position that initialization of variable finishes, read the memory segment data, obtain
The corresponding internal storage location sum of the title of the global variable and the unit of specified data sum.
Optionally, this step includes: automatic calling script debugging memory read instruction, and it is all to read the .ebss sections of RAM
The corresponding all specified data of internal storage location;It is automatic that script debugging variable is called to read instruction, read the .ebss sector address pair
The title for the global variable answered;
When getting the title of the global variable, the title pair of the accumulative global variable of the first counter is obtained
The internal storage location sum answered, and the unit sum of the accumulative specified data of the second counter is obtained, optionally, it can use
Var_Cnt indicates the corresponding internal storage location sum of the title of global variable, and the specified data of filling can be indicated with Fill_Cnt
Unit sum;
Step 104, when the unit of the corresponding internal storage location sum of the title of the global variable and the specified data is total
When number is identical, it is determined that the global variable is the global variable of no initializtion.
Optionally, as Fill_Cnt=Var_Cnt, it is determined that the corresponding global variable in the memory field of current detection
For the global variable of no initializtion, it is single that the global variable of the no initializtion is sent to the corresponding control of control window later
Member, and first counter and second counter are assigned a value of preset value, optionally, preset value can be 0.Thus
The global variable of all no initializtions can be obtained in control window, and global variable can be accurately positioned.
The detection method of a kind of pair of uninitialized variable provided in an embodiment of the present invention, by being detected software systems
All internal storage locations of .ebss section RAM carry out the filling of specified data (0x55AA), obtain global variable title it is corresponding in
Memory cell sum and the unit of the specified data of filling sum then can determine the overall situation of current detection when the two sum is identical
Variable is the global variable of no initializtion.Entire detection process, have it is easy to operate, be not required to additional temporary resources of chip, detect
As a result the features such as accurate and speed is fast.
The embodiment of the present invention provides another detection method to uninitialized variable, as shown in Fig. 2, this method comprises:
Step 201, the Integrated Development Environment IDE of embeded processor has debugging server script DSS kit.
Optionally, the test carrier that this method requires is the integrated of embedded chip minimum system plate and embeded processor
Environment ID E is developed, the two is connected using emulator JTAG and carries out in-circuit emulation.The Integrated Development Environment of embeded processor
IDE has DSS functional interface, and scripting language generally supports the high-level languages such as Java or Javasript, Perl, Python, TCL.
DSS kit can use directive script and replace manual operation in software development environment, and such as software reset is arranged breakpoint, is complete
Fast operation, single step run, memory filling, memory is read and memory address is to functions such as the readings of dependent variable.Therefore, by certain
Logical order writes shell script, can realize automatic test under minimum system plate simulated environment.For example, in this step certainly
It is dynamic to call script debugging reset instruction, system under test (SUT) is resetted, pointer is made to be directed toward system under test (SUT) main principal function.
Optionally, DSS kit is imported, script environment object is created.
Step 202, it calls and executes the DSS kit.
Optionally, debugging server script is obtained, debugging server dialogue is started.
Step 203, script debugging reset instruction is called, system under test (SUT) is resetted, pointer is made to be directed toward the master of the system under test (SUT)
Function.
When running DSS kit in this step, script debugging reset instruction can be called automatically.
Step 204, the filling instruction of script debugging memory is called .ebss sections of arbitrary access is deposited in the system under test (SUT)
All internal storage locations fill specified data in reservoir RAM.
Optionally, the filling instruction of script debugging memory is called automatically, to all memories of .ebss sections in system under test (SUT) of RAM
Unit carries out the filling of specified data.Optionally, specified data can be 0x55AA..ebss sections of embedded software are used for
The storage of global variable.
Step 205, script debugging break-poing instruction, initialization function the latter language in the tested software system are called
Sentence setting breakpoint.
The effect of breakpoint is set to terminate test program.
Step 206, script debugging full speed running instruction, tested software system described in full speed running to breakpoint sentence are called.
Step 207, script debugging memory read instruction is called, all specified of the .ebss sections of memory ram unit is read
Data.
This step is to read all specified data being filled in .ebss sections of RAM.
Step 208, it calls script debugging variable to read instruction, reads the corresponding global change of the .ebss sector address
The title of amount.
Step 209, when getting the title of the global variable, the accumulative global variable of the first counter is obtained
Title corresponding internal storage location sum, and obtain the unit sum of the accumulative specified data of the second counter.
It should be noted that here the first counter and the second counter merely to distinguish counter carry out name,
It is not that function ranking is carried out to counter.
Step 210, detect whether to read the title of next global variable.
Step 211, when reading the title of next global variable, then the title for detecting the global variable is corresponding
Whether internal storage location sum and the unit sum of the specified data are identical.
Optionally, judge whether Fill_Cnt is equal with Var_Cnt.
Step 212, when the unit of the corresponding internal storage location sum of the title of the global variable and the specified data is total
When number is identical, determine that the corresponding global variable in the memory field of current detection is the global variable of no initializtion.
Step 213, the global variable of the no initializtion is sent to the corresponding control unit of control window.
Optionally, this step is to show the global variable of the no initializtion determined in control window, so as to each complete
Office's variable is positioned, then by two counter O resets.
Step 214, first counter and second counter are assigned a value of 0.
It should be noted that after executing step 211, when the corresponding internal storage location sum of the title of the global variable and institute
State specified data unit sum it is not identical when, execute step 214.
Step 215 .ebss sections of the next address is read.
Optionally, execute step 210 after, when it is unread arrive next global variable title when, execution step 215, i.e.,
.ebss sections of the next address is read, and then continues to execute step 216.
Step 216, detect whether .ebss sections of the address is the last one unit.
Step 217, when .ebss sections of the address is the last one unit, script debugging reset instruction is called, to institute
System under test (SUT) is stated to be resetted.
When .ebss sections of addresses are not the last one units, step 208 is executed.
The embodiment of the invention provides the detection methods of a kind of pair of uninitialized variable, carry out by using DSS kit
The global variable position of no initializtion in quickly positioning embedded software is realized in automatic detection, so as to reduce software leakage
Hole, and save the debug time of software developer.
The embodiment of the present invention provides the detection device of a kind of pair of uninitialized variable, as shown in figure 3, the device includes: multiple
Position module 301, fills module 302, read module 303, determining module 304.
Reseting module 301 makes pointer be directed toward the principal function of the system under test (SUT) for resetting system under test (SUT).
Optionally, described device further includes processing module, for receiving simultaneously installation and debugging server script DSS kit,
And execute the DSS kit.
The reseting module 301 resets system under test (SUT), makes pointer pointing system for calling script debugging reset instruction
Principal function.
Module 302 is filled, specified data are filled in the application heap for storing global variable in the system under test (SUT).
Optionally, the filling module 302, for calling the filling instruction of script debugging memory, in the system under test (SUT)
.ebss all internal storage locations fill specified data in the random access memory ram of section.
It can also include calling module, for calling script debugging disconnected between filling module 302 and read module 303
Breakpoint is arranged in point instruction, initialization function the latter sentence in the tested software system;Script debugging is called to transport at full speed
Row instructs, tested software system described in full speed running to breakpoint sentence.
Read module 303 reads the memory number of segment for making pointer run to the function position that initialization of variable finishes
According to the unit of the corresponding internal storage location sum of title and the specified data that obtain the global variable is total.
Optionally, when pointer runs to the function position that initialization of variable finishes, the read module 303, for calling
Script debugging memory read instruction reads all specified data of the .ebss sections of memory ram unit;Script debugging is called to become
Amount reads instruction, reads the title of the corresponding global variable of the .ebss sector address;When getting the global variable
When title, the corresponding internal storage location sum of title of the accumulative global variable of the first counter is obtained, and obtains the second meter
The unit sum of the accumulative specified data of number device.
When the corresponding internal storage location sum of the title of the global variable and the identical unit of specified data sum,
Determining module 304 is used to then determine the global variable that the global variable is no initializtion.
Optionally, the determining module 304, for detecting whether reading the title of next global variable;
When reading the title of next global variable, then the corresponding internal storage location of title of the global variable is detected
Whether the unit sum of the total and described specified data is identical;
When the corresponding internal storage location sum of the title of the global variable and the identical unit of specified data sum,
Determine that the corresponding global variable in the memory field of current detection is the global variable of no initializtion.
Further, described device is also used to: when the corresponding global variable in the memory field for determining current detection is not
When the global variable of initialization, the global variable of the no initializtion is sent to the corresponding control unit of control window, and will
First counter and second counter are assigned a value of 0;
When the unread title to next global variable, or when the corresponding interior deposit receipt of the title of the global variable
When first total not identical with the unit sum of the specified data, or first counter and second counter are assigned
After value is 0, detect whether .ebss sections of the address is the last one unit, when .ebss sections of the address is last
When a unit, script debugging reset instruction is called, the system under test (SUT) is resetted.
The detection device of a kind of pair of uninitialized variable provided in an embodiment of the present invention, by filling module be detected it is soft
All internal storage locations of .ebss section RAM in part system carry out the filling of specified data (0x55AA), and read module obtains global become
The corresponding internal storage location sum of the title of amount and the unit of the specified data of filling sum, when the two sum is identical, it is determined that
Module can determine that the global variable of current detection is the global variable of no initializtion.Entire detection process, have it is easy to operate, no
The features such as additional temporary resources of chip of need, testing result is accurate and speed is fast.
It should be understood that the size of the serial number of each step is not meant that the order of the execution order in above-described embodiment, each process
Execution sequence should be determined by its function and internal logic, the implementation process without coping with the embodiment of the present invention constitutes any limit
It is fixed.
Fig. 4 is the schematic diagram for the terminal device that one embodiment of the invention provides.As shown in figure 4, the terminal of the embodiment is set
Standby 4 include: processor 401, memory 402 and are stored in the memory 402 and can run on the processor 401
Computer program 403, such as the detection program to uninitialized variable.The processor 401 executes the computer program
The step in the detection method embodiment of above-mentioned each pair of uninitialized variable, such as step 101 shown in FIG. 1 are realized when 403
To 104 or step 201 shown in Fig. 2 to step 217, the realization when processor 401 executes the computer program 403
The function of each module in above-mentioned each Installation practice, such as the function of module 301 to 304 shown in Fig. 3.
Illustratively, the computer program 403 can be divided into one or more modules, one or more of
Module is stored in the memory 402, and is executed by the processor 401, to complete the present invention.It is one or more of
Module can be the series of computation machine program instruction section that can complete specific function, and the instruction segment is for describing the computer
Implementation procedure of the program 403 in the detection device to uninitialized variable or terminal device 4.For example, the calculating
Machine program 403 can be divided into reseting module 301, fill module 302, read module 303, determining module 304, each module tool
Body function is as shown in figure 3, this is no longer going to repeat them.
The terminal device 4 can be the calculating such as desktop PC, notebook, palm PC and cloud server and set
It is standby.The terminal device may include, but be not limited only to, processor 401, memory 402.It will be understood by those skilled in the art that
Fig. 4 is only the example of terminal device 4, does not constitute the restriction to terminal device 4, may include more more or fewer than illustrating
Component, perhaps combines certain components or different components, for example, the terminal device can also include input-output equipment,
Network access equipment, bus etc..
Alleged processor 401 can be central processing unit (Central Processing Unit, CPU), can also be
Other general processors, digital signal processor (Digital Signal Processor, DSP), specific integrated circuit
(Application Specific Integrated Circuit, ASIC), ready-made programmable gate array (Field-
Programmable Gate Array, FPGA) either other programmable logic device, discrete gate or transistor logic,
Discrete hardware components etc..General processor can be microprocessor or the processor is also possible to any conventional processor
Deng.
The memory 402 can be the internal storage unit of the terminal device 4, for example, terminal device 4 hard disk or
Memory.The memory 402 is also possible to the External memory equipment of the terminal device 4, such as is equipped on the terminal device 4
Plug-in type hard disk, intelligent memory card (Smart Media Card, SMC), secure digital (Secure Digital, SD) card,
Flash card (Flash Card) etc..Further, the memory 402 can also have been deposited both the inside including the terminal device 4
Storage unit also includes External memory equipment.The memory 402 is for storing the computer program and the terminal device 4
Other required programs and data.The memory 402, which can be also used for temporarily storing, have been exported or will export
Data.
It is apparent to those skilled in the art that for convenience of description and succinctly, only with above-mentioned each function
Can unit, module division progress for example, in practical application, can according to need and by above-mentioned function distribution by different
Functional unit, module are completed, i.e., the internal structure of described device is divided into different functional unit or module, more than completing
The all or part of function of description.Each functional unit in embodiment, module can integrate in one processing unit, can also
To be that each unit physically exists alone, can also be integrated in one unit with two or more units, it is above-mentioned integrated
Unit both can take the form of hardware realization, can also realize in the form of software functional units.In addition, each function list
Member, the specific name of module are also only for convenience of distinguishing each other, the protection scope being not intended to limit this application.Above system
The specific work process of middle unit, module, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
In the above-described embodiments, it all emphasizes particularly on different fields to the description of each embodiment, is not described in detail or remembers in some embodiment
The part of load may refer to the associated description of other embodiments.
Those of ordinary skill in the art may be aware that list described in conjunction with the examples disclosed in the embodiments of the present disclosure
Member and algorithm steps can be realized with the combination of electronic hardware or computer software and electronic hardware.These functions are actually
It is implemented in hardware or software, the specific application and design constraint depending on technical solution.Professional technician
Each specific application can be used different methods to achieve the described function, but this realization is it is not considered that exceed
The scope of the present invention.
In embodiment provided by the present invention, it should be understood that disclosed device/terminal device and method, it can be with
It realizes by another way.For example, device described above/terminal device embodiment is only schematical, for example, institute
The division of module or unit is stated, only a kind of logical function partition, there may be another division manner in actual implementation, such as
Multiple units or components can be combined or can be integrated into another system, or some features can be ignored or not executed.Separately
A bit, shown or discussed mutual coupling or direct-coupling or communication connection can be through some interfaces, device
Or the INDIRECT COUPLING or communication connection of unit, it can be electrical property, mechanical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit
The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple
In network unit.It can select some or all of unit therein according to the actual needs to realize the mesh of this embodiment scheme
's.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit
It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list
Member both can take the form of hardware realization, can also realize in the form of software functional units.
If the integrated module/unit be realized in the form of SFU software functional unit and as independent product sale or
In use, can store in a computer readable storage medium.Based on this understanding, the present invention realizes above-mentioned implementation
All or part of the process in example method, can also instruct relevant hardware to complete, the meter by computer program
Calculation machine program can be stored in a computer readable storage medium, the computer program when being executed by processor, it can be achieved that on
The step of stating each embodiment of the method.Wherein, the computer program includes computer program code, the computer program
Code can be source code form, object identification code form, executable file or certain intermediate forms etc..Computer-readable Jie
Matter may include: can carry the computer program code any entity or device, recording medium, USB flash disk, mobile hard disk,
Magnetic disk, CD, computer storage, read-only memory (ROM, Read-Only Memory), random access memory (RAM,
Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium etc..It should be noted that described
The content that computer-readable medium includes can carry out increasing appropriate according to the requirement made laws in jurisdiction with patent practice
Subtract, such as does not include electric carrier signal and electricity according to legislation and patent practice, computer-readable medium in certain jurisdictions
Believe signal.
Embodiment described above is merely illustrative of the technical solution of the present invention, rather than its limitations;Although referring to aforementioned reality
Applying example, invention is explained in detail, those skilled in the art should understand that: it still can be to aforementioned each
Technical solution documented by embodiment is modified or equivalent replacement of some of the technical features;And these are modified
Or replacement, the spirit and scope for technical solution of various embodiments of the present invention that it does not separate the essence of the corresponding technical solution should all
It is included within protection scope of the present invention.