Trazas con gdb

Todo programador ha pasado alguna vez por la experiencia de depurar un programa a golpe de printf(), con los inconvenientes que ello supone, sobre todo recompilar cada vez que se quiere cambiar la información que se imprime en la traza.

Pues resulta que es posible hacer las cosas “bien” :)

Con gdb podemos imprimir los valores de variables de nuestro programa, eso es algo que todos sabemos PERO tambien podemos darle una serie de órdenes a ejecutar al pasar por un breakpoint.

Veamos un ejemplo. Sea el siguiente programa en C:

#include <stdio.h>

int main()
{
        int i;
        double x=2.0f;
        for (i=0; i<64; i++)
                x*=2;
        return 0;
}

Si compilamos con -g (para debug) y lo lanzamos en gdb podemos visualizar los valores de x así:


(gdb) break 8
Breakpoint 1 at 0x400463: file a.c, line 8.
(gdb) commands 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>silent
>printf "x=%g\n",x
>cont
>end
(gdb) r
Starting program: /home/slack/a.out
x=2
x=4
x=8
x=16
x=32
x=64
[...]

El “silent” del principio es para que gdb no imprima la información que suele mostrar al pararse en un breakpoint (fichero, número de línea, contador de programa, etc) y la traza salga más limpia.

Por supuesto se pueden hacer mas cosas. gdb permite definir variables externas al programa y ejecución condicional, así que podemos contar las veces que pasamos por algun sitio y lanzar órdenes en momentos concretos y tonterías similares :D

Happy coding!

1 Comment »

  1. Rita said,

    January 19, 2018 @ 18:35 pm

    The very best distributor for 100% pure Garcinia that we
    have actually located in South Africa is shown here( Pure Garcinia cambogia extract Remove ).
    You could buy from them listed below.

  2. all4webs.com said,

    January 19, 2018 @ 19:50 pm

    Wow, this paragraph is pleasant, my sister is analyzing these kinds of things,
    thus I am going to inform her.

  3. benzzi surfait said,

    January 19, 2018 @ 20:11 pm

    Some truly select blog posts on this site, bookmarked .

  4. http://nest.2land.co.il said,

    January 19, 2018 @ 20:17 pm

    Great blog here! Also your web site loads up very fast!

    What host are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as fast as yours lol

  5. Cheap Jerseys From China said,

    January 19, 2018 @ 20:22 pm

    Some providers offer their range of products to such clients mainly, as they become regular and when they purchase something, they do it in bulk.If you are not quite experienced with colour make contact with lenses, it is best to go with regular (round) lenses. Specially designed roof mounted exhaust fans would mechanically vent heat and smoke under emergency fire conditions.Understand that the disciplinary procedure is around educating your son or daughter, not hurting them. This is a good way to get modern style home.

  6. Whinna said,

    January 19, 2018 @ 20:26 pm

    http://personalloansx1.com/
    payday loans long beach ca
    personal loans
    bad credit rating loans
    personal loans

  7. Sophiaweili said,

    January 19, 2018 @ 20:38 pm

    harrah’s casino locations by state
    casinos in us
    absolutely free slots for fun
    400 free slot games

  8. Davidhic said,

    January 19, 2018 @ 20:44 pm

    online autocad jobs
    autodesk sketchbook
    descargar autocad 2017 en ingles gratis
    autodesk maya
    curso de autocad download
    download autocad
    autodesk autocad mechanical 2017 product key
    download autocad
    autocad 2011 upgrade to 2012

  9. Florida movers said,

    January 19, 2018 @ 21:33 pm

    Hey! This is kind of off topic but I need some help from an established blog.

    Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty
    quick. I’m thinking about creating my own but I’m not sure where to
    start. Do you have any ideas or suggestions? Appreciate it

  10. Whinna said,

    January 19, 2018 @ 21:56 pm

    http://personalloansx1.com/
    need personal loan
    personal loans
    get loan online
    personal loans

  11. Irommage said,

    January 19, 2018 @ 22:25 pm

    http://personalloansx1.com/
    payday loans in columbus ohio
    personal loans
    unsecured personal loans for people with bad credit
    personal loans

  12. Geneo Grissom Jersey said,

    January 19, 2018 @ 22:30 pm

    How weird is that! Well this statistics came from the fact that by 2016 the world population would be somewhere near 7. I’ve read different tips via various instructors, and so they all work. You can do the math yourself.(Australian Capital Territory) being the base for municipality functions for sports venues, grounds and recreation parks it was found that the A. After by yourself pick and put in your refreshing software package, its season in the direction of generate some choices as toward how significantly safety is suitable for your personal computer.
    Geneo Grissom Jersey http://www.nflmall.us.com/New-england-patriots-geneo-grissom-jersey/

  13. E'Twaun Moore Jersey UK said,

    January 19, 2018 @ 22:32 pm

    I hope it was of interest to you as it is to me. I hope it was of interest to you as it is to me. You should go to the article for more facts!Article From Article Directory DatabaseAustralia has a reputation for providing the world with legendary sports men and woman, world class facilities, sporting technology and arguably the worlds number one development base. Any company that statements a person needs to spend some money to become recruited or even make more money is a fake company.Small print runs are possible.
    E’Twaun Moore Jersey UK http://www.thenbauk.com/new-orleans-pelicans-etwaun-moore-jersey/

  14. http://www.ncaasportsshop.com/Auburn-Tigers-Alec-Jackson-Jersey/ said,

    January 19, 2018 @ 22:57 pm

    To change into one, you first have to have the precise tools for the job. You can actually wind up losing money to the agency you thought would make you a leading model. Another circumstances would be to call them initially, ask if it’s a great time, then ask if they may have any inquiries additional next beginning your practice. This means that you can offer a relatively small batch of products at a reduced price. There are indicators that girls give out, when they see a male they find attractive.

  15. acourne said,

    January 20, 2018 @ 00:46 am

    http://personalloansx1.com/
    personal loan criteria
    personal loans
    apply for credit online
    personal loans

  16. amaddy said,

    January 20, 2018 @ 01:01 am

    http://personalloansx1.com/
    social loan
    personal loans
    quick cash bad credit
    personal loans

  17. tieprix said,

    January 20, 2018 @ 02:39 am

    http://personalloansx1.com/
    fast personal loans online
    personal loans
    direct online payday loan lenders
    personal loans

  18. https://www.nba2kworld.net/nba-2k18-locker-codes-guide/ said,

    January 20, 2018 @ 03:04 am

    Fantastic goods from you, man. I have understand your stuff previous to and you’re just too excellent.
    I actually like what you have acquired here, really
    like what you are stating and the way in which you say it.
    You make it enjoyable and you still care for to keep it sensible.

    I can not wait to read much more from you. This is really a wonderful website.

  19. movie said,

    January 20, 2018 @ 03:49 am

    This text is worth everyone’s attention. How can I find out more?

  20. Cheap Jerseys said,

    January 20, 2018 @ 03:55 am

    Considering that you may be in a group discussion, you might not hear a joke being cracked.Halloween contacts collections and producersTwo collections dominate the special result Halloween contacts market – Crazy Lenses, developed by Cooper Vision, and Wild Eyes, created by Ciba Eyesight. These heavy gauge materials prevent warping of fan parts and malfunction at high temperatures.Change out what games your toddlers have fun with on occasion hence they refrain from acquiring tired of a particular set up. Routine checks on tyres are vital to stay safe on the road.
    Cheap Jerseys http://www.wholesalesportsjerseyscheap.us.com/

  21. http://www.sportsnflshop.com/Carolina-Panthers-Scott-Simonson-Jersey-Sale/ said,

    January 20, 2018 @ 04:33 am

    Due to the A.5. Involve them moderately in your social life. starting to be again within just the serious diamond ring consuming Microphone Tyson inside the heyday. That they like to talk about their problems, and many of the time they just want someone who listens to all of them.
    http://www.sportsnflshop.com/Carolina-Panthers-Scott-Simonson-Jersey-Sale/ http://www.sportsnflshop.com/Carolina-Panthers-Scott-Simonson-Jersey-Sale/

  22. Dallas Stars Jersey said,

    January 20, 2018 @ 04:44 am

    Getting used to being in new situations, and learning to talk to different people will increase our children’s confidence considerably. Mobile vs. Most exciting are the Puissance events where the fences grow ever higher round by round, or the mad dash around the shortened courses when more than one horse has had a clear round and a winner has to be found. It was mostly just paying attention, luck, and decent communication between my girls and me, granted sometimes at the top of our lungs.4 million (56%); however venues and sports grounds also received a substantial portion with $410.
    Dallas Stars Jersey http://www.nhlhockeyshop.us.com/Dallas-Stars/

  23. Fluke Networks OMNIScanner 2 LAN Cable Certifier said,

    January 20, 2018 @ 05:07 am

    Fantastic goods from you, man. I have understand your stuff previous to and you are just extremely fantastic.
    I actually like what you’ve acquired here, certainly like what you’re stating
    and the way in which you say it. You make it enjoyable and you still take care of to keep it wise.

    I can’t wait to read far more from you. This is really a great
    web site.

  24. najkorzystniejsze zbiorniki z betonu said,

    January 20, 2018 @ 05:16 am

    all the time i used to read smaller posts which as well clear their motive, and that is also happening with this paragraph which I am reading here.

  25. sefutqoo said,

    January 20, 2018 @ 05:20 am

    キャラウェイの種子は、特にヨーロッパでは、インド亜大陸では、スパイスとして非常に人気があります。 もう犯罪に使ったのか?と思ったら、何と拾った人が近くの交番に届けてくれたという連絡でした。 ミズノ JPX900
    おかげ、お小遣い回りが大変厳しくなっておりましたまだまだ距離感がつかみ切れていないですが、方向性はある程度モノになってきました。 山女が現れる場所は、遠野地方の東にある六角牛山。
    タイトリスト AP3 718 スライスで狙っていて、逆球が出て大怪我の連続でした。 しかしパワフルスイング傾向になってくると、もっと硬めのシャフトを使ってみたくなりました。
    ミズノ JPX900
    お昼ご飯とコーヒー、ごちそうさまでした!!帰宅後、とりあえず本日の収穫をドスドスンと荷下ろし。  今日まで沖縄県が自ら基地は提供したことはないということを強調しておきたい。 タイトリスト 718 ap
     丸一管<5463.T>  軟調。 すでにリシャフトして2週間が経過したが、いまだにしなり方はシビア。
    AP3 718 ボクサー・エンジンの構造原理は90年以上にわたり、独特なデザイン、パワフルなトルク特性、魅力的なサウンドを特徴としている。 「ここ一番のギャンブルショット」と、この間のブログで書いていた通りな感じ。
    ピン g30 評価

  26. dumpster rental Gainesville said,

    January 20, 2018 @ 06:35 am

    An intriguing discussion is worth comment. There’s no doubt that that
    you ought to write more about this subject, it might not be a taboo
    matter but generally people don’t speak about such topics. To the next!

    Cheers!!

RSS feed for comments on this post · TrackBack URI

Leave a Comment

This blog is protected by Dave\'s Spam Karma 2: 17770 Spams eaten and counting...