How to debug a Fast Common Gateway Interface (FCGI) program?

故事扮演 提交于 2019-12-11 13:32:04

问题


I encountered a problem that I don't known how to debug a FCGI program which written in C++ and based on fastcgi.

The program is managed by Lighttpd spawn-fcgi and called by nginx fastcgi module.

I wrote a shell script to restart spawn-cgi:

#! /bin/bash

cgi_default="index.cgi"
process_pid="pid"

param_ip="127.0.0.1"
param_port="9000"

if [ -f "$process_pid" ]; then
    pid=`cat $process_pid`
    kill -9 $pid &> /dev/null
    rm $process_pid
fi

spawn_out=`/usr/local/bin/spawn-fcgi -a $param_ip -p $param_port $cgi_default`
# spawn-fcgi: child spawned successfully: PID: 6423
pid=`echo $spawn_out | cut -d " " -f6`
expr $pid + 0 &> /dev/null
[ $? -eq "0" ] && echo "$pid" > $process_pid

The program index.cgi was successfully built and just printf some strings to out stream.

And my configuration in nginx:

location / {
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
}

Now I am wroking on index.cgi, change some code (maybe with faulty logic). The program crashed and 502 Bad Gateway was returned in my browser.

It's hard for me to find out what is wrong in my program because the fcgi progam acts as a callback function of nginx. So I cannot press Debug button and bebug my program normally.

So how can I debug my program properly and conveniently?


回答1:


Yeah, gdb attach the running process debugging will help a lot.



来源:https://stackoverflow.com/questions/30950094/how-to-debug-a-fast-common-gateway-interface-fcgi-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!