Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a preprocessor identifier when $DEBUG is used #29

Closed
a740g opened this issue May 3, 2022 · 11 comments · Fixed by #562
Closed

Need a preprocessor identifier when $DEBUG is used #29

a740g opened this issue May 3, 2022 · 11 comments · Fixed by #562
Labels
enhancement New feature or request

Comments

@a740g
Copy link
Contributor

a740g commented May 3, 2022

Not sure if we already have this. But I checked the wiki and found nothing.

Having an identifier (like DEBUG for example) auto-set when the $DEBUG metacommand is used can be useful to include code that we only need when debugging.

For example:

$DEBUG

$If DEBUG Then
Print "We are debugging"
$End If

@mkilgore mkilgore added the enhancement New feature or request label May 5, 2022
@SteveMcNeill
Copy link
Member

Is this really a necessary change to make? The vast majority of the user's code would have to be inside $IF blocks, as above, and all they'd need to do is add a single truth statement to the start of the program to toggle when they wanted to see the debug information or not. IE:

$LET DEBUG = FALSE

'do all sorts of stuff

$IF DEBUG THEN
Print "We are debugging"
$End If

Change that $LET from FALSE to TRUE, and the user can manually turn on that debug segment, without necessarily having to rely on the built in vWatch debugging system.

QB64 source is quite complex and longish already. I'm not certain we'd see much actual benefit to digging into and sorting an extension out for this, when it's already so easily available for an end user. ;)

@a740g
Copy link
Contributor Author

a740g commented May 5, 2022

Yes true. But QB64 IDE automatically wants to add $DEBUG at the top when the line column is clicked. It would be nice if we could detect this using the preprocessor rather than manually editing.

@mkilgore
Copy link
Contributor

mkilgore commented May 5, 2022

Personally I'm somewhere in-between - the suggestion seems reasonable to me, but Steve's not wrong that you can get basically the same functionality by just defining DEBUG yourself. That said I don't actually know all that much about how $DEBUG works, I think I should look into it a bit more.

Seeing your snippet of code, what would also be nice is if you could wrap the whole thing into some kind of DebugPrint statement, rather than have the $ifs everywhere. You could almost get there with just a SUB, but it's not quite the same :-/ Any kind of change like that would require a fair amount more thought though :D

I would personally encourage you to give this change a shot if you feel like it. Looking at the qb64.bas code I don't think this is a hugely significant change to make, but even if we did decide to do it it's probably not something we would get to soon. I would not be opposed to adding this if we had a working version and it wasn't too complicated to add. The only thing I would suggest is make the define _DEBUG or something so it's less likely to clash with what people might already have.

@ghost
Copy link

ghost commented May 5, 2022

I'm with Matt on this. I'm somewhere in-between. It sounds nice but can easily be replicated with your own $LET.

@mechatronic3000
Copy link

The though I had for this was to use it to turn off the checking when I'm debugging. Maybe also print a warning to turn off optimizations as well.

$DEBUG

' fast LOOP
DO
 $IF DEBUG = FALSE THEN
  $CHECKING:OFF
 $END IF

 'Do stuff really fast

 $IF DEBUG = FALSE THEN
  $CHECKING:ON
 $END IF
LOOP 

@FellippeHeitor
Copy link
Contributor

If $debug is active and you're actually using its set of features you'll likely not need to print anything to debug the code really.

@RhoSigma-QB64
Copy link
Member

To be honest, I think all this switching sould be done internally. If $DEBUG is active, then we could just silently disable $CHECKING:OFF and compile without the C++ optimizaton flags, even if those are set. The $DEBUG should simply have the highest priority over the other things. The user obviously wants to debug his code, so we should internally make sure it works as expected, rather than forcing him to meet this and that pre-conditions. The only thing is maybe a warning we should issue telling him that some of his used options/commands/features are currently disabled due to the use of $DEBUG and that it will be automatically re-enabled as soon as he's done debugging and removes the $DEBUG command.

@mechatronic3000
Copy link

Regardless if its internal or external a $DEBUG preprocessor variable would be nice.

For example on my larger projects I have found writing a log file to be helpful, because it can give me a history of a variable. So, if $DEBUG is active, It could switch on extra information to put into the log.

Ultimately, the end user can use that information how they choose, and there is no downside to having it.

@FellippeHeitor
Copy link
Contributor

FellippeHeitor commented Aug 10, 2024

To be honest, I think all this switching sould be done internally. If $DEBUG is active, then we could just silently disable $CHECKING:OFF and compile without the C++ optimizaton flags, even if those are set

Yeah, about that...
Captura de Tela 2024-08-10 às 12 13 41

$Checking:Off will remove all intervention in user's code, including the ability to debug those lines.

@flukiluke
Copy link
Contributor

I think there is utility in having an identifier pre-defined whenever debug mode is active, as some commands are not conducive to debugging e.g.

$if not _DEBUG then
_fullscreen
$end if

With regards to $CHECKING, I hesitate to silently disable it when debugging as there are some programs that do otherwise okay tricks with _MEM but need $CHECKING:OFF to prevent the runtime checks getting in the way. The current warning seems sufficient.

@SteveMcNeill
Copy link
Member

SteveMcNeill commented Aug 11, 2024

Isn't the simple solution just to set a variable yourself with $LET?

$DEBUG
$LET DEBUG = WHATEVER

$IF DEBUG = UNDEFINED THEN
    _FullScreen
$END IF

It's really only one extra line of typing for the user, and they can use it to toggle for when they want to test certain segments or others, as needed.

$DEBUG
$LET DEBUG = SCREEN0

$IF DEBUG = CONSOLE THEN
    $CONSOLE:ONLY
$ELSEIF DEBUG = SCREEN0 THEN
    SCREEN (120, 40, 0)
$ELSEIF DEBUG = SCREEN256 THEN
   SCREEN (640,480,256)
$ELSE 
   SCREEN (640, 480, 32)
$END IF

RhoSigma-QB64 added a commit that referenced this issue Nov 3, 2024
- refactor $LET variable handling for easier addition of new presets and exposing internal values to the currently compiling program
- exposed DEPENDENCY_SOCKETS for conditional compiling of net helper functions in auto-include afterlastline.bm
- added DEBUG_IS_ACTIVE variable indicating program is compiling with $DEBUG features, closes #29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants