Semaphore exception positioning method and device, electronic equipment and storage medium

By recording semaphore metadata and obtaining abnormal semaphore identifiers, abnormal code segments in embedded systems can be directly located, solving the problem of being stuck due to semaphore contention or deadlock, and improving the efficiency of troubleshooting and repair.

CN122285472APending Publication Date: 2026-06-26LOONGSON TECH CORP
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
LOONGSON TECH CORP
Filing Date
2026-02-26
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

In embedded systems, semaphore contention or deadlock can cause system crashes that are difficult to locate directly, leading to longer troubleshooting and repair cycles and impacting development efficiency.

Method used

By recording the semaphore metadata corresponding to the management operations of each semaphore in the target system, including semaphore identifiers and variable addresses, the abnormal semaphore identifiers are obtained and the target variable addresses are searched in the metadata, thereby directly locating the abnormal code fragments.

Benefits of technology

It improves the efficiency of locating abnormal signals, shortens the troubleshooting and repair time, and improves system maintenance efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122285472A_ABST
    Figure CN122285472A_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, electronic device, and storage medium for semaphore anomaly localization, belonging to the field of computer technology. It records semaphore metadata corresponding to management operations on each semaphore based on a target data structure. The semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system. When a semaphore anomaly occurs in the target system, the abnormal semaphore identifier is obtained. Based on the abnormal semaphore identifier, the target variable address corresponding to the abnormal semaphore identifier is searched in the semaphore metadata. The corresponding target code segment is located based on the target variable address. This allows for real-time tracing from the abnormal semaphore identifier to the target code segment in the program code after a semaphore anomaly occurs in the target system, improving the efficiency of semaphore anomaly localization, shortening anomaly investigation and repair time, and thus improving system maintenance efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of computer technology, and specifically relates to a method, apparatus, electronic device and storage medium for anomaly localization of semaphores. Background Technology

[0002] As the complexity of embedded systems continues to increase, concurrent execution of multiple tasks and resource sharing have become the norm. However, embedded systems can sometimes be stuck due to semaphores, severely impacting system stability and reliability.

[0003] In related technologies, when a system is stuck due to semaphore contention or deadlock, technicians often can only debug by manually analyzing the code line by line or by using debugging tools to traverse a large number of memory areas. These methods often make it difficult to directly locate the specific semaphore object in the program, which in turn makes it difficult to locate the code segment that caused the system to freeze from among many semaphores. This prolongs the cycle of system fault diagnosis and repair, and affects development efficiency. Summary of the Invention

[0004] To overcome the problems existing in related technologies, this application provides a method, apparatus, electronic device and storage medium for anomaly localization of signals.

[0005] In a first aspect, embodiments of this application provide a method for anomaly localization of semaphores, the method comprising: Based on the target data structure, the semaphore metadata corresponding to the management operation of each semaphore is recorded respectively; the semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system; When an abnormal semaphore phenomenon occurs in the target system, an abnormal semaphore identifier is obtained; Based on the abnormal semaphore identifier, the address of the target variable corresponding to the abnormal semaphore identifier is found in the semaphore metadata. The target code segment is located based on the address of the target variable.

[0006] Secondly, embodiments of this application provide a signal anomaly location device, the device comprising: The first recording module is used to record the semaphore metadata corresponding to the management operation of each semaphore based on the target data structure; the semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system; The first acquisition module is used to acquire the abnormal semaphore identifier when the target system experiences an abnormal semaphore phenomenon. The first lookup module is used to search for the address of the target variable corresponding to the abnormal semaphore identifier in the semaphore metadata based on the abnormal semaphore identifier; The first positioning module is used to locate the corresponding target code segment based on the address of the target variable.

[0007] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.

[0008] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.

[0009] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.

[0010] In this embodiment, by recording semaphore metadata corresponding to each management operation in the target system, including semaphore identifiers and variable addresses, when a semaphore anomaly occurs in the target system, the abnormal semaphore identifier is first obtained as an index, and the corresponding target variable address is found in the recorded semaphore metadata. Based on the target variable address, the abnormal target code segment can be directly located, avoiding manual line-by-line code analysis or traversing a large number of memory regions for investigation. This allows the target system to directly trace the target code segment in the program code in real time from the abnormal semaphore identifier after a semaphore anomaly occurs, improving the efficiency of semaphore anomaly location, shortening the anomaly investigation and repair time, and thus improving system maintenance efficiency. Attached Figure Description

[0011] Figure 1 This is a flowchart illustrating the steps of a semaphore anomaly localization method provided in an embodiment of this application; Figure 2 This is a schematic diagram of a target linked list provided in an embodiment of this application; Figure 3 This is a schematic diagram of the processing stages of a target system provided in an embodiment of this application; Figure 4 This is a structural diagram of a signal anomaly location device provided in an embodiment of this application; Figure 5 This is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0012] The anomaly localization method for signals provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.

[0013] Figure 1 This is a flowchart illustrating the steps of a semaphore anomaly localization method provided in an embodiment of this application, as follows: Figure 1 As shown, the method may include: Step 101: Based on the target data structure, record the semaphore metadata corresponding to the management operation of each semaphore; the semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system.

[0014] In this embodiment, during the operation of the target system, whenever the code performs management operations on each semaphore, such as initializing, creating, releasing, or deleting a semaphore, it synchronously records the semaphore metadata corresponding to each management operation based on the target data structure. The semaphore can be a binary semaphore, a mutex semaphore, or a counting semaphore. The semaphore metadata can include the semaphore identifier and variable address of each semaphore in the target system. The target system can be an embedded system, and the target data structure can be a data structure with traversal and search functions, such as an array or a linked list. The semaphore identifier is a string, number, or other form of encoding used to identify each semaphore. The variable address can be the memory address of the variable corresponding to the management operation, pointing to a memory area storing semaphore state information related to the semaphore. The semaphore state information can include the current state of the semaphore, associated tasks, etc. Specifically, the code modifies the current state of the semaphore by calling the corresponding interface, thereby synchronously updating the semaphore state information stored in the memory area corresponding to the variable address of the semaphore. In other words, all state changes of a semaphore can be triggered through the corresponding interface of the semaphore in the code, and the state change results of the semaphore can be reflected in the memory pointed to by the variable address where the semaphore is located.

[0015] For example, in a scenario where semaphore resources are dynamically allocated, a variable is defined based on actual needs. For instance, a variable named `aaa` is defined with an integer data type, and this variable occupies storage space in memory. When the system performs a semaphore creation operation, it assigns a unique identifier (i.e., a semaphore identifier) ​​to the semaphore and stores this identifier in the user-defined variable `aaa`. In other words, after successful semaphore creation, the semaphore identifier corresponding to the requested semaphore is stored in the variable `aaa`. The specific memory location of the variable `aaa` containing the semaphore identifier is the address of the variable corresponding to the semaphore creation operation. This address can be used as the target variable address to locate the variable storing semaphore-related information when subsequent semaphore management operations or semaphore anomalies occur. Furthermore, by examining the relevant target code snippets, anomaly investigation, verification, and repair can be performed.

[0016] Step 102: In the event of an abnormal semaphore phenomenon in the target system, obtain the abnormal semaphore identifier.

[0017] In this embodiment, when a semaphore anomaly occurs in the target system, such as semaphore deadlock or semaphore leakage, the anomaly type can be determined first. Then, based on the semaphore identifier acquisition method corresponding to that anomaly type, analysis can be performed to identify the abnormal semaphore identifier. When a semaphore anomaly occurs, the root cause often resides in the code snippet corresponding to a certain management operation.

[0018] For example, in the event of a semaphore deadlock, the type of semaphore causing the deadlock can be determined by analyzing the waiting relationships of threads and the holding status of semaphores. Then, the semaphore identifier corresponding to that semaphore can be obtained. Alternatively, the tw and show commands can be executed to view the semaphore type, semaphore ID, and the number of blocked tasks, among other relevant information.

[0019] For example, a function to get the address of a variable can be implemented as follows: #define loongarch_get_ra(out) \ do {\ UINT64 val; defines a temporary variable val used to temporarily store data read from the ra register. __asm__ __volatile__(\ "move%0, $r1 \n\t" retrieves the value (variable address) stored in register ra and stores it in val. :"=r"(val)\ :\ :\ );\ (out) = val; This assigns the value of val to the out parameter register. while(0) The value (variable address) of the ra register is copied to the temporary variable val through the __asm__ inline assembly, and then the value of the temporary variable val is passed to the memory pointed to by the macro parameter out through (out) = val. That is, out = val makes the external parameter out obtain the value (variable address) of the ra register.

[0020] Step 103: Based on the abnormal semaphore identifier, find the target variable address corresponding to the faulty semaphore identifier in the semaphore metadata.

[0021] In this embodiment, after obtaining the abnormal semaphore identifier, a search and matching can be performed among multiple sets of recorded semaphore metadata based on the abnormal semaphore identifier. Since the semaphore metadata records information such as each semaphore identifier and its corresponding variable address, by comparing the abnormal semaphore identifier with the semaphore identifier in the metadata, the semaphore metadata matching the abnormal semaphore identifier is found, and the variable address in the semaphore metadata is obtained as the corresponding target variable address. Based on the target variable address, the target variable stored in memory can be determined. The information stored in this variable includes relevant data of the faulty semaphore that caused the semaphore failure phenomenon in the target system. In other words, the target variable address is used to locate the memory area storing relevant information of the abnormal semaphore that caused the semaphore failure phenomenon in the target system.

[0022] For example, suppose the semaphore metadata recorded by the system is a linked list structure containing three nodes, and the semaphore identifier and variable address in each linked list node are as follows: Node 1: Semaphore flag = 1, Variable address = 0x2000 Node 2: Semaphore ID = 2, Variable Address = 0x3000 Node 3: Semaphore ID = 3, Variable Address = 0x4000 Suppose that when an abnormal semaphore identifier of 2 is detected, the semaphore identifier is matched by traversing the target linked list, and the variable address corresponding to node 2 is found to be 0x3000. Using 0x3000, the variable stored in memory can be located, and thus the corresponding target code segment can be located.

[0023] Step 104: Locate the corresponding target code segment based on the address of the target variable.

[0024] In this embodiment, based on the found target variable address, the memory region corresponding to that address can be directly accessed to locate the target code segment. The target variable address can be an integer data structure that directly represents a linear address in memory. The target code segment can be an abnormal code segment that may cause abnormal phenomena in the target system; subsequent verification can determine whether the target code segment is abnormal. By directly accessing the memory region indicated by the target variable address and reading the variable at that address, the current state information of the abnormal semaphore can be obtained, such as the value of the abnormal semaphore, thread or process information in the waiting queue, etc. Using the variable name, the code segment corresponding to the variable name can be found in the code as the target code segment. Combined with the current state information of the abnormal semaphore, the cause of the semaphore abnormality can be analyzed, thereby enabling abnormal handling of the target code segment.

[0025] In summary, in this embodiment, based on the target data structure, semaphore metadata corresponding to management operations on each semaphore is recorded. The semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system. When a semaphore anomaly occurs in the target system, the abnormal semaphore identifier is obtained. Based on the abnormal semaphore identifier, the target variable address corresponding to the abnormal semaphore identifier is searched in the semaphore metadata. The corresponding target code segment is located based on the target variable address. Thus, by recording the semaphore metadata corresponding to each management operation in the target system, when a semaphore anomaly occurs, the abnormal semaphore identifier is first obtained as an index. The corresponding target variable address is then searched in the recorded semaphore metadata. Based on the target variable address, the abnormal target code segment can be directly located, avoiding manual line-by-line code analysis or traversing large memory regions for investigation. This allows for real-time tracing of the target code segment from the abnormal semaphore identifier after a semaphore anomaly occurs in the target system, improving the efficiency of semaphore anomaly location, shortening anomaly investigation and repair time, and ultimately improving system maintenance efficiency.

[0026] Furthermore, since the semaphores are created using a dynamic application method, the semaphore ID changes every time the device is started. Through the steps in this embodiment, the corresponding semaphore metadata will be re-recorded each time a signal management operation (including signal initialization operation) is performed, ensuring that the semaphore metadata of the semaphores involved in each management operation is not missed, improving the comprehensiveness of the semaphore record, and thus improving the success rate of locating semaphore anomalies to a certain extent.

[0027] Optionally, step 101 may include the following steps: Step 201: Create the target data structure; the target data structure includes a target linked list.

[0028] In this embodiment, during the target system startup and semaphore management initialization phase, a target data structure, such as a target linked list, is created. The target linked list can be created in a pre-defined memory area. The target linked list can be a container using a linked structure to store semaphore-related information. Each linked list node can contain semaphore metadata, such as the semaphore identifier and the address of the variable corresponding to the semaphore, stored as node fields. Similarly, the target linked list can also be a doubly linked list. For example, when creating the target linked list, a memory space can be allocated in the pre-defined memory area to store the head node of the linked list. The head node may not store actual semaphore information, but rather the starting identifier of the target linked list. The head node may contain a pointer to the first valid linked list node; initially, this pointer is null, indicating that the linked list is empty.

[0029] Step 202: If the management operation is a semaphore creation operation, fill the predefined node fields based on the semaphore metadata of the first semaphore corresponding to the semaphore creation operation to obtain the linked list node to be inserted.

[0030] In this embodiment, when a new first semaphore is created through a semaphore creation operation, the node fields in a predefined linked list node structure are populated based on the semaphore metadata of the newly created first semaphore. The node fields in the predefined linked list node structure may include a semaphore identifier field and a variable address field. For example, in the semaphore creation function (semMCreate), after successfully creating a new semaphore, a memory space can be allocated to store the new linked list node. The obtained semaphore identifier and variable address are assigned to the corresponding fields in the linked list node structure. For instance, the obtained semaphore identifier can be written to the sem_id field of the linked list node structure using an assignment instruction, and the variable address can be written to the addr field of the linked list node structure using an address passing instruction, thus obtaining the linked list node to be inserted.

[0031] For example, the linked list node structure can be: typedef struct { DL_NODEnode; / / Linked list node pointer field, containing pointers to the previous and next nodes, allowing multiple nodes to be chained together to form a linked list. SEM_ID semId; / / Semaphore identifier field, used to uniquely identify a semaphore Char* semra; / / Semaphore variable address field, used to point to the memory location storing semaphore state information. } SEM_INFO_USR; / / Structure of the linked list node Step 203: Insert the node to be inserted into the target linked list as a linked list element.

[0032] In this embodiment, the node to be inserted is inserted into the target linked list as a linked list element. For example, if the target linked list is empty (i.e., the head node's pointer is null), the pointer of the node to be inserted is set to the head node, and the head node's pointer is set to the node to be inserted, making the node to be inserted the first valid node in the linked list. Subsequent nodes containing semaphore metadata are then inserted one by one. If the target linked list is not empty, the node to be inserted is inserted at the tail of the target linked list, and a pointer connection is established between the node to be inserted and the preceding node in the target linked list, completing the insertion operation.

[0033] In one possible implementation, a target linked list can be maintained to record the creation or deletion status of managed semaphores, or two target linked lists can be maintained to record the creation or deletion status of managed semaphores respectively. One target linked list can be used to record the metadata information of newly created or initialized semaphores, and the other target linked list can be used to record the metadata information of deleted semaphores.

[0034] For example, such as Figure 2 As shown, the system contains two target linked lists. The first target linked list records the semaphore metadata corresponding to the semaphore management initialization function `semMInit` and the semaphore creation function `semMCreate`, including `semId` (semaphore identifier) ​​and `semra` (variable address). The second target linked list records the semaphore metadata corresponding to the semaphore destruction count function `semDestroyCount`, including `semId` (semaphore identifier) ​​and `semra` (variable address). When a semaphore is created in the target system, its metadata is recorded in the first target linked list; when a semaphore is deleted, its metadata is recorded in the second target linked list. In the event of a semaphore anomaly, a query can be performed in the first target linked list based on the abnormal semaphore identifier. The target variable address corresponding to the abnormal semaphore identifier can then be obtained from the node in the target linked list obtained from the query.

[0035] In this embodiment of the application, by constructing a target linked list and inserting the semaphore metadata as a linked list node into the target linked list, the semaphores can be managed and queried in a unified manner, so that when an abnormal semaphore occurs, the specific location of the abnormal semaphore can be located, that is, the target code segment corresponding to the abnormal semaphore.

[0036] Optionally, embodiments of this application may further include the following steps: Step 301: If the management operation is a semaphore deletion operation, determine the linked list node corresponding to the second semaphore indicated by the semaphore deletion operation from the target linked list, and use it as the node to be deleted.

[0037] In this embodiment, when the management operation is a semaphore deletion operation, the corresponding linked list node is searched in the target linked list according to the second semaphore indicated by the semaphore deletion operation, and this node is identified as the node to be deleted. For example, starting from the head node of the target linked list, each node in the target linked list can be accessed sequentially in a traversal manner. The semaphore identifier of the current node is loaded from memory into a general-purpose register using memory read instructions, and then compared with the identifier of the second semaphore indicated by the semaphore deletion operation using comparison instructions. If the comparison matches, the linked list node can be marked as the node to be deleted.

[0038] Step 302: Delete the node to be deleted in the target linked list.

[0039] In this embodiment, assuming the target linked list is a doubly linked list, the pointer relationships between the preceding and following nodes need to be adjusted to ensure consistency. Specifically, it is first determined whether the node to be deleted is the head node or the tail node. If it is the head node, the head pointer of the linked list is set to the next node of the node to be deleted, and the front pointer of the new head node is set to null. If the node to be deleted is the tail node, the tail pointer of the linked list is set to the previous node of the node to be deleted, and the back pointer of the new tail node is set to null. If it is not the head node or the tail node, the back pointer of its previous node is set to the next node of the node to be deleted, and the front pointer of its next node is set to the previous node of the node to be deleted.

[0040] In this embodiment of the application, by deleting the linked list node corresponding to the second semaphore indicated by the semaphore deletion operation, the corresponding linked list node can be located and deleted from the target linked list when the semaphore deletion operation is performed, thus ensuring the consistency and accuracy of semaphore management.

[0041] Optionally, step 103 may include the following steps: Step 401: Based on the abnormal semaphore identifier, search for a target linked list node that matches the abnormal semaphore identifier in the target linked list.

[0042] In this embodiment of the application, based on the abnormal semaphore identifier, the abnormal semaphore identifier is compared with the semaphore identifiers in each linked list node stored in the target linked list by traversing the target linked list, and the linked list node corresponding to the semaphore identifier that matches is determined as the target linked list node that matches the abnormal semaphore identifier.

[0043] Specifically, starting from the linked list node indicated by the head pointer of the target linked list, the semaphore identifier field in the linked list node is obtained in turn. The abnormal semaphore identifier is compared with the semaphore identifier in the semaphore identifier field. If the abnormal semaphore identifier is the same as a certain semaphore identifier in the semaphore identifier field, the comparison is consistent, and the linked list node corresponding to the semaphore identifier is determined as the target linked list node that matches the abnormal semaphore identifier.

[0044] Step 402: If the target linked list contains the target linked list node, determine the target variable address based on the target semaphore metadata in the target linked list node; otherwise, obtain the target variable address based on the static allocation mapping table.

[0045] In this embodiment of the application, when the target linked list contains target linked list nodes, the target semaphore metadata recorded in the target linked list nodes is determined based on the field content of each field in the target linked list nodes. The content of the variable address field in the target semaphore metadata is determined as the target variable address corresponding to the abnormal semaphore identifier.

[0046] For example, the system maintains a target linked list that records metadata for all semaphores. Assume that when semaphore 1 is initialized, a linked list node is created in the target linked list, and values ​​are assigned to the node fields, such as inserting `sem_id=1` and `semra=0x3000` as linked list nodes. Subsequently, when an abnormal semaphore is detected, the target linked list is traversed to match `sem_id`. If `sem_id=1` matches the abnormal semaphore identifier, the variable address field in the linked list node corresponding to `sem_id=1` can be extracted, yielding the variable address `semra=0x3000`.

[0047] If the target linked list does not contain a target linked list node, the address of the target variable corresponding to the abnormal semaphore identifier is obtained based on the static allocation mapping table. In this embodiment, since the memory area of ​​static semaphores is pre-allocated, such as global variables and static arrays, their corresponding variable addresses are fixed and determined in advance during code compilation; the memory area of ​​dynamic semaphores is dynamically allocated by the kernel, and their corresponding variable addresses are generated at runtime. Therefore, recording semaphore metadata through a linked list structure during semaphore creation and deletion means that the target linked list records dynamically created semaphores, and the target linked list adds and deletes nodes based on the creation and deletion operations of dynamically created semaphores. Accordingly, if the address of the target variable corresponding to the abnormal semaphore identifier cannot be found in the target linked list, it can be characterized that the abnormal semaphore was statically created.

[0048] Based on the memory region pre-allocated for static semaphores, a static allocation mapping table is constructed. This table can be a hash table or an array of structures, containing metadata such as the semaphore identifier and variable address of the pre-allocated static semaphores. For example, during system startup, a function iterates through the predefined static semaphore variables, filling the static semaphore identifier and variable address into the static allocation mapping table. Assuming the system has three static semaphores: sem1: identifier = 1, address = 0x1000; sem2: identifier = 2, address = 0x2000; sem3: identifier = 3, address = 0x3000, then the static allocation mapping table filled with static semaphores would be: {1: 0x1000, 2: 0x2000, 3: 0x3000}.

[0049] In the static allocation mapping table, abnormal semaphore identifiers can be used as indexes for comparison, allowing direct lookup of the target variable address corresponding to the abnormal semaphore identifier within the static allocation mapping table. For example, during system initialization, the variable addresses of statically created semaphores can be fixedly allocated to specific memory regions. The variable addresses and semaphore identifiers of these statically created semaphores can be filled into the static allocation mapping table using a hash table or array structure. The target variable address corresponding to the abnormal semaphore identifier can then be obtained by querying the system memory mapping table or system configuration information.

[0050] In this embodiment, based on the abnormal semaphore identifier, the target variable address corresponding to the abnormal semaphore identifier is obtained from the semaphore metadata recorded and managed in the target linked list. Utilizing the ordered storage and fast retrieval characteristics of the linked list, the target linked list node is located. Furthermore, when the target linked list contains this node, the corresponding target variable address is further determined based on the target semaphore metadata in the node. This allows for quick and accurate location of the target variable address, improving the efficiency of semaphore anomaly detection and repair.

[0051] Optionally, step 104 may include the following steps: Step 501: Disassemble the system files corresponding to the target system to obtain a disassembled file.

[0052] In this embodiment, a disassembler is used to disassemble the system files corresponding to the target system to obtain a disassembled file. The system file can be a compiled binary executable file. The disassembled file contains a set of assembly instructions corresponding to the execution of the target system program. By disassembling the system file, the binary code can be converted into assembly instructions. For example, a disassembler can be used to disassemble the files of the target system, and the resulting disassembled file can be stored in a specified path.

[0053] Step 502: Based on the address of the target variable, locate the target code segment in the disassembled file.

[0054] In this embodiment, based on the target variable address corresponding to the abnormal semaphore identifier, assembly instructions that interact with the target variable address in the disassembled file are searched. These data interaction operations can include read, write, and modify operations, which affect the semaphore's state, thus causing the semaphore to malfunction. By searching for the assembly instructions that perform data interaction operations on the target variable address, the code segment related to the semaphore operation can be found, and the specific code segment location can be pinpointed.

[0055] For example, one can traverse the disassembled file, performing a global search within it. Starting from the beginning of the disassembled file, each assembly instruction's operands are checked sequentially to see if they contain the address of the target variable. If they do, the instruction is recorded. These recorded instructions form a candidate instruction set, which, combined with the target system's semaphore operation logic and abnormal behavior, helps determine the target code segment.

[0056] In this embodiment of the application, by obtaining the target variable address corresponding to the abnormal semaphore identifier and disassembling the target system file to generate a disassembly file, and then accurately locating the target code segment in the disassembly file based on the target variable address, it is possible to investigate system anomalies caused by static semaphores when the target linked list does not contain the target linked list node, thereby improving the comprehensiveness and accuracy of anomaly location.

[0057] Optionally, step 202 may include the following steps: Step 601: Determine each of the predefined node fields; the node fields include a semaphore identifier field, a semaphore sequence number field, and a variable address field.

[0058] Step 602: Fill the semaphore identifier, semaphore sequence number, and semaphore variable address of the first semaphore into the semaphore identifier field, the semaphore sequence number field, and the variable address field, respectively, to obtain the linked list node to be inserted.

[0059] In this embodiment, the predefined linked list node structure may further include a semaphore sequence number field. When a semaphore creation operation is performed, a first semaphore is generated. A unique semaphore sequence number is generated for each first semaphore according to the creation order. The semaphore identifier, semaphore sequence number, and semaphore variable address of the first semaphore are filled into the semaphore identifier field, semaphore sequence number field, and variable address field, respectively, to obtain the linked list node to be inserted. The semaphore sequence number can be obtained by numbering each newly created semaphore within the system.

[0060] For example, assuming that after the semaphore creation operation is completed, the current target system already contains 99 semaphores, then the semaphore number of the first semaphore generated this time can be determined as 100, and 100 can be written as the filling content into the semaphore number field of the linked list node.

[0061] Accordingly, embodiments of this application may further include the following steps: Step 603: For different processing stages of the target system, determine the range of semaphore numbers corresponding to each processing stage.

[0062] In this embodiment, since the loading and application execution of embedded systems typically follow a layered approach, different processing stages have different functions and characteristics. To improve the semaphore retrieval efficiency, the semaphore sequence number range corresponding to each processing stage can be determined for different processing stages of the target system. The semaphore sequence number range corresponding to different processing stages is statistically analyzed using the semaphore sequence number field in each linked list node of the target linked list.

[0063] For example, taking the VxWorks system as an example, such as Figure 3 As shown, the application loading and execution process includes different processing stages such as the VxWorks system stage, user driver program, Qt graphics library program, and graphics display program. Based on the semaphore sequence number field in each linked list node of the target linked list corresponding to stages ①②③, the semaphore sequence numbers of each stage ①②③ are counted to determine the semaphore sequence range corresponding to stages ①②③ respectively.

[0064] In this embodiment, by recording the semaphore sequence number and statistically analyzing the different semaphore sequence number ranges corresponding to different processing stages, semaphores can be classified and managed according to the processing stage. This facilitates locating the semaphore sequence range corresponding to the target processing stage when an abnormal semaphore phenomenon occurs in the target system. Within the semaphore sequence range, retrieval is performed based on the abnormal semaphore identifier. Compared to searching through all semaphores, this improves retrieval and location efficiency.

[0065] Optionally, step 401 may include the following steps: Step 701: Determine the target processing stage when the target system experiences a semaphore anomaly.

[0066] In this embodiment, the target processing stage at which the target system experiences a semaphore anomaly is determined. This stage is determined through system log recordings, error code analysis, and other methods.

[0067] Step 702: Based on the semaphore sequence range corresponding to the target processing stage, determine the set of linked list nodes that match the target processing stage from the target linked list.

[0068] In this embodiment, based on the range of semaphore numbers corresponding to the target processing stage, a set of linked list nodes matching the target processing stage is selected from the target linked list. Specifically, this can be achieved by traversing the target linked list and checking whether the semaphore number in each linked list node is within the range of semaphore numbers corresponding to the target processing stage. The linked list nodes within the range of semaphore numbers corresponding to the target processing stage are then determined as the set of linked list nodes.

[0069] For example, assuming the target system experiences a semaphore anomaly at a VxWorks system stage, and the semaphore index range for this stage is 1-50, then the target linked list can be filtered to select linked list nodes with semaphore index fields of 1-50 as the set of linked list nodes matching the VxWorks system stage. The semaphore identifier of each linked list node in this set is then iterated to check if it matches the abnormal semaphore identifier. If a match is found, the matching linked list node is identified as the target linked list node. Compared to directly traversing and matching all linked list nodes in the target linked list at once, this embodiment only needs to traverse a portion (50) of the linked list nodes corresponding to one processing stage to quickly match the target linked list node that matches the abnormal semaphore identifier, thus improving troubleshooting efficiency.

[0070] Step 703: Based on the abnormal semaphore identifier, search for the target linked list node corresponding to the abnormal semaphore identifier in the linked list node set.

[0071] In this embodiment of the application, based on the abnormal semaphore identifier, the abnormal semaphore identifier is compared with the semaphore identifiers in each linked list node in the linked list node set, and the linked list node corresponding to the semaphore identifier that matches is determined as the target linked list node that matches the abnormal semaphore identifier.

[0072] In this embodiment, by searching for the target linked list node in the linked list node set within the range of the semaphore sequence number corresponding to the target processing stage, compared to filtering and searching in all linked list nodes of the target linked list, the anomaly can be located quickly, further improving the efficiency of anomaly detection and repair.

[0073] It should be noted that the semaphore anomaly localization method provided in this application embodiment can be executed by a semaphore anomaly localization device, or a control module in the semaphore anomaly localization device for executing the method of loading semaphore anomaly localization. This application embodiment uses the execution of the method of loading semaphore anomaly localization by the semaphore anomaly localization device as an example to illustrate the semaphore anomaly localization device provided in this application embodiment.

[0074] Figure 4 This is a structural diagram of a signal anomaly location device provided in an embodiment of this application, with reference to... Figure 4 The device may include: The first recording module 801 is used to record the semaphore metadata corresponding to the management operation of each semaphore based on the target data structure; the semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system; The first acquisition module 802 is used to acquire the abnormal semaphore identifier when the target system experiences an abnormal semaphore phenomenon. The first lookup module 803 is used to look up the address of the target variable corresponding to the abnormal semaphore identifier in the semaphore metadata based on the abnormal semaphore identifier. The first positioning module 804 is used to locate the corresponding target code segment based on the target variable address.

[0075] Optionally, the first recording module 801 includes: The first creation module is used to create the target data structure; the target data structure includes a target linked list. The first filling module is used to fill predefined node fields based on the semaphore metadata of the first semaphore corresponding to the semaphore creation operation when the management operation is a semaphore creation operation, so as to obtain the linked list node to be inserted. The first insertion module is used to insert the node to be inserted into the target linked list as a linked list element.

[0076] Optionally, the device further includes: The first determining module is used to determine, when the management operation is a semaphore deletion operation, the linked list node corresponding to the second semaphore indicated by the semaphore deletion operation from the target linked list, as the node to be deleted; The first deletion module is used to delete the node to be deleted in the target linked list.

[0077] Optionally, the first search module 803 includes: The first search submodule is used to search for a target linked list node that matches the abnormal semaphore identifier in the target linked list based on the abnormal semaphore identifier. The second determining module is used to determine the target variable address based on the target semaphore metadata in the target linked list node if the target linked list contains the target linked list node; otherwise, it obtains the target variable address based on a static allocation mapping table.

[0078] Optionally, the first positioning module 804 includes: The first processing module is used to disassemble the system files corresponding to the target system to obtain a disassembled file; The first locating submodule is used to locate the target code segment in the disassembled file based on the address of the target variable.

[0079] Optionally, the semaphore metadata further includes a semaphore sequence number; the first filling module includes: The first determining submodule is used to determine each of the predefined node fields respectively; the node fields include a semaphore identifier field, a semaphore sequence number field, and a variable address field. The first filling submodule is used to fill the semaphore identifier, semaphore sequence number and semaphore variable address of the first semaphore into the semaphore identifier field, the semaphore sequence number field and the variable address field respectively, to obtain the linked list node to be inserted.

[0080] Optionally, the first search submodule includes: The fourth determining module is used to determine the target processing stage when the target system experiences a semaphore anomaly. The fifth determining module is used to determine, based on the range of semaphore numbers corresponding to the target processing stage, a set of linked list nodes that match the target processing stage from the target linked list; The second search submodule is used to search for the target linked list node corresponding to the abnormal semaphore identifier in the linked list node set based on the abnormal semaphore identifier.

[0081] The signal anomaly location device in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.

[0082] The signal anomaly location device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.

[0083] Optional, such as Figure 5 As shown, this application embodiment also provides an electronic device, including a processor 910, a memory 909, and a program or instructions stored in the memory 909 and executable on the processor 910. When the program or instructions are executed by the processor 910, they implement the various processes of the above-described abnormal location method embodiment for semaphores and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0084] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0085] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described semaphore anomaly location method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0086] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0087] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described semaphore anomaly localization method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0088] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0089] This application provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the above-described anomaly localization method for semaphores, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0090] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0091] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0092] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A method for anomaly localization of semaphores, characterized in that, The method includes: Based on the target data structure, the semaphore metadata corresponding to the management operation of each semaphore is recorded respectively; the semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system; When an abnormal semaphore phenomenon occurs in the target system, an abnormal semaphore identifier is obtained; Based on the abnormal semaphore identifier, the address of the target variable corresponding to the abnormal semaphore identifier is found in the semaphore metadata. The target code segment is located based on the address of the target variable.

2. The method according to claim 1, characterized in that, The semaphore metadata, based on the target data structure, is recorded respectively when management operations are performed on each semaphore, including: Create a target data structure; the target data structure includes a target linked list; When the management operation is a semaphore creation operation, the predefined node field is filled with the semaphore metadata of the first semaphore corresponding to the semaphore creation operation to obtain the linked list node to be inserted. The node to be inserted into the target linked list is inserted as a linked list element.

3. The method according to claim 2, characterized in that, The method further includes: When the management operation is a semaphore deletion operation, the linked list node corresponding to the second semaphore indicated by the semaphore deletion operation is determined from the target linked list and used as the node to be deleted; Delete the node to be deleted in the target linked list.

4. The method according to claim 3, characterized in that, The step of searching for the target variable address corresponding to the abnormal semaphore identifier in the semaphore metadata includes: Based on the abnormal semaphore identifier, a target linked list node matching the abnormal semaphore identifier is searched in the target linked list; if the target linked list node is contained in the target linked list, the target variable address is determined based on the target semaphore metadata in the target linked list node; otherwise, the target variable address is obtained based on the static allocation mapping table.

5. The method according to claim 1 or 4, characterized in that, The step of locating the corresponding target code segment based on the target variable address includes: The system files corresponding to the target system are disassembled to obtain a disassembled file; Based on the address of the target variable, locate the target code segment in the disassembled file.

6. The method according to claim 2, characterized in that, The semaphore data also includes the semaphore sequence number; Then, filling the predefined node fields to obtain the linked list node to be inserted includes: Each predefined node field is determined; the node fields include a semaphore identifier field, a semaphore sequence number field, and a variable address field. The semaphore identifier, semaphore sequence number, and semaphore variable address of the first semaphore are filled into the semaphore identifier field, the semaphore sequence number field, and the variable address field, respectively, to obtain the linked list node to be inserted.

7. The method according to claim 4, characterized in that, The step of searching the target linked list node that matches the abnormal semaphore identifier includes: Determine the target processing stage when the target system experiences a semaphore anomaly; Based on the semaphore sequence range corresponding to the target processing stage, determine the set of linked list nodes that match the target processing stage from the target linked list; Based on the abnormal semaphore identifier, search for the target linked list node corresponding to the abnormal semaphore identifier in the linked list node set.

8. A signal anomaly location device, characterized in that, The device includes: The first recording module is used to record the semaphore metadata corresponding to the management operation of each semaphore based on the target data structure; the semaphore metadata includes the semaphore identifier and variable address of each semaphore in the target system; The first acquisition module is used to acquire the abnormal semaphore identifier when the target system experiences an abnormal semaphore phenomenon. The first lookup module is used to search for the address of the target variable corresponding to the abnormal semaphore identifier in the semaphore metadata based on the abnormal semaphore identifier; The first positioning module is used to locate the corresponding target code segment based on the address of the target variable.

9. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the semaphore anomaly localization method as described in claims 1-7.

10. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the semaphore anomaly localization method as described in claims 1-7.