Lab4 Gdb Assembly
Lab4 Gdb Assembly
February 6, 2025
int main () {
printf ( " Hello , GDB !\ n " ) ;
return 0;
}
Commands
int main () {
int * p = NULL ;
int x = 10;
1
// p = NULL ;
// p = ( int *) 0 x1234 ;
• gdb ./pointer_bug
int main () {
int arr [5] = {1 , 2 , 3 , 4 , 5};
int sum = 0;
int i ;
int main () {
int m = multiply (3 , 4) ;
printf ( " 3 * 4 = % d \ n " , m ) ;
2
int s = sum_of_products (2 , 5) ;
printf ( " sum_of_products (2 , 5) = % d \ n " , s ) ;
return 0;
}
1.7 Wrap-Up
• step, next, finish, backtrace, info locals, info args.
int main () {
int input = 3;
3
int output = do_calculations ( input ) ;
printf ( " Final result = % d \ n " , output ) ;
return 0;
}
• info args, info locals, watch how %rax is used for returns.
int main () {
int val = 5;
long fact = factorial ( val ) ;
printf ( " factorial (% d ) = % ld \ n " , val , fact ) ;
return 0;
}
int main () {
char buffer [8] = " OK " ;
int secret_value = 123;
4
// Overwrite the buffer with a bigger string
copy_data ( buffer , " AAAAAAAAAAAAAAAAAAAA " , 20) ;
2.5 Wrap-Up
• Understand how stack frames store local vars, arguments, return address.