Author Topic: [Closed] How to find the line of code from a hexadecimal address in a CGI appli  (Read 557 times)


  • Sr. Member
  • ****
  • Posts: 351

I have the following problem:
- when I create a visual application, compile it with the debug information in it, and having the dump of a call stack, then I can restart the application in step by step debugging with F7 in order to paste the hexadecimal address in the debugging window named "Assembler": it finds me the wrong line of source code.
- but when I'm in a CGI application I can't run the debugger (neither F7, F8, nor F9).
a) Is that normal?
b) If so, how do I find the line of source code, knowing only the hexadecimal address (retrieved from a call stack too)?

« Last Edit: May 25, 2020, 11:59:45 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.


  • Hero Member
  • *****
  • Posts: 8273
  • Programming + Glam Metal + Tae Kwon Do = Me
a) Is that normal?
Yes, CGI isn't executed in your IDE, it's the webserver responsibility. And it's a one off process, meaning that the program gets launched, gives its response, then exit. You will have a hard time attaching the debugger to the short processing time.
b) If so, how do I find the line of source code, knowing only the hexadecimal address (retrieved from a call stack too)?
Not really sure, but maybe you can abuse leakview to translate the address into line number.


  • Hero Member
  • *****
  • Posts: 1319
Is the CGI program in a form in which you could wrap gdbserver around it? In other words could you interpose gdbserver between the HTTP server (Apache or whatever) and the CGI program? If that worked then even though gdbserver were running as soon as control was passed to it, your custom program wouldn't be until the IDE told gdbserver to start it.

Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.


  • Hero Member
  • *****
  • Posts: 3074
The more or less normal way of debugging a CGI is to prepare the environment as it's done by the server and then execute the CGI under the debugger.

A relatively good (though a little old) introduction is in chapter:12. Debugging and Testing CGI Applications, of CGI Programming on the World Wide Web

Note that if you're using Lazarus, the easiest way to do it is probably to add the test environment vars in "Run->Run parameters...", as shown in the attached image and then run the program in the IDE as is usual for debugging.

« Last Edit: May 24, 2020, 05:00:22 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.


  • Full Member
  • ***
  • Posts: 100
    • Fano Framework, Free Pascal web application framework
lucamar's answer is correct.

When web server executes CGI program, it sets CGI environment variables as defined in RFC 3875

So to simulate CGI program to serve request
Code: Text  [Select][+][-]
  1. GET /hello/world

you need to set environment


Before running CGI program. Also during development you may want to add -g and -gl when compile program so that more debug information is available.
« Last Edit: May 24, 2020, 08:07:58 pm by zamronypj »
Fano Framework, Free Pascal web application framework
Personal Projects


  • Sr. Member
  • ****
  • Posts: 351
Thank you for the answer @Leledumbo .

I was wondering if CGI applications have a separate memory management, because on my "backup netBook" where I'm currently coding (confinement obliges), I never saw the "View / Leaks and Traces" menu.
So, my "answering" was rather due to a specious bug in the installation of this old version of Lazarus (which never displays it, even with a visual application \ LCL.
For info. about this specious bug: old installation "innosetup way" downloaded from of Lazarus version: 2.0.2 + Lazarus svn revision: 60954 + compiled for i386-win32 with fpc 3.0.4).

I just tested with a recent Lazarus installed with FCPupDeluxe: "View / Leaks and Traces" is still present (with CGI and LCL program).

@zamronypj and @lucamar: that's what I found out, trying to call the CGI program from already written Php. The URI of a CGI program must match an " environment variable " (so, I had been looking for ways to see the CGI environment variables. This is explained in, which allows me to get their summary as in the attached file named CGI_environment_variables.pdf), in order to call the correct URL:

Code: PHP  [Select][+][-]
  1. putenv('REQUEST_METHOD=GET');
  2. // to get your parameters passed into the cgi...
  3. $_SERVER['PATH_INFO'] = '/Provider/form_edit';
  4. putenv('PATH_INFO=' . $_SERVER['PATH_INFO']);
  5. $sOutput = exec('D:\Orion7\UniServerZ\cgi-bin\extgrid.exe'); /* btw, it's even simpler with file_get_content(''): it allows you to call the full URL, as it appears. */
  6. echo $sOutput;

@MarkMLl: thanks for the track (but I hope I won't come up with such a complicated solution to debug)
« Last Edit: June 10, 2020, 11:57:55 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.


TinyPortal © 2005-2018