- Main Page
- Modules
- Classes

- Search for |

# FILTER

## Modules

| FILTER_RTN
| FILTER_LIB
| FILTER_MULTI

## Detailed Description

Filters are used to select static parts of the program to instrument. A user may only want to instrument specific routines or may way to ignore shared libraries.

The example below can be foundin InstLibExamples/filter.cpp

    #include <iomanip>
    #include <iostream>

    #include "pin.H"
    #include "instlib.H"

    using namespace INSTLIB;

    // Contains knobs to filter out things to instrument
    FILTER filter;

    ofstream out("filter.out");

    INT32 Usage()
    {
        cerr <<
            "This pin tool demonstrates use of FILTER to identify instrumentation points\n"
            "\n";

        cerr << KNOB_BASE::StringKnobSummary() << endl;
        return -1;
    }

    VOID Trace(TRACE trace, VOID * val)
    {
        if (!filter.SelectTrace(trace))
            return;

        for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
        {
            for (INS ins = BBL_InsHead(bbl); INS_Valid(ins); ins = INS_Next(ins))
            {
                out << hex << setw(8) << INS_Address(ins) << " ";

                RTN rtn = TRACE_Rtn(trace);
                if (RTN_Valid(rtn))
                {
                    out << IMG_Name(SEC_Img(RTN_Sec(rtn))) << ":" << RTN_Name(rtn) << " " ;
                }

                out << INS_Disassemble(ins) << endl;
            }
        }
    }

    // argc, argv are the entire command line, including pin -t <toolname> -- ...
    int main(int argc, char * argv[])
    {
        if( PIN_Init(argc,argv) )
        {
            return Usage();
        }

        TRACE_AddInstrumentFunction(Trace, 0);

        filter.Activate();

        // Start the program, never returns
        PIN_StartProgram();

        return 0;
    }