Recent

Author Topic: Know caller for a procedure/function  (Read 3105 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Know caller for a procedure/function
« on: December 01, 2015, 08:57:44 am »
Hi !
I am trying to get for some error logging the procedure/function name from which another procedure/function was called, inside the called procedure.
I think it is in the same way like Sender : TObject can be picked up for visual controls.

For example inside my 'Insert' procedure i would like to know if, when I had the error, 'insert' was called from function A or function B.
I could add this name to the calling parameters but I am looking into a built-in functionality.
Please advise if this would be possible and how it would look like.
Using Lazarus 1.4.4 on Windows 7.

Thank you
Lazarus 2.0.2 64b on Debian LXDE 10

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Know caller for a procedure/function
« Reply #1 on: December 01, 2015, 09:47:04 am »
Some of what you want is provided in the Lazarus IDE under View->Debug windows->Call Stack, for which the default keyboard shortcut is Ctrl+Alt+S.

You can right-click on the routines listed when your program runs, and CopyAll to get the listing into the clipboard.

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Know caller for a procedure/function
« Reply #2 on: December 01, 2015, 09:52:52 am »
Thank you.
I would be needing this for run-time to spool what happened in logs for the user debug, or the user to send the logs to me for support.
I would guess I have to go and study the debug routines?
Lazarus 2.0.2 64b on Debian LXDE 10

balazsszekely

  • Guest
Re: Know caller for a procedure/function
« Reply #3 on: December 01, 2015, 09:56:18 am »
The easiest way is to use the Debugger-->Call Stack(Ctrl + Alt +S), but I suppose you want to log the errors without debugger.  Unfortunately there is no easy solution. You can insert some basic information like(line number, file name) with the {$I} directive(see: http://www.freepascal.org/docs-html/3.0.0/prog/progsu41.html) but in order to retrieve the caller's address AFAIK you need to generate map files(fpc -Xm) and use a specialized software like madExcept, Heureka, JCLDebug was in the case of delphi. The map file generated with delphi is entirely different from the fpc map file so they are not compatible.

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Know caller for a procedure/function
« Reply #4 on: December 01, 2015, 10:02:45 am »
Thank you!
I will stick then with the caller name in the parameters.
Lazarus 2.0.2 64b on Debian LXDE 10

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Know caller for a procedure/function
« Reply #5 on: December 01, 2015, 11:47:31 am »
You can also harness the DumpStack call in LCLProc.

 

TinyPortal © 2005-2018