GithubHelp home page GithubHelp logo

tyeth / pygdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ucphhpc/pygdb

0.0 1.0 0.0 36 KB

Python extension for the GNU project debugger (GDB)

License: GNU General Public License v2.0

Python 96.57% C 1.54% GDB 1.89%

pygdb's Introduction

pygdb

Python extension for the GNU project debugger (GDB)

Introduction

This package provides a set of tools for debugging python code with GDB, including python code breakpoints. GDB breakpoints operate on native shared libraries (C/assembler code). Since python is an interpreted language it's not possible to set python code breakpoints directly from the GDB console. In this package python code breakpoints are supported by utilizing a python-c-extension breakpoint-mark function which is accessible from the GDB console. This method requires that python code breakpoints are set explictly in the python code.

Dependencies

GDB python: https://wiki.python.org/moin/DebuggingWithGdb

Install

From source: pip install .

Latest release: pip install pygdb

Copy .gdbinit to ~/.gdbinit

Literature

https://devguide.python.org/gdb/

https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html

Usage

Python code breakpoints

Breakpoints are set explicitly in the python code:

import pygdb.breakpoint
pygdb.breakpoint.enable()

def Test():
  print "Before breakpoint"
  pygdb.breakpoint.set()
  print "After breakpoint"

NOTE: pygdb.breakpoint.set() busy-waits until the python process is attached to the GDB console using the py-attach command (see below)

Pygdb breakpoint messages are written to stderr unless a Python logger is provided:

import logging
import pygdb.breakpoint

logging.basicConfig(level=logging.INFO)
pygdb.breakpoint.enable(logger=logging.getLogger())

GDB console

Launch GDB in python-mode from the shell

$> gdb python

Add source-path if not current shell directory

gdb> dir PATH

Init the pygdb framework

gdb> py-init

Attach GDB console to the python process with PID, notify pygdb.breakpoint that the console is connected and continue until the native GDB breakpoint

gdb> py-attach PID

command list

NOTE: The GDB console supports tab-completion.

All GDB console commands added by this packages are prefixed with py-

For each command use --help for detailed help.

py-init:            Initializes pygdb commands and extensions
py-info-procs:      Display list of attached processes
py-info-threads:    Display list of attached process threads
py-attach:          Attach python process to gdb console
py-detach:          Detach python process from gdb console
py-thread:          Change python thread in attached process
py-breakpoint:      Find and display code for python breakpoint
py-step:            Continue until control reaches a different python source line
py-next:            Continue until control reaches a different python source line in current frame
py-continue:        Continue until next python breakpoint and display code
py-list:            Display code for current python frame
py-backtrace:       Display current python frame and all the frames within its call stack (if any)
py-inspect-frame:   Display information about the current python frame
py-builtins:        Display builtin varialbes for current python frame
py-globals:         Display global variables for current python frame
py-locals:          Display local variables for current python frame
py-print:           Display python frame variable (if it exists)
py-set-local:       Set local variable in current python frame
py-up:              Select and display code for the python stack frame that called this one (if any)
py-down:            Select and display code for the python stack frame called by this one (if any)
py-inject:          Inject python code into current python frame

pygdb's People

Contributors

martin-rehr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.