DebugCallingPosition()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

DebugCallingPosition()

Post by GPI »

When a procedure detect, that a parameter has a complete wrong value, it would be nice to get the position of the "Calling-Position"
for example:

Code: Select all

Procedure Test(a)
  
  If a=0
    Debug "Don't Call test with 0!"
    Debug DebugCallingPosition() ;should output "file at line xyz"
    CallDebugger 
  EndIf
EndProcedure

test(0)
DebugCallingPosition() should reference to the last line with "Test(0)"
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: DebugCallingPosition()

Post by Little John »

GPI wrote:When a procedure detect, that a parameter has a complete wrong value, it would be nice to get the position of the "Calling-Position"
Hi,

doesn't PB's Callstack viewer do that?
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: DebugCallingPosition()

Post by Demivec »

In accordance with Little John's suggestion:

Code: Select all

Procedure Test(a)
  
  If a=0
    Debug "Don't Call test with 0!"
    ShowCallstack() ;should show "line xyz and contents of last line called before this procedure"
    CallDebugger 
  EndIf
EndProcedure

test(0)
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: DebugCallingPosition()

Post by User_Russian »

GPI wrote:should output "file at line xyz"
It is necessary?

Code: Select all

Procedure Test(a)
  
  If a=0
    Debug "Don't Call test with 0!"
    Debug #PB_Compiler_Filename+"        "+#PB_Compiler_Procedure+"        "+#PB_Compiler_Line
    CallDebugger 
  EndIf
EndProcedure

test(0)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: DebugCallingPosition()

Post by GPI »

this will report the line with the debug. But it should reference to the line "test(0)".
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: DebugCallingPosition()

Post by Little John »

GPI wrote:this will report the line with the debug.
If "this" refers to User_Russian's post, then I agree.

However, for looking at the call stack, see Demivec's and my post above.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: DebugCallingPosition()

Post by Danilo »

Today I was looking for something like this as well:

Code: Select all

Procedure MyFunction(x)
    If x > 0 And x < 12
        ; DoSomething
CompilerIf #PB_Compiler_Debugger
    Else
        DebuggerWarning(#PB_Compiler_Module+"::"+
                        #PB_Compiler_Procedure+
                        "(): OUT OF BOUNDS ERROR! >>> Please [Step out (F11)] of this function using the debugger and check your previous function call!")
        ShowCallstack():CallDebugger
CompilerEndIf
    EndIf
EndProcedure

MyFunction(14)
If we could get some info from the debugger callstack, we could do something like:

Code: Select all

DebuggerWarning("OUT-OF-BOUNDS ERROR at Line: "+Callstack_GetCallerLineNumber())
Would be nice for writing includes/modules. :D
Post Reply