Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ int64_t Constants::LoadRawConstant(const char* name, int64_t def) {
Error err;
int64_t v = Constants::LookupConstant(target_, name, def, err);
if (err.Fail()) {
Error::PrintInDebugMode(
"Failed to load raw constant %s, default to %" PRId64, name, def);
PRINT_DEBUG("Failed to load raw constant %s, default to %" PRId64, name,
def);
}

return v;
Expand All @@ -96,8 +96,7 @@ int64_t Constants::LoadConstant(const char* name, int64_t def) {
Error err;
int64_t v = LoadConstant(name, err, def);
if (err.Fail()) {
Error::PrintInDebugMode("Failed to load constant %s, default to %" PRId64,
name, def);
PRINT_DEBUG("Failed to load constant %s, default to %" PRId64, name, def);
}

return v;
Expand All @@ -109,9 +108,8 @@ int64_t Constants::LoadConstant(const char* name, const char* fallback,
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, default to %" PRId64, name,
fallback, def);
PRINT_DEBUG("Failed to load constant %s, fallback %s, default to %" PRId64,
name, fallback, def);
}

return v;
Expand Down
10 changes: 7 additions & 3 deletions src/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ Error::Error(bool failed, const char* format, ...) {
}


void Error::PrintInDebugMode(const char* format, ...) {
void Error::PrintInDebugMode(const char* file, int line, const char* funcname,
const char* format, ...) {
if (!is_debug_mode) {
return;
}
char fmt[kMaxMessageLength];
snprintf(fmt, sizeof(fmt), "[llv8] %s\n", format);
snprintf(fmt, sizeof(fmt), "[llnode][%s %s:%lld] %s\n", funcname, file, line,
format);
va_list arglist;
va_start(arglist, format);
vfprintf(stderr, fmt, arglist);
Expand All @@ -30,7 +32,9 @@ void Error::PrintInDebugMode(const char* format, ...) {


Error Error::Failure(std::string msg) {
PrintInDebugMode("%s", msg.c_str());
// TODO(mmarchini): The file and function information here won't be relevant.
// But then again, maybe we should rethink Error::Failure.
PRINT_DEBUG("%s", msg.c_str());
return Error(true, msg);
}

Expand Down
9 changes: 7 additions & 2 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#define SRC_ERROR_H_

#include <string>
#include <typeinfo>

#define PRINT_DEBUG(format, ...) \
Error::PrintInDebugMode(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__)

namespace llnode {

Expand All @@ -16,8 +20,9 @@ class Error {
static Error Failure(std::string msg);
static Error Failure(const char* format, ...)
__attribute__((format(printf, 1, 2)));
static void PrintInDebugMode(const char* format, ...)
__attribute__((format(printf, 1, 2)));
static void PrintInDebugMode(const char* file, int line, const char* funcname,
const char* format, ...)
__attribute__((format(printf, 4, 5)));

inline bool Success() const { return !Fail(); }
inline bool Fail() const { return failed_; }
Expand Down
8 changes: 3 additions & 5 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
res.c_str());
continue;
} else {
Error::PrintInDebugMode("%s", err.GetMessage());
PRINT_DEBUG("%s", err.GetMessage());
}
}

Expand Down Expand Up @@ -352,8 +352,7 @@ std::string GetActiveHandlesCmd::GetResultMessage(node::Environment* env,
Printer printer(llv8(), printer_options);
std::string res = printer.Stringify(v8_object, err);
if (err.Fail()) {
Error::PrintInDebugMode("Failed to load object at address %" PRIx64,
raw_object);
PRINT_DEBUG("Failed to load object at address %" PRIx64, raw_object);
break;
}

Expand Down Expand Up @@ -385,8 +384,7 @@ std::string GetActiveRequestsCmd::GetResultMessage(node::Environment* env,
Printer printer(llv8(), printer_options);
std::string res = printer.Stringify(v8_object, err);
if (err.Fail()) {
Error::PrintInDebugMode("Failed to load object at address %" PRIx64,
raw_object);
PRINT_DEBUG("Failed to load object at address %" PRIx64, raw_object);
break;
}

Expand Down
7 changes: 3 additions & 4 deletions src/llscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,9 @@ void FindReferencesCmd::ReferenceScanner::PrintContextRefs(
if (err.Success())
name = maybe_name;
else
Error::PrintInDebugMode(
"Couldn't get the variable name for 0x%" PRIx64
" in context 0x%" PRIx64,
search_value_.raw(), c.raw());
PRINT_DEBUG("Couldn't get the variable name for 0x%" PRIx64
" in context 0x%" PRIx64,
search_value_.raw(), c.raw());
}

std::stringstream ss;
Expand Down
4 changes: 2 additions & 2 deletions src/llv8-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Value SharedFunctionInfo::GetInferredName(Error& err) {
err = Error::Ok();
Value maybe_uncompiled_data = function_data(err);
if (!maybe_uncompiled_data.IsUncompiledData(err)) {
Error::PrintInDebugMode("Couldn't get UncompiledData");
PRINT_DEBUG("Couldn't get UncompiledData");
return Value();
}

Expand All @@ -430,7 +430,7 @@ Script SharedFunctionInfo::GetScript(Error& err) {
HeapObject maybe_script = script_or_debug_info(err);
if (maybe_script.IsScript(err)) return maybe_script;

Error::PrintInDebugMode("Couldn't get Script in SharedFunctionInfo");
PRINT_DEBUG("Couldn't get Script in SharedFunctionInfo");
return Script();
}

Expand Down
14 changes: 6 additions & 8 deletions src/llv8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ std::string JSDate::ToString(Error& err) {
return s;
}

Error::PrintInDebugMode("JSDate is not a Smi neither a HeapNumber");
PRINT_DEBUG("JSDate is not a Smi neither a HeapNumber");
return "";
}

Expand Down Expand Up @@ -1236,21 +1236,20 @@ JSArray JSError::GetFrameArray(Error& err) {
v8::Value maybe_stack = GetProperty(stack_trace_property(), err);

if (err.Fail() || maybe_stack.raw() == -1) {
Error::PrintInDebugMode(
"Couldn't find a symbol property in the Error object.");
PRINT_DEBUG("Couldn't find a symbol property in the Error object.");
return JSArray();
}

int64_t type = v8::HeapObject(maybe_stack).GetType(err);

if (err.Fail()) {
Error::PrintInDebugMode("Symbol property references an invalid object.");
PRINT_DEBUG("Symbol property references an invalid object.");
return JSArray();
}

// NOTE (mmarchini): The stack is stored as a JSArray
if (type != v8()->types()->kJSArrayType) {
Error::PrintInDebugMode("Symbol property doesn't have the right type.");
PRINT_DEBUG("Symbol property doesn't have the right type.");
return JSArray();
}

Expand All @@ -1275,8 +1274,7 @@ StackTrace::StackTrace(JSArray frame_array, Error& err)
v8::Value maybe_stack_len = frame_array.GetArrayElement(0, err);

if (err.Fail()) {
Error::PrintInDebugMode(
"Couldn't get the first element from the stack array");
PRINT_DEBUG("Couldn't get the first element from the stack array");
return;
}

Expand All @@ -1291,7 +1289,7 @@ StackTrace::StackTrace(JSArray frame_array, Error& err)
multiplier_ = 4;
if ((len_ != 0) ||
((frame_array_.GetArrayLength(err) - 1) % multiplier_ != 0)) {
Error::PrintInDebugMode(
PRINT_DEBUG(
"JSArray doesn't look like a Stack Frames array. stack_len: %d "
"array_len: %ld",
len_, frame_array_.GetArrayLength(err));
Expand Down
5 changes: 2 additions & 3 deletions src/printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,8 @@ std::string Printer::Stringify(v8::HeapObject heap_object, Error& err) {
return pre + Stringify(date, err);
}

Error::PrintInDebugMode("Unknown HeapObject Type %" PRId64 " at 0x%016" PRIx64
"",
type, heap_object.raw());
PRINT_DEBUG("Unknown HeapObject Type %" PRId64 " at 0x%016" PRIx64 "", type,
heap_object.raw());

std::stringstream ss;
ss << rang::fg::yellow << "<unknown>" << rang::fg::reset;
Expand Down