Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction In your first project, you will develop a simple tool to investigate your process memory. Our goal is to form a better understanding of

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Introduction In your first project, you will develop a simple tool to investigate your process memory. Our goal is to form a better understanding of memory and pointers. You will also practice developing a multi-unit project. Note: For any standard library functions that you use, including those discussed here, you must consult the manual pages to understand them before using them in your code. Make this a habit to avoid spending unnecessary time searching for solutions or debugging issues that could have been avoided. Task In this proiect, we build a program with two units: memory.c and memorytest.c . Function: Print Memory Contents (in memory.c) Create a function that takes two pointer arguments: void *start_addr and void *end_addr. Your function must first print the start and end addresses. For memory contents, start from start_addr and print each 16 bytes of the memory contents on one line. Each line must begin with the starting address of the contents printed on that line. The data must be printed as a string of hexadecimal bytes followed by the same data as printable characters. You continue printing lines of 16-byte contents until the end_address is reached. (That will be the last line.) - Note that each byte is two digits in hex. - If the byte is not a printable character {you can use function isprintt) to check it), print . [dot] instead. Refer to the following for a sample of the output described above: Start Address: 0x7ffc7f8e24a7 End Address: 0x7ffc7f8e430e 0x7ffc7f8e24a7: 3e00b96c0f2074dcc710258e7ffc7f00 >. .1. t. ..%. . . . . 0x7ffc7f8e2467: 0008c431838c55000074657374696e67 . . .1. .U. . testing 0000 0000000900090998E800TE9907 : 207/738424+ZX0 f1. . .U. ... 0x7ffc7f8e24d7: 003fd031838c55000000008000640000 ?.1. . U. .....d. . 0x7ffc7f8e24e7: 000a00000000000000c0248e7ffc7f00 . $. . 0x7ffc7f8e24f7: 0000b96c0f2074dcc700438e7ffc7f00 . ..1. t. . .C.. 0x7ffc7f8e2507: 0000438e7ffc7f000040258e7ffc7f00 . . C. . . ...%. . 0x7ffc7f8e2517: 008cc431838c55000058268e7ffc7f00 . . .1. . U. .X& . . . . . 0x7ffc7f8e2527: 00e0b9b41f0100000000000000000000 0x7ffc7f8e2537: 0058268e7ffc7f000001000000000000 . X& . . . . . . 0x7ffc7f8e2547: 00d07c821f3e7f000040268e7ffc7f00 . . | . .>...&. . . . . 0x7ffc7f8e2557: 0028c431838c55000040603183010000 . (.1. . U. . @.1. ... 0x7ffc7f8e2567: 0058268e7ffc7f000058268e7ffc7f00 . X&. . . . . .X& . . . 0x7ffc7f8e2577: 00ee67eaa4f786972600000000000000 . .g. . . . .&. . 0x7ffc7f8e2587: 0068268e7ffc7f00000020b61f3e7f00 . h&. . . . . . . .>. . 0x7ffc7f8e2597: 00d8ed31838c550000ee6748eeeb796f . . .1. .U. ..gH. . yo 0x7ffc7f8e25a7: d9ee67e05df3b9ebd800000000000000 . .g. ]. .. 0x7ffc7f8e2567: 00000000000000000000000000000000 0x7ffc7f8e25c7: 0058268e7ffc7f000001000000000000 . X& . . 0x7ffc7f8e25d7: 0000b96c0f2074dcc700000000000000 .1. t. .. 0x7ffc7f8e25e7: 008a7d821f3e7f000028c431838c5500 . . }..>... (.1. .U. 0x7ffc7f8e25f7: 00d8ed31838c550000c032b61f3e7f00 . . . 1. . U. . .2..>.. 0x7ffc7f8e2607: 00000000000000000000000000000000 0x7ffc7f8e2617: 0090c031838c55000050268e7ffc7f00 .1. . U. . P&. . . 0x7ffc7f8e2627: 00000000000000000000000000000000 0x7ffc7f8e2637: 00b5c031838c55000048268e7ffc7f00 . . .1. . U. . H& . . . . . >> 0x7ffc7f8e41f7: 00000000000000000000000000000000 0x7ffc7f8e4207: 00000000000000000000000000000000 0x7ffc7f8e4217: 00000000000000000000000000000000 0x7ffc7f8e4227: 00000000000000000000000000000000 0x7ffc7f8e4237: 00000000000000000000000000000000 0x7ffc7f8e4247: 00000000000000000000000000000000 0x7ffc7f8e4257: 00000000000000000000000000000000 0x7ffc7f8e4267: 00000000000000000000000000000000 0x7ffc7f8e4277: 00000000000000000000000000000000 00000000000000009000000000000000 : 48738424JZX0 0x7ffc7f8e4297: 00000000000000000000000000000000 0x7ffc7f8e42a7: 00000000000000000000000000000000 0x7ffc7f8e4267: 00000000000000000000000000000000 0x7ffc7f8e42c7: 00000000000000000000000000000000 0x7ffc7f8e42d7: 00000000000000000000000000000000 0x7ffc7f8e42e7: 00000000000000000000000000000000 0x7ffc7f8e42f7: 0000000000000000002e2f6d656d6f72 . . . . / memor 0x7ffc7f8e4307: 792d74657374005348454c4c3d2f6269 y-test . SHELL=/biFunction: Print Call Stack Contents (in memory . c) ~ Create a function that calls the above function to print what is on the call stack of the process at the moment. Remember that the stack is stored upside-down in the process memory. We will use an approximation of for determining the top ( start_addr ) and bottom ( end_addr ) of the stack: Top of the call stack (provided as start_addr for the memory-printing function): Simply use the address of your first local variable in this function. You should define such a variable even if you do not need it! Bottom of the call stack (provided as end_addr for the memory-printing function): Declare the following variable globally and use environ[ 0 ] as our estimated address: extern void **environ; Explanation of environ : Process are provided with a set of environment variables similar to the arguments in argv[ ] . We can access them by using a different signature for main ( main(int argc, char *argv[ ], char *env[ ]) ). Alternatively, those variables can be accessed using the extern variable that has been already defined externally (therefore, we simply declare and use it). More will be discussed in the lecture on modular C programs. Main and test functions (in memory-test . c) @ In this unit, you will create three functions: main ( ) : Call your function to print the call stack, then call f1( ) . 2. f1( ) : Use the following template and replace the function calls indicated inside it: int f1 (char *str, int multiplier) { char local_str[strlen(str) + 1]; stropy (local_str, str) ; int f1_result = strlen(str) * multiplier; /* Call your function to print the stack */ /* Call your f2() function */ return f1_result; f2( ) : Create another function of your own. Perform some operations. Then call your function to print the stack. makefile & Create a makefile to make it easier to build the project. Your makefile must have the following targets at the least: (you can have more targets if desired) memory-test : build the executable memory-test (this is your default target) memory-test . o : Compile the corresponding unit memory . o : Compile the corresponding unit clean : delete all object/executable files Running make in your project folder must build the executable memory-test . It must also avoid unnecessary compilations.Coding Requirements & 1. Properly indent your code. There are many indentation styles. Make sure that you are consistent, using the same indentation style throughout your code. 2. Choose proper names for your variables as well as your implementation of the above functions. 3. Use inline comments to document your code. Your comments should indicate why the code is doing something, not what it is doing. For example: // The following comment is a "what comment" - avoid these. i++; // Increment i // This comment is a "why comment", which helps the reader who under: it+; // Skip over the first input item since it will always be 0 4. Clearly document your function definitions. The following is a best practice example that we suggest. At the minimum, your comment must document the job of your function, the input parameters, and the return value. For example: /* * Checks whether a file descriptor is valid * @param fd: file descriptor number to check * @param 2nd-param: (This is how you document multiple input paramet * @return 1 if tile is movable, and 0 if not. */ int is_fd_valid(int fd) ; Hint: The comment block can be right before the function definition, or at the beginning of the function definition block

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

How does the government handle the employee retraining due to AI?

Answered: 1 week ago

Question

Cisco DVS uses Sophos scanning and what else?

Answered: 1 week ago