Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: base/debug/stack_trace_posix.cc

Issue 2312393002: Debug exit code (Closed)
Patch Set: abort instead of int3 Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/debug/debugger_posix.cc ('k') | base/logging.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/stack_trace.h" 5 #include "base/debug/stack_trace.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // NOTE: This code MUST be async-signal safe. 214 // NOTE: This code MUST be async-signal safe.
215 // NO malloc or stdio is allowed here. 215 // NO malloc or stdio is allowed here.
216 216
217 // Record the fact that we are in the signal handler now, so that the rest 217 // Record the fact that we are in the signal handler now, so that the rest
218 // of StackTrace can behave in an async-signal-safe manner. 218 // of StackTrace can behave in an async-signal-safe manner.
219 in_signal_handler = 1; 219 in_signal_handler = 1;
220 220
221 if (BeingDebugged()) 221 if (BeingDebugged())
222 BreakDebugger(); 222 BreakDebugger();
223 223
224 PrintToStderr("Received signal "); 224 PrintToStderr("Received SSSS signal ");
225 char buf[1024] = { 0 }; 225 char buf[1024] = { 0 };
226 internal::itoa_r(signal, buf, sizeof(buf), 10, 0); 226 internal::itoa_r(signal, buf, sizeof(buf), 10, 0);
227 PrintToStderr(buf); 227 PrintToStderr(buf);
228 PrintToStderr("\n");
228 if (signal == SIGBUS) { 229 if (signal == SIGBUS) {
229 if (info->si_code == BUS_ADRALN) 230 if (info->si_code == BUS_ADRALN)
230 PrintToStderr(" BUS_ADRALN "); 231 PrintToStderr(" BUS_ADRALN ");
231 else if (info->si_code == BUS_ADRERR) 232 else if (info->si_code == BUS_ADRERR)
232 PrintToStderr(" BUS_ADRERR "); 233 PrintToStderr(" BUS_ADRERR ");
233 else if (info->si_code == BUS_OBJERR) 234 else if (info->si_code == BUS_OBJERR)
234 PrintToStderr(" BUS_OBJERR "); 235 PrintToStderr(" BUS_OBJERR ");
235 else 236 else
236 PrintToStderr(" <unknown> "); 237 PrintToStderr(" <unknown> ");
237 } else if (signal == SIGFPE) { 238 } else if (signal == SIGFPE) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 #if defined(CFI_ENFORCEMENT) 290 #if defined(CFI_ENFORCEMENT)
290 if (signal == SIGILL && info->si_code == ILL_ILLOPN) { 291 if (signal == SIGILL && info->si_code == ILL_ILLOPN) {
291 PrintToStderr( 292 PrintToStderr(
292 "CFI: Most likely a control flow integrity violation; for more " 293 "CFI: Most likely a control flow integrity violation; for more "
293 "information see:\n"); 294 "information see:\n");
294 PrintToStderr( 295 PrintToStderr(
295 "https://www.chromium.org/developers/testing/control-flow-integrity\n"); 296 "https://www.chromium.org/developers/testing/control-flow-integrity\n");
296 } 297 }
297 #endif 298 #endif
298 299
300 PrintToStderr("Before stacktrace print\n");
299 debug::StackTrace().Print(); 301 debug::StackTrace().Print();
302 PrintToStderr("After stacktrace print\n");
300 303
301 #if defined(OS_LINUX) 304 #if defined(OS_LINUX)
302 #if ARCH_CPU_X86_FAMILY 305 #if ARCH_CPU_X86_FAMILY
303 ucontext_t* context = reinterpret_cast<ucontext_t*>(void_context); 306 ucontext_t* context = reinterpret_cast<ucontext_t*>(void_context);
304 const struct { 307 const struct {
305 const char* label; 308 const char* label;
306 greg_t value; 309 greg_t value;
307 } registers[] = { 310 } registers[] = {
308 #if ARCH_CPU_32_BITS 311 #if ARCH_CPU_32_BITS
309 { " gs: ", context->uc_mcontext.gregs[REG_GS] }, 312 { " gs: ", context->uc_mcontext.gregs[REG_GS] },
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 if ((i + 1) % 4 == 0) 370 if ((i + 1) % 4 == 0)
368 PrintToStderr("\n"); 371 PrintToStderr("\n");
369 } 372 }
370 PrintToStderr("\n"); 373 PrintToStderr("\n");
371 #endif // ARCH_CPU_X86_FAMILY 374 #endif // ARCH_CPU_X86_FAMILY
372 #endif // defined(OS_LINUX) 375 #endif // defined(OS_LINUX)
373 376
374 PrintToStderr("[end of stack trace]\n"); 377 PrintToStderr("[end of stack trace]\n");
375 378
376 #if defined(OS_MACOSX) && !defined(OS_IOS) 379 #if defined(OS_MACOSX) && !defined(OS_IOS)
377 if (::signal(signal, SIG_DFL) == SIG_ERR) 380 if (::signal(signal, SIG_DFL) == SIG_ERR) {
381 PrintToStderr("::signal(signal, SIG_DFL)\n");
378 _exit(1); 382 _exit(1);
383 }
379 #else 384 #else
380 // Non-Mac OSes should probably reraise the signal as well, but the Linux 385 // Non-Mac OSes should probably reraise the signal as well, but the Linux
381 // sandbox tests break on CrOS devices. 386 // sandbox tests break on CrOS devices.
382 // https://code.google.com/p/chromium/issues/detail?id=551681 387 // https://code.google.com/p/chromium/issues/detail?id=551681
388 PrintToStderr("Before _exit(1)\n");
383 _exit(1); 389 _exit(1);
384 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 390 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
385 } 391 }
386 392
387 class PrintBacktraceOutputHandler : public BacktraceOutputHandler { 393 class PrintBacktraceOutputHandler : public BacktraceOutputHandler {
388 public: 394 public:
389 PrintBacktraceOutputHandler() {} 395 PrintBacktraceOutputHandler() {}
390 396
391 void HandleOutput(const char* output) override { 397 void HandleOutput(const char* output) override {
392 // NOTE: This code MUST be async-signal safe (it's used by in-process 398 // NOTE: This code MUST be async-signal safe (it's used by in-process
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 }; 682 };
677 #endif // USE_SYMBOLIZE 683 #endif // USE_SYMBOLIZE
678 684
679 } // namespace 685 } // namespace
680 686
681 bool EnableInProcessStackDumping() { 687 bool EnableInProcessStackDumping() {
682 #if defined(USE_SYMBOLIZE) 688 #if defined(USE_SYMBOLIZE)
683 SandboxSymbolizeHelper::GetInstance(); 689 SandboxSymbolizeHelper::GetInstance();
684 #endif // USE_SYMBOLIZE 690 #endif // USE_SYMBOLIZE
685 691
692 fprintf(stderr, "EnableInProcessStackDumping\n");
693
686 // When running in an application, our code typically expects SIGPIPE 694 // When running in an application, our code typically expects SIGPIPE
687 // to be ignored. Therefore, when testing that same code, it should run 695 // to be ignored. Therefore, when testing that same code, it should run
688 // with SIGPIPE ignored as well. 696 // with SIGPIPE ignored as well.
689 struct sigaction sigpipe_action; 697 struct sigaction sigpipe_action;
690 memset(&sigpipe_action, 0, sizeof(sigpipe_action)); 698 memset(&sigpipe_action, 0, sizeof(sigpipe_action));
691 sigpipe_action.sa_handler = SIG_IGN; 699 sigpipe_action.sa_handler = SIG_IGN;
692 sigemptyset(&sigpipe_action.sa_mask); 700 sigemptyset(&sigpipe_action.sa_mask);
693 bool success = (sigaction(SIGPIPE, &sigpipe_action, NULL) == 0); 701 bool success = (sigaction(SIGPIPE, &sigpipe_action, NULL) == 0);
694 702
695 // Avoid hangs during backtrace initialization, see above. 703 // Avoid hangs during backtrace initialization, see above.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 *ptr = *start; 813 *ptr = *start;
806 *start++ = ch; 814 *start++ = ch;
807 } 815 }
808 return buf; 816 return buf;
809 } 817 }
810 818
811 } // namespace internal 819 } // namespace internal
812 820
813 } // namespace debug 821 } // namespace debug
814 } // namespace base 822 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/debugger_posix.cc ('k') | base/logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698