crash handling

Estaba yo preguntándome esta tarde si sería posible lanzar de forma automática gdb cuando un programa cascara, sin necesidad de ponerse a depurar después, reproducir el bug, etc, al estilo del manejador de errores que instala Visual Studio en Windows que pregunta si se desea depurar la aplicación.

Me ha salido algo como esto (HTML horrible para el coloreado de sintaxis patrocinado por Vim):

#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void attach_gdb(int signum)
{
    pid_t gdbpid;
    pid_t debuggee_pid = getpid();
    int gdb_exit_status;
    char pidbuf[100];
    char exebuf[100]; // should be safe unless PIDs reach ~90 digits ;P
    sprintf(pidbuf, "%d", debuggee_pid);
    sprintf(exebuf, "/proc/%d/exe", debuggee_pid);
    printf("Signal %d received. Attaching GDB to process. PID=%d\n", signum, debuggee_pid);

    if ((gdbpid = fork()) == 0)
    {
        execlp("gdb", "gdb", exebuf, pidbuf, NULL);
        perror("execlp");
        exit(1);
    }

    waitpid(gdbpid, &gdb_exit_status, 0); // hold on, we want to be debugged
    exit(1);
}

void __attribute__((constructor)) setup_handler()
{
    struct sigaction sa, old_sa;
    sa.sa_handler = attach_gdb;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags=0;
    // Register the handler for all actions which dump core by default
    sigaction(SIGSEGV, &sa, &old_sa);
    sigaction(SIGFPE, &sa, &old_sa);
    sigaction(SIGABRT, &sa, &old_sa);
    sigaction(SIGILL, &sa, &old_sa);
    sigaction(SIGQUIT, &sa, &old_sa);
}

Si se compila como librería dinámica y se enlaza a cualquiera de nuestros programas (o se precarga con LD_PRELOAD) lanza un gdb asociado al proceso al recibir cualquiera de las señales que causarían un core dump y terminación del programa :D.

¿Alguna idea para mejorarlo y que sea práctico? ¿Existe ya algo asi en un paquete Debian que hace mil cosas molonas más? (seguro que sí XD).

1 Comment »

  1. Elisa Brown said,

    April 18, 2017 @ 19:14 pm

    I came across your Nightly build » crash handling website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE website traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://tdil.co/3p

  2. adidas stan smith uk said,

    April 19, 2017 @ 00:56 am

    I’m writing to make you know what a helpful encounter my cousin’s girl found reading your web page. She realized several issues, most notably what it’s like to possess an excellent helping mindset to make the others without difficulty gain knowledge of selected extremely tough subject matter. You actually did more than people’s expectations. I appreciate you for distributing the effective, trusted, revealing and even easy tips on the topic to Julie.

  3. Augusto de Arruda Botelho said,

    April 19, 2017 @ 07:33 am

    Hello there! I know this is somewhat off topic but I was wondering if you
    knew where I could get a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having trouble finding one?

    Thanks a lot!

  4. Lorna said,

    April 19, 2017 @ 07:50 am

    If some one wishes expert view regarding blogging after that i advise
    him/her to visit this blog, Keep up the pleasant work.

  5. Fran said,

    April 19, 2017 @ 09:40 am

    I think what you published made a bunch of sense.
    However, what about this? what if you were to write a awesome title?
    I ain’t saying your information isn’t solid., however suppose you added something
    that makes people want more? I mean Nightly build » crash handling
    is kinda plain. You could glance at Yahoo’s front page and
    watch how they create news headlines to grab people to open the
    links. You might add a video or a related pic or two to grab people interested about everything’ve got to say.

    In my opinion, it might make your posts a little livelier.

  6. cheap jordans said,

    April 19, 2017 @ 10:59 am

    I and my pals have already been reviewing the excellent pointers located on the website and then at once I had a terrible feeling I never expressed respect to the site owner for them. My people had been as a result joyful to read through all of them and have really been having fun with these things. We appreciate you turning out to be indeed kind and then for deciding upon certain important subject matter most people are really desperate to know about. Our honest apologies for not expressing appreciation to you sooner.

  7. yeezy boost said,

    April 19, 2017 @ 11:19 am

    Thanks a lot for giving everyone such a special opportunity to check tips from this blog. It’s usually so fantastic plus stuffed with a good time for me and my office fellow workers to search your web site at the least 3 times per week to learn the new tips you will have. And definitely, I’m also always impressed with your perfect information you serve. Some 4 tips in this posting are clearly the most suitable we have all had.

  8. Augusto de Arruda Botelho said,

    April 19, 2017 @ 11:51 am

    Great post! We are linking to this particularly great article on our website.

    Keep up the great writing.

  9. cs go skin trade hack said,

    April 19, 2017 @ 13:21 pm

    Hello to all, it’s genuinely a good for me to go to see this site, it includes
    precious Information.

  10. Augusto de Arruda Botelho said,

    April 19, 2017 @ 15:48 pm

    excellent issues altogether, you just gained a logo
    new reader. What could you recommend about your submit
    that you made some days in the past? Any certain?

  11. nike air force 1 low said,

    April 20, 2017 @ 00:10 am

    My spouse and i have been absolutely ecstatic that Albert managed to finish off his reports by way of the ideas he grabbed when using the web page. It is now and again perplexing to simply continually be offering methods which often men and women have been selling. And now we consider we need the website owner to appreciate because of that. The specific explanations you’ve made, the simple web site menu, the relationships you will help to engender – it is mostly awesome, and it’s really making our son and the family know that the theme is brilliant, which is really important. Thanks for all the pieces!

  12. cs go knife skins for sale said,

    April 20, 2017 @ 06:09 am

    There’s definately a great deal to learn about this subject.

    I really like all the points you’ve made.

  13. Adidas NMD Runner Unisex Black Light Blue Grey said,

    April 20, 2017 @ 07:20 am

    Whats up! I simply want to give a huge thumbs up for the good information you may have right here on this post. I shall be coming back to your weblog for extra soon.

  14. Geri said,

    April 20, 2017 @ 10:30 am

    Hi there, I enjoy reading all of your article post.
    I wanted to write a little comment to support you.

  15. Jacelyn said,

    April 20, 2017 @ 12:26 pm

    No matter if some one searches for his necessary thing, therefore he/she desires
    to be available that in detail, so that thing is maintained over
    here.

  16. Liam said,

    April 20, 2017 @ 16:08 pm

    It’s enormous that you are getting thoughts from this post as well as from
    our discussion made at this time.

  17. lebron shoes said,

    April 20, 2017 @ 21:35 pm

    Thanks a lot for giving everyone a very remarkable opportunity to read critical reviews from this site. It really is so kind and as well , full of fun for me personally and my office colleagues to visit your website the equivalent of three times in one week to see the fresh issues you have got. Of course, I am just certainly impressed concerning the magnificent opinions you give. Some 3 points in this article are certainly the most effective I’ve had.

  18. Bill said,

    April 21, 2017 @ 05:25 am

    I every time spent my half an hour to read this web site’s posts all the time along with
    a mug of coffee.

  19. sexy said,

    April 21, 2017 @ 08:43 am

    Hand Histories can be downloaded for evaluation, transformed with the Bovada Converter , and imported into PokerTracker4 to track one’s own play (Can’t track nameless
    opponents).

  20. nba live coins cheap said,

    April 21, 2017 @ 09:09 am

    Hi there, just became alert to your blog through Google,
    and found that it is truly informative. I am gonna watch out for brussels.
    I’ll appreciate if you continue this in future.
    A lot of people will be benefited from your writing.
    Cheers!

  21. day trade to win review said,

    April 21, 2017 @ 10:44 am

    Une salle de jeu terrestre est la salle de jeu tel que nous connaissons, l’exemple type est le casino.

  22. doctors notes said,

    April 21, 2017 @ 11:02 am

    PokerStars est le website de certains des meilleurs joueurs de
    poker.

  23. Lorenza said,

    April 21, 2017 @ 12:30 pm

    My relatives always say that I am killing my time here at net, except I know I am getting familiarity every day by reading thes fastidious articles or reviews.

  24. Tiara said,

    April 21, 2017 @ 14:47 pm

    Hey there! I know this is kinda off topic but
    I’d figured I’d ask. Would you be interested in trading links or maybe guest authoring a blog post or vice-versa?
    My website goes over a lot of the same topics as yours and
    I believe we could greatly benefit from each
    other. If you happen to be interested feel free to shoot me an email.
    I look forward to hearing from you! Fantastic blog by the way!

  25. Demetra said,

    April 21, 2017 @ 17:22 pm

    What i do not understood is in fact how you are now not really much more smartly-preferred than you may be now.
    You are so intelligent. You recognize therefore significantly on the
    subject of this subject, made me individually believe it
    from so many numerous angles. Its like women and men aren’t interested
    until it is one thing to accomplish with Girl gaga!
    Your individual stuffs nice. Always maintain it up!

  26. Georges Sadala said,

    April 21, 2017 @ 19:17 pm

    Hello There. I found your blog the usage of msn. This is an extremely
    neatly written article. I will make sure to bookmark it and return to read more
    of your useful info. Thank you for the post. I’ll definitely return.

  27. hogan outlet online said,

    April 21, 2017 @ 22:09 pm

    Thanks a lot for providing individuals with remarkably marvellous chance to read from this web site. It’s usually very sweet plus full of a good time for me and my office mates to visit your blog on the least thrice every week to see the new stuff you will have. And definitely, we’re actually amazed with the very good creative concepts you give. Some 1 points in this post are clearly the most suitable we have all had.

  28. fifa coins for sale xbox 360 said,

    April 22, 2017 @ 06:49 am

    We’re a group of volunteers and starting a brand
    new scheme in our community. Your site offered us with helpful information to work on. You’ve done a
    formidable activity and our entire group will likely be thankful to you.

  29. yeezy boost said,

    April 22, 2017 @ 07:26 am

    Needed to compose you the little observation to finally give thanks yet again over the spectacular concepts you have documented above. It is surprisingly generous of you to offer without restraint exactly what a few individuals would’ve sold for an electronic book to generate some bucks on their own, precisely now that you could have tried it in case you wanted. The tips additionally worked to be the good way to know that some people have similar fervor like my very own to understand significantly more around this issue. Certainly there are a lot more pleasurable times up front for folks who examine your website.

  30. Gisele said,

    April 22, 2017 @ 10:26 am

    Hey! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my blog to rank
    for some targeted keywords but I’m not seeing very good gains.

    If you know of any please share. Thank you!

  31. atlanta falcons jersey said,

    April 22, 2017 @ 10:38 am

    I enjoy you because of every one of your effort on this web page. Gloria take interest in getting into research and it’s really easy to see why. Almost all hear all about the lively manner you present powerful guidance through your blog and as well as improve participation from some others about this topic then our favorite child is now understanding a lot of things. Enjoy the remaining portion of the new year. Your performing a remarkable job.

  32. Itamar Serpa Fernandes said,

    April 22, 2017 @ 12:59 pm

    It is the best time to make some plans for the future
    and it’s time to be happy. I’ve read this post and if I could I
    wish to suggest you few interesting things or advice. Maybe you could write next articles referring to this article.

    I want to read more things about it!

  33. bully max said,

    April 23, 2017 @ 00:32 am

    All calls after i stopped. Opening an preliminary no turbo freerolls pokerstars.

  34. Dani said,

    April 23, 2017 @ 00:58 am

    Because the admin of this web page is working, no doubt very shortly it will
    be renowned, due to its feature contents.

  35. live cams said,

    April 23, 2017 @ 01:00 am

    J’ai alors switché sur Get together Poker, avec les 1k de bankroll qui me restait,
    et ait remonté tout doucement les limites, mais avec un état de bankroll qui restait toutefois assez critique.

  36. madden mobile coin cheat no download said,

    April 23, 2017 @ 04:15 am

    I savour, result in I discovered exactly what I used to
    be looking for. You have ended my 4 day lengthy hunt!
    God Bless you man. Have a nice day. Bye

  37. longchamp said,

    April 23, 2017 @ 09:44 am

    Thanks for all of the labor on this website. Kim really likes making time for investigations and it is easy to see why. Most of us notice all about the lively ways you deliver helpful tips on the blog and therefore strongly encourage contribution from other individuals on this article so our daughter is without a doubt becoming educated a lot of things. Enjoy the rest of the year. Your carrying out a pretty cool job.

  38. Elisa Brown said,

    April 23, 2017 @ 09:52 am

    This is a message to the Nightly build » crash handling admin. Your website is missing out on at least 300 visitors per day. Our traffic system will dramatically increase your traffic to your site: http://r.rokapack.com/19 – We offer 500 free targeted visitors during our free trial period and we offer up to 30,000 targeted visitors per month. Hope this helps :)

  39. yeezy boost 350 said,

    April 23, 2017 @ 17:53 pm

    I have to show my love for your kindness supporting people who actually need guidance on your idea. Your real dedication to getting the message all over turned out to be exceedingly informative and has in every case allowed some individuals much like me to attain their targets. Your invaluable tutorial denotes so much a person like me and especially to my office colleagues. Thank you; from everyone of us.

  40. toronto wedding photographer said,

    April 23, 2017 @ 20:31 pm

    Playing poker at our poker website is a good way to benefit from
    the thrilling card sport that has a worldwide following.

  41. nike air zoom said,

    April 23, 2017 @ 21:36 pm

    Thanks for all of the work on this site. Betty loves conducting investigations and it’s easy to see why. My spouse and i know all of the dynamic mode you convey both interesting and useful tips and hints via your blog and in addition increase contribution from some other people on this topic so our favorite child is undoubtedly being taught a lot. Take advantage of the remaining portion of the year. Your conducting a dazzling job.

  42. natureal fda said,

    April 24, 2017 @ 04:42 am

    Tiger Gaming is a type of smaller online poker sites you won’t have heard
    of but actually provides a pretty spectacular poker experience.
    This is not a hardcore grinders site and, whereas the traffic is
    small, there are some very mushy spots to be had.
    It’s not a bunch of nits and bots making an attempt to grind out marginal profits.

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