[llvm-dev] llvm dynamic execution trace
Alex Susu via llvm-dev
llvm-dev at lists.llvm.org
Sat Aug 13 03:45:44 PDT 2016
Hello.
Ammar, I come back to this old thread.
Even with the current lli you can give
lli --debug -force-interpreter -stats
and you will obtain on stderr a trace of the instructions executed.
Unfortunately, the information printed on stderr is not well formatted - I edited
llvm/lib/ExecutionEngine/Interpreter/Execution.cpp, the Interpreter::run() method. You can
find how the code looks now below.
An important question I have is: how can I output the actual values the LLVM
variables take during execution? I ask because the code below I wrote outputs the static
values of the instruction operands, not the values taken at runtime.
I'm also curious: is there a project adding a GUI frontend to lli in order to perform
interactive debugging to an LLVM program (something like gdb -tui mode)? I wasn't able to
find any after a few minutes of search on the Internet.
void Interpreter::run() {
while (!ECStack.empty()) {
// Interpret a single instruction & increment the "PC".
ExecutionContext &SF = ECStack.back(); // Current stack frame
Instruction &I = *SF.CurInst++; // Increment before execute
// Track the number of dynamic instructions executed.
++NumDynamicInsts;
DEBUG(dbgs() << "About to interpret: " << I);
// Alex: new code
DEBUG(dbgs() << "\n");
const char *opcodeName = I.getOpcodeName();
if ( (strcmp(opcodeName, "call") != 0) &&
(strcmp(opcodeName, "br") != 0) ) {
for (unsigned int i = 0; i < I.getNumOperands(); i++) {
DEBUG(dbgs() << " arg " << i << ": " << * (I.getOperand(i)) << "\n");
}
}
// Alex: END new code
visit(I); // Dispatch to one of the visit* methods...
}
}
Thank you,
Alex
On 5/4/2016 8:48 AM, Dean Michael Berris via llvm-dev wrote:
> On Wed, May 4, 2016 at 3:10 PM Ammar Naqvi via llvm-dev <llvm-dev at lists.llvm.org
> <mailto:llvm-dev at lists.llvm.org>> wrote:
>
> Hi Dean, thank you for the response!
>
> I'm a newbie to LLVM, a student working on an LLVM project so I'm not quite sure of
> what you're suggesting, please excuse my naivety.
>
> To clarify there used to exist
> this http://llvm.org/releases/1.0/docs/CommandGuide/lli.html where you could type "lli
> -trace 'filename.bc' and you would get a dump of the dynamic excutiion trace.
>
> I need something like:
> to record the execution (statement/instruction) trace of a program. For example, a C
> program is like this:
>
> 1: sum = 0;
> 2: for(i = 0; i < 2; i++)
> 3: sum += i;
> 4: printf("%d", sum);
>
> The execution trace would be something like 1->2->3->2->3->2->4.
>
> Is there some way of achieving this, this was possible in previous verions of LLVM
> <2.6 i believe; I need guidance of replicating this on the newer version(using 3.8).
>
>
> Ah, that's slightly different from what XRay allows. I'll let others respond more
> specifically on what you're after.
>
> Cheers
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
More information about the llvm-dev
mailing list