-
-
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 19, 2023
1 parent
3afd12a
commit c156b30
Showing
8 changed files
with
92 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
BEGIN { | ||
@count = 0; | ||
} | ||
|
||
uprobe:./testprogs/uprobe_fork_loop:uprobeFunction1 { | ||
if (pid == $1) { | ||
// make sure the pid is always what we expect | ||
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,36 @@ | ||
#include <unistd.h> | ||
|
||
int GLOBAL_A = 0x55555555; | ||
int GLOBAL_B = 0x88888888; | ||
int GLOBAL_C = 0x33333333; | ||
char GLOBAL_D = 8; | ||
|
||
int uprobeFunction1(int *n, char c __attribute__((unused))) | ||
{ | ||
return *n; | ||
} | ||
|
||
void spin() | ||
{ | ||
while (1) | ||
{ | ||
int n = 13; | ||
char c = 'x'; | ||
uprobeFunction1(&n, c); | ||
Check warning Code scanning / CodeQL Expression has no effect Warning
This expression has no effect (because
uprobeFunction1 Error loading related location Loading |
||
usleep(500); | ||
} | ||
} | ||
|
||
int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) | ||
{ | ||
if (fork() == 0) | ||
{ | ||
spin(); | ||
} | ||
else | ||
{ | ||
spin(); | ||
} | ||
|
||
return 0; | ||
} |