Presentation is loading. Please wait.

Presentation is loading. Please wait.

Displaying Memory/Files

Similar presentations


Presentation on theme: "Displaying Memory/Files"— Presentation transcript:

1 Displaying Memory/Files
What every systems programmer needs to know how to do

2 An often-needed capability
When we want to look at memory-contents or see what’s been saved in an arbitrary file We need to write code for a memory-dump So often, It’s probably worth memorizing!

3 Here’s the basic loop in C
unsigned char *cp; // where the data starts int n; // number of bytes of data for (i = 0; i < n; i += 16) { if ( (i % 16) == 0 ) printf( “\n%a: “, cp+i ); for (j = 0; j < 16; j++) { if ( i+j < n ) printf( “%02X “, cp[i+j] ); else printf( “ “ ); } char ch = ( i+j < n ) ? cp[i+j] | 0x20; if (( ch < 0x20 )||( ch > 0x7E )) ch = ‘.’; printf( “%c”, ch ); }

4 Exercise: let’s see our stack
Write a program to ‘dump’ its user-stack We can use inline assembly to get ESP int main( void ) { unsigned char *cp; asm(“ movl %%esp, %0 “ : “=n” (cp) ); int nbytes = 0xC – (int)cp; /* then code to dump stack goes here */

5 Compare with ‘mm_struct’
Header-file ‘/usr/src/linux/include/linux/sched.h’ Defines the type ‘struct mm_struct’ Includes some fields describing user stack


Download ppt "Displaying Memory/Files"

Similar presentations


Ads by Google