Skip to content

Commit 546e2c7

Browse files
Matheus Marchinijoyeecheung
authored andcommitted
src: fix backtrace for V8 6.7
V8 6.7 unifies SharedFunctionInfo::name and SharedFunctionInfo::scope_info into SharedFunctionInfo::name_or_scope_info. Because of that, the function's name can be inferred either from name_or_scope_info (when it's a string) or from ScopeInfo::FunctionName (when name_or_scope_info is a ScopeInfo). Also, SharedFunctionInfo::GetCode was removed because it wasn't being used anywhere. Ref: https://chromium-review.googlesource.com/964201 Fixes: #180
1 parent df723d5 commit 546e2c7

File tree

6 files changed

+90
-8
lines changed

6 files changed

+90
-8
lines changed

src/llnode.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
128128
result.Printf(" %c frame #%u: 0x%016" PRIx64 " %s\n", star, i, pc,
129129
res.c_str());
130130
continue;
131+
} else {
132+
v8::Error::PrintInDebugMode("%s", err.GetMessage());
131133
}
132134
}
133135

src/llv8-constants.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,14 @@ void JSDate::Load() {
288288

289289

290290
void SharedInfo::Load() {
291+
kNameOrScopeInfoOffset =
292+
LoadConstant("class_SharedFunctionInfo__name_or_scope_info__Object");
291293
kNameOffset = LoadConstant("class_SharedFunctionInfo__raw_name__Object",
292294
"class_SharedFunctionInfo__name__Object");
293295
kInferredNameOffset =
294296
LoadConstant("class_SharedFunctionInfo__inferred_name__String",
295297
"class_SharedFunctionInfo__function_identifier__Object");
296298
kScriptOffset = LoadConstant("class_SharedFunctionInfo__script__Object");
297-
kCodeOffset = LoadConstant("class_SharedFunctionInfo__code__Code");
298299
kStartPositionOffset =
299300
LoadConstant("class_SharedFunctionInfo__start_position_and_type__int",
300301
"class_SharedFunctionInfo__start_position_and_type__SMI");
@@ -323,7 +324,8 @@ void SharedInfo::Load() {
323324
kStartPositionMask = ~((1 << kStartPositionShift) - 1);
324325
}
325326

326-
if (LoadConstant("class_SharedFunctionInfo__compiler_hints__int") == -1)
327+
if (LoadConstant("class_SharedFunctionInfo__compiler_hints__int") == -1 &&
328+
kNameOrScopeInfoOffset == -1)
327329
kEndPositionShift = 1;
328330
else
329331
kEndPositionShift = 0;

src/llv8-constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ class SharedInfo : public Module {
173173
public:
174174
MODULE_DEFAULT_METHODS(SharedInfo);
175175

176+
int64_t kNameOrScopeInfoOffset;
176177
int64_t kNameOffset;
177178
int64_t kInferredNameOffset;
178179
int64_t kScriptOffset;
179-
int64_t kCodeOffset;
180180
int64_t kStartPositionOffset;
181181
int64_t kEndPositionOffset;
182182
int64_t kParameterCountOffset;

src/llv8-inl.h

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ ACCESSOR(JSRegExp, GetSource, js_regexp()->kSourceOffset, String)
222222

223223
ACCESSOR(JSDate, GetValue, js_date()->kValueOffset, Value)
224224

225+
bool String::IsString(LLV8* v8, HeapObject heap_object, Error& err) {
226+
if (!heap_object.Check()) return false;
227+
228+
int64_t type = heap_object.GetType(err);
229+
if (err.Fail()) return false;
230+
231+
return type < v8->types()->kFirstNonstringType;
232+
}
233+
225234
inline int64_t String::Representation(Error& err) {
226235
int64_t type = GetType(err);
227236
if (err.Fail()) return -1;
@@ -242,13 +251,47 @@ ACCESSOR(Script, LineOffset, script()->kLineOffsetOffset, Smi)
242251
ACCESSOR(Script, Source, script()->kSourceOffset, HeapObject)
243252
ACCESSOR(Script, LineEnds, script()->kLineEndsOffset, HeapObject)
244253

245-
ACCESSOR(SharedFunctionInfo, Name, shared_info()->kNameOffset, String)
254+
ACCESSOR(SharedFunctionInfo, name, shared_info()->kNameOffset, String)
246255
ACCESSOR(SharedFunctionInfo, InferredName, shared_info()->kInferredNameOffset,
247256
Value)
248257
ACCESSOR(SharedFunctionInfo, GetScript, shared_info()->kScriptOffset, Script)
249-
ACCESSOR(SharedFunctionInfo, GetCode, shared_info()->kCodeOffset, Code)
250-
ACCESSOR(SharedFunctionInfo, GetScopeInfo, shared_info()->kScopeInfoOffset,
258+
ACCESSOR(SharedFunctionInfo, scope_info, shared_info()->kScopeInfoOffset,
251259
HeapObject)
260+
ACCESSOR(SharedFunctionInfo, name_or_scope_info,
261+
shared_info()->kNameOrScopeInfoOffset, HeapObject)
262+
263+
264+
HeapObject SharedFunctionInfo::GetScopeInfo(Error& err) {
265+
if (v8()->shared_info()->kNameOrScopeInfoOffset == -1) return scope_info(err);
266+
267+
HeapObject maybe_scope_info = name_or_scope_info(err);
268+
if (!String::IsString(v8(), maybe_scope_info, err)) return maybe_scope_info;
269+
270+
err = Error::Failure("Couldn't get ScopeInfo");
271+
return HeapObject();
272+
}
273+
274+
String SharedFunctionInfo::Name(Error& err) {
275+
if (v8()->shared_info()->kNameOrScopeInfoOffset == -1) return name(err);
276+
277+
HeapObject maybe_scope_info = name_or_scope_info(err);
278+
if (err.Fail()) return String();
279+
280+
if (String::IsString(v8(), maybe_scope_info, err))
281+
return String(maybe_scope_info);
282+
283+
if (err.Fail()) return String();
284+
285+
HeapObject maybe_function_name =
286+
ScopeInfo(maybe_scope_info).MaybeFunctionName(err);
287+
if (err.Fail()) return String();
288+
289+
if (String::IsString(v8(), maybe_function_name, err))
290+
return maybe_function_name;
291+
292+
err = Error::Failure("Couldn't get SharedFunctionInfo's name");
293+
return String();
294+
}
252295

253296
inline int64_t Code::Start() { return LeaField(v8()->code()->kStartOffset); }
254297

@@ -518,6 +561,32 @@ inline String ScopeInfo::ContextLocalName(int index, int param_count,
518561
return FixedArray::Get<String>(proper_index, err);
519562
}
520563

564+
inline HeapObject ScopeInfo::MaybeFunctionName(Error& err) {
565+
int proper_index = v8()->scope_info()->kVariablePartIndex +
566+
ParameterCount(err).GetValue() + 1 +
567+
StackLocalCount(err).GetValue() +
568+
(ContextLocalCount(err).GetValue() * 2);
569+
// NOTE(mmarchini): FunctionName can be stored either in the first, second or
570+
// third slot after ContextLocalCount. Since there are missing postmortem
571+
// metadata to determine in which slot its being stored for the present
572+
// ScopeInfo, we try to find it heuristically.
573+
int tries = 3;
574+
while (tries > 0) {
575+
err = Error();
576+
577+
HeapObject maybe_function_name =
578+
FixedArray::Get<HeapObject>(proper_index, err);
579+
if (err.Success() && String::IsString(v8(), maybe_function_name, err))
580+
return maybe_function_name;
581+
582+
tries--;
583+
proper_index++;
584+
}
585+
586+
err = Error::Failure("Couldn't get FunctionName from ScopeInfo");
587+
return HeapObject();
588+
}
589+
521590
inline bool Oddball::IsHoleOrUndefined(Error& err) {
522591
Smi kind = Kind(err);
523592
if (err.Fail()) return false;

src/llv8.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,9 @@ std::string FixedArray::InspectContents(int length, Error& err) {
10931093
std::string Context::Inspect(Error& err) {
10941094
std::string res;
10951095
// Not enough postmortem information, return bare minimum
1096-
if (v8()->shared_info()->kScopeInfoOffset == -1) return res;
1096+
if (v8()->shared_info()->kScopeInfoOffset == -1 &&
1097+
v8()->shared_info()->kNameOrScopeInfoOffset == -1)
1098+
return res;
10971099

10981100
Value previous = Previous(err);
10991101
if (err.Fail()) return std::string();

src/llv8.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class String : public HeapObject {
159159

160160
std::string ToString(Error& err);
161161
std::string Inspect(InspectOptions* options, Error& err);
162+
163+
static inline bool IsString(LLV8* v8, HeapObject heap_object, Error& err);
162164
};
163165

164166
class Script : public HeapObject {
@@ -191,7 +193,6 @@ class SharedFunctionInfo : public HeapObject {
191193
inline String Name(Error& err);
192194
inline Value InferredName(Error& err);
193195
inline Script GetScript(Error& err);
194-
inline Code GetCode(Error& err);
195196
inline HeapObject GetScopeInfo(Error& err);
196197
inline int64_t ParameterCount(Error& err);
197198
inline int64_t StartPosition(Error& err);
@@ -200,6 +201,11 @@ class SharedFunctionInfo : public HeapObject {
200201
std::string ProperName(Error& err);
201202
std::string GetPostfix(Error& err);
202203
std::string ToString(Error& err);
204+
205+
private:
206+
inline String name(Error& err);
207+
inline HeapObject scope_info(Error& err);
208+
inline HeapObject name_or_scope_info(Error& err);
203209
};
204210

205211
class OneByteString : public String {
@@ -412,6 +418,7 @@ class ScopeInfo : public FixedArray {
412418

413419
inline String ContextLocalName(int index, int param_count, int stack_count,
414420
Error& err);
421+
inline HeapObject MaybeFunctionName(Error& err);
415422
};
416423

417424
class Oddball : public HeapObject {

0 commit comments

Comments
 (0)