Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Debugging XS with duma/efence?

by suaveant (Parson)
on Nov 14, 2007 at 16:34 UTC ( [id://650791]=perlquestion: print w/replies, xml ) Need Help??

suaveant has asked for the wisdom of the Perl Monks concerning the following question:

Anyone know how one would go about debugging XS code with Electric Fence or Duma (or some other free solution?)

It appears that I am trying to re-use a freed memory location in my C, but I am not having much luck actually running duma or efence to catch it.

                - Ant
                - Some of my best work - (1 2 3)

Replies are listed 'Best First'.
Re: Debugging XS with duma/efence?
by renodino (Curate) on Nov 14, 2007 at 17:15 UTC
    Are you using Perl's mem. mgmt. functions ? (Newz, Safefree, etc.) Or is this something external to the Perl environment (e.g., a shared library). If the latter, you might want to build an external stub and test/debug outside XS.

    As to using any debug heap mgrs, you probably already know that XS/Perl obsconds with the std. malloc/free symbols, so you need to create your own version in an externally compiled object. I've been using the following (you'll need to reference your own set of heap mgr libs/methods):


    Perl Contrarian & SQL fanboy
      I basically wrote my own char by char ringbuffer parser for a product we connect to. I use a couple of linked lists.

      I am segfaulting on malloc, but when I clear out on of my free commands for the linked list everything runs smooth. I assume I am using freed memory somewhere and am trying to find out where. Duma does that but hooking it in seems problematic, at best.

      I can't easily compile the code outside of my module since it reads and writes Perl structures. All in all a nightmare :)

                      - Ant
                      - Some of my best work - (1 2 3)

      Oh.. and I knew nothing of newz and safefree... I am looking into those now.

      Are you supposed to use them vs normal calloc free etc when writing C under Perl? (This is my first serious foray into XS)

                      - Ant
                      - Some of my best work - (1 2 3)

        Are you supposed to use them vs normal calloc free etc when writing C under Perl?

        Probably. See Memory Mgmt API in the perldocs.


        Perl Contrarian & SQL fanboy
Re: Debugging XS with duma/efence?
by dave_the_m (Monsignor) on Nov 14, 2007 at 23:08 UTC
    If you're using Linux, just use valgrind. It will detect invalid uses of memory (eg accessing data that's been freed), and not only that, it will give you a stack dump at the point the freed block was illegally accessed, and at the point where that block was originally freed (with the option to attach gdb).

    It can do lots of other stuff too.

    And the best thing about it is you don't have to do any different compiling or linking: valgrind will run against standard binaries, eg

    $ valgrind perl myprog.pl

    Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://650791]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found