CN114047923A - Error code positioning method, device, storage medium and electronic equipment - Google Patents

Error code positioning method, device, storage medium and electronic equipment Download PDF

Info

Publication number
CN114047923A
CN114047923A CN202111358194.9A CN202111358194A CN114047923A CN 114047923 A CN114047923 A CN 114047923A CN 202111358194 A CN202111358194 A CN 202111358194A CN 114047923 A CN114047923 A CN 114047923A
Authority
CN
China
Prior art keywords
code
error
source code
information
executable file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111358194.9A
Other languages
Chinese (zh)
Inventor
吴世伟
韦保山
刘真
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202111358194.9A priority Critical patent/CN114047923A/en
Publication of CN114047923A publication Critical patent/CN114047923A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution

Abstract

The disclosure relates to a method, a device, a storage medium and an electronic device for positioning an error code, and relates to the technical field of computers, wherein the positioning method comprises the following steps: compiling source codes of a programming language into an executable file of a machine language; when the executable file has an error in operation, outputting abnormal information through an error reporting function; responding to the abnormal information, and acquiring a call stack of an error reporting function; and determining the position information of the error code of the source code according to the call stack. Therefore, a runtime error reporting mechanism of a cross-language interpretation error of a compiler which directly compiles the source code into a binary executable file can be realized, and the position of the error code can be accurately positioned.

Description

Error code positioning method, device, storage medium and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for locating an error code, a storage medium, and an electronic device.
Background
In the related art, a Python compiler translates a source code into a bytecode, a Python virtual machine interprets and executes the bytecode, and when an execution error is encountered, the Python virtual machine performs exception throwing, thereby locating an error code. However, when the virtual machine is not used for execution, the virtual machine cannot be used for exception throwing, and thus an error code cannot be located.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
In a first aspect, the present disclosure provides an error code positioning method, including:
compiling source codes of a programming language into an executable file of a machine language;
when the executable file has an error in operation, outputting abnormal information through an error reporting function;
responding to the abnormal information, and acquiring a call stack of the error reporting function;
and determining the position information of the error code of the source code according to the call stack.
In a second aspect, the present disclosure provides an error code locating device, comprising:
a compiling module configured to compile a source code of a programming language into an executable file of a machine language;
the error reporting module is configured to output abnormal information through an error reporting function when the executable file has a runtime error;
the obtaining module is configured to respond to the abnormal information and obtain a call stack of the error reporting function;
and the determining module is configured to determine the position information of the error code of the source code according to the call stack.
In a third aspect, the present disclosure provides a computer readable medium having stored thereon a computer program which, when executed by a processing apparatus, performs the steps of the method of the first aspect.
In a fourth aspect, the present disclosure provides an electronic device comprising:
a storage device having a computer program stored thereon;
processing means for executing the computer program in the storage means to carry out the steps of the method of the first aspect.
Based on the technical scheme, the error reporting function is utilized to output the abnormal information of the runtime error in the compiler which compiles the source code of the programming language into the executable file of the machine language, and the position information of the error code is determined according to the call stack of the error reporting function, so that the runtime error reporting mechanism of the cross-language interpretation error of the compiler which directly compiles the source code into the binary executable file can be realized, and the position of the error code can be accurately positioned.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale. In the drawings:
FIG. 1 is a flow diagram of a proposed error code location method in accordance with an exemplary embodiment;
FIG. 2 is a schematic diagram of proposed exception throwing in accordance with an exemplary embodiment;
FIG. 3 is a schematic flow chart of step 140 shown in FIG. 1;
FIG. 4 is a flowchart illustrating the conversion of source code into an executable file in accordance with an illustrative embodiment;
FIG. 5 is an architectural flow diagram of a proposed compiler in accordance with an exemplary embodiment;
FIG. 6 is a block diagram illustrating the connection of modules providing an error code locating device in accordance with an exemplary embodiment;
fig. 7 is a schematic diagram of an electronic device according to an exemplary embodiment.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
FIG. 1 is a flow chart diagram of a proposed error code location method according to an example embodiment. The error code positioning method disclosed in this embodiment may be executed by an electronic device, and specifically may be executed by an error code positioning apparatus, where the apparatus may be implemented in a software and/or hardware manner and configured in the electronic device. Referring to fig. 1, an error code locating method provided by an embodiment of the present disclosure may include the following steps.
In step 110, source code of a programming language is compiled into an executable file of a machine language.
Here, the programming language is a language for writing codes that can realize communication between a human and a machine, and may be, for example, Python, C/C + +, or the like. The machine language refers to a program language or instruction codes which can be directly recognized by a machine, and each operation code is completed by a corresponding circuit in a computer without translation. For example, the executable file of the machine language may be an executable file of binary code.
The source code written by the programming language cannot be directly recognized by a machine, and the source code of the programming language can be compiled into an executable file of the machine language by a compiler AOT. For example, the source code of Python is compiled into a binary executable file by a compiler AOT.
In step 120, when the executable file has a runtime error, outputting exception information through an error reporting function.
Here, since the compiler AOT directly compiles the source code into an executable file of the machine language, the Python virtual machine is no longer needed to be used at runtime, and thus, when a runtime error occurs in the executable file, an exception cannot be thrown by the Python virtual machine. In the present disclosure, all runtime errors are exception thrown by an error reporting function. For example, Index Error, Typing Error, etc. are all thrown by the FATAL function (Error reporting function).
Fig. 2 is a schematic diagram of the principle of exception throwing proposed according to an exemplary embodiment, and as shown in fig. 2, source code is compiled into a binary executable file such as containers, operators, extensions, and the like in Runtimes (runtime modules). When the executable file has run-time error, the exception information is output through the FATAL function.
In step 130, in response to the exception information, a call stack of the error reporting function is obtained.
Here, the call stack refers to a stack storing a message about a running subroutine. When the error reporting function outputs abnormal information, the electronic equipment acquires the call stack of the error reporting function. In some embodiments, the call stack of the error reporting function may be traced back through the libbacrace tool and thrown up in text format. It should be understood that the principle of the libbactrace tool tracing back the call stack of the error function may be to obtain the call stack of the error function through the int backtrace () function.
In step 140, the location information of the error code of the source code is determined according to the call stack.
Here, when the executable file has a runtime error, the error reporting function is called to output exception information, and a return address indicating the location of the executable file where the error occurred is stored in the call stack of the error reporting function. Then, from the compilation path between the source code and the executable file, location information to the error code in the source code may be determined.
The location information of the error code may include a storage location of the error code and/or a line number of the error code in the source code.
Therefore, by using the error reporting function to output the abnormal information of the runtime error in the compiler which compiles the source code of the programming language into the executable file of the machine language and determining the position information of the error code according to the call stack of the error reporting function, the runtime error reporting mechanism of the cross-language interpretation error of the compiler which directly compiles the source code into the binary executable file can be realized, and the position of the error code can be accurately positioned.
Fig. 3 is a schematic flow chart of step 140 shown in fig. 1. As shown in fig. 3, in some implementations, step 140 may include the following steps.
In step 141, a compiled code with an error is determined according to a call return address in the call stack, where the compiled code is an intermediate code when the source code is compiled into the executable file.
Here, the compiled code is an intermediate code when the source code is compiled into an executable file, and for example, the source code is Python and the compiled code is C + +. The compiler AOT compiles Python into C + +, and then compiles C + + into a binary executable file. When the executable file has a runtime error, calling an error reporting function to output abnormal information, and storing a call return address in a call stack of the error reporting function, wherein the call return address is used for indicating the position of the compiled code with the error.
In step 142, based on the compiled code with the error, the location information of the error code of the source code is determined.
Here, after the compiled code in which the error occurs is determined, the location information to the error code may be determined through a mapping relation with the compiled code and the source code.
In some embodiments, in the compiling process of the compiler AOT, a mapping relationship between position information of a source code and position information of a compiled code between the source code is recorded, and when a compiled code with an error is determined, position information of an error code corresponding to the source code is determined according to the mapping relationship.
Therefore, the compiled code with the error is positioned through the call return address in the call stack, the error code is further determined according to the mapping relation between the compiled code and the source code, and the position information of the error code in the source code can be accurately positioned.
The above embodiments are described in detail below by way of some examples.
In the present disclosure, the compiler AOT compiles the source code of Python into a compiled code of C + +, and then compiles the compiled code of C + + into a binary executable file. Whether it is List's Index error, Dict key error, or type related error, it is thrown abnormally by the FATAL function. By using the libacktrace tool in the FATAL function, the call stack of the FATAL function can be obtained.
For example, when a runtime ERROR occurs, the ERROR reporting function reports the ERROR by outputting "ERROR: test _ runtimerror _ again (__ main __. TestruntimeerrorReport) "to throw exception information. Then, the call stack of the FATAL function is obtained by "Traceback (most recent call last)".
The position information of the C + + compiled code corresponding to the abnormal information can be traced back through the call return address stored in the call stack of the false function. For example, the location of compiled code where an error occurred may be determined by a statement "matx:: runtime:: JitOp:: Process (matx:: runtime:: Pyrargs) const at/data00/works space/matx4/src/pipeline/jit _ op.cc: 103". Wherein "data 00/workspace/matx4/src/pipeline/jit _ op. cc" represents a storage location of the compiled code in C + + format in which an error occurs, and "103" represents a line number of the compiled code. Thus, the error stack and the line number of the error program can be obtained in the form of character strings.
Because the compiler AOT records the mapping relation between the Python source code and the C + + compiled code in the compiling process, the position information of the error code in the Python source code can be obtained by backtracking through the mapping relation. For example, the location information of the error code is output by the statement "ErrorRunner. __ call __ at/data00/works space/matx4/test/script/test _ runtime _ error _ report. py: 20".
Wherein, "data 00/works/matx 4/test/script/test _ running _ error _ report. py" represents the storage location of the error code in the Python format in which the error occurs, and "20" represents the line number of the error code.
FIG. 4 is a flowchart illustrating the conversion of source code into an executable file, according to an example embodiment. As shown in fig. 4, the following steps may be included.
In step 210, source code in a first programming language is obtained.
The source code for performing the code conversion may be one or more files, and when the source code is a plurality of files, one of the files may be determined as the initial source code according to default specification or user specification to perform the subsequent process. Illustratively, the first programming language may be Python.
In step 220, the source code is analyzed to obtain variable information and dependency information corresponding to the source code, where the dependency information includes dependency relationships among a plurality of analysis objects, and the analysis objects include functions and/or classes.
For example, when code development is performed, variables can be defined in the source code to describe attributes, the variable information can include names, data types, scopes and the like of the variables, and the dependency information is used for characterizing dependencies between classes and dependencies between functions in the source code.
In step 230, the abstract syntax tree corresponding to each parsing object in the dependency information is converted into an intermediate representation according to the variable information and the dependency information, where the intermediate representation includes type information of each node in the abstract syntax tree.
The Intermediate Representation (IR) is a Representation of a source program between the source code after being parsed and the target code being generated, and the Abstract Syntax Tree (AST) is a Tree Representation of an Abstract Syntax structure of the source code, where each node in the Abstract Syntax Tree represents a structure in the source code. The abstract syntax tree may be obtained by analyzing the source code through a lexical analyzer and a syntax analyzer, and the processing mode is a common mode in the art, for example, the abstract syntax tree may be obtained by analyzing through a Parser tool, which is not described herein again. Fig. 5 is a schematic diagram of an architecture flow of a compiler according to an exemplary embodiment, and as shown in fig. 5, a source code may be analyzed according to the parsing flow AST Parser to obtain the abstract syntax tree. For example, the abstract syntax tree, the variable information, and the like may be stored in the context file ScriptContext, so as to facilitate quick reading of the relevant information in the subsequent application process.
In the embodiment of the present disclosure, according to the variable information and the dependency information, code conversion may be performed on each parsed object and objects dependent thereon, and meanwhile, in combination with the variable information, the type information of each node in the abstract syntax tree may be further determined, so as to obtain a uniform structural representation corresponding to the parsed object, which facilitates subsequent uniform conversion to the second programming language.
In step 240, compiled code of a second programming language is generated from the intermediate representation.
In this embodiment, the obtained intermediate representation may be used as metadata for transcoding, and a template file of transcoding rules may be defined, wherein a syntax structure for converting to the second programming language may be defined in the template file. For example, the conversion of the intermediate representation into the compiled code may be implemented based on a code generation tool, such as generating the compiled code based on the generation flow CodeGen, which may read the intermediate representation and read the conversion rule from a template file of the code conversion rule, merge the read conversion rule with the intermediate representation for code generation, to output the compiled code. As shown in fig. 5, the intermediate representation may be converted into compiled code according to the above-mentioned intermediate representation conversion procedure Parser pair, and then enter the intermediate representation module IR module. Illustratively, the compiled code may be C + +.
In step 250, an executable file of the machine language is generated from the compiled code.
Here, in some embodiments, the dynamic library corresponding to the compiled code may be obtained by calling a compiler corresponding to the second programming language to compile the compiled code; and packaging the dynamic library and a function table corresponding to the compiled code to obtain the executable file, wherein the executable file is called based on an entry function corresponding to the executable file.
It should be understood that an executable file refers to a binary file that a computer can directly run, and in the embodiment of the present disclosure, a static compiled dynamic type language is used to convert a compiled language into an executable file. The behavior of Python core objects, such as a container (List, Dict), etc., is simulated by a dynamic library. The executable file is generated based on the dynamic library, the needed binary codes are not copied into the executable file when the linkage is performed, and the true linkage process is completed when the program runs only by copying some relocation and symbol table information.
For example, the second programming language is C + +, in this embodiment, a C + + Compiler may be further invoked to compile the compiled code, so that the compiled code may be compiled into a form of a dynamic library DSO, for example, in fig. 5, the dynamic library DSO may be obtained by compiling through a C + + Compiler. In the process, compiling tools in other programming languages need to be called, and the process can be realized through a compiling tool chain Toolchain. The function table corresponding to the compiled code can be obtained through a process of parsing the source code, wherein for the member functions in the class, it can be added to the function table in combination with the class and the function name, for example, the function of myclass.f5 represents the member function F5 in the class MyClass. If the function name is renamed in the process of analyzing the source code, the name after renaming is in the function table.
As an example, after calling a C + + compiler for compilation, the compiler AOT may load the dynamic library DSO, and encapsulate the dynamic library and the function table through an encapsulation process RTModule to obtain a binary executable file (Runtime Module). And the executable file is called based on the entry function corresponding to the executable file. For example, the GetFunction interface may be called to obtain function information of an entry function of the executable file, so that the executable file is called based on the entry function to access the upper layer service, as shown in the flow chart in fig. 5.
Therefore, according to the technical scheme, after the source code is converted to obtain the compiled code, the compiler corresponding to the second programming language can be further called to compile the compiled code, so that a dynamic library is obtained, dynamic allocation and scheduling are reduced when the second programming language runs, the automatic processing level of the AOT of the compiler is further improved, the workload of technicians is reduced, and the use experience of a user is improved.
In the technical scheme, the obtained source code is analyzed, variable information and dependency information corresponding to the source code are determined, an abstract syntax tree corresponding to each analysis object in the dependency information is converted into an intermediate representation containing type information of each node in the abstract syntax tree according to the variable information and the dependency information, and then a corresponding compiled code in a second programming language is generated according to the intermediate representation. Therefore, by the technical scheme, the intermediate representation which is equivalent to the abstract syntax tree of the source code file and contains the node type information of the source code file can be obtained based on the variable information and the dependency information through the analysis of the source code, the code conversion is realized by generating the intermediate representation of the unified structure, the association between the first programming language and the second programming language in the code conversion process can be reduced, the code conversion under multiple second programming languages can be realized based on one-time analysis of the source code, the use range of the code conversion method is improved, the uniformity and consistency of the code conversion can be ensured to a certain extent, the personal habitual difference in manual code writing is effectively avoided, the subsequent code maintenance and vulnerability inspection are facilitated, the quality of the generated compiled code is improved while the workload of technical personnel is reduced, and the code conversion adaptation can be quickly and accurately realized while the requirement is changed, reliable technical support is provided for the use of a model based on compiled codes, and the use experience of a user is further improved.
In some embodiments, in step 220, a variable in the source code may be parsed to obtain a global variable and a local variable in the source code, so as to obtain the variable information; and determining the dependency information of the analysis object according to the abstract syntax tree corresponding to the analysis object aiming at each analysis object in the source code.
The variable definition statements in the source code file can be extracted to determine each variable defined in the source code file, the local variable is a variable defined in the function, the scope of the local variable is in the function, the global variable is a variable defined out of the function, and the scope of the global variable is global, so that the scope of the variable can be determined according to the position defined by the variable to determine whether the variable is the local variable or the global variable. Meanwhile, for the grammar in the first programming language, the grammar can also be determined based on the keywords defined by the variables, for example, in Python, the variables defined by global can be determined as global variables. Meanwhile, when the variable is analyzed, the variable type and the variable name defining the variable can be further obtained to obtain the variable information. By way of example, the obtained variable information can be uniformly stored so as to be directly applied in the subsequent code conversion process. As shown in fig. 5, the variable information may be determined through a module analysis process modulean analysis.
As described above, the analysis object may be a Function or a Class, and the description will be given taking the analysis object as a Class. For example, if a change in class a causes a change in class B, it is described that class B depends on class a, and in general, a function whose dependency is expressed in a certain class uses an object of another class as a parameter. In this embodiment, dependency information for a class may be determined by classifying the functions of each class to determine whether there is a dependency.
Therefore, by the technical scheme, variable information and dependency information in the source code can be analyzed, data support is provided for determining the structured representation of the source code file, meanwhile, the dependency relationship of the source code file is determined, support can also be provided for subsequently generating the compiled code, and the logic consistency and the availability of the compiled code obtained by conversion and the source code are ensured.
In some embodiments, determining the dependency information of the parsing object according to the abstract syntax tree corresponding to the parsing object may be by determining whether a dependent object exists in a target object according to the abstract syntax tree corresponding to the target object, where the target object is initially the parsing object; if the dependent object exists, analyzing variables in the object code file under the condition that the obtained object code file to which the dependent object belongs is not the source code file aiming at the dependent object, obtaining a global variable and a local variable in the object code file to obtain variable information corresponding to the object code file, taking the dependent object as a new object, and determining whether the dependent object exists in the object according to the abstract syntax tree corresponding to the object again until the dependent object corresponding to the object does not exist; and then generating the dependency information of the analysis object according to each target object determined by the analysis object and the dependency object of the target object.
Here, taking the function F1 as an example, initially, taking the function F1 as a target object, it may be determined whether there is a node (i.e., a dependent object) that refers to another function among the nodes in the abstract syntax tree corresponding to the function F1, and if there is a node that refers to another function, it may be determined that there is a dependent object in the function F1, for example, the dependent objects are the functions F2 and F3.
For example, if there are a plurality of dependent objects, the above analysis may be performed on each dependent object in turn in a determined order. For example, first, an object code file to which the function F2 belongs is obtained, and if the object code file is not the source code, the variables in the object code file are analyzed to obtain global variables and local variables in the object code file, so as to obtain variable information corresponding to the object code file. The manner of obtaining the variable information is described in detail above, and is not described herein again. After the variable information is analyzed, the function F2 may be determined as a new target object, that is, the above-mentioned flow is further performed on the function F2 to analyze the function F2, for example, the dependent object existing in the function F2 is the function F4, and the function F4 does not have a dependent object.
For the function F3, an object code file to which the function F3 belongs is obtained, where the object code file is the source code, and since the source code has already been subjected to variable information analysis at this time, it is not necessary to re-analyze the source code, the function F3 may be directly used as a new object, that is, the above-mentioned flow is further performed on the function F3, so as to analyze the function F3, for example, there is no dependent object in the function F3 obtained by further analysis. Thereby, the analysis is completed.
Determining the dependency functions F2 and F3 of the function F1 and the dependency function F2 of the function F4 through the above analysis process, then generating the dependency relationship of the function F1 according to the determined dependency relationships to characterize the dependencies among the functions, as shown in fig. 5, the dependency information may be generated through the DAG analysis flow, and the dependency information may be represented by a DAG (Directed acyclic graph). After determining the dependency relationship, the directed acyclic graph may be generated based on a manner commonly used in the art, and this disclosure is not repeated here.
Therefore, by the technical scheme, the dependency relationship between each function and each class in the source code can be analyzed, the consistency of the logical relationship before and after code conversion is ensured, data support is provided for code conversion, meanwhile, the effectiveness and the availability of the generated compiled code can be effectively ensured, and rapid deployment and service of the model are facilitated.
In a possible embodiment, the method further comprises: and determining the library name and the library link address of the packaging library corresponding to the third-party library based on the third-party library and the signature representation preset in the compiler, wherein the packaging library comprises the link address of the third-party library. Wherein the third party library may comprise the dynamic library. The preset signature representation can be a predefined abstract representation of the library, and the signature of each third-party library can be represented in a uniform format by generating the packaging library, so that the registration of the third-party library and the identification of the third-party library by the compiler AOT are facilitated.
Generating a mapping relation according to the library name and the library link address and storing the mapping relation into a mapping table; and generating an interface code corresponding to the third-party library in the first programming language according to the library name and the mapping table of the third-party library, and adding the interface code to an interface file. For the newly registered third-party library, if the third-party library is to be called in the first programming language, the third-party library may be packaged as an interface in the first programming language, and the third-party library is called based on the interface. In this embodiment, for each third-party library, its corresponding interface code may be generated in the first programming language, for example, the interface code corresponding to the third-party library may be generated based on wrapper for calling the third-party library. In this embodiment, the interface code corresponding to the third party library may be added to the interface file, so that the compiler AOT may implement, when performing code conversion, a call to the newly registered third party library in the first programming language by importing the interface file.
Accordingly, the corresponding compiled code in the second programming language may be generated according to the intermediate representation, and the intermediate representation may be converted according to the second programming language and the interface file to obtain the compiled code.
Therefore, the third-party library can be registered in the compiler AOT in a packaging library and mapping table based mode, the compiler AOT can accurately identify and code-convert the source code calling the third-party library by generating the interface file, a developer is supported to expand the third-party library in the compiler AOT, the integration efficiency of the third-party library is improved, and meanwhile the use range and the conversion accuracy of the code conversion method are improved.
In a possible embodiment, the method further comprises:
determining, in the first programming language, the library link address based on the library name and the mapping table in the interface file;
and routing to the packaging library according to the library link address, routing to the third party library according to the link address of the third party library in the packaging library, and calling the third party library according to the calling parameter in the first programming language.
Wherein, the third-party library registered in the compiler can be called to compile under the first programming language. In this case, the library link address corresponding to the library name may be queried from the mapping table in the interface file based on the called library name. For example, the library name MyClass may be used as a key to query from the mapping table, so as to query a value corresponding to the key, that is, a library link address corresponding to the library name MyClass, which is denoted as a 1.
In this embodiment, a library call may be made based on the returned address A1 to effect a call to the packaging library MyClass. The third-party library is further called based on the link address A2 of the third-party library in the packaging library when the packaging library is called, and the calling of the third-party library in the first programming language is realized. The conversion of the parameter types in different programming languages in the calling process can be realized based on a functional context Interface (FFI) of a runtime layer in the compiler, and details are not repeated herein, so that according to the technical scheme, the calling of the package library can be distributed and routed to the actual link address of the corresponding third-party library in the first programming language based on the package library and the mapping table, the third-party library can be called, the third-party libraries in the first programming language can be directly used, the use range of the compiler is further expanded, and the compiler is attached to the actual application scene.
In a possible embodiment, the method further comprises:
and packaging the runtime module and the meta-information of the runtime module to obtain a Just-In-Time Operator (JitOp).
Integrating the just-in-time generation processor into a process flow to use the just-in-time generation processor in the process flow based on an interface of the just-in-time generation processor.
In this embodiment, after the source code is converted to obtain the compiled code, it may be integrated with other judgment logic and the like, and it may further package the runtime module for the convenience of using by a caller in the processing flow pipeline, where the meta information is information about information for describing the structure, semantics, usage, and the like of the information. In this embodiment, the structure of the meta-information may be preset, so that the meta-information of the runtime module may be determined according to the structure and the runtime module, and thus the meta-information is encapsulated. Therefore, by the technical scheme, the calling party can directly call the compiled code based on the interface after the processor is generated in real time through packaging, so that the calling of the logic in the compiled code is consistent with the calling mode of a common function, a simpler and more convenient calling mode is provided for other calling parties, the use flow and the calling mode are simplified, the automation level of the compiled code application is further improved, the complexity of model deployment can be effectively simplified, and the use experience of a user is improved.
It should be understood that, as shown in fig. 5, the Error reporting program Error Reporter is the above Error reporting function, FATAL, function, and is used to output all runtime errors.
FIG. 6 is a block diagram illustrating the connection of modules that provide an error code locating device in accordance with an exemplary embodiment. As shown in fig. 6, an embodiment of the present disclosure provides an error code locating apparatus, where the apparatus 400 may include:
a compiling module 401 configured to compile a source code of a programming language into an executable file of a machine language;
an error reporting module 402 configured to output exception information through an error reporting function when the executable file has a runtime error;
an obtaining module 403, configured to, in response to the exception information, obtain a call stack of the error reporting function;
a determining module 404 configured to determine location information of an error code of the source code according to the call stack.
Optionally, the determining module 404 includes:
the positioning subunit is configured to determine a compiled code with an error according to a call return address in the call stack, where the compiled code is an intermediate code when the source code is compiled into the executable file;
a determining subunit configured to determine, based on the compiled code in which the error has occurred, location information of an error code of the source code.
Optionally, the determining subunit is specifically configured to:
determining the position information of the error code corresponding to the source code based on the compiled code with the error and by combining a mapping relation;
the mapping relationship is a corresponding relationship between the position information of the source code recorded in the compiling process of the compiler and the position information of the compiled code corresponding to the source code.
Optionally, the compiling module 401 includes:
an acquisition subunit configured to acquire source code of a first programming language;
the analysis subunit is configured to analyze the source code to obtain variable information and dependency information corresponding to the source code, wherein the dependency information includes dependency relationships among a plurality of analysis objects, and the analysis objects include functions and/or classes;
a conversion subunit, configured to convert, according to the variable information and the dependency information, an abstract syntax tree corresponding to each parsing object in the dependency information into an intermediate representation, where the intermediate representation includes type information of each node in the abstract syntax tree;
a compiling subunit configured to generate compiled code of a second programming language from the intermediate representation;
a generating subunit configured to generate an executable file of the machine language from the compiled code.
Optionally, the generating subunit includes:
the calling subunit is configured to call a compiler corresponding to the second programming language to compile the compiled code, so as to obtain a dynamic library corresponding to the compiled code;
and the packaging subunit is configured to package the dynamic library and the function table corresponding to the compiled code to obtain the executable file, wherein the executable file is called based on an entry function corresponding to the executable file.
Optionally, the parsing subunit includes:
the variable subunit is configured to analyze the variable in the source code to obtain a global variable and a local variable in the source code to obtain the variable information;
and the dependency parsing subunit is configured to determine, for each parsing object in the source code, dependency information of the parsing object according to the abstract syntax tree corresponding to the parsing object.
Optionally, the dependency resolution subunit is specifically configured to:
determining whether the target object has a dependent object according to an abstract syntax tree corresponding to the target object, wherein the target object is initially the analysis object;
if the dependent object exists, analyzing variables in the object code file under the condition that the obtained object code file to which the dependent object belongs is not the source code file aiming at the dependent object, obtaining a global variable and a local variable in the object code file to obtain variable information corresponding to the object code file, taking the dependent object as a new object, and determining whether the dependent object exists in the object according to the abstract syntax tree corresponding to the object again until the dependent object corresponding to the object does not exist;
and generating the dependency information of the analysis object according to each target object determined by the analysis object and the dependency object of the target object.
The detailed description of the functional modules of the apparatus in the above embodiments has been given in detail in relation to the method, and is not repeated here.
Referring now to FIG. 7, a block diagram of an electronic device 600 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 7, electronic device 600 may include a processing means (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 7 illustrates an electronic device 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 609, or may be installed from the storage means 608, or may be installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can 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 electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some implementations, the electronic devices may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer-readable storage medium may be included in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable storage medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: compiling source codes of a programming language into an executable file of a machine language; when the executable file has an error in operation, outputting abnormal information through an error reporting function; responding to the abnormal information, and acquiring a call stack of the error reporting function; and determining the position information of the error code of the source code according to the call stack.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of 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 the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present disclosure may be implemented by software or hardware. Wherein the name of a module in some cases does not constitute a limitation on the module itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, 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 a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims. With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.

Claims (10)

1. An error code location method, comprising:
compiling source codes of a programming language into an executable file of a machine language;
when the executable file has an error in operation, outputting abnormal information through an error reporting function;
responding to the abnormal information, and acquiring a call stack of the error reporting function;
and determining the position information of the error code of the source code according to the call stack.
2. The method of claim 1, wherein the determining the location information of the error code of the source code according to the call stack comprises:
determining a compiled code with an error according to a call return address in the call stack, wherein the compiled code is an intermediate code when the source code is compiled into the executable file;
and determining the position information of the error code of the source code based on the compiled code with the error.
3. The method of claim 2, wherein the determining the location information of the error code of the source code based on the compiled code with the error comprises:
determining the position information of the error code corresponding to the source code based on the compiled code with the error and by combining a mapping relation;
the mapping relationship is a corresponding relationship between the position information of the source code recorded in the compiling process of the compiler and the position information of the compiled code corresponding to the source code.
4. The method of claim 1, wherein compiling source code of a programming language into an executable file of a machine language comprises:
acquiring a source code of a first programming language;
analyzing the source code to obtain variable information and dependency information corresponding to the source code, wherein the dependency information comprises dependency relationships among a plurality of analysis objects, and the analysis objects comprise functions and/or classes;
converting the abstract syntax tree corresponding to each analysis object in the dependency information into an intermediate representation according to the variable information and the dependency information, wherein the intermediate representation comprises type information of each node in the abstract syntax tree;
generating compiled code of a second programming language from the intermediate representation;
and generating an executable file of the machine language according to the compiled code.
5. The method of claim 4, wherein the generating an executable file of the machine language from the compiled code comprises:
calling a compiler corresponding to the second programming language to compile the compiled code to obtain a dynamic library corresponding to the compiled code;
and packaging the dynamic library and a function table corresponding to the compiled code to obtain the executable file, wherein the executable file is called based on an entry function corresponding to the executable file.
6. The method according to claim 4, wherein the parsing the source code to determine the variable information and the dependency information corresponding to the source code comprises:
analyzing the variables in the source code to obtain global variables and local variables in the source code so as to obtain the variable information;
and determining the dependency information of the analysis object according to the abstract syntax tree corresponding to the analysis object aiming at each analysis object in the source code.
7. The method according to claim 6, wherein the determining the dependency information of the parsed object according to the abstract syntax tree corresponding to the parsed object comprises:
determining whether the target object has a dependent object according to an abstract syntax tree corresponding to the target object, wherein the target object is initially the analysis object;
if the dependent object exists, analyzing variables in the object code file under the condition that the obtained object code file to which the dependent object belongs is not the source code file aiming at the dependent object, obtaining a global variable and a local variable in the object code file to obtain variable information corresponding to the object code file, taking the dependent object as a new object, and determining whether the dependent object exists in the object according to the abstract syntax tree corresponding to the object again until the dependent object corresponding to the object does not exist;
and generating the dependency information of the analysis object according to each target object determined by the analysis object and the dependency object of the target object.
8. An error code locating apparatus, comprising:
a compiling module configured to compile a source code of a programming language into an executable file of a machine language;
the error reporting module is configured to output abnormal information through an error reporting function when the executable file has a runtime error;
the obtaining module is configured to respond to the abnormal information and obtain a call stack of the error reporting function;
and the determining module is configured to determine the position information of the error code of the source code according to the call stack.
9. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by processing means, carries out the steps of the method according to any one of claims 1 to 7.
10. An electronic device, comprising:
a storage device having a computer program stored thereon;
processing means for executing the computer program in the storage means to carry out the steps of the method according to any one of claims 1 to 7.
CN202111358194.9A 2021-11-16 2021-11-16 Error code positioning method, device, storage medium and electronic equipment Pending CN114047923A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111358194.9A CN114047923A (en) 2021-11-16 2021-11-16 Error code positioning method, device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111358194.9A CN114047923A (en) 2021-11-16 2021-11-16 Error code positioning method, device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN114047923A true CN114047923A (en) 2022-02-15

Family

ID=80209685

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111358194.9A Pending CN114047923A (en) 2021-11-16 2021-11-16 Error code positioning method, device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN114047923A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115185525A (en) * 2022-05-17 2022-10-14 贝壳找房(北京)科技有限公司 Data skew code block positioning method, apparatus, device, medium, and program product

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115185525A (en) * 2022-05-17 2022-10-14 贝壳找房(北京)科技有限公司 Data skew code block positioning method, apparatus, device, medium, and program product

Similar Documents

Publication Publication Date Title
US11868231B2 (en) System and method for evaluating code by a hybrid of local and cloud-based computers
US11151018B2 (en) Method and apparatus for testing a code file
US8875110B2 (en) Code inspection executing system for performing a code inspection of ABAP source codes
CN109033843B (en) Java file dependency analysis method and module for distributed static detection system
US9928042B2 (en) Automatic classification of compilers
CN114035805A (en) Code conversion method, apparatus, medium, and device for pre-compiler
CN102279790A (en) Distributed debugging method and system
US9311077B2 (en) Identification of code changes using language syntax and changeset data
CN112527386B (en) Application program issuing method and device
US9672015B2 (en) Automatic determination of compiler configuration
CN114047923A (en) Error code positioning method, device, storage medium and electronic equipment
CN109284222B (en) Software unit, project testing method, device and equipment in data processing system
CN111240987B (en) Method and device for detecting migration program, electronic equipment and computer readable storage medium
US9064042B2 (en) Instrumenting computer program code by merging template and target code methods
CN112527302B (en) Error detection method and device, terminal and storage medium
CN115951916A (en) Component processing method and device, electronic equipment and storage medium
CN115705250A (en) Monitoring stack usage to optimize programs
CN111539200B (en) Method, device, medium and electronic equipment for generating rich text
CN110297639B (en) Method and apparatus for detecting code
CN114035804A (en) Code conversion method, device, medium and electronic equipment
CN115729797A (en) Code similarity function detection method and device, electronic equipment and storage medium
CN117075912B (en) Method for program language conversion, compiling method and related equipment
US20230315412A1 (en) Scalable behavioral interface specification checking
US20230315862A1 (en) Method and apparatus for identifying dynamically invoked computer code using literal values
CN117850787A (en) Dynamic call chain acquisition method and device, electronic equipment and readable storage medium

Legal Events

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