22#include " pin.H"
33#include < iostream>
44#include < fstream>
5+ #include < sstream>
56#include < unistd.h> // For getpid()
67#include " FuncTracer.hpp"
78
9+ using namespace std ;
10+
811// Global set and mutex to track logged functions
9- static std:: set<std:: string> logged_functions;
10- static std:: mutex log_mutex;
12+ static set<string> logged_functions;
13+ static mutex log_mutex;
1114
1215void log_function_call (const char * img_name, const char * func_name)
1316{
14- std:: string log_key;
17+ string log_key;
1518 {
16- std:: lock_guard<std:: mutex> guard (log_mutex);
17- log_key = std:: string (img_name) + " :" + func_name;
19+ lock_guard<mutex> guard (log_mutex);
20+ log_key = string (img_name) + " :" + func_name;
1821 if (logged_functions.contains (log_key))
1922 return ;
2023 logged_functions.insert (log_key);
@@ -25,7 +28,7 @@ void log_function_call(const char* img_name, const char* func_name)
2528 pid = PIN_GetPid ();
2629 PIN_UnlockClient ();
2730
28- std:: ostringstream oss;
31+ ostringstream oss;
2932 oss << " [PID:" << pid << " ] [Image:" << img_name << " ] [Called:" << func_name << " ]\n " ;
3033 LOG (oss.str ());
3134}
@@ -34,7 +37,7 @@ void log_function_call(const char* img_name, const char* func_name)
3437// An image is either an executable or a shared library.
3538VOID image_load (IMG img, VOID *v)
3639{
37- const std:: string &image_name = IMG_Name (img);
40+ const string &image_name = IMG_Name (img);
3841 if (!image_is_relevant (image_name)) // Check if the image is relevant for our analysis
3942 {
4043 LOG (" [Image:" + image_name + " ] is not relevant, skipping...\n " );
@@ -50,13 +53,13 @@ VOID image_load(IMG img, VOID *v)
5053 for (RTN rtn = SEC_RtnHead (sec); RTN_Valid (rtn); rtn = RTN_Next (rtn))
5154 {
5255 RTN_Open (rtn);
53- const std:: string &rtn_name = RTN_Name (rtn);
56+ const string &rtn_name = RTN_Name (rtn);
5457 if (func_is_relevant (rtn_name)) // Check if the function is relevant for our analysis
5558 {
56- std::stringstream ss ;
59+ ostringstream oss ;
5760 // We log the image name and function name so we can see which function is being instrumented.
58- ss << " [Image:" << image_name << " ] [Function:" << RTN_Name (rtn) << " ]\n " ;
59- LOG (ss .str ());
61+ oss << " [Image:" << image_name << " ] [Function:" << RTN_Name (rtn) << " ]\n " ;
62+ LOG (oss .str ());
6063 // For each routine, we insert a call to our analysis function `log_function_call`.
6164 RTN_InsertCall (rtn, IPOINT_BEFORE, (AFUNPTR)log_function_call,
6265 IARG_PTR, image_name.c_str (),
@@ -75,17 +78,16 @@ BOOL follow_child_process(CHILD_PROCESS childProcess, VOID *v)
7578 return TRUE ; // Follow the child
7679}
7780
78- // Pintool entry point
81+ // Pintool (shared library) entry point
7982int main (int argc, char *argv[])
8083{
81-
8284 // Initialize PIN symbols. This is required for routine-level instrumentation.
8385 PIN_InitSymbols ();
8486
8587 // Initialize PIN. This must be the first function called.
8688 if (PIN_Init (argc, argv))
8789 {
88- std:: cerr << " PIN_Init failed" << std:: endl;
90+ cerr << " PIN_Init failed" << endl;
8991 return 1 ;
9092 }
9193 // Register the function to be called for every loaded image.
@@ -96,6 +98,6 @@ int main(int argc, char *argv[])
9698
9799 // Start the program, never returns
98100 PIN_StartProgram ();
99-
101+ assert ( false ); // We should never reach here
100102 return 0 ;
101103}
0 commit comments