Up and Running
23
5. Because the next line calls
step_function
,
select
Debug
4
Step Into
to
call
step_function
and break on the first line. You can continue debug-
ging this function by stepping into/over its instructions. By default, the
keyboard shortcut for step into is F11.
6. To allow
execution to return to
main
, select
Debug
4
Step Out
. By
default, the keyboard shortcut for this operation is
shift
-F11.
7. Inspect the
Autos window by selecting
Debug
4
Windows
4
Auto
. You
can see the current value of some of the important variables, as shown
in Figure 1-6.
Figure 1-6: The Autos window shows the values of variables at the current breakpoint.
You can see
num1
is set to 42 and
result1
is set to 1. Why does
num2
have a gibberish value? Because the initialization to 0 hasn’t
happened
yet: it’s the next instruction to execute.
N O T E
The debugger has just emphasized a very important low-level detail: allocating an
object’s storage and initializing an object’s value are two distinct steps. You’ll learn
more about storage allocation and object initialization in Chapter 4.
The Visual Studio debugger supports many more features. For more
information, check out the Visual Studio documentation
link available at
https://ccc.codes/.
Xcode
Xcode also has an excellent, built-in debugger that’s completely integrated
into the IDE.
1. Open
main.cpp and
locate the first line of
main
.
2. Click the first line and then select
Dostları ilə paylaş: