It is currently Thu Feb 20, 2020 3:04 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: DebugCallingPosition()
PostPosted: Sun Jul 30, 2017 8:58 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
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:
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)"


Top
 Profile  
Reply with quote  
 Post subject: Re: DebugCallingPosition()
PostPosted: Sun Jul 30, 2017 9:55 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3758
Location: Berlin, Germany
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?

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: DebugCallingPosition()
PostPosted: Mon Jul 31, 2017 1:15 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3618
Location: Utah, USA
In accordance with Little John's suggestion:

Code:
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)

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: DebugCallingPosition()
PostPosted: Mon Jul 31, 2017 10:49 am 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1074
Location: Russia
GPI wrote:
should output "file at line xyz"
It is necessary?
Code:
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)

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: DebugCallingPosition()
PostPosted: Mon Jul 31, 2017 2:42 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
this will report the line with the debug. But it should reference to the line "test(0)".


Top
 Profile  
Reply with quote  
 Post subject: Re: DebugCallingPosition()
PostPosted: Mon Jul 31, 2017 4:11 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3758
Location: Berlin, Germany
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.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: DebugCallingPosition()
PostPosted: Sun Nov 17, 2019 6:44 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2942
Location: Planet Earth
Today I was looking for something like this as well:
Code:
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:
DebuggerWarning("OUT-OF-BOUNDS ERROR at Line: "+Callstack_GetCallerLineNumber())


Would be nice for writing includes/modules. :D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye