{"id":152,"date":"2014-02-04T17:39:31","date_gmt":"2014-02-04T17:39:31","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=152"},"modified":"2015-07-19T08:55:13","modified_gmt":"2015-07-19T15:55:13","slug":"linux-octave","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/octave\/","title":{"rendered":"Debugging GNU Octave plugins with VisualGDB"},"content":{"rendered":"<p>This tutorial shows how to debug a plugin of an Linux application by attaching to a process. We will make a simple function for <a href=\"http:\/\/www.gnu.org\/software\/octave\/\">GNU Octave<\/a> and debug it in Visual Studio with VisualGDB.<\/p>\n<ol>\n<li>Please install <a href=\"\/download\">VisualGDB<\/a> 3.0 or newer on your Windows machine.<\/li>\n<li>On your Linux machine install octave and its headers that are needed to make oct files:\n<pre>sudo apt-get install octave\r\napt-get install octave-headers<\/pre>\n<\/li>\n<li>Next make a file named <strong>ourpluginfunction.cpp<\/strong> in <strong>\/tmp<\/strong> containing the following code.\n<pre class=\"\">#include &lt;octave\/oct.h&gt;\r\nDEFUN_DLD(ourpluginfunc, args, nargout, \"Example Plugin Function\")\r\n{\r\n    int nargin = args.length();\r\n    if (nargin != 1)\r\n        print_usage();\r\n    else\r\n        return octave_value(args(0)*42);\r\n    return octave_value_list();\r\n}<\/pre>\n<\/li>\n<li>Compile the file with the following.\n<pre>sudo mkoctfile \/tmp\/ourpluginfunc.cpp<\/pre>\n<\/li>\n<li>Run octave.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/01-octave.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/01-octave.png\" alt=\"01-octave\" width=\"583\" height=\"505\" \/><\/a><\/li>\n<li>Run our command &#8216;ourpluginfunc(1)&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/01b-octavefunc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/01b-octavefunc.png\" alt=\"01b-octavefunc\" width=\"583\" height=\"505\" \/><\/a><\/li>\n<li>Inside Visual Studio go to <strong>Debug-&gt;Attach to Process<\/strong>, choose VisualGDB as transport and click on <strong>&#8216;Find&#8230;&#8217;<\/strong>.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/02-attach.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/02-attach.png\" alt=\"02-attach\" width=\"700\" height=\"471\" \/><\/a><\/li>\n<li>Choose the Linux machine as the remote host and click on &#8216;OK&#8217;. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/03-selectmachine.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/03-selectmachine.png\" alt=\"03-selectmachine\" width=\"500\" height=\"383\" \/><\/a><\/li>\n<li>Find octave from the list and click on &#8216;Attach&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/04-attachoctave.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/04-attachoctave.png\" alt=\"04-attachoctave\" width=\"700\" height=\"471\" \/><\/a><\/li>\n<li>VisualGDB has attached to the Octave process and suspended it. Click on the source file list icon in the GDB Session window to locate your source file in order to set a breakpoint.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/05-opensources.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/05-opensources.png\" alt=\"05-opensources\" width=\"700\" height=\"540\" \/><\/a><\/li>\n<li>Open the <strong>ourpluginfunc.cpp<\/strong> from here.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/06-opensource.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/06-opensource.png\" alt=\"06-opensource\" width=\"607\" height=\"395\" \/><\/a><\/li>\n<li>Set a breakpoint inside the function and continue execution.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/07-setbp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/07-setbp.png\" alt=\"07-setbp\" width=\"700\" height=\"540\" \/><\/a><\/li>\n<li>Go to the Linux machine and enter into octave the command &#8216;<strong>ourpluginfunc(1)<\/strong>&#8216; again.<\/li>\n<li>Go back to Visual Studio. Note how we are now stopped inside our function and can debug it.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/08-stopped.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/octave\/08-stopped.png\" alt=\"08-stopped\" width=\"700\" height=\"540\" \/><\/a><\/li>\n<li>You can use all common debugging techniques (e.g. variable evaluation, modification, step through code). When done, press F5 to continue executing Octave.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug a plugin of an Linux application by attaching to a process. We will make<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88],"tags":[33],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/152"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":2,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":208,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/152\/revisions\/208"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}