From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26569 invoked by alias); 8 Jun 2006 01:22:30 -0000 Received: (qmail 26548 invoked by uid 22791); 8 Jun 2006 01:22:26 -0000 X-Spam-Check-By: sourceware.org Received: from e2.ny.us.ibm.com (HELO e2.ny.us.ibm.com) (32.97.182.142) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 08 Jun 2006 01:22:22 +0000 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e2.ny.us.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id k581MJ1F009303 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 7 Jun 2006 21:22:19 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay02.pok.ibm.com (8.13.6/NCO/VER7.0) with ESMTP id k581MJCh221224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 7 Jun 2006 21:22:19 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id k581MIbr018148 for ; Wed, 7 Jun 2006 21:22:19 -0400 Received: from dufur.beaverton.ibm.com (dufur.beaverton.ibm.com [9.47.22.20]) by d01av04.pok.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id k581MISr018145 for ; Wed, 7 Jun 2006 21:22:18 -0400 Subject: Instrcutions that must not be stepped. From: PAUL GILLIAM Reply-To: pgilliam@us.ibm.com To: gdb@sources.redhat.com Content-Type: text/plain Date: Thu, 08 Jun 2006 02:27:00 -0000 Message-Id: <1149726000.10016.71.camel@dufur.beaverton.ibm.com> Mime-Version: 1.0 X-Mailer: Evolution 2.2.2 (2.2.2-5) Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-06/txt/msg00049.txt.bz2 On the PowerPC, there is a provision for an atomic read-modify-right sequence that is implemented using the "lwarx" and "stwcx" instructions. These do not guarantee an atomic operation, but will detect its failure. If threads are being used, then glibc functions use this sequence to implement a lock by looping back to the start of the sequence if it was not atomic. When gdb is stepping through a library function, which it does under some circumstances if there is no source for the function, it gets stuck in this loop because the sequence will never be recognized as atomic. The only solution is to check each instruction about to be stepped to see if it's an "lwarx". If not, step as usual. If it is, then analyze the instructions that follow; set a temporary breakpoint after the loop, do a 'continue' and then continue stepping normally after it's been hit. Does there currently exist an arch. independent way to detect instruction sequences that must not be single stepped? Failing that, is there some hook I can use to implement this for just the PowerPC? Should there be a new gdbarch member like 'single_step_nonstepable' that will detect and handle non-stepable sequences?. Or maybe a gdbarch member like 'find_end_of_nonstepable_sequence' that returns 0 if the instruction about be be stepped is not the the start of a non-stepable sequence and the address of the end of the sequence (where to set a temp. break) if it is. Thanks for your help, -=# Paul #=- PS: The following hack prevents single-stepping a "lwarx" instruction. The user can then manually find the end of the sequence, put a temp. break there, continue, and then go back to stepping as normal. Before you get upset, remember I did say it was a hack and it actually allowed a teammate to make progress on an unrelated glibc bug. --- inf-ptrace.c 2006-01-24 14:34:34.000000000 -0800 +++ new.inf-ptrace.c 2006-06-07 13:59:02.000000000 -0700 @@ -326,6 +326,14 @@ if (step) { + /* Horrible hack: See if we are about to step an "lwarx" + instruction and abort with an error message if so. */ + long pc = (long) read_register (PC_REGNUM); + long inst = ptrace (PT_READ_I, pid, pc, 0); + + if ((inst & 0xfc0007fe) == 0x7C000028) + perror_with_name (("(barf) lwarx (barf)")); + /* If this system does not support PT_STEP, a higher level function will have called single_step() to transmute the step request into a continue request (by setting breakpoints on