On Mon, Apr 28, 2008 at 07:03:16AM +0000, tuyun wrote:
> 
> Hi
> May be this is a basic question, but I havent find answer through google :(
> I'm not familiar with python. I wrote a C library, and some body used the 
> library in his python program, and found a bug of my library, I want to 
> figure out what's wrong in my library.
> So how can I make a breakpoint for a suspect function in my C library when he 
> is "running in " a python program.
> Is there a debugger or what, which like gdb, I just need to issue:b xxxxxxxx?
> Thanks in advance for my "amateurish question" :(
>  
> Thanks
> Twomol

Yes, I have been able to debug into a Python extension module using
gdb on Linux.  Attached are several files that should help.

Here is a bit of explanation about the attached files:

- run_gdb starts the gdb debugger and:

  (1) specifies a directory containing source files (-d flag);

  (2) specifies a file containing gdb commands (the -x flag and for
      example test2.gdb);

  (3) passes in the the program name (python) and the PID of the
      python process (that's what the ps command in back-ticks
      does).

- test1.gdb and test2.gdb -- Sample gdb command files which can be
  used by run_gdb.  Of particular interest are the ability to set
  breakpoints and to specify arguments that would be passed in from
  the command line if you were not running with the debugger. 
  test1.gdb gives examples of doing both of these.

Needless to say, you will need to modify the attached files for
your use.

If I recall correctly, you could separately:

  (1) start up your python test (with something like raw_input() in
      your test to temporarily stop the test) and then

  (2) start up gdb and attach it to that running python process

in two separate steps.  The run_gdb sample script combines those
two steps.

For more information try:

- "man gdb"

- The gdb manual:

  * "Debugging with GDB"
    http://www.delorie.com/gnu/docs/gdb/gdb_toc.html

  * "20.3 Command files"
    http://www.delorie.com/gnu/docs/gdb/gdb_191.html

Hope this helps.  It has been quite a while since I've done this,
but I remember that it worked pretty slick.

- Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
#!/bin/sh -v
gdb -d /path/to/your/source/code -x test2.gdb python `ps -C python -o pid=`
# Set arguments that would be passed in from the command line.
set args --param ital 'no' --param border 2 camping_par.xsl camping_list.xml
#set args --param ital 'no' --param border 2 --output tmp1.html camping_par.xsl 
camping_list.xml

# Set breakpoints.
b main
b xsltProcess



b translate_to_file
b translate_to_string

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to