简体   繁体   English

CGI程序在调试模式下运行

[英]CGI program run in debug mode

We have a C++ CGI application which serves some web request. 我们有一个C ++ CGI应用程序,可以处理一些Web请求。 I am trying to run the same in debug mode for analysis purpose. 我试图在调试模式下运行相同的分析目的。 The approach I have taken is invoking it with gdb: 我采用的方法是通过gdb调用它:

As per first step - I rename my actual CGI application and place my own program with the same name 第一步-重命名我的实际CGI应用程序,并使用相同的名称放置自己的程序

In that program I am trying to invoke the actual CCGI application in debug mode using GDB: 在该程序中,我试图使用GDB在调试模式下调用实际的CCGI应用程序:

const char* argv[] = ["gdb -p <pid> -batch -ex bt 2>/dev/null", NULL];

execve("./myprog", (char**)argv, NULL);

The issue is that since myrog is a CGI application it takes input from STDIN. 问题在于,由于myrog是CGI应用程序,因此需要从STDIN输入。

How can I capture the input in my program and pass the same to the actual CGI application? 如何捕获程序中的输入并将其传递给实际的CGI应用程序?

I did this: in cgi main i added code to look for an existing file, like /var/tmp/flag. 我做到了:在cgi main中,我添加了代码来查找现有文件,例如/ var / tmp / flag。 While existing, i run in a loop. 当存在时,我会循环运行。 Time enough to attach to cgi process via gdb. 有足够的时间通过gdb附加到cgi进程。 After then i delete /var/tmp/flag and from now I can debug my cgi code. 之后,我删除/ var / tmp / flag,从现在开始我可以调试我的cgi代码。

bool file_exists(const char *filename)
{
   ifstream ifile(filename);
   return ifile;
}

int cgiMain()
{

 while (file_exists ("/var/tmp/flag"))
     sleep (1);
 ...
 your code 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM