1 00:00:00,380 --> 00:00:01,370 Hello, my name is Tayfun. 2 00:00:01,370 --> 00:00:04,970 And in this lecture we will step through the program with the debugger. 3 00:00:04,970 --> 00:00:08,900 Now, as we did in previous lecture, we will look at our program again. 4 00:00:08,900 --> 00:00:14,720 So actually, let's run it our Hello program that we will assemble a program, assembler language. 5 00:00:14,720 --> 00:00:17,300 And here this is our source code for it. 6 00:00:17,300 --> 00:00:21,560 So we will gdb hello again and that's it. 7 00:00:21,560 --> 00:00:26,300 So here what we're going to do is we will firstly. 8 00:00:27,150 --> 00:00:27,360 It. 9 00:00:28,530 --> 00:00:35,400 We will we will put a break in the program, which is pausing the execution and allowing us to examine 10 00:00:35,400 --> 00:00:36,540 a number of things. 11 00:00:36,540 --> 00:00:39,180 So here we will do break main. 12 00:00:39,330 --> 00:00:46,470 So here, as you can see here, it gave us output a breakpoint at, uh, 40 1110 file. 13 00:00:46,470 --> 00:00:46,740 Hello. 14 00:00:47,460 --> 00:00:49,950 And in line eight. 15 00:00:49,950 --> 00:00:53,070 And now in our case, this is the output here. 16 00:00:53,070 --> 00:00:53,340 So. 17 00:00:53,340 --> 00:00:57,900 But this memory numbers will be different at your PC. 18 00:00:58,380 --> 00:01:04,590 And now what we're going to do is we will run the program now run. 19 00:01:04,590 --> 00:01:07,590 And as you can see here, we also have the breakpoint here. 20 00:01:07,590 --> 00:01:13,980 So the debugger stops at the break and throws the next instruction that will be executed. 21 00:01:13,980 --> 00:01:20,880 So that is, uh, move here, move rax one is not executed yet. 22 00:01:21,460 --> 00:01:26,170 And now we will type this info registers here. 23 00:01:26,170 --> 00:01:31,400 And as you can see, we this is the gdb returns the output here. 24 00:01:31,420 --> 00:01:32,170 So. 25 00:01:32,920 --> 00:01:41,140 The content of these registers is not that important now, except for this recipe. 26 00:01:41,260 --> 00:01:44,680 Here we will, as you can see here, our IP. 27 00:01:45,100 --> 00:01:47,950 So the instructor instruction pointer. 28 00:01:47,950 --> 00:01:57,960 So the register our IP has the value of 40 1110, which is the memory address of the next instructions 29 00:01:57,970 --> 00:01:59,320 to execute. 30 00:01:59,350 --> 00:02:08,800 So remember, we put the breakpoint at the four 1110, and this is the same address for 11 1040 1110, 31 00:02:09,310 --> 00:02:09,880 same address. 32 00:02:09,880 --> 00:02:10,430 Right. 33 00:02:10,450 --> 00:02:15,100 So here, this points to the first instruction. 34 00:02:15,830 --> 00:02:19,040 And we also have mov rax one gdb. 35 00:02:19,820 --> 00:02:24,530 Let's actually put this somewhere move rax one gdb here. 36 00:02:25,190 --> 00:02:32,360 This stops and gdb stops just before the instructions and waits for your command. 37 00:02:33,180 --> 00:02:34,410 And it is not important. 38 00:02:34,410 --> 00:02:35,940 And it's sorry. 39 00:02:35,940 --> 00:02:42,390 It's important to remember that the instruction pointed to by RIP here. 40 00:02:42,420 --> 00:02:44,910 This rip is not executed. 41 00:02:45,520 --> 00:02:46,920 Not yet executed here. 42 00:02:46,920 --> 00:02:54,410 So in your case gdb may show something different from the 40 1110 that and that's okay. 43 00:02:54,420 --> 00:03:01,260 It is the address of that particular line in memory and which may be different depending on depending 44 00:03:01,260 --> 00:03:02,700 on your computer configuration. 45 00:03:02,700 --> 00:03:05,520 But in most cases it will be different than this. 46 00:03:05,520 --> 00:03:08,580 And now we will type the step. 47 00:03:09,850 --> 00:03:10,330 Yep. 48 00:03:10,540 --> 00:03:15,940 And as you can see here, we have this here now, which is the now we will also. 49 00:03:17,480 --> 00:03:19,900 Type I and are here. 50 00:03:19,910 --> 00:03:22,820 So this is the abbreviation for info registers. 51 00:03:22,820 --> 00:03:28,820 As you can see here I if stands for EHR info and r for registers. 52 00:03:30,460 --> 00:03:33,400 And after that we will get this output here. 53 00:03:33,490 --> 00:03:41,800 Now indeed Rax contains now zero here, 00X1 here actually. 54 00:03:42,700 --> 00:03:44,620 And here. 55 00:03:45,360 --> 00:03:47,100 0X11. 56 00:03:48,030 --> 00:03:50,850 And and the rip here. 57 00:03:50,880 --> 00:03:55,940 The rip here contains the address of the next instruction to execute. 58 00:03:55,950 --> 00:04:05,650 So we can also step further through the program and notice that how RSI receives the address of message. 59 00:04:05,880 --> 00:04:11,040 A message which prints the Hello World on the screen and exits. 60 00:04:11,040 --> 00:04:19,860 And notice also how Rip Rip points every time to the next instruction to execute. 61 00:04:19,950 --> 00:04:28,740 And here we also I want to discuss here is also some additional GDB commands here which is the break 62 00:04:28,740 --> 00:04:35,340 here or b sets a break point as we have done before in this lecture. 63 00:04:35,340 --> 00:04:39,570 So for example, we can also disable this uh, break point here. 64 00:04:39,570 --> 00:04:42,720 So disable break point. 65 00:04:42,990 --> 00:04:44,070 Uh, break. 66 00:04:45,940 --> 00:04:46,660 Point. 67 00:04:46,660 --> 00:04:49,270 And after that, you will enter the number in this case, actually. 68 00:04:49,360 --> 00:04:53,350 As you can see, this is the main is not the breakpoint number here. 69 00:04:54,530 --> 00:05:00,980 But also we also can, after disabling it, enable the break point again. 70 00:05:03,430 --> 00:05:04,150 Like this. 71 00:05:04,480 --> 00:05:06,910 And we also have the continue. 72 00:05:08,380 --> 00:05:14,590 Or see this is the continue the execution until the next breakpoint. 73 00:05:14,620 --> 00:05:21,400 As you can see here, we don't have we don't have breakpoints except that main breakpoint here with. 74 00:05:23,190 --> 00:05:26,160 And that's why our program exited normally. 75 00:05:26,160 --> 00:05:28,020 So our program done executed. 76 00:05:28,020 --> 00:05:35,580 And we also have the next we have this is to step over the current line and stop at the next line. 77 00:05:35,760 --> 00:05:38,360 So we also have help. 78 00:05:38,370 --> 00:05:42,330 This shows the help here, help or age. 79 00:05:43,180 --> 00:05:43,660 So. 80 00:05:45,070 --> 00:05:46,120 As you can see here. 81 00:05:46,120 --> 00:05:55,210 And we also have to enable this is enables the text user interface and to disable it, you can simply 82 00:05:55,210 --> 00:06:04,300 write why disable and we can also which you learned in previous lecture actually um, print and also 83 00:06:04,300 --> 00:06:07,750 print the value of a variable registers and so on. 84 00:06:08,480 --> 00:06:11,480 So now let's actually see some examples here. 85 00:06:11,510 --> 00:06:14,270 Uh, now we will print, uh, p. 86 00:06:14,570 --> 00:06:15,530 Racks. 87 00:06:15,560 --> 00:06:16,520 Racks here. 88 00:06:16,520 --> 00:06:21,320 And as you can see, there is a no registers because our program is already done executing. 89 00:06:21,380 --> 00:06:22,460 Now we will. 90 00:06:22,880 --> 00:06:24,710 Let's actually start this again. 91 00:06:24,740 --> 00:06:27,590 Clear the screen and gdb. 92 00:06:28,190 --> 00:06:28,580 Hello. 93 00:06:29,400 --> 00:06:34,800 And as you can see here, we started our, uh, debugging process from zero again. 94 00:06:34,800 --> 00:06:37,500 And now what we're going to do is we will start. 95 00:06:38,910 --> 00:06:40,410 We must set a break point. 96 00:06:40,620 --> 00:06:41,370 Break. 97 00:06:42,320 --> 00:06:43,890 Break main. 98 00:06:44,250 --> 00:06:48,640 And we can also enable or disable the break point as we did in previous. 99 00:06:48,660 --> 00:06:50,640 As you learned in here. 100 00:06:51,270 --> 00:06:51,960 In order to. 101 00:06:53,260 --> 00:06:53,680 Run it. 102 00:06:53,680 --> 00:06:59,290 So we will disable, as you can see here, when we set the break main here, we are getting this one 103 00:06:59,290 --> 00:07:03,820 number here so we can use it to disable break point. 104 00:07:03,820 --> 00:07:06,280 And after that we will set the number one. 105 00:07:06,280 --> 00:07:10,810 And as you can see, it's disabled and we can also delete the break point. 106 00:07:10,810 --> 00:07:13,360 So we disabled it but didn't delete it. 107 00:07:13,360 --> 00:07:17,320 So after that we can also enable a break point. 108 00:07:17,320 --> 00:07:26,710 So but if you deleted it, you need to define a Neve break Neve break here enable break point. 109 00:07:26,710 --> 00:07:31,840 And as you can see here, we also have the break point here enabled. 110 00:07:31,840 --> 00:07:34,870 And now we will delete the break point here. 111 00:07:34,870 --> 00:07:38,020 And after that you will enter the number and this is the list. 112 00:07:38,030 --> 00:07:45,610 So now if we enable this break point right now, enable break point one, we will get an error because 113 00:07:45,610 --> 00:07:47,710 the no break point number one. 114 00:07:47,710 --> 00:07:51,070 So now we will add our break point again. 115 00:07:51,070 --> 00:07:56,680 And after that we will run here or run our main program. 116 00:07:56,680 --> 00:08:01,690 And we will also use the info registers here that we did here. 117 00:08:01,690 --> 00:08:05,590 And as you can see, that's so this line is not executed. 118 00:08:05,590 --> 00:08:12,610 And now we will also get the info registers, info registers here and now. 119 00:08:14,920 --> 00:08:17,650 We will use this print function here. 120 00:08:17,770 --> 00:08:25,540 Now p here and this dollar sign rax and as you can see, we have this. 121 00:08:26,020 --> 00:08:26,740 And. 122 00:08:27,840 --> 00:08:29,250 P message here. 123 00:08:29,460 --> 00:08:34,510 As you can see, it's void because there's no message here, which the message is not stored. 124 00:08:35,190 --> 00:08:40,650 Variable type stored in the memory. 125 00:08:40,950 --> 00:08:44,020 So we need to get that memory address to print it out. 126 00:08:44,040 --> 00:08:45,930 In this case here. 127 00:08:49,700 --> 00:08:53,210 Of which we learned that in previous lecture. 128 00:08:53,210 --> 00:08:58,640 We did some examples to print the Hello world message using the GDB. 129 00:08:59,030 --> 00:09:07,430 And one important remark about the GDP is to properly use it, you must insert a function prologue and 130 00:09:07,430 --> 00:09:09,870 the function epilogue in your code. 131 00:09:09,890 --> 00:09:13,670 So I will show in the next sections how to do that. 132 00:09:13,670 --> 00:09:20,870 And in later sections we will discuss function, prologue and function epilogues when we talk about 133 00:09:20,870 --> 00:09:21,860 stack frames. 134 00:09:21,860 --> 00:09:27,980 So for short information, for short programs such as our Hello World program, there is no problem. 135 00:09:27,980 --> 00:09:35,810 But with longer and bigger and fancy programs, GDB will show an expected behavior if there is no prologue 136 00:09:35,810 --> 00:09:36,980 or epilogue. 137 00:09:36,980 --> 00:09:41,810 So play around with gdb refer to the online manual for example. 138 00:09:41,810 --> 00:09:46,190 You can also type the man gdb here man. 139 00:09:47,840 --> 00:09:48,380 EDB. 140 00:09:49,670 --> 00:09:50,900 So here. 141 00:09:51,950 --> 00:09:54,560 And in this case, I didn't get it any. 142 00:09:54,890 --> 00:09:55,610 So it's okay. 143 00:09:55,610 --> 00:10:02,660 But you can also find or find a lot of online manuals and get familiar with GDB because even when you 144 00:10:02,660 --> 00:10:09,470 use a graphical user interface debugger, some functionality may not be available or may not want to 145 00:10:09,470 --> 00:10:16,670 install the graphical user interface debugger on your system because GDB does all the job at 10 or 10 146 00:10:16,670 --> 00:10:17,390 out of ten. 147 00:10:17,390 --> 00:10:24,560 And now in the next lecture we will also create some assembly code, a slightly improved version of 148 00:10:24,560 --> 00:10:25,250 Hello World. 149 00:10:25,250 --> 00:10:27,200 So I'm meeting you in next lecture.