CCTLib
Calling-context and data-object attribution library for Intel Pin
cctlib_reader.cpp
Go to the documentation of this file.
1 // @COPYRIGHT@
2 // Licensed under MIT license.
3 // See LICENSE.TXT file in the project root for more information.
4 // ==============================================================
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdint.h>
9 #include <iostream>
10 #include <unistd.h>
11 #include <assert.h>
12 #include <string.h>
13 #include <sstream>
14 #include "pin.H"
15 #include "cctlib.H"
16 using namespace std;
17 using namespace PinCCTLib;
18 
19 static INT32 Usage() {
20  PIN_ERROR("DeadSPy is a PinTool which tracks each memory access and reports dead writes.\n" + KNOB_BASE::StringKnobSummary() + "\n");
21  return -1;
22 }
23 
24 
25 // Main for DeadSpy, initialize the tool, register instrumentation functions and call the target program.
26 FILE* gTraceFile;
27 
28 
29 // Initialized the needed data structures before launching the target program
30 void ClientInit(int argc, char* argv[]) {
31  // Create output file
32  char name[MAX_FILE_PATH] = "client.out.";
33  char* envPath = getenv("CCTLIB_CLIENT_OUTPUT_FILE");
34 
35  if (envPath) {
36  // assumes max of MAX_FILE_PATH
37  snprintf(name, sizeof(name), "%s", envPath);
38  }
39 
40  gethostname(name + strlen(name), MAX_FILE_PATH - strlen(name));
41  pid_t pid = getpid();
42  sprintf(name + strlen(name), "%d", pid);
43  cerr << "\n Creating log file at:" << name << "\n";
44  gTraceFile = fopen(name, "w");
45  // print the arguments passed
46  fprintf(gTraceFile, "\n");
47 
48  for (int i = 0; i < argc; i++) {
49  fprintf(gTraceFile, "%s ", argv[i]);
50  }
51 
52  fprintf(gTraceFile, "\n");
53 }
54 
55 int main(int argc, char* argv[]) {
56  // Initialize PIN
57  if (PIN_Init(argc, argv))
58  return Usage();
59 
60  // Initialize Symbols, we need them to report functions and lines
61  PIN_InitSymbols();
62  // Init Client
63  ClientInit(argc, argv);
64  // Init CCTLib postmortem analysis
65  PinCCTLibInitForPostmortemAnalysis(gTraceFile, "DeadSpy-CCTLib-database");
66 #if 0
67  vector<Context> contextVec;
68  // Gather full human-readable calling context for a reasonably expected value of context handle.
69  ContextHandle_t ctxtHndl = 1234; // some reasonably OK handle number
70  GetFullCallingContext(ctxtHndl, contextVec);
71  // Print to the log file full human-readable calling context.
72  PrintFullCallingContext(ctxtHndl);
73 #endif
74  return 0;
75 }
#define MAX_FILE_PATH
Definition: cctlib.H:18
int main(int argc, char *argv[])
FILE * gTraceFile
static INT32 Usage()
void ClientInit(int argc, char *argv[])
VOID PrintFullCallingContext(const ContextHandle_t ctxtHandle)
Definition: cctlib.cpp:2346
int PinCCTLibInitForPostmortemAnalysis(FILE *logFile, const std::string &serializedFilesDirectory)
Definition: cctlib.cpp:3183
VOID GetFullCallingContext(const ContextHandle_t curCtxtHndle, std::vector< Context > &contextVec)
Definition: cctlib.cpp:2339
uint32_t ContextHandle_t
Definition: cctlib.H:22