I'm trying to run the following C code. This get compiled and runs at terminal but it doesn't give the expected output. Logic is wrong, of course. To debug, gdb is used. But gdb hangs with the warning when this program is attached. Following is the code, command to compile, run the code and sample output is shown below.
#include <stdio.h>
void array_former(long long int *lst, int *length) {
int i;
long long int value;
for (i=0; i < *length; i++) {
value = lst[i];
if(value < 12)
continue;
lst[*length++] = value / 2;
lst[*length++] = value / 3;
lst[*length++] = value / 4;
}
}
void clear_array(long long int *lst) {
int i;
for(i=0; i<100000; i++)
lst[i] = 0;
}
int main() {
long long int n;
long long int array[100000];
int length, i;
while((n = scanf("%lld", &n)) != EOF) {
clear_array(array);
array[0] = n;
length = 1;
array_former(array, &length);
for(i=0; i<length; i++)
printf("%lld ", array[i]);
}
return 0;
}
Commands
gcc -g test.c
gdb ./a.out
At gdb console:
deepak@ubuntu:~/Desktop$ gdb ./a.out
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/deepak/Desktop/a.out...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/deepak/Desktop/a.out 15
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
[cursor keep blinking for sometime and stops like forever, gdb hangs]
I searched for the above warning and found here that, it can be ignored.
Question: How can I get gdb running without getting hung, so that I can debug this program.