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 f
= func();
27 return instrToString(f
->at(offset()), f
);
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
->fullName()->data(),
40 (uint32_t)sk
.funcID(), sk
.offset(),
41 resumeModeShortName(sk
.resumeMode()),
42 sk
.hasThis() ? "t" : "",
43 sk
.prologue() ? "p" : "");
46 std::string
showShort(SrcKey sk
) {
47 if (!sk
.valid()) return "<invalid SrcKey>";
48 return folly::sformat(
49 "{}(id {:#x})@{}{}{}{}",
50 sk
.func()->fullName(),
53 resumeModeShortName(sk
.resumeMode()),
54 sk
.hasThis() ? "t" : "",
55 sk
.prologue() ? "p" : ""
59 void sktrace(SrcKey sk
, const char *fmt
, ...) {
60 if (!Trace::enabled
) return;
62 auto const f
= sk
.func();
63 auto inst
= instrToString(f
->at(sk
.offset()), f
);
64 Trace::trace("%s: %20s ", show(sk
).c_str(), inst
.c_str());
67 Trace::vtrace(fmt
, a
);
71 std::string
SrcKey::getSymbol() const {
72 const Func
* f
= func();
73 const Unit
* u
= unit();
76 return f
->fullName()->data();
79 if (f
->isMethod() && !f
->cls()) {
82 f
->preClass()->name(),
84 u
->getLineNumber(offset())
88 // methods with a cls() and functions
92 u
->getLineNumber(offset())