5 #include "src/source-position.h" 6 #include "src/objects-inl.h" 7 #include "src/optimized-compilation-info.h" 12 std::ostream& operator<<(std::ostream& out,
const SourcePositionInfo& pos) {
14 if (!pos.script.is_null() && pos.script->name()->IsString()) {
15 out << String::cast(pos.script->name())->ToCString(DISALLOW_NULLS).get();
19 out <<
":" << pos.line + 1 <<
":" << pos.column + 1 <<
">";
23 std::ostream& operator<<(std::ostream& out,
24 const std::vector<SourcePositionInfo>& stack) {
26 for (
const SourcePositionInfo& pos : stack) {
27 if (!first) out <<
" inlined at ";
34 std::ostream& operator<<(std::ostream& out,
const SourcePosition& pos) {
35 if (pos.isInlined()) {
36 out <<
"<inlined(" << pos.InliningId() <<
"):";
38 out <<
"<not inlined:";
40 out << pos.ScriptOffset() <<
">";
44 std::vector<SourcePositionInfo> SourcePosition::InliningStack(
45 OptimizedCompilationInfo* cinfo)
const {
46 SourcePosition pos = *
this;
47 std::vector<SourcePositionInfo> stack;
48 while (pos.isInlined()) {
49 const auto& inl = cinfo->inlined_functions()[pos.InliningId()];
50 stack.push_back(SourcePositionInfo(pos, inl.shared_info));
51 pos = inl.position.position;
53 stack.push_back(SourcePositionInfo(pos, cinfo->shared_info()));
57 std::vector<SourcePositionInfo> SourcePosition::InliningStack(
58 Handle<Code> code)
const {
59 Isolate* isolate = code->GetIsolate();
60 Handle<DeoptimizationData> deopt_data(
61 DeoptimizationData::cast(code->deoptimization_data()), isolate);
62 SourcePosition pos = *
this;
63 std::vector<SourcePositionInfo> stack;
64 while (pos.isInlined()) {
65 InliningPosition inl =
66 deopt_data->InliningPositions()->get(pos.InliningId());
67 Handle<SharedFunctionInfo>
function(
68 deopt_data->GetInlinedFunction(inl.inlined_function_id), isolate);
69 stack.push_back(SourcePositionInfo(pos,
function));
72 Handle<SharedFunctionInfo>
function(
73 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo()), isolate);
74 stack.push_back(SourcePositionInfo(pos,
function));
78 void SourcePosition::Print(std::ostream& out,
79 SharedFunctionInfo*
function)
const {
80 Script::PositionInfo pos;
81 Object* source_name =
nullptr;
82 if (function->script()->IsScript()) {
83 Script* script = Script::cast(function->script());
84 source_name = script->name();
85 script->GetPositionInfo(ScriptOffset(), &pos, Script::WITH_OFFSET);
88 if (source_name !=
nullptr && source_name->IsString()) {
89 out << String::cast(source_name)
90 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)
95 out <<
":" << pos.line + 1 <<
":" << pos.column + 1 <<
">";
98 void SourcePosition::PrintJson(std::ostream& out)
const {
99 out <<
"{ \"scriptOffset\" : " << ScriptOffset() <<
", " 100 <<
" \"inliningId\" : " << InliningId() <<
"}";
103 void SourcePosition::Print(std::ostream& out, Code code)
const {
104 DeoptimizationData deopt_data =
105 DeoptimizationData::cast(code->deoptimization_data());
107 SharedFunctionInfo*
function(
108 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo()));
109 Print(out,
function);
111 InliningPosition inl = deopt_data->InliningPositions()->get(InliningId());
112 if (inl.inlined_function_id == -1) {
115 SharedFunctionInfo*
function =
116 deopt_data->GetInlinedFunction(inl.inlined_function_id);
117 Print(out,
function);
119 out <<
" inlined at ";
120 inl.position.Print(out, code);
124 SourcePositionInfo::SourcePositionInfo(SourcePosition pos,
125 Handle<SharedFunctionInfo> f)
127 script(f.is_null() || !f->script()->IsScript()
128 ? Handle<Script>::null()
129 : handle(Script::cast(f->script()), f->GetIsolate())) {
130 if (!script.is_null()) {
131 Script::PositionInfo info;
132 if (Script::GetPositionInfo(script, pos.ScriptOffset(), &info,
133 Script::WITH_OFFSET)) {
135 column = info.column;