Pin++: a Object-Oriented Framework for Writing Pintools ⇤

Pin++: a Object-Oriented Framework for Writing Pintools ⇤

View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by IUPUIScholarWorks Pin++: A Object-oriented Framework for Writing Pintools ⇤ James H. Hill Dennis C. Feiock Department of Computer and Information Science Indiana University-Purdue University Indianapolis Indianapolis, IN USA hilljh, dfeiock @iupui.edu { } Abstract the examples discussed in Pin’s user manual [11] and dis- This paper presents a framework named Pin++. Pin++ is an tributed with Pin are implemented as if it was a traditional C object-oriented framework that uses template metaprogram- program (i.e., C functions, global variables, and no informa- ming to implement Pintools, which are analysis tools for the tion hiding). dynamic binary instrumentation tool named Pin. The goal Unfortunately, current techniques for implementing a of Pin++ is to simplify programming a Pintool and promote Pintool can result in designs that are fragile [12] (i.e., the reuse of its components across different Pintools. Our re- tendency of the software to break in many places every time sults show that Pintools implemented using Pin++ can have it is changed), rigid [12] (i.e., the tendency for software to a 54% reduction in complexity, increase its modularity, and be difficult to change, even in simple ways), and have com- up to 60% reduction in instrumentation overhead. ponents that are hard to reuse due to high cyclomatic com- plexity [13] (i.e., the number of linearly independent paths Keywords Pin, Pintools, template metaprogramming, frame- through a program’s source code) and low modularity [14]. work For example, if several components in a Pintool are depen- dent on one or more global variables, then it is hard to reuse 1. Introduction the component across different Pintools due to this coupling. Pin [1] is a dynamic binary instrumentation (DBI) [2] tool Likewise, changing the global variable’s definition can break for the IA-32 and x86-64 instruction-set architecture. It en- the design in many locations. ables the creation of dynamic program analysis tools called There are also inherent complexities that complicate the Pintools. Pintools have been created to analyze a wide vari- design and implementation of a Pintool. For example, de- ety of concerns within programs, such as program faults [3], velopers have to manually validate that analysis routines are program behavior [3–5], performance profiling [4, 5], and registered with Pin using a parameter list that matches the root-cause analysis [6]. Examples of other DBI tools in- analysis routine’s signature. This is because there is no check clude, but is not limited to: DynamoRIO [7], DynInst [8], in place—at compile time or runtime—to validate this re- Solaris Dynamic Tracing (DTrace) [9], and Valgrind [10]. quirement (see Section 2 for an example). When developers implement a Pintool, they use the C++ Although Pin is widely used today, implementing a Pin- programming language. Although developers use C++, Pin- tool can be a complicated process. Given the capabilities tools interface with Pin using a C-like application program- of C++, such as abstraction, encapsulation, and template ming interface (API). This does not imply developers are metaprogramming, many complexities in a Pintool should forced to implement their Pintools using C, but the current not exist. Most importantly, developers should be capable of design and structure promoted by Pin through its interface implementing Pintools from “components engineered with result in developers creating C-like Pintools. For example, reuse and for reuse in mind instead of reinvention” [15]. To achieve this desire, however, Pin needs a supporting frame- ⇤ This work was sponsored in part by the Australian Defense Science and work that embodies these principles. Technology Organization (DSTO). For these reasons we implemented Pin++, which is an object-oriented framework for implementing Pintools. Pin++ uses software design patterns [16] to promote reuse and reduce the complexity of a Pintool. It also uses template meta-programming [17, 18] to reduce potential development errors and optimize a Pintool’s performance at compile-time. Lastly, Pin++ is engineered to promote reuse of different components in a Pintool; it codifies required functionality so _______________________________________________________________ This is the author's manuscript of the article published in final edited form as: Hill, J. H., & Feiock, D. C. (2014). Pin++: An Object-oriented Framework for Writing Pintools. In Proceedings of the 2014 International Conference on Generative Programming: Concepts and Experiences (pp. 133–141). New York, NY, USA: ACM. http://doi.org/10.1145/2658761.2658777 developers do not have to re-implement such functionality 26 VOID Fini(INT32 code, VOID *v) 27 OutFile.setf(ios::showbase); { for each and every Pintool. 28 O u t F i l e << ”Count ” << icount << endl ; The main contributions of this paper are as follows: 29 O u t F i l e . c l o s e ( ) ; 30 • It highlights accidental and inherent complexities associ- 31 } 32 INT32 Usage ( ) ated with implementing a traditional Pintool; 33 c e r r << ”Counts{ number of dynamic instructions executed” 34 << endl << endl << KNOB BASE : : StringKnobSummary ( ) • It discusses how Pin++ addresses accidental and inherent 35 << endl ; complexities associated with implementing a traditional 36 return 1; 37 − Pintool; 38 } 39 int main ( int argc , char * argv []) • It quantitatively evaluates Pin++’s impact on the com- 40 // Initialize pin { plexity (a design metric), modularity (a design metric), 41 if (PIN Init (argc , argv )) return Usage ( ) ; 42 and instrumentation overhead (a performance metric) of 43 OutFile.open(KnobOutputFile.Value(). c str ()); a Pintool; 44 45 // Register instruments and callbacks • It provides suggestions on what features should be re- 46 I N S AddInstrumentFunction ( Instruction , 0); 47 PIN AddFiniFunction ( Fini , 0); moved from Pin and placed in a supporting framework, 48 such as Pin++. 49 // Start the program, never returns 50 P I N StartProgram (); We validated Pin++ by implementing examples distributed 51 return 0; 52 with Pin using Pin++. Our results show that Pin++ can re- } duce the complexity of a Pintool up to 54%, improve the Listing 1. Pintool that counts the number of instructions modularity of a Pintool, and reduce instrumentation over- executed by a program. head by up to 60%. Each of these improvements, however, is dependent on what features of Pin are used. As shown in this example, there are several complexities Paper organization. The remainder of this paper is or- associated with a traditional Pintool: ganized as follows: Section 2 introduces a simple example to illustrate the challenges associated with writing a Pintool; 1. A Section 3 discusses the design and implementation of Pin++; Hard to see the design and structure of a Pintool. Pintool consists of several key components: a tool, one Section 4 presents results from comparing traditional Pin- or more instruments, and one or more analysis routines. tools against ones implemented using Pin++; Section 5 dis- In Listing 1, the docount function (line 12) is the anal- cusses different design decision’s impact on performance; ysis component; the Instruction function (line 16) Section 6 compares our work to other related works; and is the instrument component; and the remaining func- Section 7 provides concluding remarks. tions comprise the tool component. Although this is a small example, it is hard to see the individual components 2. The Complexities of Implementing a that constitute a Pintool. As the Pintool increases in size Pintool and complexity, it becomes harder to see the design and Listing 1 illustrates an example Pintool from Pin’s user man- structure of a Pintool. This is an accidental complexity ual. It is actually the first example in Pin’s user manual. that can result in Pintools having rotten designs [12] (e.g., fragility and rigidity due to the use of global variables); 1 #include <iostream> 2 #include <fstream> and exhibiting code smells [19] (e.g., the use of global 3 #include ”pin.H” 4 variables, too many parameters, and vertical separation) 5ofstreamOutFile; and antipatterns [20] (e.g., spaghetti code, stovepipe Pin- 6 7 // The running count of instructions is kept here tool, and reinvent the wheel). 8 // make it static to help the compiler optimize docount 2. 9 static UINT64 icount = 0; Hidden constraints between analysis routine defini- 10 tion and its registration with Pin. In Listing 1, the 11 // Function called before every instruction is executed 12 VOID docount ( ) icount++; developer creates an analysis routine (line 12). In or- 13 { } der to register the analysis routine for callback, the de- 14 // Pin calls this function every time a new instruction 15 // is encountered veloper has to first register it with Pin. As shown on 16 VOID Instruction(INS ins , VOID *v) line 17, the analysis routine is registered against each 17 I N S InsertCall (ins , IPOINT BEFORE{ , 18 (AFUNPTR) docount , IARG END ) ; instruction executed by the program under instrumenta- 19 tion. As part of the registration process, the developer 20 } 21 KNOB<string> KnobOutputFile (KNOB MODE WRITEONCE, ” p i n t o o l ” , must remember the type of each parameter in the anal- 22 ”o”,”inscount.out”, ysis routine’s argument list, and specify it when invoking 23 ”specifyoutputfilename”); INS InsertCall 24 . The developer must also end the ar- 25 // This function is called when the application exits gument list specification with IARG END. In this exam- ple, since the docount function has no arguments, there gram under instrumentation. The remainder of this paper are no parameters included with INS InsertCall. will therefore discuss how Pin++ helps address the complex- In some cases, there are analysis routine argument types ities discussed above—improving the design, implementa- that require an extra parameter. In this situation, it is the tion, and performance of a Pintool. developer’s responsibility to remember this requirement.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us