Reland D23318594 and D23318592 add recordbasenativesp instr
[hiphop-php.git] / hphp / runtime / vm / srckey.cpp
blob86972915f98431b3004982cc57c589e78c57fcae
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/vm/srckey.h"
19 #include <folly/Format.h>
21 #include "hphp/runtime/vm/hhbc.h"
23 namespace HPHP {
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(),
51 sk.funcID(),
52 sk.offset(),
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());
65 va_list a;
66 va_start(a, fmt);
67 Trace::vtrace(fmt, a);
68 va_end(a);
71 std::string SrcKey::getSymbol() const {
72 const Func* f = func();
73 const Unit* u = unit();
75 if (f->isBuiltin()) {
76 return f->fullName()->data();
79 if (f->isMethod() && !f->cls()) {
80 return folly::format(
81 "{}::{}::line-{}",
82 f->preClass()->name(),
83 f->name(),
84 u->getLineNumber(offset())
85 ).str();
88 // methods with a cls() and functions
89 return folly::format(
90 "{}::line-{}",
91 f->fullName(),
92 u->getLineNumber(offset())
93 ).str();