Skip to content

Commit

Permalink
src: improved some comments and linter applied
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheus Marchini committed Aug 17, 2017
1 parent 7d9d1e1 commit ff614a9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
85 changes: 47 additions & 38 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include "src/llnode.h"
#include "src/llscan.h"
#include "src/llv8.h"
#include "src/llv8-constants.h"
#include "src/llv8.h"

namespace llnode {

Expand Down Expand Up @@ -145,7 +145,8 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
lldb::SBMemoryRegionInfo info;
if (target.GetProcess().GetMemoryRegionInfo(pc, info).Success() &&
info.IsExecutable() && info.IsWritable()) {
result.Printf(" %c frame #%u: 0x%016" PRIx64 " <builtin>\n", star, i, pc);
result.Printf(" %c frame #%u: 0x%016" PRIx64 " <builtin>\n", star, i,
pc);
continue;
}
}
Expand Down Expand Up @@ -306,7 +307,7 @@ bool ListCmd::DoExecute(SBDebugger d, char** cmd,
}

bool GetActiveHandlesCmd::DoExecute(SBDebugger d, char** cmd,
SBCommandReturnObject& result) {
SBCommandReturnObject& result) {
SBTarget target = d.GetSelectedTarget();
SBProcess process = target.GetProcess();
SBThread thread = process.GetSelectedThread();
Expand All @@ -317,7 +318,7 @@ bool GetActiveHandlesCmd::DoExecute(SBDebugger d, char** cmd,

llv8.Load(target);

int size = 8; // TODO size is arch-dependent
int size = 8;
int64_t envPtr = 0;
uint64_t env = 0;
int64_t queue = 0;
Expand All @@ -330,43 +331,46 @@ bool GetActiveHandlesCmd::DoExecute(SBDebugger d, char** cmd,
envPtr = LookupConstant(target, "nodedbg_currentEnvironment", envPtr, err2);
process.ReadMemory(envPtr, &env, size, sberr);

queue = LookupConstant(target, "nodedbg_class__Environment__handleWrapQueue", queue, err2);
head = LookupConstant(target, "nodedbg_class__HandleWrapQueue__headOffset", head, err2);
next = LookupConstant(target, "nodedbg_class__HandleWrapQueue__nextOffset", next, err2);
queue = LookupConstant(target, "nodedbg_class__Environment__handleWrapQueue",
queue, err2);
head = LookupConstant(target, "nodedbg_class__HandleWrapQueue__headOffset",
head, err2);
next = LookupConstant(target, "nodedbg_class__HandleWrapQueue__nextOffset",
next, err2);
node = LookupConstant(target, "nodedbg_class__HandleWrap__node", node, err2);
persistant_handle = LookupConstant(target, "nodedbg_class__BaseObject__persistant_handle", persistant_handle, err2);
persistant_handle =
LookupConstant(target, "nodedbg_class__BaseObject__persistant_handle",
persistant_handle, err2);

// uint8_t *buffer = new uint8_t[size];
// XXX Ozadia time
uint64_t buffer = 0;
bool go=true;
bool go = true;
if (!thread.IsValid()) {
result.SetError("No valid process, please start something\n");
return false;
}

int activeHandles = 0;
uint64_t currentNode = env;
currentNode += queue; // env.handle_wrap_queue_
currentNode += head; // env.handle_wrap_queue_.head_
currentNode += next; // env.handle_wrap_queue_.head_.next_
currentNode += queue; // XXX env.handle_wrap_queue_
currentNode += head; // XXX env.handle_wrap_queue_.head_
currentNode += next; // XXX env.handle_wrap_queue_.head_.next_
process.ReadMemory(currentNode, &buffer, size, sberr);
currentNode = buffer;
// TODO needs a stop condition, currently it's being stopped by a break
while(go) {
while (go) {
addr_t myMemory = currentNode;
myMemory = myMemory - node; // wrap
myMemory = myMemory - node; // wrap
myMemory += persistant_handle;
// w->persistent().IsEmpty()
if(myMemory == 0) {
// XXX w->persistent().IsEmpty()
if (myMemory == 0) {
continue;
}

process.ReadMemory(myMemory, &buffer, size, sberr);
myMemory = buffer;
process.ReadMemory(myMemory, &buffer, size, sberr);
// TODO needs a better check
if(sberr.Fail()) {
if (sberr.Fail()) {
break;
}

Expand All @@ -381,7 +385,8 @@ bool GetActiveHandlesCmd::DoExecute(SBDebugger d, char** cmd,
activeHandles++;
resultMsg << res.c_str() << std::endl;

currentNode += next; // env.handle_wrap_queue_.head_.next_->next_->(...)->next_
// XXX env.handle_wrap_queue_.head_.next_->next_->(...)->next_
currentNode += next;
process.ReadMemory(currentNode, &buffer, size, sberr);
currentNode = buffer;
}
Expand All @@ -391,7 +396,7 @@ bool GetActiveHandlesCmd::DoExecute(SBDebugger d, char** cmd,
}

bool GetActiveRequestsCmd::DoExecute(SBDebugger d, char** cmd,
SBCommandReturnObject& result) {
SBCommandReturnObject& result) {
SBTarget target = d.GetSelectedTarget();
SBProcess process = target.GetProcess();
SBThread thread = process.GetSelectedThread();
Expand All @@ -402,7 +407,7 @@ bool GetActiveRequestsCmd::DoExecute(SBDebugger d, char** cmd,

llv8.Load(target);

int size = 8; // TODO size is arch-dependent
int size = 8;
int64_t envPtr = 0;
uint64_t env = 0;
int64_t queue = 0;
Expand All @@ -415,43 +420,46 @@ bool GetActiveRequestsCmd::DoExecute(SBDebugger d, char** cmd,
envPtr = LookupConstant(target, "nodedbg_currentEnvironment", envPtr, err2);
process.ReadMemory(envPtr, &env, size, sberr);

queue = LookupConstant(target, "nodedbg_class__Environment__reqWrapQueue", queue, err2);
head = LookupConstant(target, "nodedbg_class__ReqWrapQueue__headOffset", head, err2);
next = LookupConstant(target, "nodedbg_class__ReqWrapQueue__nextOffset", next, err2);
queue = LookupConstant(target, "nodedbg_class__Environment__reqWrapQueue",
queue, err2);
head = LookupConstant(target, "nodedbg_class__ReqWrapQueue__headOffset", head,
err2);
next = LookupConstant(target, "nodedbg_class__ReqWrapQueue__nextOffset", next,
err2);
node = LookupConstant(target, "nodedbg_class__ReqWrap__node", node, err2);
persistant_handle = LookupConstant(target, "nodedbg_class__BaseObject__persistant_handle", persistant_handle, err2);
persistant_handle =
LookupConstant(target, "nodedbg_class__BaseObject__persistant_handle",
persistant_handle, err2);

// uint8_t *buffer = new uint8_t[size];
// XXX Ozadia time
uint64_t buffer = 0;
bool go=true;
bool go = true;
if (!thread.IsValid()) {
result.SetError("No valid process, please start something\n");
return false;
}

int activeHandles = 0;
uint64_t currentNode = env;
currentNode += queue; // env.handle_wrap_queue_
currentNode += head; // env.handle_wrap_queue_.head_
currentNode += next; // env.handle_wrap_queue_.head_.next_
currentNode += queue; // XXX env.handle_wrap_queue_
currentNode += head; // XXX env.handle_wrap_queue_.head_
currentNode += next; // XXX env.handle_wrap_queue_.head_.next_
process.ReadMemory(currentNode, &buffer, size, sberr);
currentNode = buffer;
// TODO needs a stop condition
while(go) {
while (go) {
addr_t myMemory = currentNode;
myMemory = myMemory - node;
myMemory = myMemory - node;
myMemory += persistant_handle;
// w->persistent().IsEmpty()
if(myMemory == 0) {
// XXX w->persistent().IsEmpty()
if (myMemory == 0) {
continue;
}

process.ReadMemory(myMemory, &buffer, size, sberr);
myMemory = buffer;
process.ReadMemory(myMemory, &buffer, size, sberr);
// TODO needs a better check
if(sberr.Fail()) {
if (sberr.Fail()) {
break;
}

Expand All @@ -466,7 +474,8 @@ bool GetActiveRequestsCmd::DoExecute(SBDebugger d, char** cmd,
activeHandles++;
resultMsg << res.c_str() << std::endl;

currentNode += next; // env.handle_wrap_queue_.head_.next_->next_->(...)->next_
// env.handle_wrap_queue_.head_.next_->next_->(...)->next_
currentNode += next;
process.ReadMemory(currentNode, &buffer, size, sberr);
currentNode = buffer;
}
Expand Down
2 changes: 1 addition & 1 deletion src/llv8-constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Module::Assign(SBTarget target, Common* common) {


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

res = def;
Expand Down
2 changes: 1 addition & 1 deletion src/llv8-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Error;
namespace constants {

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

// Forward declarations
class Common;
Expand Down
15 changes: 7 additions & 8 deletions src/llv8.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <assert.h>

#include <algorithm>
#include <cinttypes>
#include <algorithm>
#include <cinttypes>

#include "llv8-inl.h"
#include "llv8.h"
Expand Down Expand Up @@ -90,8 +90,7 @@ double LLV8::LoadDouble(int64_t addr, Error& err) {
std::string LLV8::LoadBytes(int64_t length, int64_t addr, Error& err) {
uint8_t* buf = new uint8_t[length + 1];
SBError sberr;
process_.ReadMemory(addr, buf,
static_cast<size_t>(length), sberr);
process_.ReadMemory(addr, buf, static_cast<size_t>(length), sberr);
if (sberr.Fail()) {
err = Error::Failure("Failed to load V8 raw buffer");
delete[] buf;
Expand Down Expand Up @@ -1111,9 +1110,9 @@ std::string JSArrayBuffer::Inspect(InspectOptions* options, Error& err) {

char tmp[128];
snprintf(tmp, sizeof(tmp),
"<ArrayBuffer: backingStore=0x%016" PRIx64 ", byteLength=%d",
data, byte_length);
"<ArrayBuffer: backingStore=0x%016" PRIx64 ", byteLength=%d", data,
byte_length);

std::string res;
res += tmp;
if (options->detailed) {
Expand Down Expand Up @@ -1155,8 +1154,8 @@ std::string JSArrayBufferView::Inspect(InspectOptions* options, Error& err) {
int byte_length = static_cast<int>(length.GetValue());
int byte_offset = static_cast<int>(off.GetValue());
char tmp[128];
snprintf(tmp, sizeof(tmp),
"<ArrayBufferView: backingStore=0x%016" PRIx64 ", byteOffset=%d, byteLength=%d",
snprintf(tmp, sizeof(tmp), "<ArrayBufferView: backingStore=0x%016" PRIx64
", byteOffset=%d, byteLength=%d",
data, byte_offset, byte_length);

std::string res;
Expand Down
1 change: 0 additions & 1 deletion src/llv8.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ class JSArrayBuffer : public HeapObject {
inline bool WasNeutered(Error& err);

std::string Inspect(InspectOptions* options, Error& err);

};

class JSArrayBufferView : public HeapObject {
Expand Down

0 comments on commit ff614a9

Please sign in to comment.