Making cmd slower

1

Is there any command for cmd to run a program that I run from the compiler? I would like to Debug what I did, and as I often fall into an infinite loop, I want to know if I can do cmd run slower (much slower) so I can see at what point the program is crashing.

    
asked by anonymous 14.06.2015 / 01:13

2 answers

2

Your best option is to use a debugger . With a debugger you can run the program line by line, you can inspect the value of variables before and after each instruction or function, you can change the value of variables dynamically, ..., ...

Each compiler has its own debugger. Many IDEs integrate the debugger into the development environment in a natural way; if you use IDE the use of the debugger may not be so natural but it is perfectly reasonable.

Another way you can 'use% s and% s inside the program to see what is happening to one or more variables

for (i = 0; i < 10000; i++) {
    fprintf(stderr, "DEBUGGING: i = %d; j = %d; x = %f\n", i, j, x);
    /* resto do loop */
}
    
14.06.2015 / 10:43
0

You can use switches (example below ... It does not work in all locations, since the statement can vary across platforms):

#include <stdio.h>
#include <stdlib.h>

int main (void) {

   const int teste = 3;
   __asm__ ("int3");
   int teste2 = 5;
   __asm__("int3");

  return 0;
}

gcc -g test.c

gdb a.out

run

Program received signal SIGTRAP, Trace/breakpoint trap.
main () at teste.c:8
8      int teste2 = 5;

continue

Program received signal SIGTRAP, Trace/breakpoint trap.
main () at teste.c:13
13    return 0;

To see the contents of the variables, just type: info locals

(gdb) info locals
teste = 3
teste2 = 5
    
16.06.2015 / 13:38