debugging a shared library wrapped by SWIG in perl
Asked Answered
E

2

8

I have wrapped my C/C++ code using SWIG in Perl. I have few segmentation fault because of the wrapped code. I am trying to use ddd with the Perl script but unfortunately even if I set a breakpoint on a line of the script ( the one calling C/C++ code ), ddd is not able to step in down to the C/C++ code.

Is there any way to set breakpoint into my C lib when I am debugging Perl code or do you know a good way/tool to debug the C lib when I am running this Perl script?

I am using Linux/gcc.

Exudation answered 13/7, 2011 at 15:19 Comment(0)
E
7

I did a simple thing. I called the gdb directly on perl interpreter.

    gdb /usr/bin/perl
    (gdb) r myscript
    #block the script someway or rerun it
    (gdb) b whatever_my_function

It seems that once the scipt is running shared memory is also loaded in memory. Once this happened I have available all information, functions and breakpoint for debugging.

Exudation answered 13/7, 2011 at 15:52 Comment(2)
How can I debug it if I am using Komodo?Tachycardia
Hi rpg. I have no idea. I had a look and Komodo seems a IDE debugging exclusively PERL script. I dond't know if it is able to debug C/C++ instructions when Perl calls shared libraries. With GDB the starting point is the binary for the PERL interpreter. The breakpoint is set in a line of C/C++ code not in a line of the Perl script.Exudation
U
0

I've only used SWIG for calling C++ from TCL, and debugged it using Visual Studio, but the same ideas should apply for your case as well. I'll describe what I've done to debug, hopefully you can figure out how to apply it to your situation.

  • Build a debug version of the C++ module
  • Make sure the TCL script is including the debug version (the path in the TCL load command points to the debug version of the module)
  • Place breakpoints in the C++ code
  • Invoke the TCL script through the Visual Studio debugger; for instance the command used is tclsh85.exe MyScript.tcl

HTH

Univalence answered 13/7, 2011 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.