Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

OutputDebugString implementation


  • Please log in to reply
51 replies to this topic
procyon
  • Members
  • 14 posts
  • Last active: May 16 2005 02:41 PM
  • Joined: 10 Feb 2005
I use OutputDebugString for most of my programming tasks, and I'm sure AutoHotkey would also benefit from this easy and convenient debugging feature.

BoBo
  • Guests
  • Last active:
  • Joined: --
Btw. Welcome procyon. Nice to know that someone from the Baltics is arround. :D

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

I use OutputDebugString for most of my programming tasks, and I'm sure AutoHotkey would also benefit from this easy and convenient debugging feature.

Do you mean having such strings appear in the script's main window or some similar window?

In case it helps, you can put "breakpoints" into a script this way:
ListLines ; Or ListVars (to show the contents of all variables)
pause

When the script reaches a breakpoint, it will display the info and then wait for you to unpause it.

procyon
  • Members
  • 14 posts
  • Last active: May 16 2005 02:41 PM
  • Joined: 10 Feb 2005
I use a program called DebugView from Sysinternals - http://www.sysintern...debugview.shtml that enables me to view debug output from my programs. By inserting OutputDebugString("some_explaining_text_and_values_of_variables") to key locations I can easily find out the cause of problem, if something went wrong.
I could of course use messageboxes or in this case breakpoints in scripts, but this would require my interaction while the script is running. With OutputDebugString I can let the script/program run as normal, and determine what went wrong afterwards. Of course I could also write a logfile to disk, but IMHO DebugView is so much more convenient.
And implementing this feature in AutoHotkey should be very easy.
A command called OutputDebugString with one string parameter, that would just call void OutputDebugString(LPCTSTR lpOutputString); with the same parameter.

Edit:
I tested ListVariables a bit, but it has some annoying side effects:
1) AutoHotkey window is activated every time
2) No history of values of variables, only most recent values

Edit2:
Just in case I was a bit unclear - void OutputDebugString(LPCTSTR lpOutputString); is a standard windows API call exported by kernel32.dll

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004

A command called OutputDebugString with one string parameter, that would just call void OutputDebugString(LPCTSTR lpOutputString); with the same parameter.


That seems easy enough; if you know enough C++, you can just make the command yourself and recompile AutoHotkey. I don't think anyone else would use this feature anyway.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I would use it. It's a great idea, although I would not put it on high priority. If Chris could put it on his to-do/wish list, it would be great.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
The nature of it restricts it's usage to those who have the appropriate debugging utilities, though. I imagine this is restricted to those who are heavy coders in a different language already, which, I'd guess, is a relatively small percentage of the AHK community.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
As procyon posted: the tool is freeware. So no problem for anyone to get it. I assume that nearly every AHK user is already useing command line tools. So why not get that tool too if he wants to have a benifit from that comand?
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Because up 'till now, AHK has stayed distant from other software of any kind, and I think it helps it's image a lot. It would be kind of strange to include a link to a foreign debugger on the main page, and to find out that it is intimately integrated with AutoHotkey. Call it "purity," call it "cleanness," call it whatever you want, but I think AHK should stand alone.

Of course outside software helps; I couldn't imagine using AHK without Winspector Spy, PSPad, or the countless command line tools I have in PATH. But the point is that they are optional, and use AHK features that are unobtrusive and not specialized like this would be.

As a last note, the size of AHK scripts/executables already surprises some; we should try to avoid adding more commands "on-demand" or just as a novelty. Like I said, if it's just a few lines, recompile it yourself.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

I would use it. It's a great idea, although I would not put it on high priority.

I don't have a concrete idea of exactly how it would work or what it would do. My impression is that you would store the store the output of OutputDebugString in memory. Later (upon selecting something from the main menu or tray menu, perhaps), the script could pop up a window containing the debug log for that session. Is this what you had in mind?

Mats
  • Guests
  • Last active:
  • Joined: --
Not quite. OutputDebugString is a simple Windows-API function (takes only a string as parameter) and that's all. There is no need to buffer anything. Another program (like the one from sysinternals, but there are dozens of other tools that do this) can hook into windows to receive the string. If no such program is running, no one will ever see the messages. Otherwise you see the live output just like printing to a console window.

It is a great help for debugging scripts, because you can leave your debug messages in the production code and only start the DebugString-Viewer when you want to see what's going on. No need for debug-MsgBoxes anymore!

Again: There is no penalty for using OutputDebugString without a Viewer/Debugger. And OutputDebugString is no third party tool - it's part of windows!

procyon
  • Members
  • 14 posts
  • Last active: May 16 2005 02:41 PM
  • Joined: 10 Feb 2005
This is how OutputDebugString API call works:
when a program calls it with some string as a parameter:
OutputDebugString("some text to output");
the windows kernel determines if there is a debugger attached to the process, if so the debugger gets the pointer to the string to do whatever it feels appropriate (DebugView adds it to its display, some debuggers pop-up a message box etc.) If no debuggers are present, then it does nothing.
An example:

#include <windows.h>

int main(void)
{
	OutputDebugString("test string");
	return 0;
}

This program would just exit if no debugger is present.
If you run it with for example DebugView present, then you see "test string" in DebugView's window. An example of how DebugView's output looks like, is on the page I gave the link to earlier.

Of course I admit, that not many people besides programmers know about debugging etc. So my suggestion would be - a command similar to ListVariables, but - it should let user specify some text to output, and the output would be shown on one of the windows accessible from "View" menu of AHK.

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Sorry. I was uncertain of the exact nature of it; I think this sounds great.

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004

I don't have a concrete idea of exactly how it would work or what it would do.

...as other people have said, it's a raw Win API call, like BlockInput (except perhaps, unlike BlockInput, this one takes one parameter...I don't know, maybe the BlockInput API does take a param?). Basically if you implement my WinAPI command, this would automatically be implemented too.

Do you mean having such strings appear in the script's main window or some similar window?

...he didn't mean that, but giving the AHK main window the DebugView functionality would be good, a new menu item "Debug messages.....Ctrl+D" & command ListDebug (or ViewDebug). Debugging with MsgBox's is clunky & sometimes changes the outcome, the delay provided by the box gives some things time to happen, but without the MsgBox, that same thing would fail. I recommend both, the OutputDebugString command & the AHK DebugView. Perhaps a separate .exe that hooks into all existing & newly run AHK processes & adds that menu item, so each script isn't operating as it's own DebugView. One .exe would catch the debug messages & send it to any AHK windows that request it & thus be off while the other .exe isn't running. My 1st idea was for the new .exe to add the menu item, but it could exist & start the program if it's not running, any AHK could start it, but it would only run once & work for all AHK's. Perhaps while running tho, it would add a menu item "Close Debugger" to stop that process.
Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
I have debugging code I use with pclip to output errors to the familiar console; just my two cents. :)