summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common
diff options
context:
space:
mode:
authorMaxim Ostapenko <m.ostapenko@partner.samsung.com>2016-01-18 07:55:12 +0000
committerMaxim Ostapenko <m.ostapenko@partner.samsung.com>2016-01-18 07:55:12 +0000
commit67eec7c3fff10537b005a4dcaa16f644554f7c93 (patch)
tree5295d2d8241e70bbc56a7226c7d6d52d07a1b0d5 /lib/sanitizer_common
parent3bac9e421b77b1e40939362a35d0023379729a7c (diff)
downloadcompiler-rt-67eec7c3fff10537b005a4dcaa16f644554f7c93.tar.gz
[asan] Optionally print reproducer cmdline in ASan reports.
Differential Revision: http://reviews.llvm.org/D16070 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@258037 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r--lib/sanitizer_common/sanitizer_common.cc9
-rw-r--r--lib/sanitizer_common/sanitizer_common.h2
-rw-r--r--lib/sanitizer_common/sanitizer_flags.inc2
-rw-r--r--lib/sanitizer_common/sanitizer_linux.cc8
-rw-r--r--lib/sanitizer_common/sanitizer_mac.cc4
-rw-r--r--lib/sanitizer_common/sanitizer_win.cc5
6 files changed, 29 insertions, 1 deletions
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc
index 2cc826f38..3f2a6f4b2 100644
--- a/lib/sanitizer_common/sanitizer_common.cc
+++ b/lib/sanitizer_common/sanitizer_common.cc
@@ -487,6 +487,15 @@ uptr ReadBinaryNameCached(/*out*/char *buf, uptr buf_len) {
return name_len;
}
+void PrintCmdline() {
+ char **argv = GetArgv();
+ if (!argv) return;
+ Printf("\nCommand: ");
+ for (uptr i = 0; argv[i]; ++i)
+ Printf("%s ", argv[i]);
+ Printf("\n\n");
+}
+
} // namespace __sanitizer
using namespace __sanitizer; // NOLINT
diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h
index e3ce86040..97f5cada7 100644
--- a/lib/sanitizer_common/sanitizer_common.h
+++ b/lib/sanitizer_common/sanitizer_common.h
@@ -282,6 +282,8 @@ bool IsAbsolutePath(const char *path);
u32 GetUid();
void ReExec();
+char **GetArgv();
+void PrintCmdline();
bool StackSizeIsUnlimited();
void SetStackSizeLimitInBytes(uptr limit);
bool AddressSpaceIsUnlimited();
diff --git a/lib/sanitizer_common/sanitizer_flags.inc b/lib/sanitizer_common/sanitizer_flags.inc
index c28f7f4a6..f9726fe5c 100644
--- a/lib/sanitizer_common/sanitizer_flags.inc
+++ b/lib/sanitizer_common/sanitizer_flags.inc
@@ -200,3 +200,5 @@ COMMON_FLAG(
COMMON_FLAG(bool, suppress_equal_pcs, true,
"Deduplicate multiple reports for single source location in "
"halt_on_error=false mode (asan only).")
+COMMON_FLAG(bool, print_cmdline, false, "Print command line on crash "
+ "(asan only).")
diff --git a/lib/sanitizer_common/sanitizer_linux.cc b/lib/sanitizer_common/sanitizer_linux.cc
index cba38c8c3..69d8d7126 100644
--- a/lib/sanitizer_common/sanitizer_linux.cc
+++ b/lib/sanitizer_common/sanitizer_linux.cc
@@ -424,7 +424,7 @@ static void ReadNullSepFileToArray(const char *path, char ***arr,
}
#endif
-static void GetArgsAndEnv(char*** argv, char*** envp) {
+static void GetArgsAndEnv(char ***argv, char ***envp) {
#if !SANITIZER_GO
if (&__libc_stack_end) {
#endif
@@ -441,6 +441,12 @@ static void GetArgsAndEnv(char*** argv, char*** envp) {
#endif
}
+char **GetArgv() {
+ char **argv, **envp;
+ GetArgsAndEnv(&argv, &envp);
+ return argv;
+}
+
void ReExec() {
char **argv, **envp;
GetArgsAndEnv(&argv, &envp);
diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc
index 715509d30..5d81eaeb1 100644
--- a/lib/sanitizer_common/sanitizer_mac.cc
+++ b/lib/sanitizer_common/sanitizer_mac.cc
@@ -666,6 +666,10 @@ void MaybeReexec() {
LeakyResetEnv(kDyldInsertLibraries, new_env);
}
+char **GetArgv() {
+ return *_NSGetArgv();
+}
+
} // namespace __sanitizer
#endif // SANITIZER_MAC
diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc
index f241fec0e..0c1ee81ac 100644
--- a/lib/sanitizer_common/sanitizer_win.cc
+++ b/lib/sanitizer_common/sanitizer_win.cc
@@ -770,6 +770,11 @@ void MaybeReexec() {
// No need to re-exec on Windows.
}
+char **GetArgv() {
+ // FIXME: Actually implement this function.
+ return 0;
+}
+
} // namespace __sanitizer
#endif // _WIN32