Add sub-controls for Hack array compat runtime checks
[hiphop-php.git] / hphp / runtime / base / stack-logger.cpp
blob1412b5c7f8255cf277fda50ecea39c4c4ecb65b4
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/stack-logger.h"
19 #ifndef FACEBOOK
21 // folly::symbolizer isn't supported on all the platforms that HHVM is, so we
22 // deliberately exclude it in our CMake setup, which makes this feature FB-only
23 // for now.
25 namespace HPHP {
26 void log_native_stack(const char* msg) {}
29 #else // FACEBOOK
31 #include <folly/experimental/symbolizer/StackTrace.h>
32 #include <folly/experimental/symbolizer/Symbolizer.h>
34 #include "hphp/util/logger.h"
36 namespace HPHP {
38 using namespace folly::symbolizer;
40 void log_native_stack(const char* msg) {
41 constexpr size_t kMaxFrames = 128;
43 uintptr_t addresses[kMaxFrames];
44 auto nframes = getStackTrace(addresses, kMaxFrames);
46 Symbolizer symbolizer;
47 std::vector<SymbolizedFrame> frames(nframes);
48 symbolizer.symbolize(addresses, frames.data(), nframes);
50 StringSymbolizePrinter printer;
51 printer.println(addresses, frames.data(), nframes);
52 Logger::Error("%s\n\nC++ stack:\n%s",
53 msg,
54 printer.str().c_str());
59 #endif // FACEBOOK