Page 1 of 1

Variable Viewer, view passed pointed structure

Posted: Tue Jul 22, 2025 4:10 pm
by Thumper
Well, that's the best way I can describe it. I've been trying out the debugger and hit a bump trying to view passed pointed structure.

I call my button draw routines with

Code: Select all

drawNormalButton ( @wPlayer01 \ audioPause )
which is

Code: Select all

procedure drawNormalButton ( *thebutton._gadgetExt )
     if startDrawing ( canvasOutput ( *theButton \ id ) )
. . .
What I'm seeing in the Variable Viewer for *theButton is a number, the pointer value itself.

Since I have a usable structure _gadgetExt defined in the procedure, is there a way to make the variable viewer expand that to view the contents of that structure ? I've tried the usual double-clicking, right-click menu (Add to Watchlist), + key, etc.

And yes, the passed parameter is a structure within a structure. wPlayer01 contains all of the controls (and more), audioPause here which has the _gadgetExt structure. (And I'm still loving the structure capabilities of PureBasic!)

Anyhow, figuring this out would be helpful. My current workaround is to assign a temp variable to see the structure item in question.

Dan

Re: Variable Viewer, view passed pointed structure

Posted: Tue Jul 22, 2025 9:07 pm
by HeX0R
Not sure why you didn't provide a usable short code instead of a difficult to follow description.
Assuming I got it correct, with the internal debugger you can show the content, when hovering over *button:
Image

I don't think it is possible with the variable viewer

Re: Variable Viewer, view passed pointed structure

Posted: Tue Jul 22, 2025 9:42 pm
by Thumper
Well, I've been told that my messages were too long so I posted only what is needed. Also, I don't see the source code. I've got something else. Give me a few hours to write something and make a screen shot.

Re: Variable Viewer, view passed pointed structure

Posted: Tue Jul 22, 2025 9:50 pm
by HeX0R
You shouldn't invest several hours, I said a "usable short code".
Which is a tiny code, anyone can paste into the IDE, press F5, it runs and people can look into it.
Like mine, you didn't say a word now, did I miss the point? Hovering in the IDE is not accepted?
Here again my quick'n dirty code according to your description:

Code: Select all

Structure _gadgetExt
	id.i
	s.s
EndStructure

Structure Player
	audioPause ._gadgetExt
EndStructure

Define Player.Player


Procedure BBBLA(*button._gadgetExt)
	Debug *button\id ;<- hover here over *button
	
	
	
	CallDebugger
EndProcedure

Player\audioPause\id = 12
BBBLA(@Player\audioPause)

Re: Variable Viewer, view passed pointed structure

Posted: Tue Jul 22, 2025 9:58 pm
by Thumper
I am on an extended phone call that will probably last at least another hour and will write something after the call.

Re: Variable Viewer, view passed pointed structure

Posted: Tue Jul 22, 2025 11:09 pm
by Thumper
I've distilled a real program to the essence below. Setting standardFont to 0 deliberately causes an error. What I'm showing is that cannot how to see how to get the variable viewer to show structure contents. Nothing serious. It will show other variables just fine. My solution has been to assign a temp variable before the error line and re-run.

Code: Select all

     structure _windowExt
          id                       .i
     endStructure

     structure _gadgetExt
          id                       .i
          type                     .i
          text1                    .s{1024}
          font1                    .i
     endStructure

     structure _pbpp_w_home
          window                   ._windowExt
          close                    ._gadgetExt
     endStructure

     declare w_home_create ( )
     declare drawButton ( *theButton._gadgetExt )

     global exitEventProcessor     .i = 0
     global w_home                 ._pbpp_w_home
     global standardFont           .i = 0 ; fontID ( loadFont ( #pb_any, "Courier New", 12 ) )
                                      ; setting to 0 to  _deliberately_ causing an error to show debugger

     procedure w_home_create ( )
          w_home \ window \ id = openWindow ( #pb_any, 0, 0, 200, 50, "Test proggy", #pb_window_screenCentered | #pb_window_systemMenu, 0 )

          if w_home \ window \ id
               with w_home \ close
                    \id = canvasGadget ( #pb_any, 5, 5, 190, 40 )
                    \text1 = "Close Program"
                    \font1 = standardFont
               endWith
               drawButton ( @w_home \ close )
          endIf
     endProcedure

     procedure drawButton ( *theButton._gadgetExt )
          if startDrawing ( canvasOutput ( *theButton \ id ) )
               drawingMode ( #pb_2dDrawing_default )
               box ( 0, 0, outputWidth ( ), outputHeight ( ), $004040 )

               drawingMode ( #pb_2dDrawing_transparent | #pb_2dDrawing_nativeText )
               drawingFont ( *theButton \ font1 )  ; error triggered here
               drawText ( 0, 0, *theButton \ text1 )
               stopDrawing ( )
          endIf
     endProcedure

     w_home_create ( )

     repeat
          select waitWindowEvent ( )
               case #pb_event_closeWindow
                    if eventWindow ( ) = w_home \ window \ id
                         closeWindow ( w_home \ window \ id )
                         exitEventProcessor = 1
                    endIf

               case #pb_event_gadget
                    if eventGadget ( ) = w_home \ close \ id
                         select eventType ( )
                              case #pb_eventType_leftClick
                              closeWindow ( w_home \ window \ id )
                              exitEventProcessor = 1
                         endSelect
                    endIf
          endSelect
     until exitEventProcessor = 1
Image

And here is a snippet of the batch file in case that is the problem.

Code: Select all

set currentProgram=t9889
set currentExecutable=%currentProgram%.exe

call "\progutil\PureBasic\purebasic 6.20\compilers\pbcompiler.exe" "%currentProgram%.%cpextension%" --output "%currentExecutable%" --thread --optimizer --debugger /dynamiccpu /UCRT
pb6debugger %currentExecutable%

Re: Variable Viewer, view passed pointed structure

Posted: Tue Jul 22, 2025 11:11 pm
by Thumper
Oh, and I do not use the PureBasic text editor. Let's just say that I have a well established workflow and am compiling from batch files.

Re: Variable Viewer, view passed pointed structure

Posted: Wed Jul 23, 2025 4:48 pm
by PBJim
I would think that the variable viewer is not intended to provide for the opening of structure elements when the structure is assigned to a pointer, at least that's the way it looks to me. As the icon appears as a block, rather than the usual arrow, I'd say it was deliberate.

It can be seen with a simple example. If we take existing code that's shown within the Pointers and memory access help, it allows us to open Point1 and its structure, but not *CurrentPoint. I couldn't see anything in the variable viewer help that might confirm this, but I would say that's the case. It provides only the pointed address — confirmed below.

Code: Select all

Define Point1.Point, Point2.Point

*CurrentPoint.Point = @Point1
*CurrentPoint \x = 10
*CurrentPoint.Point = @Point2
*CurrentPoint \x = 20

Debug *CurrentPoint

ShowVariableViewer()
CallDebugger

Re: Variable Viewer, view passed pointed structure

Posted: Wed Jul 23, 2025 8:10 pm
by spikey
I think this could be a feature request. The context debugger popup in the IDE supports dereferencing this sort of pointer:

Image

I'm guessing that it's possibly a case that the variable viewer window has never been updated to display it too. If I recall correctly, the context debugger info is a "new" feature introduced since I first started using PB so it's feasible the two features have become out of sync.

Re: Variable Viewer, view passed pointed structure

Posted: Thu Jul 24, 2025 4:07 am
by Thumper
Well, the Variable Viewer does show structures for local variables. It just seems that it cannot when the passed parameter points to a structure. It would be helpful but the workaround to create a local variable just before the error is still a means.

Still, I've used the --debugger a few times and have found it quite useful. It had almost exactly what is needed. Now that I think about, did PowerBasic even have a debugger?

Anyhow, thanks for looking at it. I'm moving on... doing a lot of graphics work tonight. Going to see if I can figure out what a "screen" really is...

Cheers!

Re: Variable Viewer, view passed pointed structure

Posted: Thu Jul 24, 2025 8:32 am
by PBJim
spikey wrote: Wed Jul 23, 2025 8:10 pm I think this could be a feature request. The context debugger popup in the IDE supports dereferencing this sort of pointer
I tend to take the view that the variable viewer is fine as it is — pointers with structures are an advanced feature and to some extent not an unreasonable limitation and which we can see while hovering over the pointer variable. Perhaps there was a technical obstacle.

I'm glad that the OP raised this though — I hadn't previously considered that the variable viewer could serve as a useful means of identifying possible obsolete vars in procedures :D

Re: Variable Viewer, view passed pointed structure

Posted: Thu Jul 24, 2025 11:17 am
by User_Russian
PBJim wrote: Thu Jul 24, 2025 8:32 amand which we can see while hovering over the pointer variable.
You cannot see all the fields of the structure. Only a few fields are displayed (note the three dots at the bottom of the window).
Image
Also, you will not be able to view an array or list in this structure.