[Soot-list] Newbie's question

mbatch at cs.mcgill.ca mbatch at cs.mcgill.ca
Fri Apr 21 09:58:46 EDT 2006


> 1. What do you mean by "ahead-of-time" instrumentation? Does this mean
> compile-time?And are there any other types of instrumentations in Soot

Yes, I mean compile time (or, when you run Soot on the program, that is,
to produce an instrumented version). Soot has no direct way of
instrumenting on the fly or at runtime.


> 2. When a method is called, can I easily obtain the context information
> of this invocation?That is, can I know who is the caller, who is callee,
> and what are the arguments/return values of this method call?

What I proposed was instrumenting using Soot. This means you have any
information you want, as long as you can get it within the confines of the
java program. That is to say, if you want to record the caller, you'll
have to add in normal java code which will do that for you (maybe a method
call that takes the caller as argument and implements what your aspect
originally did). However, if you have your aspects working for method
calls already, it may be worthwhile to simple continue using those
(compile the aspects in before running Soot) and then use Soot only to
instrument recording of local read/writes.

> 3. When a field or local variable is read/written, can I know what is the
>  read/write statement's context (i.e., what is the statement's enclosing
> object and what is the field's declaring object)?

Again, same as above. If you want to record a local's before and after
value, as well as it's enclosing object you could do the following:

Original method:

boolean foo(int i) {
  boolean localBool;
  localBool = i % 2;
  return localBool;
}

then you could instrument as follows:

boolean foo(int i) {
  boolean localBool;

  // inserted method call for recording local's type, name,
  //    enclosing object, and before-value
  recordLocalBefore("boolean", "localBool", this, localBool);

  localBool = i % 2;

  // insert local after value
  recordLocalAfter("localBool",localBool);

  return localBool;
}


> 4. Whan a field or local variable is written, can I know the old value of
>  this field/local?

Soot doesn't do anything for you, it just gives you the framework to
insert code (or run analyses). You'll have to record this yourself (as in
above example - send it to the method you build)

> I have tried the example "Using Soot to instrument a class file" by
> Feng Qian?

This should give you a good idea of how to add bytecode into an existing
classfile, and it should be fairly simple after that. If you run into more
specific problems or questions, just ask away. Good luck.

Michael Batchelder




More information about the Soot-list mailing list