I'm trying to run an HTTP::Simple::Server based server (it's actually my still under development CGI::Application::Server::Dispatch) and I'd like to run it inside the perl debugger.

It seems that when I run it w/ perl -d it ends up listening to the console instead of opening a network socket and listening there.

Does anyone out there know a sufficient incantation that will let me play with my code inside the debugger?

I've tried explicitly setting $server->port() and $server->host() to no avail.

I also just figured out how to use the debugger's RemotePort option get the debugging io to occur in another xterm (using nc -l) and the server's IO *still* is connected to the debugging window.

Thanks,

g.

---------------------------------------------------

So, here's an answer. There's something funny about how HTTP::Server::Simple hooks stdin and stdout up to the socket it creates. I'm still trying to figure out if the problem only happens on my FreeBSD-STABLE system, or if it's a more generall bug. In the mean time, the following patch makes things work for me:


--- /usr/local/lib/perl5/site_perl/5.8.8/HTTP/Server/Simple.pm  Sat Nov 25 16:15:39 2006
+++ lib/HTTP/Server/Simple.pm   Sat Feb 24 14:33:12 2007
@@ -262,8 +262,18 @@
                 $self->accept_hook if $self->can("accept_hook");
 
 
-                *STDIN  = $self->stdin_handle();
-                *STDOUT = $self->stdout_handle();
+                # hooking stdio to the socket using dup2 lets everything work
+                # in the perl debugger.  
+                # cons'ed together w/ hints on dup2 usage from the qpsmtpd.
+                # hartzell@alerce.com --- Sat Feb 24 14:23:12 PST 2007
+                # *STDIN  = $self->stdin_handle();
+                # *STDOUT = $self->stdout_handle();
+                use POSIX;
+                POSIX::dup2(fileno($self->stdin_handle()), 0)
+                  || die "unable to duplicate filehandle to STDIN - $!";
+                POSIX::dup2(fileno($self->stdout_handle()), 1)
+                  || die "unable to duplicate filehandle to STDOUT - $!";
+
                 select STDOUT;   # required for HTTP::Server::Simple::Recorder
                                  # XXX TODO glasser: why?
                 $pkg->process_request;


In reply to Help running HTTP::Server::Simple server under the debugger? by hartzell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.