FIT3042 Lecture Notes - Lecture 8: Stack Trace, Call Stack, C Dynamic Memory Allocation

20 views3 pages
L8: C Projects and Make
.c File
Anything that causes the compiler to generate code should go into
Funcon bodies
Global variable declaraons
.h File
Anything intended as a message to the compiler
Funcon prototypes
Struct definions
Typedefs
#defines
Make
L9: Debugging with gdb
Errors in C
Common in all languages
Typos
Incorrect algorithms
Buffer overruns
Misuse of pointers
Segmentaon Fault
Segmentation Fault
Happens when you program tries to access memory that has not been allocated to it
Is a signal that the OS sends to your program, causing it to exit
OS manages memory, as it manages all hardware; it won’t let your program read from or
write to memory segments it doesn’t own
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

A(cid:374)(cid:455)thi(cid:374)g that (cid:272)auses the (cid:272)o(cid:373)piler to ge(cid:374)erate (cid:272)ode should go i(cid:374)to. A(cid:374)(cid:455)thi(cid:374)g i(cid:374)te(cid:374)ded as a (cid:373)essage to the (cid:272)o(cid:373)piler. Happe(cid:374)s (cid:449)he(cid:374) (cid:455)ou progra(cid:373) tries to a(cid:272)(cid:272)ess (cid:373)e(cid:373)or(cid:455) that has (cid:374)ot (cid:271)ee(cid:374) allo(cid:272)ated to it. Is a sig(cid:374)al that the os se(cid:374)ds to (cid:455)our progra(cid:373), (cid:272)ausi(cid:374)g it to e(cid:454)it. Os (cid:373)a(cid:374)ages (cid:373)e(cid:373)or(cid:455), as it (cid:373)a(cid:374)ages all hard(cid:449)are; it (cid:449)o(cid:374)"t let (cid:455)our progra(cid:373) read fro(cid:373) or (cid:449)rite to (cid:373)e(cid:373)or(cid:455) seg(cid:373)e(cid:374)ts it does(cid:374)"t o(cid:449)(cid:374) Che(cid:272)k retur(cid:374) (cid:448)alues fro(cid:373) fu(cid:374)(cid:272)(cid:415)o(cid:374)s su(cid:272)h as malloc() a(cid:374)d fopen() Al(cid:449)a(cid:455)s i(cid:374)i(cid:415)alize poi(cid:374)ter to (cid:374)ull o(cid:374) (cid:272)rea(cid:415)o(cid:374) if (cid:455)ou"re (cid:374)ot gi(cid:448)i(cid:374)g the(cid:373) a (cid:448)alid target i(cid:373)(cid:373)ediatel(cid:455) Sho(cid:449) the li(cid:374)e (cid:449)here the progra(cid:373) (cid:272)rashed. If the progra(cid:373) takes (cid:272)o(cid:373)(cid:373)a(cid:374)d-li(cid:374)e argu(cid:373)e(cid:374)ts, (cid:455)ou (cid:272)a(cid:374)"t put the(cid:373) o(cid:374) the gdb (cid:272)o(cid:373)(cid:373)a(cid:374)d li(cid:374)e. Bt : sho(cid:449)s (cid:455)ou a sta(cid:272)k tra(cid:272)e. Up : (cid:373)o(cid:448)es (cid:455)ou up fro(cid:373) the sta(cid:272)k fra(cid:373)e. Down : (cid:373)o(cid:448)es (cid:455)ou do(cid:449)(cid:374) a sta(cid:272)k fra(cid:373)e. Tells gd(cid:271) to stop ru(cid:374)(cid:374)i(cid:374)g the (cid:272)ode (cid:449)he(cid:374) it gets to a (cid:272)ertai(cid:374) poi(cid:374)t.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents