public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Debugging ARM noreturn functions
@ 2009-11-23 13:06 Paul Brook
  2009-11-24 13:58 ` Richard Earnshaw
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Brook @ 2009-11-23 13:06 UTC (permalink / raw)
  To: gcc-patches

The patch below addresses a long standing issue when debugging code that 
includes noreturn functions on ARM targets.

For somewhat nebulous performance reasons, the ARM backend decides not to save 
any registers in noreturn functions. While this is technically valid, it makes 
it impossible for the debugger to unwind past this point. A common example of 
this kind of function is abort(), so this happens more than you may first 
think.

This has been discussed a previously [*], and the compromise reached was to 
save just enough information to allow a backtrace to be obtained. In practice 
this means the link register (r14), and common frame pointer registers
(r7, r11). Conveniently the result is a more localized hack than the previous 
code.

Tested on arm-none-eabi.
Applied to SVN head.

Paul

[*] Unfortunately I've lost the link to these discussions.

2009-11-23  Paul Brook  <paul@codesourcery.com>

	gcc/
	* config/arm/arm.c (arm_compute_save_reg0_reg12_mask): Add special
	case for noreturn functions.
	(arm_compute_save_reg_mask): Remove special noreturn handling.

Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	(revision 154433)
+++ gcc/config/arm/arm.c	(working copy)
@@ -12831,6 +12831,20 @@ arm_compute_save_reg0_reg12_mask (void)
 	  && crtl->uses_pic_offset_table)
 	save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM;
     }
+  else if (IS_VOLATILE(func_type))
+    {
+      /* For noreturn functions we historically omitted register saves
+	 altogether.  However this really messes up debugging.  As a
+	 compromise save just the fame pointers.  Combined with the link
+	 register saved elsewhere this should be sufficient to get
+	 a backtrace.  */
+      if (frame_pointer_needed)
+	save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM;
+      if (df_regs_ever_live_p (ARM_HARD_FRAME_POINTER_REGNUM))
+	save_reg_mask |= 1 << ARM_HARD_FRAME_POINTER_REGNUM;
+      if (df_regs_ever_live_p (THUMB_HARD_FRAME_POINTER_REGNUM))
+	save_reg_mask |= 1 << THUMB_HARD_FRAME_POINTER_REGNUM;
+    }
   else
     {
       /* In the normal case we only need to save those registers
@@ -12917,11 +12931,6 @@ arm_compute_save_reg_mask (void)
       | (1 << LR_REGNUM)
       | (1 << PC_REGNUM);
 
-  /* Volatile functions do not return, so there
-     is no need to save any other registers.  */
-  if (IS_VOLATILE (func_type))
-    return save_reg_mask;
-
   save_reg_mask |= arm_compute_save_reg0_reg12_mask ();
 
   /* Decide if we need to save the link register.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Debugging ARM noreturn functions
  2009-11-23 13:06 Debugging ARM noreturn functions Paul Brook
@ 2009-11-24 13:58 ` Richard Earnshaw
  2009-11-24 14:06   ` Paul Brook
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Earnshaw @ 2009-11-24 13:58 UTC (permalink / raw)
  To: Paul Brook; +Cc: gcc-patches


On Mon, 2009-11-23 at 13:03 +0000, Paul Brook wrote:
> +        compromise save just the fame pointers.  Combined with the
> link

Frame pointers

R.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Debugging ARM noreturn functions
  2009-11-24 13:58 ` Richard Earnshaw
@ 2009-11-24 14:06   ` Paul Brook
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Brook @ 2009-11-24 14:06 UTC (permalink / raw)
  To: Richard Earnshaw; +Cc: gcc-patches

On Tuesday 24 November 2009, Richard Earnshaw wrote:
> On Mon, 2009-11-23 at 13:03 +0000, Paul Brook wrote:
> > +        compromise save just the fame pointers.  Combined with the
> 
> Frame pointers

Fixed, thanks.

Paul

2009-11-24  Paul Brook  <paul@codesourcery.com>

	gcc/
	* gcc/config/arm/arm.c (arm_compute_save_reg0_reg12_mask): Fix comment
	typo.

Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	(revision 154446)
+++ gcc/config/arm/arm.c	(working copy)
@@ -12835,7 +12835,7 @@ arm_compute_save_reg0_reg12_mask (void)
     {
       /* For noreturn functions we historically omitted register saves
 	 altogether.  However this really messes up debugging.  As a
-	 compromise save just the fame pointers.  Combined with the link
+	 compromise save just the frame pointers.  Combined with the link
 	 register saved elsewhere this should be sufficient to get
 	 a backtrace.  */
       if (frame_pointer_needed)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-24 14:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-23 13:06 Debugging ARM noreturn functions Paul Brook
2009-11-24 13:58 ` Richard Earnshaw
2009-11-24 14:06   ` Paul Brook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).