Page 1 of 4

issue-#187 adding a run-time debugger to BlackBox

Posted: Tue May 15, 2018 2:21 pm
by Josef Templ
I have created https://redmine.blackboxframework.org/issues/187 for adding a run-time debugger to BlackBox.

Technically the debugger is based on a prototype by ominc, which has been ported to BB1.7 by oberoncore+x512+Ivan.
I have tested the prototype but was not very happy with the user interface. The main problem was that it required to start the
debugger first and attach the debugged BlackBox process to it later. In my opinion, the reverse approach would be more natural,
i.e. while working in BlackBox it should be possible to attach a debugger to it and to debug a command very much like
executing a command directly. A first version of this 'reversed' approach is now available.
The main differences over the ominc prototype are:

- improved user interface: debugger is attached to running BB, no flickering when single-stepping, tool dialog, etc.
- internationalized
- relevant DevDebug changes since BB1.6 applied to RTDebug.

A test version is available from http://blackboxframework.org/unstable/i ... 1.1023.zip.
If you want to debug a command M.P then select M.P in a text viewer and execute Dev->Debug Command.
If you want to open a module M in the debugger (e.g. for setting breakpoints) then select M in a text viewer and execute Dev->Debug Module.
Docu is included.

The debugger is a normal BlackBox process which simply uses the startup option /LOAD DevRTDebug.
DevRTDebug is a new module that uses the Windows debug API for attaching a debugger to a running process.
DevRTDebug is only loaded in the debugger process. Normal BlackBox execution does not load this module and is not affected.
There is only a small interface added in DevDebug for attaching (starting) a run-time debugger to the running BlackBox.
A couple of missing Windows debug API functions have been added to WinApi.
A nice side-effect of the reversed approach, and may be an indication that it is the right approach, is the fact
that the Kernel support for starting under the prototype run-time debugger with the magic lines

Code: Select all

S.PUTREG(ML, S.ADR(modList));
WinApi.OutputDebugStringW("BlackBox started");
(or any variation of it) is no longer required. However, it has been left for compatibility reasons.

The changes are https://redmine.blackboxframework.org/p ... a4d9f1453b.

Note: This also fixes an error in DevDebug.ShowArray, where the type of the variable vi has been changed from SHORTINT to INTEGER in issue-#19.
This variable is used for reading 2-byte characters and must be reset to SHORTINT.

I would be glad to get feed-back on this version of debugger.

- Josef

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Wed May 16, 2018 3:40 am
by Ivan Denisov
It is much easier to use now. Thanks for this new version!

There is still the old problem is if somebody would copy text from application to the debugger, it is hanging forever.

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Wed May 16, 2018 5:58 am
by Josef Templ
Ivan Denisov wrote:It is much easier to use now. Thanks for this new version!

There is still the old problem is if somebody would copy text from application to the debugger, it is hanging forever.
I see, if the application is stopped it cannot provide the clipboard data.
This applies to all applications that receive clipboard data, i.e. if I try to copy data from a
stopped application to Word, for example, it also hangs forever.
If I copy to Notepad, it also hangs but not forever.
After some time the Paste operation is terminated. So it may be possible to
solve this at the side of the receiver by using something like a timeout.

- Josef

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Tue May 29, 2018 1:54 pm
by Josef Templ
A small fix regarding Strings resources has been added.
Now there are separate keys SourceCodeBtn for the button label and
and SourceCode for the source code window title.

See diffs at https://redmine.blackboxframework.org/p ... b7d8c12d82.

The latest version can be downloaded from http://blackboxframework.org/unstable/i ... 1.1025.zip.

- Josef

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Wed May 30, 2018 7:14 am
by Ivan Denisov
Josef, can you please make it separate module?
DevDebug was platform independent module without WinApi import. It is distributing with Cross-Platform version well.
Now you put WinApi and it will cause problems for me (hard to sync with Center version).

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Wed May 30, 2018 11:47 am
by Josef Templ
Ivan Denisov wrote:Josef, can you please make it separate module?
DevDebug was platform independent module without WinApi import. It is distributing with Cross-Platform version well.
Now you put WinApi and it will cause problems for me (hard to sync with Center version).
I am looking into this.

But currently I am working on a problem with the 'Stop' button of the run-time debugger.
It used to work fine and I have not changed anything, but all of a sudden it no longer
works in most cases. The only thing I have done is a Windows version upgrade.
As far as I see also the X512/ominc debugger has the same problem now.

- Josef

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Thu May 31, 2018 9:02 am
by Josef Templ
Ivan Denisov wrote:Josef, can you please make it separate module?
DevDebug was platform independent module without WinApi import. It is distributing with Cross-Platform version well.
Now you put WinApi and it will cause problems for me (hard to sync with Center version).
I was thinking about moving the debugger start procedures to DevRTDebug but then
a large module is loaded even when only a very small part is needed.

The debugger start procedures could also be moved into a separate small module, e.g. DevDebugCmds.
The trivial guard 'DebugGuard' could remain in DevDebug and then there is nothing loaded at all unless you really
use it, i.e. attach a debugger. I have tried this approach now.

The latest version can be downloaded from http://blackboxframework.org/unstable/i ... 1.1026.zip.

- Josef

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Fri Jun 01, 2018 12:14 pm
by Josef Templ
I have added a work around for a problem with Stop.

The new version of DevRTDebug.Stop uses a retry loop. It is a work around for a problem probably introduced
by a recent Windows 10 update. It seems that setting the processor's trace flag is ignored when
the process is executing a certain part of the Windows library code. Therefore Stop does not
always work at the first attempt. So we retry until it works or it times out.

The latest version can be downloaded from http://blackboxframework.org/unstable/i ... 1.1027.zip.

- Josef

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Sat Jun 02, 2018 3:43 am
by DGDanforth
Josef,
I just want to add my two bits by saying thank you for doing this.

Doug

Re: issue-#187 adding a run-time debugger to BlackBox

Posted: Mon Jun 04, 2018 10:59 am
by Josef Templ
The latest version fixes the problem with 'Stop' in a reliable way
by using the function WinApi.DebugBreakProcess instead of setting the trace flag directly.
It also improves some details in the docu and it includes some cleanups.

The latest version can be downloaded from http://blackboxframework.org/unstable/i ... 1.1030.zip.

- Josef