Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Debugging CINs

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

Windows supports source-level debugging of CINs using Microsoft's Visual C++ environment.

Complete the following steps to debug CINs on Windows.

  1. Modify the CIN to set a debugger trap. You must do this to force Visual C++ to load the debugging symbols. The trap call must be done after the CIN is in memory. The easiest way to do this is to place the CIN in the CINLoad procedure. After the debugging symbols are loaded, you can set normal debug points inside Visual C++. The most common way to set a debugger trap on Windows is to insert a debugger break using an in-line assembly command, as shown in the following line of code:

    asm int 3;

    Adding this line to CINLoad gives the following code:

    CIN MgErr CINLoad(RsrcFile reserved)
    {
        Unused(reserved);
        asm int 3;
        return noErr;
    }

    When the debugger trap is hit, Visual C++ invokes a debug window that highlights that line.

    (Windows) You can use the DebugBreak function. To use DebugBreak, include <windows.h> at the top of the file and place the call where you want to break, as shown in the following example code:

    #include <windows.h>
    CIN MgErr CINLoad(RsrcFile reserved)
    {
        Unused(reserved);
        DebugBreak();
        return noErr;
    }

    When that line runs, you are in assembly. Step out of that function to get to the point of the DebugBreak call.
  2. Rebuild the CIN with debugging symbols. If you built the CIN from the command line, add the following lines to the .lvm file of the CIN to add debug information to the CIN:

    DEBUG = 1
    cinLibraries = Kernel32.lib

    If you built the CIN using an IDE, you also must tell the IDE what executable makes the call into the DLL that you want to debug and then build a debug version of the DLL.

  3. If you built the CIN from the command line, start LabVIEW normally. When the debugger trap runs, the following message appears:
    Click Cancel to launch the debugger, which attaches to LabVIEW, searches for the DLLs, then asks for the source file of your CIN.

    Point it to the source file, and the debugger loads the CIN source code. Then you can debug the code.
  4. If you built the CIN using an IDE, open the CIN project in the IDE and select the Debug configuration for the project. Set breakpoints at the points in the CIN you want to debug and then click the GO button. The IDE launches LabVIEW, and you can debug when a breakpoint occurs.

(Linux) You can use standard C printf calls or the DbgPrintf function. You also can use gdb, the Gnu debugger, to debug the CIN. You must load the VI that contains the CIN before you add breakpoints. The CIN is not loaded until the VI is loaded.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit