This preview shows page 1. Sign up to view the full content.
Unformatted text preview: gram to show values at this point Disassembly up through call to gets Figure 3.28: C and Disassembled Code for Problem 3.24. 170 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS
Practice Problem 3.24:
Figure 3.28 shows a (low quality) implementation of a function that reads a line from standard input, copies the string to newly allocated storage, and returns a pointer to the result. Consider the following scenario. Procedure getline is called with the return address equal to 0x8048643, register %ebp equal to 0xbffffc94, register %esi equal to 0x1, and register %ebx equal to 0x2. You type in the string “012345678901.” The program terminates with a segmentation fault. You run GDB and determine that the error occurs during the execution of the ret instruction of getline. A. Fill in the diagram below indicating as much as you can about the stack just after executing the instruction at line 6 in the disassembly. Label the quantities stored on the stack (e.g., “Return Address”) on the right, and their hexadecimal values (if known) within the box. Each box represents four bytes. Indicate...
View Full Document