Customizing your projects with custom steps

This tutorial shows how to extend a simple Linux project with custom actions. For this we make a program that outputs into a file and we download this file on each program run into the Windows machine. Adding custom actions works for all project types since VisualGDB 4.0.

Before we begin, ensure that VisualGDB 4.0 or later is installed.

  1. Follow the Linux tutorial to make a simple program. We used the name CustomizedLinuxProject for the project name.
  2. Exchange the contents of the main source file with the following:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        ofstream file;
        file.open ("output.txt");
    
        // Fibonacci sequence
        unsigned long long fn_1 = 1;
        unsigned long long fn_2 = 0;
        unsigned long long fn = 0;
        for(int i=0;i<80;i++)
        {
            file << fn << "\r\n";
            fn_2=fn_1;
            fn_1=fn;
            fn=fn_1+fn_2;
        }
    
        file.close();
        return 0;
    }

    This new code generates the first 80 numbers of the Fibonacci sequence and saves it to a file called output.txt.

  3. Build and run the project.01-builddebug
  4. As we did not set any breakpoints, the GDB log message appears. You can choose to not be shown this dialog again, you can change this option later on from Tools->Options. 12-popup
  5. Go to Tools->SSH Host Manager. Open the console.14-ssh
  6. Open the console to the remote machine. Go to the source stored on the remote machine. In our case the source is in the tmp directory under VisualGDB. Locate the output.txt file there and open it for viewing inside the console. 15-shell
  7. Our next step is to add a custom debug action to bring this output.txt file for local viewing. For this right-click on the project and select VisualGDB Project Properties. 02-openproperties
  8. Open the custom debug steps page. Edit the “Cleanup actions after GDB exits”. 03-postdebug
  9. Click on the plus button to add an action. 04-add
  10. Choose the transfer action as the type. 09-transfer05-newaction
  11. Browse for the output.txt file on the remote machine as the source file. 06-file
  12. Save the file locally to the project directory. 07-save
  13. The ready command looks as follows. Click on OK. 08-command
  14. Click OK in the dialogs and run the project again.09-actionsequence
  15. Right click on the project and select Add->Existing Item. Browse to the local project directory and add the output.txt file.10-addexisting
  16. Open the output.txt file.13-output
  17. Run the app again. As the file was open, Visual Studio will now prompt to reopen the file which can be handy with quickly changing output files. 11-refresh