I've used GPC on the Mac a little bit, and here are my tricks for debugging it using GDB (aka: XCode's Debugger Console).
Viewing Value of Str255s
XCode's debugging interface doesn't show the value of strings in Pascal. Luckily, we have the Debugging Console to give us Under The Hood power.
In this case we want to view the value (aka: the string) of a Str255. XCode's Variable/Value screen is mostly worthless here, showing us (if we're lucky) the address of the string. Not what we want.
What follows are two user defined GDB functions that you can use from the Debugging Console. I suggest you create a .gdbint file in your home directory and paste these two commands into it.
Usage (debugging PROCEDURE something(const npw: Str255); )
(gdb) constpst Npw $N = "bob"
Usage (debugging PROCEDURE something(var npw: Str255); )
(gdb) varpst Npw $N = "bob"
Yes, you have to make sure you're using the right function for the right type of variable. Sadly I can't find a way to automatically determine which one to use. Also if you have a plain Str255 (that is called from another Pascal function) you should be able to use constpst.
There's a GDB command: help user-defined that will print out the document strings in your .gdbinit file, if you need a refresher on which one to use.
If you use the wrong one you'll get garbage out!! (Not that it really hurts, but you may end up going on a wild goose hunt wondering why your variable isn't getting passed in correctly).
define CONSTpst
set $strlen = (UInt16)(((char*)($arg0))[0])
if ($strlen)
print ( ((char*)($arg0))[1]@$strlen )
else
print "string is empty"
end
end
document CONSTpst
Print out a CONST 0;pascal string
end
define VARpst
set $strlen = (UInt16)(((char*)(&$arg0))[0])
if ($strlen)
print ( ((char*)(&$arg0))[1]@$strlen )
else
print "string is empty"
end
end
document VARpst
print out a Pascal string passed by reference (VAR)
end
Comments:
Add comments by visiting: GDB/GPC/Comments