Archive for the ‘fedora’ Category

gdb tricks: printing arrays

January 20, 2011

int main(){
  int *a;
  int b[3] = {1,2,3};
  a = b;

  int *c[3] = {a, b, 0};
  int **d = c;
  return 0;
}

While debugging the above code if you do:


(gdb) print b
$4 = {1, 2, 3}

that works.


(gdb) print a
$5 = (int *) 0x7fffffffe0f0

that works too, but in order to print a as an array you must do:


(gdb) print (int []) *a
$7 = {1}

and when you specify the size it gets better:


(gdb) print (int [3]) *a
$8 = {1, 2, 3}

The same goes for c and d:


(gdb) p c
$9 = {0x7fffffffe0f0, 0x7fffffffe0f0, 0x0}
(gdb) p (int*[3]) *d
$10 = {0x7fffffffe0f0, 0x7fffffffe0f0, 0x0}
(gdb) 

And finally a very recently discovered short hand thanks to Jan Kratochvil:


(gdb) p *a@3
$11 = {1, 2, 3}
(gdb) p *d@3
$12 = {0x7fffffffe0f0, 0x7fffffffe0f0, 0x0}

Eclipse Tips (Open References to…)

January 5, 2011

One of my favourite eclipse features when reading and trying to understand it is Ctrl+Shift+G (Open References to). This creates a list in the ‘Search’ view of all references to the highlighted element.

Another thing that I discovered recently is that you can click on the little arrow next to the little pen symbol on the right hand side and open up the history what previous searches. These are of course important to your understanding of the current new code.

Eclipse tips (Call Hierarchy)

December 21, 2010

This is one of my favourite features. I had to retrofit some error checking into a function in a patch I am working on.
The function is

evpy_add_attribute

. I wanted to know the functions that call this function and the functions that call them. Once I figured that out. I went through and made sure that the return values where checked for errors and appropriate action was taken.

Surprisingly Free

December 14, 2010

I only discovered this awesome podcast recently:

http://surprisinglyfree.com/

I highly recommend it.

git tips

November 26, 2010

For a quick log of what I have on my branch/repo which I have not pushed upstream I do this:

git log --pretty=oneline --branches --not --remotes=origin

A tip I got from Dodji:

git-new-workdir

creates a new working directory that shares the repository of your original clone. If like me you like to create a new direcotry for each branch you are working on this is a much faster way to do it. It also has the added bonus of being awair of you other directories so you can share commits whithought having to git remote add

In my Fedora 13 installation. This is currently located at

/var/lib/mock/fedora-14-x86_64/root/usr/share/doc/git-1.7.2/contrib/workdir/git-new-workdir

Thundersearch

November 24, 2010

I am a big fan the of the Thunderbird search bar. It has definitely helped my productivity. The star is awesome.

Bad User Interface

November 16, 2010

I am not a big fan of the twist switch. I actually took the shade of this lap to take the picture which improved the user interface a little bit.

“The [user] is always right”

November 15, 2010

Dilbert.com

The old saying goes “the customer is always right”. This saying, in a nice sound bight, summarizes the idea of good customer service. That you should always make your customer happy, because, in the end, it is her money that you seek.

I think this is far truer for users though. I believe that every mistake a user makes, their first attempt at something, and the questions they ask give the developer valuable insight into how they can improve the usability of their software. Always.

Jessyink

November 10, 2010

I have recently discovered jessyink. Jessyink is an inkscape extention which allows you do create presentation slides in inkscape, save them as svg, and display them using firefox.

I think that when you start your presentation in inkspace instead of OpenOffice Impress, it puts your mind in a more graphical mode. This mindset helps you create slides which are more graphical and less verbose/text heavy/bullet-pointy.

I found this excellent tutorial which helped me get started with jessyink.

One thing I would like to add that tutorial:

Creating Views

You can add zooming, panning and rotation effects to you slides. (Use with caution. These are addictive).
To do this you have to first create view ports using rectangles. Using the inkscape rectangle tool create a rectangle. Position and size it around the part of the slide that you want to focus on. Once you have done that go to Extensions -> Jessyink -> view… .

On that screen select an order. This determines when in the order of events the transition to this view happens. Duration will determine how long it should take to transition from the old view to this view. Click apply and you are done.

Now if you want the view port to rotate, simply select the rectangle you have created for the view, click on it again and rotate it. You can experiment with it to know how exactly that will work.

You can checkout this cheesy example if you want. Use mouse click or arrow keys to navigate through the presentation.

smart pointers in GDB+

November 5, 2010

While back a reader of my blog, Jonner, requested a C++ feature in GDB; smart pointers. I am glad to say that this work is very close to complete, pending approval to commit upstream.

Supporting smart pointers boils down to supporting the overloading of operator-> which was a bit tricky.
Take this example:


class A{
  public:
    int foo() {return 11;}
}

template <typename T> class SmartPointer{
  T *p;
  public:
    SmartPointer(T *pointer){
      p = pointer;
    }

  T *operator->(){
    return p;
  }
};

int main(){
  A a;
  SmartPointer<A> sp(&a);
  sp->foo();
}

In the code above when we are calling

sp->foo()

we really mean something like:

(sp->)->foo()

There is the issue that if the object that is returned also overloads the -> operator. When that is the case gdb must continue to follow the links until it arrives at the final object then make the function call or return the reference requested. Another issue to handle was that operator-> can either return a copy, a reference, or a pointer. In all these cases the forwarding should work seamlessly. And finally, tying all of that into overload resolution.

So this all now works in gdb upstream and should be in fedora soon. One known bug about this is that if there is more than one level of overloading of operator-> and any level after the second level returns the object by copy instead of by reference the call might fail because gdb does not properly implement the implied copy constructor.

I got a lot of help from the reviewers on gdb-patches lest. Special thanks to all :)


Follow

Get every new post delivered to your Inbox.