Take_home_Test_1_GDB_Nov_6_2023

pdf

School

The City College of New York, CUNY *

*We aren’t endorsed by this school

Course

342

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

5

Uploaded by DoctorKouprey15874

Report
LAST NAME: FIRST NAME : Test Home-work CSC 342 November 6-7 , 2023 Submit on Slack DM to instructor by 11:58PM on November 7, 2023 Please bring Hard COPY of this completed TEST to the next class at 2:00 PM Please circle major: Computer Science or Engineering You should allocate no more than 4 hours for this test. Start Time and date: End TIME and date: You can use any resource. You are not allowed to communicate with fellow students or other professionals. The exam has 12 questions on 5 pages. THIS IS NOT A TEAM PROJECT!! Please keep in mind that addresses may vary on different platforms. This test is based on LINUX, GCC, and GDB, or MAC on i7. Please use handout for MAC reference. On MAC please use for debugger lldb instead of gdb. 1. Create file quiz.cpp int main() { int a = -1; int b = -2; int m = 0x7fffffff; int n = 0x80000000; int c = a + b; return 0; } 1. Compile gcc -g -o0 quiz.cpp -o qq 2. gdb qq GNU gdb (GDB) Fedora 7.7.1-21.fc20 Copyright (C) 2014 Free Software Foundation, Inc. Follow the steps. You may create your own debug session. You will have to answer questions.
LAST NAME: FIRST NAME : Test Home-work CSC 342 November 6-7 , 2023 Submit on Slack DM to instructor by 11:58PM on November 7, 2023 (gdb) break main Breakpoint 1 at 0x4004f4: file quiz.cpp, line 4. (gdb) run Starting program: ……/Quiz_GDB/qq Breakpoint 1, main () at quiz.cpp:4 4 int a = -1; (gdb) disassemble Dump of assembler code for function main(): 0x00000000004004f0 <+0>: push %rbp 0x00000000004004f1 <+1>: mov %rsp,%rbp => 0x00000000004004f4 <+4>: movl $0xffffffff,-0x4(%rbp) 0x00000000004004fb <+11>: movl $0xfffffffe,-0x8(%rbp) 0x0000000000400502 <+18>: movl $0x7fffffff,-0xc(%rbp) 0x0000000000400509 <+25>: movl $0x80000000,-0x10(%rbp) 0x0000000000400510 <+32>: mov -0x8(%rbp),%eax 0x0000000000400513 <+35>: mov -0x4(%rbp),%edx 0x0000000000400516 <+38>: add %edx,%eax 0x0000000000400518 <+40>: mov %eax,-0x14(%rbp) 0x000000000040051b <+43>: mov $0x0,%eax 0x0000000000400520 <+48>: pop %rbp 0x0000000000400521 <+49>: retq End of assembler dump. Question 1. (10 points) What is the program length in bytes in memory? Please show your work. Question 2. (10 points) Can you list all instructions of length 1 byte 2 bytes 3 bytes 4 bytes 5 bytes 6 bytes
LAST NAME: FIRST NAME : Test Home-work CSC 342 November 6-7 , 2023 Submit on Slack DM to instructor by 11:58PM on November 7, 2023 7 bytes Question 3. (5 points) Use gdb command to print the content of instruction pointer register. Show the command and the output. Question 4. (5 points) Use gdb command to print the content of base pointer register. Show the command and the output. Question 5. (5 points) Use gdb command to print the content of stack pointer register. Show the command and the output. Question 6. (10 points) Use gdb command to print the content and the address of 4-byte word on stack at a offset -4 from base pointer. Question 7. (5 points) What is the address of instruction that will be executed next step? Question 7.1(5 points) Please write down this machine instruction here. Use gdb commands to do that. Question 9. (5 points) What is the value stored in base pointer register?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
LAST NAME: FIRST NAME : Test Home-work CSC 342 November 6-7 , 2023 Submit on Slack DM to instructor by 11:58PM on November 7, 2023 Question 10. (5 points) What is the value stored in stack pointer register? Question 11. (10 points) Use gdb commands to print out all machine instructions. Please list each gdb command to print the address and the corresponding machine instruction.
LAST NAME: FIRST NAME : Test Home-work CSC 342 November 6-7 , 2023 Submit on Slack DM to instructor by 11:58PM on November 7, 2023 Question 12. (5 points) Use gdb commands to print out stack starting from base pointer. 12.1 (5 points) What is the offset in decimal and hex from base pointer to local variable a on the stack?