Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a GDB script to do the following to the program `debuggingPractice.c`. 1.

ID: 2247810 • Letter: W

Question

Write a GDB script to do the following to the program `debuggingPractice.c`.

1. Break at the assignment of the loop in main and print the value of the general purpose registers.

2. Print "OVER " in GDB when the variable `i` is greater than 5. Do note that we expect a newline at the end of the print statement.

3. Set the variable `i` to `0xCAFE` when `i` reaches the value 10.

// compile with gcc -g debuggingPractice.c -o debuggingPractice.out

#include<stdio.h>

#include<stdlib.h>

void foo()

{

printf("In foo ");

}

void bar()

{

printf("In bar ");

exit(0);

}

int main()

{

int i = 0;

while(i < 20) {

printf("i is %#X ", i);

i++;

}

foo();

}

Explanation / Answer

gdb transcript:

(gdb) b main

Breakpoint 1 at 0x400575: file Sasi.c, line 15.

(gdb) b foo

Breakpoint 2 at 0x400535: file Sasi.c, line 3.

(gdb) b foo()

Breakpoint 3 at 0x400555: file Sasi.c, line 9.

(gdb) r

Starting program: /home/mohit/test/a.out

warning: the debug information found in "/lib64/ld-2.19.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).

Breakpoint 1, main () at Sasi.c:15

15    int i = 0;

(gdb) p &i

$1 = (int *) 0x7fffffffdf7c

(gdb) c

Continuing.

Breakpoint 2, fn1 () at Sasi.c:3

3     int j = 0;

(gdb) p &j

$2 = (int *) 0x7fffffffdf5c

(gdb) c

Continuing.

Breakpoint 3, fn2 () at Sasi.c:9

9     int k = 0;

(gdb) p &k

$3 = (int *) 0x7fffffffdf5c

(gdb)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote