Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-02

i'm looking for tips on debugging deep nested code with recursive functions

8 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello,

I have a code with a lot of loops and recursive calls. Somewhere at the code, at some point, I think I have an Off By One or something similar that happens that break my code. The question is, how would you suggest to compile such complicated calls to figure out where the problem/s exists ?

I'm using Lazarus 0.9.31 r35319M FPC 2.5.1 x86_64-linux-gtk 2 if that's helps

Thanks,
Ido

Reply by email

Everton Vieira
to ik
ik wrote 7 lines
Hello, I have a code with a lot of loops and recursive calls. Somewhere at the code, at some point, I think I have an Off By One or something similar that happens that break my code. The question is, how would you suggest to compile such complicated calls to figure out where the problem/s exists ?

For debug that, would be nice to make some log of the behavior of the app, that i`ve been thinking this days, but in which doesn't get nothing at far as usable. Well you can make a lot of debugln to monitor the behavior of it to try to see where is the problem. But i`m freak sure is hard work.

Show quoted text 11 lines
I'm using Lazarus 0.9.31 r35319M FPC 2.5.1 x86_64-linux-gtk 2 if that's helps Thanks, Ido -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

ik
to Everton Vieira
Everton Vieira wrote 11 lines
Em 15/02/2012, ?s 09:49, ik escreveu: > Hello, > > I have a code with a lot of loops and recursive calls. > Somewhere at the code, at some point, I think I have an Off By One or > something similar that happens that break my code. > The question is, how would you suggest to compile such complicated > calls to figure out where the problem/s exists ? For debug that, would be nice to make some log of the behavior of the app, that i`ve been thinking this days, but in which doesn't get nothing at far as usable. Well you can make a lot of debugln to monitor the behavior of it to try to see where is the problem. But i`m freak sure is hard work.

I have a lot of prints on the screen (stderr even). but I just can't figure out what am I missing. I know where it happens, and on what level, but not why.

Show quoted text 19 lines
> > I'm using Lazarus 0.9.31 r35319M FPC 2.5.1 x86_64-linux-gtk 2 if that's helps > > Thanks, > Ido > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

ik
to ik
ik wrote 16 lines
On Wed, Feb 15, 2012 at 13:59, Everton Vieira wrote: > Em 15/02/2012, ?s 09:49, ik escreveu: > >> Hello, >> >> I have a code with a lot of loops and recursive calls. >> Somewhere at the code, at some point, I think I have an Off By One or >> something similar that happens that break my code. >> The question is, how would you suggest to compile such complicated >> calls to figure out where the problem/s exists ? > > For debug that, would be nice to make some log of the behavior of the app, that i`ve been thinking this days, but in which doesn't get nothing at far as usable. Well you can make a lot of debugln to monitor the behavior of it to try to see where is the problem. But i`m freak sure is hard work. I have a lot of prints on the screen (stderr even). but I just can't figure out what am I missing. I know where it happens, and on what level, but not why.

Simple debug conditions works. found the reason, but not what cause it :)

Show quoted text 20 lines
> >> >> I'm using Lazarus 0.9.31 r35319M FPC 2.5.1 x86_64-linux-gtk 2 if that's helps >> >> Thanks, >> Ido >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Everton Vieira
to ik
ik wrote 19 lines
On Wed, Feb 15, 2012 at 14:19, ik wrote: > On Wed, Feb 15, 2012 at 13:59, Everton Vieira wrote: >> Em 15/02/2012, ?s 09:49, ik escreveu: >> >>> Hello, >>> >>> I have a code with a lot of loops and recursive calls. >>> Somewhere at the code, at some point, I think I have an Off By One or >>> something similar that happens that break my code. >>> The question is, how would you suggest to compile such complicated >>> calls to figure out where the problem/s exists ? >> >> For debug that, would be nice to make some log of the behavior of the app, that i`ve been thinking this days, but in which doesn't get nothing at far as usable. Well you can make a lot of debugln to monitor the behavior of it to try to see where is the problem. But i`m freak sure is hard work. > > I have a lot of prints on the screen (stderr even). but I just can't > figure out what am I missing. I know where it happens, and on what > level, but not why. Simple debug conditions works. found the reason, but not what cause it :)

I think you`ll have to go and see the three with its roots and so on that will happen to generate your problem. I think only with that view would be able to solve it. Specially in a app with recursive behavior. That`s in some cases is a lot complex. So, my guess remains, a lot of debugln.

Show quoted text 27 lines
> >> >>> >>> I'm using Lazarus 0.9.31 r35319M FPC 2.5.1 x86_64-linux-gtk 2 if that's helps >>> >>> Thanks, >>> Ido >>> >>> -- >>> _______________________________________________ >>> Lazarus mailing list >>> >>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Martin
to ik: I have a lot of prints on the screen (stderr even). but I just can't figure out what am I…
ik wrote 15 lines
On Wed, Feb 15, 2012 at 13:59, Everton Vieira wrote: > Em 15/02/2012, ?s 09:49, ik escreveu: > >> Hello, >> >> I have a code with a lot of loops and recursive calls. >> Somewhere at the code, at some point, I think I have an Off By One or >> something similar that happens that break my code. >> The question is, how would you suggest to compile such complicated >> calls to figure out where the problem/s exists ? > For debug that, would be nice to make some log of the behavior of the app, that i`ve been thinking this days, but in which doesn't get nothing at far as usable. Well you can make a lot of debugln to monitor the behavior of it to try to see where is the problem. But i`m freak sure is hard work. I have a lot of prints on the screen (stderr even). but I just can't figure out what am I missing. I know where it happens, and on what level, but not why.

For logging info on nested stuff. have a look at Debugln / DebuglnEnter / DebuglnExit (LclProc, trunk LazLogger)

Procedure Foo;
begin
   DebuglnEnter('now in foo')
   try  // optional
   Bar(Foo());
   Debugln('123');
   finally
   DebuglnExit('leaving foo')
   end
end;

All Debugln in the block are indented with 2 spaces per level (or prefixed number, if more than 15 spaces)

So that gives a nice log

Reply by email

Martin
to ik: Simple debug conditions works. found the reason, but not what cause it :)
ik wrote 16 lines
On Wed, Feb 15, 2012 at 14:19, ik wrote: > On Wed, Feb 15, 2012 at 13:59, Everton Vieira wrote: >> Em 15/02/2012, ?s 09:49, ik escreveu: >> >>> Hello, >>> >>> I have a code with a lot of loops and recursive calls. >>> Somewhere at the code, at some point, I think I have an Off By One or >>> something similar that happens that break my code. >>> The question is, how would you suggest to compile such complicated >>> calls to figure out where the problem/s exists ? >> For debug that, would be nice to make some log of the behavior of the app, that i`ve been thinking this days, but in which doesn't get nothing at far as usable. Well you can make a lot of debugln to monitor the behavior of it to try to see where is the problem. But i`m freak sure is hard work. > I have a lot of prints on the screen (stderr even). but I just can't > figure out what am I missing. I know where it happens, and on what > level, but not why. Simple debug conditions works. found the reason, but not what cause it :)

If you know the variable, and where it first exists:

trunk has watchpoints, so you can stop when the variable changes.

Note depending on cpu, the number of watchpoints (and the possible size of value) vary. he error is only given when trying to run/step.

Reply by email

ik
to Martin
Martin wrote 35 lines
On 15/02/2012 13:01, ik wrote: > > On Wed, Feb 15, 2012 at 14:19, ik ?wrote: >> >> On Wed, Feb 15, 2012 at 13:59, Everton Vieira >> ?wrote: >>> >>> Em 15/02/2012, ?s 09:49, ik escreveu: >>> >>>> Hello, >>>> >>>> I have a code with a lot of loops and recursive calls. >>>> Somewhere at the code, at some point, I think I have an Off By One or >>>> something similar that happens that break my code. >>>> The question is, how would you suggest to compile such complicated >>>> calls to figure out where the problem/s exists ? >>> >>> For debug that, would be nice to make some log of the behavior of the >>> app, that i`ve been thinking this days, but in which doesn't get nothing at >>> far as usable. Well you can make a lot of debugln to monitor the behavior of >>> it to try to see where is the problem. But i`m freak sure is hard work. >> >> I have a lot of prints on the screen (stderr even). but I just can't >> figure out what am I missing. I know where it happens, and on what >> level, but not why. > > Simple debug conditions works. found the reason, but not what cause it :) If you know the variable, and where it first exists: trunk has watchpoints, so you can stop when the variable changes. Note depending on cpu, the number of watchpoints (and the possible size of value) vary. ?he error is only given when trying to run/step.

Thanks. I finally figure out what happens. and It was off by 2 :) I had an inc(Index, 2); without checking first if it required, and 99% of the time it does, but 1% it does not, and that's the reason for the bug.
I can dig now a hole to China :)

Show quoted text 7 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email