[comp.sys.mac.programmer] dump virtual method table C++

Reid Ellis <rae@utcs.toronto.edu> (02/21/91)

Due to popular demand, here's my SADE proc to dump virtual method
tables.  You have to hand it a standard SADE-type list of "__vptr"
variables [i.e. no spaces, and commas as separators], like this:

dv View^.__vptr,View^.__OPort.__vptr,View^.__OPort.__PPerformer^.__vptr

Enjoy!
					Reid
---
proc dv
	define i
	define ptr

	for i:=1 to NArgs do
		#
		# skip first zero entry in the table
		# [each entry is 8 bytes]
		#
		ptr := ^__mtab(Arg[i]+8)
		#
		# end of table is marked by a zero "f" pointer
		#
		while ptr^.f != 0
			printf "\t%2d %2d ", ptr^.d, ptr^.i
			#
			# this [slow] part figures out the name of the func
			# pointed to by ptr^.f.  If you don't care
			# about the name, replace the if statement with
			# its if clause [printf "%8X\n", ptr^.f], which
			# prints out the address of the function in hex.
			#
			name = where(ptr^.f)
			if length(name) = 0 then
				printf "%8X\n", ptr^.f
			else
				printf "%t\n", where(ptr^.f)
			end
		end
	end
end

--
Reid Ellis  176 Brookbanks Drive, Toronto ON, M3A 2T5 Canada
rae@utcs.toronto.edu        ||  rae%alias@csri.toronto.edu
CDA0610@applelink.apple.com ||             +1 416 446 1644