Debugging Merge Sort Using GDB Degugger
Debugging Merge Sort Using GDB Degugger
GDB stands for GNU Project Debugger and is a powerful debugging tool for C(along with other languages
like C++).
It helps you to poke around inside your C programs while they are executing and also allows you to see
what exactly happens when your program crashes.
GDB operates on executable files which are binary files produced by compilation process.
GDB offers many more ways to debug and understand a code like examining stack, memory, threads,
manipulating the program, etc.
• If a core dump happened, then what statement or expression did the program crash on?
• If an error occurs while executing a function, what line of the program contains the call to that
function, and what are the parameters?
• What are the values of program variables at a particular point during execution of the program?
program:
#include <iostream>
using namespace std;
void mergetwosortedarrays(int arr1left, int arr1right,int arr2left, int arr2right, int dataarr[])
{
int memlen=(arr1right-arr1left+1)+(arr2right-arr2left+1);
int *buffer = new int [memlen];
int i,j,k=0,l=0;
for(i=arr1left, j=arr2left; (i<=arr1right) && (j<=arr2right); )
{
if(dataarr[i]<dataarr[j])
{
buffer[k++]=dataarr[i++];
}
else
{
buffer[k++]=dataarr[j++];
}
}
while(i<=arr1right)
{
buffer[k++]=dataarr[i++];
}
while(j<=arr2right)
{
buffer[k++]=dataarr[j++];
}
for(i=0;i<(arr1right-arr1left+1);i++)
{
dataarr[arr1left+i]=buffer[l++];
}
for(j=0;j<(arr2right-arr2left+1);j++)
{
dataarr[arr2left+j]=buffer[l++];
}
// delete []buffer;
}
int main() {
int len;
std::cin>>len;
int *dataarr = new int[len];
for(int i=0;i<len;i++)
std::cin>>dataarr[i];
mergesort(dataarr,0,len-1);
for(int i=0;i<len;i++)
std::cout<<dataarr[i]<<" ";
delete []dataarr;
return 0;
}