Highlighted
Absent Member.
Absent Member.
1083 views

[archive] Detect debugger?

[Migrated content. Thread originally posted on 05 April 2004]

Is it possible to know at runtime whether or not the debugger is enabled (-d used on the command line)?
0 Likes
6 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Detect debugger?

Thanks. That helps a little, but won't work if my program is running on Unix.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Detect debugger?

A method that is portable is to enable the D symbol in the indicator area (e.g. pos 7).

If you for instance want to have a message box display if you execute under the debugger:

Change this:

DISPLAY MESSAGE BOX "With debugger!".

to:
D DISPLAY MESSAGE BOX "With debugger!".

(Note that the D is supposed to be in column 7 and DISPLAY starts in column 12... I intended to format this better, but this editor isn't my pal today... )

and compile with -Sd in addition to -Zd.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Detect debugger?

That would let me know if a program was compiled with the debugger, but I would like to know when the program is being *run* with the debugger (runcbl -d or wrun32 -d), regardless of how it was compiled.

It's an odd request, but I have a need to start another runtime to run something, and I would like the second runtime to have the debugger on if the original runtime had the debugger on, and vice versa.

I can't use CALL RUN because I need the two runtimes to execute simultaneously, and I don't want to use threads because I would have to do some major restructuring of some things because of some global external variables that are used, so starting a second runtime keeps things simple.

(Now, if I could do CALL RUN IN THREAD.....)
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Detect debugger?

Well, assuming this is something not going public (e.g. to end users), you could always set an environment variable indicating the status in a batch file and then read that from within the cobol app...

Like...

SET DEBUG-MODE = 1
wrun32 -d myapp

inside the app:

ACCEPT DBG FROM ENVIRONMENT ...


and so on...
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Detect debugger?

Another way that you can do this, is to use the statement :

ACCEPT ws-item FROM COMMAND-LINE

This will return the value of the command line that was used to start the run unit. From here you can inspect the item returned and see if the debugger option (-d) was used within the original command line.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Detect debugger?

ACCEPT FROM COMMAND-LINE won't include the -d. It only returns the part of the command line after the program name.

If I execute: wrun32 -d myprog.acu a b c

then ACCEPT FROM COMMAND-LINE only returns "a b c".
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.