Detailed Description
To make the objects, technical solutions and advantages of the present disclosure clearer, the present disclosure will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present disclosure, rather than all embodiments. All other embodiments, which can be derived by one of ordinary skill in the art from the embodiments disclosed herein without making any creative effort, shall fall within the scope of protection of the present disclosure.
The terminology used in the embodiments of the present disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in the disclosed embodiments and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise, and "a plurality" typically includes at least two.
It should be understood that the term "and/or" as used herein is merely one type of association that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
It should be understood that although the terms first, second, third, etc. may be used to describe … … in embodiments of the present disclosure, these … … should not be limited to these terms. These terms are used only to distinguish … …. For example, the first … … can also be referred to as the second … … and, similarly, the second … … can also be referred to as the first … … without departing from the scope of embodiments of the present disclosure.
The words "if", as used herein, may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to a detection", depending on the context. Similarly, the phrases "if determined" or "if detected (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when detected (a stated condition or event)" or "in response to a detection (a stated condition or event)", depending on the context.
It is also noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that an article or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such article or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in the article or device in which the element is included.
Alternative embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
As shown in fig. 1, the logic relationship diagram according to the embodiment of the present disclosure includes a compiling process, a mobile phone terminal, an analysis server, and a front-end display, where the compiling process is that a program developer performs simplified editing of an APK through a compiler, the generated APK installation package is installed in the mobile phone terminal of a user, when the mobile phone terminal crashes or jams, an instruction offset value and a function name of a call stack are obtained through an SDK in the APK, and are reported to the analysis server, and the analysis server obtains an accurate crash position after analyzing, and displays the crash position to the program developer through the front-end display device, and the program developer can accurately locate the crash or jam position. The method comprises the following specific steps:
the APK compilation process is as follows, as shown in fig. 2:
step S202: and acquiring a dex file in the APK.
The Android Package (APK) is an Android installation package (APK), and the APK file can be installed by directly transmitting the APK file to an Android simulator or an Android mobile phone for execution.
The APK is used for packaging the project compiled by the android sdk into an installer file with the format of APK. The apk file is in zip format, but the suffix name is modified into apk, and the dex file can be seen after being decompressed by UnZip.
The dex file is the type of executable file on the Android platform. Dex (Dalvik vm executions), an Android Dalvik executive, is a Dalvik bytecode. When the Android runs a program, UnZip decompression is firstly needed, and a dex file can be seen after decompression.
Step S204: and storing the mapping relation between the instruction offset and the line number in the dex file as a first data file through a first file application tool.
The first file application tool can be dexdump to obtain a complete dex file before the deletion line number of Proguard, the dex file reserves the relation between each function dexPC (instruction offset) and the source code line number, and the relation can be stored as a data file by the dexdump tool and is used for describing the relation between each function dexPC (instruction offset) and the source code line number. This data file will be used by the parsing server.
Step S206: and deleting the line number file in the dex file through a second file application tool to form a simplified installation package file.
The second file application tool may be Proguard, which controls Proguard to generate a dex file without including debug item, and may be implemented by removing a configuration option of "-keep linemanaging table" used in general development, so that the generated dex file does not retain a relationship between a dexPC (instruction offset) and a line number of a function, and an APK volume is reduced.
Optionally, the method further comprises the following steps:
step S208: and saving the confusion relation of the function names in the dex file as a second data file through a third file application tool.
The third file application tool may be a trace, which saves the relationship between the member name of the class name before confusion and the member name of the class name after confusion as a mapping file, and the mapping file is also used by the resolution server. For example, the function name "do sth" is confused as "d", and the mapping file retains the mapping relationship between "do sth" and "d", so that anyone can know that the function name is "do sth" substantially through "d".
Optionally, the APK compiling process further includes one of the following method steps:
firstly, the first data file is sent to a server for data analysis.
And sending the dex file without deleting the line number to a server side, wherein the dex file reserves the mapping relation between the instruction offset and the line number, and when the corresponding instruction offset value is obtained from the mobile phone crash side, the accurate line number of the call stack can be obtained through the mapping relation.
Secondly, the simplified installation package file is sent to a mobile terminal for installation.
And the APK file with the row number deleted is sent to the mobile terminal, and the mobile terminal rapidly installs the APK file after obtaining the APK, so that the time and the space for installing the APK are reduced, the data flow is saved, and the user experience performance is improved.
The mobile terminal can be any android system such as a mobile phone and a PAD (PAD application program), and can be an intelligent terminal for operating the APK, after the intelligent terminal obtains the simplified APK file, once the intelligent terminal is broken down (for example, flashing) in the installation and operation process, the SDK in the APK can automatically obtain the needed call stack to analyze the reason of the breakdown. And after the SDK acquires the dexPC and the function signature of each stack frame in the call stack, reporting to the server for analysis to obtain the DexPC.
And thirdly, sending the second data file to a server for data analysis.
The server comprises any analysis server used for analyzing the crash problem, the analysis server is used for analyzing the information reported by the android client into a call stack with a real source code line number, and the analysis server is divided into two parts:
A. and obtaining the source code line number of each stack frame in the call stack according to the relationship between the dexPC and the source code line number of each function in the dex generated in the compiling process and the reported dexPC value and function signature of each stack frame in the call stack.
B. And obtaining the class name and the function name before each stack frame is confused according to the mapping file generated in the compiling process and the stack frame information in the call stack obtained in the last step (which is realized by a trace tool of Proguard). This results in a call stack with a true source line number and an un-obfuscated class name method name for each stack frame.
The APK resolution process is as follows, as shown in fig. 3:
step S302: and acquiring a first data file, wherein the first data file stores the mapping relation between the instruction offset and the line number in the dex file.
The first data file is a dex file which reserves the mapping relation between the instruction offset and the line number in the APK file.
The complete dex file before deleting the line number is acquired through Proguard, the dex file maintains the relation between each function dexPC (instruction offset) and the source code line number, and the relation can be saved as a data file through a dexdump tool and is used for describing the relation between each function dexPC (instruction offset) and the source code line number. This data file will be used by the parsing server.
Step S304: and acquiring a second data file, wherein the second data file stores the confusion relation of the function names in the dex file.
The second data file is a file storing the confusion relationship of the function name in the dex file, the application tool trace saves the relationship between the member name of the class name before confusion and the member name of the class name after confusion as a mapping file, and the file is also used by the analysis server. For example, the function name "do sth" is confused as "d", and the mapping file retains the mapping relationship between "do sth" and "d", so that anyone can know that the function name is "do sth" substantially through "d".
Step S306: and acquiring an instruction offset value and a function signature of each stack frame in a call stack reported by a network.
The network report is obtained from the mobile terminal provided with the simplified APK, and the mobile terminal is quickly installed after obtaining the APK, so that the time and the space for installing the APK are reduced, the data flow is saved, and the user experience performance is improved.
The mobile terminal can be any android system such as a mobile phone and a PAD (PAD application program), and can be an intelligent terminal for operating the APK, after the intelligent terminal obtains the simplified APK file, once the intelligent terminal is broken down (for example, flashing) in the installation and operation process, the SDK in the APK can automatically obtain the needed call stack to analyze the reason of the breakdown. And after the SDK acquires the dexPC and the function signature of each stack frame in the call stack, reporting to the server for analysis to obtain the DexPC.
Step S308: and finding the source code line number and the class name function name before confusion of each stack frame from the relationship between the first data file and the second data file through the instruction deviation value and the function signature.
The server comprises any analysis server used for analyzing the crash problem, the analysis server is used for analyzing the information reported by the android client into a call stack with a real source code line number, and the analysis server is divided into two parts:
A. and obtaining the source code line number of each stack frame in the call stack according to the relationship between the dexPC and the source code line number of each function in the dex generated in the compiling process and the reported dexPC value and function signature of each stack frame in the call stack.
B. And obtaining the class name and the function name before each stack frame is confused according to the mapping file generated in the compiling process and the stack frame information in the call stack obtained in the last step (which is realized by a trace tool of Proguard). This results in a call stack with a true source line number and an un-obfuscated class name method name for each stack frame.
Optionally, the method further comprises the following steps:
step S310: determining an accurate call stack according to the line number of the source code and the name of the class name function before confusion; and displaying the call stack information.
Once an accurate call stack is determined through the source code line number and the name of the class name function before confusion, the call stack is sent to the front end to be displayed, the front end is used for displaying the call stack from the android client after being processed by the analysis server, and an intuitive visual interface is provided for a developer to solve problems and obtain application information.
The method for acquiring the instruction offset by the mobile phone terminal comprises the following steps:
as shown in fig. 4, the present disclosure provides a method for obtaining a call stack frame instruction offset, including:
step S402: and acquiring a call stack storage object in the trigger event.
Optionally, the method specifically includes:
when the trigger event is a crash event (a Throwable object), a call stack storage object (a backup object) is directly obtained through reflection, wherein the crash event is that when problems such as invalid access of a memory, an invalid object, memory leakage, stack overflow and the like occur in the running process of a mobile phone application program, the application program cannot run normally, so that the program has phenomena such as flash back, no response and the like.
When the trigger event is a stuck event (Thread object), the stuck event refers to an unsmooth event such as delayed response occurring in the process of program running. The acquiring a call stack storage object (backing object) in the trigger event comprises:
first, the ID of the target thread is obtained. Obtaining a pointer parameter for storing local service in the katton event through reflection; and executing the first function to obtain the ID of the target thread.
Firstly, obtaining a member which is stored with a native (local service) layer representation in a target Thread object through reflection, wherein the member is a pointer and is called targetPtr below; then execute the GetThreadId function of Dbg class to get the id of the target thread, hereinafter targetId.
And secondly, pausing the target thread according to the ID of the target thread. And inputting the ID of the target thread as a parameter into a second function, and pausing the target thread.
Then, using targetId as a parameter, the suspend thread function of Dbg class is executed, and then the target thread suspends the execution.
And thirdly, acquiring the call stack storage object from the suspended target thread. And inputting the pointer parameter of the local service stored in the morton event into a third function to obtain the call stack storage object.
And then, taking the targetPtr as a parameter, executing a creatInternalStackTrace function, and obtaining a return result, namely backtrace.
Fourth, resume execution of the target thread. And inputting the ID of the target thread as a parameter into a fourth function, and recovering the execution of the target thread.
Finally, with targetId as a parameter, Dbg class resumerThread function is executed, after which the target thread resumes execution.
Step S404: and converting the call stack storage object into an object array by force.
Step S406: and taking a first element of the object array, and converting the first element into an integer array or a long integer array.
Step S408: and intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset.
Specifically, the call stack storage Object backtrace is forced to be an Object [ ] type Object (hereinafter referred to as backtraceArr); then taking a first element first of the backstraceArr; then, the first is converted into an object (hereinafter referred to as first IL) of an int [ ] type (under 32-bit operation condition) or a long [ ] type (under 64-bit operation condition); and finally, taking out the data of the second half section of the array of the firstIL, namely the dexPC value of all stack frames.
The method for acquiring the function signature by the mobile phone terminal comprises the following steps:
since the size of the backtracear is +1, the length of the stackCnt is-1; then i starts traversing from 0 to stackCnt-1, i.e. all stack frames are traversed, and each traversal process is as follows: taking an element (hereinafter referred to as mid) with an index of i of firstIL, which is jmehthodID of the method of the stack frame, taking an element (hereinafter referred to as cls) with an index of i +1 of backstraceArr, which is a class where the method of the stack frame is located, then transferring the mid and the cls from a java layer to a c layer, obtaining a method object (hereinafter referred to as method) by the c layer through a ToReflectMethod function of a java virtual machine, and then transferring the method to the java layer and recording a signature (including a method name, a parameter number and types of each parameter).
Thus, the required call stack is obtained, the dexPC value and the method signature of each stack frame in the call stack are obtained, and the DexPC value and the method signature are reported to the analysis server for processing through the network at the android client.
The method can accurately obtain the instruction offset value of the call stack frame in the crash event or the stuck event, can further determine the source code line number in the dex file through the instruction offset value, so that after the APK deletes the line number information in the installation package, the APK can still obtain the instruction offset value of the call stack frame in the crash event or the stuck event through the built-in SDK, and further find out the crash position of the file, so that the volume of the android application installation package can be effectively simplified, the downloading success rate of the application is improved, more users are brought to the product, and the popularization efficiency of the product is improved.
In addition, the present disclosure also provides an apparatus embodiment adapted to the above embodiment, for implementing the method steps described in the above embodiment, and the explanation based on the same name and meaning is the same as that of the above embodiment, and has the same technical effect as that of the above embodiment, and is not described again here.
As shown in fig. 5, according to the specific embodiment of the present disclosure, the present disclosure provides an apparatus for obtaining a call stack frame instruction offset, which includes a obtaining unit 502, a first converting unit 504, a second converting unit 506, and an intercepting unit 508.
The acquisition unit 502: and acquiring a call stack storage object in the trigger event.
Optionally, the method specifically includes:
and when the trigger event is a crash event (Throwable object), directly reflecting and acquiring a call stack storage object (backing object).
When the trigger event is a click event (Thread object), acquiring a call stack storage object (fallback object) in the trigger event includes:
first, the ID of the target thread is obtained. Obtaining a pointer parameter for storing local service in the katton event through reflection; and executing the first function to obtain the ID of the target thread.
Firstly, obtaining a member which is used for storing a native layer representation in a target Thread object through reflection, wherein the member is a pointer and is called targetPtr below; then execute the GetThreadId function of Dbg class to get the id of the target thread, hereinafter targetId.
And secondly, pausing the target thread according to the ID of the target thread. And inputting the ID of the target thread as a parameter into a second function, and pausing the target thread.
Then, using targetId as a parameter, the suspend thread function of Dbg class is executed, and then the target thread suspends the execution.
And thirdly, acquiring the call stack storage object from the suspended target thread. And inputting the pointer parameter of the local service stored in the morton event into a third function to obtain the call stack storage object.
And then, taking the targetPtr as a parameter, executing a creatInternalStackTrace function, and obtaining a return result, namely backtrace.
Fourth, resume execution of the target thread. And inputting the ID of the target thread as a parameter into a fourth function, and recovering the execution of the target thread.
Finally, with targetId as a parameter, Dbg class resumerThread function is executed, after which the target thread resumes execution.
First conversion unit 504: and converting the call stack storage object into an object array by force.
Second conversion unit 506: and taking a first element of the object array, and converting the first element into an integer array or a long integer array.
The interception unit 508: and intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset.
Specifically, the call stack storage Object backtrace is forced to be an Object [ ] type Object (hereinafter referred to as backtraceArr); then taking a first element first of the backstraceArr; then, the first is converted into an object (hereinafter referred to as first IL) of an int [ ] type (under 32-bit operation condition) or a long [ ] type (under 64-bit operation condition); and finally, taking out the data of the second half section of the array of the firstIL, namely the dexPC value of all stack frames.
The device can accurately obtain the instruction deviation value of the call stack frame in the crash event or the stuck event, and can further determine the source code line number in the dex file after the instruction deviation value, so that after the APK deletes the line number information in the installation package, the APK can still obtain the instruction deviation value of the call stack frame in the crash event or the stuck event through the built-in SDK, and further find the crash position of the file, so that the volume of the android application installation package can be effectively simplified, the downloading success rate of the application is improved, more users are brought to the product, and the popularization efficiency of the product is improved.
As shown in fig. 6, the present embodiment provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the one processor to cause the at least one processor to perform the method steps of the above embodiments.
The disclosed embodiments provide a non-volatile computer storage medium having stored thereon computer-executable instructions that may perform the method steps as described in the embodiments above.
Referring now to FIG. 6, shown is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. 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. 6 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. 6, the electronic device may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 601, which may perform various appropriate actions and processes according to 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 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 605. An input/output (I/O) interface 605 is also connected to bus 605.
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.; an output device 605 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, etc.; storage 608 including, for example, tape, hard disk, etc.; and a communication device 605. The communication device 605 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 illustrates an electronic device 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 embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication device 605, or installed from the storage device 608, or 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.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including 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 units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.