无法在 fpc 调试输出中生成行号

Unable to generate line numbers in fpc debugging output

我有一个非常简单的测试程序 (test.pas),如下所示,我正在尝试生成内存跟踪,但无法获得包含行号等的任何详细输出。

program test;

var
  intPointer:^integer;

begin
  new(intPointer); //Allocate some memory
  intPointer^:=5;
  // dispose(intPointer);

  WriteLn('Hello World');

end.

我运行以下

fpc -g -gh -gl test.pas; ./test

这是我得到的输出。

Hello World
Heap dump by heaptrc unit
1 memory blocks allocated : 2/8
0 memory blocks freed     : 0/0
1 unfreed memory blocks : 2
True heap size : 327680 (32 used in System startup)
True free heap : 327488
Should be : 327512
Call trace for block [=12=]000001000CA0C0 size 2

在这个玩具示例中,我可以看出 intPointer 没有被处理掉,但对于更大的应用程序,我希望获得更多见解。其他在线示例似乎显示了分配内存的原始文件中的行号,我想知道我做错了什么。

有什么建议吗?

编辑:

添加了另一个我无法获取其行号信息的示例(第 9.2 小节)。

http://www.math.uni-leipzig.de/pool/tuts/FreePascal/units/node10.html

有时 lineinfo 无法准确确定源文件,特别是对于堆栈跟踪中的顶部调用。如果您想查看文件名,您需要将代码从主 begin/end 语句移动到过程中。这不是理想的解决方案,但它使调试更容易一些。

program test;

procedure PointerTest;
var
  intPointer:^integer;
begin
  new(intPointer); //Allocate some memory
  intPointer^:=5;
  // dispose(intPointer);

  WriteLn('Hello World');
end;

begin
  PointerTest;
end.

另外,现在单元exeinfo(lineinfo使用的)好像只支持ppc32 architecture on macOS.