-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[uprobe] support for pid targeting for shared libs
This adds support for specifying the pid even when targeting a uprobe/uretprobe in a library shared by multiple pids. Example: ``` sudo bpftrace -p 1899508 -e 'uprobe:libc:getaddrinfo { print((comm, pid)); } ``` [Issue 2817](#2817)
- Loading branch information
Jordan Rome
committed
Nov 25, 2023
1 parent
4151bab
commit c83afea
Showing
9 changed files
with
90 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
BEGIN { | ||
@count = 0; | ||
} | ||
|
||
uprobe:./testprogs/uprobe_fork_loop:uprobeFunction1 { | ||
if (pid == $1) { | ||
// counting 10 instances of the expected pid | ||
// is similar to a delay to ensure we never get | ||
// an unexpected pid | ||
if (@count == 10) { | ||
print("hello"); | ||
exit(); | ||
} else { | ||
@count++; | ||
} | ||
} else { | ||
// pid should always be the first positional param | ||
exit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
int uprobeFunction1(int *n, char c __attribute__((unused))) | ||
{ | ||
return *n; | ||
} | ||
|
||
void spin() | ||
{ | ||
while (1) | ||
{ | ||
int n = 13; | ||
char c = 'x'; | ||
uprobeFunction1(&n, c); | ||
usleep(500); | ||
} | ||
} | ||
|
||
int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) | ||
{ | ||
pid_t p = fork(); | ||
if (p < 0) | ||
{ | ||
perror("fork fail"); | ||
exit(1); | ||
} | ||
spin(); | ||
|
||
return 0; | ||
} |