[PATCH] [ASan] Introduce the dump_instruction_bytes flag to print the faulting instruction upon SIGSEGV

Alexander Potapenko glider at google.com
Thu Sep 4 02:53:15 PDT 2014


> What if instruction pc points to is not in the zero page, but is inaccessible? It would be sad to crash the program while printing ASan error report in this case.
If pc points to inaccessible page, then we're in a SEGV handler caused by this. We can't print anything meaningful besides the stack, and _Unwind_Backtrace() will crash on this pc right away.

================
Comment at: lib/asan/asan_report.cc:162
@@ +161,3 @@
+void MaybeDumpInstructionBytes(uptr pc) {
+  if (!flags()->dump_instruction_bytes)
+    return;
----------------
samsonov wrote:
> You may check that pc < GetPageSizeCached() here.
Done.

================
Comment at: lib/asan/asan_report.cc:656
@@ -632,1 +655,3 @@
       GetCurrentTidOrInvalid());
+  if (pc < GetPageSizeCached()) {
+    Report("Hint: pc points to the zero page.\n");
----------------
samsonov wrote:
> We print pc above... do you really need this?
Many people do not understand that this is just a SEGV handler, so they keep asking whether this crash is a false positive and why ASan doesn't print more info about it.
I'm not insisting on this piece, however.

================
Comment at: lib/asan/asan_rtl.cc:234
@@ +233,3 @@
+
+  ParseFlag(str, &f->dump_instruction_bytes, "dump_instruction_bytes",
+      "If true, dump 16 bytes starting at the instruction that caused SEGV");
----------------
samsonov wrote:
> Wait, where is the default value for this flag?
Done.

================
Comment at: lib/sanitizer_common/sanitizer_posix_libcdep.cc:151
@@ -150,2 +150,3 @@
   sigact.sa_sigaction = (sa_sigaction_t)handler;
-  sigact.sa_flags = SA_SIGINFO;
+  // Do not block the signal from being received in that signal's handler.
+  // Clients are responsible for handling this correctly.
----------------
samsonov wrote:
> Can this go as a separate change?
Done.

http://reviews.llvm.org/D5167






More information about the llvm-commits mailing list