Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use GDB inside giant loops
    primarykey
    data
    text
    <p>I have the following loop and my code breaks but I don't know at which iteration it breaks exactly. </p> <pre><code>int n=1000; for (i=0; i&lt;n; i++) { slot = random() % max_allocs; doAlloc = random() % 4; doWrite = writeData; if (!doAlloc || ptr[slot] != NULL) { if (ptr[slot] == NULL) ;//assert(Mem_Free(ptr[slot]) == -1); else { printf("I got here \n"); printf("mem free ptr slot is %d \n",Mem_Free(ptr[slot])); } free(shadow[slot]); ptr[slot] = NULL; shadow[slot] = NULL; } if (doAlloc) { size[slot] = min_alloc_size + (random() % (max_alloc_size - min_alloc_size + 1)); printf("size[slot] :%d\n", size[slot]); ptr[slot] = Mem_Alloc(size[slot], BESTFIT); printf("ptr slot is %p \n",ptr[slot]); assert(ptr[slot] != NULL); if (doWrite) { shadow[slot] = malloc(size[slot]); int j; for (j=0; j&lt;size[slot]; j++) { char data = random(); *((char*)(ptr[slot] + j)) = data; *((char*)(shadow[slot] + j)) = data; } } } } </code></pre> <p>How can I find at which iteration of n the code breaks and how can I put a breakpoint at that iteration?</p> <p>P.S.: Is there any other better debugger for this purpose in Linux? (If I don't want to use Eclipse!)</p> <p>Here's the error I am receiving in gdb:</p> <pre><code>mymain: mymain.c:104: main: Assertion `ptr[slot] != ((void *)0)' failed. Program received signal SIGABRT, Aborted. 0x000000368da328e5 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 64 return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig); (gdb) backtrace #0 0x000000368da328e5 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 #1 0x000000368da340c5 in abort () at abort.c:92 #2 0x000000368da2ba0e in __assert_fail_base (fmt=&lt;value optimized out&gt;, assertion=0x40114b "ptr[slot] != ((void *)0)", file=0x401142 "mymain.c", line=&lt;value optimized out&gt;, function=&lt;value optimized out&gt;) at assert.c:96 #3 0x000000368da2bad0 in __assert_fail (assertion=0x40114b "ptr[slot] != ((void *)0)", file=0x401142 "mymain.c", line=104, function=0x401199 "main") at assert.c:105 #4 0x0000000000400e2a in main (argc=4, argv=0x7fffffffdb68) at mymain.c:104 (gdb) frame 1 #1 0x000000368da340c5 in abort () at abort.c:92 92 raise (SIGABRT); (gdb) frame 3 #3 0x000000368da2bad0 in __assert_fail (assertion=0x40114b "ptr[slot] != ((void *)0)", file=0x401142 "mymain.c", line=104, function=0x401199 "main") at assert.c:105 105 __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"), </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload