Skip to content

Commit

Permalink
src: format source code using V8's clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Nov 11, 2015
1 parent 92135c8 commit 7500fed
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 161 deletions.
4 changes: 4 additions & 0 deletions .clang-format
@@ -0,0 +1,4 @@
# Defines the Google C++ style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Google
MaxEmptyLinesToKeep: 2
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -16,4 +16,7 @@ install-linux:
uninstall-linux:
rm /usr/lib/lldb/llnode.so

format:
clang-format -i src/*

.PHONY: all
49 changes: 24 additions & 25 deletions src/llnode.cc
Expand Up @@ -22,8 +22,8 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
}

errno = 0;
int number = (cmd != nullptr && *cmd != nullptr) ?
strtol(*cmd, nullptr, 10) : -1;
int number =
(cmd != nullptr && *cmd != nullptr) ? strtol(*cmd, nullptr, 10) : -1;
if ((number == 0 && errno == EINVAL) || (number < 0 && number != -1)) {
result.SetError("Invalid number of frames");
return false;
Expand All @@ -41,8 +41,7 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
SBFrame selected_frame = thread.GetSelectedFrame();

uint32_t num_frames = thread.GetNumFrames();
if (number != -1)
num_frames = number;
if (number != -1) num_frames = number;
for (uint32_t i = 0; i < num_frames; i++) {
SBFrame frame = thread.GetFrameAtIndex(i);
SBSymbol symbol = frame.GetSymbol();
Expand All @@ -52,7 +51,7 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
SBStream desc;
if (!frame.GetDescription(desc)) continue;
result.Printf(frame == selected_frame ? " * %s" : " %s",
desc.GetData());
desc.GetData());
continue;
}

Expand All @@ -65,10 +64,10 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
if (err.Fail()) continue;

// V8 symbol
result.Printf(
frame == selected_frame ? " * frame #%u: 0x%016llx %s\n" :
" frame #%u: 0x%016llx %s\n",
i, static_cast<unsigned long long int>(frame.GetPC()), res.c_str());
result.Printf(frame == selected_frame ? " * frame #%u: 0x%016llx %s\n"
: " frame #%u: 0x%016llx %s\n",
i, static_cast<unsigned long long int>(frame.GetPC()),
res.c_str());
}

return true;
Expand Down Expand Up @@ -140,7 +139,7 @@ bool CodeMap::DoExecute(SBDebugger d, char** cmd,


bool ListCmd::DoExecute(SBDebugger d, char** cmd,
SBCommandReturnObject& result) {
SBCommandReturnObject& result) {
static SBFrame last_frame;
static uint64_t last_line = 0;
SBTarget target = d.GetSelectedTarget();
Expand Down Expand Up @@ -185,8 +184,7 @@ bool ListCmd::DoExecute(SBDebugger d, char** cmd,
if (line_switch) {
reset_line = true;
last_line = line_from_switch;
}
else if (frame != last_frame) {
} else if (frame != last_frame) {
last_line = 0;
reset_line = true;
}
Expand All @@ -209,8 +207,7 @@ bool ListCmd::DoExecute(SBDebugger d, char** cmd,
uint32_t lines_found = 0;

uint32_t line_cursor = v8_frame.GetSourceForDisplay(
reset_line, last_line, kDisplayLines,
lines, lines_found, err);
reset_line, last_line, kDisplayLines, lines, lines_found, err);
if (err.Fail()) {
result.SetError(err.GetMessage());
return false;
Expand All @@ -219,7 +216,7 @@ bool ListCmd::DoExecute(SBDebugger d, char** cmd,

for (uint32_t i = 0; i < lines_found; i++) {
result.Printf(" %d %s\n", line_cursor - lines_found + i + 1,
lines[i].c_str());
lines[i].c_str());
}

return true;
Expand All @@ -234,30 +231,32 @@ bool PluginInitialize(SBDebugger d) {

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

v8.AddCommand("bt", new llnode::BacktraceCmd(),
v8.AddCommand(
"bt", new llnode::BacktraceCmd(),
"Show a backtrace with node.js JavaScript functions and their args. "
"An optional argument is accepted; if that argument is a number, it "
"specifies the number of frames to display. Otherwise all frames will "
"be dumped.\n\n"
"Syntax: v8 bt [number]\n");

v8.AddCommand("print", new llnode::PrintCmd(false),
"Print short description of the JavaScript value.\n\n"
"Syntax: v8 print expr\n");
"Print short description of the JavaScript value.\n\n"
"Syntax: v8 print expr\n");

v8.AddCommand("inspect", new llnode::PrintCmd(true),
v8.AddCommand(
"inspect", new llnode::PrintCmd(true),
"Print detailed description and contents of the JavaScript value.\n\n"
"Syntax: v8 inspect expr\n");

v8.AddCommand("code-map", new llnode::CodeMap(),
"Print code map of all compiled functions.\n\n"
"Syntax: v8 code-map\n");
"Print code map of all compiled functions.\n\n"
"Syntax: v8 code-map\n");

SBCommand source = v8.AddMultiwordCommand("source",
"Source code information");
SBCommand source =
v8.AddMultiwordCommand("source", "Source code information");
source.AddCommand("list", new llnode::ListCmd(),
"Print source lines around a selected JavaScript frame.\n\n"
"Syntax: v8 source list\n");
"Print source lines around a selected JavaScript frame.\n\n"
"Syntax: v8 source list\n");

return true;
}
Expand Down
15 changes: 5 additions & 10 deletions src/llnode.h
Expand Up @@ -9,20 +9,17 @@ namespace llnode {

class BacktraceCmd : public lldb::SBCommandPluginInterface {
public:
~BacktraceCmd() override {
}
~BacktraceCmd() override {}

bool DoExecute(lldb::SBDebugger d, char** cmd,
lldb::SBCommandReturnObject& result) override;
};

class PrintCmd : public lldb::SBCommandPluginInterface {
public:
PrintCmd(bool detailed) : detailed_(detailed) {
}
PrintCmd(bool detailed) : detailed_(detailed) {}

~PrintCmd() override {
}
~PrintCmd() override {}

bool DoExecute(lldb::SBDebugger d, char** cmd,
lldb::SBCommandReturnObject& result) override;
Expand All @@ -33,17 +30,15 @@ class PrintCmd : public lldb::SBCommandPluginInterface {

class CodeMap : public lldb::SBCommandPluginInterface {
public:
~CodeMap() override {
}
~CodeMap() override {}

bool DoExecute(lldb::SBDebugger d, char** cmd,
lldb::SBCommandReturnObject& result) override;
};

class ListCmd : public lldb::SBCommandPluginInterface {
public:
~ListCmd() override {
}
~ListCmd() override {}

bool DoExecute(lldb::SBDebugger d, char** cmd,
lldb::SBCommandReturnObject& result) override;
Expand Down
5 changes: 2 additions & 3 deletions src/llv8-code-map.cc
Expand Up @@ -56,7 +56,7 @@ std::string CodeMap::Collect(Error& err) {

char tmp[128];
snprintf(tmp, sizeof(tmp), "0x%016llx, 0x%016llx, ", entry.start(),
entry.end());
entry.end());
res += tmp + entry.name() + "\n";
}
entries_.clear();
Expand Down Expand Up @@ -135,8 +135,7 @@ void CodeMap::CollectArea(int64_t start, int64_t end, Error& err) {
CollectObject(obj, &instance_size, err);
if (err.Fail()) continue;

if (instance_size < kPointerSize)
instance_size = kPointerSize;
if (instance_size < kPointerSize) instance_size = kPointerSize;

// Align
if ((instance_size % kPointerSize) != 0)
Expand Down
11 changes: 4 additions & 7 deletions src/llv8-code-map.h
Expand Up @@ -10,8 +10,7 @@ namespace v8 {

class CodeMap {
public:
CodeMap(LLV8* v8) : v8_(v8) {
}
CodeMap(LLV8* v8) : v8_(v8) {}

std::string Collect(Error& err);

Expand All @@ -20,10 +19,8 @@ class CodeMap {
private:
class QueueItem {
public:
QueueItem(int64_t start, int64_t end, std::string name) : start_(start),
end_(end),
name_(name) {
}
QueueItem(int64_t start, int64_t end, std::string name)
: start_(start), end_(end), name_(name) {}

static bool Sort(QueueItem a, QueueItem b);

Expand Down Expand Up @@ -51,4 +48,4 @@ class CodeMap {
} // namespace v8
} // namespace llnode

#endif // SRC_LLV8_CODE_MAP_H_
#endif // SRC_LLV8_CODE_MAP_H_
33 changes: 15 additions & 18 deletions src/llv8-constants.cc
Expand Up @@ -32,7 +32,7 @@ void Module::Assign(SBTarget target, Common* common) {


static int64_t LookupConstant(SBTarget target, const char* name, int64_t def,
Error& err) {
Error& err) {
int64_t res;

res = def;
Expand Down Expand Up @@ -99,8 +99,8 @@ int64_t Module::LoadRawConstant(const char* name, int64_t def) {

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 =
LookupConstant(target_, (kConstantPrefix + name).c_str(), def, err);
if (err.Fail() && IsDebugMode()) fprintf(stderr, "Failed to load %s\n", name);

return v;
Expand All @@ -110,8 +110,8 @@ int64_t Module::LoadConstant(const char* name, int64_t def) {
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);
int64_t v =
LookupConstant(target_, (kConstantPrefix + name).c_str(), def, err);
if (err.Fail())
v = LookupConstant(target_, (kConstantPrefix + fallback).c_str(), def, err);
if (err.Fail() && IsDebugMode()) fprintf(stderr, "Failed to load %s\n", name);
Expand Down Expand Up @@ -162,15 +162,14 @@ void HeapObject::Load() {


void Map::Load() {
kInstanceAttrsOffset =
LoadConstant("class_Map__instance_attributes__int");
kInstanceAttrsOffset = LoadConstant("class_Map__instance_attributes__int");
kMaybeConstructorOffset =
LoadConstant("class_Map__constructor_or_backpointer__Object",
"class_Map__constructor__Object");
kInstanceDescriptorsOffset =
LoadConstant("class_Map__instance_descriptors__DescriptorArray");
kBitField3Offset = LoadConstant("class_Map__bit_field3__int",
"class_Map__bit_field3__SMI");
kBitField3Offset =
LoadConstant("class_Map__bit_field3__int", "class_Map__bit_field3__SMI");
kInObjectPropertiesOffset = LoadConstant(
"class_Map__inobject_properties_or_constructor_function_index__int",
"class_Map__inobject_properties__int");
Expand Down Expand Up @@ -215,8 +214,7 @@ void JSArray::Load() {
void JSFunction::Load() {
kSharedInfoOffset =
LoadConstant("class_JSFunction__shared__SharedFunctionInfo");
kContextOffset =
LoadConstant("class_JSFunction__context__Context");
kContextOffset = LoadConstant("class_JSFunction__context__Context");

if (kContextOffset == -1) {
common_->Load();
Expand Down Expand Up @@ -307,13 +305,13 @@ void String::Load() {

void OneByteString::Load() {
kCharsOffset = LoadConstant("class_SeqOneByteString__chars__char",
"class_SeqAsciiString__chars__char");
"class_SeqAsciiString__chars__char");
}


void TwoByteString::Load() {
kCharsOffset = LoadConstant("class_SeqTwoByteString__chars__char",
"class_SeqAsciiString__chars__char");
"class_SeqAsciiString__chars__char");
}


Expand Down Expand Up @@ -363,8 +361,7 @@ void JSArrayBuffer::Load() {

kBackingStoreOffset = kByteLengthOffset + common_->kPointerSize;
kBitFieldOffset = kBackingStoreOffset + common_->kPointerSize;
if (common_->kPointerSize == 8)
kBitFieldOffset += 4;
if (common_->kPointerSize == 8) kBitFieldOffset += 4;
}

kWasNeuteredMask = LoadConstant("jsarray_buffer_was_neutered_mask");
Expand Down Expand Up @@ -433,7 +430,7 @@ void NameDictionary::Load() {
}

kPrefixSize = LoadConstant("class_NameDictionaryShape__prefix_size__int") +
kPrefixStartIndex;
kPrefixStartIndex;
}


Expand Down Expand Up @@ -506,8 +503,8 @@ void Types::Load() {
kJSTypedArrayType = LoadConstant("type_JSTypedArray__JS_TYPED_ARRAY_TYPE");
kJSRegExpType = LoadConstant("type_JSRegExp__JS_REGEXP_TYPE");
kJSDateType = LoadConstant("type_JSDate__JS_DATE_TYPE");
kSharedFunctionInfoType = LoadConstant(
"type_SharedFunctionInfo__SHARED_FUNCTION_INFO_TYPE");
kSharedFunctionInfoType =
LoadConstant("type_SharedFunctionInfo__SHARED_FUNCTION_INFO_TYPE");
}

} // namespace constants
Expand Down
21 changes: 10 additions & 11 deletions src/llv8-constants.h
Expand Up @@ -12,8 +12,7 @@ class Common;

class Module {
public:
Module() : loaded_(false) {
}
Module() : loaded_(false) {}

inline bool is_loaded() const { return loaded_; }

Expand All @@ -23,22 +22,22 @@ class Module {
int64_t LoadRawConstant(const char* name, 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);
int64_t def = -1);
int64_t Eval(const char* expr, int64_t def = -1);

lldb::SBTarget target_;
Common* common_;
bool loaded_;
};

#define MODULE_DEFAULT_METHODS(NAME) \
NAME() {} \
inline NAME* operator()() { \
if (loaded_) return this; \
loaded_ = true; \
Load(); \
return this; \
}
#define MODULE_DEFAULT_METHODS(NAME) \
NAME() {} \
inline NAME* operator()() { \
if (loaded_) return this; \
loaded_ = true; \
Load(); \
return this; \
}

class Common : public Module {
public:
Expand Down

0 comments on commit 7500fed

Please sign in to comment.