Skip to content

Commit d18a32f

Browse files
authored
Merge pull request #81 from ilmanzo/pin40
Update to PIN 4.0
2 parents 69a76d9 + f734f52 commit d18a32f

File tree

6 files changed

+27
-51
lines changed

6 files changed

+27
-51
lines changed

FuncTracer.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
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

1215
void 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.
3538
VOID 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
7982
int 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
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To build and run this tool, you'll need:
1818
- **x86_64 CPU** (other architectures are not supported)
1919
- `make`
2020
- **Go language compiler**
21-
- `g++` version **14** (Pin is not compatible with version 15)
21+
- `g++` version **15** (or any c++ 2017 )
2222
- **Catch2 v2** library (optional, only for running the C++ test suite)
2323
- A copy is provided in `tests/catch2/catch.hpp`
2424

@@ -50,7 +50,7 @@ Download and build the project:
5050
Before building, export the PIN_ROOT environment variable:
5151

5252
```bash
53-
export PIN_ROOT=../pin-external-3.31-98869-gfa6f126a8-gcc-linux
53+
export PIN_ROOT=../pin-external-4.0-99633-g5ca9893f2-gcc-linux
5454
```
5555

5656
`PIN_ROOT` should point to the root directory where Intel Pin was extracted.
@@ -74,7 +74,7 @@ coverage. Please compile your target programs with:
7474
gcc -g -gdwarf-4 main.c
7575
```
7676

77-
Pin 3.31 supports DWARF4. Debug info is essential for accurate line mapping.
77+
Pin 3+ supports DWARF4. Debug info is essential for accurate line mapping.
7878

7979
## 🧪 Running Unit Tests
8080

build.sh

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
PIN_ARCHIVE="pin-external-3.31-98869-gfa6f126a8-gcc-linux"
4+
PIN_ARCHIVE="pin-external-4.0-99633-g5ca9893f2-gcc-linux"
55
PIN_URL="https://software.intel.com/sites/landingpage/pintool/downloads/${PIN_ARCHIVE}.tar.gz"
6-
REQUIRED_GCC=14
7-
8-
CXX=""
9-
GPP_VERSION=""
10-
11-
if command -v g++-14 &>/dev/null; then
12-
CXX=$(command -v g++-14)
13-
else
14-
if command -v g++ &>/dev/null; then
15-
CXX=$(command -v g++)
16-
GPP_VERSION=$($CXX -dumpversion)
17-
GPP_MAJOR_VERSION=${GPP_VERSION%%.*}
18-
if [[ "$GPP_MAJOR_VERSION" -ne "$REQUIRED_GCC" ]]; then
19-
echo "Error: Found $CXX version $GPP_VERSION; required version is $REQUIRED_GCC.*"
20-
exit 1
21-
fi
22-
else
23-
echo "Error: g++ 14.* not found in PATH."
24-
exit 1
25-
fi
26-
fi
27-
echo "Using $CXX $GPP_VERSION"
286

297
pushd .. > /dev/null
308

@@ -38,12 +16,12 @@ if [[ ! -d "$PIN_ARCHIVE" ]]; then
3816
exit 1
3917
fi
4018

41-
PIN_ROOT=$(realpath `ls -d pin*`)
19+
PIN_ROOT=$(realpath `ls -d $PIN_ARCHIVE`)
4220
export PIN_ROOT
4321
popd > /dev/null
44-
export CXX="$CXX -std=c++20"
4522
make
4623
echo "export PIN_ROOT=\"$PIN_ROOT\"" > env
24+
strip obj-intel64/FuncTracer.so
4725

4826
# Build Go program in cmd folder
4927
if command -v go &>/dev/null; then
@@ -57,9 +35,3 @@ else
5735
fi
5836

5937

60-
61-
# Optional: Build and run the example
62-
# First you have to set PIN_ENV generated in `env`
63-
#
64-
# pushd example && make && popd
65-
# "$PIN_ROOT/pin" -t ./obj-intel64/FuncTracer.so -- example/cov_sample 7 3

cmd/funkoverage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
)
1010

11-
const versionString = "0.4.5"
11+
const versionString = "0.5.0"
1212

1313
// --- CLI ---
1414

cmd/wrapunwrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ timestamp=$(date "+%%Y%%m%%d-%%H%%M%%S")
141141
nano_seconds=$(date "+%%N")
142142
log_file="$LOG_DIR/${binary_name}_${timestamp}_${nano_seconds}.log"
143143
144-
exec "$PIN_ROOT/pin" -t "$PIN_TOOL" -logfile "$log_file" -- "$ORIGINAL_BINARY" "$@"
144+
exec "$PIN_ROOT/pin" -follow_execv -t "$PIN_TOOL" -logfile "$log_file" -- "$ORIGINAL_BINARY" "$@"
145145
`, wrapperIDComment, time.Now().Format(time.RFC3339), movedBinaryPath, PIN_ROOT, pinTool, LOG_DIR, movedBinaryPath)
146146
if err := os.WriteFile(targetBinary, []byte(wrapperScript), 0755); err != nil {
147147
return err

makefile.rules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,6 @@ SANITY_SUBSET := $(TEST_TOOL_ROOTS) $(TEST_ROOTS)
8383

8484
# This section contains the build rules for all binaries that have special build rules.
8585
# See makefile.default.rules for the default build rules.
86+
#
87+
TOOL_CXXFLAGS += -std=c++20
8688

0 commit comments

Comments
 (0)