Donc, j'ai déjà lu cet article Counting machine instructions of a process using PTRACE_SINGLESTEP, et je comprends que lier dynamiquement un programme de test à mon programme ptrace retournera un nombre d'instructions qui compte également l'initialisation de la bibliothèque d'exécution. Cependant, je suis en train d'obtenir un compte valide pour mon programme de test, qui est:Pourquoi ptrace singlestep renvoie-t-il un nombre d'instructions trop important lorsqu'il le lie statiquement?
int main(){
return 0;
}
Mon programme ptrace premier également retourné 90k + valeurs, donc je l'ai changé pour relier statiquement le programme de test utilisé. Le compteur est maintenant moins, mais toujours plus de 12k. Le programme que je comptais les instructions est:
#include <sys/ptrace.h>
#include <unistd.h>
#include <stdio.h>
int main() {
long long counter = 1; // machine instruction counter
int wait_val; // child's return value
int pid; // child's process id
int dat;
switch (pid = fork()) { // copy entire parent space in child
case -1: perror("fork");
break;
case 0: // child process starts
ptrace(PTRACE_TRACEME,0,NULL,NULL);
/*
must be called in order to allow the
control over the child process and trace me (child)
0 refers to the parent pid
*/
execl("./returntestprog","returntestprog",NULL);
/*
executes the testprogram and causes
the child to stop and send a signal
to the parent, the parent can now
switch to PTRACE_SINGLESTEP
*/
break;
// child process ends
default: // parent process starts
wait(&wait_val);
if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0)
perror("ptrace");
/*
switch to singlestep tracing and
release child
if unable call error.
*/
wait(&wait_val);
// parent waits for child to stop at next
// instruction (execl())
while (wait_val == 1407) {
counter++;
if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0)
perror("ptrace");
/*
switch to singlestep tracing and
release child
if unable call error.
*/
wait(&wait_val);
// wait for next instruction to complete */
}
/*
continue to stop, wait and release until
the child is finished; wait_val != 1407
Low=0177L and High=05 (SIGTRAP)
*/
}
printf("Number of machine instructions : %lld\n", counter);
return 0;
} // end of switch
Toute aide serait vraiment apprécié que je ne suis pas tout à fait sûr si cela fonctionne bien, ou pas du tout. Une fois que j'ai commencé cette chose, je veux travailler sur l'analyse de synchronisation avec ptrace, mais d'abord les choses d'abord et essayer de compter le nombre de instructions exécutées
merci!
Comment votre projet s'est-il déroulé? Avez-vous posté quelque chose à ce sujet? –