mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "chengjian (D)" <cj.chengjian@huawei.com>
To: <catalin.marinas@arm.com>, <will.deacon@arm.com>,
	<oleg@redhat.com>, <linux@armlinux.org.uk>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	"chengjian (D)" <cj.chengjian@huawei.com>,
	"Xiexiuqi (Xie XiuQi)" <xiexiuqi@huawei.com>,
	Li Bin <huawei.libin@huawei.com>
Subject: A issue about ptrace/SINGLESTEP on arm64
Date: Mon, 16 Oct 2017 12:27:17 +0800	[thread overview]
Message-ID: <8ad32f6b-e04d-98f8-d944-7ec3582fbdf4@huawei.com> (raw)

Hi
I write demo use ptrace/SINGLESTEP to count the number of instructions 
executed by the process
The parent process fork+exec a child process, and trace(SINGLESTEP) it,

It works fine under the x86_64 architecture but has an exception under 
arm64.

```cpp
//demo.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>

#include <unistd.h>

#ifdef DEBUG
#define dprintf printf
#else
#define dprintf 0 && printf
#endif


int main(int argc, char *argv[])
{
     long long counter = 0;
     int wait_val;
     int pid;

     puts("Please wait");

     switch (pid = fork()) {
     case -1:
         perror("fork");
         break;

     case 0:
         ptrace(PTRACE_TRACEME, 0, 0, 0);
         execl("/bin/ls", "ls", NULL);
         break;

     default:
         //ptrace(PTRACE_ATTACH, pid, NULL, NULL);
         //waitpid(pid, &wait_val, 0);
          //while (wait_val == 1407 ) {
          while ( 1 )
          {
             wait(&wait_val);
             if(WIFEXITED(&wait_val)) {
                 break;
             }
             counter++;
             if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0)
                 perror("ptrace");
             else
             dprintf("counter = %lld\n", counter);
         }
     }

     printf("Number of machine instructions : %lld\n", counter);
     return 0;
}
```

It run for a long long time and seems never to stop.


./demo /bin/ls


     counter = 8033129
     counter = 8033130
     counter = 8033131
     counter = 8033132
     counter = 8033133
     counter = 8033134
     counter = 8033135
     counter = 8033136
     counter = 8033137
     counter = 8033138
     counter = 8033139
     ^C




It return the same results when track other the other C processes
And then I make an assembly demo(just print Hello-World),

It looks just all right

```asm
//hello.s
// as hello.s –o hello.o
// ld hello.o –o hello
.text //code section
.globl _start
_start:
     mov x0, 0     // stdout has file descriptor 0
     ldr x1, =msg  // buffer to write
     mov x2, len   // size of buffer
     mov x8, 64    // sys_write() is at index 64 in kernel functions table
     svc #0        // generate kernel call sys_write(stdout, msg, len);
     mov x0, 123 // exit code
     mov x8, 93  // sys_exit() is at index 93 in kernel functions table
     svc #0      // generate kernel call sys_exit(123);
.data //data section
msg:
     .ascii      "Hello, ARM!\n"
len = . - msg
```



./demo ./hello


     ./hello : hello

     Please wait
     Hello, ARM!
     Number of machine instructions : 8


I want to know what's going on about it, Is this a bug?

             reply	other threads:[~2017-10-16  4:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-16  4:27 chengjian (D) [this message]
2017-10-16 15:30 ` Will Deacon
2017-10-17  2:04   ` chengjian (D)
2017-10-17  9:23     ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ad32f6b-e04d-98f8-d944-7ec3582fbdf4@huawei.com \
    --to=cj.chengjian@huawei.com \
    --cc=catalin.marinas@arm.com \
    --cc=huawei.libin@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=oleg@redhat.com \
    --cc=will.deacon@arm.com \
    --cc=xiexiuqi@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome