2 +----------------------------------------------------------------------+
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/vm/srckey.h"
19 #include <folly/Format.h>
21 #include "hphp/runtime/vm/hhbc.h"
25 std::string
SrcKey::showInst() const {
26 if (prologue()) return "Prologue";
27 if (funcEntry()) return "FuncEntry";
28 auto const f
= func();
29 return instrToString(f
->at(offset()), f
);
32 std::string
show(SrcKey sk
) {
33 auto func
= sk
.func();
34 auto unit
= sk
.unit();
35 const char *filepath
= "*anonFile*";
36 if (unit
->origFilepath()->data() && unit
->origFilepath()->size()) {
37 filepath
= unit
->origFilepath()->data();
39 return folly::sformat("{}:{} in {}(id 0x{:#x})@{: >6}{}{}{}{}",
40 filepath
, sk
.lineNumber(),
41 func
->fullName()->data(),
42 sk
.funcID().toInt(), sk
.printableOffset(),
43 resumeModeShortName(sk
.resumeMode()),
44 sk
.hasThis() ? "t" : "",
45 sk
.prologue() ? "p" : "",
46 sk
.funcEntry() ? "e" : "");
49 std::string
showShort(SrcKey sk
) {
50 if (!sk
.valid()) return "<invalid SrcKey>";
51 return folly::sformat(
52 "{}(id {:#x})@{}{}{}{}{}",
53 sk
.func()->fullName(),
56 resumeModeShortName(sk
.resumeMode()),
57 sk
.hasThis() ? "t" : "",
58 sk
.prologue() ? "p" : "",
59 sk
.funcEntry() ? "e" : ""
63 void sktrace(SrcKey sk
, const char *fmt
, ...) {
64 if (!Trace::enabled
) return;
66 auto const inst
= sk
.showInst();
67 Trace::trace("%s: %20s ", show(sk
).c_str(), inst
.c_str());
70 Trace::vtrace(fmt
, a
);
74 std::string
SrcKey::getSymbol() const {
75 const Func
* f
= func();
78 return f
->fullName()->data();
81 if (f
->isMethod() && !f
->cls()) {
84 f
->preClass()->name(),
90 // methods with a cls() and functions