-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devel/google-perftools: Add a more reliable way to detect that the pr…
…ocess is run under Valgrind
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
devel/google-perftools/files/patch-src_base_dynamic__annotations.c
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,37 @@ | ||
- add another way to determine if the process is run under valgrind - based on LD_PRELOAD patterns presence | ||
- Submitted: https://github.com/gperftools/gperftools/pull/1316 | ||
|
||
--- src/base/dynamic_annotations.c.orig 2021-02-15 06:44:21 UTC | ||
+++ src/base/dynamic_annotations.c | ||
@@ -43,6 +43,19 @@ | ||
#include "base/dynamic_annotations.h" | ||
#include "getenv_safe.h" // for TCMallocGetenvSafe | ||
|
||
+static int running_on_valgrind_preload = -1; | ||
+void __attribute__ ((constructor)) premain() { | ||
+ char *LD_PRELOAD = getenv("LD_PRELOAD"); | ||
+ running_on_valgrind_preload = LD_PRELOAD != NULL && | ||
+ ( | ||
+ strstr(LD_PRELOAD, "/valgrind/") != NULL | ||
+ || | ||
+ strstr(LD_PRELOAD, "/vgpreload") != NULL | ||
+ ) | ||
+ ? | ||
+ 1 : 0; | ||
+} | ||
+ | ||
static int GetRunningOnValgrind(void) { | ||
#ifdef RUNNING_ON_VALGRIND | ||
if (RUNNING_ON_VALGRIND) return 1; | ||
@@ -51,6 +64,11 @@ static int GetRunningOnValgrind(void) { | ||
if (running_on_valgrind_str) { | ||
return strcmp(running_on_valgrind_str, "0") != 0; | ||
} | ||
+ | ||
+ // use the LD_PRELOAD trick from https://stackoverflow.com/questions/365458/how-can-i-detect-if-a-program-is-running-from-within-valgrind | ||
+ if (running_on_valgrind_preload == 1) | ||
+ return 1; | ||
+ | ||
return 0; | ||
} | ||
|