Recent blog entries for marcioandreyoliveira

5 Dec 2008 »

I am not afraid anymore

Have you ever been afraid of changing some code? Even one that you've developed?

I have. Many times. Why this happened to me? Well, that is because I could not be 100% confident that my changes would not break any other part of the program.

My life changed when I learned the Test Driven Development methodology (aka TDD).

The idea behind TDD is that you must write automated tests before writing your code. This methodology will not only help you design better software by catching bugs at the same time you are coding, but (IMHO) it is also a great way to assure your code will keep working after maintenances.

Managers love to say they want you to deliver fully tested software. They even say that TDD is a wonderful idea. But things change when you need to fix a bug or insert new features into a product that do not have automated tests. At this moment, managers complain that there is no time to let you write a test suite to cover the entire software.

To be totally honest we need to agree that being able to fix problems and / or insert new features into your company's products in a timely manner is essential in the global market competition.

- I can not write an entire test suite to the program, and take the risk to not deliver it in a time it must be delivered. And if I do not write tests how can I assure that everything will keep working after I put my hands in it?

In this case I write tests to the part of the software that I will alter. Moreover, whenever I have a bug to fix I write tests to fully cover that part I'm working on.

Yes, I know that to be considered effective, tests must cover 100% of the program, but you must have a fresh view about it:

This approach significantly reduces the number of tests I should write to be able to check if my changes did not affect anything else. So, it will take less time and effort than the ideal situation (which my manager probably would not allow let me to do).

I will be able to write them little by little, during my development activities. The product did not have any test at all so if I write a little number of tests each time that I am working on it is better than nothing.

What you think? Is my approach good? I would like to listen to your opinion.

Syndicated 2008-12-04 23:21:00 from Marcio Andrey Oliveira

20 Oct 2008 »

Blind Programmer

I used to complain almost every day about my tendonitis.

Today I was reading a post named Programador Cego (Blind Programmer) at Aurélio's blog (It is written in Brazilian Portuguese).

This post talks aboit Ângelo Beck. He is 27 years old and he is completely blind.

Ângelo uses a screen reader and a method he developed to help him see the source code. So he is able to develop in PHP.

Ângelo proved that a blind person can do almost anything and changed my mind. He is a hero!

From now on I will never complain about my tendonitis again.
<iframe src="http://www.google.com/search?lookitup&q=define:programmer&css=div#guser,body%3Ecenter%7Bdisplay:none%7D&xremove=/html/body/table%5Bposition%28%29%3C=3%5D" style="border: 1px solid black; width: 460px; height: 100%; top: 0px; right: 0px; padding-left: 0px; position: fixed; background-color: white; z-index: 1000; display: none;" id="ResultBox5"></iframe>

Syndicated 2008-10-20 15:09:00 from Marcio Andrey Oliveira

17 Mar 2008 »

How to load debug symbols with GDB - Another Approach

I wrote in the post How to load debug symbols with GDB one way do debug a stripped version of an application with full access to debug symbols.

In this post I will explain another way you can do it.

We are going to load debuging information from a file that was generated by our executable just before it was stripped off..

I am going to use the same source and environment settings that I used in my earlier post:
  • released.c: source code of the program we wish to debug (listing 1).
  • ~/estudo/: Source code of our program will be put here.
  • ~/local/bin: The stripped off version of binary program will stay here.
  • ~/local/symbols: In this place are all files that contain debuging information.

<center><tbody></tbody>

#include <stdio.h>
#include <stdlib.h>


int division(int a, int b);

int m;

int main(void)
{
int i;
int j;

printf("vou setar i\n");
i = 10;

printf("vou setar j\n");
j = 1;

printf ("i = %d, j = %d\n", i, j);
m = division(i, j);

printf("m = %d / %d = %d\n", i, j, m);

return 0;

int division(int a, int b)
{
return a / b;
}


</center>
Listing 1 - sample program source code

Let's start:

1 - Create your program with debug information. In our sample:
gcc -g -o release release.c <ENTER>

2 - Now we will generate a file that will contain only debug informations. You generate this file by issuing this command:
objcopy --only-keep-debug <executable_file> <symbol_file> <object_file> <symbol_file> <ENTER></symbol_file></object_file></symbol_file></executable_file>
In our sample:
objcopy --only-keep-debug release release.sym <ENTER>

The choice of .sym as an extension for the debug info file is totally arbitrary. You can use whatever you wish to.

3 - You remove debugging information:
strip -s release <ENTER>

4 - Move file release to ~/local/bin/:
mv release ~/local/bin <ENTER>

5 - Move file released.sym to ~/local/symbols/
mv release.sym ~/local/symbols <ENTER>

6 - Go to directory ~/local/bin
cd ~/local/bin <ENTER>

7 - Run GDB:
gdb ./release <ENTER>

8 - Try list command to see that release executable file doesn't have symbols in it.

Figure 1 shows us what I said.

Figure 1 - executable file named release is loaded by GDB.

9 - Let GDB to load symbols from symbols file named release.sym. This file has all symbols that we need to debug. You achieve this by issuing the following command:
add-symbol-file ~/local/symbols/release.sym <ENTER>

From now on you can debug your program as usual.

Figure 2 shows us that debuging symbols where imported successfully and that now the list command shows us the program source code.

Figure 2 - now our GDB session has debuging symbols

As you can see in figure 3, I set a break point at line 17 and I ran the program that stopped there. Then I printed i variable. It is possible just because symbols were loaded.

Figure 3 - debugging session.

You can see that this method to load debug symbols is easier than the previous one presented in the post How to load debug symbols with GDB.

My friend Jumpi complained that it is not the unix way to debug applications that just don't have debug information by loading a separated file. We have core files to help us to debug the application in our host.

I agree with him that it is unusual to debug this way, but it may be useful.

The idea behind this method (and behind the previous one) is similar to that used by MS with .pdb files.

It will allow you to save disk space on your host because you can keep only stripped versions of your applications and libraries in it. It is especially important to embedded systems.

At the same time it let you have a colection of symbol files stored at some place (say, a DVD disc or another server). When (and if) you need to do a debug session

I hope this post will make your life easier.

Syndicated 2008-03-17 14:49:00 from Marcio Andrey Oliveira

16 Mar 2008 »

Precision Resistors

A lot of hobbyists want to make their own circuits but they face a problem: precision resistors.

But what is the difference between a precision resistor and an ordinary resistor? Answer: none.

By the way, the term precision is unappropriated because the tolerance of the component doesn't show us the precision of the resistor but how much its real value can differ from the nominal value.

- What you mean by none?

I will explain. By no means the manufacturer can assure that during a manufacturing process of resistors all of them will have the same value.

So, the manufacturer measures the resistance of each component and then it groups them by ranges of values. Each group has the same tolerance or (in)precision.

But what does tolerance means? It means that manufacturer assures that the real value of the resistor will not be either greater nor lower than nominal value plus or minus a percentage that is indicated by the tolerance band.

Let's see a sample.

Say a manufacturer is producing resistors with resistances of 100 ohms (nominal value) and that he sells them with 1%, 2%, 5%, 10% and 20% of tolerance.

Manufacturer will measure each resistance of 100 ohms and he will group them as follows:

All resistors with resistance varying between 99 and 101 ohms will be put together in the group of components with 1% of tolerance.

All resistors with resistance varying between 98 and 99 ohms or between 101 and 102 ohms will be put together in the group of components with 2% of tolerance (you should remember that all components with resistances varying between 99 and 101 ohms are in the group of resistors with 1% of tolerance).

All resistors with resistance varying between 95 and 98 ohms or between 102 and 105 ohms will be put together in the group of components with 5% of tolerance (you should remember that all components with resistances greater than 98 and less than 102 ohms were put in the groups of resistors with 1% and 2 % of tolerance).

This process continues until all components are classified in their tolerance band.

So I say again: There is no difference between a precision resistor and an ordinary resistor.

There are many projects where the ratio between resistances is more important than the actual values. In these case we can do the same thing as the manufacturer. We can measure our resistors to select the most appropriated.

Let me show an example. Suppose we have an inverter amplifier as shown in figure 1.

Figure 1 - Inverter Amplifier

Gain is determined by equation

We can see that the circuit's gain is determined by the ratio between Rf and Ri.

Suppose we want a gain of X.

If Rf = 10,000 ohms and Ri = 5,000 ohms the gain is -2.

If Rf = 20,000 ohms and Ri = 10,000 ohms the gain is -2 too.

If we use resistors with tolerance (precision) of 5% the gain could vary between -1.81and -2.21 depending on real values of resistors Rf and Ri.

If we use resistors with tolerance (precision) of 2% the gain could vary between -1.92 e -2.08 what is much better.

What if we don't have precision resistors? What can we do?

We can use our ordinary resistors (tolerance of 5%). Take a bunch of them and measure each one until you find two resistors with a resistance ratio as near as possible of the value we wish (It is 2 in our sample).

Let me illustrate with an example. Say we take a bunch of resistors of 20K and 10K ohms (nominal values) to measure.

Suppose we found some resistors of 20,900 and 10,400 ohms. So we could do Rf = 20,900 ohms and Ri = 10,400. With these values, the gain would be -2.01 that is a better result than estimated with 2% tolerance resistors.

If we found Rf = 21,000 and Ri = 10,500 than the gain would be exactly 2.

The method, presented in this post, to use ordinary resistors instead of precision resistors is suitable only in prototype development. In commercial scale it is not feasible and the use of precision resistors is mandatory.


Syndicated 2008-03-17 02:38:00 from Marcio Andrey Oliveira

9 Mar 2008 »

How to load debug symbols with GDB

My friend Wanderley asked me if it is possible to tell GBD to load debuging symbols from some file and use it to help debuging a program that doesn't have them.

Yes. It is.

There are two solutions to this question.

I going to explain the first solution in this post. The other solution I will explain in the next post.

You can load debuging information from an debug enabled version of executable file.

In order to better explain the first solution, I will setup my sample enviroment as follows:
  • released.c: source code of the program we wish to debug (listing 1).
  • ~/estudo/: Source code of our program will be put here.
  • ~/local/bin: The stripped off version of binary program will stay here.
  • ~/local/symbols: In this place are all files that contain debuging information.

<center><tbody></tbody>

#include <stdio.h>
#include <stdlib.h>


int division(int a, int b);

int m;

int main(void)
{
int i;
int j;

printf("vou setar i\n");
i = 10;

printf("vou setar j\n");
j = 1;

printf ("i = %d, j = %d\n", i, j);
m = division(i, j);

printf("m = %d / %d = %d\n", i, j, m);

return 0;

int division(int a, int b)
{
return a / b;
}


</center>
Listing 1 - sample program source code

I have two versions of the program: with and without debuging information.

1 - You compile your program with debug information. In our sample:
gcc -Wall -g -release release.c <ENTER>

2 - You make a copy of your program. In our sample:
cp release release.full <ENTER>

3 - You strip off debuging information:
strip -s release <ENTER>

As you can see on Figure 1, we have two programs. released.full has debuging symbols but release doesn't have them.

Figure 1

4 - Move file release to ~/local/bin/:
mv release ~/local/bin <ENTER>

5 - Move file released.full to ~/local/symbols/
mv release.full ~/local/symbols <ENTER>

6 - Go to directory ~/local/bin
cd ~/local/bin <ENTER>

7 - Run GDB:
gdb ./release <ENTER>

8 - Try list command to see that release executable file doesn't have symbols in it.

Note: if the program was already running you could get its PID then attach GDB to it.

Figure 2 shows us two windows. The first one shows that our executable file has no debug information. In the other window we can see that release is not yet loaded.

Figure 2 - executable file named release is loaded by GDB but it is not yet running.

9 - Let GDB to load symbols from executable file named release.full. This binary version of our program has all symbols that we need to debug.

Please notice that GDB will not replace the release executable by release.full version of our program. It will just import symbols from release.full into release debugging session.

But GDB needs to know in advance where it must put the symbols it will load. How can you determine the correct memory address?

It is quite simple. You issue command maint inside GDB:
maint info sections

Then you look for .text section. The address that is in the first column is what you want. In our sample, it is 0x08048320. See figure 3.

Figure 3 - looking for .text section address

10 - The next step is to instruct GDB to load debug symbols into .text section. To achieve it you do this:
add-symbol-file ~/local/symbols/release.full <.text section address>

In our sample it means to type:
add-symbol-file ~/local/symbols/release.full 0x08048320

From now on you can debug your program as usual.

Figure 4 shows us that debuging symbols where imported successfully and that now the list command (abbreviated as l) shows us the program source code.

Figure 4 - now our GDB session has debuging symbols

As you can see in figure 5, I set a break point at line 17 and I ran the program that stopped there. Then I printed i variable.

In the other terminal I issued ps command. It was done just to show you that the only program running was release executable. There is no instance of release.full program.

Figure 5 - debugging session.

I hope this post will make your life easier. In the next time I will teach you another way to import debuging symbols.

Syndicated 2008-03-08 04:07:00 from Marcio Andrey Oliveira

9 Mar 2008 »

Using Mutt with Gmail

Gmail is the best e-mail service and Firefox is the best browser. But if you keep Gmail's page open for a long time then Firefox will waste a lot of memory of your computer.

If you have an old machine like me, you know that each byte is important. So, I decided to come back to my old mail client: Mutt.

Here I'm showing some steps you need to let mutt access Gmail with IMAP protocol.

I'm using Ubuntu 7.04 with mutt 1.5.13, but it should work with other distros.

You must replace my_mail@gmail.com and my_password occurrences with real values.

  1. First of all you must enable IMAP access to your Gmail account. To enable IMAP in your Gmail account:
    1.1. Log in to your Gmail account.
    1.2. Click Settings at the top of any Gmail page.
    1.3. Click Forwarding and POP/IMAP.
    1.4. Select Enable IMAP.

  2. Install mutt, msmtp and ssl. I won't show you how to do it because it is different for each distro.

  3. Create msmtp configuration file (~/.msmtprc) as shown:
    account default
    host smtp.gmail.com
    port 587
    from my_mail@gmail.com
    tls on
    tls_starttls on
    auth on
    user my_mail@gmail.com
    password my_password
    logfile ~/.msmtp.log

  4. Create mutt configuration file (~/.muttrc) as shown:
    set imap_user = "my_mail@gmail.com"
    set imap_pass = "my_password"

    set from = "my_mail@gmail.com"
    set realname = "Your Real Name"

    set folder = "imaps://imap.gmail.com:993"
    set spoolfile = imaps://imap.gmail.com:993/INBOX
    set record=""
    set postponed="imaps://imap.gmail.com/[Gmail]/Drafts"

    set header_cache="~/.mutt/cache/headers"
    set message_cachedir="~/.mutt/cache/bodies"
    set certificate_file=~/.mutt/certificates
    set move = no
    set imap_check_subscribed="yes"
    set imap_list_subscribed="yes"
    set mbox="imaps://imap.gmail.com/[Gmail]/All Mail"
    # this line instructs mutt to refresh my IMAP mailbox every 120 seconds
    set mail_check=60
    #I'm using ^ character to instruct mutt to update e-mail list immediately
    bind index "^" imap-fetch-mail
And that's all folks.

Syndicated 2008-02-29 16:46:00 from Marcio Andrey Oliveira

9 Mar 2008 »

Looking for many words at once

I use Vim daily and my admiration for it always is renewed. It has so may features that I doubt any one can use 100% of its capacity.

One of the Vim's features I like too much is its ability to search different words at once in text.

When we want to find a word we enter in command mode and we type:

/word <ENTER>

- But what if we want to find two or more words ? Do we need to do separate searches?

No! We do just one search in command mode with each word separated by escaped pipes (\|) :

/word1\|word2\|word3 <ENTER>

Figure 1 shows a search for four words. Notice that spaces are considered as part of the word we are looking for.


Figure 2 shows the result of the search.


I hope this tip will be as useful for you as it is for me.

Syndicated 2008-01-30 16:37:00 from Marcio Andrey Oliveira

9 Mar 2008 »

Livros que eu já li

Aqui estão alguns dos livros que eu já li (técnicos ou não).



Shelfari: Book reviews on your book blog<script src="http://www.shelfari.com/ws/39201/widget.js" language="javascript" type="text/javascript"></script>

Syndicated 2008-01-24 19:40:00 from Marcio Andrey Oliveira

9 Mar 2008 »

Procurando várias palavras ao mesmo tempo

Uso o Vim todos os dias e minha admiração por ele sempre se renova. Ele é tão cheio de recursos que duvido que exista alguém que consiga utilizar 100% das suas capacidades.

Um dos recursos que o Vim possui que mais me agrada é a sua capacidade de procurar por várias palavras diferentes ao mesmo tempo no texto.

Normalmente, quando queremos procurar uma palavra, entramos no modo de comando e digitamos:

/palavra <ENTER>

- Mas e quando queremos procurar duas ou mais palavras? Vamos ter que fazer as buscas separadamente?

Não! Nós efetuamos a busca, no modo de comando, com as palavras separadas pelo pipe escapado (\|) :

/palavra1\|palavra2\|palavra3 <ENTER>

A figura 1 abaixo ilustra o comando de busca para quatro palavras. Observe que os espaços são considerados como parte da palavra que se procura.


A figura 2 mostra o resultado da busca.


Espero que esta dica seja tão útil para ti quanto é para mim.

Syndicated 2008-01-23 00:15:00 from Marcio Andrey Oliveira

9 Mar 2008 »

Entendendo o Mercurial (2)

Fiz as correções na tradução do artigo Understanding Mercurial. A versão traduzida encontra-se aqui.

Aproveito para agradecer ao meu amigo Wanderley pelas correções e sugestões.

Syndicated 2008-01-15 16:01:00 from Marcio Andrey Oliveira

21 older entries...

New Advogato Features

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!