Hi,
On Fri, May 18, 2012 at 09:18:57PM -0400, Lipeng Wan wrote:
> int bb_count[10000][0] ;
>
> In my opinion, the second dimension of this array should be the number of
> blocks rather than be 0.
Indeed, and this is obviously what the author intended too.
> Is there anyone who is familiar with counter.ml in PowerTOSSIM and can help me
> find out if the counter.ml was written correctly?
It is not written correctly.
The size of the array is computed by:
15 let myType = Formatcil.cType
16 "int [%d:motes][%d:bbs]"
17 [("motes", Fd max_motes); ("bbs",Fd !num_bbs) ];;
18
19 let cntArr = makeGlobalVar "bb_count" myType;;
The problem is that !num_bbs is the value of the counter *at the point of
definition*, and in that case it is 0 because countbbClass has not been called
yet to count the instuctions. The code is very convoluted and would need to be
rewritten completely IMHO, but here is a quick patch that solves this issue
(not tested):
--- counter.ml.old 2012-05-19 09:01:09.741057180 +0200
+++ counter.ml 2012-05-19 09:00:58.853553282 +0200
@@ -12,12 +12,6 @@
let num_bbs = ref 0;;
let cur_bb = ref 0;;
-let myType = Formatcil.cType
- "int [%d:motes][%d:bbs]"
- [("motes", Fd max_motes); ("bbs",Fd !num_bbs) ];;
-
-let cntArr = makeGlobalVar "bb_count" myType;; (* (TArray(intType, Some
(integer !num_bbs),[]));; *)
-
(* Just count the number of basic blocks in the file *)
class countbbClass = object
inherit nopCilVisitor
@@ -34,7 +28,7 @@
end
-class instrumentClass = object
+class instrumentClass cntArr = object
inherit nopCilVisitor
method vstmt (s: stmt) : stmt visitAction = begin
@@ -80,7 +74,13 @@
(* f.globals <- GVarDecl (ctrVar, locUnknown) :: f.globals; *)
- visitCilFile ((new instrumentClass) :> cilVisitor) f;
+ let myType = Formatcil.cType
+ "int [%d:motes][%d:bbs]"
+ [("motes", Fd max_motes); ("bbs",Fd !num_bbs) ] in
+
+ let cntArr = makeGlobalVar "bb_count" myType in (* (TArray(intType, Some
(integer !num_bbs),[]));; *)
+
+ visitCilFile ((new instrumentClass cntArr) :> cilVisitor) f;
f.globals <- GVarDecl (cntArr, locUnknown) :: f.globals
Best regards,
--
Gabriel
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
CIL-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cil-users