CN111078540B - QT-development-based universal aviation flight service software memory anomaly detection and positioning method - Google Patents

QT-development-based universal aviation flight service software memory anomaly detection and positioning method Download PDF

Info

Publication number
CN111078540B
CN111078540B CN201911200037.8A CN201911200037A CN111078540B CN 111078540 B CN111078540 B CN 111078540B CN 201911200037 A CN201911200037 A CN 201911200037A CN 111078540 B CN111078540 B CN 111078540B
Authority
CN
China
Prior art keywords
file
name
child
yes
judging whether
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
CN201911200037.8A
Other languages
Chinese (zh)
Other versions
CN111078540A (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.)
Sichuan Jiuzhou ATC Technology Co Ltd
Original Assignee
Sichuan Jiuzhou ATC 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 Sichuan Jiuzhou ATC Technology Co Ltd filed Critical Sichuan Jiuzhou ATC Technology Co Ltd
Priority to CN201911200037.8A priority Critical patent/CN111078540B/en
Publication of CN111078540A publication Critical patent/CN111078540A/en
Application granted granted Critical
Publication of CN111078540B publication Critical patent/CN111078540B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3664Environments for testing or debugging software
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a QT-based universal aviation flight service software memory anomaly detection and positioning method, which comprises the steps of setting a detection program, wherein the detection program is used for detecting memory anomaly caused by conflict between a QT semi-automatic memory management mechanism and a C + + stack memory management mechanism; and the detection program takes each software engineering catalog of the navigation flight service software as a parameter, and outputs a detection result after the detection program is operated. The method effectively solves the problem of debugging and positioning of memory leakage caused by QT semi-automatic memory management mechanism and C + + stack memory management conflict in the development process of general aviation flight service software, and ensures the safe and stable operation of the software. By the detection method, the potential memory abnormality of the software can be predicted in advance, the reliability of the software is improved, and the flight safety caused by the software is reduced. Meanwhile, the detection method can effectively locate the abnormal position of the memory, improve the development and debugging efficiency and shorten the development period.

Description

QT-based universal aviation flight service software memory anomaly detection and positioning method
Technical Field
The invention relates to a QT-based universal aviation flight service software memory anomaly detection and positioning method.
Background
The general aviation industry is one of strategic emerging industries which are key developed currently in China and plays an important role in the construction of national economy and society. Establishing and perfecting a low-altitude airspace management and general aviation service guarantee system is a basic requirement for expanding the service field and promoting the rapid development of general aviation. The general aviation flight service software is used as important software for guaranteeing the navigation flight task, comprises flight data processing service software, data recording and playback service software, controller seat software, meteorological information display software, safety alarm processing service software and the like, provides functions of flight data processing, navigation information processing, meteorological information processing, flight information processing, information publishing processing, alarm and rescue processing, flight service display, flight monitoring display and the like, provides flight plan and flight dynamic related information for a navigation flight service controller, and plays an important role in guaranteeing low-altitude flight safety.
The navigation flight service software is important software for guaranteeing flight safety, high reliability and fault tolerance are required, very high requirements are provided for stable operation of the software, and abnormal phenomena such as midway abnormal exit, memory leakage and the like cannot occur in the software operation process. The total number of code statistics of the navigation flight service software is 167 ten thousand, the manual positioning of software memory leakage in a debugging mode and the like can consume a large amount of time, and how to effectively position the memory leakage position has important significance for developers. The method detects the potential memory abnormality in the software code through Python software, helps developers locate the memory abnormality, and therefore improves the development efficiency.
The navigation flight service software is developed by adopting C + + language based on QT platform. An Object tree (Object tree) is used in the QT semi-automatic memory management mechanism to organize and manage all objects of QObject classes and their sub-classes. When a QObject is created, if other objects are used as its parent object (parent), the QObject child object is added to the child () list of the parent object; when the parent object is destroyed, the QObject child object is also destroyed. However, the pop principle in C + + is first-in, last-out, and last-in, and when the QObject child object is generated and stored in the stack before the parent object, the parent object is destructed, an abnormal phenomenon of memory leak occurs, which causes the program to crash. Similarly, the management principle of the heap memory in C + + is first-in first-out, last-in last-out, and when the Qobject child object is generated later than the parent object and stored in the heap, the parent object is destructed, so that the memory leakage is abnormal, and the program is crashed. The existing method for statically detecting QT memory leak codes mainly aims at memory overflow check and memory release check, and does not detect memory leak caused by conflict between a QT semi-automatic memory management mechanism and C + + stack memory management. The memory leakage is easy to occur in the encoding process, and the crash and the abnormity of the flight service software caused by the memory abnormity can cause great hidden troubles to the flight safety of the general aviation aircraft.
In the existing QT memory leak detection method, memory overflow check and memory release check are mainly performed, that is, if an object is created by a new operator in a heap by a program, the object must be destructed by a delete operator to complete a delete operation, otherwise, the program may have a memory leak problem. There is no positioning method for memory leakage caused by QT semi-automatic memory management mechanism and C + + stack heap memory management conflict. Firstly, when a QObject object is destructed, the Qt automatically destructs all the child objects in an object tree children () list to have potential conflict with a C + + stack memory mechanism of first-in last-out and last-in first-out and a C + + stack memory mechanism of first-in first-out and last-in last-out; secondly, when the QObject object is destructed and when the QObject object has a parent object, the QT automatically destructs the parent object tree itself and has a potential conflict with a C + + heap memory mechanism of first-in first-out, last-in last-out.
Disclosure of Invention
According to the memory abnormal phenomenon caused by the specific QObject management mechanism in the QT in the work of developing the navigation flight service software, the invention forms a solution method for program static detection, can detect the memory abnormal position caused by the conflict between the QT semi-automatic memory management mechanism and the C + + stack memory management mechanism, and feeds back the detection result to developers, thereby helping the developers concentrate on the development of software service functions.
The purpose of the invention is realized by the following technical scheme:
the method for detecting and positioning the memory abnormity of the general aviation flight service software developed based on QT comprises the steps of setting a detection program, wherein the detection program is used for detecting the memory abnormity caused by the conflict between a QT semi-automatic memory management mechanism and a C + + stack memory management mechanism;
and the detection program takes each software engineering catalog of the navigation flight service software as a parameter, and outputs a detection result after the detection program is operated.
Preferably, the detection program is developed using Python.
Preferably, the detection result is output to the TXT document after the detection program is run.
Preferably, the detection procedure is implemented as follows:
the method comprises the following steps: acquiring all CPP source files (.cpp) and header files (.h) under a general aviation flight service software source code directory through an os module in Python, and storing file names and file paths into a Python dictionary hFileDirDict and a cpFileDirDict;
step two: reading a certain file in a dictionary hfileDirDict, opening a header file (.h) file of a corresponding path, reading code information line by line, analyzing an Object declaration statement, acquiring declaration information corresponding to a QT Object control, and storing the declaration information in a Python dictionary Object NumDict; analyzing the file name of a header file (.h), acquiring a path of a CPP source file (.cpp) corresponding to the file through cppFileDirDict, opening the CPP source file (.cpp) corresponding to the path, reading code information line by line, analyzing a source file Object initialization statement, acquiring creation information corresponding to a QT Object control, and storing the created information in a Python dictionary Object NumDict;
step three: reading a file path in a dictionary cppFileDirDict, opening a path of a CPP source file (. CPP) corresponding to the path, reading code information line by line, analyzing a key sentence for setting a parent-child relationship, obtaining the parent-child relationship corresponding to a QT Object control, and storing the parent-child relationship in a Python dictionary child ParentDict, wherein a key of the child-ParentDict is a child Object name of the QT Object control, and a value of the child-child relationship is a parent Object name of the QT Object control;
step four: traversing the key value of child ParentDict, acquiring the line numbers of the child object and the parent object through the object NumDict, judging, recording the name of the child object, the name of the parent object and the line number of the key sentence for setting the parent object when the line number of the parent object is larger than that of the child object, and outputting the key sentence to a console for printing.
Preferably, in the first step, the key of hfiledirdicot is the file name of the header file (.h), the value is the path of the corresponding header file, the key of cppifiledirdicot is the file name of the CPP source file (.cpp), and the value is the path of the corresponding source file.
Preferably, in step two, the key of the object numdit is the object name of the QT QObject control, and the value is the number of lines of the declaration or creation statement.
Preferably, the first step specifically includes:
step 11: acquiring a project path set as dir;
step 12: acquiring all files under a path by using an os module of Python;
step 13: judging whether the file of the current path traverses or not; if not, ending; if yes, go to step 14;
step 14: and reading the file name fileName and acquiring a complete file path fullDir. Slicing the fileName by using a split () method and returning a partitioned character string table fileName;
step 15: judging whether the length of the character string table filenameArr is greater than 1; if not, assigning fullDir to dir and returning to execute the step 12; if yes, go to step 16;
step 16: reading fileNarameArr [1] as file type fileType;
and step 17: judging whether the fileType is 'h'; if yes, storing the fileName and the file path fullPath into the hFileDirDict, and returning to execute the step 13; if not, entering step 17;
step 18: judging whether the fileType is 'cpp'; if yes, storing the fileName and the file path fullPath into cppfiledirdicect, and returning to execute the step 13; otherwise, the step 13 is executed.
Preferably, the second step specifically includes:
step 21: acquiring a key list (h file name list) of a dictionary hFileDirDict, and acquiring all h file names of the key list;
step 22: judging whether the h file name in the key list traverses or not; if yes, ending; if not, go to step 23;
step 23: acquiring an h file path through an h file name, opening a corresponding h file, and reading a code in the h file;
and step 24: judging whether the codes in the h file traverse or not; if not, executing step 25; if yes, go to step 28;
step 25: reading a code line, putting the code line into a string type line, and judging whether the line is an annotation or not; if yes, go back to step 24; if not, go to step 26;
step 26: judging whether the line is a statement or not; if yes, the class name and the object name of the declaration object are obtained, step 27 is executed, and if not, the step 24 is executed;
step 27: judging whether the QObject class or the subclass of the QT is present; if yes, storing the stack object name and line number into a dictionary stackQObjectNum, storing the stack object name and line number into a dictionary heapQObjectNum, returning to the step 24, and if not, returning to the step 24;
step 28: intercepting and searching a corresponding cpp file according to the h file name, and judging whether the corresponding cpp file exists or not; if not, returning to execute the step 22, if so, acquiring the code in the cpp file, and executing the step 29;
step 29: judging whether the read code traverses or not; if yes, go back to step 22; otherwise, the read code line is placed in a string type line and step 210 is performed.
Step 210: judging whether the line is an annotation; if yes, go back to step 29; otherwise, go to step 211;
step 211: judging whether the line is a statement or not; if yes, the class name and object name of the declaration object are obtained, and step 213 is executed; if not, go to step 212;
step 212: judging whether the line is an initialization statement; if yes, the class name and object name of the declaration object are obtained, and step 213 is executed; if not, returning to the step 29;
step 213: judging whether the QObject class or the subclass of the QT is judged; if yes, storing the stack object name and line number into the dictionary stackQObjectNum, and storing the stack object name and line number into the dictionary heapQObjectNum; otherwise, the step 29 is executed.
Preferably, the third step specifically includes:
step 31: acquiring a code in the cpp file;
step 32: judging whether the code traverses or not; if yes, ending; if not, reading the code line and putting the code line into a string type line, and executing the step 33;
step 33: judging whether the line is an annotation; if yes, go back to step 32, if no, go to step 34;
step 34: judging whether the sentence contains a setParent keyword; if yes, storing the child object name and the father object name obtained by analysis into a dictionary child ParentDict; if not, go to step 35;
step 35: judging whether the sentence is an initialization sentence and initializing a father object; if so, analyzing to obtain a child object name and a parent object name and storing the child object name and the parent object name in a dictionary child ParentDict; otherwise, the process returns to the step 32.
Preferably, the fourth step specifically includes:
step 41: acquiring a parent-child relationship dictionary child ParentDict, and executing step 42;
step 42: judging whether to traverse a dictionary child ParentDict; if yes, ending; if not, go to step 43;
step 43: acquiring the name of the child object and the name of the parent object, and executing the step 44;
step 44: judging whether the sub-object is in a first stack object dictionary stackQObjectNum or not; if yes, go to step 45; if not, go to step 47;
step 45: judging whether the father object is in the first stack object dictionary stackQObjectNum or not; if yes, the row number of the parent-child object is obtained through stackQObjectNum, and step 46 is executed; if not, returning to the step 42;
step 46: judging whether the value of the line number of the child object is smaller than that of the line number of the parent object; if yes, outputting the name of the child object and the name of the parent object, establishing a key sentence of parent-child relationship, and returning to execute the step 42;
step 47: judging whether the child object is in a second stack object dictionary heapQObjectNum or not; if yes, go to step 48; if not, returning to the step 42;
and 48: judging whether the father object is in the second stack object dictionary heapQObjectNum or not; if yes, the line number of the parent-child object is obtained through the heapQObjectNum, and step 49 is executed; if not, returning to the step 42;
step 49: judging whether the value of the row number of the child object is larger than that of the row number of the parent object; if yes, the child object name and the parent object name are output, and the key sentence for establishing the parent-child relationship is returned to execute step 42.
The beneficial effects of the invention are:
the method for detecting and positioning the memory abnormity of the general aviation flight service software developed based on the QT effectively solves the problem of debugging and positioning of memory leakage caused by conflict between a QT semi-automatic memory management mechanism and C + + stack memory management in the development process of the general aviation flight service software, and ensures the safe and stable operation of the software. In the development process of a large-scale complex information system, debugging takes three times or more of the development time. By the detection method, the potential memory abnormality of the software can be predicted in advance, the reliability of the software is improved, and the flight safety caused by the software is reduced. Meanwhile, the detection method can effectively locate the abnormal position of the memory, improve the development and debugging efficiency and shorten the development period.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
FIG. 1 is a flow chart of a first step of the present invention.
FIG. 2 is a flowchart of step two of the present invention.
FIG. 3 is a flow chart of step three of the present invention.
Fig. 4 is a flow chart of step four of the present invention.
Detailed Description
The technical solutions of the present invention are further described in detail below with reference to the accompanying drawings, but the scope of the present invention is not limited to the following descriptions.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings of the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without inventive efforts based on the embodiments of the present invention, are within the scope of protection of the present invention. Thus, the following detailed description of the embodiments of the present invention, as presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be obtained by a person skilled in the art without inventive efforts based on the embodiments of the present invention, are within the scope of protection of the present invention.
The QObject class is the base class of all classes of Qt, is the core of the Qt object model, and has unique characteristics and management mechanisms, such as: seamless object communication mechanisms signal and slots (signs and slots), events and event filters (events and event filters), and the like. In particular, qobjects have a hierarchical, queryable object tree (object trees) property that enables object ownership (object owenershirp) to be organized in a natural manner. When a QObject object is created, qt will create an object tree for it at the same time. When this QObject needs to be delete, qt will automatically delete all child objects in the object tree children () list. Meanwhile, when the QObject object delete in any object tree exists, if the object has a parent, the object automatically removes the object from the child () list of the parent and then delete the object.
However, in the C + + memory management mechanism, the memory management of the stack is the principle of "first-in last-out, last-in first-out", and the memory management of the heap is the principle of "first-in first-out, last-in last-out". Therefore, the following two memory exception problems may occur during the use of QObject of QT:
(1) The QObject object A is firstly generated in a stack, the QObject object B is then generated in the stack, parent of the object A is set as B, namely A.setPart (& B), then the A needs to be deleted firstly when B is constructed, but the A is generated in the stack before the B, because of a memory management mechanism of 'first in, last out, last in, first out', the program has memory exception problem;
(2) The method comprises the steps that a QObject object A is firstly generated in a heap, a QObject object B is then generated in the heap, parent of the object B is set to be A, namely B.setPart (& A), B needs to be deleted firstly when the A is constructed, but the A is generated in the heap before the B, and the problem of memory exception can occur to a program due to a memory management mechanism of first-in first-out, last-in last-out and last-out of the heap.
The problem of memory abnormity caused by conflict of a QT semi-automatic memory management mechanism and a C + + stack memory management mechanism in the development process of navigation flight service software is solved.
Example one
The method for detecting and positioning the memory abnormity of the general aviation flight service software developed based on QT comprises the steps of setting a detection program, wherein the detection program is used for detecting the memory abnormity caused by the conflict between a QT semi-automatic memory management mechanism and a C + + stack memory management mechanism;
and the detection program takes each software engineering catalog of the navigation flight service software as a parameter, and outputs a detection result after the detection program is operated.
The detection program was developed using Python. And outputting the detection result to the TXT document after the detection program runs.
The detection program is specifically implemented as follows:
the method comprises the following steps: acquiring all CPP source files (.cpp) and header files (.h) under a general aviation flight service software source code directory through an os module in Python, and storing file names and file paths into a Python dictionary hFileDirDict and a cpFileDirDict;
step two: reading a certain file in a dictionary hfileDirDict, opening a header file (.h) file of a corresponding path, reading code information line by line, analyzing an Object declaration statement, acquiring declaration information corresponding to a QT Object control, and storing the declaration information in a Python dictionary Object NumDict; analyzing the file name of a header file (.h), acquiring a path of a CPP source file (.cpp) corresponding to the file through cppFileDirDict, opening the CPP source file (.cpp) corresponding to the path, reading code information line by line, analyzing a source file Object initialization statement, acquiring creation information corresponding to a QT Object control, and storing the created information in a Python dictionary Object NumDict;
step three: reading a file path in a dictionary cppFileDirDict, opening a path of a CPP source file (. CPP) corresponding to the path, reading code information line by line, analyzing a key sentence for setting a parent-child relationship, obtaining the parent-child relationship corresponding to a QT Object control, and storing the parent-child relationship in a Python dictionary child ParentDict, wherein a key of the child-ParentDict is a child Object name of the QT Object control, and a value of the child-child relationship is a parent Object name of the QT Object control;
step four: traversing the key value of child ParentDict, acquiring the line numbers of the child object and the parent object through the object NumDict, judging, recording the name of the child object, the name of the parent object and the line number of a key statement for setting the parent object when the line number of the parent object is greater than that of the child object, outputting to a console and printing.
Example two
The present embodiment is similar to the first embodiment, and the difference is that:
in the first step, the key of hfiledirdicrt is the file name of the header file (.h) file, the value is the path of the corresponding header file, the key of cppifiledirdicrt is the file name of the CPP source file (.cpp), and the value is the path of the corresponding source file.
In step two, the key of object NumDict is the object name of QT QObject control, and the value is the number of lines declared or created statements.
As shown in fig. 1, the first step specifically includes:
step 11: acquiring a project path set as dir;
step 12: acquiring all files under a path by using an os module of Python;
step 13: judging whether the file of the current path traverses or not; if not, ending; if yes, go to step 14;
step 14: and reading the file name fileName and acquiring a complete file path fullDir. Slicing the fileName by using a split () method and returning a partitioned character string table fileName;
step 15: judging whether the length of the character string table filenameArr is greater than 1; if not, assigning fullDir to dir and returning to execute the step 12; if yes, go to step 16;
step 16: reading fileNarameArr [1] as file type fileType;
and step 17: judging whether the fileType is h; if yes, storing the fileName and the file path fullPath into the hfiledirdicect, and returning to execute the step 13; if not, entering step 17;
step 18: judging whether the fileType is 'cpp'; if yes, storing the fileName and the file path fullPath into cppfiledirdicect, and returning to execute the step 13; otherwise, the step 13 is executed.
EXAMPLE III
The present embodiment is similar to the first embodiment, and the difference is that:
as shown in fig. 2, the second step specifically includes:
step 21: acquiring a key list (h file name list) of a dictionary hFileDirDict, and acquiring all h file names of the key list;
step 22: judging whether the h file name in the key list traverses or not; if yes, ending; if not, entering step 23;
step 23: acquiring an h file path through an h file name, opening a corresponding h file, and reading a code in the h file;
and step 24: judging whether the codes in the h file traverse or not; if not, executing step 25; if yes, go to step 28;
step 25: reading a code line, putting the code line into a string type line, and judging whether the line is an annotation or not; if yes, go back to step 24; if not, go to step 26;
step 26: judging whether the line is a statement or not; if yes, acquiring the class name and the object name of the declaration object, executing the step 27, otherwise, returning to the step 24;
step 27: judging whether the QObject class or the subclass of the QT is present; if yes, storing the stack object name and line number into a dictionary stackQObjectNum, storing the stack object name and line number into a dictionary heapQObjectNum, returning to the step 24, and if not, returning to the step 24;
step 28: intercepting and searching a corresponding cpp file according to the h file name, and judging whether the corresponding cpp file exists or not; if not, returning to execute the step 22, if so, acquiring the code in the cpp file, and executing the step 29;
step 29: judging whether the read code traverses or not; if yes, go back to step 22; otherwise, the read code line is placed in a string type line, and step 210 is performed.
Step 210: judging whether the line is an annotation; if yes, go back to step 29; if not, go to step 211;
step 211: judging whether the line is a statement or not; if yes, the class name and object name of the declaration object are obtained, and step 213 is executed; if not, go to step 212;
step 212: judging whether the line is an initialization statement or not; if yes, the class name and object name of the declaration object are obtained, and step 213 is executed; if not, returning to the step 29;
step 213: judging whether the QObject class or the subclass of the QT is judged; if yes, storing the stack object name and the line number into a dictionary stackQObjectNum, and storing the stack object name and the line number into a dictionary heapQObjectNum; otherwise, the step 29 is executed.
Example four
The present embodiment is similar to the first embodiment, and the difference is that:
as shown in fig. 3, the third step specifically includes:
step 31: acquiring a code in the cpp file;
step 32: judging whether the code traverses or not; if yes, ending; if not, reading the code line, putting the code line into a string type line, and executing the step 33;
step 33: judging whether the line is an annotation; if yes, go back to step 32, if no, go to step 34;
step 34: judging whether the statement contains a setParent keyword or not; if yes, storing the child object name and the father object name obtained by analysis into a dictionary child ParentDict; if not, go to step 35;
step 35: judging whether the statement is an initialization statement and initializing a parent object; if so, analyzing to obtain a child object name and a parent object name and storing the child object name and the parent object name in a dictionary child ParentDict; otherwise, the step 32 is executed.
EXAMPLE five
The present embodiment is similar to the first embodiment, and the difference is that:
as shown in fig. 4, the fourth step specifically includes:
step 41: acquiring a parent-child relationship dictionary child parentDict, and executing step 42;
step 42: judging whether to traverse a dictionary child ParentDict; if yes, ending; if not, go to step 43;
step 43: acquiring the name of the child object and the name of the parent object, and executing the step 44;
step 44: judging whether the sub-object is in a first stack object dictionary stackQObjectNum or not; if yes, go to step 45; if not, go to step 47;
step 45: judging whether the father object is in the first stack object dictionary stackQObjectNum or not; if yes, the row number of the parent-child object is obtained through stackQObjectNum, and step 46 is executed; if not, returning to the step 42;
step 46: judging whether the value of the line number of the child object is smaller than that of the line number of the parent object; if yes, outputting the name of the child object and the name of the parent object, establishing a key sentence of parent-child relationship, and returning to execute the step 42;
step 47: judging whether the child object is in a second stack object dictionary heapQObjectNum or not; if yes, go to step 48; if not, returning to the step 42;
and step 48: judging whether the father object is in a second stack object dictionary heapQObjectNum or not; if yes, the line number of the parent-child object is obtained through the heapQObjectNum, and step 49 is executed; if not, returning to the step 42;
step 49: judging whether the value of the row number of the child object is larger than that of the row number of the parent object; if yes, the child object name and the parent object name are output, and the key sentence for establishing the parent-child relationship is returned to execute step 42.
The invention provides a method for detecting and positioning memory abnormity in QT-based development navigation flight service software, which solves the potential memory abnormity problems of object tree (object trees) characteristics with a hierarchical structure and a C + + memory management mechanism stack of first-in last-out and last-in first-out and last-in last-out of the stack due to QTQObject in the development of the navigation flight service software.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including the preferred embodiment and all changes and modifications that fall within the scope of the invention. The present invention should be considered as limited only by the preferred embodiments and not by the specific details, but rather as limited only by the accompanying drawings, and as used herein, is intended to cover all modifications, equivalents and improvements falling within the spirit and scope of the invention.

Claims (7)

1. QT-based universal aviation flight service software memory anomaly detection and positioning method is characterized by comprising the following steps of: setting a detection program, wherein the detection program is used for detecting memory abnormity caused by conflict between a QT semi-automatic memory management mechanism and a C + + stack memory management mechanism;
the detection program takes each software engineering catalog of the navigation flight service software as a parameter, and outputs a detection result after the detection program is operated;
the specific implementation process of the detection program is as follows:
the method comprises the following steps: acquiring all CPP source files and head files in a source code directory of the general aviation flight service software through an os module in Python, and storing file names and file paths into a Python dictionary hFileDirdict and cppFileDirdict; the key of the hFileDirDict is the filename of the header file, the value is the path of the corresponding header file, the key of the cppFileDirDict is the filename of the CPP source file, and the value is the path of the corresponding source file;
step two: reading files in a dictionary hFileDirDict, opening header files of corresponding paths, reading code information line by line, analyzing Object declaration statements, acquiring declaration information corresponding to a QT Object control, and storing the declaration information in a Python dictionary Object NumDict; analyzing the file name of a header file, acquiring a path of a CPP source file corresponding to the file through cppFileDirDict, opening the CPP source file corresponding to the path, reading code information line by line, analyzing a source file Object initialization statement, acquiring creation information corresponding to a QT Object control, and storing the creation information into a Python dictionary Object NumDict; wherein the key of the object NumDict is the object name of the QT QObject control, and the value is the line number of the statement or the creation statement;
step three: reading a file path in a dictionary cppFileDirDict, opening a path of a CPP source file corresponding to the path, reading code information line by line, analyzing a key sentence for setting a parent-child relationship, obtaining the parent-child relationship corresponding to a QT Object control, and storing the parent-child relationship into a Python dictionary child ParentDict, wherein a key of the child-ParentDict is a child Object name of the QT Object control, and a value of the child-child ParentDict is a parent Object name of the QT Object control;
step four: traversing the key value of child ParentDict, acquiring the line numbers of the child object and the parent object through the object NumDict, judging, recording the name of the child object, the name of the parent object and the line number of the key sentence for setting the parent object when the line number of the parent object is larger than that of the child object, and outputting the line numbers to the console.
2. The QT-based development general aviation flight service software memory anomaly detection and positioning method of claim 1, characterized in that: the detection program was developed using Python.
3. The memory anomaly detection and positioning method for QT-based development of general aviation flight service software according to claim 1 or 2, characterized in that: and outputting the detection result to the TXT document after the detection program runs.
4. The QT-based development general aviation flight service software memory anomaly detection and positioning method of claim 1, which is characterized in that: the first step specifically comprises:
step 11: acquiring a project path set as dir;
step 12: acquiring all files under a path by using an os module of Python;
step 13: judging whether the file of the current path traverses or not; if not, ending; if yes, go to step 14;
step 14: reading a file name fileName, and acquiring a complete file path fullDir; slicing the fileName by using a split () method, and returning a segmented character string table filenamear;
step 15: judging whether the length of the character string table filenameArr is greater than 1; if not, assigning fullDir to dir and returning to execute the step 12; if yes, go to step 16;
step 16: reading fileNarameArr [1] as file type fileType;
and step 17: judging whether the fileType is h; if yes, storing the fileName and the file path fullPath into the hFileDirDict, and returning to execute the step 13; if not, go to step 17;
step 18: judging whether the fileType is 'cpp'; if yes, storing the file name fileName and the file path fullPath into cppFileDirDict, and returning to execute the step 13; otherwise, the step 13 is executed.
5. The QT-based development general aviation flight service software memory anomaly detection and positioning method of claim 1, characterized in that: the second step specifically comprises:
step 21: acquiring a key list of a dictionary hFileDirDict, and acquiring all h file names of the key list;
step 22: judging whether the h file name in the key list traverses or not; if yes, ending; if not, go to step 23;
step 23: acquiring an h file path through an h file name, opening a corresponding h file, and reading a code in the h file;
step 24: judging whether the codes in the h file traverse or not; if not, executing step 25; if yes, go to step 28;
step 25: reading a code line, putting the code line into a string type line, and judging whether the line is an annotation or not; if yes, go back to step 24; if not, go to step 26;
step 26: judging whether the line is a statement or not; if yes, the class name and the object name of the declaration object are obtained, step 27 is executed, and if not, the step 24 is executed;
step 27: judging whether the QObject class or the subclass of the QT is present; if yes, storing the stack object name and the line number into a dictionary stackQObjectNum, storing the stack object name and the line number into a dictionary heapQObjectNum, returning to the step 24, and if not, returning to the step 24;
step 28: intercepting and searching a corresponding cpp file according to the h file name, and judging whether the corresponding cpp file exists or not; if not, returning to the step 22, if yes, acquiring the code in the cpp file, and executing the step 29;
step 29: judging whether the read code traverses or not; if yes, go back to step 22; if not, reading the code line and putting the code line into a string type line, and executing the step 210;
step 210: judging whether the line is an annotation; if yes, go back to step 29; otherwise, go to step 211;
step 211: judging whether the line is a statement or not; if yes, the class name and object name of the declaration object are obtained, and step 213 is executed; if not, go to step 212;
step 212: judging whether the line is an initialization statement or not; if yes, the class name and object name of the declaration object are obtained, and step 213 is executed; if not, returning to the step 29;
step 213: judging whether the QObject class or the subclass of the QT is present; if yes, storing the stack object name and line number into the dictionary stackQObjectNum, and storing the stack object name and line number into the dictionary heapQObjectNum; otherwise, the process returns to step 29.
6. The QT-based development general aviation flight service software memory anomaly detection and positioning method of claim 1, characterized in that: the third step specifically comprises:
step 31: acquiring a code in the cpp file;
step 32: judging whether the code traverses or not; if yes, ending; if not, reading the code line, putting the code line into a string type line, and executing the step 33;
step 33: judging whether the line is an annotation; if yes, go back to step 32, if no, go to step 34;
step 34: judging whether the sentence contains a setParent keyword; if yes, storing the child object name and the father object name obtained by analysis into a dictionary child ParentDict; if not, go to step 35;
step 35: judging whether the sentence is an initialization sentence and initializing a father object; if yes, analyzing to obtain a child object name and a parent object name and storing the child object name and the parent object name in a dictionary child ParentDict; otherwise, the process returns to the step 32.
7. The QT-based development general aviation flight service software memory anomaly detection and positioning method of claim 1, which is characterized in that: the fourth step specifically comprises:
step 41: acquiring a parent-child relationship dictionary child parentDict, and executing step 42;
step 42: judging whether to traverse a dictionary child ParentDict; if yes, ending; if not, go to step 43;
step 43: acquiring the name of the child object and the name of the parent object, and executing the step 44;
step 44: judging whether the sub-object is in a first stack object dictionary stackQObjectNum or not; if yes, go to step 45; if not, go to step 47;
step 45: judging whether the father object is in the first stack object dictionary stackQObjectNum or not; if yes, the row number of the parent-child object is obtained through the stackQObjectNum, and step 46 is executed; if not, returning to the step 42;
step 46: judging whether the value of the line number of the child object is smaller than that of the line number of the parent object; if yes, outputting the name of the child object and the name of the parent object, establishing a key statement of parent-child relationship, and returning to execute step 42;
step 47: judging whether the child object is in a second stack object dictionary heapQObjectNum or not; if yes, go to step 48; if not, returning to the step 42;
and step 48: judging whether the father object is in the second stack object dictionary heapQObjectNum or not; if yes, the line number of the parent-child object is obtained through the heapQObjectNum, and step 49 is executed; if not, returning to the step 42;
step 49: judging whether the value of the line number of the child object is larger than that of the line number of the parent object; if yes, the child object name and the parent object name are output, and the key sentence for establishing the parent-child relationship is returned to execute step 42.
CN201911200037.8A 2019-11-29 2019-11-29 QT-development-based universal aviation flight service software memory anomaly detection and positioning method Active CN111078540B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911200037.8A CN111078540B (en) 2019-11-29 2019-11-29 QT-development-based universal aviation flight service software memory anomaly detection and positioning method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911200037.8A CN111078540B (en) 2019-11-29 2019-11-29 QT-development-based universal aviation flight service software memory anomaly detection and positioning method

Publications (2)

Publication Number Publication Date
CN111078540A CN111078540A (en) 2020-04-28
CN111078540B true CN111078540B (en) 2023-03-07

Family

ID=70312074

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911200037.8A Active CN111078540B (en) 2019-11-29 2019-11-29 QT-development-based universal aviation flight service software memory anomaly detection and positioning method

Country Status (1)

Country Link
CN (1) CN111078540B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113157513B (en) * 2021-05-10 2024-06-18 北京字节跳动网络技术有限公司 Heap memory damage detection method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101944061A (en) * 2010-09-15 2011-01-12 青岛海信移动通信技术股份有限公司 Method and device for debugging codes
CN104461890A (en) * 2014-12-12 2015-03-25 四川川大智胜软件股份有限公司 Qt program memory using static test method for air traffic control training system
CN104536773A (en) * 2015-02-03 2015-04-22 积成电子股份有限公司 Method for recovering dynamic memory of embedded software based on memory scan
CN107729107A (en) * 2017-10-09 2018-02-23 武汉斗鱼网络科技有限公司 A kind of modal dialog box processing method and processing device

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102103676B (en) * 2011-02-28 2013-09-25 南京邮电大学 Method for protecting Java program progress based on inheritance relationship among progresses
CN104050076B (en) * 2013-03-12 2018-02-13 阿里巴巴集团控股有限公司 Application software testing method, apparatus and system on mobile terminal
US10108475B2 (en) * 2014-08-20 2018-10-23 Oracle International Corporation Pattern analysis for triaging memory leaks
CN104572471B (en) * 2015-01-28 2017-10-03 杭州电子科技大学 A kind of Java software Code Clones detection method based on index

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101944061A (en) * 2010-09-15 2011-01-12 青岛海信移动通信技术股份有限公司 Method and device for debugging codes
CN104461890A (en) * 2014-12-12 2015-03-25 四川川大智胜软件股份有限公司 Qt program memory using static test method for air traffic control training system
CN104536773A (en) * 2015-02-03 2015-04-22 积成电子股份有限公司 Method for recovering dynamic memory of embedded software based on memory scan
CN107729107A (en) * 2017-10-09 2018-02-23 武汉斗鱼网络科技有限公司 A kind of modal dialog box processing method and processing device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Relda2: An effective static analysis tool for resource leak detection in Android apps;Tianyong Wu等;《2016 3st IEEE/ACM International Conference on Automated Software Engineering (ASE)》;20161006;第762-767页 *
一种基于Qt的系统内存泄露检测方法;张玲等;《计算机技术与发展》;20170927;第119-123页 *

Also Published As

Publication number Publication date
CN111078540A (en) 2020-04-28

Similar Documents

Publication Publication Date Title
US8875110B2 (en) Code inspection executing system for performing a code inspection of ABAP source codes
RU2328032C2 (en) Checking system and xml method of documents accuracy and message delivery about scheme irregularity
US7617444B2 (en) File formats, methods, and computer program products for representing workbooks
US6574792B1 (en) Dynamically generating expanded user messages in a computer system
CN109471634B (en) Method and device for checking source code format
US20110197097A1 (en) Incremental problem determination and resolution in cloud environments
EP1672526A2 (en) File formats, methods, and computer program products for representing documents
US20120192151A1 (en) Software development tool
JP2000148461A (en) Software model and existing source code synchronizing method and device
US11113137B2 (en) Error incident fingerprinting with unique static identifiers
US20100131472A1 (en) Detection and utilzation of inter-module dependencies
US20070033579A1 (en) System and method for searching for multiple types of errors in file following translation into a new natural language
CN111078540B (en) QT-development-based universal aviation flight service software memory anomaly detection and positioning method
CN114003269A (en) Component processing method and device, electronic equipment and storage medium
CN112631944A (en) Source code detection method and device based on abstract syntax tree and computer storage medium
CN106886471A (en) A kind of read-write fault detection method and system based on disk in linux
CN115080448B (en) Method and device for automatically detecting inaccessible path of software code
CN110543641A (en) chinese and foreign language information comparison method and device
US20110047417A1 (en) Method and system for error detection in pattern definitions
JP2004126866A (en) Description output suppression program analysis system and description output suppression program analysis method
CN114116471A (en) Automatic code scanning method, system, electronic equipment and storage medium
CN114443165A (en) SQL file checking method and system based on domestic CPU and database
CN115374074A (en) Log processing method and device, storage medium and electronic equipment
CN116136825B (en) Data detection method and system
US20160239277A1 (en) Field size calculation and color coding display options usable in an emulated integrated development environment (ide)

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