-
Notifications
You must be signed in to change notification settings - Fork 10
how to debug
eddid edited this page Sep 13, 2014
·
1 revision
As I said in README.md, a part of code is written in C, and generate to IR code by clang. It's hard to debug this part of code in runtime.
I create an individual project for this part of code, and write some test code to simulate the runtime, for example, I meet problem when test with following JavaScript code:
var obj1 = { 100: "a", 2: "b", 7: "c"};
for (var prop1 in obj1) {
console.log("o." + prop1 + " = " + obj1[prop1]);
}
But there isn't any output when run, I have to add some test when generate IR code like this:
{
Function *echoFunction = context.getFunction("printf");
std::vector<llvm::Value *> echoArgs;
echoArgs.push_back(context.getVariableRef("intFormat", false));
echoArgs.push_back(lengthV);
CallInst::Create(echoFunction, makeArrayRef(echoArgs), "", context.currentBlock());
}
The log show that the length of property array is 0, but I can't debug into Object.getOwnPropertyNames, since this function is generate by jclang from C code. So I have to write some test code to simulate it like this:
int main(int argn, const char *argv[])
{
AllInOneInit();
//var obj1 = { 100: "a", 2: "b", 7: "c"};
JSValue obj1 = js_Object_create(js_global, js_global, 1, &jsNull);
JSValue key = NUMBER_TO_JSVAL(100);
JSValue value = js_string_new_utf8("a");
js_object_define_value_property(obj1, key, value, JS_PROP_FLAGS_ENUMERABLE | JS_PROP_FLAGS_ENUMERABLE_SET);
//add other two properties here
JSValue properties = js_Object_getOwnPropertyNames(jsUndefined, jsUndefined, 1, &obj1);
JSValue property = js_vtable_get(obj1, key, obj1);
js_dump_value(property);
}
And I find that the modification of generate hash code lead this issue.