<div dir="ltr">This patch adds a call to alarm(30) around each call to PrettyStackTraceEntry::print(). I add a new llvm::sys::Watchdog class which takes a number of seconds after which to time out. The implementation is best-effort (the watchdog falls back to doing nothing if we lack an implementation), and is only implemented on Unix with unistd.h. Please review!<div>

<br></div><div>The motivation is a hang-on-crash in clang because clang called into malloc in its pretty stack printer after a crash that occurred inside free. With crashes that time out, the output looks like this:<div>
<br>
</div><div><div>0  clang           0x0000000002fa513e llvm::sys::PrintStackTrace(_IO_FILE*) + 38<br></div><div>1  clang           0x0000000002fa53c5</div><div>2  clang           0x0000000002fa4e14</div><div>3  libpthread.so.0 0x00007f949a699cb0</div>

<div>4  clang           0x0000000001fff407</div><div>5  clang           0x0000000001ffc1f7 clang::PragmaNamespace::HandlePragma(clang::Preprocessor&, clang::PragmaIntroducerKind, clang::Token&) + 233</div><div>6  clang           0x0000000001ffc1f7 clang::PragmaNamespace::HandlePragma(clang::Preprocessor&, clang::PragmaIntroducerKind, clang::Token&) + 233</div>

<div>7  clang           0x0000000001ffc276 clang::Preprocessor::HandlePragmaDirective(unsigned int) + 124</div><div>8  clang           0x0000000001fe3105 clang::Preprocessor::HandleDirective(clang::Token&) + 1315</div>

<div>9  clang           0x0000000001fc531c clang::Lexer::LexTokenInternal(clang::Token&) + 8850</div><div>10 clang           0x0000000000d6a376</div></div><div><div>11 clang           0x0000000000d6a4f5</div><div>12 clang           0x0000000001fc3294 clang::Lexer::LexTokenInternal(clang::Token&) + 522</div>

<div>13 clang           0x0000000000d6a376</div><div>14 clang           0x0000000000d6a4f5</div><div>15 clang           0x000000000117adb1</div><div>16 clang           0x0000000001173c89 clang::Parser::Initialize() + 2299</div>

<div>17 clang           0x00000000011707be clang::ParseAST(clang::Sema&, bool, bool) + 290</div><div>18 clang           0x0000000000d66da8 clang::ASTFrontendAction::ExecuteAction() + 298</div><div>19 clang           0x0000000000f95694 clang::CodeGenAction::ExecuteAction() + 1414</div>

<div>20 clang           0x0000000000d6692a clang::FrontendAction::Execute() + 200</div><div>21 clang           0x0000000000d3b6dc clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 722</div><div>22 clang           0x0000000000d0b610 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1018</div>

<div>23 clang           0x0000000000cfb487 cc1_main(char const**, char const**, char const*, void*) + 722</div></div><div><div>24 clang           0x0000000000d05beb main + 496</div><div>25 libc.so.6       0x00007f94998d676d __libc_start_main + 237</div>

<div>26 clang           0x0000000000cfab79</div><div>Stack dump:</div><div>0.      Program arguments: /usr/local/google/home/nlewycky/llvm/Debug+Asserts/bin/clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj [... lots more ...] -o /tmp/--9Lb3sl.o -x c++ - </div>

</div><div><div>1.      clang: error: unable to execute command: Alarm clock</div><div>clang: error: clang frontend command failed due to signal (use -v to see invocation)</div><div>clang version 3.3 (trunk 177917) (llvm/trunk 177901)</div>

<div>Target: x86_64-unknown-linux-gnu</div><div>Thread model: posix</div><div>clang: note: diagnostic msg: PLEASE submit a bug report to <a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source, and associated run script.</div>

</div><div><br></div><div style>Nick</div><div style><br></div></div></div>