Sign In

    Enjoy FOSSwire's content? Have it delivered! Subscribe

    Debugging with Nemiver

    You're writing some C code that you just managed to compile. You are able to get it to build without errors, and you're ready to run. But then, something disastrous happens:

    $ gcc main.c -o out
    $ ./out
    Segmentation fault

    Great. Your application dies without so much as an explanation as to why. Nobody likes to debug code, but it has to be done at some point. If you compiled with the -g flag to gcc or g++, your program will have some debugging information included that special programs, like gdb, can use to assist you in solving the problem.

    Nemiver is a graphical tool that can be used to take advantage of debugging information that uses gdb as a backend. It provides all of the features that the terminal-based gdb provides, but in a more sophisticated GUI interface that follows the code as it is executed. This means you can run code line-by-line, add breakpoints, view pointers, variables, memory registers, and see the call stack. In addition, you are also able to attach to a program over a network; so if your web server application goes down, you can run it over-the-wire with Nemiver to try to solve the problem.

    Nemiver

    To give it a test run, let's try it out with some code that segfaults in a normal run. First, after loading up the file, we'll run it line-by-line to find the problem.

    Nemiver Line-By-Line

    Okay, so the segmentation fault appears:

    Nemiver Segfault

    It's at a line where an object is attempting to "lock" another object. Let's take a look at the variables:

    Nemiver Variable View

    Yep, there's the problem. Surface isn't actually pointing to any real variable, hence the 0x1. You may also see 0x0, it also means a pointer is not assigned correctly.

    Nemiver is a great tool to use for code problems as in the example above. It does have a few usability quirks; it can take a lot of clicks to get from one point to the next. Session saving in 0.5.2 also has its problems and usually results in an error or two. But 90% of the time, Nemiver works like a charm and is a nice breath of fresh air from trying to debug from a terminal. If you like to program in C or C++ and constantly have debugging errors or just want to try something new, Nemiver is a must.


    Tasque - a simple todo list application for GNOME

    Keeping organised can be tough sometimes and there are lots of different applications and tools designed to help you get organised.

    Tasque is designed to be a very simple todo list application, designed specifically to link in with popular online todo service Remember The Milk.

    It is written in C#/Mono, so you will need all the relevant Mono gubbins already installed to get it up and running. Here on Fedora 8, there isn't a package yet, so I'll run you through how to install it from source.

    First of all, head to the Tasque download page and download the archive in whichever format you want. Once you've got it, extract it somewhere, then open a terminal in that directory.

    It's a fairly standard compilation process:

    $ ./configure
    $ make
    $ make install # as root

    Once that's done, it should show up under Office in your GNOME Applications menu. As soon as you load it up, you'll be given the option to integrate directly with Remember The Milk.

    Tasque Remember The Milk integration screenshot

    Clicking the Authorise button whisks you away to the RTM site, where you enter your username and password on the site itself and then allow API access for Tasque. Once you've done that, and clicked the button back in the app, your todo list syncs directly from the service.

    Tasque main window screenshot

    By default, all your future tasks show up in the main window all together, but you can use the selection box at the top left to filter between what would appear as your different tabs in RTM.

    In a similar vein, adding a task just by clicking the big button adds it directly to your RTM inbox, but again you can select which category to add it to using the arrow.

    Once you've set up a task, you can then add more information such as a due date and notes. I found the due date interface to not work very well or very intuitively, requiring me to hold down the mouse on the - column to select a date from a pop-up list.

    Tasque still is in its early days, and there are no official 'stable releases' yet, so this behaviour might be improved in future.

    The syncing between RTM and Tasque as a desktop client works well. Any changes you make are synchronised almost instantly. My only concern on the reliance on the service is that Tasque appears to have no offline mode or cache of your tasks - i.e. at launch time you must have a connection to RTM or the application ceases to be of use.

    Nevertheless, from what I've seen, Tasque is a simple approach to making Remember The Milk integrate well with the GNOME desktop, and despite some teething troubles is a must for any GNOME and RTM user.


    C++: Variables and Functions

    If you haven't read the previous tutorial, we highly recommend you do so. Otherwise, you might miss important concepts used here.

    Go ahead and fire up a text editor, and begin reading and typing. The meat of this tutorial is in the comments. Remember, try typing it out instead of copying and pasting. This way you will be able to remember by doing instead of by reading.


    #include

    /* First off: let's make a basic function that prints "Hello" on the screen.
    * The syntax for a basic function is as follows:
    ** returnType functionName()
    * Like with main(), you can return an int if you want, but with normal
    * functions it is possible to return nothing (void).
    */
    void sayHello(){
    std::cout << "Hello from a function!" << std::endl;
    /* Here is something new. std::endl (or just endl if you used the namespace
    * mentioned in the previous lesson) inserts a new line into the console.
    * Get into the habit of adding it to cout statements for readibility.
    */
    } /* Notice how using void as a return type means we don't have to return
    * anything. For a quick example, let's make a function that does return
    * something.
    */

    int threeTimesThree(){
    int result;
    /* Woah, we haven't seen this before. This is simply known as a variable.
    * Basically, it stores data. But before you can store anything, you need
    * to tell the compiler what type of data you want to store. This is
    * specified here with "int". So, we just made an integer named "result".
    */

    result = 3 * 3;
    /* To set a variable to something, just use the syntax
    ** variable = value;
    * Value can be a single value, a calculation, or the result of another
    * function. But, it has to be of the same type that you defined it as
    * above. result should equal 9 right now.
    */

    return result;
    /* As with main(), if we set a return type we need to actually return
    * something. Here, we are returning the variable result.
    */
    }

    /* What if you want to pass a variable to your function? That is when arguments
    * come in handy. They aren't much more difficult to use than a simple
    * variable:
    */
    int multiply(int number1, int number2){
    /* You can have as many arguments as you want, and name them whatever you want.
    * They can be used in your function as a simple variable.
    */

    int result = number1 * number2;
    // This is an example of defining and setting a variable at the same time.

    return result;
    }

    // Of course, we need our usual main() function.
    int main(){
    /* To call a function, use the same syntax you did for defining it, except
    * without the type before it. If a function returns a value, you can
    * assign it to a variable.
    */

    // Print out hello
    sayHello();

    int answer = threeTimesThree();
    std::cout << answer << std::endl;
    // You can use variables in a cout statement as well.

    // If you like, you can even use a function directly.
    std::cout << multiply(4, 5) << std::endl;

    // Finally, finish up our main() function with a return.
    return 0;
    }

    Compile it (if you forget how, see the previous tutorial) and run. You should get something like:

    ./test
    Hello from a function!
    9 20

    If not, or you got an error, check your code and see if you mistyped anything. If you are still having trouble, post a comment and I'll try to help you out.

    We hope you enjoyed this tutorial. Stay tuned for more!


    1. 1
    2. 2