How to debug programs in C by Command Prompt?

Asked

Viewed 761 times

5

I need to debug a C-language algorithm but the machine I’m using does not have Code::Blocks. Which way for me to debug at Windows Command Prompt ?

2 answers

3

To debug with Comand Promp there are only two options.Or use a Debugger with no graphical interface as is the case with GDB, or use text output.

This is through printf or even fprintf can "print" the value of the variables in question, or if you want to know if you enter a condition you can put inside it in order to be sure.

It’s not the best, but when you don’t have the resources almost everything serves.

  • OK thank you very much helped a lot

2

A great program for debugging C codes is gdb, and to be able to debug the code, you need to compile it with the -g parameter, which compiles the code and creates a binary file for debug. When opening the file in gdb you use these commands:

b método/linha - coloca um breakpoint na linha ou no método desejado
r              - inicia o debug
n              - faz o breakpoint ir para a proxima linha
c              - executa até o proximo breakpoint
q              - sai do gdb
  • Thank you very much, you helped very much man !

Browser other questions tagged

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