View Issue Details

IDProjectCategoryView StatusLast Update
0036633FPCCompilerpublic2020-03-29 16:55
ReporterCyrax Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformLinux x86_64OSArch 
Product Version3.3.1 
Summary0036633: [i386-linux] GDB and debug info generated by FPC trunk doesn't play along, "Step over" doesn't work as it should.
DescriptionThis bug report is continuation of this one https://bugs.freepascal.org/view.php?id=36522 ("[GDB backend] Inside at certain procedure, pressing F8 continues execution of the program instead of stepping to next line.")

Attached test program suddenly stops (its execution terminates succesfully) when stepping out ("Step over") from subroutine.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Cyrax

2020-01-28 11:32

reporter  

project1.zip (1,246 bytes)

Cyrax

2020-03-03 09:33

reporter   ~0121334

If I change result type of function Test to different one than String (AnsiString) then there will no abrupt program ending, debugger will continue debugging the process to the end.

Cyrax

2020-03-03 10:16

reporter   ~0121335

Attached updated test project.
project2.zip (1,367 bytes)

Cyrax

2020-03-27 09:47

reporter  

project3.zip (993 bytes)

Cyrax

2020-03-27 09:47

reporter   ~0121727

Attaching most simplest project which demonstrates this bug.

----

Somehow GDB gets confused on call opcode just before subroutine exit code and thinks that it is okay to keep executing until process ends, even if GDB is told to debug one line at the time.

project1.lpr:10                   begin
080490D0 55                       push   %ebp
080490D1 89e5                     mov    %esp,%ebp
080490D3 8d6424f8                 lea    -0x8(%esp),%esp
project1.lpr:11                   test1;
080490D7 e8e4ffffff               call   0x80490c0 <TEST1>
project1.lpr:12                   end;
080490DC 89ec                     mov    %ebp,%esp
080490DE 5d                       pop    %ebp
080490DF c3                       ret    


---

However if compiler adds nop opcode just before subroutine stack cleanup is done and execution is returned to caller routine, GDB keeps debugging one line at the time.

project1.lpr:10                   begin
080490D0 55                       push   %ebp
080490D1 89e5                     mov    %esp,%ebp
080490D3 8d6424f8                 lea    -0x8(%esp),%esp
project1.lpr:11                   test1;
080490D7 e8e4ffffff               call   0x80490c0 <TEST1>
project1.lpr:12                   end;
080490DC 90                       nop
080490DD 89ec                     mov    %ebp,%esp
080490DF 5d                       pop    %ebp
080490E0 c3                       ret


---

Attaching a patch (cgcpu.pas.diff) which works around this GDB bug and allows normal debugging behaviour to occur.
cgcpu.pas.diff (712 bytes)   
diff --git a/compiler/i386/cgcpu.pas b/compiler/i386/cgcpu.pas
index 397a2aba16..4a9df43263 100644
--- a/compiler/i386/cgcpu.pas
+++ b/compiler/i386/cgcpu.pas
@@ -302,6 +302,12 @@ unit cgcpu;
         end;
 
       begin
+
+        { Due to bug(?) in i386-linux GDB; normal debugging process ends aruptly, altought succesfully if GDB debugger encounters call instruction just before subroutine exit routines.
+          Add NOP instuction to go around this bug/feature. }
+        if target_info.system in [system_i386_linux] then
+          list.concat(Taicpu.op_none(A_NOP));
+
         { MMX needs to call EMMS }
         if assigned(rg[R_MMXREGISTER]) and
            (rg[R_MMXREGISTER].uses_registers) then
cgcpu.pas.diff (712 bytes)   

Jonas Maebe

2020-03-29 16:55

manager   ~0121754

Please file a bug report against gdb instead (https://sourceware.org/bugzilla/).

Issue History

Date Modified Username Field Change
2020-01-28 11:32 Cyrax New Issue
2020-01-28 11:32 Cyrax File Added: project1.zip
2020-03-03 09:33 Cyrax Note Added: 0121334
2020-03-03 10:16 Cyrax File Added: project2.zip
2020-03-03 10:16 Cyrax Note Added: 0121335
2020-03-27 09:47 Cyrax File Added: project3.zip
2020-03-27 09:47 Cyrax File Added: cgcpu.pas.diff
2020-03-27 09:47 Cyrax Note Added: 0121727
2020-03-29 16:55 Jonas Maebe Note Added: 0121754