[转载]gdb中的信号-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务...

来源:百度文库 编辑:神马文学网 时间:2024/04/28 04:30:12

    • 域名注册

    • 域名惊喜价格 cn域名1元注册
    • com域名39.9元

      虚拟主机

    • 主机按月支付,低至19元/月
    • 超大流量,可开子站点

      VPS主机

    • 特惠VPS168元/月,4-8M独享带宽保证
    • 独立操作系统,无限开站点

         
           
           
    一篇不错的帖子,讲的是gdb中的信号(signal)相关调试技巧
    转自Magic C++论坛
    http://www.magicunix.com/index_ch.html
    http://www.magicunix.com/cgi-bin1/forum_cn/ultimatebb.cgi?ubb=get_topic&f=1&t=000060#000003
    引用:
    --------------------------------------------------------------------------------
    原发贴者 Couger:
    我写了一个INT信号的处理函数,在处理函数里设置断点后go,不过在console下按Ctrl-C后MC并没有进入处理函数,而console下的程式也直接退出,没有给出希望的输出。
    --------------------------------------------------------------------------------
    在console下按Ctrl-C后确实发送了SIGINT信号,不过gdb里的缺省设置将会导致由GDB截获的该信息,调试的应用程式无法接受到该信号。
    有两种方法能使调试的应用程式接受到信号:
    (1)改动gdb信号处理的设置
    比如,以下设置会告诉gdb在接收到SIGINT时不要停止、打印出来、传递给调试目标程式
    =====================================
    (gdb) handle SIGINT nostop print pass
    SIGINT is used by the debugger.
    Are you sure you want to change it? (y or n) y
    Signal Stop Print Pass to program Description
    SIGINT No Yes Yes Interrupt
    (gdb)
    =====================================
    (2)使用gdb命令直接向调试的应用程式发送信号
    首先在你希望发送信号的语句处设置断点,然后运行程式,当停止到断点所在位置后,用gdb的signal命令发送信号给调试目标程式
    ====================================
    (gdb) signal SIGINT
    Continuing with signal SIGINT.
    Breakpoint 1, handler (signal=2) at main.cpp:15
    15 printf("Signal handler...\n"

    ;
    ====================================
    ;-( 不过这两种方法目前MC都还不支持,所以需要等新版本的MC才能方便的支持你这种调试情况,呵呵。临时先手工调试一下吧。
    新版本将会增加
    (1)调试器的信号处理设置
    (2)支持发送信号命令
    调试用例:
    ============
    /*
    * This program is uninterruptable with
    * Ctrl+C, uses signal handler
    */
    #include ;
    #include ;
    #include ;
    /* The signal handler function */
    void handler( int signal ) {
    printf("Signal handler...\n"

    ;
    psignal( signal, "Signal: "

    ;
    } /*handler*/
    main() {
    /* Registering the handler, catching
    SIGINT signals */
    signal( SIGINT, handler );
    /* Do nothing */
    while( 1 ) {
    printf("Running...\n"

    ;
    sleep(10);
    } /*while*/
    } /*main*/
    ============
    改动gdb的信号处理设置
    ============
    5.3 Signals
    A signal is an asynchronous event that can happen in a program. The
    operating system defines the possible kinds of signals, and gives each
    kind a name and a number. For example, in Unix SIGINT is the signal a
    program gets when you type an interrupt character (often C-c); SIGSEGV
    is the signal a program gets from referencing a place in memory far
    away from all the areas in use; SIGALRM occurs when the alarm clock
    timer goes off (which happens only if your program has requested an
    alarm).
    Some signals, including SIGALRM, are a normal part of the functioning
    of your program. Others, such as SIGSEGV, indicate errors; these
    signals are fatal (they kill your program immediately) if the program
    has not specified in advance some other way to handle the signal.
    SIGINT does not indicate an error in your program, but it is normally
    fatal so it can carry out the purpose of the interrupt: to kill the
    program.
    GDB has the ability to detect any occurrence of a signal in your
    program. You can tell GDB in advance what to do for each kind of
    signal.
    Normally, GDB is set up to let the non-erroneous signals like SIGALRM
    be silently passed to your program (so as not to interfere with their
    role in the program’s functioning) but to stop your program immediately
    whenever an error signal happens. You can change these settings with
    the handle command.
    info signals
    info handle
    Print a table of all the kinds of signals and how GDB has been told to
    handle each one. You can use this to see the signal numbers of all the
    defined types of signals.
    info handle is an alias for info signals.
    handle signal keywords...
    Change the way GDB handles signal signal. signal can be the number of a
    signal or its name (with or without the `SIG’ at the beginning); a list
    of signal numbers of the form `low-high’; or the word `all’, meaning
    all the known signals. The keywords say what change to make.
    The keywords allowed by the handle command can be abbreviated. Their full names are:
    nostop
    GDB should not stop your program when this signal happens. It may still
    print a message telling you that the signal has come in.
    stop
    GDB should stop your program when this signal happens. This implies the print keyword as well.
    print
    GDB should print a message when this signal happens.
    noprint
    GDB should not mention the occurrence of the signal at all. This implies the nostop keyword as well.
    pass
    noignore
    GDB should allow your program to see this signal; your program can
    handle the signal, or else it may terminate if the signal is fatal and
    not handled. pass and noignore are synonyms.
    nopass
    ignore
    GDB should not allow your program to see this signal. nopass and ignore are synonyms.
    When a signal stops your program, the signal is not visible to the
    program until you continue. Your program sees the signal then, if pass
    is in effect for the signal in question at that time. In other words,
    after GDB reports a signal, you can use the handle command with pass or
    nopass to control whether your program sees that signal when you
    continue.
    The default is set to nostop, noprint, pass for non-erroneous signals
    such as SIGALRM, SIGWINCH and SIGCHLD, and to stop, print, pass for the
    erroneous signals.
    You can also use the signal command to prevent your program from seeing
    a signal, or cause it to see a signal it normally would not see, or to
    give it any signal at any time. For example, if your program stopped
    due to some sort of memory reference error, you might store correct
    values into the erroneous variables and continue, hoping to see more
    execution; but your program would probably terminate immediately as a
    result of the fatal signal once it saw the signal. To prevent this, you
    can continue with `signal 0’. See section Giving your program a signal.
    ============
    直接使用gdb signal命令发送信号给调试目标程式
    ================
    三、产生信号
    使用singal命令,能产生一个信号给被调试的程式。如:中断信号Ctrl+C。这非常方便于程式的调试,能在程式运行的任意位置设置断点,并在该断点用GDB产生一个信号,这种精确地在某处产生信号非常有利程式的调试。
    语法是:signal ;,UNIX的系统信号通常从1到15。所以;取值也在这个范围。
    single命令和shell的kill命令不同,系统的kill命令发信号给被调试程式时,是由GDB截获的,而single命令所发出一信号则是直接发给被调试程式的。

  • [转载]gdb中的信号-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务... 用C语言编写CGI程式-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务... linux下裸设备的使用-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 “笑”傲流媒体―SMIL基础教程-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟... Shell编程入门:Linux解释器原理-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,... 2.6下的内核模块编译-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,... 视频压缩编码的新发展-H.264(转贴)-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 [图]Linux更新工具Yumex&yum揭秘-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 硬盘安装+游戏功能 虚拟机XP-80分钟打造娱乐型ubuntu7.10[转]-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 Resin服务器的使用(一篇不错的文章,如果想使用resin做服务器建议看看)-JSP编程-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 linux vi使用手册-Linux -华夏名网 讯游数码代理资讯中心 虚拟主机,域名注册... 2G网络向3G平滑演进的若干关键技术探讨-硬件技术-华夏名网资讯中心 虚拟主机,域名注册,... 视窗系统 XP 转移和文件设置-windows操作系统-华夏名网资讯中心 虚拟主机,域名注... 域名注册虚拟主机注册服务提供商-新网互联 软件技巧 / Powerpoint - 西部数码站长资讯中心|虚拟主机|域名注册|主机租用 软件技巧 / Powerpoint - 西部数码站长资讯中心|虚拟主机|域名注册|主机租用 公司主要从事于域名注册、虚拟主机 虚拟主机 网页设计中标志设计技巧 网络营销趋势 -深圳网站建设-深圳虚拟主机-深圳网页设计-域名注册... 页面设计中的导航栏设计要点 网络营销趋势 -深圳网站建设-深圳虚拟主机-深圳网页设计-域名... 虚拟主机简介及虚拟主机应用技术 外国虚拟主机空间评测网 | 不断追踪最好最便宜的虚拟主机空间 基于IP,基于port和基于域名的三种虚拟主机的配置方法(原创) Vmware--虚拟主机的利器