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 auto const u
= unit();
27 return instrToString(u
->at(offset()), u
);
30 std::string
show(SrcKey sk
) {
31 auto func
= sk
.func();
32 auto unit
= sk
.unit();
33 const char *filepath
= "*anonFile*";
34 if (unit
->filepath()->data() && unit
->filepath()->size()) {
35 filepath
= unit
->filepath()->data();
37 return folly::sformat("{}:{} in {}(id 0x{:#x})@{: >6}{}{}",
38 filepath
, unit
->getLineNumber(sk
.offset()),
39 func
->isPseudoMain() ? "pseudoMain"
40 : func
->fullName()->data(),
41 (uint32_t)sk
.funcID(), sk
.offset(),
42 sk
.resumed() ? "r" : "",
43 sk
.hasThis() ? "t" : "",
44 sk
.prologue() ? "p" : "");
47 std::string
showShort(SrcKey sk
) {
48 if (!sk
.valid()) return "<invalid SrcKey>";
49 return folly::sformat(
50 "{}(id {:#x})@{}{}{}{}",
51 sk
.func()->fullName(),
54 sk
.resumed() ? "r" : "",
55 sk
.hasThis() ? "t" : "",
56 sk
.prologue() ? "p" : ""
60 void sktrace(SrcKey sk
, const char *fmt
, ...) {
61 if (!Trace::enabled
) return;
63 auto const u
= sk
.unit();
64 auto inst
= instrToString(u
->at(sk
.offset()), u
);
65 Trace::trace("%s: %20s ", show(sk
).c_str(), inst
.c_str());
68 Trace::vtrace(fmt
, a
);
72 std::string
SrcKey::getSymbol() const {
73 const Func
* f
= func();
74 const Unit
* u
= unit();
77 return f
->fullName()->data();
80 if (f
->isPseudoMain()) {
82 "{{pseudo-main}}::{}::line-{}",
84 u
->getLineNumber(offset())
88 if (f
->isMethod() && !f
->cls()) {
91 f
->preClass()->name(),
93 u
->getLineNumber(offset())
97 // methods with a cls() and functions
101 u
->getLineNumber(offset())