CN109902001B - Method for detecting uninitialized variable and terminal equipment - Google Patents

Method for detecting uninitialized variable and terminal equipment Download PDF

Info

Publication number
CN109902001B
CN109902001B CN201910111480.1A CN201910111480A CN109902001B CN 109902001 B CN109902001 B CN 109902001B CN 201910111480 A CN201910111480 A CN 201910111480A CN 109902001 B CN109902001 B CN 109902001B
Authority
CN
China
Prior art keywords
memory
total number
global variable
global
units
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.)
Active
Application number
CN201910111480.1A
Other languages
Chinese (zh)
Other versions
CN109902001A (en
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.)
Xiamen Kehua Hengsheng Co Ltd
Zhangzhou Kehua Technology Co Ltd
Original Assignee
Xiamen Kehua Hengsheng Co Ltd
Zhangzhou Kehua Technology Co Ltd
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 Xiamen Kehua Hengsheng Co Ltd, Zhangzhou Kehua Technology Co Ltd filed Critical Xiamen Kehua Hengsheng Co Ltd
Priority to CN201910111480.1A priority Critical patent/CN109902001B/en
Publication of CN109902001A publication Critical patent/CN109902001A/en
Application granted granted Critical
Publication of CN109902001B publication Critical patent/CN109902001B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention is suitable for the technical field of embedded software detection, and provides a method for detecting uninitialized variables and terminal equipment, wherein the method comprises the following steps: resetting the tested system to enable a pointer to point to the main function of the tested system; filling specified data in a memory segment for storing global variables in the tested system; enabling a pointer to run to a function position where variable initialization is finished, reading the memory segment data, and obtaining the total number of memory units corresponding to the name of the global variable and the total number of units of the specified data; and when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the designated data, determining that the global variables are uninitialized global variables. The method can realize the rapid detection of uninitialized global variables in the embedded software by a script automatic detection method.

Description

Method for detecting uninitialized variable and terminal equipment
Technical Field
The invention belongs to the technical field of embedded unit testing, and particularly relates to a method for detecting uninitialized variables and terminal equipment.
Background
Before the embedded software system runs, the referenced global variable needs to be declared and initialized. If the global variable is not initialized before the variable is referenced, its initial value is not fixed. When the global variable is referred, the operation result is unpredictable, and the operation phenomena are different every time, so that economic loss is possibly brought, difficulty is brought to problem positioning for software developers, software bugs cannot be searched completely, and the time investment of the software developers for debugging programs is increased.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method for detecting an uninitialized variable and a terminal device, which can implement rapid detection of an uninitialized global variable in embedded software by using a script automatic detection method.
A first aspect of an embodiment of the present invention provides a method for detecting an uninitialized variable, including:
resetting the tested system to enable a pointer to point to a main function of the tested system;
filling specified data in a memory segment for storing global variables in the tested system;
enabling a pointer to run to a function position where variable initialization is finished, reading the memory segment data, and obtaining the total number of memory units corresponding to the name of the global variable and the total number of units of the specified data;
and when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the designated data, determining that the global variables are uninitialized global variables.
In an embodiment, before the resetting the system under test and pointing a pointer to the main function of the system under test, the method further includes:
the integrated development environment IDE of the embedded processor is provided with a debugging server script DSS toolkit;
invoking execution of the DSS toolkit;
the resetting the system under test to make the pointer point to the main function of the system under test includes:
and calling a script debugging reset instruction, resetting the tested system and enabling the pointer to point to the main function of the tested system.
In an embodiment, filling specified data in a memory segment storing a global variable in the system under test includes:
and calling a script debugging memory filling instruction, and filling specified data in all memory units in the RAM of the ebss section in the system to be tested.
In an embodiment, after the invoking script debugs the memory filling instruction, in the system under test, after all the memory units in the RAM of the ebss section are filled with the specified data, the method further includes:
calling a script debugging breakpoint instruction, and setting a breakpoint in a statement behind an initialization function in the tested software system;
and calling a script debugging full-speed running instruction, and running the tested software system to a breakpoint statement at full speed.
In an embodiment, the reading the memory segment, and obtaining the total number of memory cells corresponding to the name of the global variable and the total number of cells of the specified data includes:
calling a script debugging memory reading instruction, and reading all specified data of the memory unit of the ebss section RAM;
calling a script debugging variable reading instruction, and reading the name of the global variable corresponding to the ebss section address;
and when the name of the global variable is acquired, acquiring the total number of memory units corresponding to the name of the global variable accumulated by a first counter, and acquiring the total number of units of the specified data accumulated by a second counter.
In an embodiment, when the total number of memory cells corresponding to the name of the global variable is the same as the total number of cells of the designated data, determining that the global variable is an uninitialized global variable includes:
detecting whether the name of the next global variable is read or not;
when the name of the next global variable is read, detecting whether the total number of memory units corresponding to the name of the global variable is the same as the total number of units of the specified data or not;
and when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the specified data, determining that the global variables corresponding to the currently detected memory area are uninitialized global variables.
In an embodiment, the method further comprises:
when the global variable corresponding to the currently detected memory area is determined to be an uninitialized global variable, sending the uninitialized global variable to a control unit corresponding to a control window, and assigning the first counter and the second counter to be 0;
when the name of the next global variable is not read, or when the total number of memory units corresponding to the name of the global variable is different from the total number of units of the specified data, or after the first counter and the second counter are assigned to be 0, whether the address of the ebss section is the last unit is detected;
and when the address of the ebss section is the last unit, calling a script debugging reset instruction to reset the tested system.
A second aspect of an embodiment of the present invention provides an apparatus for detecting an uninitialized variable, including:
the reset module is used for resetting the tested system to enable the pointer to point to the main function of the tested system;
the filling module is used for filling specified data in a memory segment for storing the global variable in the tested system;
the reading module is used for enabling the pointer to run to a function position where the variable initialization is finished, reading the memory segment data, and acquiring the total number of memory units corresponding to the name of the global variable and the total number of units of the specified data;
and the determining module is used for determining the global variable as the uninitialized global variable when the total number of the memory units corresponding to the names of the global variable is the same as the total number of the units of the specified data.
A third aspect of the embodiments of the present invention provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the method for detecting uninitialized variables provided in the above embodiments when executing the computer program.
A fourth aspect of embodiments of the present invention provides a computer-readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method for detecting uninitialized variables provided in the above-described embodiments.
Compared with the prior art, the embodiment of the invention has the following beneficial effects: the embodiment of the invention leads the pointer to point to the main function of the system to be tested by resetting the system to be tested; filling specified data in a memory segment for storing global variables in the tested system; enabling a pointer to run to a function position where the variable initialization is finished, reading the data of the memory segment, and acquiring the total number of memory units corresponding to the name of the global variable and the total number of units of the specified data; when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the designated data, the global variables are determined to be uninitialized global variables, and the uninitialized global variables in the embedded software can be quickly detected. And the whole detection process does not need to additionally occupy chip resources, and the detection result is accurate and fast.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic flow chart of an implementation of a method for detecting an uninitialized variable according to an embodiment of the present invention;
fig. 2 is a schematic flow chart of another implementation of a method for detecting uninitialized variables according to an embodiment of the present invention;
FIG. 3 is an exemplary diagram of a detection apparatus for uninitialized variables provided by an embodiment of the present invention;
fig. 4 is a schematic diagram of a terminal device according to an embodiment of the present invention.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
In order to explain the technical means of the present invention, the following description will be given by way of specific examples.
An embodiment of the present invention provides a method for detecting an uninitialized variable, as shown in fig. 1, where the method includes the following steps:
step 101, resetting the system to be tested, and enabling a pointer to point to a main function of the system to be tested.
Optionally, before resetting the system under test, a Debug Server Script (DSS) toolkit is introduced, a script environment object is created, the Debug Server is acquired, and a Debug Server session is started. And automatically calling a script debugging reset instruction, and resetting the tested system to enable the pointer to point to the main function of the tested system.
The execution subject of the method may be a computer terminal, and may be a computer-readable storage medium, and the method is not limited to the execution subject, and is described above only as an example.
Optionally, the Test carrier required by the method is an Integrated Development Environment (IDE) of an embedded chip minimum system board and an embedded processor, and the two are connected by using a Joint Test Action Group (JTAG) and perform online simulation. The software development environment has a DSS functional interface, and the script language generally supports high-level languages such as Java or JavaScript, Perl, Python, TCL and the like. In a software development environment, the DSS toolkit can replace manual operation by using script instructions, such as functions of software resetting, breakpoint setting, full-speed operation, single-step operation, memory filling, memory reading, reading of variables corresponding to memory addresses and the like. Therefore, the automatic test can be realized in the minimal system board simulation environment by compiling the script program in a certain logic sequence. For example, in this step, a script debugging reset instruction is automatically called to reset the system under test, so that the pointer points to the main function of the system under test.
And 102, filling specified data in a memory segment storing the global variable in the tested system.
And automatically calling a script debugging memory filling instruction, and filling specified data in all memory units in a Random Access Memory (RAM) of the ebss section in the tested system.
Alternatively, the specified data may be 0x55AA or the like. Ebss segments in embedded software are used for storing global variables.
Optionally, the method further includes automatically calling a script debugging breakpoint instruction after the step, and setting a breakpoint in a statement after an initialization function in the tested software system;
and automatically calling a script to debug the full-speed running instruction, and running the tested software system to the breakpoint statement at full speed.
And 103, operating the pointer to a function position where the variable initialization is completed, reading the memory segment data, and acquiring the total number of memory units corresponding to the name of the global variable and the total number of units of the specified data.
Optionally, the present step includes: automatically calling a script to debug a memory reading instruction, and reading all specified data corresponding to all memory units of the ebss section RAM; automatically calling a script debugging variable reading instruction, and reading the name of the global variable corresponding to the ebss section address;
when the name of the global variable is obtained, obtaining the total number of memory cells corresponding to the name of the global variable accumulated by a first counter, and obtaining the total number of cells of the specified data accumulated by a second counter, optionally, Var _ Cnt may be used to represent the total number of memory cells corresponding to the name of the global variable, and Fill _ Cnt may be used to represent the total number of cells of the specified data;
and step 104, when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the designated data, determining that the global variables are uninitialized global variables.
Optionally, when Fill _ Cnt is equal to Var _ Cnt, it is determined that the global variable corresponding to the currently detected memory area is an uninitialized global variable, then the uninitialized global variable is sent to the control unit corresponding to the control window, and the first counter and the second counter are assigned as preset values, where the preset value may be 0. Thus, all uninitialized global variables can be obtained in the control window, and the global variables can be accurately positioned.
According to the method for detecting the uninitialized variables, all memory units of the ebss section RAM in the detected software system are filled with the specified data (0x55AA), the total number of the memory units corresponding to the names of the global variables and the total number of the filled specified data units are obtained, and when the total numbers of the memory units and the filled specified data units are the same, the currently detected global variables can be determined to be the uninitialized global variables. The whole detection process has the characteristics of simple operation, no need of additional temporary chip resources, accurate detection result, high speed and the like.
An embodiment of the present invention provides another method for detecting an uninitialized variable, as shown in fig. 2, the method includes:
step 201, an integrated development environment IDE of an embedded processor is provided with a debug server script DSS toolkit.
Optionally, the test carrier required by the method is an embedded chip minimum system board and an integrated development environment IDE of the embedded processor, and the embedded chip minimum system board and the embedded processor are connected by using a simulator JTAG and are subjected to online simulation. The integrated development environment IDE of the embedded processor has a DSS functional interface, and the script language generally supports high-level languages such as Java or JavaScript, Perl, Python, TCL and the like. In a software development environment, the DSS toolkit can replace manual operation by using script instructions, such as functions of software resetting, breakpoint setting, full-speed operation, single-step operation, memory filling, memory reading, reading of variables corresponding to memory addresses and the like. Therefore, the automatic test can be realized in the minimal system board simulation environment by compiling the script program in a certain logic sequence. For example, in this step, a script debugging reset instruction is automatically called to reset the system under test, so that the pointer points to the main function of the system under test.
Optionally, a DSS toolkit is imported, and a script environment object is created.
Step 202, invoking execution of the DSS toolkit.
Optionally, a script of the debugging server is obtained, and a dialogue of the debugging server is started.
Step 203, calling a script debugging reset instruction, and resetting the tested system to enable the pointer to point to the main function of the tested system.
When the DSS toolkit is operated in the step, a script debugging reset instruction can be automatically called.
And step 204, calling a script debugging memory filling instruction, and filling specified data in all memory units in the RAM of the ebss section in the system to be tested.
Optionally, the script is automatically called to debug the memory filling instruction, and all memory units of the RAM of the ebss section in the system to be tested are filled with the specified data. Alternatively, the specified data may be 0x55 AA. For embedded software, the ebss segment is used for storing global variables.
Step 205, a script debugging breakpoint instruction is called, and a breakpoint is set in a statement behind an initialization function in the tested software system.
The breakpoint is set to terminate the test program.
And step 206, calling a script debugging full-speed running instruction, and running the tested software system to a breakpoint statement at full speed.
And step 207, calling a script debugging memory reading instruction, and reading all specified data of the memory unit of the ebss section RAM.
This step is to read all the specified data filled in the ebss section RAM.
And 208, calling a script debugging variable reading instruction, and reading the name of the global variable corresponding to the ebss section address.
Step 209, when the name of the global variable is obtained, obtaining the total number of the memory cells corresponding to the name of the global variable accumulated by the first counter, and obtaining the total number of the cells of the specified data accumulated by the second counter.
It should be noted that the first counter and the second counter are only named for distinguishing the counters, and the counters are not functionally ranked.
Step 210, detecting whether the name of the next global variable is read.
In step 211, when the name of the next global variable is read, it is detected whether the total number of the memory cells corresponding to the name of the global variable is the same as the total number of the cells of the specified data.
Optionally, it is determined whether Fill _ Cnt is equal to Var _ Cnt.
Step 212, when the total number of memory cells corresponding to the names of the global variables is the same as the total number of cells of the specified data, determining that the global variables corresponding to the currently detected memory area are uninitialized global variables.
And step 213, sending the uninitialized global variable to a control unit corresponding to the control window.
Optionally, in this step, the determined uninitialized global variables are displayed in a control window so as to locate each global variable, and then the two counters are cleared.
Step 214, assigning the first counter and the second counter to 0.
It should be noted that, after the step 211 is executed, when the total number of the memory cells corresponding to the name of the global variable is different from the total number of the cells of the designated data, the step 214 is executed.
Step 215, read the next address of the ebss segment.
Optionally, after step 210 is executed, when the name of the next global variable is not read, step 215 is executed, that is, the next address of the ebss segment is read, and step 216 is further executed.
Step 216, detecting whether the address of the ebss segment is the last unit.
And step 217, when the address of the ebss section is the last unit, calling a script debugging reset instruction to reset the tested system.
When the address of the ebss segment is not the last element, step 208 is performed.
The embodiment of the invention provides a method for detecting uninitialized variables, which can realize the rapid positioning of uninitialized global variable positions in embedded software by adopting a DSS kit for automatic detection, thereby reducing software bugs and saving the debugging time of software developers.
An embodiment of the present invention provides a device for detecting an uninitialized variable, as shown in fig. 3, the device includes: the device comprises a reset module 301, a filling module 302, a reading module 303 and a determining module 304.
The resetting module 301 is configured to reset the system under test, so that the pointer points to the main function of the system under test.
Optionally, the apparatus further includes a processing module, configured to receive and install a debugging server script DSS toolkit, and execute the DSS toolkit.
The reset module 301 is configured to call a script debugging reset instruction, and reset the system under test, so that the pointer points to the system main function.
A filling module 302, configured to fill the specified data in the memory segment storing the global variable in the system under test.
Optionally, the filling module 302 is configured to invoke a script debug memory filling instruction, and fill the specified data in all memory units in the RAM of the ebss segment in the system under test.
Between the filling module 302 and the reading module 303, a calling module may be further included, configured to call a script debugging breakpoint instruction, and set a breakpoint in a statement following an initialization function in the software system under test; and calling a script debugging full-speed running instruction, and running the tested software system to a breakpoint statement at full speed.
A reading module 303, configured to enable a pointer to run to a function position where variable initialization is completed, read the memory segment data, and obtain a total number of memory cells corresponding to the name of the global variable and a total number of cells of the specified data.
Optionally, when the pointer is operated to the function position where the variable initialization is completed, the reading module 303 is configured to call a script debugging memory reading instruction, and read all specified data of the ebss-segment RAM memory unit; calling a script debugging variable reading instruction, and reading the name of the global variable corresponding to the ebss section address; and when the name of the global variable is acquired, acquiring the total number of memory units corresponding to the name of the global variable accumulated by a first counter, and acquiring the total number of units of the specified data accumulated by a second counter.
When the total number of memory cells corresponding to the name of the global variable is the same as the total number of cells of the designated data, the determining module 304 is configured to determine that the global variable is an uninitialized global variable.
Optionally, the determining module 304 is configured to detect whether a name of a next global variable is read;
when the name of the next global variable is read, detecting whether the total number of memory units corresponding to the name of the global variable is the same as the total number of units of the specified data or not;
and when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the specified data, determining that the global variables corresponding to the currently detected memory area are uninitialized global variables.
Further, the apparatus is further configured to: when the global variable corresponding to the currently detected memory area is determined to be an uninitialized global variable, sending the uninitialized global variable to a control unit corresponding to a control window, and assigning the first counter and the second counter to be 0;
when the name of the next global variable is not read, or when the total number of memory units corresponding to the name of the global variable is different from the total number of units of the specified data, or after the first counter and the second counter are assigned to be 0, whether the address of the ebss section is the last unit is detected, and when the address of the ebss section is the last unit, a script debugging reset instruction is called to reset the tested system.
According to the device for detecting the uninitialized variables, all memory units of the ebss section RAM in the detected software system are filled with the specified data (0x55AA) through the filling module, the reading module obtains the total number of the memory units corresponding to the names of the global variables and the total number of the filled specified data units, and when the total numbers of the memory units and the filled specified data units are the same, the determining module can determine that the currently detected global variables are the uninitialized global variables. The whole detection process has the characteristics of simple operation, no need of additional temporary chip resources, accurate detection result, high speed and the like.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 4 is a schematic diagram of a terminal device according to an embodiment of the present invention. As shown in fig. 4, the terminal device 4 of this embodiment includes: a processor 401, a memory 402 and a computer program 403, such as a detection program for uninitialized variables, stored in said memory 402 and operable on said processor 401. The processor 401 implements the steps in the above-mentioned embodiments of the method for detecting an uninitialized variable, such as steps 101 to 104 shown in fig. 1 or steps 201 to 217 shown in fig. 2, when executing the computer program 403, and the processor 401 implements the functions of the modules in the above-mentioned embodiments of the apparatus, such as the functions of the modules 301 to 304 shown in fig. 3, when executing the computer program 403.
Illustratively, the computer program 403 may be partitioned into one or more modules that are stored in the memory 402 and executed by the processor 401 to implement the present invention. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of the computer program 403 in the detection device for uninitialized variables or terminal equipment 4. For example, the computer program 403 may be divided into a reset module 301, a fill module 302, a read module 303, and a determination module 304, and specific functions of the modules are shown in fig. 3, which is not described herein again.
The terminal device 4 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The terminal device may include, but is not limited to, a processor 401, a memory 402. Those skilled in the art will appreciate that fig. 4 is merely an example of a terminal device 4 and does not constitute a limitation of terminal device 4 and may include more or fewer components than shown, or some components may be combined, or different components, e.g., the terminal device may also include input-output devices, network access devices, buses, etc.
The Processor 401 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 402 may be an internal storage unit of the terminal device 4, such as a hard disk or a memory of the terminal device 4. The memory 402 may also be an external storage device of the terminal device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the terminal device 4. Further, the memory 402 may also include both an internal storage unit and an external storage device of the terminal device 4. The memory 402 is used for storing the computer programs and other programs and data required by the terminal device 4. The memory 402 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. . Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U.S. disk, removable hard disk, magnetic diskette, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signal, telecommunications signal, and software distribution medium, etc. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.

Claims (10)

1. A method for detecting uninitialized variables, comprising:
resetting the tested system to enable a pointer to point to a main function of the tested system;
filling specified data in all memory units in a RAM (random access memory) in a memory segment storing a global variable in the system to be tested;
enabling a pointer to run to a function position where variable initialization is finished, reading the memory segment data, and obtaining the total number of memory units corresponding to the name of the global variable and the total number of units of the specified data;
and when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the designated data, determining that the global variables are uninitialized global variables.
2. The method for detecting uninitialized variables according to claim 1, wherein before said resetting the system under test to point a pointer to a main function of the system under test, further comprising:
the integrated development environment IDE of the embedded processor is provided with a debugging server script DSS toolkit;
invoking execution of the DSS toolkit;
the resetting the system under test to make the pointer point to the main function of the system under test includes:
and calling a script debugging reset instruction, resetting the tested system and enabling the pointer to point to the main function of the tested system.
3. The method for detecting uninitialized variables according to claim 2, wherein filling specified data in the memory segment storing global variables in the system under test comprises:
and calling a script debugging memory filling instruction, and filling specified data in all memory units in the RAM of the ebss section in the system to be tested.
4. The method for detecting uninitialized variables according to claim 3, wherein after said calling script debugging a memory fill instruction fills specified data in all memory locations in the RAM of the ebss section in the system under test, further comprising:
calling a script debugging breakpoint instruction, and setting a breakpoint in a statement behind an initialization function in the system to be tested;
and calling a script debugging full-speed running instruction, and running the tested system to a breakpoint statement at full speed.
5. The method according to claim 3 or 4, wherein the reading the memory segment and obtaining the total number of memory cells corresponding to the name of the global variable and the total number of cells of the specified data includes:
calling a script debugging memory reading instruction, and reading all specified data of the memory unit of the ebss section RAM;
calling a script debugging variable reading instruction, and reading the name of the global variable corresponding to the ebss section address;
and when the name of the global variable is acquired, acquiring the total number of memory units corresponding to the name of the global variable accumulated by a first counter, and acquiring the total number of units of the specified data accumulated by a second counter.
6. The method according to claim 5, wherein determining that the global variable is an uninitialized global variable when the total number of the memory cells corresponding to the name of the global variable is the same as the total number of the cells of the designated data comprises:
detecting whether the name of the next global variable is read or not;
when the name of the next global variable is read, detecting whether the total number of memory units corresponding to the name of the global variable is the same as the total number of units of the specified data or not;
and when the total number of the memory units corresponding to the names of the global variables is the same as the total number of the units of the specified data, determining that the global variables corresponding to the currently detected memory area are uninitialized global variables.
7. The method for detecting uninitialized variables according to claim 6, further comprising:
when the global variable corresponding to the currently detected memory area is determined to be an uninitialized global variable, sending the uninitialized global variable to a control unit corresponding to a control window, and assigning the first counter and the second counter to be 0;
when the name of the next global variable is not read, or when the total number of memory units corresponding to the name of the global variable is different from the total number of units of the specified data, or after the first counter and the second counter are assigned to be 0, whether the address of the ebss section is the last unit is detected;
and when the address of the ebss section is the last unit, calling a script debugging reset instruction to reset the tested system.
8. An apparatus for detecting uninitialized variables, comprising:
the reset module is used for resetting the tested system to enable the pointer to point to the main function of the tested system;
the filling module is used for filling specified data in all memory units in the RAM in the memory segment for storing the global variables in the tested system;
the reading module is used for enabling the pointer to run to a function position where the variable initialization is finished, reading the memory segment data, and acquiring the total number of memory units corresponding to the name of the global variable and the total number of units of the specified data;
and the determining module is used for determining the global variable as the uninitialized global variable when the total number of the memory units corresponding to the names of the global variable is the same as the total number of the units of the specified data.
9. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 7.
CN201910111480.1A 2019-02-12 2019-02-12 Method for detecting uninitialized variable and terminal equipment Active CN109902001B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910111480.1A CN109902001B (en) 2019-02-12 2019-02-12 Method for detecting uninitialized variable and terminal equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910111480.1A CN109902001B (en) 2019-02-12 2019-02-12 Method for detecting uninitialized variable and terminal equipment

Publications (2)

Publication Number Publication Date
CN109902001A CN109902001A (en) 2019-06-18
CN109902001B true CN109902001B (en) 2022-06-07

Family

ID=66944780

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910111480.1A Active CN109902001B (en) 2019-02-12 2019-02-12 Method for detecting uninitialized variable and terminal equipment

Country Status (1)

Country Link
CN (1) CN109902001B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110688320B (en) * 2019-09-30 2023-05-23 潍柴动力股份有限公司 Global variable detection method and device and terminal equipment
CN112527660B (en) * 2020-12-17 2022-11-22 展讯通信(上海)有限公司 Static detection method and device for codes

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927187A (en) * 2014-05-09 2014-07-16 成都凯智科技有限公司 Program execution method of embedded system
CN105677559A (en) * 2015-12-31 2016-06-15 杭州华为数字技术有限公司 Detection method and device
CN106294170A (en) * 2016-08-17 2017-01-04 厦门科灿信息技术有限公司 The method of testing of embedded control system initialization of variable
JP2017059009A (en) * 2015-09-17 2017-03-23 横河電機株式会社 Control device
CN107391191A (en) * 2017-07-18 2017-11-24 杭州中天微系统有限公司 A kind of program module method for dynamically loading

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927187A (en) * 2014-05-09 2014-07-16 成都凯智科技有限公司 Program execution method of embedded system
JP2017059009A (en) * 2015-09-17 2017-03-23 横河電機株式会社 Control device
CN105677559A (en) * 2015-12-31 2016-06-15 杭州华为数字技术有限公司 Detection method and device
CN106294170A (en) * 2016-08-17 2017-01-04 厦门科灿信息技术有限公司 The method of testing of embedded control system initialization of variable
CN107391191A (en) * 2017-07-18 2017-11-24 杭州中天微系统有限公司 A kind of program module method for dynamically loading

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
JavaScript之函数作用域;clearbug;《博客园 https://www.cnblogs.com/craftsman-gao/p/4720635.html》;20150811;全文 *
未初始化全局变量;liuqiaoyu080512;《CSDN博客 https://blog.csdn.net/liuqiaoyu080512/article/details/8455652》;20121231;全文 *

Also Published As

Publication number Publication date
CN109902001A (en) 2019-06-18

Similar Documents

Publication Publication Date Title
US8769504B2 (en) Method and apparatus for dynamically instrumenting a program
CN110580226B (en) Object code coverage rate testing method, system and medium for operating system level program
US8990622B2 (en) Post-silicon validation using a partial reference model
CN110209520B (en) Method and device for improving SSD (solid State disk) testing efficiency, computer equipment and storage medium
CN110543420B (en) Software testing method, system, terminal and storage medium
CN112597064B (en) Method for simulating program, electronic device and storage medium
CN112541313B (en) Method and device for configuring trigger expression for logic analysis state
US9058427B2 (en) Iterative generation of symbolic test drivers for object-oriented languages
US8117499B2 (en) Generation of a stimuli based on a test template
CN109902001B (en) Method for detecting uninitialized variable and terminal equipment
CN111563032A (en) APP debugging method and device, computer equipment and storage medium
CN111382077B (en) Application program crash reason positioning method and device, electronic equipment and storage medium
CN112631926A (en) Code test coverage rate display method and device, computer equipment and storage medium
CN110704303B (en) Method and device for acquiring test coverage information
CN108628734B (en) Functional program debugging method and terminal
CN115686961A (en) Processor testing method and device and electronic equipment
CN109189671B (en) Layer-by-layer approximation type variable positioning method and system and terminal equipment
CN115964237A (en) Method and device for testing functions and performance of Central Processing Unit (CPU)
CN115373929A (en) Test method, device, equipment, readable storage medium and program product
CN114139479A (en) Simulation verification method and device and computing equipment
CN113792522A (en) Simulation verification method and device and computing equipment
CN113806231A (en) Code coverage rate analysis method, device, equipment and medium
CN113220586A (en) Automatic interface pressure test execution method, device and system
CN112506806A (en) Method for debugging program, electronic device and storage medium
US20220058109A1 (en) Method for debugging computer program, device employing method, and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant