I117 II I117 PROGRAMMING PRACTICE II DEBUG Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp
/ SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming 2. 2011/06/09(Thu) / Fundamental data structures 3. 2011/06/14(Tue) / Memory Management 1 4. 2011/06/16(Thu) / Memory Management 2 5. 2011/06/21(Tue) / Debugging 6. 2011/06/23(Thu) / Software Development Env. 1 7. 2011/06/28(Tue) / Software Development Env. 2 8. 2011/06/30(Thu) / Data Structure : Tree 9. 2011/07/05(Tue) / Data Structure: Hash 10. 2011/07/07(Thu) / Understanding Programs 1 11. 2011/07/12(Tue) / Understanding Programs 2 12. 2011/07/14(Thu) / Script Language 1 13. 2011/07/19(Tue) / Script Language 2 14. 2011/07/21(Thu) / Other Languages 15. 2011/07/26(Tue) / Examination
/ FINAL REPORT free topic : decide topic by 7/5(Tue) report us of the topic by e-mail: i117report@jaist.ac.jp / Sound file converter / web crawler (CalDAV) calendar program new shell, editor, window manager rsync encrypt/decrypt, rsync markov-chain program choose good theme TAask TA and me The final report must have deep consideration
/ TODAY'S INDEX / queue, stack / debug / how program runs / memory location, call stack, stack trace / debug method printf / printf debug /debugger / memory checker
/ QUEUE, STACK
FIFOFIRST IN FIRST OUT queue / queue is an array / FIFO enqueue: / insert data dequeue: / extract data / pseudo code enqueue(data) queue q; q.enqueue(1); q.enqueue(2); q.enqueue(3); q.enqueue(4); q.dequeue(); /* 1/ result is 1 */ q.dequeue(); /* 2/ result is 2 */ dequeue() 4 3 2 1
LIFOLAST IN FIRST OUT / stack / LIFO push: / insert data pop: / extract data push(data) / pseudo code pop() stack s; s.push(1); s.push(2); s.push(3); s.push(4); s.pop(); /* 4/ result is 4 */ s.pop(); /* 3/ result is 3 */ 4 3 2 1
/ HOW PROGRAM RUNS
/ COMPONENTS OF COMPUTER SYSTEMS CPU / processing unit SPARC, x86, MIPS,POWER,,, / memory CPU / main, cache memory HDD / storage I/O / I/O Devices / HDD, Network I/F, Keyboard, mouse, display I/O / Memory mapped I/O I/O CPU
CPU / CPU ACTIONS / control fetch, decode, execute, write back / instructions / arithmetic instruction / shift instruction / jump instruction / compare instruction / I/O instruction / instruction, operand http://ray.sakura.ne.jp/asm/0.html / A book.
CPU / CPU ACTIONSCONT / instruction cycles (Fetch) (Decode) (Execute) (Writeback / sequential control FDEW / FDEW for one instruction / one instruction each. F D E W F D E W F D E W
CPU / CPU ACTIONS (CONT) / advanced control / pipeline / constant time for each instruction / gain thruput by shifting instruction stages F D E W F D E W F D E W 4 F D E W 5 F D E W 6 F D E W
/ MEMORY ASSIGNMENT, CALL STACK
/ MEMORY RANGE / physical memory Kernel / memory mapping in kernel / logical memory virtual memory / logical memory address spaces / paging
/ MEMORY MAPPING / segment / text segment / data segment DATA BSS HEAP / common library segment / stack segment / protection SIGSEGV / send SIGSEGV upon accessing other than the segment. low-address high-address
TEXT / TEXT SEGMENT / a program in a machine code is located / function pointers point an address within this area. TEXT / protected against write x86 CPU / recent CPU does not execute other than this area. / buffer overrun : NX bit (AMD), XD bit (Intel) / bits in a page table entry to select whether the data is executable
DATA DATA / initialized static and global variables / the initial value is described BSSBlock Started by Symbol / uninitialized static and global variables BSS / the executable file does not have BSS area BSS0 / allocated before run HEAP malloc / used by malloc
STACK / HOW STACK WORKS PUSH POP SPARC : SP x86 : SP(16bit)/ESP(32bit)/RSP(64bit) SPARC: FP x86 : BP(16bit)/EBP(32bit)/RBP(64bit) high-address
/ EXAMPLE PROCESS MEMORY MAPPING pmap display information about the address space of a process TEXT DATA LIBRARY STACK libc TEXT libc DATA Shared Mapping ld TEXT ld DATA
/ PROCESS RESOURCE LIMITATION csh/sh limit/ulimit