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. SethWap said,

    May 25, 2017 @ 10:33 am

    cialis con alcohol

    [url=http://cialisbuyvbz.com/]cheap cialis[/url]

    buy cialis

    the best place cialis overnigh

  2. http://pasjagsm.pl/ said,

    May 25, 2017 @ 11:51 am

    Hello there, You’ve done a great job. I’ll definitely digg it
    and personally recommend to my friends. I am sure they’ll
    be benefited from this website.

  3. NFL Jerseys Wholesale said,

    May 25, 2017 @ 11:55 am

    Your traumatic brain injury attorney can help you assess your potential TBI claim and help you get the compensation you deserve for the devastation incurred in traumatic brain injuries. Visitors to LegalView. They are very experienced in the industry and are always up to the task.Easily Choosing From Document Scanning ServicesEasily Choosing From Document Scanning ServicesMay 11, 2014 | Author: Loris F. We will face our challenges head on, step by step with a winning plan.
    NFL Jerseys Wholesale

  4. Cheap Jerseys China said,

    May 25, 2017 @ 11:59 am

    They will put the demands of the customers first and will ensure the protection of their products. Author Resource:All the wholesale companies do not cut out middleman. Among the three options, you can pick any, which you feel has enough benefits.information, so its no use searching for. That’s absolutely \u00fcber coffee for you.
    Cheap Jerseys China

  5. www.mersa-dnd.com said,

    May 25, 2017 @ 12:00 pm

    The most crucial feature of GSA SER is that it can construct links on internet sites that it
    scuffs from search results of lots of internet search engine as opposed to a number of fixed web sites(naturally if you
    like you can also prefer to send to an existing GSA SER
    web link list you got from someplace).

  6. Elba said,

    May 25, 2017 @ 12:03 pm

    Thank you, I’ve just been looking for info about this subject for a while and yours is the greatest I’ve came upon till
    now. However, what in regards to the conclusion? Are you positive concerning the supply?

  7. Party Cleaning Service said,

    May 25, 2017 @ 12:26 pm

    Hello! I just would like to give a huge thumbs up for the great info you have here on this post. I will be coming back to your blog for more soon.

  8. jvdxzeldnn said,

    May 25, 2017 @ 12:34 pm

    Nightly build » Trazas con gdb
    [url=http://www.gst547933a5v3r2q192e5d4cswi37ltzs.org/]ujvdxzeldnn[/url]
    ajvdxzeldnn
    jvdxzeldnn http://www.gst547933a5v3r2q192e5d4cswi37ltzs.org/

  9. Cheap Jerseys China said,

    May 25, 2017 @ 13:19 pm

    Article From Article Directory DatabaseNationals Sign Nate SchierholtzRealGM WiretapThe Washington Nationals have signed Nate Schierholtz to a Minor League contract.Feather skirts are developed by way of stitching a layer of feathers more than the outer material of the skirt.legalview. The skirt is frequently finished off having a ribbon waistband. To be effective, all protective equipment should be properly fitted and used for the purpose in which is was designed.

  10. dublin estate agents said,

    May 25, 2017 @ 13:36 pm

    It’s appropriate time to make some plans for the future and it is
    time to be happy. I have read this post and if I could I want to suggest you few interesting
    things or suggestions. Maybe you could write next articles referring to this article.
    I want to read even more things about it!

  11. GregWap said,

    May 25, 2017 @ 13:39 pm

    only now 100mg cialis

    [url=http://cialiscanadampz.com/]cialis online[/url]

    cialis generic

    billig cialis 20mg

  12. GregWap said,

    May 25, 2017 @ 13:46 pm

    how to order cialis sublingual

    buy cialis online

    cilais price

    cialis e levitra onlin

  13. check it out said,

    May 25, 2017 @ 13:51 pm

    My relatives all the time say that I am wasting my time here
    at net, however I know I am getting know-how all the time by reading thes
    pleasant articles.

  14. domestic contract cleaners dublin said,

    May 25, 2017 @ 14:15 pm

    Wow, this post is nice, my sister is analyzing such things,
    so I am going to let know her.

  15. buy csgo skins said,

    May 25, 2017 @ 14:53 pm

    We stumbled over here different website and thought I might as
    well check things out. I like what I see so now i’m following you.
    Look forward to checking out your web page yet again.

  16. Ollie said,

    May 25, 2017 @ 16:04 pm

    I go to see daily some blogs and information sites to read
    articles, however this website provides quality
    based articles.

  17. residential driveway contractors said,

    May 25, 2017 @ 16:23 pm

    Today, while I was at work, my sister stole my iPad and tested to see if it can survive
    a 25 foot drop, just so she can be a youtube sensation. My
    iPad is now broken and she has 83 views. I know this is totally off topic but I had to
    share it with someone!

  18. transoformational tattoo said,

    May 25, 2017 @ 16:43 pm

    While there are numerous GSA Internet search engine Ranker tutorials you could
    discover, none of them take a look at absolutely every aspect as well as capability of this GSA software.

  19. mail printing said,

    May 25, 2017 @ 17:31 pm

    Nice post. I learn something totally new and challenging on websites I stumbleupon on a daily basis.
    It’s always interesting to read content from
    other authors and use something from their web sites.

  20. Korey said,

    May 25, 2017 @ 17:35 pm

    One of the most preferred versions amongst the software application users are 9.0, 5.2 as well as 4.5.
    The program’s installer documents are generally known as
    Search_Engine_Ranker.

  21. KirkWap said,

    May 25, 2017 @ 17:51 pm

    viagra in uk

    buy viagra

    viagra online

    buy viagra india delhi

  22. Cheap NFL Jerseys said,

    May 25, 2017 @ 17:53 pm

    You have to be strong in the belief that you have what it takes to run a successful business and have zero doubt about that fact.One unique thing about commercial property is that it presents a higher risk threshold than residential units because they can be vacant for a very long time. To find official Georgia Tech merchandise, you can visit his store atAt the college level, over one third of football players has suffered a concussion and about 20 percent have had multiple concussions.A bunch of assorted coloured balloons filled with helium and printed with a advertising message can not fail to be noticed and since advertising is to some extent about getting noticed then helium balloons would appear to be a low cost and effective solution.
    Cheap NFL Jerseys

  23. KirkWap said,

    May 25, 2017 @ 18:44 pm

    wow)) viagra best price

    [url=http://cheapviagrazxd.com/]buy viagra[/url]

    viagra pills

    viagra viro

  24. KirkWap said,

    May 25, 2017 @ 18:51 pm

    best viagra for women in india

    buy viagra

    generic viagra

    viagra sales adelaide

  25. Cheap NFL Jerseys China said,

    May 25, 2017 @ 19:02 pm

    For instance, you can choose offices, industrial or retail property. 8, 1980: Tech 3, Notre Dame 3. Over the past 100 years, Tech has had only 12 head football coaches: John Heisman, Bill Alexander, Bobby Dodd, Bud Carson, Bill Fulcher, Pepper Rodgers, Bill Curry, Bobby Ross, Bill Lewis, George O Leary, Chan Gailey and the present coach, Paul Johnson.” Mike Mussina started that game on September 18, 2003, calling the decision to play a “foolish decision.Concussion is a mild form of TBI from which recovery often occurs without long term effects unless a person experiences multiple concussions.

  26. KateWap said,

    May 25, 2017 @ 20:27 pm

    cialis 5 mg ne ise yarar

    [url=http://www.cialisonline100.com/]cialis without a doctors prescription[/url]

    generic cialis

    cialis kaufen 5 mg

  27. Huvudsida said,

    May 25, 2017 @ 20:41 pm

    There are some interesting points in time in this article but I don¡¯t know if I see all of them center to heart. There is some validity but I will take hold opinion until I look into it further. Good article , thanks and we want more! Added to FeedBurner as well

  28. csgo skins said,

    May 25, 2017 @ 21:00 pm

    Hi there, all is going well here and ofcourse every
    one is sharing data, that’s actually fine, keep up writing.

  29. KateWap said,

    May 25, 2017 @ 21:38 pm

    link for you cialis.com

    generic cialis

    cialis without prescription

    purchase cialis black

  30. KateWap said,

    May 25, 2017 @ 23:05 pm

    cialis original precio

    [url=http://www.cialisonline100.com/]cialis without a doctors prescription[/url]

    cialis pills

    cialis 30 m

  31. Cheap NFL Jerseys said,

    May 25, 2017 @ 23:05 pm

    Hughes had two homers and five RBI Sunday, as the Twins ended a sevengame losing streak with an 114 victory over the Tigers in front of the 57th announced sellout crowd of the season at Target Field. All the wholesale companies do not cut out middleman. You happen to be mentioned just part of an even larger fact: absolutely nothing makes up for diet plan and bodily exercise. The layers of stitching needed to maintain the feathers in location, too as the delicacy from the supplies, make it tough to get a feather skirt to become cleaned at property. Owners that are interested in this process should know the basics of selecting from document scanning services.
    Cheap NFL Jerseys

  32. Wholesale Hockey Jerseys said,

    May 25, 2017 @ 23:08 pm

    Loris F.Nov. Repeated brain injuries have a cumulative effect resulting in more severe and more prolonged postconcussion symptoms.Nov. Ostrich feathers generate a wispy, fringed impact, even though pheasant feathers produce sleek, scalloped layers.
    Wholesale Hockey Jerseys

  33. KateWap said,

    May 25, 2017 @ 23:13 pm

    buying cialis online canada

    cialis pills

    cialis cheap

    cialis pastilla suave

  34. AnnWap said,

    May 25, 2017 @ 23:41 pm

    ontario pharmacy cialis prices

    http://buycialisfxz.com/ – cheap cialis

    order cialis

    cialis super active 20mg uk

  35. air jordan uk said,

    May 25, 2017 @ 23:57 pm

    You have brought up a very good points , regards for the post.

  36. michael kors outlet store said,

    May 25, 2017 @ 23:58 pm

    Some truly nice and useful info on this site, too I conceive the style has got excellent features.

  37. make your own rubber bracelet said,

    May 26, 2017 @ 01:28 am

    Great – I shouild certaily pronounce, impressed with your web site.
    I had no trouble navigating through all the tabs andd relted info ended up being truly simple to doo to access.
    I recently found what I hoped for before you know iit
    at all.Quite unusual. Is likely to appreciate it for those who add forums
    or anything, website theme . a tones way foor your client to communicate.
    Nice task.

  38. GregWap said,

    May 26, 2017 @ 02:05 am

    only here canadain cialis

    [url=http://cialiscanadampz.com/]cialis canada[/url]

    cialis online

    usefull link get cialis online

  39. industrial cleaning equipment dublin said,

    May 26, 2017 @ 02:06 am

    After exploring a few of the blog posts on your site, I seriously appreciate your way of writing a blog.
    I added it to my bookmark site list and will be checking back in the
    near future. Take a look at my web site as well and let me know what you think.

  40. real estate agents said,

    May 26, 2017 @ 02:07 am

    Today, I went to the beach front with my kids. I found a sea shell
    and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.”
    She put the shell to her ear and screamed. There was a hermit
    crab inside and it pinched her ear. She never wants to go
    back! LoL I know this is completely off topic but I had to tell
    someone!

  41. GregWap said,

    May 26, 2017 @ 02:13 am

    can i take two 5mg of cialis

    [url=http://cialiscanadampz.com/]canadain cialis[/url]

    buy cialis

    cialis originale vs generico,

  42. web based digital signage said,

    May 26, 2017 @ 02:51 am

    It’s very effortless to find out any matter on web as compared to textbooks, as I
    found this piece of writing at this website.

  43. start online business with amazon said,

    May 26, 2017 @ 03:04 am

    In current occasions, these often extremely ornate and
    symbolic marriage ceremony rings have seen an enormous resurgence
    in popularity.

  44. official site said,

    May 26, 2017 @ 03:15 am

    With havin so much content do you ever run into any issues
    of plagorism or copyright infringement? My site has a lot of exclusive content I’ve
    either created myself or outsourced but it appears a lot of it
    is popping it up all over the internet without my authorization. Do you know any techniques
    to help protect against content from being stolen? I’d genuinely appreciate it.

  45. antalya escort said,

    May 26, 2017 @ 03:52 am

    Thɑnk you for the goߋd writeup. It іf
    truth be toⅼd waѕ a leisure account іt. Glance complicated tߋ far brought agreeable fгom you!
    By the way, һow can we keep in touch? http://www.timecode.org/

  46. CNC Machining Software said,

    May 26, 2017 @ 04:05 am

    Nightly build » Trazas con gdb

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...