Help on LLVM Instrumentation

Hi ,

I am using LLVM for my Post Graduate course project on Optimization. I am trying to do some insrtumentation to the bytecode.I 've been going through your Instrumentation code for the past few days in /llvm/lib/Transforms/Instrumentation folder and finally found two ways of instrumentation :

  1. injecting LLVM bytecode instructions

  2. calling an external C function.

I am trying both and I am comfortable with the 2).
My goal is to insert a global variable , which will count the total number of functions executed.At each method entry the global variable should be incremented and at the last method exit , it should print the count. The code compiled successfully, but when I used in the opt tool, I get an error in the getElementPtr(…) statement and finally a segmentation fault error. Please help me regarding this.

I am sending the code as an attachment.

I 've written a pass which will do instrumentation using the opt tool and then execute with lli JIT enabled.

Thank you ,

Sandra Johnson , M.E. (C.S.E.)

Anna University,

Chennai , India.

Sample.cpp (5.01 KB)


It's unlikely you'll get someone to help you debug a problem like this without more information (and without giving some evidence that you have tried hard to fix it yourself). Let me suggest what I suggest to post-graduate and undergraduate students taking my compiler classes when they send such a question:

1. Use a debugger (e.g. gdb) to find the symptoms. You may have done so already but if so, it wasn't clear.
2. Try to narrow down the cause of the problem yourself. Often, the problem is obvious and you won't need help.
3. If you still cannot figure it out, try to construct a small test case that shows the problem. For LLVM, use bugpoint to do this -- it should work very well for your kind of pass.
4. If you still need help, give this list as much information as you can based on what you've found so far. Then, they will feel justified in helping you.

Good luck,

--Vikram Adve

One tool you may find extremely helpful is bugpoint. Bugpoint will take
you bytecode and perform a search to find the smallest subset of the
file that triggers an error. Sharing this "reduced" file is much better
when seeking help (if the reduction doesn't make it clear to you what
the problem is). Check out the tool's instructions and email the list
if you need help running it.

Bugpoint is how we all stay sane when tracking down bugs.