Recent

Author Topic: Stopping a program  (Read 6213 times)

guest64142

  • Guest
Stopping a program
« on: June 20, 2019, 03:23:07 am »
Hi
Newbe here with a question.  Yes , I'm in waay over my head.

I need to know what to insert in the s/w that will make it stop at a certain point. The s/w was written in BP abt 25 years ago.

The issue I'm having is with s/w that controls a tester. If a oddball module is installed, I get an error during initialization. I know which file is running but not sure at what point in the file that the error occurs.  I need to insert what ever it is (hook?,test point?) so the file stops running at that point. If the s/w stops, before the error occurs I'll know to move the hook(?) further down until the error occurs. Hope this makes sense.
I have the source code and I'm able to compile.

Thx!

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Stopping a program
« Reply #1 on: June 20, 2019, 03:28:33 am »
Yes, you need to load Lazarus and debug your program there.

Compile it with debug info and run the program from the Lazarus IDE.

 You can place a break point on the lines of source code where you may suspect an issue and
when the code gets there, you use F8 to single step each line of code and F7 to step into
a function or procedure. F9 will resume run.

The only true wisdom is knowing you know nothing

guest64142

  • Guest
Re: Stopping a program
« Reply #2 on: June 20, 2019, 03:45:14 am »
What does a break point look like? Is it a single character or a series of characters?

I was planning on editing the source code with a regular text editor then compile with BP which is already installed on the tester.
Will that not work?

Thx!


guest64142

  • Guest
Re: Stopping a program
« Reply #3 on: June 20, 2019, 05:08:18 am »
Gave up using BP. Opened file in Lazarus and found the BREAKPOINT option under RUN. I tried adding a breakpoint then saved file, then re-opened it and I don't see any change at the line I added a breakpoint. Should I see something there?

I see 3 different types of breakpoints:
Source Breakpoint
Address Breakpoint
Data/Watch Breakpoint

Which one should I be using?

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Stopping a program
« Reply #4 on: June 20, 2019, 06:27:55 am »
Just press the f5 key on the line where you want the breakpoint (press again to get rid of it).  If you do much debugging it's good to read up on the options (lot's of fun things to do like setting a watch on a variable to trigger when it hits a certain value).  Hover the mouse over variables to see their current values.

guest64142

  • Guest
Re: Stopping a program
« Reply #5 on: June 20, 2019, 07:07:05 am »
Used the F5 key. Line turned red and a little balloon appeared. Used "save as" and saved it. When I re-open the file, I don't see the red line or balloon where I set it. Does this mean it isn't there anymore or it's still there but not visible?

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Stopping a program
« Reply #6 on: June 20, 2019, 07:52:03 am »
Bookmarks and breakpoints are not saved. Nor should they be saved at all.
Specialize a type, not a var.

incendio

  • Sr. Member
  • ****
  • Posts: 269
Re: Stopping a program
« Reply #7 on: June 20, 2019, 07:58:55 am »
If not mistaken, breakpoints were saved in Lazarus 2.0.2 for linux.

guest64142

  • Guest
Re: Stopping a program
« Reply #8 on: June 20, 2019, 09:23:51 am »
This is what I assumed that I needed to do:
1. Modify pascal source code file init.pas somehow to make it stop at a predetermined point.
2. Copy modified source code file to tester. 
3. Rename the orig init.exe to init.bak
4. Compile modified source code file on tester.. Say it was called init.pas, after being compiled, it would create a file called init.exe
5. Installed init.exe into the proper directory (if not already)
6. Attempt to initialize tester and see if the pop-up error occurs before or after s/w stops running.
7. Move stop point in source code and repeat process to zero in on what's causing error to occur.

What am I missing?

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Stopping a program
« Reply #9 on: June 20, 2019, 09:27:31 am »
Under Windows, probably all intel/amd platforms this is quite easy:
Code: Pascal  [Select][+][-]
  1. asm int 3 end;
a.k.a. a software breakpoint.
You can decorate it with e.g. {$ifdef debug}

Reason: this can be actually in the sourcecode and is not dependent on any specific configuration or editor.
Flaw: depends on intel/amd instruction set
« Last Edit: June 20, 2019, 09:43:02 am by Thaddy »
Specialize a type, not a var.

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Stopping a program
« Reply #10 on: June 20, 2019, 09:48:07 am »
Instead of using a debugger, try just inserting some writeln statements at various points...like: writeln('at line 500');

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Stopping a program
« Reply #11 on: June 20, 2019, 12:30:30 pm »
Hi, first of all ensure your setup is correct: https://wiki.lazarus.freepascal.org/Debugger_Setup
Best results are usually with "dwarf with sets" setting.

What OS? 32/64 bit?

Can you test with a new project (just one or two lines of code) if the breakpoint works?

-----------
You said it might be in an unit's "initialization" section?
This may (maybe) require some extra config.
Tools > Option > DEbugger
There is a property grid, search for the entry "InternalStartBreak" and set it to "gdsbAddZero"

------------
If you have a project, then breakpoints should be saved. Please check the breakpoint window: View > Debug Windows > Breakpoints
If breakpoints are not shown in the source editor, check if there are symlinks (*nux) to the source file (or the folder). And if you open the file sometimes via the symlink and sometimes direct.
THe IDE does not know the symlinks, and this are 2 different files.
« Last Edit: June 20, 2019, 12:34:00 pm by Martin_fr »

guest64142

  • Guest
Re: Stopping a program
« Reply #12 on: June 20, 2019, 06:18:17 pm »
The OS on the tester is DOS 6.22..
The adding a writeln would probably do what I need. Just trying to figure out what section of the init file is causing the error to display. When the file runs, it's controlling the tester, by changing the config of relays, power supplies, DMMs, taking measurements looking up stuff from other files, etc. If any values are beyond preset limits it creates an error message. So basically, I don't think the file will run properly by itself in a simulated environment.

guest64142

  • Guest
Re: Stopping a program
« Reply #13 on: June 20, 2019, 08:02:22 pm »
Nothing but errors so far while trying to compile.

I add to the file:
Begin
          writeln('line 1078');
End;

Try to compile and it says:
Init.pas(1081) : Error 94: "." expected.
End;
     ^

Do I need a "Begin" and "End;" before and after the writeln command?

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Stopping a program
« Reply #14 on: June 20, 2019, 08:28:21 pm »
The last line of your program should be:
Code: Pascal  [Select][+][-]
  1. end.

 

TinyPortal © 2005-2018