Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watch Expression in Xcode

Say I am debugging. Say I need to know what the value of [somevariable count]

How would I do so?

like image 787
user4951 Avatar asked Apr 25 '11 14:04

user4951


People also ask

How do you evaluate expressions in Xcode?

Evaluate a C/ObjC/C++ expression in the current program context, using user defined variables and variables currently in scope. This command takes 'raw' input (no need to quote stuff). -G <gdb-format> ( --gdb-format <gdb-format> ) Specify a format using a GDB format specifier string.

How do I add variables to watch Xcode?

Right click in the local variables window to see the "Watch Expression" menu command. Type the variable name and the variable will be added.

What is LLDB in Xcode?

LLDB is the system debugger on macOS, iPadOS, iOS, tvOS, and watchOS. It can also be used for Objective-C and Swift development for architectures: x86_64. i386, ARM and AArch64, and default debugger in Xcode on macOS. It supports debugging on desktop, in simulators and devices.

How do I trace in Xcode?

Use the bt command in (lldb). Once paused or after a crash, just type bt into the debug console. It will print the full stack trace. Awesome tip for tracking down a constraint issue after setting the symbolic breakpoint.


2 Answers

If what you want to do is know the value of the expression while program execution is halted, then do something like

> p (int)[somevariable count] 

in the gdb console.

Note: People searching for the term "watch" might be expecting an answer about being able to observe when a value changes. For that question these are some answers that are more appropriate:

Watching variables in Xcode

Xcode LLDB watchpoints

like image 190
ThomasW Avatar answered Oct 03 '22 08:10

ThomasW


Put a breakpoint on the relevant code line. When Xcode stops on that line, in the debug area (the bottom of the screen is splitted to two parts, look at the right one, if you don't see the bottom part, shift+cmd+Y, plus sometimes the right side or the left side are hidden and there are small buttons on the right bottom side to show them), you see all of the local and global variables. Right click (or two fingers) that debug area, and you will see a context menu with one of the options "add expression". Type in your expression.

Note: above previous user's comment about the word "watch" is pretty clear to whomever comes from any other IDE but not in Xcode.

like image 29
Elad Lavi Avatar answered Oct 03 '22 08:10

Elad Lavi