code-debug icon indicating copy to clipboard operation
code-debug copied to clipboard

CodeDebug, LLDB, and FreePascal

Open pakLebah opened this issue 7 years ago • 4 comments

Continuing #118 by @carlca …

  • System:

    • [x] FPC v.3.0.2.
    • [x] VS Code v.1.23.
    • [x] Mac OS v.10.11 (El Capitan).
  • Debugger:

    • [x] LLDB v.360.1.70 (osx default).
    • [x] lldb-mi via XCode toolchain.
  • FPC debug info setting:

    • [x] -gw2 omitting dwarf v.2 format.
    • [x] -godwarfcpp simulating c++ info.
  • Status:

    • [x] All VS Code debugging features work.
  • Problems:

    1. All program identifiers become upper-case: minor.
    2. No global variables are shown in debugger panel, but they're still accessible through debug console using p command: major.
    3. There's no way to view the content of dynamic arrays, p command seems to view its memory address or something: major.
    4. Pascal program is unable to accept input because terminal setting is unknown: major.
    5. Debug console is producing some garbage texts if program using Pascal's CRT unit: major.
  • Sample code:

program test;

{$MODE OBJFPC}{$H+}

uses CRT;

var
  s: string;
  c,r: integer;
  a: array of integer;

begin
  ClrScr;

  // dynamic array test
  SetLength(a,10);
  for c := 0 to High(a) do a[c] := c;

  // string test
  c := ScreenWidth;
  r := ScreenHeight;
  s := 'Screen size: ';

  // input-output test
  writeln(s,c,'x',r);
  write('Type your name: ');
  readln(s);
  writeln('Hello, ',s,'!');
end.
  • Compiler command: fpc test.pas -Px86_64 -gw2 -godwarfcpp It can be configured as a task.

Hope those problems will be fixed soon.

Thank you.

pakLebah avatar May 27 '18 16:05 pakLebah

ii: general issue I found, not sure how to do a solution yet. iv: you could use gdb instead. lldb-mi does not have an option to redirect program output to another tty nor to spawn a separate terminal. v: can you specify that issue in more detail?

WebFreak001 avatar May 27 '18 17:05 WebFreak001

ii: I also have tried CodeLLDB extension. It's not using lldb-mi, it doesn't have such problem. But it has its own issues as well.

iv: CodeLLDB is able to redirect input/output through VS Code's integrated terminal. IMO, it gives better user experience. Mac has no gdb installed by default and I want to use lldb.

v: I think it's related to Debug Console due to codepage issue. Terminal could handle it well.

No response for i and iii?

pakLebah avatar May 27 '18 17:05 pakLebah

i: probably not fixable, I didn't look into it yet but I could imagine the pascal compiler changing identifiers to all uppercase. iii: not investigated yet, probably just needs a bit of work on the lldb/gdb output parser/renderer.

WebFreak001 avatar May 27 '18 18:05 WebFreak001

i is not a big problem, I can live with that as long as the variables are available on the debug panel (ii).

But iii and iv are deal breakers for me. How can I debug my code if I couldn't watch some important variables? Changing them into static arrays requires too much changes.

Workaround for v is not too hard, I can accept that.

pakLebah avatar May 28 '18 02:05 pakLebah