CCTLib
Calling-context and data-object attribution library for Intel Pin
cct_shape_check.cpp File Reference
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <iostream>
#include <unistd.h>
#include "pin.H"
#include "cctlib.H"
+ Include dependency graph for cct_shape_check.cpp:

Go to the source code of this file.

Classes

struct  TData
 
struct  CctInventory
 
struct  AssertionRecorder
 

Typedefs

using FnChain = vector< string >
 
using CheckFn = void(*)(const CctInventory &, AssertionRecorder &)
 

Functions

static KNOB< string > KnobCheck (KNOB_MODE_WRITEONCE, "pintool", "check", "", "name of the per-victim CCT-shape check function to run at Fini (required)")
 
static TDataGetTls (THREADID t)
 
static VOID ThreadStart (THREADID t, CONTEXT *, INT32, VOID *)
 
static VOID ThreadStartRegister (THREADID t, CONTEXT *ctxt, INT32 flags, VOID *v)
 
static VOID RecordCtxt (uint32_t opaqueHandle, THREADID t)
 
static VOID CaptureMainHandle (uint32_t opaqueHandle, THREADID t)
 
static VOID InstrumentInsCallback (INS ins, VOID *, const uint32_t slot)
 
BOOL InterestingInsCallOrRet (INS ins)
 
static VOID OnImgLoad (IMG img, VOID *)
 
static bool isHardSentinelName (const string &n)
 
static bool isSoftSentinelName (const string &n)
 
static bool isSentinelName (const string &n)
 
static bool isRootName (const string &n)
 
static void BuildInventoryFromThread (THREADID t, CctInventory &inv)
 
static void expectMarkerAnchored (AssertionRecorder &r, const CctInventory &inv, const string &fn, const string &parent)
 
static void check_rec_fib_deep (const CctInventory &inv, AssertionRecorder &r)
 
static void check_rec_ackermann (const CctInventory &inv, AssertionRecorder &r)
 
static void check_rec_multi_direct (const CctInventory &inv, AssertionRecorder &r)
 
static void check_rec_indirect_only (const CctInventory &inv, AssertionRecorder &r)
 
static void check_rec_mixed_direct_indirect (const CctInventory &inv, AssertionRecorder &r)
 
static void check_rec_stripped (const CctInventory &inv, AssertionRecorder &r)
 
static void check_rec_exception (const CctInventory &inv, AssertionRecorder &r)
 
static void check_rec_baseline_nonrec (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_deep_unwind (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_ctor_throw (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_catch_and_resume (const CctInventory &inv, AssertionRecorder &r)
 
static void check_sig_longjmp (const CctInventory &inv, AssertionRecorder &r)
 
static void check_sig_sigsegv_recover (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_simple_throw (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_rethrow (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_catchall (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_dtor_cleanup (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_stress_loop (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_polymorphic (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_recurse_trycatch (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_none_tn (const CctInventory &inv, AssertionRecorder &r)
 
static void check_exc_uncaught_tn (const CctInventory &inv, AssertionRecorder &r)
 
static void RunChecksAndExit (const string &check)
 
static VOID ThreadFini (THREADID t, const CONTEXT *, INT32, VOID *)
 
static void FiniFunc (INT32 code, VOID *v)
 
static INT32 Usage ()
 
int main (int argc, char *argv[])
 

Variables

static TLS_KEY g_tlsKey
 
static PIN_LOCK g_lock
 
static vector< THREADID > g_threads
 
static ADDRINT g_mainLo = 0
 
static ADDRINT g_mainHi = 0
 
static const set< string > kThrowMachineryFns
 
static const map< string, CheckFnkChecks
 
static bool g_checkRan = false
 
static FILE * gTraceFile
 

Typedef Documentation

◆ CheckFn

using CheckFn = void (*)(const CctInventory&, AssertionRecorder&)

Definition at line 980 of file cct_shape_check.cpp.

◆ FnChain

using FnChain = vector<string>

Definition at line 163 of file cct_shape_check.cpp.

Function Documentation

◆ BuildInventoryFromThread()

◆ CaptureMainHandle()

static VOID CaptureMainHandle ( uint32_t  opaqueHandle,
THREADID  t 
)
static

Definition at line 112 of file cct_shape_check.cpp.

References PinCCTLib::GetContextHandle(), GetTls(), h(), and TData::mainCtxtHndl.

Referenced by InstrumentInsCallback().

◆ check_exc_catch_and_resume()

static void check_exc_catch_and_resume ( const CctInventory inv,
AssertionRecorder r 
)
static

◆ check_exc_catchall()

◆ check_exc_ctor_throw()

◆ check_exc_deep_unwind()

◆ check_exc_dtor_cleanup()

◆ check_exc_none_tn()

static void check_exc_none_tn ( const CctInventory inv,
AssertionRecorder r 
)
static

◆ check_exc_polymorphic()

◆ check_exc_recurse_trycatch()

◆ check_exc_rethrow()

◆ check_exc_simple_throw()

◆ check_exc_stress_loop()

◆ check_exc_uncaught_tn()

◆ check_rec_ackermann()

◆ check_rec_baseline_nonrec()

static void check_rec_baseline_nonrec ( const CctInventory inv,
AssertionRecorder r 
)
static

◆ check_rec_exception()

◆ check_rec_fib_deep()

◆ check_rec_indirect_only()

◆ check_rec_mixed_direct_indirect()

◆ check_rec_multi_direct()

◆ check_rec_stripped()

static void check_rec_stripped ( const CctInventory inv,
AssertionRecorder r 
)
static

◆ check_sig_longjmp()

◆ check_sig_sigsegv_recover()

◆ expectMarkerAnchored()

◆ FiniFunc()

static void FiniFunc ( INT32  code,
VOID *  v 
)
static

Definition at line 1113 of file cct_shape_check.cpp.

References g_checkRan, KnobCheck(), and RunChecksAndExit().

Referenced by main().

◆ GetTls()

static TData* GetTls ( THREADID  t)
inlinestatic

Definition at line 66 of file cct_shape_check.cpp.

References g_tlsKey.

Referenced by BuildInventoryFromThread(), CaptureMainHandle(), RecordCtxt(), and RunChecksAndExit().

◆ InstrumentInsCallback()

static VOID InstrumentInsCallback ( INS  ins,
VOID *  ,
const uint32_t  slot 
)
static

Definition at line 122 of file cct_shape_check.cpp.

References CaptureMainHandle(), g_mainHi, g_mainLo, and RecordCtxt().

Referenced by main().

◆ InterestingInsCallOrRet()

BOOL InterestingInsCallOrRet ( INS  ins)
inline

Definition at line 145 of file cct_shape_check.cpp.

Referenced by main().

◆ isHardSentinelName()

static bool isHardSentinelName ( const string &  n)
static

Definition at line 342 of file cct_shape_check.cpp.

Referenced by BuildInventoryFromThread(), and isSentinelName().

◆ isRootName()

static bool isRootName ( const string &  n)
static

Definition at line 359 of file cct_shape_check.cpp.

Referenced by BuildInventoryFromThread().

◆ isSentinelName()

static bool isSentinelName ( const string &  n)
static

Definition at line 355 of file cct_shape_check.cpp.

References isHardSentinelName(), and isSoftSentinelName().

◆ isSoftSentinelName()

static bool isSoftSentinelName ( const string &  n)
static

Definition at line 349 of file cct_shape_check.cpp.

Referenced by BuildInventoryFromThread(), and isSentinelName().

◆ KnobCheck()

static KNOB<string> KnobCheck ( KNOB_MODE_WRITEONCE  ,
"pintool"  ,
"check"  ,
""  ,
"name of the per-victim CCT-shape check function to run at Fini (required)"   
)
static

Referenced by FiniFunc(), and ThreadFini().

◆ main()

◆ OnImgLoad()

static VOID OnImgLoad ( IMG  img,
VOID *   
)
static

Definition at line 151 of file cct_shape_check.cpp.

References g_mainHi, and g_mainLo.

Referenced by main().

◆ RecordCtxt()

static VOID RecordCtxt ( uint32_t  opaqueHandle,
THREADID  t 
)
static

Definition at line 100 of file cct_shape_check.cpp.

References PinCCTLib::GetContextHandle(), GetTls(), h(), and TData::hits.

Referenced by InstrumentInsCallback().

◆ RunChecksAndExit()

◆ ThreadFini()

static VOID ThreadFini ( THREADID  t,
const CONTEXT *  ,
INT32  ,
VOID *   
)
static

Definition at line 1031 of file cct_shape_check.cpp.

References g_checkRan, KnobCheck(), and RunChecksAndExit().

Referenced by main().

◆ ThreadStart()

static VOID ThreadStart ( THREADID  t,
CONTEXT *  ,
INT32  ,
VOID *   
)
static

Definition at line 70 of file cct_shape_check.cpp.

References g_tlsKey.

Referenced by ThreadStartRegister().

◆ ThreadStartRegister()

static VOID ThreadStartRegister ( THREADID  t,
CONTEXT *  ctxt,
INT32  flags,
VOID *  v 
)
static

Definition at line 80 of file cct_shape_check.cpp.

References PinCCTLib::flags, g_lock, g_threads, and ThreadStart().

Referenced by main().

◆ Usage()

static INT32 Usage ( )
static

Definition at line 1127 of file cct_shape_check.cpp.

Referenced by main().

Variable Documentation

◆ g_checkRan

bool g_checkRan = false
static

Definition at line 1029 of file cct_shape_check.cpp.

Referenced by FiniFunc(), and ThreadFini().

◆ g_lock

PIN_LOCK g_lock
static

Definition at line 77 of file cct_shape_check.cpp.

Referenced by main(), and ThreadStartRegister().

◆ g_mainHi

ADDRINT g_mainHi = 0
static

Definition at line 96 of file cct_shape_check.cpp.

Referenced by InstrumentInsCallback(), and OnImgLoad().

◆ g_mainLo

ADDRINT g_mainLo = 0
static

Definition at line 96 of file cct_shape_check.cpp.

Referenced by InstrumentInsCallback(), and OnImgLoad().

◆ g_threads

vector<THREADID> g_threads
static

Definition at line 78 of file cct_shape_check.cpp.

Referenced by RunChecksAndExit(), and ThreadStartRegister().

◆ g_tlsKey

TLS_KEY g_tlsKey
static

Definition at line 65 of file cct_shape_check.cpp.

Referenced by GetTls(), main(), and ThreadStart().

◆ gTraceFile

FILE* gTraceFile
static

Definition at line 1132 of file cct_shape_check.cpp.

Referenced by main().

◆ kChecks

const map<string, CheckFn> kChecks
static
Initial value:
= {
{"rec_fib_deep", check_rec_fib_deep},
{"rec_ackermann", check_rec_ackermann},
{"rec_multi_direct", check_rec_multi_direct},
{"rec_indirect_only", check_rec_indirect_only},
{"rec_mixed_direct_indirect", check_rec_mixed_direct_indirect},
{"rec_stripped", check_rec_stripped},
{"rec_exception", check_rec_exception},
{"rec_baseline_nonrec", check_rec_baseline_nonrec},
{"exc_simple_throw", check_exc_simple_throw},
{"exc_deep_unwind", check_exc_deep_unwind},
{"exc_rethrow", check_exc_rethrow},
{"exc_catchall", check_exc_catchall},
{"exc_dtor_cleanup", check_exc_dtor_cleanup},
{"exc_stress_loop", check_exc_stress_loop},
{"exc_polymorphic", check_exc_polymorphic},
{"exc_recurse_trycatch", check_exc_recurse_trycatch},
{"exc_none_tn", check_exc_none_tn},
{"exc_uncaught_tn", check_exc_uncaught_tn},
{"exc_ctor_throw", check_exc_ctor_throw},
{"exc_catch_and_resume", check_exc_catch_and_resume},
{"sig_longjmp", check_sig_longjmp},
{"sig_sigsegv_recover", check_sig_sigsegv_recover},
}
static void check_exc_deep_unwind(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_none_tn(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_ctor_throw(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_dtor_cleanup(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_fib_deep(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_stress_loop(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_baseline_nonrec(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_catch_and_resume(const CctInventory &inv, AssertionRecorder &r)
static void check_sig_sigsegv_recover(const CctInventory &inv, AssertionRecorder &r)
static void check_sig_longjmp(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_ackermann(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_uncaught_tn(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_polymorphic(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_exception(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_simple_throw(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_recurse_trycatch(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_indirect_only(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_multi_direct(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_rethrow(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_stripped(const CctInventory &inv, AssertionRecorder &r)
static void check_exc_catchall(const CctInventory &inv, AssertionRecorder &r)
static void check_rec_mixed_direct_indirect(const CctInventory &inv, AssertionRecorder &r)

Definition at line 981 of file cct_shape_check.cpp.

Referenced by RunChecksAndExit().

◆ kThrowMachineryFns

const set<string> kThrowMachineryFns
static
Initial value:
= {
"__cxa_throw",
"__cxa_rethrow",
"__cxa_allocate_exception",
"__cxa_begin_catch",
"__cxa_end_catch",
"__gxx_personality_v0",
"_Unwind_RaiseException",
"_Unwind_Resume",
"_Unwind_Resume_or_Rethrow",
"_Unwind_ForcedUnwind",
"_Unwind_Backtrace",
"_Unwind_Find_FDE",
"_Unwind_GetIP",
"_Unwind_GetTextRelBase",
"_Unwind_GetCFA",
"__longjmp",
}

Definition at line 516 of file cct_shape_check.cpp.

Referenced by expectMarkerAnchored().