1

I am hoping to find something similar to strace which will yield the instructions used by the CPU. For example, I have a simple loop which calculates a sum and prints out every tenth iteration

float fsum = 0.0;
for(int i = 0; i < 1000; i++) {
  if(i%10==0) {
    fprintf(stderr, "%10.5f%%\n", 100.0*float(i)/float(1000));
  }
  fsum += 1.0/float(i);
}

Now, strace will give information about the fprintf statement since that is a write(2 statement, but it gives no information about the summation steps. If I want to get information about a currently running program including the CPU instructions used, is there a way to do that?

NOTE: I know about tools such as gprof which require prior compilation. I am searching for a way to find the same information that gprof might give you, but with a CURRENTLY running program which may or may not have been compiled with profiling in mind.

drjrm3
  • 1,476
  • 6
  • 26
  • 44
  • What about `gdb`: https://www.gnu.org/software/gdb/ .. ? – txtechhelp Jan 26 '15 at 21:43
  • Perhaps I am mistaken but I did not think that gdb could attach to an already running program, can it? – drjrm3 Jan 27 '15 at 14:14
  • yup: `gdb prorgram 1234` where `1234` is the PID of the program you want to attach to; unless you happen to have a file in the directory from you where you run gdb named `1234` then it would try to debug the file, otherwise the PID. You won't be able to see full execution stacks (i.e. full function names of the things in the program itself) unless you have the debug symbols for that specific program, but you can see quite a bit of what's happening (including the assembly, i.e. CPU instructions) – txtechhelp Jan 27 '15 at 19:27

0 Answers0