Take subroutines from the Deployed Mode Routine
Hello Community,
Is it possible to retrieve/find all the names of subroutines, procedures, or functions from a deployed routine?. in the routine below, how can I extract names like x2 and execsql? I’ve just tried using openId on %RoutineMgr but it didn’t help.
xdeploy.mac
xdeploy
quit
x2 ; test1
write 123
q
execsql(sql) ; test2
Set tResult = ##Class(%SQL.Statement).%ExecDirect(,sql)
Return tResult
Thanks
Comments
It is not possible to retrieve the names of subroutines/functions from a routine in deployed mode. One source states that for pure routines, this is “an almost impossible attempt,” and another explicitly says of deployed code: “nowhere. It's the purpose of deployed code not to be hacked nor debugged.” [1][2]
The practical workaround shown for non-deployed source routines is to open the .mac routine with %RoutineMgr, read it line by line, and parse label lines yourself. The example does this by:
- opening the routine with
%RoutineMgr.%OpenId(routine_".mac") - reading each line from
rtn.Code - skipping lines that begin with tab/space/# or that do not contain
" ; " - extracting the label name from the first token, and stripping parameters with
$Piece(...,"(")[1]
In that example, the relevant parsing logic is: [1]
Set rtn = ##class(%RoutineMgr).%OpenId(routine_".mac")
Quit:'$IsObject(rtn)
Set menu = ""
While 'rtn.Code.AtEnd {
Set line = rtn.Code.ReadLine()
Continue:$Char(9,32,35)[$Extract(line)
Continue:line'[" ; "
Set label = $Piece($Piece(line, " "), "(")
Set title = $Piece(line, " ; ", 2, *)
Set menu = menu _ $Listbuild($Listbuild(label, title))
}
Applied to your sample source routine, this kind of parsing would identify labels such as x2 and execsql from the routine text, but only if the source text is available to read; the retrieved material does not provide a supported way to do this from deployed code itself. [1][2]
Note: This might not work with deployed code and even if it does will likely not provide any details of the deployed programs. Hopefully it will at least show an entry for the deployed routine so you can see what is being called. [2]
Sources: