MapServer 5.0 and enable-DEBUG

rich.fromm nospam420 at YAHOO.COM
Tue Dec 4 16:43:37 EST 2007


rich.fromm wrote:
> 
> 2) I have had several instances in which a small little mistake in my map
> file
>    (like a typo in the name of another file being referenced) was much
> harder to
>    track down than I would have hoped, because I get no meaningful error
> message
>    from mapserver, even with DEBUG set to 5.  All I get is the same,
> single
>    generic error message in /var/log/apache2/error.log:
> 
> [Mon Dec 03 11:38:14 2007] [error] [client 127.0.0.1] Premature end of
> script headers: mapserv
> 
>    And the webserver returns a 500 error.  Is there any easy way to debug
>    what's the problem when something like this occurs?  I suppose one way
>    might be to run mapserver via gdb, if indeed it is crashing, but the
>    standalone mapserv binary doesn't look like it's capable of that:
> 
> $ ./mapserv
> This script can only be used to decode form results and 
> should be initiated as a CGI process via a httpd server.
> 
>    and I don't see a C/C++ implementation of mapscript, so I'm not even
> sure
>    exactly how I would go about doing that.  (How do mapserver developers
>    debug it?  I'm not really sure if I were to run apache2 via gdb if that
>    would do the right thing for a CGI application written in C.)
> 

i figured out how to do this on my own, so i'm replying here in case it
helps
anyone in the future.

the mapserver code to parse the cgi input is located in cgiutil.c.  pay
particular attention to loadParams()

there are a number of ways to do this, but the simplest is to just set the
REQUEST_METHOD (to GET) and QUERY_STRING environment variables and then run
the mapserv binary.

for a URL of a form like:

http://yourhost/cgi-bin/mapserv?foo1=bar1&foo2=bar2

you want to be setting QUERY_STRING as follows:

QUERY_STRING="foo1=bar1&foo2=bar2"

so, a more complete example of a successful run would be:

---
[rich at peyote mapserver-5.0.0-5 12:08:05]$ REQUEST_METHOD=GET
QUERY_STRING="map=/ext/home/rich/wrk/mapserver/freenavi/zoom0-5.rich.map&mode=map"
./mapserv
Content-type: image/png; mode=24bit

‰PNG
<... lots of binary data follows ..,>
---

now this isn't all that useful for a successful run, because the HTTP header
and body are both going to the console, and you'd need to expend a little
bit
of effort to process that.  but what i'm interested in here is duplicating
unsuccessful cases, like the following:

---
[rich at peyote mapserver-5.0.0-5 12:07:44]$ REQUEST_METHOD=GET
QUERY_STRING="map=/ext/home/rich/wrk/mapserver/freenavi/zoom0-5.rich.map&mode=map"
./mapserv
Content-type: image/png; mode=24bit

Segmentation fault
---

note that the reason the same line here is an error is because the .map file
has been
edited.  for more details, see the following thread:
http://www.nabble.com/wrong-filename-in-FORMATOPTION-leads-to-mapserv-segfault-tf4945787.html

anyway, with apache/cgi, this just shows up as a 500 error.  but now that i
can run it standalone, i can debug it via gdb and find the source of the
error.

note that you may have to pass other environment variables if you find the
need to be passing them to apache.

for example, in my apache config (/etc/apache2/sites-available/default) i
have:

    <FilesMatch ^mapserv>
        SetEnv LD_LIBRARY_PATH /usr/local/lib
    </FilesMatch>

to pass LD_LIBRARY_PATH to apache.  which means that i also must have that
properly set when directly invoking mapserv.

if you're going to run gdb from within emacs (and i can't personally
productively use gdb any other way), you need to either:
1) properly set your environment when invoking gdb
2) properly set your environment from within emacs
3) properly set your environment before invoking emacs

i'm sure (1) and (2) ought to be possible, but i wasn't able to get them to
work with a little bit of effort, so i just chose (3) and started a new
emacs
just for this debugging session.  (feel free to reply here if you are able
to
get (1) or (2) to work.)

-- 
View this message in context: http://www.nabble.com/MapServer-5.0-and-enable-DEBUG-tf4710307.html#a14160178
Sent from the Mapserver - User mailing list archive at Nabble.com.



More information about the mapserver-users mailing list