• 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: lldb expression shows wrong variable values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lldb expression shows wrong variable values


  • Subject: Re: lldb expression shows wrong variable values
  • From: Kate Stone <email@hidden>
  • Date: Tue, 18 Nov 2014 17:50:06 -0800

The behavior you’re seeing is the result of not knowing the function declaration for the symbol printf, which results in the LLDB _expression_ evaluator trying to guess and getting it wrong.  Specifically, the inferred calling convention for the case you cite is that of function that takes two parameters (a string followed by an unsigned int) whereas the reality is that printf is a variadic function that takes an arbitrary number of parameters.  This isn’t a problem on x86 where the calling conventions happen to be identical for these two cases, but on arm64 the distinction matters.

You can add definitions for functions like printf that you intend to use as follows:

1. Edit ~/.lldbinit to add the following line:

settings set target.expr-prefix ~/.lldb-expr-prefix

2. Create the file ~/.lldb-expr-prefix with the following content:

extern “C”
{
    int printf(const char * __restrict, …);
}

3. Restart the debug session

This results in every _expression_ implicitly including the appropriate function declaration for printf(), which has the pleasant side effect of eliminating the need to cast the results of the call.  The same technique can be extended to any declaration that you find yourself needing on a regular basis.  The only downside to doing so is the potential for getting two conflicting definitions, one derived from debug information and the other from your _expression_ prefix.

Kate Stone email@hidden
 Xcode Runtime Analysis Tools

On Nov 17, 2014, at 12:04 PM, Beinan Li <email@hidden> wrote:

Hello Xcode,

I used to use breakpoint action:
"""
expr (int) printf("X is: %u\n", x)
"""

to print out local variables.

Now with Xcode 6.1 on an ARM64, I just get all sorts of wrong values.

For example:

code: 

unsigned int x = 10800;

The above debug action gives me:

(int) $0 = 15
X is: 55574528

What am I missing here?

Thanks,
Beinan

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: 
 >lldb expression shows wrong variable values (From: Beinan Li <email@hidden>)

  • Prev by Date: Re: Any way to prevent Xcode SourceKitService crashing?
  • Next by Date: findExportedSymbol crash
  • Previous by thread: lldb expression shows wrong variable values
  • Next by thread: findExportedSymbol crash
  • Index(es):
    • Date
    • Thread