Using VSCode's debugger you can quickly find bugs!
Objective
We will work with the VSCode debugger to extract a few values from the program and change a variable in the middle of execution.
You can follow the more detailed steps here or use the less detailed comments in the code
Requirements
- Set Breakpoints:
- Click to the left of the line number in your source code where you want to pause the execution.
- For your first debugging challenge, we will set a breakpoint on line 22, with the line
- A red dot appears, indicating a breakpoint is set.
- You can set multiple breakpoints.
- Start Debugging:
- Click the Debugging Button in the side bar
- Then press F5 or click on the green play button in the Debug Side Bar to start debugging.
- The debugger will start and pause at the first breakpoint encountered.
- Inspecting Variables and State:
- When the debugger pauses, you can hover over variables in your code to see their current values.
- The Debug Side Bar will also show variables, call stack, and breakpoints.
- When you stop for the first time, expand the variables heading in the Debug Side Bar
- Under that section, you'll see
x
, new_value
, and plain_value
- Execution Tool Bar:
- Use the top control bar (appearing during debugging) to continue (F5), step over (F10), step into (F11), step out (Shift+F11), or stop (Shift+F5) the debugging process.
- Continue (F5) restarts the execution until the next breakpoint is reached
- Step Over (F10) executes the next line in the program but does not go into a function call
- Step into (F11) works like Step Over but it steps into a function call.
- Step Out (Shift-F11) will continue executing until the end of the current function is reached.
- Control Execution:
- The program should be stopped at line the breakpoint, in the variables window, x will be 0
- You will want to use either the continue (F5) or the Step Over (F10) to move the execution forward until you reach the breakpoint line and the value of x is 2
- Write down the hex value of
new_value
(x is 2)
- Step through again until reaching the print statement again, x should now be 3
- Write down the hex value of new_value (x is 3)
- Change new_value's value
- While still at the location from the last step (step 5) and stopped at line 18, where x==2 after looping three times
- Change the value of
new_value
to 'b' which is 0x62 in hex by double clicking it and entering 'b'
- Complete the programs execution
- Remove the breakpoint by clicking on the red dot
- Click Continue (F5)
- Write down the "Final value" printed out by the program
- Get Flag
- Execute
/challenge/getflag
and enter in the 3 values you wrote down
- You are done!