Code positioning method and device, equipment, storage medium and vehicle

By matching the execution instructions and stack request instructions in the program assembly code and calculating the dynamic stack memory, the task stack overflow problem is solved and efficient and accurate code positioning is achieved.

CN120653409APending Publication Date: 2025-09-16SHANGHAI LIXIANG AUTOMOBILE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410288865.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-13
Publication Date
2025-09-16

AI Technical Summary

Technical Problem

Existing technologies cannot effectively locate the execution instructions in task stack overflows, making dynamic stack memory usage difficult to monitor and manual detection time-consuming and labor-intensive.

Method used

By obtaining the program assembly code, matching the execution instructions and stack request instructions, calculating the dynamic stack memory, and locating the target execution instructions whose dynamic stack memory exceeds the preset threshold.

Benefits of technology

It reduces labor costs, improves the efficiency and accuracy of code positioning, and clarifies the memory usage of the dynamic stack.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653409A_ABST
    Figure CN120653409A_ABST
Patent Text Reader

Abstract

The invention relates to a code positioning method and device, equipment, a storage medium and a vehicle, and the method comprises the steps: obtaining a program assembly code which comprises a plurality of execution instructions and a stack application instruction; respectively matching the plurality of execution instructions and the stack application instruction; determining a target execution instruction matched with the stack application instruction, and calculating a dynamic stack memory applied by the stack application instruction according to the arithmetic logic of the target execution instruction; when the dynamic stack memory is larger than a preset memory threshold value, the target execution instruction is positioned, the dynamic stack memory applied by the stack application instruction is calculated through the operation logic of the target execution instruction matched with the stack application instruction, and the dynamic stack use condition of the target execution instruction is clarified; compared with the prior art, manual code inspection is not needed, the labor cost is reduced, the code positioning efficiency is improved, and the accuracy of the code positioning method is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a code positioning method, apparatus, device, storage medium, and vehicle. Background Art

[0002] The memory used during program execution is divided into static memory and dynamic memory. Static memory refers to the size of compiled code segments and data segments. Dynamic memory refers to the memory allocated by the system from the dynamic heap or dynamic stack during runtime. The dynamic stack refers to the memory allocated by pop or push instructions within the context of program function execution. Excessive dynamic stack memory allocation leads to memory waste and can cause the task stack to overflow during runtime due to insufficient space.

[0003] In the existing technology, one solution is to detect task stack overflow and determine whether the task context execution code is written improperly. However, this solution cannot reflect the dynamic stack usage of each execution instruction. Another solution is to examine the execution code to see whether a large number of arrays are defined and used inside the program function. Although this solution can determine the memory requested in the dynamic stack, it is time-consuming and labor-intensive.

[0004] Therefore, a code location method is urgently needed to locate the execution instructions that cause task stack overflow during task execution and determine the memory application status of the dynamic stack. Summary of the Invention

[0005] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a code positioning method, device, equipment, storage medium and vehicle to reduce labor costs, improve the efficiency of code positioning, and enhance the accuracy of the code positioning method.

[0006] In a first aspect, an embodiment of the present disclosure provides a code positioning method, comprising:

[0007] Obtaining a program assembly code, wherein the program assembly code includes a plurality of execution instructions and a stack allocation instruction;

[0008] Matching the plurality of execution instructions and the stack application instruction respectively;

[0009] Determine a target execution instruction that matches the stack application instruction, and calculate the dynamic stack memory applied for by the stack application instruction according to the operation logic of the target execution instruction;

[0010] When the dynamic stack memory is larger than a preset memory threshold, the target execution instruction is located.

[0011] In some embodiments, matching the plurality of execution instructions and the stack allocation instruction respectively includes:

[0012] For each execution instruction, comparing a first code value of the execution instruction with a second code value of the stack application instruction;

[0013] When the first encoding value and the second encoding value are equal, it is determined that the execution instruction and the stack allocation instruction match.

[0014] In some embodiments, the method further comprises:

[0015] Obtaining a first code of the execution instruction and a second code of the stack application instruction;

[0016] A first code value of the first code and a second code value of the second code are calculated.

[0017] In some embodiments, calculating a first code value of the first code and a second code value of the second code includes:

[0018] When the first code of the execution instruction and the second code of the stack application instruction have different bases, performing base conversion on the first code of the execution instruction and the second code of the stack application instruction respectively to obtain a first code value of the execution instruction and a second code value of the stack application instruction, wherein the first code value and the second code value have the same base;

[0019] When the first code of the execution instruction and the second code of the stack allocation instruction are in the same base, the first code is determined as the first code value, and the second code is determined as the second code value.

[0020] In some embodiments, obtaining the second encoding of the stack application instruction includes:

[0021] The second encoding of the stack application instruction is obtained through the fixed format of the stack application instruction.

[0022] In some embodiments, calculating the dynamic stack memory requested by the stack request instruction according to the operation logic of the target execution instruction includes:

[0023] Determining the instruction type and operation of the target execution instruction by parsing the target execution instruction;

[0024] The dynamic stack memory requested by the stack request instruction is calculated by the arithmetic operation according to the instruction type, where the instruction type includes at least one of the following:

[0025] Arithmetic instructions;

[0026] Logical instructions;

[0027] Shift instructions.

[0028] In a second aspect, an embodiment of the present disclosure provides a code locating device, comprising:

[0029] A first acquisition module is used to acquire a program assembly code, wherein the program assembly code includes a plurality of execution instructions and stack allocation instructions;

[0030] A matching module, configured to match the plurality of execution instructions and the stack application instruction respectively;

[0031] A first calculation module is used to determine a target execution instruction that matches the stack application instruction, and calculate the dynamic stack memory requested by the stack application instruction according to the operation logic of the target execution instruction;

[0032] A positioning module is used to locate the target execution instruction when the dynamic stack memory is greater than a preset memory threshold.

[0033] In a third aspect, an embodiment of the present disclosure provides an electronic device, including:

[0034] Memory;

[0035] processor; and

[0036] computer programs;

[0037] The computer program is stored in the memory and is configured to be executed by the processor to implement the method as described in the first aspect.

[0038] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the method described in the first aspect.

[0039] In a fifth aspect, an embodiment of the present disclosure further provides a vehicle, comprising: the code positioning device as described in the second aspect; or, the electronic device as described in the third aspect; or, the computer-readable storage medium as described in the fourth aspect.

[0040] The code positioning method, apparatus, device, storage medium and vehicle provided by the embodiments of the present disclosure obtain program assembly code, wherein the program assembly code includes multiple execution instructions and stack application instructions; the multiple execution instructions and the stack application instructions are matched respectively; a target execution instruction matching the stack application instruction is determined, and the dynamic stack memory requested by the stack application instruction is calculated according to the operation logic of the target execution instruction; when the dynamic stack memory is greater than a preset memory threshold, the target execution instruction is positioned, and the dynamic stack memory requested by the stack application instruction is calculated through the operation logic of the target execution instruction matching the stack application instruction, and the dynamic stack usage of the target execution instruction is clarified; when the dynamic stack memory is greater than the preset memory threshold, the target execution instruction is positioned. Compared with the prior art, manual code review is not required, which reduces labor costs, improves the efficiency of code positioning, and enhances the accuracy of the code positioning method. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0042] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0043] Figure 1 A flow chart of a code location method provided in an embodiment of the present disclosure;

[0044] Figure 2 A schematic diagram of the program assembly code provided by an embodiment of the present disclosure;

[0045] Figure 3 A schematic diagram of encoding of a stack application instruction provided in an embodiment of the present disclosure;

[0046] Figure 4 A schematic diagram of encoding of a stack application instruction provided in an embodiment of the present disclosure;

[0047] Figure 5 A flow chart of a code location method provided in an embodiment of the present disclosure;

[0048] Figure 6 A schematic diagram of the structure of a code positioning device provided in an embodiment of the present disclosure;

[0049] Figure 7 A schematic diagram of the structure of a code positioning device provided in an embodiment of the present disclosure;

[0050] Figure 8A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0051] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features therein can be combined with each other in the absence of conflict.

[0052] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0053] The embodiments of the present disclosure provide a code positioning method, which is described below in conjunction with specific embodiments.

[0054] Figure 1 This is a flow chart of the code location method provided by an embodiment of the present disclosure. The method can be executed by a code location device, which can be implemented in software and / or hardware. The code location device can be configured in an electronic device, such as a server or a terminal, where the terminal specifically includes a mobile phone, a computer, or a tablet computer. In addition, the method can be applied to application scenarios such as analyzing the dynamic stack of program assembly code and application scenarios such as code location. It is understandable that the code location method provided by the embodiment of the present disclosure can also be applied in other scenarios.

[0055] Figure 1 The flowchart of the code positioning method provided by the embodiment of the present disclosure is as follows: Figure 1 As shown, the method includes the following specific steps:

[0056] S101: Obtain program assembly code, where the program assembly code includes multiple execution instructions and stack allocation instructions.

[0057] Assembly language is a low-level programming language used to communicate with a specific type of computer architecture or processor. The code locating device obtains program assembly code, which can be obtained by code assembly.

[0058] Optionally, obtaining the program assembly code includes: determining a target architecture platform; and obtaining the program assembly code of the target architecture platform.

[0059] The same content has different corresponding assembly languages ​​in different architectures. Therefore, it is necessary to first obtain the target architecture platform and then obtain the program assembly code of the target architecture platform. For example, the target architecture platform can be ARM, x86, RISC-V, etc. The implementation methods and implementation principles of target architecture platforms such as ARM, x86, RISC-V are similar. This embodiment will take the program assembly code of the ARM architecture platform as an example.

[0060] For example, the code for the ARM architecture platform is as follows:

[0061] int stack_test(void)

[0062] {

[0063] char stack_tmp

[1024] ;

[0064] stack_tmp[0] = '1';

[0065] printf("%s",stack_tmp);

[0066] }

[0067] int main(void)

[0068] {

[0069] stack_test();

[0070] }

[0071] In the above code, the stack_test function defines the target array stack_tmp

[1024] , which dynamically divides the dynamic stack space into 1024 bytes. The corresponding assembly program is as follows Figure 2 As shown, the first column represents the address of the program assembly code, the second column represents the code of the execution instruction, the third column represents the execution instruction, and the fourth column is the assembly language of the execution instruction. Figure 2 In the example, multiple execution instructions include: movw, movt, sub, mov, etc., and the corresponding codes of the multiple execution instructions include e3000000, e3400000, e24ddb01, e3a03031, etc.

[0072] The encoding format of the stack request instruction in ARM is as follows:

[0073] SUB,SUBS(SP minus immediate)

[0074] Figure 3 and Figure 4 A schematic diagram of the encoding of the stack application instruction provided in the embodiment of the present disclosure is shown as follows: Figure 3As shown, imm12 represents a constant, and the total length of imm12 is 12 bits. Figure 4 As shown, it is divided into high-bit rot from 11 to 8 and 8-bit immediate from 7 to 0.

[0075] S102: Match the multiple execution instructions and the stack allocation instruction respectively.

[0076] Each execution instruction is matched with the stack application instruction, such as by matching the encoding of each execution instruction with the encoding of the stack application instruction. For example, the encoding e3000000 of the execution instruction movw and Figure 3 The stack request instruction code shown matches the execution instruction sub code e24ddb01 and Figure 3 The stack request instruction encoding shown matches.

[0077] In other embodiments, the execution instruction and the stack allocation instruction may be matched by calculating the first encoding value of the execution instruction and the second encoding value of the stack allocation instruction.

[0078] S103: Determine a target execution instruction that matches the stack application instruction, and calculate the dynamic stack memory requested by the stack application instruction according to the operation logic of the target execution instruction.

[0079] A dynamic stack is a data structure implementation in which the stack size can dynamically grow or shrink as needed. When an execution instruction matches a stack allocation instruction, the target execution instruction that matches the stack allocation instruction is determined. The dynamic stack memory allocated by the stack allocation instruction is calculated based on the operation logic of the target execution instruction.

[0080] Optionally, the dynamic stack memory requested by the stack application instruction is calculated according to the operation logic of the target execution instruction, including: determining the instruction type and operation operation of the target execution instruction by parsing the target execution instruction; and calculating the dynamic stack memory requested by the stack application instruction through the operation operation according to the instruction type.

[0081] Parse the target execution instruction, for example, the execution instruction sub code e24ddb01 and Figure 3 If the stack request instruction encoding shown matches, the execution instruction sub is the target execution instruction. The target execution instruction sub is parsed to determine the instruction type and operation of the target execution instruction sub. Sub is the abbreviation of subtraction, which means moving right in this embodiment. Sub sp, sp, #n means that sp moves to a lower address, freeing up memory space of size n for use. Figure 4The encoding of the stack allocation instruction shown indicates a circular right shift of imm by rot*2. Based on the instruction type of the target execution instruction, the dynamic stack memory allocated by the stack allocation instruction is calculated through arithmetic operations. The specific calculation method is: the lower 8 bits of the stack allocation instruction are 1; the upper 4 bits of the stack allocation instruction are 0b`1011 = 11, sub sp, sp, #1024, which means 1 is circularly shifted right by 22 bits.

[0082] S104: When the dynamic stack memory is larger than a preset memory threshold, locate the target execution instruction.

[0083] When the dynamic stack memory is greater than a preset memory threshold, the target execution instruction matching the stack request instruction is located. The preset memory can be set according to actual conditions and is not limited in this embodiment.

[0084] Optionally, in some embodiments, when the dynamic stack memory is less than or equal to a preset memory threshold, the target execution instruction matching the stack request instruction is ignored.

[0085] The embodiment of the present disclosure obtains program assembly code, which includes multiple execution instructions and stack application instructions; matches the multiple execution instructions and the stack application instructions respectively; determines the target execution instruction that matches the stack application instruction, and calculates the dynamic stack memory requested by the stack application instruction according to the operation logic of the target execution instruction; when the dynamic stack memory is greater than a preset memory threshold, locates the target execution instruction, calculates the dynamic stack memory requested by the stack application instruction through the operation logic of the target execution instruction that matches the stack application instruction, clarifies the dynamic stack usage of the target execution instruction, and locates the target execution instruction when the dynamic stack memory is greater than the preset memory threshold. Compared with the existing technology, there is no need for manual code inspection, which reduces labor costs, improves the efficiency of code positioning, and enhances the accuracy of the code positioning method.

[0086] Based on the above embodiment, the matching of the multiple execution instructions and the stack application instruction respectively includes: for each execution instruction, comparing the first encoding value of the execution instruction and the second encoding value of the stack application instruction; when the first encoding value and the second encoding value are equal, determining that the execution instruction and the stack application instruction match.

[0087] Optionally, the method further includes: obtaining a first code of the execution instruction and a second code of the stack allocation instruction; and calculating a first code value of the first code and a second code value of the second code.

[0088] Optionally obtaining the second encoding of the stack application instruction includes: obtaining the second encoding of the stack application instruction through a fixed format of the stack application instruction.

[0089] Specifically, the second code of the stack application instruction is obtained through the fixed format of the stack application instruction, and the second code value of the second code is calculated. For each execution instruction, the first code of the execution instruction is obtained and the first code value of the first code is calculated. The first code value of the execution instruction and the second code value of the stack application instruction are compared. When the first code value and the second code value are equal, it is determined that the execution instruction and the stack application instruction match.

[0090] Optionally, calculating the first code value of the first code and the second code value of the second code includes: when the first code of the execution instruction and the second code of the stack application instruction have different bases, performing base conversion on the first code of the execution instruction and the second code of the stack application instruction respectively to obtain the first code value of the execution instruction and the second code value of the stack application instruction, and the first code value and the second code value have the same base; when the first code of the execution instruction and the second code of the stack application instruction have the same base, determining the first code as the first code value, and determining the second code as the second code value.

[0091] Base conversion is a common operation in computer science and mathematics that involves converting numbers from one number system (or base) to another. The most common number systems are decimal (base 10), binary (base 2), octal (base 8), and hexadecimal (base 16).

[0092] When the execution instruction and the stack application instruction have different bases, for example, when the execution instruction is in hexadecimal and the stack application instruction is in binary, the first code value of each execution instruction is calculated, and the second code value of the stack application instruction is calculated. Specifically, the stack application instruction can be converted from binary to hexadecimal, and the first code value of each execution instruction is compared with the second code value of the stack application instruction to see if they are the same; the first code value of each execution instruction can also be converted from hexadecimal to binary, and the first code value of each execution instruction is compared with the second code value of the stack application instruction to see if they are the same; the first code value of each execution instruction and the second code value of the stack application instruction can also be converted into decimal or other identical bases, and the first code value of each execution instruction is compared with the second code value of the stack application instruction to see if they are the same. When the first code value and the second code value are numerically equal, it is determined that the execution instruction and the stack application instruction match.

[0093] When the first code of the execution instruction and the second code of the stack allocation instruction have the same base, the first code is determined as the first code value; and the second code is determined as the second code value. For example, the first code value and the second code value can both be binary, octal, decimal, hexadecimal, etc., which is not limited in this embodiment.

[0094] The embodiment of the present disclosure obtains the first code value of the execution instruction and the second code value of the stack application instruction by performing base conversion on the first code of the execution instruction and the second code of the stack application instruction. The bases of the first code value and the second code value are the same. The first code value and the second code value are compared. When the first code value and the second code value are equal, it is determined that the execution instruction and the stack application instruction match, which provides a data basis for code positioning, eliminates the need for manual code review, reduces labor costs, and improves the accuracy of the code positioning method.

[0095] Figure 5 A flowchart of a code location method provided by another embodiment of the present disclosure is shown in FIG. Figure 5 As shown, the method includes the following steps:

[0096] S501: Obtain program assembly code, where the program assembly code includes multiple execution instructions and stack allocation instructions.

[0097] Specifically, the implementation process and principle of S501 and S101 are the same and will not be described in detail here.

[0098] S502. Obtain a first code of the execution instruction and a second code of the stack application instruction; calculate a first code value of the first code and a second code value of the second code; and for each execution instruction, compare the first code value of the execution instruction and the second code value of the stack application instruction.

[0099] The second code of the stack application instruction is obtained through the fixed format of the stack application instruction, and the second code value of the second code is calculated. For each execution instruction, the first code of the execution instruction is obtained, and the first code value of the first code is calculated; and the first code value of the execution instruction is compared with the second code value of the stack application instruction.

[0100] Optionally, calculating the first code value of the first code and the second code value of the second code includes: when the first code of the execution instruction and the second code of the stack application instruction have different bases, performing base conversion on the first code of the execution instruction and the second code of the stack application instruction respectively to obtain the first code value of the execution instruction and the second code value of the stack application instruction, and the first code value and the second code value have the same base; when the first code of the execution instruction and the second code of the stack application instruction have the same base, determining the first code as the first code value, and determining the second code as the second code value.

[0101] Base conversion is a common operation in computer science and mathematics that involves converting numbers from one number system (or base) to another. The most common number systems are decimal (base 10), binary (base 2), octal (base 8), and hexadecimal (base 16).

[0102] Exemplarily, when the execution instruction and the stack application instruction have different bases, for example, when the execution instruction is in hexadecimal and the stack application instruction is in binary, the first code value of each execution instruction is calculated, and the second code value of the stack application instruction is calculated. Specifically, the stack application instruction can be converted from binary to hexadecimal, and the first code value of each execution instruction is compared with the second code value of the stack application instruction to see if they are the same; the first code value of each execution instruction can also be converted from hexadecimal to binary, and the first code value of each execution instruction is compared with the second code value of the stack application instruction to see if they are the same; the first code value of each execution instruction and the second code value of the stack application instruction can also be converted into decimal or other identical bases, and the first code value of each execution instruction is compared with the second code value of the stack application instruction to see if they are the same. When the first code value and the second code value are numerically equal, it is determined that the execution instruction and the stack application instruction match.

[0103] For example, when the first encoding of the execution instruction and the second encoding of the stack allocation instruction have the same base, the first encoding is determined as the first encoding value, and the second encoding is determined as the second encoding value. For example, the first encoding value and the second encoding value can both be binary, octal, decimal, hexadecimal, etc., and this embodiment is not limited thereto.

[0104] S503: When the first coding value and the second coding value are equal, determine that the execution instruction and the stack allocation instruction match.

[0105] S504: Determine a target execution instruction that matches the stack request instruction, and determine an instruction type and a calculation operation of the target execution instruction by parsing the target execution instruction.

[0106] S505 , calculating the dynamic stack requested by the stack request instruction through the arithmetic operation according to the instruction type.

[0107] For example, the code e24ddb01 and Figure 3 The stack request instruction encoding shown is matched, the execution instruction sub is parsed, and the instruction type and operation of the execution instruction sub are determined. Among them, sub is the abbreviation of subtraction; for moving right, sub sp, sp, #n means that sp moves to a lower address, making room for n-sized memory space for use. Figure 4The encoding of the stack allocation instruction shown indicates a circular right shift of imm by rot*2. Based on the instruction type, the dynamic stack memory allocated by the stack allocation instruction is calculated using the following arithmetic operations: the lower 8 bits of the stack allocation instruction are 1; the upper 4 bits of the stack allocation instruction are 0b`1011 = 11, sub sp, sp, #1024, which means a circular right shift of 1 by 22 bits.

[0108] Optionally, the instruction type includes at least one of the following: an arithmetic instruction; a logical instruction; a shift instruction.

[0109] Specifically, arithmetic instructions are mainly used to perform various arithmetic operations. These instructions usually involve basic arithmetic operations such as addition, subtraction, multiplication, and division.

[0110] Specifically, logic instructions are mainly used to perform logical operations on data. These operations generally include basic operations such as logical AND, logical OR, and logical NOT, as well as combinational logic operations such as XOR and XOR.

[0111] Specifically, shift instructions can perform bit shift operations on binary data. Shift instructions generally include two types: logical shift and arithmetic shift. Among them, logical shift instructions mainly focus on how to fill the empty bits after the shift. The logical left shift (such as SHL) instruction shifts all the bits of the operand to the left by the specified number of bits, and fills the empty bits on the right with 0; the logical right shift (such as SHR) instruction shifts all the bits of the operand to the right, and the empty bits on the left are also filled with 0. Arithmetic shift instructions consider the preservation of the sign bit when shifting. Arithmetic left shift (such as SAL) is usually the same as logical left shift, while arithmetic right shift (such as SAR) fills the empty bits on the left with the original sign bit (that is, the highest bit) when shifting the operand to the right to keep the sign of the number unchanged.

[0112] S506 , determining whether the dynamic stack memory has a preset memory threshold, if so, executing S507 ; if not, executing S508 .

[0113] S507: Locate an execution instruction that matches the stack request instruction.

[0114] S508: Ignore the execution instruction that matches the stack request instruction.

[0115] The disclosed embodiment obtains program assembly code, which includes multiple execution instructions and stack request instructions; performs base conversion on a first code of the execution instruction and a second code of the stack request instruction to obtain a first code value of the execution instruction and a second code value of the stack request instruction, wherein the first code value and the second code value have the same base, and compares the first code value and the second code value; determines that the execution instruction and the stack request instruction match when the first code value and the second code value are equal; parses the execution instruction based on the match between the execution instruction and the stack request instruction to determine the instruction type and operation of the execution instruction; calculates the dynamic stack memory requested by the stack request instruction based on the operation according to the instruction type; calculates the dynamic stack memory requested by the stack request instruction by matching the execution instruction with the stack request instruction, clarifies the dynamic stack usage of the execution instruction, and locates the execution instruction that matches the stack request instruction when the dynamic stack memory is greater than a preset memory threshold. Compared with the prior art, manual code review is unnecessary, which reduces labor costs, improves the efficiency of code location, and enhances the accuracy of the code location method.

[0116] Figure 6 This is a schematic diagram of the structure of the code positioning device provided by the embodiment of the present disclosure. The code positioning device can be the terminal as described in the above embodiment, or the code positioning device can be a component or assembly in the terminal. The code positioning device provided by the embodiment of the present disclosure can execute the processing flow provided by the embodiment of the code positioning method, such as Figure 6 As shown, the code positioning device 60 includes:

[0117] A first acquisition module 61 is used to acquire a program assembly code, wherein the program assembly code includes a plurality of execution instructions and stack allocation instructions;

[0118] a matching module 62, configured to match the plurality of execution instructions and the stack application instruction respectively;

[0119] A first calculation module 63 is configured to determine a target execution instruction that matches the stack application instruction, and calculate the dynamic stack memory requested by the stack application instruction according to the operation logic of the target execution instruction;

[0120] The positioning module 64 is configured to locate the target execution instruction when the dynamic stack memory is greater than a preset memory threshold.

[0121] Optionally, the matching module 62 is further used to compare the first coding value of the execution instruction and the second coding value of the stack application instruction for each execution instruction; when the first coding value and the second coding value are equal, it is determined that the execution instruction and the stack application instruction match.

[0122] Alternatively, as Figure 7 As shown, the code positioning device 60 also includes: a second acquisition module 71 and a second calculation module 72; wherein the second acquisition module 71 is used to obtain the first code of the execution instruction and the second code of the stack application instruction; the second calculation module 72 is used to calculate the first code value of the first code and the second code value of the second code.

[0123] Optionally, the second calculation module 72 is also used to perform base conversion on the first code of the execution instruction and the second code of the stack application instruction respectively when the bases of the first code of the execution instruction and the second code of the stack application instruction are different, so as to obtain the first code value of the execution instruction and the second code value of the stack application instruction, and the first code value and the second code value have the same base; when the first code of the execution instruction and the second code of the stack application instruction have the same base, the first code is determined as the first code value, and the second code is determined as the second code value.

[0124] Optionally, the second acquisition module 71 is further configured to acquire the second code of the stack application instruction through a fixed format of the stack application instruction.

[0125] Optionally, the first calculation module 63 is also used to determine the instruction type and operation of the target execution instruction by parsing the target execution instruction; according to the instruction type, calculate the dynamic stack memory requested by the stack request instruction through the operation, and the instruction type includes at least one of the following: arithmetic instruction; logical instruction; shift instruction.

[0126] Figure 6 The code positioning device of the illustrated embodiment can be used to implement the technical solution of the above-mentioned code positioning method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.

[0127] In some embodiments, the above-mentioned code locating device can also be designed as a code detection tool, which traverses and scans all program assembly codes according to the format of the stack request instruction encoding, and filters out execution instructions whose dynamic stack memory requested by the stack request instruction is greater than the preset memory threshold, thereby realizing code locating and facilitating users to analyze abnormal dynamic stack requests.

[0128] Figure 8 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. The electronic device may be a terminal as described in the above embodiment. The electronic device provided by an embodiment of the present disclosure may execute the processing flow provided by the embodiment of the code positioning method, such as Figure 8As shown, the electronic device 80 includes: a memory 81, a processor 82, a computer program and a communication interface 83; wherein the computer program is stored in the memory 81 and is configured so that the processor 82 executes the code positioning method as described above.

[0129] In addition, an embodiment of the present disclosure further provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the code locating method described in the above embodiment.

[0130] In addition, an embodiment of the present disclosure further provides a vehicle, which includes the code positioning device as described in the above embodiment; or the electronic device as described in the above embodiment; or the computer-readable storage medium as described in the above embodiment.

[0131] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or component. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.

[0132] In some embodiments, the client and server can communicate using any currently known or future developed network protocol, such as HTTP (HyperText Transfer Protocol), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0133] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0134] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device:

[0135] Obtaining a program assembly code, wherein the program assembly code includes a plurality of execution instructions and a stack allocation instruction;

[0136] Matching the plurality of execution instructions and the stack application instruction respectively;

[0137] Determine a target execution instruction that matches the stack application instruction, and calculate the dynamic stack memory applied for by the stack application instruction according to the operation logic of the target execution instruction;

[0138] When the dynamic stack memory is larger than a preset memory threshold, the target execution instruction is located.

[0139] In addition, the electronic device may also execute other steps in the code positioning method described above.

[0140] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including, but not limited to, object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0141] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0142] The units involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the name of a unit does not necessarily limit the unit itself.

[0143] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.

[0144] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0145] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0146] The foregoing description is intended only to provide specific embodiments of the present disclosure, intended to enable those skilled in the art to understand and implement the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but rather to be construed in the broadest manner consistent with the principles and novel features disclosed herein.

Claims

1. A code positioning method, characterized in that: The method comprises: Obtaining a program assembly code, wherein the program assembly code includes a plurality of execution instructions and a stack allocation instruction; Matching the plurality of execution instructions and the stack application instruction respectively; Determine a target execution instruction that matches the stack application instruction, and calculate the dynamic stack memory applied for by the stack application instruction according to the operation logic of the target execution instruction; When the dynamic stack memory is larger than a preset memory threshold, the target execution instruction is located.

2. The method according to claim 1, characterized in that The matching of the plurality of execution instructions and the stack application instruction respectively includes: For each execution instruction, comparing a first code value of the execution instruction with a second code value of the stack application instruction; When the first encoding value and the second encoding value are equal, it is determined that the execution instruction and the stack allocation instruction match.

3. The method according to claim 2, characterized in that The method further comprises: Obtaining a first code of the execution instruction and a second code of the stack application instruction; A first code value of the first code and a second code value of the second code are calculated.

4. The method according to claim 3, characterized in that Calculating a first code value of the first code and a second code value of the second code includes: When the first code of the execution instruction and the second code of the stack application instruction have different bases, performing base conversion on the first code of the execution instruction and the second code of the stack application instruction respectively to obtain a first code value of the execution instruction and a second code value of the stack application instruction, wherein the first code value and the second code value have the same base; When the first code of the execution instruction and the second code of the stack allocation instruction are in the same base, the first code is determined as the first code value, and the second code is determined as the second code value.

5. The method according to claim 3, characterized in that Obtaining a second encoding of the stack application instruction includes: The second encoding of the stack application instruction is obtained through the fixed format of the stack application instruction.

6. The method according to claim 1, characterized in that Calculating the dynamic stack memory requested by the stack request instruction according to the operation logic of the target execution instruction includes: Determining the instruction type and operation of the target execution instruction by parsing the target execution instruction; The dynamic stack memory requested by the stack request instruction is calculated by the arithmetic operation according to the instruction type, where the instruction type includes at least one of the following: Arithmetic instructions; Logical instructions; Shift instructions.

7. A code positioning device, characterized in that: The device comprises: A first acquisition module is used to acquire a program assembly code, wherein the program assembly code includes a plurality of execution instructions and stack allocation instructions; A matching module, configured to match the plurality of execution instructions and the stack application instruction respectively; A first calculation module is configured to determine a target execution instruction that matches the stack application instruction, and calculate the dynamic stack memory requested by the stack application instruction according to the operation logic of the target execution instruction; A positioning module is used to locate the target execution instruction when the dynamic stack memory is greater than a preset memory threshold.

8. An electronic device, characterized in that: include: Memory; processor; as well as computer programs; The computer program is stored in the memory and configured to be executed by the processor to implement the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

10. A vehicle, characterized in that: include: The code positioning device according to claim 7; Or, the electronic device according to claim 8; Or, the computer-readable storage medium of claim 9.