Recent

Author Topic: GDB: debugger won't step into code / breakpoints won't break  (Read 3499 times)

CCRDude

  • Hero Member
  • *****
  • Posts: 596
I'm currently trying out some debugger code outside the IDE (will be added as a package later), and have problems with reaching certain code.

Situation: a FPCUnit console runner program. If I try to go through the whole program in the IDE pressing F7, I cannot reach my test code (probably because it's called from the test suite, which is in a package, which has no debugging information). If I set a break point within my test methods, I can reach them.

Experienced:
1. using a self created instance of TGDBMIDebugger, I can stepinto the whole program as well, but would not reach my test methods (as above with Lazarus itself).
2. using gdb on the console, I can set breakpoints on the test methods, and this way, gdb will step into this code.
3. using a self created instance of TGDBMIDebugger, the breakpoints I set are not working.

Expected:
Breakpoints to break execution, even if stepinto would otherwise skip it. I log the OnCurrent event to see which lines are reached, and those of the test methods are not. OnBreakpointHit is not triggered either.

Some very simple code:
Code: Pascal  [Select][+][-]
  1. procedure TCodeCoverageDebugger.Go(AFilename: string);
  2. var
  3.    i: integer;
  4. begin
  5.    FDebugger.Free;
  6.    FDebugger := CreateDebugger;
  7.    FLineProtocol.Clear;
  8.    FDebugger.BreakPoints.Add('c:\Development\Projects\CodingTools\laz-codecoverage-helper\source\CodeCoverage.GDB.TestCase.pas', 65);
  9.    FDebugger.BreakPoints.Add('c:\Development\Projects\CodingTools\laz-codecoverage-helper\source\CodeCoverage.GDB.TestCase.pas', i);
  10.    FDebugger.BreakPoints.Add('TCODECOVERAGEGDBTESTCASE__TESTLISTALLUNITFILENAMES');
  11.    FDebugger.Init;
  12.    try
  13.       FDebugger.FileName := AFilename;
  14.       FDebugger.WorkingDir := ExtractFilePath(AFilename);
  15.       repeat
  16.          FDebugger.StepInto;
  17.       until (FDebugger.State in [dsStop]);
  18.    finally
  19.       FDebugger.Done;
  20.    end;
  21. end;      

This is the debugger unit from which the above code is from, the TestDebugger project with the TestDebuggerForm form unit is there as well.

(it uses a slightly modified version of GDBMIDebugger.pas, where I added support for breakpoints by name, but only because the line based approach did not work before)

Has anyone enough direct experience with the debugger to see what I'm missing?

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: GDB: debugger won't step into code / breakpoints won't break
« Reply #1 on: June 23, 2017, 09:34:59 am »
I'm getting nearer:

Quote
Output: (gdb)
Output: <info line "c:\Development\Projects\CodingTools\laz-codecoverage-helper\source\CodeCoverage.GDB.TestCase.pas":97>
Output: &"info line \"c:\\Development\\Projects\\CodingTools\\laz-codecoverage-helper\\source\\CodeCoverage.GDB.TestCase.pas\":97\n"
Output: ~"Line 97 of \"CodeCoverage.GDB.TestCase.pas\" is at address 0x423210 <TCODECOVERAGEGDBTESTCASE__TESTGETUNITFULLFILENAME> but contains no code.\n"
Output: ^done
Output: (gdb)
Output: <-break-insert  "\"c:/Development/Projects/CodingTools/laz-codecoverage-helper/source/CodeCoverage.GDB.TestCase.pas\":97">
Output: ^done,bkpt={number="9",type="breakpoint",disp="keep",enabled="y",addr="0x0042321e",func="TCODECOVERAGEGDBTESTCASE__TESTGETUNITFULLFILENAME",file="CodeCoverage.GDB.TestCase.pas",fullname="C:\\Development\\Projects\\CodingTools\\laz-codecoverage-helper\\source\\CodeCoverage.GDB.TestCase.pas",line="97",thread-groups=["i1"],times="0",original-location="c:/Development/Projects/CodingTools/laz-codecoverage-helper/source/CodeCoverage.GDB.TestCase.pas:97"}
Output: (gdb)
Output: <-break-disable 9>
Output: ^done
Output: (gdb)

Direct "break" command at the console seems to behave differently than the -break-insert of the MI interface; it does not complain about the line not containing code.

Quote
(gdb) break c:\Development\Projects\CodingTools\laz-codecoverage-helper\source\CodeCoverage.GDB.TestCase.pas:65
Breakpoint 1 at 0x42306e: file CodeCoverage.GDB.TestCase.pas, line 65.

But even if I choose a line containing code, and set Enabled to true, -break-disable is called on my custom breakpoints... will need to dive deeper into the debugger units code.
« Last Edit: June 23, 2017, 09:58:57 am by CCRDude »

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: GDB: debugger won't step into code / breakpoints won't break
« Reply #2 on: June 23, 2017, 10:32:37 am »
Problem found; breakpoints get disabled by GDBMIDebugger when created; setting Enabled only works after the process has started (which for gdb is an unnecessary restriction imho, based on my experience with gdb at the console).

 

TinyPortal © 2005-2018