Giter Club home page Giter Club logo

cygdb-demo's Introduction

cygdb-demo

Example of debugging Cython project

Install dependencies

Set-up environment, for example using vagrant

$ vagrant init debian/jessie64
$ vagrant up
$ vagrant ssh

$ sudo apt-get install build-essential python-dbg git gdb \
                       python-setuptools python-pip python-dev

$ sudo /usr/bin/python-dbg /usr/bin/pip install cython

Check version and configuation

$ python-dbg --version
Python 2.7.9


$ python --version
Python 2.7.9


$ python3
-bash: python3: command not found


$ cython --version
Cython version 0.25.2
[89796 refs]


$ gdb --version
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".


$ gdb --configuration
This GDB was configured as follows:
    configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu
              --with-auto-load-dir=$debugdir:$datadir/auto-load
              --with-auto-load-safe-path=$debugdir:$datadir/auto-load
              --with-expat
              --with-gdb-datadir=/usr/share/gdb (relocatable)
              --with-jit-reader-dir=/usr/lib/gdb (relocatable)
              --without-libunwind-ia64
              --with-lzma
              --with-python=/usr (relocatable)
              --with-separate-debug-dir=/usr/lib/debug (relocatable)
              --with-system-gdbinit=/etc/gdb/gdbinit
              --with-zlib
              --without-babeltrace
("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)

build

Get the source code:

git clone https://github.com/dfroger/cygdb-demo
cd cygdb-demo

Build:

python-dbg setup.py build_ext --inplace

demo.c and debug infos

demo.pyx compiles to demo.c and cython_debug/cython_debug_info_demo

For readiblity, cython_debug_info_demo has been formatted bellow with:

sudo apt-get install libxml2-utils
xmllint --format --recover cython_debug_info_demo > out.xml

cdef

cdef double foo(double x):
    return 2*x

compiles to:

static double __pyx_f_4demo_foo(double __pyx_v_x)

debug info:

<Function cname="__pyx_f_4demo_foo" lineno="1" name="foo" pf_cname="" qualified_name="demo.foo">
  <Locals>
    <LocalVar cname="__pyx_v_x" lineno="1" name="x" qualified_name="demo.foo.x" type="CObject"/>
  </Locals>
  <Arguments>
    <x/>
  </Arguments>
  <StepIntoFunctions/>
</Function>

def

def bar(double x):
    return 2*x

compiles to:

static PyObject *__pyx_pw_4demo_1bar(PyObject *__pyx_self, PyObject *__pyx_arg_x)
static PyObject *__pyx_pf_4demo_bar(CYTHON_UNUSED PyObject *__pyx_self, double __pyx_v_x)

debug info:

<Function cname="__pyx_pw_4demo_1bar" lineno="4" name="bar" pf_cname="" qualified_name="demo.bar">
  <Locals>
    <LocalVar cname="__pyx_v_x" lineno="4" name="x" qualified_name="demo.bar.x" type="CObject"/>
  </Locals>
  <Arguments/>
  <StepIntoFunctions/>
</Function>

cpdef

cpdef double baz(double x):
    return 2*x

compiles to:

static PyObject *__pyx_pw_4demo_3baz(PyObject *__pyx_self, PyObject *__pyx_arg_x)
static PyObject *__pyx_pf_4demo_2baz(CYTHON_UNUSED PyObject *__pyx_self, double __pyx_v_x)
static double __pyx_f_4demo_baz(double, int __pyx_skip_dispatch)

debug info:

<Function cname="__pyx_f_4demo_baz" lineno="7" name="baz" pf_cname="__pyx_pw_4demo_3baz" qualified_name="demo.baz">
  <Locals>
    <LocalVar cname="__pyx_v_x" lineno="7" name="x" qualified_name="demo.baz.x" type="CObject"/>
  </Locals>
  <Arguments>
    <x/>
  </Arguments>
  <StepIntoFunctions/>
</Function>

Demo of using cygdb

Run debugger:

$ cygdb . -- --args python-dbg main.py

Set up a breakpoint, and run:

cy break foo

cy run

cy list

cygdb-demo's People

Contributors

dfroger avatar

Stargazers

 avatar  avatar  avatar

Watchers

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