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

    June 22, 2017 @ 13:28 pm

    personal loans no faxing – https://personalloansnhl.org/ personal loans for bad credit [url=https://personalloansnhl.org/]personal loans[/url] ’

  2. bigfamilyhouse.de said,

    June 22, 2017 @ 13:44 pm

    Hello there! This is kind of off topic but I need some advice from an established blog.
    Is it 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 tips or suggestions? Thank you

  3. Instagram Follower Booster App Android said,

    June 22, 2017 @ 15:21 pm

    Excellent post. I was checking continuously this blog and I
    am impressed! Extremely useful information specially the last part :) I care for
    such information a lot. I was looking for this particular information for a very
    long time. Thank you and best of luck.

  4. Mike said,

    June 22, 2017 @ 16:25 pm

    I am really loving the theme/design of your site.
    Do you ever run into any browser compatibility issues?
    A handful of my blog audience have complained about my blog not operating correctly in Explorer but looks great in Chrome.
    Do you have any suggestions to help fix this problem?

  5. GfdddsWala said,

    June 22, 2017 @ 18:54 pm

    online payday loans with – https://paydayloansxxe.com/ online payday loans [url=https://paydayloansxxe.com/]online payday loans[/url] ’

  6. Get More Instagram Followers Free Fast Website said,

    June 22, 2017 @ 19:13 pm

    This info is invaluable. When can I find out more?

  7. sunfrog t shirt said,

    June 22, 2017 @ 19:52 pm

    I visited multiple web pages however the audio feature for audio songs current at this site is really marvelous.

  8. BrellJUS said,

    June 22, 2017 @ 20:50 pm

    personal loans with bad credit – https://badcreditjkkl.com/loan bad credit [url=https://badcreditjkkl.com/]bad credit loan[/url] ’

  9. safety gate with pet door said,

    June 22, 2017 @ 20:55 pm

    Is it really helping? 1. Take your child shoe shopping.

  10. LwvcTussy said,

    June 22, 2017 @ 21:40 pm

    payday loans – https://paydayeev.com/ payday loans [url=https://paydayeev.com/]payday loans[/url] ’

  11. LwvcTussy said,

    June 22, 2017 @ 22:16 pm

    no fax same day payday loans – https://paydayeev.com/ no fax no teletrack payday loans [url=https://paydayeev.com/]payday loans[/url] ’

  12. GfdddsWala said,

    June 22, 2017 @ 22:52 pm

    no fax no teletrack payday loans – https://paydayloansxxe.com/ no fax no teletrack payday loans [url=https://paydayloansxxe.com/]no fax no teletrack payday loans[/url] ’

  13. Bernardo said,

    June 22, 2017 @ 23:06 pm

    This is my first time visit at here and i am
    genuinely happy to read all at alone place.

  14. Llkidpag said,

    June 23, 2017 @ 00:38 am

    personal loans no faxing – https://personalloanplk.com/ unsecured personal loans [url=https://personalloanplk.com/]personal loans bad credit[/url] ’

  15. LoplSot said,

    June 23, 2017 @ 01:59 am

    online installment loans – https://installmentloannbbm.com/bad credit installment loans [url=https://installmentloannbbm.com/]bad credit personal installment loan[/url] ’

  16. Llkidpag said,

    June 23, 2017 @ 02:03 am

    loans personal loans – https://personalloanplk.com/ personal loans for bad credit [url=https://personalloanplk.com/]unsecured personal loans[/url] ’

  17. http://mashhad.tvta.ir/ActivityFeed/MyProfile/tabid/312/userId/17143/Default.aspx said,

    June 23, 2017 @ 02:37 am

    Hi! I’m at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading through your blog and look forward to all your
    posts! Keep up the superb work!

  18. snapstealer.pro said,

    June 23, 2017 @ 03:32 am

    I don’t even know how I ended up here, but I thought this post was great.
    I don’t know who you are but certainly you are going to
    a famous blogger if you aren’t already ;) Cheers!

  19. LoplSot said,

    June 23, 2017 @ 04:35 am

    online installment loans – https://installmentloannbbm.com/online installment loans [url=https://installmentloannbbm.com/]online installment loans[/url] ’

  20. pop-up photo studios at Asian weddings said,

    June 23, 2017 @ 04:37 am

    Ahaa, its pleasant discussion on the topic of this paragraph here at this webpage, I have
    read all that, so now me also commenting at this place.

  21. Find out more about a whole house reverse osmosis system said,

    June 23, 2017 @ 04:50 am

    Thanks in favor of sharing such a good thinking, piece of writing
    is good, thats why i have read it fully

  22. FervfgEn said,

    June 23, 2017 @ 04:53 am

    generic cialis – http://cialisonlineanegeneric.com/ generic cialis [url=http://cialisonlineanegeneric.com/]buy cialis[/url] ’

  23. Donde Puedo Comprar VigRX Plus En Argentina said,

    June 23, 2017 @ 05:21 am

    I go to see each day some websites and websites to read articles or reviews,
    but this weblog presents feature based articles.

  24. New Orleans Saints John Jenkins Jersey said,

    June 23, 2017 @ 05:43 am

    You can sleep and eat at this hideaway in the Loire Valley. It’s likely you’ll be following other network marketers. People are the major factors yourself will imagine concerning each time coming up with an offer you. Nevertheless, if the course can beat you up and still entice you back for more, it must be good. You canstudy new things although playing this particular game like the way to put additional effort to succeed in at next level, how to control your assets.
    New Orleans Saints John Jenkins Jersey

  25. http://ewb2.dothome.co.kr said,

    June 23, 2017 @ 05:52 am

    Hey just wanted to give you a quick heads up.
    The text in your article seem to be running off the screen in Opera.
    I’m not sure if this is a formatting issue or something
    to do with web browser compatibility but I thought I’d post
    to let you know. The style and design look great though!
    Hope you get the problem resolved soon. Thanks

  26. Henrik Lundqvist Jersey UK said,

    June 23, 2017 @ 05:54 am

    The profits out from the site tend to be determined by the actual congenial efforts put forth by the seo companies in the first place. It is possible to use visualisation and affirmations to help work on self image. In comes the junk man or perhaps better stated, the junk people. Make sure you ask for discounts during the offpeak season.) Rather than starting class with some form of curriculum, I start with neutral ground.
    Henrik Lundqvist Jersey UK

  27. Cheap NFL Jerseys Wholesale China said,

    June 23, 2017 @ 06:07 am

    Texas deregulation electricity suppliers offer commercial and residential property owners advice on how to save money on their energy bills. Furthermore these profits have steadily continued, up until the recent day in 2006, with Betfair trading being my full-time job until recently.39 to back and 1. No tucking your hip bones under or swaying your back and rolling forward off your pelvic bone onto your thighs. Duckett appears poised to become a fantastic asset for the Lions this year.
    Cheap NFL Jerseys Wholesale China

  28. Steven Matz Jersey UK said,

    June 23, 2017 @ 06:22 am

    Hence it is exceptionally sizeable that oneself dont even try out toward open up an electronic mail which is mysterious in direction of your self. Of course, it is important that these really look nice and, if possible, these should complement the interior design but what is most important is that they are comfortable for the customers, especially the chairs.” With a team of nationwide dealers, offices and distributions facilities on both coasts, and free CAD services to purchasing customers, MAiSPACE feels completely confident in being able to deliver any size project on time and on budget. At 10 10 Drones, assemble an Overlord.To start a search, head to the Department of Justice and secure the Live Scan form.
    Steven Matz Jersey UK

  29. Wholesale China Jerseys said,

    June 23, 2017 @ 06:43 am

    Check also some of the projects he has handled in the past. Selecting an incompatible coach or supporting staff could lead to an ineffective team and a disappointing season. A full 180 degree splits depends on loose hamstrings, loose buttock muscles, loose hip muscles, loose inner thigh muscles (of the derriere leg) and also a loose spine (anterior muscles front of spine, and lateral muscles on either side of the spine. For more information click here. This is quite an extravagant approach to the use of resources available.
    Wholesale China Jerseys

  30. Wholesale Jerseys Cheap said,

    June 23, 2017 @ 07:01 am

    To begin with, it’s the most ideal materials to keep your feet warm, plus with the ability to keep them cool when the weather is hot. And also, make sure that there’s a flexible billing plan, and you are able to cancel your membership anytime.”Former Yankee War Pilot Jerry Coleman Dies At 89 – RealGM WiretapCommissioner Bud Selig issued the following statement regarding the passing of 2005 Ford C. You want a site that updates their database at least one time per week. In actuality, your initial customers of UGGs were literally surfers, but these days they have got become stylish among both famous people and also the general public.

  31. gmail.com login said,

    June 23, 2017 @ 07:47 am

    In the Android Gmail app, tap the Action overflow menu (a few vertical dots) to your right of the sender’s name within an open email
    to dam the sender.

  32. Ccusaf said,

    June 23, 2017 @ 08:03 am

    loans people bad credit bad credit loan bad credit loans guaranteed approval [url=https://badcreditjkkl.com/]bad credit installment loans[/url] ’

  33. FervfgEn said,

    June 23, 2017 @ 08:16 am

    cialis online – http://cialisonlineanegeneric.com/ generic cialis [url=http://cialisonlineanegeneric.com/]cheap cialis[/url] ’

  34. BrdedFoori said,

    June 23, 2017 @ 09:21 am

    cash advance online – https://cashadvancetfj.com/payday loans cash advances [url=https://cashadvancetfj.com/]cash advance near me[/url] ’

  35. Cheap NFL Jerseys Free Shipping said,

    June 23, 2017 @ 11:30 am

    Whenever they have trouble locating the best electrician Orange County dwellers check the web.Time and CostApplying a brand new set of nail gels typically takes up to 2 hours and fill up can take up to 45 minutes that will depend on the kind of products, power of heat light fixture and the timing of a gel coat. Not surprisingly, Woods stands out, too. By acquiring yourself initial, you will gradually accumulate a financial basic web. Don’t make this information up.
    Cheap NFL Jerseys Free Shipping

  36. http://www.cheapnfljerseysdiscount.us.com/ said,

    June 23, 2017 @ 11:55 am

    If the person does this, then the carpets may be used somewhere else around the house. It should then be used as protection for their pick up truck’s bed.You can also visit the internet.One method to unearth achievement in Forex trading is actually by letting your profits to run. Furthermore these profits have steadily continued, up until the recent day in 2006, with Betfair trading being my full-time job until recently.

  37. VedwsHiz said,

    June 23, 2017 @ 12:13 pm

    online payday loans online payday loans with no fax payday loans direct lenders [url=https://paydayloansxxe.com/]payday loans 300[/url] ’

  38. W1ayneGrize said,

    June 23, 2017 @ 12:26 pm

    Reverse Phone Lookup

    i reverse phone lookup
    r http://reversephonelookupfreeus.com/#
    reverse phone lookup

  39. W1ayneGrize said,

    June 23, 2017 @ 12:39 pm

    Reverse Phone Lookup

    z reverse phone lookup spy
    i http://reversephonelookupfreeus.com/#
    reverse phone lookup

  40. Marc Andre Ter Stegen Jersey said,

    June 23, 2017 @ 12:40 pm

    Using Twitter is pretty easy.com blog business and is a certified teacher and learning specialist and is the author Jhonny Peralta Has Surgery Out Until MidseasonRealGM WiretapJhonny Peralta underwent surgery to repair a torn ligament in his left thumb Thursday morning and will be out until midseason, according to the St.Good luck, and most of all…have fun!– Readers Digest ( Binoculars can be used for this service.
    Marc Andre Ter Stegen Jersey

  41. Michigan Wolverines Jerseys said,

    June 23, 2017 @ 13:10 pm

    The final step in curing my materialism was the locker auction because up to that point we had only been junk amateurs. Experience has taught us that projects are best planned with a coordinated team to manage logistics and help clients mitigate extraneous costs and risks associated with employee downtime. Deservedly rated by many Pro’s as their favourite course in that part of the world. Make a Queen in addition to a set of Zerglings. I anticipate this tiny report aids your self with your appear for Holdem poker internet websites for sale.
    Michigan Wolverines Jerseys

  42. http://nprnews.org/ said,

    June 23, 2017 @ 13:38 pm

    Great post! We will be linking to this particularly
    great post on our website. Keep up the good writing.

  43. http://repubrick.fr/ said,

    June 23, 2017 @ 15:13 pm

    Link exchange is nothing else but it is only placing
    the other person’s blog link on your page at proper place and
    other person will also do similar in support
    of you.

  44. introducing allergenic foods to babies said,

    June 23, 2017 @ 15:14 pm

    I couldn’t resist commenting. Well written!

  45. main domino qiu qiu said,

    June 23, 2017 @ 15:21 pm

    You should take part in a contest for one of the best sites
    on the internet. I most certainly will recommend this web site!

  46. this content said,

    June 23, 2017 @ 15:25 pm

    Thank you for the auspicious writeup. It in fact was a leisure account
    it. Look complex to far delivered agreeable from you!
    By the way, how can we be in contact?

  47. Ccusaf said,

    June 23, 2017 @ 15:36 pm

    bad credit personal loans loans bad credit loan with bad credit [url=https://badcreditjkkl.com/]bad credit instant approval payday loans[/url] ’

  48. VedwsHiz said,

    June 23, 2017 @ 15:48 pm

    no fax no teletrack payday loans payday loans payday loans no credit check [url=https://paydayloansxxe.com/]payday loans online[/url] ’

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