Android Question Is Sub Routine tracing possible?

Similar threads

B4A Tutorial Uncaught Exceptions
B4A Question SSL Websocket client
B4A Code Snippet [B4X] Log stack trace
B4A Code Snippet ImageView / Bitmap rotating
B4A Question Mqtt chat network error

Robert Valentino

Well-Known Member
Licensed User
Is there a way in Debug mode to turn on routine tracing?

I know I can go put Log messages in the beginning and ALL the exit points of me routines (what a pain this would be)

It would be nice if there was someway to turn this type of feature on so I could easily see the execution path so maybe I can tighten things up.



Well-Known Member
Licensed User
Yes, that's something I've longed for in just about every dev environment I've worked in. A log, somewhat like this:

2015-03-25 07:42:02.142 Main.SelectFile_Click()
2015-03-25 07:42:02.144 Main.ShowFileSelector(Startdir="/")
2015-03-25 07:42:15.764 Main.SaveSettings()

Edit: Once in place, this would also be a large step towards a code profiler.
Last edited:


Well-Known Member
Licensed User
A stack trace is also useful, but in a different way. Routine tracing is helpful to see stuff like order of events, what is actually called, timing, if program flow is as expected and performance profiling. Stack trace is not useful in these cases.

Stack Trace, however, is very useful when you break on an error and wonder "OK, how did I get here???".

Brian Robinson

Active Member
Licensed User
Ahh yes... sorry - didn't really read it well enough did I.

Yes, both editions would be great...

If you add as a wish, I will like.


Well-Known Member
Licensed User
A not-perfect but possible approach would be (did something similar some time ago but not for these purposes. There may be errors, this is not the exact code but just the idea)

Replace any direct Sub call by xCallSub(module,procedureName)

where xCallSub is
Sub xCallSub(Component as Object, procedurename as string) as Object
  Dim O as Object
   log("START:"...) 'DateTiime, procedure name,...
#end if
   O=CallSub(Component, procedurename)
   log("EXIT"&.....) 'Datetime, .....
#end if
  return O
end sub
And define TRACING depending on your build configuration (or, if you don't want this overhead, replace any "xCallSub" string in the project for "CallSub" again)

You can also do it for CallSub2, CallSub3, needed

Also, for events, they should be defined in the following way

Sub myButton_Click
end sub

Sub myButtonClickHandler
  ' process the event here
end Sub

Hope this helps