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. http://www.insolvencyadvice.ie/discussion/134428/dumpster-rentals-are-effortless-to-make said,

    January 19, 2018 @ 07:40 am

    Great items from you, man. I have remember your stuff prior to and
    you’re simply extremely excellent. I actually like what you’ve obtained here, really like what you are
    stating and the best way during which you are saying it.

    You are making it enjoyable and you continue to care for to stay it wise.

    I cant wait to learn much more from you. That is really a tremendous site.

  2. Noyes MLP 5-2B said,

    January 19, 2018 @ 07:54 am

    Excellent blog! Do you have any helpful hints for aspiring writers?

    I’m planning to start my own website soon but I’m
    a little lost on everything. Would you advise starting with a free
    platform like WordPress or go for a paid option? There are so many options out there that I’m totally confused ..
    Any tips? Many thanks!

  3. hopkinton interior designer said,

    January 19, 2018 @ 07:57 am

    Heya i’m for the primary time here. I came across this board and I find It really helpful & it helped me out much.
    I hope to provide something back and aid others such as you helped
    me.

  4. free coffee samples by mail said,

    January 19, 2018 @ 08:18 am

    Great delivery. Sound arguments. Keep up the good spirit.

  5. better world said,

    January 19, 2018 @ 08:27 am

    It’s a pity you don’t have a donate button! I’d without a doubt donate to this excellent
    blog! I suppose for now i’ll settle for bookmarking and
    adding your RSS feed to my Google account. I look forward to fresh updates and will share this website
    with my Facebook group. Talk soon!

  6. Light modifiers said,

    January 19, 2018 @ 09:26 am

    Hi there, just became aware of your blog through Google, and found that it’s truly informative.

    I am going to watch out for brussels. I will appreciate if
    you continue this in future. Lots of people will be benefited from your writing.
    Cheers!

  7. altamenterica.com said,

    January 19, 2018 @ 09:58 am

    Hello to every , as I am in fact eager of reading this
    website’s post to be updated on a regular basis.
    It carries nice information.

  8. play doh said,

    January 19, 2018 @ 10:06 am

    Hello there, just became aware of your blog through
    Google, and found that it is really informative.

    I?m going to watch out for brussels. I?ll appreciate if you continue this in future.
    Lots of people will be benefited from your writing. Cheers!

  9. oriesy said,

    January 19, 2018 @ 10:06 am

    buy generic cialis
    prices cialis
    http://buychcialismrxonline.com
    reductil online without prescription cialis 20mg
    buy cialis online

  10. Exterior Painting Atlanta said,

    January 19, 2018 @ 11:43 am

    Do you have a spam problem on this blog; I also am a blogger, and I was wanting to know your situation; many of us have developed some nice practices and we are looking
    to swap strategies with other folks, be sure to shoot me an e-mail if interested.

  11. Addike said,

    January 19, 2018 @ 12:10 pm

    buy generic cialis
    natural forms of viagra cialis pills cialis
    http://buychcialismrxonline.com
    buy cialis online without prescripition
    cialis online

  12. Kevinjaide said,

    January 19, 2018 @ 12:18 pm

    autocad patterns download
    autodesk maya
    autocad architecture 2012 price
    autodesk inventor
    product license activation autocad 2017
    autocad
    autocad revit 2012 download
    autocad
    autocad apple store

  13. brickcousin0.over-blog.com said,

    January 19, 2018 @ 13:29 pm

    Heya just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading correctly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different browsers and both show the same results.

  14. acourne said,

    January 19, 2018 @ 15:06 pm

    http://personalloansx1.com/
    loan company
    personal loans
    payday loans no teletrack
    personal loans

  15. AwtsStice said,

    January 19, 2018 @ 16:04 pm

    cialis pills http://cialisovnsm.com/[url=http://cialisovnsm.com/]order cialis online[/url] cialis 20 mg directions cialis soft

  16. Estuabs said,

    January 19, 2018 @ 16:20 pm

    http://personalloansx1.com/
    loans without credit
    personal loans
    studen loans
    personal loans

  17. amaddy said,

    January 19, 2018 @ 17:38 pm

    http://personalloansx1.com/
    what is a pay day loan
    personal loans
    payday loans austin tx
    personal loans

  18. incalt said,

    January 19, 2018 @ 17:55 pm

    cheap cialis online
    buy cialis online cheap
    http://buychcialismrxonline.com
    buy cialis generic pharmac
    online cialis

  19. brargy said,

    January 19, 2018 @ 18:52 pm

    generic cialis
    buying cialis without a prescription cialis
    http://buychcialismrxonline.com
    buy cialis pill
    online cialis

  20. Noyes OLS1 said,

    January 19, 2018 @ 19:40 pm

    Pretty! This has been an incredibly wonderful post.

    Thanks for supplying this info.

  21. nhung cau stt hay said,

    January 19, 2018 @ 19:46 pm

    Having read this I thought it was extremely enlightening.
    I appreciate you spending some time and energy to put this short article together.
    I once again find myself spending a lot of time both reading and posting comments.
    But so what, it was still worthwhile!

  22. Noyes OLS1 OLS1 Fiber Optic Test said,

    January 19, 2018 @ 20:37 pm

    It’s impressive that you are getting ideas from this paragraph as well as from our dialogue made at
    this time.

  23. tanie drukowanie jaka drukarka said,

    January 19, 2018 @ 21:13 pm

    Purchasing an Epson printer is usually were the greatest financial savings
    are to be made when buying affordable inkjet cartridges, the rate difference from compatibles to the originals can be shocking, any person who asks what’s
    the best printer to buy so i could acquire inexpensive inks, Epson printers, as the Epson compatibles are generally the least expensive ink cartridges to get, if you
    want to only buy initial inks after that
    Kodak say they offer the most effective value original
    inks on the marketplace to day. Low quality ink can trigger damages
    to a machine by blocking it up with deposit that will certainly
    protect against the printer from working. We are concentrated on the consumer experience, and also because of this, exceed and also beyond to satisfy our
    clients. We just provide cartridges (inks as well as printer toners) that we have actually completely evaluated, for both print high
    quality as well as long life. It is true that we provide low-cost inks as well as economical
    printer toner cartridges, however discount rate inks does not suggest that
    you are compromising on top quality. We depend on word of mouth marketing as we operate really
    low margins, as well as it is our quality and service that
    establishes us in addition to your other ink vendors and also why
    we are able to provide our 100% Guarantee for 1 Year on all our value cartridges as well as
    a life time guarantee on our Premium cartridges.

  24. greeLm said,

    January 19, 2018 @ 21:15 pm

    http://personalloansx1.com/
    no interest personal loans
    personal loans
    fixed loan
    personal loans

  25. JDSU OLP-6 Fiber Optic Test said,

    January 19, 2018 @ 21:34 pm

    This design is incredible! You most certainly know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to start my
    own blog (well, almost…HaHa!) Excellent job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  26. agen judi bola said,

    January 19, 2018 @ 21:43 pm

    Hey! Ι just ѡanted too ask if you ever have any issues with hackers?

    My lasst blоg (wordpress) waѕs hacked and I
    ended up losing many months of hard work due to no data
    backup. Do you have any methods to proοtect against
    hаckers? http://dlchuming.com/comment/html/?63548.html

  27. sgp singapura pengeluaran said,

    January 19, 2018 @ 22:12 pm

    Everyone loves it when people come together and share thoughts.
    Great website, keep it up!

  28. greeLm said,

    January 19, 2018 @ 23:54 pm

    http://personalloansx1.com/
    payday loans lubbock
    personal loans
    personal loans ga
    personal loans

  29. http://www.aniboo.com said,

    January 20, 2018 @ 00:25 am

    Good post. I learn something new and challenging on websites I stumbleupon everyday.

    It will always be useful to read through articles from other authors
    and practice a little something from their web sites.

  30. ttlink.com said,

    January 20, 2018 @ 01:58 am

    Great post.

  31. Detroit Metro Towing near M-14 said,

    January 20, 2018 @ 02:21 am

    I all the time used to study paragraph in news papers but now as I am
    a user of internet therefore from now I am using net for articles, thanks to web.

  32. Cenafipaf said,

    January 20, 2018 @ 03:13 am

    can you take viagra with high blood pressure medicine
    http://viagrabs.com/ – generic viagra online
    can you take coreg and viagra
    [url=http://viagrabs.com]buy viagra[/url]
    is it bad if a teenager takes viagra
    buy viagra
    viagra eu apotheke

  33. tieprix said,

    January 20, 2018 @ 03:29 am

    http://personalloansx1.com/
    fast loans with bad credit
    [url=http://personalloansx1.com/]personal loans[/url]
    how to cash money order
    personal loans

  34. priertd said,

    January 20, 2018 @ 03:34 am

    buy viagra
    buying viagra
    http://genviagrammrx.com
    comprar viagra
    generic viagra online

  35. acourne said,

    January 20, 2018 @ 03:43 am

    http://personalloansx1.com/
    direct lenders for payday loans no teletrack
    [url=http://personalloansx1.com/]personal loans[/url]
    payday loans no guarantor
    personal loans

  36. Jamesstepe said,

    January 20, 2018 @ 04:31 am

    autocad application download
    autodesk inventor
    autocad online 3d
    [url=http://autodeskoutyk.com/#]autodesk inventor[/url]
    autocad 1998 download
    download autodesk autocad
    autocad 2014 download iso
    [url=http://autocadmnfheru.com/#]auto cad[/url]
    autocad vehicles

  37. Payday Loans said,

    January 20, 2018 @ 07:22 am

    online payday loans instant approval loans instant approval online loans bad credit instant approval [url=http://loansinstantapproval.us.com]guaranteed payday loans[/url]

  38. Bột thông cống nào tốt nhất said,

    January 20, 2018 @ 07:35 am

    What’s up to all, how is the whole thing, I think every one is getting more from this site, and your views are nice for new people.

  39. innerpostchaos.tumblr.com said,

    January 20, 2018 @ 07:36 am

    These are genuinely fantastic ideas in on the topic of blogging.
    You have touched some pleasant points here. Any way keep up wrinting.

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