How to make cmd slower

Asked

Viewed 385 times

1

Is there any command for the cmd run a program I have run from the compiler? I would like to debug what I did and, as I often fall into infinite loop, I want to know if you have how to do the cmd run slower (much slower) than time to see at what point the program is crashing.

  • 5

    Have you tried using a IDE to debug for real?

  • 1

    What tools do you write and compile the programs with? In addition to the Ides there are also "debuggers" apart as the gdb. Normally, you can use "breakpoints" to make the "Debugger" stop on a line of code, and then go step by step.

2 answers

2

Your best option is to use one 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 specific 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 shape you’ve got printfare within 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 */
}

0

You can use switches (Example below... Does not work in all locations as the instruction may vary between 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.