Hi all,
  I was trying out debugging ocropus using gdb and python. I thought I will
share it with the group so that it will be helpful for others since
debugging method for ocropus is not shared till now.  I am using trying out
these things in ubuntu.
I am using ocroswig, which is python binding for ocropus.

For debugging, first the binaries have to be built in debug mode with '-g'
option using gcc. Currently the binaries built by using scons has all the
debug symbols embedded into it.

Dependencies: ocroswig,ocropus,python2.6, python2.6-dbg, gdb.
Advantage of using ocroswig is that each individual component of ocropus and
iulib can be debugged. I will explain step by step taking an example.

Have a python script ready using ocroswig. Below is an example python script
which I used.
+++++++++
#filename:debugscript.py
#example script to test binarizer.
from iulib import * ;
from ocropus import * ;
bin=make_IBinarize("BinarizeByRange");#create a component
errorstr="Icomponent fails:"
image = bytearray()
read_image_gray(image,"TestImages/lena.jpg")
bin_image = bytearray()
#pdb.set_trace()
bin.name();
bin.binarize(bin_image,image)
check_binary(bin_image);
#ocropus::BinarizeByRange::binarize(colib::narray<unsigned char>&,
colib::narray<unsigned char>&)
++++++++++++++++

1) *Start:* gdb to debug python using command "gdb python" at console.
2) *Setting breakpoints*:To set break point one needs to know the function
name.
If ones knows the functions names by then it is fine, if not follow the
method below.
a) Load the modules to gdb by initially typing "r debugscript.py" in gdb
console. This loads all the modules of ocropus and iulib into gdb.
b) Now search for the function name using TAB expansion. In my case I was
trying to debug binarize, so I gave "b ocropus<TAB>". This lists all the
functions in 'ocropus' namespace inside gdb. Similar thing can be done for
the 'iulib'.
c) copy the full string of function name and store it in a notepad. In my
case it was "ocropus::BinarizeByRange::binarize(colib::narray<unsigned
char>&, colib::narray<unsigned char>&)"
d) Exit the gdb. Start the gdb with python again with "gdb python" and set
the breakpoint using command "b
ocropus::BinarizeByRange::binarize(colib::narray<unsigned char>&,
colib::narray<unsigned char>&)"
Note: step 'd' was required in this special case, setting breakpoint on the
binarize without exiting the gdb was setting break point on all the narray
instances initializations and I also met with unexplainable errors. But I
worked on few other functions. So I is always better to set the breakpoints
before u start the execution.
3) *Execution*. use 'r debugscript.py'. Now the program stops. Use 'next and
step' to run through the execution.

Cheers,
Lakshmesha

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ocropus" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocropus?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to