-
Notifications
You must be signed in to change notification settings - Fork 140
Debugging macros using pdb
If you want to debug a .py
macro at FreeCAD the pdb debugger is the easiest way.
It works at once without any tricks and wows.
You have just to put the "import pdb
" command at the beginning of the .py
file and next invoke the debugger at the line you wish.
There are many ways for that.
The simplest is by using the "pdb.set_trace()
" command at the wished line.
When the program execution reaches this line it stops and you have at your disposal a variety of commands:
Like "c
" to continue running the program, "s
" or "n
" to execute the next line etc.
Also you can type a variable name at python console and see its value at ReportView.
There is a very good help about debugger usage and commands - see below.
Three tips.
- Do not use a variable with name "c". The pdb debugger confuse the variable with the command "c" and gets crazy. Period.
- Command:"
unt [lineno]
". Use it without "[ ]" e.g.unt 35
= execute all lines until line number 35.unt [35]
simply gives an error. - If you have reached at least one "
pdb.set_trace()
" or similar command: At the end of program running be sure that you are out of pdb BEFORE exiting FreeCAD. Always use the pdb command "q
" or "quit
" before exiting from FreeCAD. If you disobey this rule you will be punished with a black FreeCAD GUI or frozen FreeCAD or even frozen operating system!
There is a very useful post about pdb debugger by @ediloren. The help is well written and you find it at: https://docs.python.org/3/library/pdb.html.
Original post from user manos on FreeCAD's forum.