Howto Debug CgiCC App
I develop a Win32 C++ cgi app for wind开发者_运维百科ows and linux and start from scratch. I use CgiCC as lib and Visual Studio 2010 as IDE.
How can I debug that? When I instanziate my cgicc class the program holds and waits for CGI input I guess.
How can I set up an environment for my CGI input?
I set some environment variables like QUERY_STRING. But I have no idea how to provide the values my cgi app would get while running on a webserver.EDIT:
I am almost there.- I captured the traffic while browsing and wrote that content to a file.
- Then I redirected stdin to that file: "< input.txt" as debug command line arguments in visual studio.
- I set some environment variables under windows like CONTENT_LENGTH and CONTENT_TYPE.
after that I can read some content from my input like this:
cgicc::Cgicc cgi;
string u = cgi("user");
but i get an exception (reading from unallocated memory and exceptions like that) while doing this:
vector<FormFile, allocator<FormFile>> files = cgi.getFiles();
somehow not everthing if loaded correctly.
CGI apps receive their input via environment variables and standard input, so you can easily replicate the environment that a web server sets up for the CGI task.
As far as environment variables, here is a list of the environment variables that are part of the CGI protocol. I recommend that you set all of them, either by hand or better yet, by capturing the environment given to a working cgi app by a production web server. Since environment variables are inherited by child processes, if you set these up in your environment inside a Windows command prompt and then invoke the Visual Studio IDE from that same window then these variables will be available when your CGI application starts inside the debugger and also when you run it without debugging.
Getting a standard input replacement can be a bit more complex in your case, since you are working with a file upload form. This site contains a template that should get you started with the multipart/form-data format. The official document for file uploads via forms is RFC 1867.
I hope this helps.
Solved it by myself:
- Build cgicc with the same visual studio version that I compile my project with.
- Build cgicc as a static library instead of a dynamic library.
- Setting the preprocessor define CGICC_EXPORTS in my project which activated __declspec(dllexport).
Then it worked!
精彩评论