2

When attached to the debugger via Xcode, LLDB provides a useful view of local variables (the bottom left of the screenshot):

LLDB screenshot

I found an LLDB command frame variable (and gdb's info locals) that provides a list of the local variables (as seen in the right side of the screenshot above).

My hope is that this functionality is possible to perform on the device at runtime. For example, I can access the stack trace using backtrace_symbols(), the current selector via _cmd, and a few others.

Has anyone had experience in this area? Thanks in advance.

1
  • There's no way to access local variables in a manner similar to a debugger by just using the objective-c runtime (I'm not quite sure why you'd want to either). LLDB/GDB depend on debug information that will be missing in release builds of binaries. Commented May 19, 2014 at 22:52

1 Answer 1

4

Xcode/LLDB can show you this information because they have access to debug information in the binary, called a symbol table, which help it understand what memory locations correspond to which names in your source code. This is all outside the Objective-C runtime, and there's no interface in the runtime to get at it.

There's another reason why this won't work, though. When you're building code to run in the debugger, compiler optimizations are turned off, so all the variables you reference in your code are there.

When you build for release, though, generally the compiler optimizations get in there and re-arrange all your carefully named local variables to make things run faster. They might not even ever get stored in memory, just in CPU registers. Or they might not exist at all, if the optimizer can prove to itself that it doesn't need them.

My advice is to think again about the larger problem you're trying to solve...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.