trying to debug a small program but cannot continue debugging after printf(), please help! this is the code:
#include <stdio.h>
#include <stdlib.h>
struct dll {
struct dll* prev;
int data;
struct dll* next;
};
struct dll* head;
int main() {
struct dll *p1, *p2, *p3, *p4, *p5, *temp;
struct dll * add=NULL;
p1 = (struct dll *)malloc(sizeof(struct dll));
p2 = (struct dll *)malloc(sizeof(struct dll));
p3 = (struct dll *)malloc(sizeof(struct dll));
p4 = (struct dll *)malloc(sizeof(struct dll));
p5 = (struct dll *)malloc(sizeof(struct dll));
p1->prev = NULL;
p1->data = 1;
p1->next = p2;
p2->prev = p1;
p2->data = 2;
p2->next = p3;
p3->prev = p2;
p3->data = 3;
p3->next = p4;
p4->prev = p3;
p4->data = 4;
p4->next = p5;
p5->prev = p4;
p5->data = 5;
p5->next = NULL;
head=p1;
int count=0, pos=0,i=0;
printf("add of p1::%p add of p2::%p add of p3::%p add of p4::%p add of p5::%p\n", p1, p2, p3, p4, p5);
for ( temp = p1; temp != NULL; temp = temp->next ){
count++;
}
if(count%2==0)
puts("even nodes so no midlle node");
else if(count%2!=0)
{
pos=count/2;
printf("pos::%d\n",pos+1);
for ( i=0; i<=pos; i++)
{
for ( temp = p1;temp != NULL;temp = temp->next )
{
if(i==pos)
printf("middle node is %p\n",temp);
}
}
}
return 0;
}
Debugging output:
(gdb) b 47
Breakpoint 1 at 0x8048643: file sony.c, line 47.
(gdb) b 57
Breakpoint 2 at 0x8048696: file sony.c, line 57.
(gdb) run
Starting program: /home/jeevan/Documents/jvt/ds/sony
add of p1::0x804b008 add of p2::0x804b018 add of p3::0x804b028 add of p4::0x804b038 add of p5::0x804b048
pos::3
Breakpoint 1, main () at sony.c:47
47 for ( i=0; i<=pos; i++)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
47 for ( i=0; i<=pos; i++)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
47 for ( i=0; i<=pos; i++)
(gdb) s
50 for ( temp = p1;temp != NULL;temp = temp->next )
(gdb) s
53 if(i==pos)
(gdb) s
54 printf("middle node is %p\n",temp);
(gdb) s
__printf (format=0x804879d "middle node is %p\n") at printf.c:28
28 printf.c: No such file or directory.
(gdb) s
__x86.get_pc_thunk.bx () at ../sysdeps/i386/i686/multiarch/strcat.S:55
55 ../sysdeps/i386/i686/multiarch/strcat.S: No such file or directory.
(gdb) s
__printf (format=0x804879d "middle node is %p\n") at printf.c:32
32 printf.c: No such file or directory.
(gdb) s
33 in printf.c
(gdb) s
_IO_vfprintf_internal (s=0xb7fb3ac0 <_IO_2_1_stdout_>, format=format@entry=0x804879d "middle node is %p\n",
ap=ap@entry=0xbfffef44 "\b\260\004\b\030\260\004\b(\260\004\b8\260\004\bH\260\004\b\001") at vfprintf.c:235
235 vfprintf.c: No such file or directory.
(gdb) s
270 in vfprintf.c
After printf() I am stuck in a loop, I don’t understand what it is telling and how much time should I wait to go to next statement?
printf, but can't find it. So it's just stepping through instruction by instruction.