Search code examples
armgdbpthreadsglibcperformance-monitor

Why is there is difference in number of instructions executed by a program when it is running under GDB?


I am using ARM PMU counter to count the number of instructions executed between two system calls by a process. Particularly I am using "INST_RETIRED" event to count the number of instructions executed by a process in user mode. Reference: ARMv7 R/A Reference Manual. The number of instructions is consistent if either I am running a program in free mode or under GDB. The problem arises when I try to create a thread using pthread_create. The number of instructions executed by the same program between two system calls mprotect and clone (both executed by the function pthread_create) is different when I run it under GDB. That means that the user program is executing some different code when it is running under a debugger, may be in the library, libpthread. I have seen the source code of pthread_create but could not find anything related to trace/debug flags. Copuld anybody please guide me where is then this ambuguity coming from?


Solution

  • I have seen the source code of pthread_create but could not find anything related to trace/debug flags

    There is in fact such code here and here. report_events is set to true only when running under debugger.