It is currently Sat May 25, 2013 2:26 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Figuring out where a function is called
PostPosted: Tue Apr 01, 2008 9:09 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Mon Jun 02, 2003 1:42 am
Posts: 2013
Location: Ashland, KY
From inside a procedure at runtime is it possible to somehow output the line of code that called the procedure?

Example :

Code:
Line 147 : testme()

Procedure testme()

    debug "testme() is called on line " + str(exe_line)

EndProcedure


Would output "147"..

Reason being - I'm seeing calls to a function and just can't seem to figure out where it's being called (and why!).

_________________
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 11:54 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Jan 02, 2007 8:16 pm
Posts: 4328
Location: Cypress TX
Karbon

Simple... make the line that called the procedure part of the call to that procedure.

Code:
Procedure Something(Line$)
Debug "Called from line: "+Line$
; other stuff
Endprocedure


And then if you didn't tell whatever pointer to call that procedure... you will get a bad call at line...

OR

Use the Edit Menu to search for where you call the procedure...

OR

Use a combo of those two ideas to edit the procedure calls by finding the lines and then editing the call...

8)

_________________
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 12:05 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5188
Location: Germany
Place a breakpoint in the procedure and open the 'Callstack' debugger tool once it is reached.
There you can see it all.

_________________
Perl – The only language that looks the same before and after RSA encryption.
-- Keith Bostic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 12:14 am 
Offline
User
User
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 39
Location: Germany, Homburg (Saar)
If you don't use Threads and you procedure has no result, use this:
Code:
;add a global value for the line
Global exe_line.l

;rename the procedure
Procedure testme_renamed(a.l, b.l)
  Debug "testme() is called on line " + Str(exe_line)
  Debug a
  Debug b
EndProcedure

;create a original named macro
Macro testme
  exe_line = #PB_Compiler_Line : testme_renamed
EndMacro

testme(1, 2)

testme(3, 4)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 3:19 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Mon Jun 02, 2003 1:42 am
Posts: 2013
Location: Ashland, KY
Thanks guys!

_________________
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 12:11 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 442
Location: ger
Code:
Procedure.s foo_proc(param1, param2opt, called_at=-1)
  ; procedure-code
  Debug "called at line "+Str(called_at)
  Debug param1
  Debug param2opt
  ProcedureReturn "returnvalue"
  ; [..]
 
 
  ; call-wrapper
  Macro foo(p1,p2=123)
    foo_proc(p1,p2,#PB_Compiler_Line)
  EndMacro
EndProcedure


Debug foo(8,5)
Debug ""
Debug foo(44)

..but notice that you have to define optional parameters in the macro instead.


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 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