Skip to content

Commit

Permalink
Merge pull request #28 from manuels/any_interpreter
Browse files Browse the repository at this point in the history
Make trace.bt support any path to the python interpreter
  • Loading branch information
avilum authored Nov 25, 2023
2 parents d41a22c + c956bba commit 7bcb5ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions secimport/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def trace(
f"{entrypoint_cmd}",
"-o",
f"{trace_log_file}",
f"{python_interpreter}",
]
colored_print(COLORS.HEADER, "\nTracing using ", cmd)
colored_print(
Expand All @@ -242,12 +243,16 @@ def trace_pid(
trace_log_file (str): The output file to write the trace into.
"""
assert isinstance(pid, int), f"pid must be an int, got: {pid}"

python_interpreter = (Path('/proc') / str(pid) / 'exe').resolve()

cmd = [
str(SECIMPORT_ROOT) + "/profiles/trace.bt",
"-p",
f"{pid}",
"-o",
f"{trace_log_file}",
f"{python_interpreter}"
]
colored_print(COLORS.HEADER, "\nTRACING PID:")
colored_print(COLORS.OKBLUE, pid)
Expand Down
6 changes: 3 additions & 3 deletions secimport/profiles/trace.bt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// It can be attached to a running process using -p or can be used to trace a python shell interactively.
//
// Usage:
// ./trace.bt -c Python-3.10.0/python
// ./trace.bt Python-3.10.0/python -c Python-3.10.0/python

BEGIN {
// Mapping all syscalls both ways, based on https://github.com/iovisor/bpftrace/blob/2c7a7a598dbe1aa790db2dfe2db242aa69137d5b/tools/syscount.bt
Expand Down Expand Up @@ -688,7 +688,7 @@ BEGIN {
printf("Tracing Modules - Exit gracefully with Ctrl+D\n")
}

usdt:/workspace/Python-3.10.0/python:function__entry {
usdt:$1:function__entry {
@["depth"]++;
@entrypoints[str(arg0)] = @["depth"];
@globals["previous_module"] = @globals["current_module"];
Expand All @@ -698,7 +698,7 @@ usdt:/workspace/Python-3.10.0/python:function__entry {
// printf("%s, %s, depth=%d\n", str(arg0), str(arg1), @["depth"]) ;
}

usdt:/workspace/Python-3.10.0/python:function__return {
usdt:$1:function__return {
@["depth"]--;
}

Expand Down

0 comments on commit 7bcb5ba

Please sign in to comment.