Skip to content

Commit c231a6b

Browse files
authored
src: fix backtrace with v8 6.4 (#168)
This is the minimum patch to make llnode display stack traces produced by v8 6.4. PR-URL: #168 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent a3b9032 commit c231a6b

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/llv8-constants.cc

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,39 @@ int64_t Module::LoadRawConstant(const char* name, int64_t def) {
9393
Error err;
9494
int64_t v = LookupConstant(target_, name, def, err);
9595
if (err.Fail()) {
96-
Error::PrintInDebugMode("Failed to load raw constant %s", name);
96+
Error::PrintInDebugMode(
97+
"Failed to load raw constant %s, default to %" PRId64, name, def);
9798
}
9899

99100
return v;
100101
}
101102

103+
int64_t Module::LoadConstant(const char* name, Error& err, int64_t def) {
104+
int64_t v =
105+
LookupConstant(target_, (kConstantPrefix + name).c_str(), def, err);
106+
return v;
107+
}
102108

103109
int64_t Module::LoadConstant(const char* name, int64_t def) {
104110
Error err;
105-
int64_t v =
106-
LookupConstant(target_, (kConstantPrefix + name).c_str(), def, err);
111+
int64_t v = LoadConstant(name, err, def);
107112
if (err.Fail()) {
108-
Error::PrintInDebugMode("Failed to load constant %s", name);
113+
Error::PrintInDebugMode("Failed to load constant %s, default to %" PRId64,
114+
name, def);
109115
}
110116

111117
return v;
112118
}
113119

114-
115120
int64_t Module::LoadConstant(const char* name, const char* fallback,
116121
int64_t def) {
117122
Error err;
118-
int64_t v =
119-
LookupConstant(target_, (kConstantPrefix + name).c_str(), def, err);
120-
if (err.Fail())
121-
v = LookupConstant(target_, (kConstantPrefix + fallback).c_str(), def, err);
123+
int64_t v = LoadConstant(name, err, def);
124+
if (err.Fail()) v = LoadConstant(fallback, err, def);
122125
if (err.Fail()) {
123-
Error::PrintInDebugMode("Failed to load constant %s, fallback %s", name,
124-
fallback);
126+
Error::PrintInDebugMode(
127+
"Failed to load constant %s, fallback %s, default to %" PRId64, name,
128+
fallback, def);
125129
}
126130

127131
return v;
@@ -179,7 +183,16 @@ void HeapObject::Load() {
179183

180184

181185
void Map::Load() {
182-
kInstanceAttrsOffset = LoadConstant("class_Map__instance_attributes__int");
186+
Error err;
187+
kInstanceAttrsOffset =
188+
LoadConstant("class_Map__instance_attributes__int", err);
189+
if (err.Fail()) {
190+
kInstanceAttrsOffset = LoadConstant("class_Map__instance_type__uint16_t");
191+
kMapTypeMask = 0xffff;
192+
} else {
193+
kMapTypeMask = 0xff;
194+
}
195+
183196
kMaybeConstructorOffset =
184197
LoadConstant("class_Map__constructor_or_backpointer__Object",
185198
"class_Map__constructor__Object");

src/llv8-constants.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55

66
namespace llnode {
77
namespace v8 {
8+
9+
class Error;
10+
811
namespace constants {
912

1013
// Forward declarations
1114
class Common;
1215

16+
1317
class Module {
1418
public:
1519
Module() : loaded_(false) {}
@@ -20,6 +24,7 @@ class Module {
2024

2125
protected:
2226
int64_t LoadRawConstant(const char* name, int64_t def = -1);
27+
int64_t LoadConstant(const char* name, Error& err, int64_t def = -1);
2328
int64_t LoadConstant(const char* name, int64_t def = -1);
2429
int64_t LoadConstant(const char* name, const char* fallback,
2530
int64_t def = -1);
@@ -83,6 +88,7 @@ class Map : public Module {
8388
public:
8489
MODULE_DEFAULT_METHODS(Map);
8590

91+
int64_t kMapTypeMask;
8692
int64_t kInstanceAttrsOffset;
8793
int64_t kMaybeConstructorOffset;
8894
int64_t kInstanceDescriptorsOffset;

src/llv8-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ inline int64_t Map::GetType(Error& err) {
8989
v8()->LoadUnsigned(LeaField(v8()->map()->kInstanceAttrsOffset), 2, err);
9090
if (err.Fail()) return -1;
9191

92-
return type & 0xff;
92+
return type & v8()->map()->kMapTypeMask;
9393
}
9494

9595

0 commit comments

Comments
 (0)