gdb/arm-tdep.c: Remove "Infinite loop detected" error message.

Message ID 527D12A4.6070109@linaro.org
State Accepted
Headers show

Commit Message

Will Newton Nov. 8, 2013, 4:34 p.m.
Since as far back as the beginning of the sourceware repository
the ARM port has printed an error "Infinite loop detected" when
the next_pc calculated is the same as the current one, for example
when encountering a branch to the current PC address.

This causes the test gdb.base/random-signal.exp as the error message
is not expected. I have not been able to find a good reason for the
message to be here so remove it and let the test pass.

gdb/ChangeLog:

2013-11-08  Will Newton  <will.newton@linaro.org>

	* arm-tdep.c (arm_get_next_pc): Remove "Infinite loop detected"
	error message.
---
 gdb/arm-tdep.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Richard Earnshaw Nov. 19, 2013, 3:06 p.m. | #1
On 08/11/13 16:34, Will Newton wrote:
> 
> Since as far back as the beginning of the sourceware repository
> the ARM port has printed an error "Infinite loop detected" when
> the next_pc calculated is the same as the current one, for example
> when encountering a branch to the current PC address.
> 
> This causes the test gdb.base/random-signal.exp as the error message
> is not expected. I have not been able to find a good reason for the
> message to be here so remove it and let the test pass.
> 
> gdb/ChangeLog:
> 
> 2013-11-08  Will Newton  <will.newton@linaro.org>
> 
> 	* arm-tdep.c (arm_get_next_pc): Remove "Infinite loop detected"
> 	error message.

I guess the reasoning for this is that you can't single-step a
'branch-to-self' instruction, since the next instruction (where the new
breakpoint has to go) is the same as the current instruction.

However, it ought to be the higher levels of GDB that handle this, not
some random low-level function like get-next-pc.

Ok.

R.
Pedro Alves Nov. 19, 2013, 4:30 p.m. | #2
On 11/19/2013 03:06 PM, Richard Earnshaw wrote:
> On 08/11/13 16:34, Will Newton wrote:
>>
>> Since as far back as the beginning of the sourceware repository
>> the ARM port has printed an error "Infinite loop detected" when
>> the next_pc calculated is the same as the current one, for example
>> when encountering a branch to the current PC address.
>>
>> This causes the test gdb.base/random-signal.exp as the error message
>> is not expected. I have not been able to find a good reason for the
>> message to be here so remove it and let the test pass.
>>
>> gdb/ChangeLog:
>>
>> 2013-11-08  Will Newton  <will.newton@linaro.org>
>>
>> 	* arm-tdep.c (arm_get_next_pc): Remove "Infinite loop detected"
>> 	error message.
> 
> I guess the reasoning for this is that you can't single-step a
> 'branch-to-self' instruction, since the next instruction (where the new
> breakpoint has to go) is the same as the current instruction.

You should.  It should stop again in the same place.

> However, it ought to be the higher levels of GDB that handle this, not
> some random low-level function like get-next-pc.
> 

I just tried it on x86-64 (on a gdb branch that makes x86 use
software single-step), and it works as expected:

(gdb) disassemble
Dump of assembler code for function main:
   0x000000000040049c <+0>:     push   %rbp
   0x000000000040049d <+1>:     mov    %rsp,%rbp
=> 0x00000000004004a0 <+4>:     jmp    0x4004a0 <main+4>
   0x00000000004004a2 <+6>:     pop    %rbp
   0x00000000004004a3 <+7>:     retq
End of assembler dump.
(gdb) si
6               asm ("here: jmp here");
(gdb) set debug infrun 1
(gdb) si
infrun: clear_proceed_status_thread (process 29432)
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT, step=1)
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 29432] at 0x4004a0
next pc: 0x4004a0 ==> 0x4004a0
infrun: inserting single-step breakpoint at 0x4004a0
infrun: wait_for_inferior ()
infrun: target_wait (-1, status) =
infrun:   29432 [process 29432],
infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: infwait_normal_state
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x4004a0
infrun: stepi/nexti
infrun: stop_stepping
6               asm ("here: jmp here");
(gdb)
Will Newton Nov. 20, 2013, 11:02 a.m. | #3
On 19 November 2013 15:06, Richard Earnshaw <rearnsha@arm.com> wrote:
> On 08/11/13 16:34, Will Newton wrote:
>>
>> Since as far back as the beginning of the sourceware repository
>> the ARM port has printed an error "Infinite loop detected" when
>> the next_pc calculated is the same as the current one, for example
>> when encountering a branch to the current PC address.
>>
>> This causes the test gdb.base/random-signal.exp as the error message
>> is not expected. I have not been able to find a good reason for the
>> message to be here so remove it and let the test pass.
>>
>> gdb/ChangeLog:
>>
>> 2013-11-08  Will Newton  <will.newton@linaro.org>
>>
>>       * arm-tdep.c (arm_get_next_pc): Remove "Infinite loop detected"
>>       error message.
>
> I guess the reasoning for this is that you can't single-step a
> 'branch-to-self' instruction, since the next instruction (where the new
> breakpoint has to go) is the same as the current instruction.
>
> However, it ought to be the higher levels of GDB that handle this, not
> some random low-level function like get-next-pc.

Thanks, applied.

Single stepping an infinite loop works before and after this patch,
the patch just prevents an error message getting printed on every
step.

Patch

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 1ed21ea..035894c 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -4970,17 +4970,9 @@  arm_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
   CORE_ADDR nextpc;

   if (arm_frame_is_thumb (frame))
-    {
-      nextpc = thumb_get_next_pc_raw (frame, pc);
-      if (nextpc == MAKE_THUMB_ADDR (pc))
-	error (_("Infinite loop detected"));
-    }
+    nextpc = thumb_get_next_pc_raw (frame, pc);
   else
-    {
-      nextpc = arm_get_next_pc_raw (frame, pc);
-      if (nextpc == pc)
-	error (_("Infinite loop detected"));
-    }
+    nextpc = arm_get_next_pc_raw (frame, pc);

   return nextpc;
 }