Hi Dave,
I tried some of the scripts in the website on the code that I had sent
earlier. The following script (I refer this as script1.js) raised an
exception when I executed it on the code.
require({ after_gcc_pass: "cfg" });
include('gcc_util.js'); // for function_decl_cfg
include('gcc_print.js');
function process_tree(fn) {
print("function " + decl_name(fn)); // fn is a FUNCTION_DECL
let cfg = function_decl_cfg(fn);
for (let bb in cfg_bb_iterator(cfg)) {
print(" basic block " + bb_label(bb, cfg));
for (let isn in bb_isn_iterator(bb)) {
print(" " + isn_display(isn));
}
}
}
The exception is
function _GLOBAL__I__Z8functionv
../../../../dehydra-gcc-9a5b57d4a44a/libs/treehydra.js:13: JS
Exception: No index in this lazy object
:0: #0: Error("No index in this lazy object")
../../../../dehydra-gcc-9a5b57d4a44a/libs/treehydra.js:13: #1:
unhandledLazyProperty("index")
../../../../dehydra-gcc-9a5b57d4a44a/libs/gcc_util.js:91: #2:
bb_label([object GCCNode],[object GCCNode])
././script1.js:8: #3: process_tree([object GCCNode])
I commented the code in unhandledLazyProperty function in treehydra.js
to get it working. I was not sure if this was a bug in the code or if
there is something else I should take care of when I execute the
script, so thought I will find out from you.
I also tried executing the following java script code
require({ after_gcc_pass: "einline" + (isGCC42 ? "" : "_ipa")});
include('gcc_util.js'); // for function_decl_cfg
function process_cgraph(cgraph) {
// cgraph is a GCC structure representing a group of functions
// within the call graph. Iterate over the functions like this.
for (let fn = cgraph; fn; fn = fn.next) {
if (DECL_STRUCT_FUNCTION(fn)) { // fn has a body
print(fn);
let cfg = function_decl_cfg(fn);
}
}
And I got the following error:
../../../Software/dehydra-gcc-9a5b57d4a44a/libs/gcc_compat.js:216: JS
Exception: TypeError: node.function_decl is undefined
../../../Software/dehydra-gcc-9a5b57d4a44a/libs/gcc_compat.js:216: #0:
DECL_STRUCT_FUNCTION([object GCCNode])
././script2.js:7: #1: process_cgraph([object GCCNode])
I was not able to solve this error. I tested this on the latest
version of dehydra that is found in the hg repository.
I had one another question. I think GIMPLE representation would be the
best place to start for the kind of analysis that I am thinking of.
The process_tree is the function is the one that I should use. I
dumped the gimple representation from gcc using -fdump-tree-cfg option
and I got the following for the if condition in the code:
D.30570 = s.a;
D.30571 = s.b;
if (D.30570 > D.30571) goto <L0>; else goto <L1>;
# SUCC: 3 (true) 4 (false)
# BLOCK 3
# PRED: 2 (true)
<L0>:;
s.c = 2;
goto <bb 5> (<L2>);
# SUCC: 5 (fallthru)
# BLOCK 4
# PRED: 2 (false)
<L1>:;
s.c = 3;
# SUCC: 5 (fallthru)
script1.js gave the output for the if condition as follows:
GIMPLE_MODIFY_STMT D_21125 := s.a
GIMPLE_MODIFY_STMT D_21126 := s.b
COND_EXPR if GT_EXPR
basic block BBundefined
GIMPLE_MODIFY_STMT s.c := 2
basic block BBundefined
GIMPLE_MODIFY_STMT s.c := 3
I noticed one thing. The output of script1.js does not mark the then-
block and else-block that is found in the gimple representation from
gcc. Also the condition is represented as GT_EXPR and I could not find
a reference to GT_EXPR in the output. Is there some other function
call that I should use to get these? or is there something
fundamentally wrong with the way that I am executing the script?
Thanks for the help.
Sreekumar
_______________________________________________
dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis