Page 1 of 1

DebugCallingPosition()

Posted: Sun Jul 30, 2017 8:58 pm
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)"

Re: DebugCallingPosition()

Posted: Sun Jul 30, 2017 9:55 pm
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?

Re: DebugCallingPosition()

Posted: Mon Jul 31, 2017 1:15 am
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)

Re: DebugCallingPosition()

Posted: Mon Jul 31, 2017 10:49 am
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)

Re: DebugCallingPosition()

Posted: Mon Jul 31, 2017 2:42 pm
by GPI
this will report the line with the debug. But it should reference to the line "test(0)".

Re: DebugCallingPosition()

Posted: Mon Jul 31, 2017 4:11 pm
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.

Re: DebugCallingPosition()

Posted: Sun Nov 17, 2019 6:44 am
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