CN110727480A - Method, device, medium and equipment for acquiring call stack frame instruction offset - Google Patents

Method, device, medium and equipment for acquiring call stack frame instruction offset Download PDF

Info

Publication number
CN110727480A
CN110727480A CN201910835078.8A CN201910835078A CN110727480A CN 110727480 A CN110727480 A CN 110727480A CN 201910835078 A CN201910835078 A CN 201910835078A CN 110727480 A CN110727480 A CN 110727480A
Authority
CN
China
Prior art keywords
call stack
thread
target thread
acquiring
parameter
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.)
Granted
Application number
CN201910835078.8A
Other languages
Chinese (zh)
Other versions
CN110727480B (en
Inventor
刘洪凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
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 CN201910835078.8A priority Critical patent/CN110727480B/en
Publication of CN110727480A publication Critical patent/CN110727480A/en
Application granted granted Critical
Publication of CN110727480B publication Critical patent/CN110727480B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The present disclosure provides a method, an apparatus, a medium, and a device for obtaining a call stack frame instruction offset, where the method includes: initializing an SDK (software development kit), and constructing an assistance process, wherein only one thread is arranged in the assistance process; acquiring a call stack storage object in the program running process; converting the call stack storage object into an object array; acquiring a first element of the object array, and strongly converting the first element into an integer array or a long integer array; and intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset. The method can accurately obtain the instruction offset value of the call stack frame, so that the volume of the android application installation package can be effectively reduced, the downloading success rate of the application is further improved, more users are brought to the product, and the popularization efficiency of the product is improved.

Description

Method, device, medium and equipment for acquiring call stack frame instruction offset
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a medium, and a device for obtaining a call stack frame instruction offset.
Background
The inclusion volume of android applications is one of the important indexes for measuring the application quality: the smaller the bag volume is, the higher the download success rate of the user is, and the more users can use the application. The dex in the installation package (apk file) of the android application stores the code of the application, and occupies a considerable volume. If the volume of the part can be reduced, the volume of the installation package can be effectively reduced undoubtedly, the line number information of the application code is stored in the debug item in the dex, the operation effect of the code cannot be influenced after deletion, but the line number information of the source code corresponding to the application cannot be obtained, and the positioning is difficult when the application goes wrong.
Therefore, how to accurately acquire the instruction offset value of the call stack after deleting the source code line number of the call stack, and then find the source code line number is a technical problem to be solved.
BRIEF SUMMARY OF THE PRESENT DISCLOSURE
An object of the present disclosure is to provide a method, an apparatus, a medium, and a device for obtaining a call stack frame instruction offset, which can solve at least one of the above-mentioned technical problems. The specific scheme is as follows:
according to a specific implementation manner of the present disclosure, in a first aspect, the present disclosure provides a method for obtaining a call stack frame instruction offset, including:
initializing an SDK (software development kit), and constructing an assistance process, wherein only one thread is arranged in the assistance process;
acquiring a call stack storage object in the program running process;
converting the call stack storage object into an object array;
acquiring a first element of the object array, and strongly converting the first element into an integer array or a long integer array;
and intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset.
Optionally, the initializing the SDK further includes:
acquiring pointer parameters for storing local services;
and acquiring a construction function under the specified file directory, wherein the construction function is used for constructing a java thread calling stack bottom layer representation object.
Optionally, the obtaining a call stack storage object in the program running process includes:
acquiring the ID of a target thread;
pausing the target thread according to the ID of the target thread;
acquiring the call stack storage object from the suspended target thread;
resuming execution of the target thread.
Optionally, the obtaining the ID of the target thread includes:
calling a name extraction function;
acquiring the name of the target thread through the name extraction function;
and traversing all subdirectories under the specified file directory, and searching the ID of the target thread through the name of the target thread.
Optionally, the suspending the target thread according to the ID of the target thread includes:
calling a first system call of a linux operating system through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a first character string, and the second parameter adopts the ID of the target thread;
calling a second system call of the linux operating system through the assisting thread, wherein the second system call comprises the second parameter;
and after the second system call is successfully called, the target thread is suspended.
Optionally, the obtaining the call stack storage object from the suspended target thread includes:
and inputting the pointer parameter of the stored local service into the construction function to acquire the call stack storage object.
Optionally, the resuming the execution of the target thread includes:
calling the first system call again through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a second character string, and the second parameter adopts the ID of the target thread;
and after the first system call is successfully called again, the target thread resumes executing.
According to a second aspect of the present disclosure, an apparatus for obtaining an offset of a call stack frame instruction is provided, which includes:
the device comprises an initialization unit, a processing unit and a processing unit, wherein the initialization unit is used for initializing the SDK and constructing an assistance process, and only one thread is arranged in the assistance process;
the first acquisition unit is used for acquiring a call stack storage object in the program running process;
the conversion unit is used for converting the call stack storage object into an object array;
the second acquisition unit is used for acquiring a first element of the object array and converting the first element into an integer array or a long integer array;
and the intercepting unit is used for intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset.
According to a third aspect, the present disclosure provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method of any one of the above.
According to a fourth aspect thereof, the present disclosure provides an electronic device, comprising: one or more processors; storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out a method as claimed in any preceding claim.
Compared with the prior art, the scheme of the embodiment of the disclosure at least has the following beneficial effects: the method can accurately obtain the instruction offset value of the call stack frame when the program runs and has the events such as the jamming and the delay, can further determine the line number of the source code in the dex file through the instruction offset value, enables the APK to obtain the instruction offset value of the call stack frame in the jamming event through the built-in SDK after deleting the line number information in the installation package, and further finds the collapse position of the file, enables the volume of the android application installation package to be effectively simplified, further improves the downloading success rate of the application, brings more users to the product, and improves the popularization efficiency of the product.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without the exercise of inventive faculty. In the drawings:
FIG. 1 illustrates a logical relationship diagram according to an embodiment of the present disclosure;
FIG. 2 illustrates an edit process method flow diagram in accordance with an embodiment of the present disclosure;
FIG. 3 illustrates a parsing process method flow diagram according to an embodiment of the disclosure;
FIG. 4 illustrates a flow diagram of a get instruction offset method according to an embodiment of the disclosure;
FIG. 5 is a schematic diagram of a fetch instruction offset apparatus according to an embodiment of the present disclosure;
fig. 6 shows an electronic device connection structure schematic according to an embodiment of the present disclosure.
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 "dosth" is confused as "d", and the mapping file retains the mapping relation between "dosth" and "d", so that anyone can know that the function name is "dosth" 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, a method for obtaining a call stack frame instruction offset includes the following method steps:
step S402: the SDK is initialized and a helper process (helper process) is constructed, which has only one thread. Preferably, the initializing the SDK further includes: acquiring pointer parameters for storing local services; and acquiring a construction function under the specified file directory, wherein the construction function is used for constructing a java thread calling stack bottom layer representation object.
The SDK firstly acquires a Field (generally, a member named as native Peer in the Thread class) used for storing a pointer of a native layer Thread object in the Thread class; so find a function by reading libart. The build java Thread calls the function CreateImataStackTrace (symbol is usually _ ZNK3art6Thread24 CreateImataStackTraceILb 0EEEP8_ jobjectRKNS _33 ScopedObjectAccessAlreadyRunnable). Then a new process (such as a helper process) is created, and only one thread (helper thread) exists in the process, and one implementation way of creating the process is to use a clone system call provided by the Linux operating system.
Step S404: and acquiring a call stack storage object in the program running process.
In the program running process, events such as system crash, jamming or unsmooth communication can occur, which indicates that the program thread is abnormal when being called. For example, when the trigger event is a crash event (a Throwable object), the call stack storage object (a backing object) is obtained by direct reflection, where the crash event is that when a problem such as invalid access to a memory, an invalid object, memory leak, stack overflow, or the like occurs in an operation process of a mobile application program, the application program cannot normally operate, so that the program has phenomena such as flash back, no response, or 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.
Optionally, the obtaining of the call stack storage object in the program running process includes the following sub-steps:
step S4041: and acquiring the ID of the target thread.
Optionally, the obtaining the ID of the target thread includes: calling a name extraction function; acquiring the name of the target thread through the name extraction function; and traversing all subdirectories under the specified file directory, and searching the ID of the target thread through the name of the target thread.
Specifically, each thread in the process has a corresponding subdirectory (the name is the thread id of the thread) under the/proc/self/task directory, and the comm file under the subdirectory stores the name of the thread (the length is limited). Firstly, calling a getName method of a target Thread object to obtain the name (hereinafter, targetThreadName); then, the directory of/proc/self/task is opened, all the sub-directories below the directory are traversed, a comm file below the directory is read (the full path is/proc/self/[ tid ]/comm, wherein [ tid ] needs to be replaced by the true value of thread id), that is, the name of the thread is obtained, if the targetThreadName contains the character string, the thread is the target thread, and the thread id (hereinafter, targetTid) of the target thread is obtained.
Step S4042: and pausing the target thread according to the ID of the target thread.
Optionally, the suspending the target thread according to the ID of the target thread includes: calling a first system call of a linux operating system through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a first character string, and the second parameter adopts the ID of the target thread; calling a second system call of the linux operating system through the assisting thread, wherein the second system call comprises the second parameter; and after the second system call is successfully called, the target thread is suspended.
The method comprises the following specific steps: 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; the helper thread then suspends the target thread: the helper thread calls PTRACE of the linux operating system, the first parameter is PTRACE _ ATTACH, the second parameter is the thread id (targettid) of the target thread obtained above, and the third and fourth parameters are ignored (both NULL is used). After the ptrace call is successful, the helper thread calls waitpid, which is the system call, and takes targetTid as the first parameter. After the waitpid call is successfully called, the target thread is in a suspended state, the java code cannot be continuously executed, and the call stack can be safely acquired at the moment.
Step S4043: and acquiring the call stack storage object from the suspended target thread. The method comprises the following steps: and inputting the pointer parameter of the stored local service into the construction function to acquire the call stack storage object.
For example, a createlintersalstacktrace function is executed with targetpttr as a parameter, and the return result obtained is hereinafter referred to as backtrace.
Step S4044: resuming execution of the target thread.
Optionally, the resuming the execution of the target thread includes: calling the first system call again through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a second character string, and the second parameter adopts the ID of the target thread; and after the first system call is successfully called again, the target thread resumes executing.
Specifically, the system call PTRACE is called again by the helper thread, the first parameter is PTRACE _ DETACH, the second parameter is the thread id (targettid) of the target thread, and the third and fourth parameters are ignored (both NULL may be used). And after the ptrace call is successful, the target thread can resume execution and continuously execute the java code.
Step S406: and converting the call stack storage object into an object array by force. For example, the call stack storage Object backtrace is forced to an Object [ ] type Object (hereinafter, backtraceArr).
Step S408: and acquiring a first element of the object array, and strongly converting the first element into an integer array or a long integer array. For example, the first element of backstracearr, first, is fetched; the first is then forced to an object of int [ ] type (32 bit run case) or long [ ] type (64 bit run case) (hereinafter called first il).
Step S410: and intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset. For example, the data of the second half of the array of the firstll is taken as 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 when the program runs and has the events such as the jamming and the delay, can further determine the line number of the source code in the dex file through the instruction offset value, enables the APK to obtain the instruction offset value of the call stack frame in the jamming event through the built-in SDK after deleting the line number information in the installation package, and further finds the collapse position of the file, enables the volume of the android application installation package to be effectively simplified, further improves the downloading success rate of the application, brings more users to the product, and improves the popularization efficiency of the product.
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 a specific embodiment of the present disclosure, an apparatus for obtaining an instruction offset of a call stack frame includes an initialization unit 502, a first obtaining unit 504, a translation unit 506, a second obtaining unit 508, and an intercepting unit 510.
The initialization unit 502: for initializing the SDK, a helper process (helper process) is constructed, which has only one thread within it. Preferably, the initializing the SDK further includes: acquiring pointer parameters for storing local services; and acquiring a construction function under the specified file directory, wherein the construction function is used for constructing a java thread calling stack bottom layer representation object.
The first acquisition unit 504: the method is used for acquiring the call stack storage object in the program running process.
Optionally, the first obtaining unit 504 is configured to:
first, the ID of the target thread is obtained.
Optionally, the obtaining the ID of the target thread includes: calling a name extraction function; acquiring the name of the target thread through the name extraction function; and traversing all subdirectories under the specified file directory, and searching the ID of the target thread through the name of the target thread.
Secondly, the method comprises the following steps: and pausing the target thread according to the ID of the target thread.
Optionally, the suspending the target thread according to the ID of the target thread includes: calling a first system call of a linux operating system through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a first character string, and the second parameter adopts the ID of the target thread; calling a second system call of the linux operating system through the assisting thread, wherein the second system call comprises the second parameter; and after the second system call is successfully called, the target thread is suspended.
And thirdly, acquiring the call stack storage object from the suspended target thread. The method comprises the following steps: and inputting the pointer parameter of the stored local service into the construction function to acquire the call stack storage object.
Fourth, resume execution of the target thread.
Optionally, the resuming the execution of the target thread includes: calling the first system call again through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a second character string, and the second parameter adopts the ID of the target thread; and after the first system call is successfully called again, the target thread resumes executing.
The conversion unit 506: and the method is used for converting the call stack storage object into an object array.
The second acquisition unit 508: and the method is used for acquiring a first element of the object array and converting the first element into an integer array or a long integer array.
Intercept unit 510: and the method is used for intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset.
The device can accurately obtain the instruction deviation value of the call stack frame when the program runs and has the events such as jamming and delay, can further determine the line number of the source code in the dex file after the instruction deviation value is passed, 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 jamming event through the built-in SDK, and further find the collapse position of the file, so that the volume of the android application installation package can be effectively simplified, the download 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.

Claims (10)

1. A method for obtaining a call stack frame instruction offset, comprising:
initializing an SDK (software development kit), and constructing an assistance process, wherein only one thread is arranged in the assistance process;
acquiring a call stack storage object in the program running process;
converting the call stack storage object into an object array;
acquiring a first element of the object array, and strongly converting the first element into an integer array or a long integer array;
and intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset.
2. The method of claim 1, wherein the initializing the SDK, further comprises:
acquiring pointer parameters for storing local services;
and acquiring a construction function under the specified file directory, wherein the construction function is used for constructing a java thread calling stack bottom layer representation object.
3. The method of claim 2, wherein said obtaining a call stack memory object in the process of program execution comprises:
acquiring the ID of a target thread;
pausing the target thread according to the ID of the target thread;
acquiring the call stack storage object from the suspended target thread;
resuming execution of the target thread.
4. The method of claim 3, wherein obtaining the ID of the target thread comprises:
calling a name extraction function;
acquiring the name of the target thread through the name extraction function;
and traversing all subdirectories under the specified file directory, and searching the ID of the target thread through the name of the target thread.
5. The method of claim 4, wherein said pausing said target thread based on said target thread's ID comprises:
calling a first system call of a linux operating system through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a first character string, and the second parameter adopts the ID of the target thread;
calling a second system call of the linux operating system through the assisting thread, wherein the second system call comprises the second parameter;
and after the second system call is successfully called, the target thread is suspended.
6. The method of claim 4, wherein said fetching the call stack memory object from the suspended target thread comprises:
and inputting the pointer parameter of the stored local service into the construction function to acquire the call stack storage object.
7. The method of claim 6, wherein said resuming execution of the target thread comprises:
calling the first system call again through the assisting thread, wherein the first system call comprises a first parameter and a second parameter, the first parameter is expressed by a second character string, and the second parameter adopts the ID of the target thread;
and after the first system call is successfully called again, the target thread resumes executing.
8. An apparatus for obtaining a call stack frame instruction offset, comprising:
the device comprises an initialization unit, a processing unit and a processing unit, wherein the initialization unit is used for initializing the SDK and constructing an assistance process, and only one thread is arranged in the assistance process;
the first acquisition unit is used for acquiring a call stack storage object in the program running process;
the conversion unit is used for converting the call stack storage object into an object array;
the second acquisition unit is used for acquiring a first element of the object array and converting the first element into an integer array or a long integer array;
and the intercepting unit is used for intercepting the second half section data of the integer array or the long integer array to obtain the call stack frame instruction offset.
9. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out the method according to any one of claims 1 to 7.
10. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out the method of any one of claims 1 to 7.
CN201910835078.8A 2019-09-05 2019-09-05 Method, device, medium and equipment for acquiring call stack frame instruction offset Active CN110727480B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910835078.8A CN110727480B (en) 2019-09-05 2019-09-05 Method, device, medium and equipment for acquiring call stack frame instruction offset

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910835078.8A CN110727480B (en) 2019-09-05 2019-09-05 Method, device, medium and equipment for acquiring call stack frame instruction offset

Publications (2)

Publication Number Publication Date
CN110727480A true CN110727480A (en) 2020-01-24
CN110727480B CN110727480B (en) 2023-04-07

Family

ID=69218921

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910835078.8A Active CN110727480B (en) 2019-09-05 2019-09-05 Method, device, medium and equipment for acquiring call stack frame instruction offset

Country Status (1)

Country Link
CN (1) CN110727480B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111813465A (en) * 2020-06-19 2020-10-23 北京字节跳动网络技术有限公司 Information acquisition method, device, medium and equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050076172A1 (en) * 2003-07-16 2005-04-07 Infology Pty Limited Dba/Muvium.Com Architecture for static frames in a stack machine for an embedded device
CN101615136A (en) * 2009-06-26 2009-12-30 中兴通讯股份有限公司 The linux environment is changed the system and method for allocating stack address down fast
CN104391787A (en) * 2014-11-13 2015-03-04 华为软件技术有限公司 Monitoring method aiming at target method as well as thermal cutting-in method and device
CN104572448A (en) * 2014-12-23 2015-04-29 大唐移动通信设备有限公司 Method and device for realizing use condition of thread stack
BR102015030217A2 (en) * 2015-12-02 2017-06-06 Fund Cpqd - Centro De Pesquisa E Desenvolvimento Em Telecomunicações method for monitoring independent processes allocated in database access from a java virtual machine
CN107085548A (en) * 2016-02-16 2017-08-22 阿里巴巴集团控股有限公司 A kind of method, device and electronic equipment for monitoring application program internal memory

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050076172A1 (en) * 2003-07-16 2005-04-07 Infology Pty Limited Dba/Muvium.Com Architecture for static frames in a stack machine for an embedded device
CN101615136A (en) * 2009-06-26 2009-12-30 中兴通讯股份有限公司 The linux environment is changed the system and method for allocating stack address down fast
CN104391787A (en) * 2014-11-13 2015-03-04 华为软件技术有限公司 Monitoring method aiming at target method as well as thermal cutting-in method and device
CN104572448A (en) * 2014-12-23 2015-04-29 大唐移动通信设备有限公司 Method and device for realizing use condition of thread stack
BR102015030217A2 (en) * 2015-12-02 2017-06-06 Fund Cpqd - Centro De Pesquisa E Desenvolvimento Em Telecomunicações method for monitoring independent processes allocated in database access from a java virtual machine
CN107085548A (en) * 2016-02-16 2017-08-22 阿里巴巴集团控股有限公司 A kind of method, device and electronic equipment for monitoring application program internal memory

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111813465A (en) * 2020-06-19 2020-10-23 北京字节跳动网络技术有限公司 Information acquisition method, device, medium and equipment
CN111813465B (en) * 2020-06-19 2023-11-21 北京字节跳动网络技术有限公司 Information acquisition method, device, medium and equipment

Also Published As

Publication number Publication date
CN110727480B (en) 2023-04-07

Similar Documents

Publication Publication Date Title
CN110764941B (en) Method, device, medium and equipment for acquiring call stack frame instruction offset
CN110489179B (en) Method, device, medium and equipment for acquiring call stack frame function signature
CN110489165B (en) Method, device, medium and equipment for acquiring call stack frame instruction offset
CN110489101B (en) Interface simulation method, system, medium and electronic equipment
US9262132B1 (en) Incremental local source code analysis
CN110865898B (en) Method, device, medium and equipment for converging crash call stack
CN111813641B (en) Method, device, medium and equipment for collecting crash information
CN111240684B (en) Cutting method and device of JS codes, medium and electronic equipment
CN111740948B (en) Data packet issuing method, dynamic updating method, device, equipment and medium
CN103885814A (en) Simulator device and method for operating ARM APKs on x86 framework
CN108089870B (en) Method and apparatus for repairing applications
CN111813465B (en) Information acquisition method, device, medium and equipment
CN110489159A (en) Installation kit compressing method and data analysis method, device, medium and equipment
CN110659210A (en) Information acquisition method and device, electronic equipment and storage medium
CN110727480B (en) Method, device, medium and equipment for acquiring call stack frame instruction offset
CN105786568A (en) Upgrade content display method and device and intelligent terminal
CN110941549B (en) Memory leak detection method, device, medium and electronic equipment
CN111435328B (en) Application testing method and device, electronic equipment and readable storage medium
CN110489164B (en) Acquisition method, device, medium and equipment of hidden assertion information
CN110889116A (en) Advertisement blocking method and device and electronic equipment
CN113377365B (en) Code display method, apparatus, device, computer readable storage medium and product
CN110908860B (en) Java thread acquisition method and device, medium and electronic equipment
CN111258797B (en) Memory leak detection method, device, medium and electronic equipment
CN117251355A (en) Performance test method, device, equipment, computer readable storage medium and product
CN115080113A (en) Item code detection method and device, readable storage medium and electronic equipment

Legal Events

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