Recent

Author Topic: Lazarus debugger fail in Ubuntu 13.04  (Read 37005 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10930
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #30 on: May 02, 2013, 01:53:08 pm »
I saw the response on the gdb list.
Quote
If Lazarus is depending on the language used by GDB to be English,
it sounds like Lazarus should override the user's environment in
terms of i18n. Typically, the language is determined via the LANG
and/or LC_* environment variables, so it should be able to force
English by setting LANG/LC_ALL et al to Eg. "C" before starting GDB.

The quickest way to test this, is for you to set this before starting lazarus.
If Lazarus gets the modified value, it should pass it on to gdb. (afaik)

You can set Lazarus to force using your language in the IDE, even if the environment is diff.

miguel-laz

  • New Member
  • *
  • Posts: 19
    • Bitiopia
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #31 on: May 02, 2013, 06:26:38 pm »
I saw the response on the gdb list.
Quote
If Lazarus is depending on the language used by GDB to be English,
it sounds like Lazarus should override the user's environment in
terms of i18n. Typically, the language is determined via the LANG
and/or LC_* environment variables, so it should be able to force
English by setting LANG/LC_ALL et al to Eg. "C" before starting GDB.

The quickest way to test this, is for you to set this before starting lazarus.
If Lazarus gets the modified value, it should pass it on to gdb. (afaik)

You can set Lazarus to force using your language in the IDE, even if the environment is diff.

Right, this is the solution. I modified the environment variable "LANG" to "export LANG = C" and debugging worked well, no errors.

Now we just need to automate the process, I thought of using "Project Options-> Compilation-> (Execute Before: Conmand & Execute After: Conmand)" but I'm not sure this works.

Do these commands correspond to terminal commands?Seems not!

How could I run "export LANG = C" before debugging and "export LANG = es_ES.UTF-8" after debugging from Lazarus?

Any idea?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10930
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #32 on: May 02, 2013, 06:56:04 pm »
It will need to be set to TProcess.Environment.
But all the other env may have to be copied, or it may be lost to gdb.

Also I am not sure if C is always the right choice.

And this needs to be tested, how it affects other platforms.... Probably it will become, an option.

You can report it on mantis, so it will not be forgotten.

miguel-laz

  • New Member
  • *
  • Posts: 19
    • Bitiopia
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #33 on: May 02, 2013, 11:41:48 pm »
Quote
It will need to be set to TProcess.Environment.
But all the other env may have to be copied, or it may be lost to gdb.

This solution is very interesting, I understand that the Lazarus  creates process "gdb" and before starting the process "gdb" set environment variables (copy of Lazarus + LANG modified process). When finished debugging do nothing.

What Lazarus source file manages the creation and completion of the process "gdb"?
Try to modify the source code to do some tests!

macmike

  • Jr. Member
  • **
  • Posts: 85
    • Soft-Practice
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #34 on: May 02, 2013, 11:56:01 pm »
. More importantly though the debugger appears to crash in that I can't move in or over the next statement (F7,F8) or out of the method. In fact pressing run F9 doesn't do anything either.

Pressing the stop button doesn't stop the debugging app and the breakpoint no longer stops execution. Here's what I think is the relevant bit of the log?

Indeed seems you found a bug in gdb. And gdb crashed:
Code: [Select]
<< TCmdLineDebugger.ReadLn "&"/build/buildd/gdb-7.6~20130417/gdb/parse.c:588: internal-error: mark_struct_expression: Assertion `parse_completion && expout_tag_completion_type == TYPE_CODE_UNDEF' failed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable.""
  [Debugger] Log output: &"/build/buildd/gdb-7.6~20130417/gdb/parse.c:588: internal-error: mark_struct_expression: Assertion `parse_completion && expout_tag_completion_type == TYPE_CODE_UNDEF' failed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable."
  << TCmdLineDebugger.ReadLn "&"\n""
  [Debugger] Log output: &"\n"

GDb may be able to recover and continue, after this crash (may be, or may not be.)

The problem is that gdb does not print the prompt, that it is ready for the next command. So the IDE waits indefinitely.


You may want to try, and change between stabs and dwarf (whatever you currently use). Maybe that will fix the error.
If you do, ensure you do for *ALL* packages, that have debug info.


If it doesn't help, you can try and configure a timeout.
In the debugger page of the option dialog is a property grid. This has an entry "TimeOutForEval" set it to 50. (And disable the "WarnOnTimeOut" if you like.)

Thanks for this.

Changing from dwarf to stabs didn't appear to do anything so I went back to dwarf. Now if I hover (after applying the suggested timeout settings) and then try to step I get the Debugger Stopping errors message and then:

Code: [Select]
The debugger experienced and unknown condition:
Press "Ignore" to continue debugging. This may NOT be safe. Press "Abort" to stop the debugger.
Exception: EAccessViolation with message "Access violation"
Context: TGDBMIDebuggerCommandEvaluate. State: Error

  $08060570
  $088F85F7  TGDBMIDEBUGGERCOMMANDEVALUATE__DOEXECUTE,  line 12357 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088F655B  TGDBMIDEBUGGERCOMMAND__EXECUTE,  line 10832 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E54EA  TGDBMIDEBUGGER__RUNQUEUE,  line 6557 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E3B24  TGDBMIDEBUGGER__UNLOCKCOMMANDPROCESSING,  line 6270 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E57D0  TGDBMIDEBUGGER__RUNQUEUE,  line 6614 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10930
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #35 on: May 03, 2013, 12:07:23 am »
debugger\cmdlinedebugger.pp

the gdb stuff is in debugger\gdbmidebugger.pp  so it will be called from there.

IIRC cmdlinedebugger.pp is also used for running projects if the debugger is disabled (the unit for that is processdebugger , which is not a real debugger)

----
Note that you will find environemntstuff, but that is nod for gdb. It is stuff passed VIA gdb to the project (if set in Menu>Run>"run parameters")


----
function TCmdLineDebugger.CreateDebugProcess(const AOptions: String): Boolean;

This must also be fixed, because the current used CommandLine is deprecated. exe-name and arguments must in future be separated.

For your own testing, you can set environment here.

But the final solution must ass a param to the function (maybe TStrings) from gdbmidebugger



Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10930
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #36 on: May 03, 2013, 12:19:09 am »

Changing from dwarf to stabs didn't appear to do anything so I went back to dwarf. Now if I hover (after applying the suggested timeout settings) and then try to step I get the Debugger Stopping errors message and then:

Code: [Select]
The debugger experienced and unknown condition:
Press "Ignore" to continue debugging. This may NOT be safe. Press "Abort" to stop the debugger.
Exception: EAccessViolation with message "Access violation"
Context: TGDBMIDebuggerCommandEvaluate. State: Error

  $08060570
  $088F85F7  TGDBMIDEBUGGERCOMMANDEVALUATE__DOEXECUTE,  line 12357 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088F655B  TGDBMIDEBUGGERCOMMAND__EXECUTE,  line 10832 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
 [/quote]

Ok, that is a bug in the Lazarus code.

I will need a new log from you please, so I can see which commands the IDE sends to gdb before the IDE fails.

Also the log may tell me, if gdb is still reacting same, or if it has taken damage to the debug session.

macmike

  • Jr. Member
  • **
  • Posts: 85
    • Soft-Practice
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #37 on: May 03, 2013, 01:00:41 am »
Here you go:

Code: [Select]
  OnIdle: UnLock
  TGDBMIDebugger.UnLockCommandProcessing: Execute RunQueue
    Executing (Recurse-Count=0) queued= 15 CmdPrior=0 CmdMinRunLvl=-1 : "TGDBMIDebuggerCommandEvaluate: n Thread=1, Frame=0" State=Pause PauseWaitState=0
      >>Enter: TGDBType.ProcessExpression: state = gtpsInitial   Expression="n"
      <<Exit:  TGDBType.ProcessExpression: state = gtpsInitialSimple  Result=False Kind=skSimple Attr= Typename="" InternTpName="" TypeDeclaration=""
      >> TCmdLineDebugger.SendCmdLn "ptype n"
      << TCmdLineDebugger.ReadLn "&"ptype n\n""
      [Debugger] Log output: &"ptype n\n"
      << TCmdLineDebugger.ReadLn "&"No symbol \"n\" in current context.\n""
      [Debugger] Log output: &"No symbol \"n\" in current context.\n"
      << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"n\" in current context.""
      TGDBMIDebugger.ProcessResult Error: ,msg="No symbol \"n\" in current context."
      << TCmdLineDebugger.ReadLn "(gdb) "
      >>Enter: TGDBType.ProcessExpression: state = gtpsInitialSimple   Expression="n"
        ERROR: detected state loop in ProcessExpression
      <<Exit:  TGDBType.ProcessExpression: state = gtpsInitialSimple  Result=True Kind=skSimple Attr= Typename="" InternTpName="" TypeDeclaration=""
      >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression parentfp"
      << TCmdLineDebugger.ReadLn "^error,msg="No symbol \"parentfp\" in current context.""
      TGDBMIDebugger.ProcessResult Error: ,msg="No symbol \"parentfp\" in current context."
      >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression 7"
      >> TCmdLineDebugger.SendCmdLn "-data-evaluate-expression 1"
      << TCmdLineDebugger.ReadLn "(gdb) "
      [WARNING] TGDBMIDebugger:  ExecuteCommand "-data-evaluate-expression parentfp" failed.
      DebuggerState: Setting to Error, from Pause
        DebugDataMonitor: >>ENTER: TGDBMIThreads.DoStateChange  New-State=Error
        DebugDataMonitor: <<EXIT: TGDBMIThreads.DoStateChange
        DebugDataMonitor: >>ENTER: TGDBMICallStack.DoStateChange  New-State=Error
        DebugDataMonitor: <<EXIT: TGDBMICallStack.DoStateChange
        DebugDataMonitor: >>ENTER: TGDBMILocals.DoStateChange  New-State=Error
        DebugDataMonitor: <<EXIT: TGDBMILocals.DoStateChange
        DebugDataMonitor: >>ENTER: TGDBMIWatches.DoStateChange  New-State=Error
        DebugDataMonitor: <<EXIT: TGDBMIWatches.DoStateChange
        Canceling: "TGDBMIDebuggerCommandEvaluate: Result Thread=1, Frame=0"
        Canceling: "TGDBMIDebuggerCommandEvaluate: y Thread=1, Frame=0"
        Canceling: "TGDBMIDebuggerCommandEvaluate: x Thread=1, Frame=0"
        Canceling: "TGDBMIDebuggerCommandEvaluate: n Thread=1, Frame=0"
        >> TCmdLineDebugger.SendCmdLn "kill"
        DebugDataMonitor: >>ENTER: TSnapshotManager.DoStateChange  New-State=Error
        DebugDataMonitor: <<EXIT: TSnapshotManager.DoStateChange
      DebuggerState: Finished Error
      DebugDataMonitor: TWatchValue.SetValidity: FThreadId=1  FStackFrame=0 Expr=n AValidity=ddsError
      ERROR: Exception occured in TGDBMIDebuggerCommandEvaluate.DoExecute EAccessViolation Msg="Access violation" Addr=08060570 Dbg.State=Error
        $08060570
  $088F85F7  TGDBMIDEBUGGERCOMMANDEVALUATE__DOEXECUTE,  line 12357 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088F655B  TGDBMIDEBUGGERCOMMAND__EXECUTE,  line 10832 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E54EA  TGDBMIDEBUGGER__RUNQUEUE,  line 6557 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E3B24  TGDBMIDEBUGGER__UNLOCKCOMMANDPROCESSING,  line 6270 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E57D0  TGDBMIDEBUGGER__RUNQUEUE,  line 6614 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E5CC1  TGDBMIDEBUGGER__QUEUECOMMAND,  line 6696 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E68D6  TGDBMIDEBUGGER__GDBRUN,  line 6955 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $088E817E  TGDBMIDEBUGGER__REQUESTCOMMAND,  line 7370 of /usr/share/lazarus/1.0.8/debugger/gdbmidebugger.pp
  $084E5374  TDEBUGGER__REQCMD,  line 6396 of /usr/share/lazarus/1.0.8/debugger/debugger.pp
  $084E5A3B  TDEBUGGER__RUN,  line 6410 of /usr/share/lazarus/1.0.8/debugger/debugger.pp
  $084D7414  TDEBUGMANAGER__RUNDEBUGGER,  line 2466 of debugmanager.pas
  $084D1A24  TDEBUGMANAGER__ONRUNTIMER,  line 795 of debugmanager.pas
  $082C7545  TCUSTOMTIMER__DOONTIMER,  line 181 of customtimer.pas
  $082C74AF  TCUSTOMTIMER__TIMER,  line 156 of customtimer.pas
  $082BE1D4  GTKTIMERCB,  line 2852 of gtk2callback.inc
  $B7013107
      Canceling: "TGDBMIDebuggerCommandEvaluate: n Thread=1, Frame=0"
      Canceling: "TGDBMIDebuggerCommandEvaluate: n Thread=1, Frame=0"
      DebuggerState: Setting to None, from Error
        DebugDataMonitor: >>ENTER: TGDBMIThreads.DoStateChange  New-State=None
        DebugDataMonitor: <<EXIT: TGDBMIThreads.DoStateChange
        DebugDataMonitor: >>ENTER: TGDBMICallStack.DoStateChange  New-State=None
        DebugDataMonitor: <<EXIT: TGDBMICallStack.DoStateChange
        DebugDataMonitor: >>ENTER: TGDBMILocals.DoStateChange  New-State=None
        DebugDataMonitor: <<EXIT: TGDBMILocals.DoStateChange
        DebugDataMonitor: >>ENTER: TGDBMIWatches.DoStateChange  New-State=None
        DebugDataMonitor: <<EXIT: TGDBMIWatches.DoStateChange
        DebugDataMonitor: >>ENTER: TSnapshotManager.DoStateChange  New-State=None
        DebugDataMonitor: <<EXIT: TSnapshotManager.DoStateChange
      DebuggerState: Finished None
    Exec done
    Leaving Queue with count: 0 Recurse-Count=0 State=No

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10930
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #38 on: May 03, 2013, 02:05:02 am »
Unfortunately the log does not go back to the point where the gdb crash happened. So it is hard to interpret it.

It may however be enough to figure out what crashes the Lazarus exe.

However that will probably not help to much. It does look that gdb is no longer fully responsive at this stage.

The IDE detects that via the timeouts. Unfortunately the timeout does not recover. As a result the IDE does the last thing it can do: Go to error state, and try to at least shut down the debug session. However going to error state at this particular location leads to a crash.
That means fixing the crash will only allow the IDE to inform you that the debug session was lost.

BTW: longer timeouts will (most likely) not help. the 50 milliseconds you specified only indicate how soon the IDE starts detection. Detection will wait about 3 full seconds minimum.

I can see you are hovering (or add a watch) over "n". But there is no such variable.
"parentfp" is an internal symbol. It is used to detect if or if not you are in a nested procedure (you probably were not). On that gdb failed, which is very unusual.

------------------

I have seen a similar issue before.  If gdb fails on looking for a symbol that does not exist, then it means that gdb must scan the *entire* list of *all* symbols in the exe.
And if just one symbol in that list is not good to gdb, then good bye.

** 1)
Do you use any extra packages? bgra, lazreport, tachart, 3rd party?

Each package has its own settings for dwarf versus stabs.
Unfortunately the IDE is not smart enough to detect if a project mixes different settings.

So your final exe can end up with both. Technically that is possible. But gdb may dislike it (some gdb seem fine with that, but not all).

So please check each used package.

** 2)
This is only to be checked in the project. on the linking page of the options.

Make sure you do NOT smart link (units can be "smart linkable", but the linker must NOT smart link them)

Some linkers, when smart linking include stuff for code that is not in the exe, and that can also cause gdb to get into trouble.

--------------------------------------
If neither of that helps: Did the previous/older gdb do better?



miguel-laz

  • New Member
  • *
  • Posts: 19
    • Bitiopia
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #39 on: May 03, 2013, 01:43:41 pm »
Well, this is the first approximation of source code modification of the method TCmdLineDebugger.CreateDebugProcess () but there are a number of issues that I have not yet very clear ...

1. SysUtils.GetEnvironment? .... () Refers to the main application process?I understand that it is!

2. The format of each entry in TProcess.Environment think is right, I need to see the value of TStrings doing a debug .

Code: [Select]
function TCmdLineDebugger.CreateDebugProcess(const AOptions: String): Boolean;
var
  envCount: integer;
  cont:integer;
  envValue:string;
  checkLang:boolean;
  setLangValid:boolean;
begin
  if FDbgProcess = nil
  then begin
    setLangValid:=False;
    FDbgProcess := TProcess.Create(nil);

    // Get all environment variables ¿current application process?
    // and add to FDbgProcess.Environment
    envCount := SysUtils.GetEnvironmentVariableCount;
    if envCount > 0 then
    begin
      for cont:=1 to envCount do
      begin
           envValue:=SysUtils.GetEnvironmentString(cont);
           checkLang:=StrUtils.AnsiStartsText('LANG=en', envValue);
           if checkLang = True then
           begin
              envValue:='LANG=C';
              setLangValid:=True;
           end;
           FDbgProcess.Environment.Add(envValue);
      end;
    end;

    if setLangValid = False then
       FDbgProcess.Environment.Add('LANG=C');
    // end LANG case
    "
    "


How I can debug Lazarus himself?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10930
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #40 on: May 03, 2013, 02:09:10 pm »

How I can debug Lazarus himself?

Open: ide/lazarus.lpi

miguel-laz

  • New Member
  • *
  • Posts: 19
    • Bitiopia
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #41 on: May 03, 2013, 06:03:33 pm »

How I can debug Lazarus himself?

Open: ide/lazarus.lpi

I tried to debug Lazarus "ide/lazarus.lpi" from a portable version (usb pen drive) Lazarus and does not work, now on a version installed everything worked properly ... thanks

It is really hard to debug Lazarus itself! In Ubuntu, I had to create a local installation from the sources that the original location "usr/share/lazarus" I have permission problems.

When you start debugging an error "in dir EReadError 8A6463" debugging options step-to-step all disabled on the primary IDE, the debugger stops at the breakpoint selected but does not show the values ​​of the variables.

Does the IDE in debug runs before leaving TCmdLineDebugger.CreateDebugProcess ()? Can more than one process?

Developers Lazarus! Like what are you doing?
« Last Edit: May 03, 2013, 07:40:47 pm by miguel-laz »

miguel-laz

  • New Member
  • *
  • Posts: 19
    • Bitiopia
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #42 on: May 03, 2013, 08:19:18 pm »
It seems the problem has been resolved.  :D

The debugger error window no longer appears at the end of debugging with the stop button (red square), the method TCmdLineDebugger.CreateDebugProcess () looks like this:

Code: [Select]
function TCmdLineDebugger.CreateDebugProcess(const AOptions: String): Boolean;
var
  envCount: integer;
  cont:integer;
  envValue:string;
  checkLang:boolean;
  setLangValid:boolean;
begin
  if FDbgProcess = nil
  then begin
    setLangValid:=False;
    FDbgProcess := TProcess.Create(nil);
    FDbgProcess.CommandLine := UTF8ToSys(ExternalDebugger + ' ' + AOptions);
    // TODO: under win9x and winMe should be created with console,
    // otherwise no break can be sent.
    FDbgProcess.Options:= [poUsePipes, poNoConsole, poStdErrToOutPut, poNewProcessGroup];
    FDbgProcess.ShowWindow := swoNone;
    AssignUTF8ListToAnsi(DebuggerEnvironment,FDbgProcess.Environment);
  end;
  if not FDbgProcess.Running
  then begin
    // Get all environment variables ¿current application process?
    // and add to FDbgProcess.Environment
    envCount := SysUtils.GetEnvironmentVariableCount;
    if envCount > 0 then
    begin
      for cont:=1 to envCount do
      begin
           envValue:=SysUtils.GetEnvironmentString(cont);
           checkLang:=StrUtils.AnsiStartsText('LANG=', envValue);
        if checkLang = True AND
           StrUtils.AnsiStartsText('LANG=en', envValue) = False then
           begin
              envValue:='LANG=C';
              setLangValid:=True;
           end;
           FDbgProcess.Environment.Add(envValue);
      end;
    end;

    if setLangValid = False then
       FDbgProcess.Environment.Add('LANG=C');
    // end LANG case

    FDbgProcess.Execute;
    DebugLn('[TCmdLineDebugger] Debug PID: ', IntToStr(FDbgProcess.Handle));
  end;
  Result := FDbgProcess.Running;
end;

this is the new log file "laz.log" (attached), everything seems fine.

In short I will create a new entry error report "bugtracker".

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10930
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #43 on: May 03, 2013, 08:38:05 pm »
Good, but as I explained: To make it into the official lazarus, it must be optional, and it must be limited to gdb based debuggers.

Anyway, glad it works for you now.

miguel-laz

  • New Member
  • *
  • Posts: 19
    • Bitiopia
Re: Lazarus debugger fail in Ubuntu 13.04
« Reply #44 on: May 06, 2013, 09:11:41 pm »
Just wanted to mention that I received an email from "Tom Tromey" of "Redhat" says:

Code: [Select]
I just wanted to mention that it would be even better to change Lazarus
to use MI.  This is what MI was made for.

To solve this problem Do I need to create an entry in Bugtracker?
Is it enough grounds here?

 

TinyPortal © 2005-2018