From 2c7823e97accaef46de9f7163f95fcceb312bc6d Mon Sep 17 00:00:00 2001 From: Hizenberg Date: Sat, 18 Oct 2025 17:43:52 +0000 Subject: [PATCH] process stack and memory leak --- gdb.txt | 2 +- process-stack.txt | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/gdb.txt b/gdb.txt index 6d33615..6c44b95 100644 --- a/gdb.txt +++ b/gdb.txt @@ -251,7 +251,7 @@ Command: CTRL+p (key bindings) will move to previous command if focus is on src window. -Command: winheight src -2 +Command: winheight src -2 (winheight or wh) To change the size of window passed as an argument. In this case, decrease by 2. diff --git a/process-stack.txt b/process-stack.txt index 52ed9f4..29e0c6c 100644 --- a/process-stack.txt +++ b/process-stack.txt @@ -33,3 +33,101 @@ Section 7: Foundation of Processes (Part A): -> What is a Call stack? +++++++++++++++++++++ + + + +--------+ + | main | + +--------+ + | square |-----/ + +--------+ | + | + | + | + | + | + | + \ + Frame + +----------------+ + | parameters | + | return address| + | locals | * Each Call stack has one section called as frame + | exceptions | which contains the information for certain operations. + | | These operations are self explainatory as written. + +----------------+ + +-> Navigate the Call Stack with Backtrace: + ++++++++++++++++++++++++++++++++++++++ + + + * To know about the call stack of functions, we can use... + + Command: + (gdb)bt + + This shows what are the function calls to trace back to the + beginning function, which is "main" in C and C++. + + * To know about the arguments and the value passed to the current + function in which we are present, we can use... + + Command: + (gdb)info args + + * To know about the local variables of the current functions context, + we can use... + + Command: + (gdb)info locals + + + * To know about the frame section of the function call stack, we can use: + + Command: + (gdb)info frame + + * To get us out of the function that we are currently in without terminating + the execution of the program. + + Command: + (gdb)finish + + or + + (gdb)fin + + + * To move up in the stack, i.e. moving to the context of the calling function + , we can use.... + + Command: + (gdb)up + + * To move up down the stack, i.e. moving to the context of the callee function + , we can use... + + Command + (gdb)down + + + * Segmentation fault: + ~~~~~~~~~~~~~~~~~~~ + + + It is the section of memory which the program is trying to access + and it is out of bound. + + For this kind of error, we get signal from kernel SIGSEGV. + + * Memory leak: + ~~~~~~~~~~~~ + + Failure to reclaim memory while our program runs. + + We can also use tools like valgrind to detect memory leak issue. + + Command: + $valgrind ./ + + + We can also use Address-sanitizers