0

Recently I'm trying to modify GCC and gcov to collect execution sequence for program. As we all know, gcc will instrument code on arcs between basic blocks to count the execution count of arc. So I instrument a function on the arc, and the function will print out the no of that arc, so I can collect program execution sequence. It works well for c program on x86 and x86_64, also for c++ program of x86. But for c++ program on x86_64, the program will crash by segment error. The compilation has no problem. The os that I use is CentOS 6.4. Version of gcc is 3.4.5. Does anybody has some advice?

sample program:

#include <iostream> using namespace std; int main(){cout<<"hello world"<<endl;}

If I compile the program in x86_64 mode. The program crash by Segment Error when comes to the cout CALL.

ShenYi
  • 121
  • 1
  • 7

3 Answers3

0

Ok, by another night debug on it. I found that the function emit_library_call will only generate asm code to invoke my function, but not protect the context (registers). So function call before or after the emitted code may fail due to nonuniform context. And x86_64 asm use different registers with x86. So to work well on x86 platform may be just accident. I need a function api which can emit library function call and also protect the context. Maybe I should write another emit_library_call.

ShenYi
  • 121
  • 1
  • 7
0

Perhaps you might try a dynamic binary translation framework, e.g. DynamoRIO or Pin. These tools offer more flexibility than you need, but they would allow you do inject code at the beginning/end of each basic block. What you then want to do is save/restore the flags and registers (and potentially re-align the stack), and call out to a function. DynamoRIO has similar functionality built in, named a "clean call". I think Pin also enables this with a potentially higher-level interface.

Peter Goodman
  • 438
  • 3
  • 12
0

I did same thing what you did in 3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:13:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

#include <iostream>

`using namespace std;

int main()

{

    cout<<"hello world"<<endl;

}`

compiled above code with g++ -ftest-coverage -fprofile-arcs hello.cpp -o hello hello.gcno file is generated.

After executing ./hello hello.gcda file generated .

So once check your gcc version .

My gcc version is gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

vinay hunachyal
  • 3,781
  • 2
  • 20
  • 31