Can a (Basic) macro break to the IDE debugger?

Is there any way to cause LibreOffice to break to the debugger in the IDE? I have a macro that occasionally fails with an invalid data type in one of the arguments, but I have no idea how that happens. When the macro fails the run-time context is gone, so I have no way of inspecting the arguments or call stack. If there were something I could call (or statement I could perform), I could temporarily add an On Error statement to trap errors and break to the debugger, and find out how to reproduce the error.

I am using LibreOffice Basic, but if it can be done with a different macro language that would be worth knowing too. Ideally the IDE would open even if it were not currently active, but a solution that only works if is already active would be better than nothing.

I do not think there is any point sharing my code, as the problem occurs quite deep while executing a macro in a large codebase and I have not isolated a situation that triggers it. Moreover I want a solution that will help me in the future, not just for this one problem.

We can not help you without your bugous macro code.

even with, no warranty :wink:

why temporarily ? :thinking:
sounds like a good practice to keep a fair number of them.

1 Like

You must know what (which typ of) arguments you pass to your macro functions and subroutines.
For example: a selected thing in a spreadsheet document can be a cell, a cell range, more than one subtypes of graphic objects, etc… They have basicly different properties. You must check the type of the passed argument/object by your code (inside the function/subroutine) before you use it: “is this object a Cell? - if ‘yes’ then do something”.
.
Otherwise there are object inspection tools: MRI and XRAYTOOL. Use them when you write a new subroutine. You call them “in situ” (inside the subroutine, before you use the passed object. They can list the existing properties, methods of the inspected programming object. You can remove the “MRI someobject” command from the code when the macro works fine.

You do not need to help me debug with it either, just tell me if you know of a function in the API that breaks into the debugger without terminating macro execution. It would save me time now and in future. Otherwise I am quite capable of narrowing it down and finding it myself.

Good point. I fear it would bloat my code too much to leave them everywhere, but for widely used functions I agree.

The object inspection tools can examine the problematic objects. But you must place the inspection command (manually) at the suspicious lines of the codelist. The macro running will be continued (if it is possible) after you close the window/panel of the inspection tool.
.
MRI

XrayTool
https://web.archive.org/web/20231002132402/https://berma.pagesperso-orange.fr/Files_en/XrayTool60_en.odt

Thanks; I shall take a look.