Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This project helps you to use gdb, the GNU debugger to run a C/C++ program under the cygwin environment. Firstly, you need to use a
This project helps you to use gdb, the GNU debugger to run a C/C++ program under the cygwin environment. Firstly, you need to use a plaintext editor to create the source code and name it as project1.cpp. Secondly, you need to use the gec, the C++ compiler to compile and link the source code into a loadable module and name it as projectl.exe. Then you can use gdb to run the program step by step. examine a memory location, check the contents of CPU registers, and debug the program. 1. Project Description Source Code: // Student Name: // Student ID: // projectl.cpp #include int main() { register int wye; int *ptr: int ex; // request that wye is stored in a CPU register ptr=&ex; ex = 305441741; wye = -1; printf(\"Enter an integer: \"); scanf(\"%i\", ptr); wye - *ptr; printf(\"The result is %i \", wye); return 0; } Steps to follow: 1) After you have created your source code, open cygwin window and change to your corresponding directory. Following the window's prompt $, type the following command line and the press the enter key, $ gcc -g -00-Wall -o project projectl.cpp In the above command line, -* are gcc options. Correct any typo or mistake in your source code until you get the executable module projectl.exe. 2) Type the following command in the cygwin window: S gdb /project 1 It will display the gdb related information. 3) Type the following command following the (gdb) prompt:: (gdb) li 11 1 // Student Name: // Student ID: // project1.cpp #include amno. int main() { register int wye; int *ptr; int ex; // request that wye is stored in a CPU register ptr = &ex; ex = 305441741; 7 8 9 10 11 12 13 (gdb) 14 15 16 17 18 19 20 21 (gdb) wye = -1; printf(\"Enter an integer: \"); scanf(\"%i\", ptr); wye +- *ptr; printf(\"The result is i \", wye); return 0; 3 Where Ox 40114 is an address in hexadecimal. This address may change from machine to machine and from time to time. 5) Run the program: (gdb) run Starting program: */.../project 1 Breakpoint 1. main) at project.cpp:15 15 printf(\"Enter an integer: \"); (gdb) 6) Type the following commands: (gdb) print ex SI = 305441741 (gdb) print &ex S2 = (int) 0x62cc28 (gdb) 7) Type the following command: (gdb) help x Examine memory: x/FMT ADDRESS. The help command will provide very brief instructions on using a command. The x command is to examine the memory given an address. 8) Examine a memory location and multi-byte arrangement: (gdb) x/1dw Ox62cc28 Ox62cc28: 305441741 (gdb) x/lxw Ox62cc28 Ox62cc28: Ox 1234abcd (gdb) x/4xb Ox62cc28 Ox62cc28: Oxcd Oxab Ox34 Ox12 (gdb) In memory location Ox62cc28 (i.e., &ex), the integer stored is 305441741 in decimal, 0x 1234abcd in hexadecimal, it is 4-byte little endian storage (i.c., the least significant byte comes first): 0x62cc28: Oxcd Ox62cc29: Oxab Ox62cc2a: 0x34 Ox62cc2b: 0x12 9) Check other variable and locations: (gdb) print ptr S3 = (int) 0x62cc28 (gdb) print & per S4 (int **) Ox62cc2c (gdb) print wye SS-1 (gdb) print &wye Address requested for identifier \"wye\" which is in register Sebx (gdb) 10) Display register information: (gdb) ir Ox62cc28 CCX Ox0 cdx Ox0 cbx Oxfm esp Ox62cc10 ebp Ox62cc38 esi Ox8004952e edi Ox8004953a eip 0x4011a4 eflags 0x246 CS Ox23 SS Ox2b ds Ox2b es Ox2b fs Ox53 ES 0x25 (gdb) 6474792 0 0 - 1 Ox62cc10 Ox62cc38 -2147183314 -2147183302 0x4011a4 ()+36)>, what are the meanings the option -g, -00, -Wall, and -o? 3) How to run gdb with an executable.exe? 4) How to view the lines in the source code? 5) How to setup a break point in a program? 6) How to execute the executable.exe step by step? 7) How to view a variable content? 8) How to view CPU registers? 9) How to continue the execution after a break point? 10) How to examine memory? A
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started