Wikia

Vim Tips Wiki

Changes: Using quickfix in a different way

Edit

Back to page

(Set category Compiler + remove html entities)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 4: Line 4:
 
|previous=350
 
|previous=350
 
|next=352
 
|next=352
|created=October 24, 2002
+
|created=2002
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Karthick Gururaj
 
|author=Karthick Gururaj
Line 14: Line 14:
 
I'm a software developer and I find Vim's quickfix very helpful. You can also use this while debugging your code, in a slightly different way.
 
I'm a software developer and I find Vim's quickfix very helpful. You can also use this while debugging your code, in a slightly different way.
   
Usually, you will have some print messages in your code, and after the program runs, you'll look at the output to see the execution trace (e.g which if-constructs were taken, how many times did a while loop iterate.. ). If you precede these statements with a <tt><filename>:<linenumber>:</tt>, then, the program output can be parsed with a :cfile, and the execution trace becomes very simple.
+
Usually, you will have some print messages in your code, and after the program runs, you'll look at the output to see the execution trace (e.g which if-constructs were taken, how many times did a while loop iterate.. ). If you precede these statements with a <code><filename>:<linenumber>:</code>, then, the program output can be parsed with a :cfile, and the execution trace becomes very simple.
   
 
For instance, in C
 
For instance, in C
Line 55: Line 55:
 
fprintf(fdebug, "%0s:%0d:\n >>> the variable i am interested = %d<<<", __FILE__, __LINE__, variable_in_question) ;
 
fprintf(fdebug, "%0s:%0d:\n >>> the variable i am interested = %d<<<", __FILE__, __LINE__, variable_in_question) ;
   
I work in embedded system and a lot of time our only debugging tool for code is <tt>printf</tt>. Not all of us have in circuit emulators available to us.
+
I work in embedded system and a lot of time our only debugging tool for code is <code>printf</code>. Not all of us have in circuit emulators available to us.
   
 
And like you said, this is debugging. The code does not go live with debugging statements, they are removed.
 
And like you said, this is debugging. The code does not go live with debugging statements, they are removed.

Latest revision as of 05:26, July 13, 2012

Tip 351 Printable Monobook Previous Next

created 2002 · complexity intermediate · author Karthick Gururaj · version 6.0


I'm a software developer and I find Vim's quickfix very helpful. You can also use this while debugging your code, in a slightly different way.

Usually, you will have some print messages in your code, and after the program runs, you'll look at the output to see the execution trace (e.g which if-constructs were taken, how many times did a while loop iterate.. ). If you precede these statements with a <filename>:<linenumber>:, then, the program output can be parsed with a :cfile, and the execution trace becomes very simple.

For instance, in C

// fdebug is a pointer to the debug file called, debug.txt say.
#define DEBUG_MESG() fprintf(fdebug, "%0s:%0d:\n", __FILE__, __LINE__)
...
function( )
{
  ...
  if (something)
    DEBUG_MESG( );
  else
    DEBUG_MESG( );
  ...
}

Open your code in vim and do

:cfile debug.txt

ReferencesEdit

CommentsEdit

In your vimrc file add:

ia prtf fprintf(fdebug, "%0s:%0d:\n", __FILE__, __LINE__);

to make this macro part of vim aliases in "insert" mode.


One disadvantage of having fprints scattered all over the code is, after debugging, you got to remove them. If you have defined a macro instead, you can easily (re)define it to null..
By the way, if you want to debug shell scripts/perl/tcl/whatever, consider getting yourself a generic preprocessor. I found filepp (http://www.cabaret.demon.co.uk/filepp/) pretty good.


The advantage of the alias is that you can modify the expanded alias to suite your need at point of insertion.

ie.

fprintf(fdebug, "%0s:%0d:\n >>> the variable i am interested = %d<<<", __FILE__, __LINE__, variable_in_question) ;

I work in embedded system and a lot of time our only debugging tool for code is printf. Not all of us have in circuit emulators available to us.

And like you said, this is debugging. The code does not go live with debugging statements, they are removed.


Around Wikia's network

Random Wiki