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 protected] <mailto:[email protected]>
Xcode Runtime Analysis Tools
> On Nov 17, 2014, at 12:04 PM, Beinan Li <[email protected]> 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 protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/xcode-users/katherine_stone%40apple.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com
This email sent to [email protected]