[Implemented] The debugger should be improved

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
IceSoft
Addict
Addict
Posts: 1692
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

[Implemented] The debugger should be improved

Post by IceSoft »

Hello Fred,

I belive this is a very important whish (Of course it's my attention)

You changed the compiler with 3.91 (I am right?)
Now it is time to improve one of the important developer tool too:

The debugger!

Here are my wish list!
- Different views of the variables e.g.::
global view, local view (variables which are can be seen from the scope of the program structure, etc... (Maybe have a look on the Visual Studio Debugger too (for idees) :?

Here are a (sorry) windows only whish:
Maybe a compatible PDB file which can used with e.g: the free microsoft tool WinDbg (Windows Debugger)
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: The most important developer tool should be improved...

Post by NoahPhense »

True. But until then, check this out:
viewtopic.php?p=61207

- np
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: The most important developer tool should be improved...

Post by tinman »

NoahPhense wrote:True. But until then, check this out:
viewtopic.php?p=61207
DebugView is hardly any different from the PB debugger, although it can give you slightly different displays in it's logging. However, it's just an output logging program, not a debugger.

The PB debugger doesn't even show local variables, unless you specifically display it with the "Debug" command.

The PB debugger should have features added to it such as:
* The ability to display local variables (as mentioned by IceSoft)
* The ability to choose what variables to see, not just all of them (watches)
* The ability to evaluate the value of a variable in a one off display
* The ability to see inside structured variables
* Step over (procedures) not always into
* Array / memory address displays
* Ability to skip commands (currently if a command throws an error but you know it is safe to ignore because you have other checks in your code the only thing you can do is quit your program)
* Trace program execution (running as if you pressed step each time)
* A CPU view might be useful for inline asm-heads
* Modifying breakpoints, or setting conditions for breakpoints would be excellent but I can't see it happening too easily.

These are probably all in the VS debugger. Similar features can probably also be found in the gdb and Borland Turbodebugger.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: The most important developer tool should be improved...

Post by NoahPhense »

Ok, no reason to get defensive.. wasn't trying to put a halt to the building
of the debugger. ;)

Just sharing some sh!t I use..

- np
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: The most important developer tool should be improved...

Post by tinman »

NoahPhense wrote:Ok, no reason to get defensive.. wasn't trying to put a halt to the building of the debugger. ;)
I'm not getting defensive and why would my suggestions halt the building of the debugger (see, now that's defensive ;)? They're basically the same as what IceSoft wants to see, just written here rather than Fred having to go look at the VS debugger.

I use DebugView every day at work and at home (in my PB libraries mainly), I'd recommend it to anyone. But it's not a debugger :)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: The most important developer tool should be improved...

Post by NoahPhense »

Yeah, that's where I found debugview to be good for me, about a year
ago. Getting information from DLL's without having to spit'em out some
where else..

- np
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

I don't know if it may help but here is something I designed.

I guess it may help some of us, or give ideas to ask for debug extensions.

You will find two part here, a .pb for testing and a .pbi you may use as an include.

File : EnhancedDebugger.pb

Code: Select all

Enumeration
  #Window_Main
  #Gadget_Editor
EndEnumeration

;
; Sample code for using EnhancedDebugger
;
IncludeFile("EnhancedDebugger.pbi")

  EnhancedDebugger_Start("Console") ; Start EnhancedDebugger console mode
  EnhancedDebugger_Start("Window") ; Start EnhancedDebugger window mode
  EnhancedDebugger_Start("Debug") ; Start EnhancedDebugger regular debug mode (NOP)
  EnhancedDebugger_Start("File:EnhancedDebugger_Output.txt") ; Start EnhancedDebugger regular debug mode (NOP)

  a$ = "The quick brown fox jumps over the lazy dog ... "
  a$ = a$ + a$
  a$ = a$ + a$

  EnhancedDebugger_Output("Console", a$) ; Outputs a$ as a regular string
  EnhancedDebugger_HexDump("Console", @a$, Len(a$), 32) ; Dumps memory from a$ start address to last character of a$, using a width of 32 chars for display
  EnhancedDebugger_SplittedString("Console", a$, 40) ; Display a$ splitting it in 40 chars width substrings
  
  Dim Array.l(12, 12)
  
  For i = 0 To 12
    a$ = ""
    For j = 0 To 12
      Array(i, j) = 12 * i + j
      a$ + Str(Array(i, j)) + " "
    Next
    EnhancedDebugger_Output("File", a$)
  Next

  If OpenWindow(0, 0, 0, 322, 150,#PB_Window_SystemMenu |#PB_Window_ScreenCentered,"Test Window")
      EnhancedDebugger_Output("Window", Str(WindowID()))
      If CreateGadgetList(WindowID(0))
          hEditorGadget = EditorGadget (0,8,8,306,133,#PB_Container_Raised) 
          EnhancedDebugger_Output("Window", "Editor gadget handle is : " + Str(hEditorGadget)) 
      EndIf
      For a=0 To 5 
        Text.s = "Line "+Str(a)
        EnhancedDebugger_Output("Window", "Adding a line : " + Text)
        AddGadgetItem(0,a,Text) 
      Next 
      Repeat
  EnhancedDebugger_BreakPoint("Window") ; Set a Break Point
      Until WaitWindowEvent()=#PB_Event_CloseWindow 
      CloseWindow(0)
  EndIf 
  EnhancedDebugger_BreakPoint("") ; Set a Break Point
  EnhancedDebugger_Close("") ; Close EnhancedDebugger
End
File : EnhancedDebugger.pbi

Code: Select all

Global EnhancedDebugger_WindowNumber.l
EnhancedDebugger_WindowNumber = 1234
Global EnhancedDebugger_EditorGadgetNumber.l
EnhancedDebugger_EditorGadgetNumber = 1235
Global EnhancedDebugger_IsWindow.l
EnhancedDebugger_IsWindow = #FALSE
Global EnhancedDebugger_IsConsole.l
EnhancedDebugger_IsConsole = #FALSE
Global EnhancedDebugger_FileName.s

Procedure AppendFile(FileName.s, String.s)
  If OpenFile(99, FileName)
      FileSeek(Lof())
      WriteStringN(String)
      CloseFile(99)
  EndIf
EndProcedure

;
; EnhancedDebugger_Start(Output) Starts EnhancedDebugger using Output output name
;
; Available modes are right now :
;
; - Console
; - Debug
; - File[:FileName]
; - Window
;
; This procedure sets EnhancedDebugger_OutputName as a global variable reusable in all other EnhancedDebugger procedures
;
Procedure EnhancedDebugger_Start(Output.s)
  If Left(Output, 4) = "File"
      EnhancedDebugger_FileName = StringField(Output, 2, ":")
      Output = "File"
      If EnhancedDebugger_FileName = ""
          EnhancedDebugger_FileName = "Debug.txt"
      EndIf
  EndIf
  EnhancedDebugger_WindowNumber = 1234
  EnhancedDebugger_EditorGadgetNumber = 1235
  Select Output
    Case "Console"
      OpenConsole()
      Debug "Debugger console opened"
      EnhancedDebugger_IsConsole = #TRUE
    Case "Debug"
    Case "Window"
      If WindowID()
          WindowID = WindowID()
      EndIf
      WindowXSize = 480
      WindowYSize = 360
      WindowX = GetSystemMetrics_(#SM_CXSCREEN) - WindowXSize
      WindowY = 0
      If OpenWindow(EnhancedDebugger_WindowNumber, WindowX, WindowY, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_BorderLess, "EnhancedDebugger Window")
          AddKeyboardShortcut(EnhancedDebugger_WindowNumber, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
          If CreateGadgetList(WindowID(EnhancedDebugger_WindowNumber))
              EditorGadget(EnhancedDebugger_EditorGadgetNumber, 10, 10, WindowXSize - 20, WindowYSize - 20, "")
          EndIf
      EndIf
      If WindowID
          SetForegroundWindow_(WindowID)
      EndIf
      Debug "Debugger window opened"
      EnhancedDebugger_IsWindow = #TRUE
    Default
  EndSelect
EndProcedure

;
; EnhancedDebugger_Close(Output) closes the EnhancedDebugger device named in Output
; If Output is #NULL all opened EnhancedDebugger devices are closed.
;
Procedure EnhancedDebugger_Close(Output.s)
  Select Output
    Case "Console"
      If EnhancedDebugger_IsConsole
          CloseConsole()
      EndIf
    Case "Window"
      If EnhancedDebugger_IsWindow
          CloseWindow(EnhancedDebugger_WindowNumber)
      EndIf
    Case ""
      If EnhancedDebugger_IsConsole
          CloseConsole()
      EndIf
      If EnhancedDebugger_IsWindow
          CloseWindow(EnhancedDebugger_WindowNumber)
      EndIf
  EndSelect
EndProcedure

;
; EnhancedDebugger_Output(Output, String) outputs String to the Output device declared using EnhancedDebugger_Start
;
Procedure EnhancedDebugger_Output(Output.s, String.s)
  Select Output
    Case "Console"
      PrintN(String)
    Case "Debug"
      Debug String
    Case "File"
      AppendFile(EnhancedDebugger_FileName, String)
    Case "Window"
      If WindowID()
          WindowID = WindowID()
      EndIf
      UseWindow(EnhancedDebugger_WindowNumber)
      AddGadgetItem(EnhancedDebugger_EditorGadgetNumber, -1, String)
      If WindowID
          SetForegroundWindow_(WindowID)
      EndIf
    Default
      Debug String
  EndSelect
EndProcedure

;
; EnhancedDebugger_BreakPoint(Output) halts the program in a loop using Output device
;
Procedure EnhancedDebugger_BreakPoint(Output.s)
  Select Output
    Case "Console"
      While Inkey() = ""
      Wend
    Case "Debug"
      CallDebugger
    Case "Window"
      If WindowID()
          WindowID = WindowID()
      EndIf
      UseWindow(EnhancedDebugger_WindowNumber)
      SetWindowTitle(EnhancedDebugger_WindowNumber, "EnhancedDebugger Window : Break")
      Quit = #FALSE
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_Menu
            Select EventMenuID()
              Case #PB_Shortcut_Escape
                Quit = #TRUE
            EndSelect
        EndSelect
      Until Quit
      SetWindowTitle(EnhancedDebugger_WindowNumber, "EnhancedDebugger Window")
      If WindowID
          SetForegroundWindow_(WindowID)
      EndIf
    Default
  EndSelect
EndProcedure

;
; EnhancedDebugger_SplittedString(Output, String, Length) splits a string in multilined text of Length width to the Output device
;
Procedure EnhancedDebugger_SplittedString(Output.s, String.s, Length.l)
  For i = 1 To Len(String)
    EnhancedDebugger_Output(Output, Str(i) + " : " + Mid(String, i, Length))
    i + Length - 1
  Next
EndProcedure

;
; EnhancedDebugger_SplittedString(Output, String, Length) outputs an hexadecimal dump both Hex and ASCII representation
; using Length as memory size to display and Width as line width to use for display, starting the memory scan at Address.
; Output is the device used.
;
Procedure EnhancedDebugger_HexDump(Output.s, Address.l, Length.l, Width.l)
  EnhancedDebugger_Output(Output, "***** HexDump : " + Hex(Address) + " rendering " + Hex(Length) + " bytes")
  *Buffer = AllocateMemory(Length)
  CopyMemory(Address, *Buffer, Length)
  For i = 0 To Length - 1
    If PeekB(*Buffer + i) < ' '
        PokeB(*Buffer + i, ' ')
    EndIf
  Next
  For i = 0 To Length - 1
    a$ = ""
    For j = i To i + Width - 1
      a$ = a$ + RSet(Hex(PeekB(Address + j) & $FF), 2, "0") + " "
    Next
    EnhancedDebugger_Output(Output, RSet(Hex(Address + i), 8, "0") + " | " + a$ + " - " + PeekS(*Buffer + i, Width))
    i + Width - 1
  Next
EndProcedure
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

That's pretty nifty.. have you thought of a continuation of a full blown
debugger, or are you just waiting for Fred? 8O

**edit**
This needs to go in the CodeArchiv (Andre)

- np
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

I don't know if it may help but here is something I designed.
Nice, Fweil never stops coding! 8O :)
--Kale

Image
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

This is just at start for my own purpose and not to compete with the debugger.

My intention is to continue to add some more functions until the debug will be enhanced.

But we could start a collaborative work on this.
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Post Reply