From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751745AbdJPE2F (ORCPT ); Mon, 16 Oct 2017 00:28:05 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8456 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751126AbdJPE2E (ORCPT ); Mon, 16 Oct 2017 00:28:04 -0400 From: "chengjian (D)" To: , , , , , , "chengjian (D)" , "Xiexiuqi (Xie XiuQi)" , Li Bin Subject: A issue about ptrace/SINGLESTEP on arm64 Message-ID: <8ad32f6b-e04d-98f8-d944-7ec3582fbdf4@huawei.com> Date: Mon, 16 Oct 2017 12:27:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.219.85] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.59E43536.004D,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: ccb9ded9746c0820c61a96bc083b88c1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 #include #include #include #include #include #include #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?