#include "base/logging.h"
#include "base/macros.h"
+#include "base/stringprintf.h"
#include "gc/heap.h"
#include "gc/space/image_space.h"
#include "oat_file.h"
// Keep pausing.
printf("Going to sleep\n");
for (;;) {
- pause();
+ sleep(1);
}
}
return false;
}
+
+static void MoreErrorInfo(pid_t pid, bool sig_quit_on_fail) {
+ printf("Secondary pid is %d\n", pid);
+
+ PrintFileToLog(StringPrintf("/proc/%d/maps", pid), ERROR);
+
+ if (sig_quit_on_fail) {
+ int res = kill(pid, SIGQUIT);
+ if (res != 0) {
+ PLOG(ERROR) << "Failed to send signal";
+ }
+ }
+}
#endif
// Currently we have to fall back to our own loader for the boot image when it's compiled PIC
result = CheckStack(bt.get(), full_signatrues ? full_seq : seq);
}
+ constexpr bool kSigQuitOnFail = true;
+ if (!result) {
+ MoreErrorInfo(pid, kSigQuitOnFail);
+ }
+
if (ptrace(PTRACE_DETACH, pid, 0, 0) != 0) {
PLOG(ERROR) << "Detach failed";
}
+ // If we failed to unwind and induced an ANR dump, give the child some time (20s).
+ if (!result && kSigQuitOnFail) {
+ sleep(20);
+ }
+
// Kill the other process once we are done with it.
kill(pid, SIGKILL);
}
// Wait until the forked process had time to run until its sleep phase.
+ BufferedReader lineReader;
try {
InputStreamReader stdout = new InputStreamReader(p.getInputStream(), "UTF-8");
- BufferedReader lineReader = new BufferedReader(stdout);
+ lineReader = new BufferedReader(stdout);
while (!lineReader.readLine().contains("Going to sleep")) {
}
} catch (Exception e) {
if (!unwindOtherProcess(fullSignatures, pid)) {
System.out.println("Unwinding other process failed.");
+
+ // In this case, log all the output.
+ // Note: this is potentially non-terminating code, if the secondary is totally stuck.
+ // We rely on the run-test timeout infrastructure to terminate the primary in
+ // such a case.
+ try {
+ String tmp;
+ System.out.println("Output from the secondary:");
+ while ((tmp = lineReader.readLine()) != null) {
+ System.out.println("Secondary: " + tmp);
+ }
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ try {
+ lineReader.close();
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
}
} finally {
// Kill the forked process if it is not already dead.