• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: No Breakpoints on Unused Variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: No Breakpoints on Unused Variables


  • Subject: Re: No Breakpoints on Unused Variables
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 09 Aug 2011 12:07:23 -0700

On Aug 9, 2011, at 11:29 , Gordon Apple wrote:

Why can I not set a breakpoint on an unused variable _expression_ so I can step into it?  Is there a setting I need to change?  (Diagnostic purpose.)

Answering "why?" questions when it comes to gdb is probably quixotic, but …

It's a somewhat unfortunate fact that the compilers Apple uses are *very* aggressive about shortening the effective lifetime of variables. I happen to think it has lousy usability in the Debug configuration, but you can probably file that opinion in the same place as "Snowballs, Chance in Hell".

The compiler has likely optimized your variable's lifetime away completely, which means there isn't anywhere you can set a breakpoint. It may additionally have optimized away the _expression_ itself. (However, if the _expression_ contains a function/method call, the compiler isn't allowed to discard that, because it might have side effects you're depending on.)

In order to preserve the ability to step into the _expression_, you'll have to use the variable in a subsequent _expression_ that the compiler doesn't also optimize away. In practical terms, this means you'll need to use the variable (or another variable that depends on it) as a parameter to a function/method call. The simplest approach might be to write your own dummy function:

static void WhatHo (…) {}

…
int myUnusedVariable = … some _expression_ … 
WhatHo (myUnusedVariable);



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >No Breakpoints on Unused Variables (From: Gordon Apple <email@hidden>)

  • Prev by Date: No Breakpoints on Unused Variables
  • Next by Date: Re: No Breakpoints on Unused Variables
  • Previous by thread: No Breakpoints on Unused Variables
  • Next by thread: Re: No Breakpoints on Unused Variables
  • Index(es):
    • Date
    • Thread