Vim Tips Wiki
Register
(re:)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=351
 
|id=351
  +
|previous=350
|title=Using quickfix in a different way
 
  +
|next=352
|created=October 24, 2002 6:11
+
|created=October 24, 2002
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Karthick Gururaj
 
|author=Karthick Gururaj
 
|version=6.0
 
|version=6.0
 
|rating=41/20
 
|rating=41/20
|text=
 
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>&lt;filename&gt;:&lt;linenumber&gt;:</tt>, then, the program output can be parsed with a :cfile, and the execution trace becomes very simple.
   
  +
For instance, in C
   
  +
<pre>
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>&lt;filename&gt;:&lt;linenumber&gt;:</tt>, then, the program output can be parsed with a :cfile, and the execution trace becomes very simple.
 
 
// 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( );
 
...
  +
}
  +
</pre>
   
For instance, in C
+
Open your code in vim and do
// fdebug is the pointer to the debug file called, debug.txt say.
 
&#35;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 a
 
 
:cfile debug.txt
 
:cfile debug.txt
   
Line 40: Line 38:
 
*{{help|:cfile}}
 
*{{help|:cfile}}
   
== Comments ==
+
==Comments==
In your vimrc file add:
+
In your vimrc file add:
ia prtf fprintf(fdebug, "%0s:%0d:\n", __FILE__, __LINE__) ;
+
ia prtf fprintf(fdebug, "%0s:%0d:\n", __FILE__, __LINE__);
   
 
to make this macro part of vim aliases in "insert" mode.
 
to make this macro part of vim aliases in "insert" mode.
   
'''Anonymous'''
 
, November 6, 2002 7:21
 
 
----
 
----
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.. <br/>
+
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.. <br/> Btw, 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.
Btw, 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.
 
   
No vim stuff.. anyways..
 
- Karthick
 
 
'''Anonymous'''
 
, November 6, 2002 7:33
 
 
----
 
----
The advantage of the alias is that you can modify the expanded alias to suite your need at point of insertion.
+
The advantage of the alias is that you can modify the expanded alias to suite your need at point of insertion.
   
ie.
+
ie.
fprintf(fdebug, "%0s:%0d:\n &gt;&gt;&gt; the variable i am interested = %d&lt;&lt;&lt;", __FILE__, __LINE__, variable_in_question) ;
+
fprintf(fdebug, "%0s:%0d:\n &gt;&gt;&gt; the variable i am interested = %d&lt;&lt;&lt;", __FILE__, __LINE__, variable_in_question) ;
 
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. <br/>
 
The code does not go live with debugging statements, they are removed.
 
 
 
'''Anonymous'''
 
, November 6, 2002 16:12
 
----
 
TO DO: Some of these comments looks like digressions about how we should do it in C. I don't found them very pertinent as some flavours of C support variadic macros, C++ support chaining, ''etc.''. Hence, I vote for removing these digressions. Any other though?
 
   
 
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.
--[[User:Luc Hermitte|Luc Hermitte]] 18:31, 31 July 2007 (UTC)
 
   
 
And like you said, this is debugging. The code does not go live with debugging statements, they are removed.
I like the insight that even when there are powerful specialized tools, they are not always applicable and that vim can do it too. Could that be retained? [[User:Bastl|bastl]] 08:38, 2 August 2007 (UTC)
 
   
 
----
 
----
<!-- parsed by vimtips.py in 0.489253 seconds-->
 
 
[[Category:Compiler]]
 
[[Category:Compiler]]

Revision as of 12:26, 2 November 2007

Tip 351 Printable Monobook Previous Next

created October 24, 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

References

Comments

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..
Btw, 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.