This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][5/5] Sample python scripts


These 2 new files are sample python script for demonstrating the new
functions of gdb python scripting. check_segfault adds a handler for
sigsegv signal stops and executes a backtrace when a sigsegv event
occurs. test_events is just for printing the info inside events,
attaches itself to every current event.

check_segfault.py:

# Copyright (C) 2009 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gdb

def sigsegv_handler (event):
    if (event.stop_signal == "SIGSEGV"):
        print "event type : %s" % (event.event_type)
        print "stop reason: %s" % (event.stop_reason)
        print "stop signal: %s" % (event.stop_signal)
        gdb.execute ("backtrace")

class Check_Segfault (gdb.Command):
    """Check segfault."""

    def __init__ (self):
        gdb.Command.__init__ (self, "check_segfault", gdb.COMMAND_STACK)

    def invoke (self, arg, from_tty):
        gdb.selected_thread().signal_stop_eventregistry.connect
(sigsegv_handler)
        print "SIGSEGV handler registered."

Check_Segfault ()


test_events.py:
# Copyright (C) 2009 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gdb

def signal_stop_handler (event):
    print "event type : %s" % (event.event_type)
    print "stop reason: %s" % (event.stop_reason)
    print "stop signal: %s" % (event.stop_signal)

def breakpoint_stop_handler (event):
    print "event type       : %s" % (event.event_type)
    print "stop reason      : %s" % (event.stop_reason)
    print "breakpoint number: %s" % (event.breakpoint.number)

def exit_handler (event):
    print "event type: %s" % (event.event_type)
    print "exit code : %d" % (event.exit_code)

def continue_handler (event):
    print "event_type: %s" % (event.event_type)

class Test_Events (gdb.Command):
    """Test events."""

    def __init__ (self):
        gdb.Command.__init__ (self, "test_events", gdb.COMMAND_STACK)

    def invoke (self, arg, from_tty):
        gdb.selected_thread().signal_stop_eventregistry.connect
(signal_stop_handler)
        gdb.selected_thread().breakpoint_stop_eventregistry.connect
(breakpoint_stop_handler)
        gdb.selected_thread().exited_eventregistry.connect (exit_handler)
        gdb.selected_thread().continue_eventregistry.connect (continue_handler)

        print "Event testers registered."

Test_Events ()


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]