Skip to content

Commit 6363cbb

Browse files
committed
fix styles, cache LLNODE_DEBUG, tag variadic functions
1 parent 11b3597 commit 6363cbb

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

src/llnode.cc

+13
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,24 @@ bool ListCmd::DoExecute(SBDebugger d, char** cmd,
299299
return true;
300300
}
301301

302+
303+
void InitDebugMode() {
304+
bool isDebugMode = false;
305+
char* var = getenv("LLNODE_DEBUG");
306+
if (var != nullptr && strlen(var) != 0) {
307+
isDebugMode = true;
308+
}
309+
310+
v8::Error::SetDebugMode(isDebugMode);
311+
}
312+
302313
} // namespace llnode
303314

304315
namespace lldb {
305316

306317
bool PluginInitialize(SBDebugger d) {
318+
llnode::InitDebugMode();
319+
307320
SBCommandInterpreter interpreter = d.GetCommandInterpreter();
308321

309322
SBCommand v8 = interpreter.AddMultiwordCommand("v8", "Node.js helpers");

src/llv8-constants.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ static int64_t LookupConstant(SBTarget target, const char* name, int64_t def,
8989
int64_t Module::LoadRawConstant(const char* name, int64_t def) {
9090
Error err;
9191
int64_t v = LookupConstant(target_, name, def, err);
92-
if (err.Fail())
92+
if (err.Fail()) {
9393
Error::PrintInDebugMode("Failed to load raw constant %s", name);
94+
}
9495

9596
return v;
9697
}

src/llv8-inl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SRC_LLV8_INL_H_
22
#define SRC_LLV8_INL_H_
33

4+
#include <cinttypes>
45
#include "llv8.h"
56

67
namespace llnode {
@@ -20,7 +21,7 @@ inline T LLV8::LoadValue(int64_t addr, Error& err) {
2021
T res = T(this, ptr);
2122
if (!res.Check()) {
2223
// TODO(joyeecheung): use Error::Failure() to report information when
23-
// there is less noise from here
24+
// there is less noise from here.
2425
err = Error(true, "Invalid value");
2526
return T();
2627
}

src/llv8.cc

+9-15
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ void LLV8::Load(SBTarget target) {
5858
types.Assign(target, &common);
5959
}
6060

61+
bool Error::isDebugMode = false;
62+
6163
Error::Error(bool failed, const char* format, ...) {
6264
failed_ = failed;
63-
char tmp[MSG_BUF_LENGTH];
65+
char tmp[kMaxMessageLength];
6466
va_list arglist;
6567
va_start(arglist, format);
6668
vsnprintf(tmp, sizeof(tmp), format, arglist);
@@ -69,19 +71,11 @@ Error::Error(bool failed, const char* format, ...) {
6971
}
7072

7173

72-
bool IsDebugMode() {
73-
char* var = getenv("LLNODE_DEBUG");
74-
if (var == nullptr) return false;
75-
76-
return strlen(var) != 0;
77-
}
78-
79-
8074
void Error::PrintInDebugMode(const char* format, ...) {
81-
if (!IsDebugMode()) {
75+
if (!isDebugMode) {
8276
return;
8377
}
84-
char fmt[MSG_BUF_LENGTH];
78+
char fmt[kMaxMessageLength];
8579
snprintf(fmt, sizeof(fmt), "[llv8] %s\n", format);
8680
va_list arglist;
8781
va_start(arglist, format);
@@ -91,13 +85,13 @@ void Error::PrintInDebugMode(const char* format, ...) {
9185

9286

9387
Error Error::Failure(std::string msg) {
94-
PrintInDebugMode(msg.c_str());
88+
PrintInDebugMode("%s", msg.c_str());
9589
return Error(true, msg);
9690
}
9791

9892

9993
Error Error::Failure(const char* format, ...) {
100-
char tmp[MSG_BUF_LENGTH];
94+
char tmp[kMaxMessageLength];
10195
va_list arglist;
10296
va_start(arglist, format);
10397
vsnprintf(tmp, sizeof(tmp), format, arglist);
@@ -112,7 +106,7 @@ int64_t LLV8::LoadPtr(int64_t addr, Error& err) {
112106
process_.ReadPointerFromMemory(static_cast<addr_t>(addr), sberr);
113107
if (sberr.Fail()) {
114108
// TODO(joyeecheung): use Error::Failure() to report information when
115-
// there is less noise from here
109+
// there is less noise from here.
116110
err = Error(true, "Failed to load pointer from v8 memory");
117111
return -1;
118112
}
@@ -129,7 +123,7 @@ int64_t LLV8::LoadUnsigned(int64_t addr, uint32_t byte_size, Error& err) {
129123

130124
if (sberr.Fail()) {
131125
// TODO(joyeecheung): use Error::Failure() to report information when
132-
// there is less noise from here
126+
// there is less noise from here.
133127
err = Error(true, "Failed to load unsigned from v8 memory");
134128
return -1;
135129
}

src/llv8.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,28 @@ class Error {
2323
public:
2424
Error() : failed_(false), msg_("") {}
2525
Error(bool failed, std::string msg) : failed_(failed), msg_(msg) {}
26-
Error(bool failed, const char* format, ...);
26+
Error(bool failed, const char* format, ...)
27+
__attribute__((format(printf, 3, 4)));
2728

2829
static inline Error Ok() { return Error(false, "ok"); }
2930
static Error Failure(std::string msg);
30-
static Error Failure(const char* format, ...);
31-
static void PrintInDebugMode(const char* format, ...);
31+
static Error Failure(const char* format, ...)
32+
__attribute__((format(printf, 1, 2)));
33+
static void PrintInDebugMode(const char* format, ...)
34+
__attribute__((format(printf, 1, 2)));
3235

3336
inline bool Success() const { return !Fail(); }
3437
inline bool Fail() const { return failed_; }
3538

3639
inline const char* GetMessage() { return msg_.c_str(); }
3740

41+
static void SetDebugMode(bool mode) { isDebugMode = mode; }
42+
3843
private:
3944
bool failed_;
4045
std::string msg_;
41-
static const size_t MSG_BUF_LENGTH = 128;
46+
static const size_t kMaxMessageLength = 128;
47+
static bool isDebugMode;
4248
};
4349

4450
#define V8_VALUE_DEFAULT_METHODS(NAME, PARENT) \

0 commit comments

Comments
 (0)