A method and system for improving debug information pertaining to user variables using a compiler. The method may include identifying a statement to be removed from its current position in an internal representation of a program by a compiler as part of the compiler optimization, replacing the statement to be removed with a debug annotation, adding references to the debug annotation in subsequent debug expressions referring to the removed statement, and emitting debug location information for a user variable using the debug annotation.
|
12. A system comprising:
a memory; and
a processing device, operatively coupled to the memory, to:
identify a statement to be removed from a current position in an internal representation of a program by a compiler as part of compiler optimization, the statement comprising an assignment of a computation to an internal representation name;
identify the internal representation name in elements in a debug expression of a debug statement, wherein the debug statement describes a variable bound to an expression that represents the variable's value;
determine whether the internal representation name is not further used and is assigned to a single operand;
in response to determine that the internal representation name is not further used and is assigned to the single operand, substitute the internal representation name with the single operand;
replace the statement to be removed with a compiler-introduced debug annotation, wherein the compiler-introduced debug annotation comprises an artificial variable bound to a value that would have been computed by the removed statement described by an expression of the computation;
add references to the artificial variable in the compiler-introduced debug annotation in the debug expression referring to the internal representation name; and
provide debug location information for a user variable using a declaration of the compiler-introduced debug annotation, wherein the debug location information comprises the user variable and an expression that, using elements of the compiler-introduced debug annotation, describes a location or a value of the user variable.
1. A method comprising:
identifying, by a processing device, a statement to be removed from a current position in an internal representation of a program by a compiler as part of compiler optimization, the statement comprising an assignment of a result of a computation to an internal representation name;
identifying, by the processing device, the internal representation name in elements in a debug expression of a debug statement, wherein the debug statement describes a variable bound to an expression that represents the variable's value;
determining, by the processing device, whether the internal representation name is not further used and is assigned to a single operand;
in response to determining that the internal representation name is not further used and is assigned to the single operand, substituting, by the processing device, the internal representation name with the single operand;
replacing, by the processing device, the statement to be removed with a compiler- introduced debug annotation, wherein the compiler-introduced debug annotation comprises an artificial variable bound to a value that would have been computed by the removed statement described by an expression of the computation;
adding, by the processing device, references to the artificial variable in the compiler-introduced debug annotation in the debug expression referring to the internal representation name; and
providing, by the processing device, debug location information for a user variable using a declaration of the compiler-introduced debug annotation, wherein the debug location information comprises the user variable and an expression that, using elements of the compiler-introduced debug annotation, describes a location or a value of the user variable.
7. A non-transitory computer readable storage medium comprising instruction, which when executed by a processing device, cause the processing device to execute operations comprising:
identify, by the processing device, a statement to be removed from a current position in an internal representation of a program by a compiler as part of compiler optimization, the statement comprising an assignment of a computation to an internal representation name;
identify, by the processing device, the internal representation name in elements in a debug expression of a debug statement, wherein the debug statement describes a variable bound to an expression that represents the variable's value;
determine, by the processing device, whether the internal representation name is not further used and is assigned to a single operand;
in response to the determination that the internal representation name is not further used and is assigned to the single operand, substitute, by the processing device, the internal representation name with the single operand;
replace, by the processing device, the statement to be removed with a compiler-introduced debug annotation, wherein the compiler-introduced debug annotation comprises an artificial variable bound to a value that would have been computed by the removed statement described by an expression of the computation;
add, by the processing device, references to the artificial variable in the compiler-introduced debug annotation in the debug expression referring to the internal representation name; and
provide, by the processing device, debug location information for a user variable using a declaration of the compiler-introduced debug annotation, wherein the debug location information comprises the user variable and expression that, using elements of the compiler-introduced debug annotation, describes a location or a value of the user variable.
2. The method of
3. The method of
4. The method of
prior to replacing the statement to be removed with the compiler-introduced debug annotation, determining whether the use of the compiler-introduced debug annotation is desirable; and
in response to a determination that the use of the compiler-introduced debug annotation is undesirable, performing an inline substitution.
5. The method of
emitting location information for the artificial variable imitating the user variable.
6. The method of
emitting location information for the user variable that references the compiler-introduced debug annotation using a location expression that evaluates a location or a value bound to the compiler-introduced debug annotation.
8. The non-transitory computer readable storage medium of
9. The non-transitory computer readable storage medium of
10. The non-transitory computer readable storage medium of
emitting location information for the artificial variable imitating the user variable.
11. The non-transitory computer readable storage medium of
emitting location information for the user variable that references the compiler-introduced debug annotation using a location expression that evaluates a location or a value bound to the compiler-introduced debug annotation.
13. The system of
14. The system of
15. The system of
provide location information for the artificial variable imitating the user variable.
16. The system of
provide location information for the user variable that references the compiler-introduced debug annotation using a location expression that evaluates a location or a value bound to the compiler-introduced debug annotation.
|
Embodiments of the present invention relate to compilers. Specifically, embodiments of the invention relate to a method and system for improving debug information pertaining to user variables using a compiler.
Compilers can communicate the location of user variables at run time to debuggers, program analysis tools, run-time monitors and the like. However, as compilers gained more and more optimization passes, the lack of infrastructure to retain a correspondence between source-level and run-time constructs has become a serious problem. As a result, a compiler may fail to emit location information for some local user variables or a compiler may emit locations that make it seem like variables hold unexpected values at certain points in the program.
One solution for improving debug information is to annotate the internal representation of a program, held by the compiler, with statements that bound user variables to expressions that represent the variables' location or value.
Referring to
An optimizing compiler realizes that—7 and —5 compute the same value, and —8 and —6 compute the same value, as shown by statements 110. Hence, the compiler discards the duplicate computations as part of the compiler optimization. In addition, the compiler realizes that —9 is assigned to zero (i.e., —6-—6), as shown by statement 112. As a result, all internal names are left unreferenced, except for the uses in debug statements 106.
As all definitions, from —1 to —8, have become unused in the executable code (excluding debug statements), the compiler is supposed to discard them while retaining as much debug information as it can. The result is a set of statements 108. As shown, expression 110 that computes the value for the optimized-away user variable f has grown exponentially, increasing memory consumption and resulting in CPU overhead when emitting debug information.
The present invention is illustrated by way of example, and not by way of limitation, in the figures of the accompanying drawings in which like references indicate similar elements. It should be noted that different references to “an” or “one” embodiment in this disclosure are not necessarily to the same embodiment, and such references mean at least one.
Embodiments of a method and system for improving debug information pertaining to user variables using a compiler are described herein. In one embodiment, a compiler identifies a statement that should be removed from its current position in an internal representation of a program as part of the compiler optimization. This statement may be a statement that should be optimized away (completely removed) or a statement that should be moved about (moved to a different location in the internal representation of the program). The compiler then replaces this statement with a debug annotation (e.g., a debug temporary such as a compiler-introduced identifier), and adds references to the debug annotation in subsequent debug expressions referring to the removed statement. Further, the compiler emits debug location information for a user variable using the debug annotation.
The use of debug annotations such as debug temporaries keeps debug expressions from exploding in size, simplifying bookkeeping of the debug expressions by the compiler. In addition, the use of debug temporaries prevents loss of debug information due to assignments to operands between assignment and bind points, and enables the compiler to easily emit debug information location subroutines, instead of duplicating this location information in location expressions at every use point, or factoring out the common sub-expressions by other means.
In one embodiment, the compiler system 202 includes a debug information compiler subsystem 206 that transforms a program into an internal representation, assigns debug annotations to statements within the internal representation before the statements are removed or moved elsewhere as part of the compiler optimization, and then references these debug annotations in subsequent debug expressions. A debug annotation may be a debug temporary representing a compiler-introduced identifier. The debug information compiler subsystem 206 uses the debug annotations when emitting debug location information for user variables, Debug location information for a user variable may be provided to the debug information consuming system 210 at run time, periodically or in response to a request of the debug information consuming system 210. Debug location information for a user variable may identity the location of the value of the user variable in memory or in a register, or it may include some other information that will allow the debug information consuming system 210 to compute the value of the user variable. The debug information may be provided to the debug information consuming system 210 in the debug with arbitrary record format (DWARF) or any other debug information format,
In some embodiments, statements that should be removed or moved somewhere are replaced with debug temps only if such replacement is desirable in view of several factors. These factors may include, for example, preferences for saving space in debug information, speeding up compilation, simplifying the work to be performed by debugger, etc. In some embodiments, a replacement may be undesirable when inline substitutions such as trivial substitutions (e.g., line 308), substitutions in a single use (e.g., line 310), etc. can be made. A trivial substitution can be illustrated using the following example:
Before preforming significant optimization, the compiler may have the following statements:
When the compiler realizes that —3 is unused, the compiler may decide to remove the definition of —3. The compiler may then realize that the expression assigned to —3 is a single operand (—2), that would not grow debug expressions, and that is stable and accessible at all debug expressions that refer to it. Hence, instead of introducing a debug temp, the compiler may perform a trivial substitution of —3 in the debug statement for c, which can be expressed as follows:
# DEBUG c=>—2
The compiler can then simply remove the assignment of —3, without introducing any debug temp. Another trivial substitution can take place when the compiler realizes that —2 was also unused and that the bound expression —1 is accessible at all debug statements that reference —2. The compiler can then perform the following trivial substitution:
In some embodiments, a replacement may be undesirable when the compiler can avoid the overhead of introducing a debug temp, effectively performing an early inline substitution, when the symbol defined in the statement is referenced in only one location. This is referred as a “substitution in a single use.” The removal of the —3 assignment above can also qualify as a substitution in a single use, but other situations can be qualified as well. A substitution in a single use is a case in which the definition would make debug expressions grow, but since the removed definition is only used once, the growth will be very limited (as opposed to potentially exponential) and most likely profitable (the debug temp would most likely be just overhead). Consider the following example:
—3=—1+—2;
# DEBUG x=>—3
In this example, once the compiler realizes that —3 is not used elsewhere, and that —1 and —2 are accessible at the debug statement, the compiler can substitute it in the single debug use and drop the assignment altogether, without a debug temp:
# DEBUG x=>1+—2
This is more desirable than emitting the following debug temp:
# DEBUG #1=>—1+—2
# DEBUG x=>#1
However, if —3 was referenced in more than one debug expression or more than once in a single debug expression, then the use of a debug temp (as opposed to an inline substitution) would be desirable. One such an example is the following debug expression:
# DEBUG x=>—3*—3
If debug temps are not used, this debug expression will grow as follows:
# DEBUG x=>(—1+—2)*(—1+—2)
If the above operation is performed repeatedly (e.g., similarly for —1 and —2 and other symbols referenced in their definitions), it will exhibit the very excessive growth of debug expressions that embodiments of the invention are directed to avoid.
The internal representation creator 402 transforms a program into an internal representation as discussed above with reference to
The optimizer 404 optimizes the internal representation of the program, identifies statements that are to be removed or moved elsewhere as part of the compiler optimization, and informs the debug temps assignor 406 about these statements. The debug temps assignor 406 replaces these statements with debug temps, and adds references to the debug temps in subsequent debug expressions referring to the removed statements. As discussed above, in some embodiments, the debug temps assignor 406 does not perform a debug temp replacement if the statement to be replaced constitutes a special case (e.g., a trivial substitution case, a a substitution in a single use case, etc.). The resulting optimized representation of the program is stored in a data store 412, which may be a file, a database, a repository, or any other data structure(s) residing on one or more electronic devices, such as main memory, or on one or more mass storage devices, such as magnetic or optical storage based disks, tapes or hard drives.
The debug information emitter 408 provides debug location information for user variables to a debugger or another debug information consumer. The debug location information may identify the location of the value of the user variable in memory or in a register, or it may consist of an expression involving constants, registers and memory locations, that yields the value the variable should hold if it had not been optimized away.
In some embodiments, the debug information emitter 408 substitutes occurrences of debug temps with expressions that evaluate the value bound to the debug temp, if it is computable or available elsewhere. In one embodiment, the debug information emitter 408 emits declarations of artificial variables in debug information, corresponding to the debug temps. Artificial variables may need to be used because debug temps cannot be present in executable code, only in annotations used to generate debug information, and no run-time storage can be generated for debug temps. Indeed, the compiler ought to generate the same executable code, regardless of whether debug temps (or any other debug annotations) are introduced.
The debug information emitter 408 may emit location information for user variables that reference debug temps using the artificial variables to stand for the debug temps in location expressions. The debug information emitter 408 can emit location information for artificial variables as if they were user variables. Further, the debug information emitter 408 may emit location information for user variables that reference debug temps using location expressions that evaluate the location or the value bound to the debug temps. This inline substitution of location expressions may enable simplifications of the expressions, which some embodiments of the invention may perform.
In one embodiments, the debug information emitter 408 decides whether to introduce artificial variables and/or perform inline substitutions of debug temps depending on various factors, such as preferences for saving space in debug information, speeding up compilation, simplifying the work to be performed by a debugger, etc.
Referring to
At block 504, the debug information compiler subsystem determines whether it is desirable to replace the identified statement with a debug temp. The determination may be made using such factors as preferences for saving space in debug information, speeding up compilation, simplifying the work to be performed by debugger, etc.
If the determination is negative, the debug information compiler subsystem performs a conventional inline substitution (block 512) and proceeds to block 510. If the determination is positive, the debug information compiler subsystem replaces the identified statement with a debug temp (block 506), and refers to the debug temp in subsequent debug expressions having references to the removed statement (block 508).
At run time, the debug information compiler subsystem emits debug location information for user variables (block 510). As discussed in more detail above, the debug information compiler subsystem can emit debug location information using corresponding debug temps.
The exemplary computer system 600 includes one or more processing devices 602, a main memory 604 (e.g., read-only memory (ROM), flash memory, dynamic random access memory (DRAM) such as synchronous DRAM (SDRAM) or Rambus DRAM (RDRAM), etc.), a static memory 606 (e.g., flash memory, static random access memory (SRAM), etc.), and a secondary memory 616 (e.g., a data storage device in the form of a drive unit, which may include fixed or removable computer-readable storage medium), which communicate with each other via a bus 608.
Processing devices 602 represent one or more general-purpose processing devices such as a microprocessor, central processing unit, or the like. More particularly, the processing device 602 may be a complex instruction set computing (CISC) microprocessor, reduced instruction set computing (RISC) microprocessor, very long instruction word (VLIW) microprocessor, processor implementing other instruction sets, or processors implementing a combination of instruction sets. Processing device 602 may also be one or more special-purpose processing devices such as an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), a digital signal processor (DSP), network processor, or the like. Processing device 602 is configured to execute instructions for a compiler system 202 for performing the operations and steps discussed herein.
The computer system 600 may further include a network device 622 (e.g., NIC, Ethernet network card, etc.). The computer system 600 also may include a video display unit 610 (e.g., a liquid crystal display (LCD) or a cathode ray tube (CRT)) connected to the computer system through a graphics port and graphics chipset, an alphanumeric input device 612 (e.g., a keyboard), a cursor control device 614 (e.g., a mouse), and a signal generation device 620 (e.g., a speaker).
The secondary memory 616 may include a machine-readable storage medium (or more specifically a computer-readable storage medium) 624 on which is stored one or more sets of instructions for a compiler system 202 embodying any one or more of the methodologies or functions described herein. The instructions for compiler system 202 may also reside, completely or at least partially, within the main memory 604 and/or within the processing device 602 during execution thereof by the computer system 600, the main memory 604 and the processing device 602 also constituting machine-readable storage media. The instructions for an enhanced authentication system 112 may further be transmitted or received over a network 618 via the network device 622.
The computer-readable storage medium 624 may also be used to store the instructions for compiler system 202 persistently. While the computer-readable storage medium 626 is shown in an exemplary embodiment to be a single medium, the term “computer-readable storage medium” should be taken to include a single medium or multiple media (e.g., a centralized or distributed database, and/or associated caches and servers) that store the one or more sets of instructions. The terms “computer-readable storage medium” shall also be taken to include any medium that is capable of storing or encoding a set of instructions for execution by the machine and that cause the machine to perform any one or more of the methodologies of the present invention. The term “computer-readable storage medium” shall accordingly be taken to include, but not be limited to, solid-state memories, and optical and magnetic media.
The components and other features described herein (for example in relation to
In the above description, numerous details are set forth. It will be apparent, however, to one skilled in the art, that the present invention may be practiced without these specific details. In some instances, well-known structures and devices are shown in block diagram form, rather than in detail, in order to avoid obscuring the present invention.
Some portions of the detailed descriptions above are presented in terms of algorithms and symbolic representations of operations on data bits within a computer memory. These algorithmic descriptions and representations are the means used by those skilled in the data processing arts to most effectively convey the substance of their work to others skilled in the art. An algorithm is here, and generally, conceived to be a self-consistent sequence of steps leading to a desired result. The steps are those requiring physical manipulations of physical quantities. Usually, though not necessarily, these quantities take the form of electrical or magnetic signals capable of being stored, transferred, combined, compared and otherwise manipulated. It has proven convenient at times, principally for reasons of common usage, to refer to these signals as bits, values, elements, symbols, characters, terms, numbers or the like.
It should be borne in mind, however, that all of these and similar terms are to be associated with the appropriate physical quantities and are merely convenient labels applied to these quantities. Unless specifically stated otherwise as apparent from the above discussion, it is appreciated that throughout the description, discussions utilizing terms such as “identifying,” “replacing,” “adding,” “responding,” “providing” or the like, refer to the actions and processes of a computer system, or similar electronic computing device that manipulates and transforms data represented as physical (electronic) quantities within the computer system's registers and memories into other data similarly represented as physical quantities within the computer system memories, registers or other such information storage, transmission or display devices.
The present invention also relates to an apparatus for performing the operations herein. This apparatus may be specially constructed for the required purposes or it may comprise a general purpose computer selectively activated or reconfigured by a computer program stored in the computer. Such a computer program may be stored in a computer readable storage medium, such as, but not limited to, any type of disk including floppy disks, optical disks, CD-ROMs and magnetic-optical disks, read-only memories (ROMs), random access memories (RAMs), EPROMs, EEPROMs, magnetic or optical cards, Flash memory devices including universal serial bus (USB) storage devices (e.g., USB key devices) or any type of media suitable for storing electronic instructions, each of which may be coupled to a computer system bus.
The algorithms and displays presented herein are not inherently related to any particular computer or other apparatus. Various general purpose systems may be used with programs in accordance with the teachings herein or it may prove convenient to construct more specialized apparatus to perform the required method steps. The required structure for a variety of these systems will appear from the description below. In addition, the present invention is not described with reference to any particular programming language. It will be appreciated that a variety of programming languages may be used to implement the teachings of the invention as described herein.
A computer-readable storage medium includes any mechanism for storing information in a form readable by a computer. For example, a computer-readable storage medium includes read only memory (“ROM”), random access memory (“RAM”), magnetic disk storage media; optical storage media, flash memory devices or other type of machine-accessible storage media.
Thus, a method and apparatus for improving debug information using a compiler has been described. It is to be understood that the above description is intended to be illustrative and not restrictive. Many other embodiments will be apparent to those of skill in the art upon reading and understanding the above description. The scope of the invention should, therefore, be determined with reference to the appended claims, along with the full scope of equivalents to which such claims are entitled.
MacLeod, Andrew, Oliva, Alexandre
Patent | Priority | Assignee | Title |
Patent | Priority | Assignee | Title |
5754860, | Jul 23 1996 | Hewlett Packard Enterprise Development LP | Method and apparatus for software testing using a differential testing technique to test compilers |
5812854, | Mar 18 1996 | International Business Machines Corporation | Mechanism for integrating user-defined instructions with compiler-generated instructions and for optimizing the integrated instruction stream |
5836014, | Feb 27 1991 | Hewlett Packard Enterprise Development LP | Method of constructing a constant-folding mechanism in a multilanguage optimizing compiler |
5842021, | Jun 16 1995 | SOCIONEXT INC | Optimizer |
5956512, | Jun 05 1992 | HEWLETT-PACKARD DEVELOPMENT COMPANY, L P | Computer program debugging in the presence of compiler synthesized variables |
5999735, | Apr 01 1997 | Intel Corporation | Method for constructing a static single assignment language accommodating complex symbolic memory references |
6002879, | Apr 01 1997 | U S BANK NATIONAL ASSOCIATION, AS COLLATERAL AGENT | Method for performing common subexpression elimination on a rack-N static single assignment language |
6016398, | Apr 01 1997 | U S BANK NATIONAL ASSOCIATION, AS COLLATERAL AGENT | Method for using static single assignment to color out artificial register dependencies |
6072952, | Apr 22 1998 | Hewlett Packard Enterprise Development LP | Method and apparatus for coalescing variables |
6425122, | Apr 24 1997 | INTELLECTUAL VENTURES ASSETS 12 LLC; SK HYNIX INC | Single stepping system and method for tightly coupled processors |
6593940, | Dec 23 1998 | Intel Corporation | Method for finding errors in multithreaded applications |
6708325, | Jun 27 1997 | Intel Corporation | Method for compiling high level programming languages into embedded microprocessor with multiple reconfigurable logic |
6708326, | Nov 10 2000 | GOOGLE LLC | Method, system and program product comprising breakpoint handling mechanism for debugging and/or monitoring a computer instruction sequence |
6721945, | Sep 18 2000 | International Business Machines Corporation | Optimization of calls in programming languages using pointers for passing reference parameters |
6795963, | Nov 12 1999 | International Business Machines Corporation | Method and system for optimizing systems with enhanced debugging information |
6874140, | Jul 31 2000 | Microsoft Technology Licensing, LLC | Debug annotations |
6883162, | Jun 06 2001 | Oracle America, Inc | Annotations for transaction tracing |
6938185, | Jun 25 2002 | Macom Technology Solutions Holdings, Inc | Method and system for adapting a debugger to new targets |
6971091, | Nov 01 2000 | International Business Machines Corporation | System and method for adaptively optimizing program execution by sampling at selected program points |
7493630, | Oct 02 1998 | Microsoft Technology Licensing, LLC | Tools and techniques for instrumenting interfaces of units of a software program |
8312434, | Jul 02 2008 | International Business Machines Corporation | Finding the source statement of the definition of a storage location |
20020038452, | |||
20020188831, | |||
20030004671, | |||
20030070117, | |||
20030126590, | |||
20030204838, | |||
20040040013, | |||
20050183072, | |||
20050240820, | |||
20070006167, | |||
20070143742, | |||
20070226702, | |||
20080263338, | |||
20080270988, | |||
20100005249, | |||
20100050159, | |||
20100138820, | |||
20110231829, | |||
20130019228, | |||
20130290942, |
Executed on | Assignor | Assignee | Conveyance | Frame | Reel | Doc |
Mar 18 2010 | MACLEOD, ANDREW | Red Hat, Inc | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 024110 | /0994 | |
Mar 18 2010 | OLIVA, ALEXANDRE | Red Hat, Inc | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 024110 | /0994 | |
Mar 19 2010 | Red Hat, Inc. | (assignment on the face of the patent) | / |
Date | Maintenance Fee Events |
Apr 30 2019 | M1551: Payment of Maintenance Fee, 4th Year, Large Entity. |
Apr 25 2023 | M1552: Payment of Maintenance Fee, 8th Year, Large Entity. |
Date | Maintenance Schedule |
Nov 03 2018 | 4 years fee payment window open |
May 03 2019 | 6 months grace period start (w surcharge) |
Nov 03 2019 | patent expiry (for year 4) |
Nov 03 2021 | 2 years to revive unintentionally abandoned end. (for year 4) |
Nov 03 2022 | 8 years fee payment window open |
May 03 2023 | 6 months grace period start (w surcharge) |
Nov 03 2023 | patent expiry (for year 8) |
Nov 03 2025 | 2 years to revive unintentionally abandoned end. (for year 8) |
Nov 03 2026 | 12 years fee payment window open |
May 03 2027 | 6 months grace period start (w surcharge) |
Nov 03 2027 | patent expiry (for year 12) |
Nov 03 2029 | 2 years to revive unintentionally abandoned end. (for year 12) |