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.

user229044
  • 232,980
  • 40
  • 330
  • 338
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173

2 Answers2

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.

Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
  • How can I debug it if I am using Komodo? – rpg Sep 02 '11 at 10:10
  • 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. – Abruzzo Forte e Gentile Sep 05 '11 at 09:45
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

Praetorian
  • 106,671
  • 19
  • 240
  • 328