Dear ListFolks,
I am unable to set breakpoints, and therefore unable to debug, GPC programs under GDB. The cause appears to be bad debugging information generated by GPC. For example, compiling:
program debug (output);
var i, j: integer;
begin i := 1; j := 2; writeln ('A Pascal test'); writeln ('Variable i is ', i); writeln ('Variable j is ', j) end.
with:
gpc -g -o debug.exe debug.pas
and starting GDB with:
gdb debug.exe
and then trying to set breakpoints, I see the following:
(gdb) break 6 Breakpoint 1 at $4011f2: file <implicit code>, line 6. (gdb) break 8 Note: breakpoint 1 also set at pc $4011f2. Breakpoint 2 at $4011f2: file <implicit code>, line 8. (gdb) break 10 Note: breakpoints 1 and 2 also set at pc $4011f2. Breakpoint 3 at $4011f2: file <implicit code>, line 10.
Note that all breakpoints reference the same address. Attempting to start the program gives:
(gdb) r Starting program: D:/debug.exe
Breakpoint 1, init_pascal_main_program () at <implicit code>:11 11 <implicit code>: No such file or directory. in <implicit code>
If I try running "objdump", I see the following:
objdump --debugging debug.exe
debug.exe: file format pei-i386
Bad stab: Datevalid:(0,21)=@s8;16;,0,8;Timevalid:(0,21),8,8; Year:(0,1),32,32;Month:(0,22)=r(0,1);0000000000001;0000000000014;,64,32; Day:(0,23)=r(0,1);0000000000001;0000000000037;,96,32; Dayofweek:(0,24)=r(0,1);0000000000000;0000000000006;,128,32; [...]
Running "objdump" on the object file yields a similar error report.
I've reproduced this on several PCs, as follows:
* OS: Win95, WinNT4, Win2K
* GPC versions: 20011222 (i486-pc-mingw32msvc, 2.95.3) 20020318 (i386-unknown-mingw32 -- the Chief's distro) 20020410 (i486-pc-mingw32msvc, 2.95.3) 20020410 (i686-pc-cygwin, 2.95.3)
* GDB versions: 4.18, 5.0, 5.1.1
Is this the same error that is listed in the "Known Bugs" section of the GPC manual as:
"...error in debug entries generated for objects" 8F990E3D9A6FD1118F3B0000F81EA1D84985D7@exchsa2.dsto.defence.gov.au
-- Dave Bryan
Dave Bryan wrote:
Dear ListFolks,
I am unable to set breakpoints, and therefore unable to debug, GPC programs under GDB. The cause appears to be bad debugging information generated by GPC. For example, compiling:
program debug (output);
var i, j: integer;
begin i := 1; j := 2; writeln ('A Pascal test'); writeln ('Variable i is ', i); writeln ('Variable j is ', j) end.
with:
gpc -g -o debug.exe debug.pas
and starting GDB with:
gdb debug.exe
and then trying to set breakpoints, I see the following:
(gdb) break 6 Breakpoint 1 at $4011f2: file <implicit code>, line 6. (gdb) break 8 Note: breakpoint 1 also set at pc $4011f2. Breakpoint 2 at $4011f2: file <implicit code>, line 8. (gdb) break 10 Note: breakpoints 1 and 2 also set at pc $4011f2. Breakpoint 3 at $4011f2: file <implicit code>, line 10.
The following method works here:
Set a breakpoint on "pascal_main_program", run it, and when it stops at the breakpoint (which is the first line of your main program body), set all other breakpoints you need (and delete the first one, if you like to). This step is needed just once, i.e. even if your program terminates, you may set any breakpoints normally and rerun it, without the hack just described.
Example:
(gdb) break pascal_main_program Breakpoint 1 at $8049bc6: file test.pas, line 6. (gdb) run Starting program: /mnt/sda2/home/ejer5183/pascal/a.out
Breakpoint 1, pascal_main_program () at test.pas:6 6 i := 1; (gdb) delete 1 (gdb) break 6 Breakpoint 2 at $8049bc6: file test.pas, line 6. (gdb) break 8 Breakpoint 3 at $8049bda: file test.pas, line 8. (gdb) cont Continuing.
Breakpoint 3, pascal_main_program () at test.pas:8 8 writeln ('A Pascal test'); (gdb) Continuing. A Pascal test Variable i is 1 Variable j is 2
Program exited normally. (gdb) break 10 Breakpoint 4 at $8049c50: file test.pas, line 10. (gdb) delete 2 (gdb) delete 3 (gdb) run Starting program: /mnt/sda2/home/ejer5183/pascal/a.out A Pascal test Variable i is 1
Breakpoint 4, pascal_main_program () at test.pas:10 10 writeln ('Variable j is ', j) (gdb)
Emil Jerabek
Note that all breakpoints reference the same address. Attempting to start the program gives:
(gdb) r Starting program: D:/debug.exe
Breakpoint 1, init_pascal_main_program () at <implicit code>:11 11 <implicit code>: No such file or directory. in <implicit code>
If I try running "objdump", I see the following:
objdump --debugging debug.exe
debug.exe: file format pei-i386
Bad stab: Datevalid:(0,21)=@s8;16;,0,8;Timevalid:(0,21),8,8; Year:(0,1),32,32;Month:(0,22)=r(0,1);0000000000001;0000000000014;,64,32; Day:(0,23)=r(0,1);0000000000001;0000000000037;,96,32; Dayofweek:(0,24)=r(0,1);0000000000000;0000000000006;,128,32; [...]
Running "objdump" on the object file yields a similar error report.
I've reproduced this on several PCs, as follows:
OS: Win95, WinNT4, Win2K
GPC versions: 20011222 (i486-pc-mingw32msvc, 2.95.3) 20020318 (i386-unknown-mingw32 -- the Chief's distro) 20020410 (i486-pc-mingw32msvc, 2.95.3) 20020410 (i686-pc-cygwin, 2.95.3)
GDB versions: 4.18, 5.0, 5.1.1
Is this the same error that is listed in the "Known Bugs" section of the GPC manual as:
"...error in debug entries generated for objects" 8F990E3D9A6FD1118F3B0000F81EA1D84985D7@exchsa2.dsto.defence.gov.au
-- Dave Bryan
On 25 Apr 2002, at 18:30, Emil Jerabek wrote:
Set a breakpoint on "pascal_main_program", run it, and when it stops at the breakpoint (which is the first line of your main program body), set all other breakpoints you need....
Indeed, that works fine. Thanks for the workaround.
-- Dave Bryan
J. David Bryan wrote:
I am unable to set breakpoints, and therefore unable to debug, GPC programs under GDB. The cause appears to be bad debugging information generated by GPC. For example, compiling:
program debug (output);
var i, j: integer;
begin i := 1; j := 2; writeln ('A Pascal test'); writeln ('Variable i is ', i); writeln ('Variable j is ', j) end.
with:
gpc -g -o debug.exe debug.pas
and starting GDB with:
gdb debug.exe
and then trying to set breakpoints, I see the following:
(gdb) break 6 Breakpoint 1 at $4011f2: file <implicit code>, line 6. (gdb) break 8 Note: breakpoint 1 also set at pc $4011f2. Breakpoint 2 at $4011f2: file <implicit code>, line 8. (gdb) break 10 Note: breakpoints 1 and 2 also set at pc $4011f2. Breakpoint 3 at $4011f2: file <implicit code>, line 10.
Note that all breakpoints reference the same address. Attempting to start the program gives:
AFAICS, setting the breakpoints works fine if you specify the file name (break foo.pas:6).
GPC creates some code automatically at the end of the program, including a `main' function which calls the initializers, then the real Pascal main program, and finally the finalizers. In order to avoid another debugging problem (that execution seems to start at the end of the file when you step through it, e.g. in RHIDE), we're telling the debugger that these functions are in a non-existent source file `<implicit code>'.
As I see now, gdb seems to use the file name of `main' as the default source file name. This might be reasonable for C, but here it causes the default source file name to be `<implicit code>' which leads to these strange results.
I don't know so much about gdb, so I don't know if/how one can tell gdb about the real source file, and I don't see what we could change in GPC without introducing the other problem again. If anyone has an idea ...
Is this the same error that is listed in the "Known Bugs" section of the GPC manual as:
"...error in debug entries generated for objects" 8F990E3D9A6FD1118F3B0000F81EA1D84985D7@exchsa2.dsto.defence.gov.au
No, that one was referring to OOP objects. Actually, I just checked it, and it seems to work now. (The report was 4 years old, so I can't tell exactly when or how it was fixed, but there have been so many changes since then ...)
Frank