Skip to content

Commit

Permalink
src: fix backtrace with v8 6.4 (nodejs#168)
Browse files Browse the repository at this point in the history
This is the minimum patch to make llnode display stack traces
produced by v8 6.4.

PR-URL: nodejs#168
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
joyeecheung authored Feb 17, 2018
1 parent a3b9032 commit c231a6b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
37 changes: 25 additions & 12 deletions src/llv8-constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,39 @@ int64_t Module::LoadRawConstant(const char* name, int64_t def) {
Error err;
int64_t v = LookupConstant(target_, name, def, err);
if (err.Fail()) {
Error::PrintInDebugMode("Failed to load raw constant %s", name);
Error::PrintInDebugMode(
"Failed to load raw constant %s, default to %" PRId64, name, def);
}

return v;
}

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

int64_t Module::LoadConstant(const char* name, int64_t def) {
Error err;
int64_t v =
LookupConstant(target_, (kConstantPrefix + name).c_str(), def, err);
int64_t v = LoadConstant(name, err, def);
if (err.Fail()) {
Error::PrintInDebugMode("Failed to load constant %s", name);
Error::PrintInDebugMode("Failed to load constant %s, default to %" PRId64,
name, def);
}

return v;
}


int64_t Module::LoadConstant(const char* name, const char* fallback,
int64_t def) {
Error err;
int64_t v =
LookupConstant(target_, (kConstantPrefix + name).c_str(), def, err);
if (err.Fail())
v = LookupConstant(target_, (kConstantPrefix + fallback).c_str(), def, err);
int64_t v = LoadConstant(name, err, def);
if (err.Fail()) v = LoadConstant(fallback, err, def);
if (err.Fail()) {
Error::PrintInDebugMode("Failed to load constant %s, fallback %s", name,
fallback);
Error::PrintInDebugMode(
"Failed to load constant %s, fallback %s, default to %" PRId64, name,
fallback, def);
}

return v;
Expand Down Expand Up @@ -179,7 +183,16 @@ void HeapObject::Load() {


void Map::Load() {
kInstanceAttrsOffset = LoadConstant("class_Map__instance_attributes__int");
Error err;
kInstanceAttrsOffset =
LoadConstant("class_Map__instance_attributes__int", err);
if (err.Fail()) {
kInstanceAttrsOffset = LoadConstant("class_Map__instance_type__uint16_t");
kMapTypeMask = 0xffff;
} else {
kMapTypeMask = 0xff;
}

kMaybeConstructorOffset =
LoadConstant("class_Map__constructor_or_backpointer__Object",
"class_Map__constructor__Object");
Expand Down
6 changes: 6 additions & 0 deletions src/llv8-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

namespace llnode {
namespace v8 {

class Error;

namespace constants {

// Forward declarations
class Common;


class Module {
public:
Module() : loaded_(false) {}
Expand All @@ -20,6 +24,7 @@ class Module {

protected:
int64_t LoadRawConstant(const char* name, int64_t def = -1);
int64_t LoadConstant(const char* name, Error& err, int64_t def = -1);
int64_t LoadConstant(const char* name, int64_t def = -1);
int64_t LoadConstant(const char* name, const char* fallback,
int64_t def = -1);
Expand Down Expand Up @@ -83,6 +88,7 @@ class Map : public Module {
public:
MODULE_DEFAULT_METHODS(Map);

int64_t kMapTypeMask;
int64_t kInstanceAttrsOffset;
int64_t kMaybeConstructorOffset;
int64_t kInstanceDescriptorsOffset;
Expand Down
2 changes: 1 addition & 1 deletion src/llv8-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ inline int64_t Map::GetType(Error& err) {
v8()->LoadUnsigned(LeaField(v8()->map()->kInstanceAttrsOffset), 2, err);
if (err.Fail()) return -1;

return type & 0xff;
return type & v8()->map()->kMapTypeMask;
}


Expand Down

0 comments on commit c231a6b

Please sign in to comment.