2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 return instrToString(reinterpret_cast<const Op
*>(unit()->at(offset())));
29 std::string
show(SrcKey sk
) {
30 auto func
= sk
.func();
31 auto unit
= sk
.unit();
32 const char *filepath
= "*anonFile*";
33 if (unit
->filepath()->data() && unit
->filepath()->size()) {
34 filepath
= unit
->filepath()->data();
36 return folly::format("{}:{} in {}(id 0x{:#x})@{: >6}{}",
37 filepath
, unit
->getLineNumber(sk
.offset()),
38 func
->isPseudoMain() ? "pseudoMain"
39 : func
->fullName()->data(),
40 (uint32_t)sk
.getFuncId(), sk
.offset(),
41 sk
.resumed() ? "r" : "").str();
44 std::string
showShort(SrcKey sk
) {
45 if (!sk
.valid()) return "<invalid SrcKey>";
46 return folly::format("{}(id {:#x})@{}{}",
47 sk
.func()->fullName()->data(), sk
.getFuncId(),
48 sk
.offset(), sk
.resumed() ? "r" : "").str();
51 void sktrace(SrcKey sk
, const char *fmt
, ...) {
52 if (!Trace::enabled
) return;
54 auto inst
= instrToString((Op
*)sk
.unit()->at(sk
.offset()));
55 Trace::trace("%s: %20s ", show(sk
).c_str(), inst
.c_str());
58 Trace::vtrace(fmt
, a
);
62 std::string
SrcKey::getSymbol() const {
63 const Func
* f
= func();
64 const Unit
* u
= unit();
67 return f
->fullName()->data();
70 if (f
->isPseudoMain()) {
72 "{{pseudo-main}}::{}::line-{}",
73 u
->filepath()->data(),
74 u
->getLineNumber(offset())
78 if (f
->isMethod() && !f
->cls()) {
81 f
->preClass()->name()->data(),
83 u
->getLineNumber(offset())
87 // methods with a cls() and functions
90 f
->fullName()->data(),
91 u
->getLineNumber(offset())