On 2026-02-20 17:19, Martin Frb via fpc-devel wrote:
E.g. currently
procedure foo;
var SeenByBar: byte;
procedure Bar;
begin {} end;
var NOT_SeenByBar: byte;
begin {} end;
FPC currently does not include the info that the 2nd var is not in
scope for Bar. There would afaik be several ways. So not a Dwarf
problem.
That was an interesting case - thanks for mentioning it. FPC has the
information needed, I just had to emit it into the debug info. It took
me about 5 minutes to include the declaration index in the debug
output and then read that info back in the debugger engine.
It took a bit longer to figure out the heuristics for my 'locals'
command, because the HighPC and LowPC for procedures are not nested
as I initially expected. FPC processed one method after another, even
though Bar() declaration is nested inside Foo().
But, got it all sorted out in the end, and I added this as an
official integration test.
------
(pdr) break test_19_nested_scope.pas:14
(pdr) break test_19_nested_scope.pas:24
(pdr) c
[PROG] running test
[INFO] Hit breakpoint at 0x0000000000401113
(pdr) locals
BarLocal = 2
SeenByBar = 1
(pdr) c
[PROG] inside bar
[INFO] Hit breakpoint at 0x00000000004010B3
(pdr) locals
SeenByBar = 1
NotSeenByBar = 99
(pdr) q
Exiting...
------
Complete example program is attached.
Regards,
Graeme
program test_19_nested_scope;
{$mode objfpc}{$H+}
procedure Foo;
var
SeenByBar: Integer;
procedure Bar;
var
BarLocal: Integer;
begin
SeenByBar := 1;
BarLocal := 2;
WriteLn('[PROG] inside bar'); { sentinel }
end;
var
NotSeenByBar: Integer;
begin
SeenByBar := 99;
NotSeenByBar := 99;
Bar();
WriteLn('[PROG] after bar'); { sentinel }
end;
begin
WriteLn('[PROG] running test');
Foo();
WriteLn('[PROG] done');
end.
_______________________________________________
fpc-devel maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel