Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] src: v8 snapshot command #199

Closed
wants to merge 6 commits into from
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
5 changes: 5 additions & 0 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <fstream>

#include <cinttypes>

Expand Down Expand Up @@ -397,6 +399,9 @@ bool PluginInitialize(SBDebugger d) {
"JavaScript string value\n"
"\n");

v8.AddCommand("snapshot", new llnode::V8SnapshotCmd(),
"Converts the core file being debugged into a V8 snapshot\n");

return true;
}

Expand Down
94 changes: 94 additions & 0 deletions src/llnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,100 @@ class ListCmd : public CommandBase {
lldb::SBCommandReturnObject& result) override;
};

class V8SnapshotCmd : public CommandBase {
public:
struct Node {
enum Type {
kHidden = 0, // v8::HeapGraphNode::kHidden,
kArray = 1, // v8::HeapGraphNode::kArray,
kString = 2, // v8::HeapGraphNode::kString,
kObject = 3, // v8::HeapGraphNode::kObject,
kCode = 4, // v8::HeapGraphNode::kCode,
kClosure = 5, // v8::HeapGraphNode::kClosure,
kRegExp = 6, //v8::HeapGraphNode::kRegExp,
kHeapNumber = 7, // v8::HeapGraphNode::kHeapNumber,
kNative = 8, // v8::HeapGraphNode::kNative,
kSynthetic = 9, // v8::HeapGraphNode::kSynthetic,
kConsString = 10, // v8::HeapGraphNode::kConsString,
kSlicedString = 11, // v8::HeapGraphNode::kSlicedString,
kSymbol = 12, // v8::HeapGraphNode::kSymbol,
kSimdValue = 13, // v8::HeapGraphNode::kSimdValue

kInvalid = -1
};
// static const int kNoEntry;

uint64_t addr;
Type type;
uint64_t name_id;
uint64_t node_id;
uint64_t self_size;
uint64_t children;
uint64_t trace_node_id;
};

struct Edge {
// TODO (mmarchini) this should come from V8 metadata
enum Type {
kContextVariable = 0, // v8::HeapGraphEdge::kContextVariable,
kElement = 1, // v8::HeapGraphEdge::kElement,
kProperty = 2, // v8::HeapGraphEdge::kProperty,
kInternal = 3, // v8::HeapGraphEdge::kInternal,
kHidden = 4, // v8::HeapGraphEdge::kHidden,
kShortcut = 5, // v8::HeapGraphEdge::kShortcut,
kWeak = 6 // v8::HeapGraphEdge::kWeak
};

Type type;
uint64_t index_or_property;
uint64_t to_id;
uint64_t to_addr;
};

~V8SnapshotCmd() override {}

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

void PrepareData(v8::Error &err);

Node::Type GetInstanceType(v8::Error &err, uint64_t word);
uint64_t GetStringId(v8::Error &err, std::string name);
uint64_t GetSelfSize(v8::Error &err, uint64_t word);
Edge CreateEdgeFromValue(v8::Error &err, v8::HeapObject &obj, v8::Value value);
uint64_t ChildrenCount(v8::Error &err, uint64_t word);

bool SerializeImpl(v8::Error &err);

void SerializeSnapshot(v8::Error &err);

void SerializeNodes(v8::Error &err);
void SerializeNode(v8::Error &err, Node* node, bool first_node);

void SerializeEdges(v8::Error &err);
void SerializeEdge(v8::Error &err, Edge edge, bool first_edge);

// TODO
void SerializeTraceNodeInfos(v8::Error &err);

// TODO
void SerializeTraceTree(v8::Error &err);
void SerializeTraceNode(v8::Error &err);

// TODO
void SerializeSamples(v8::Error &err);

// TODO
void SerializeStrings(v8::Error &err);
void SerializeString(v8::Error &err, std::string s);

private:
std::ofstream writer_;
std::vector<Node> nodes_;
std::vector<Edge> edges_;
std::vector<std::string> strings_;
};

} // namespace llnode

#endif // SRC_LLNODE_H_
Loading