370 lines
8.6 KiB
Plaintext
370 lines
8.6 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: Casting demo
|
|
; @Description:
|
|
;
|
|
; This batchfile demonstrates how to cast variables to other types for
|
|
; viewing. It also shows how to view memory regions as different types
|
|
; of variable.
|
|
;
|
|
; It uses a dialog to get options from the user before executing the
|
|
; appropriate commands.
|
|
;
|
|
; The script is designed to be re-entrant so it can be called again to
|
|
; run one of the sub routines and update the dialog; this prevents it
|
|
; from being forced MODAL and allows the rest of the TRACE32 interface
|
|
; to continue running.
|
|
;
|
|
; @Keywords: PRACTICE, variable formatting, casting, Dialog, WinTABS, re-entrant
|
|
; @Props: Template
|
|
; @Author: RIC
|
|
; @Copyright: (C) 1989-2021 Lauterbach GmbH, licensed for use with TRACE32(R) only
|
|
; --------------------------------------------------------------------------------
|
|
; $Id: variable_casting.cmm 17628 2021-04-23 14:26:40Z rweiss $
|
|
|
|
LOCAL &label
|
|
ENTRY %LINE &label
|
|
|
|
IF "&label"!=""
|
|
(
|
|
; If the script is called with arguments:
|
|
; DO <script> <sub-routine> [<args>]
|
|
; this bit allows for the subroutine to be called without
|
|
; running the whole script again.
|
|
LOCAL &func &args
|
|
; Strip first arg as sub routine - rest as args
|
|
&func=STRing.SPLIT("&label"," ",0.)
|
|
&args=STRing.CUT("&label",STRing.LENgth("&func"))
|
|
|
|
; Call the sub routine and quit when it's done.
|
|
GOSUB &func &args
|
|
ENDDO
|
|
)
|
|
|
|
|
|
LOCAL &typelist &ppf
|
|
; Get the full pathname of this script so we can us it later
|
|
&ppf=OS.PPF()
|
|
|
|
|
|
IF WINdow.EXIST("TypeWin01")==TRUE()
|
|
ENDDO
|
|
|
|
DIALOG.view
|
|
(&+
|
|
NAME "TypeWin01"
|
|
HEADER "Casting Memory/Variables"
|
|
ICON "[:alistvar]"
|
|
POS 0. 0. 55. 3.
|
|
BOX "Address / Expression"
|
|
POS 1. 1. 43. 1.
|
|
A1: EDIT "" ""
|
|
POS 45. 1. 3. 1.
|
|
B1: BUTTON "[:symbols]"
|
|
(
|
|
; Opens a Symbol Browser and allows for the user selection to
|
|
; execute a command. The command puts the selection into our
|
|
; EDIT field.
|
|
sYmbol.Browse * /Click "DIALOG.Set A1 ""*""" /Delete
|
|
)
|
|
POS 49. 1. 5. 1.
|
|
CB1: CHECKBOX "HLL" ""
|
|
|
|
POS 0. 3. 55. 15.
|
|
BOX "View as:"
|
|
POS 1. 4. 43. 1.
|
|
E1: EDIT "" ""
|
|
POS 45. 4. 4. 1.
|
|
B2: BUTTON "[:rightpage]"
|
|
(
|
|
LOCAL &selected
|
|
&selected=DIALOG.STRing(E1)
|
|
IF "&selected"!=""
|
|
(
|
|
DO &ppf GetTypeInfo "&selected"
|
|
WinRESIZE 112. 20.
|
|
DIALOG.Enable B3
|
|
); </if>
|
|
); </BUTTON>
|
|
POS 50. 4. 4. 1.
|
|
B3: BUTTON "[:leftpage]"
|
|
(
|
|
WinRESIZE 56. 20.
|
|
DIALOG.Disable B3
|
|
)
|
|
POS 1. 5. 53. 1.
|
|
TEXT "Double-click to select. Use button '>>' to show details."
|
|
POS 1. 6. 53. 8.
|
|
L1: LISTBOX ""
|
|
(
|
|
LOCAL &sel
|
|
&sel=DIALOG.STRing(L1)
|
|
IF "&sel"!=""
|
|
(
|
|
DIALOG.Set E1 "&sel"
|
|
; This should allow a double click to refresh the right hand
|
|
; panel if it is open.
|
|
DO &ppf GetTypeInfo "&sel"
|
|
)
|
|
)
|
|
POS 1. 14. 25. 1.
|
|
CB2: CHECKBOX "Hide types with '__'"
|
|
(
|
|
IF DIALOG.BOOLEAN(CB2)
|
|
(
|
|
; Call back into the script with arguments to get the sub-
|
|
; routine executed.
|
|
DO &ppf BuildTypeList SUPPRESS=YES
|
|
)
|
|
ELSE
|
|
(
|
|
; Call back into the script with arguments to get the sub-
|
|
; routine executed.
|
|
DO &ppf BuildTypeList SUPPRESS=NO
|
|
)
|
|
); </CHECKBOX>
|
|
POS 1. 15. 15. 1.
|
|
CB3: CHECKBOX "Use as a pointer" ""
|
|
|
|
POS 1. 16. 15. 1.
|
|
CB4: CHECKBOX "Cast as an Array of"
|
|
(
|
|
IF DIALOG.BOOLEAN(CB4)
|
|
(
|
|
DIALOG.Enable E2
|
|
)
|
|
ELSE
|
|
(
|
|
DIALOG.Disable E2
|
|
)
|
|
)
|
|
POS 17. 16. 5. 1
|
|
E2: EDIT "" ""
|
|
POS 23. 16. 10. 1.
|
|
TEXT "elements."
|
|
|
|
POS 57. 1. 55. 16.
|
|
L2: INFOTEXT "" WHite SUnken Fixed2 HScroll
|
|
|
|
POS 1. 18. 10. 1.
|
|
B4: BUTTON "[:area]Execute"
|
|
(
|
|
LOCAL &var &type &arr_cnt &ptr
|
|
&arr_cnt=""
|
|
&ptr=""
|
|
|
|
; Get data from form
|
|
&var=DIALOG.STRing(A1)
|
|
&type=DIALOG.STRing(E1)
|
|
IF DIALOG.BOOLEAN(CB3)==TRUE()
|
|
(
|
|
&ptr=" *"
|
|
)
|
|
IF DIALOG.BOOLEAN(CB4)
|
|
(
|
|
; Treat as an array so get Number of elements
|
|
&arr_cnt=DIALOG.STRing(E2)
|
|
&arr_cnt=&arr_cnt-1.
|
|
&arr_cnt="[0..&arr_cnt]"
|
|
)
|
|
IF "&arr_cnt"==""
|
|
(
|
|
Var.View (&type &ptr)&var
|
|
)
|
|
ELSE
|
|
(
|
|
Var.View %OPEN.1 ((&type *)&var)&arr_cnt
|
|
)
|
|
);</button>
|
|
POS 13. 18. 10. 1.
|
|
B5: BUTTON "[:goup]Reset"
|
|
(
|
|
DIALOG.Set A1 ""
|
|
DIALOG.Set E1 ""
|
|
DIALOG.Enable B2
|
|
DIALOG.Disable B3
|
|
WinRESIZE 56. 20. TypeWin01
|
|
DIALOG.Set CB1 FALSE()
|
|
DIALOG.Set CB2 FALSE()
|
|
DIALOG.Set CB3 FALSE()
|
|
DIALOG.Set CB4 FALSE()
|
|
DIALOG.Disable E2
|
|
)
|
|
); </DIALOG.view>
|
|
GOSUB BuildTypeList SUPPRESS=NO
|
|
WinRESIZE 56. 20. TypeWin01
|
|
DIALOG.Disable B3
|
|
DIALOG.Disable E2
|
|
|
|
;STOP
|
|
|
|
ENDDO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; Sub-Routines
|
|
;;
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; GetTypeInfo
|
|
;;
|
|
;; Args - Variable Type
|
|
;; Returns - A comma separated list of detailed information
|
|
;; Description:
|
|
;; Use sYmbol.TYPEINFO to get detailed information about a type.
|
|
;; Save this to a temporary file. Then read it back and put each line
|
|
;; into a comma separated list and load to L2
|
|
;; control.
|
|
GetTypeInfo:
|
|
ENTRY &type
|
|
LOCAL &tfile &dlist &line
|
|
|
|
&type=&type
|
|
&dlist=""
|
|
&line=""
|
|
&tfile=OS.TMPFILE()
|
|
|
|
PRinTer.FILE "&tfile"
|
|
PRinTer.FileType ASCIIE
|
|
WinPrint.sYmbol.TYPEINFO &type
|
|
&tfile="&tfile"+".lst"
|
|
|
|
; WAIT until the command has completed
|
|
; This allows for filesystem caches to be flushed before
|
|
; we try to open the file.
|
|
&cnt=0.
|
|
WHILE (!FILE.EXIST("&tfile"))&&(&cnt<100)
|
|
(
|
|
WAIT 200.ms
|
|
&cnt=&cnt+1.
|
|
); </while>
|
|
; Check to see if the count has been exceeded
|
|
IF &cnt>=100.
|
|
(
|
|
;ERROR
|
|
DIALOG.OK "TMPFILE for name does not exist. Please check &tfile."
|
|
); </if>
|
|
ELSE
|
|
(
|
|
OPEN #1 "&tfile"
|
|
;Read first two lines and throw them away
|
|
READ #1 %LINE &line
|
|
READ #1 %LINE &line
|
|
|
|
WHILE !FILE.EOF(1)
|
|
(
|
|
READ #1 %LINE &line
|
|
; Check the line is not empty
|
|
IF "&line"!=""
|
|
(
|
|
&dlist="&dlist"+"&line"+CONVert.CHAR(10.)
|
|
);</if>
|
|
);</while>
|
|
|
|
CLOSE #1
|
|
|
|
); </ELSE>
|
|
|
|
DIALOG.Set L2 "&dlist"
|
|
RETURN
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; BuildTypeList
|
|
;;
|
|
;; Args - SUPPRESS=[YES|NO]
|
|
;; Suppress any types beginning "__"
|
|
;; Returns - NONE
|
|
;; Description:
|
|
;; Use sYmbol.List.TYPE to dump a list of all types to a temporary file.
|
|
;; read the file and create a comma separated list. Apply the list to
|
|
;; LISTBOX L1.
|
|
;; Filter so that only unique entries are present.
|
|
BuildTypeList:
|
|
ENTRY %LINE &cmdline
|
|
LOCAL &tfile &tlist &line &cnt &val &oldval &suppress &skip
|
|
|
|
&suppress=STRing.SCANAndExtract("&cmdline","SUPPRESS=", "NO")
|
|
&suppress=STRing.UPpeR("&suppress")
|
|
|
|
&tlist=""
|
|
&line=""
|
|
&tfile=OS.TMPFILE()
|
|
|
|
PRinTer.FILE "&tfile"
|
|
PRinTer.FileType ASCIIE
|
|
; Use WinTABS to make sure the first column is wide enough.
|
|
; The default is to truncate at 25 characters width. We may need
|
|
; more than that for long type names,
|
|
WinTABS 50.
|
|
WinPrint.sYmbol.List.Type
|
|
&tfile="&tfile"+".lst"
|
|
|
|
; WAIT until the command has completed
|
|
; This allows for filesystem caches to be flushed before
|
|
; we try to open the file.
|
|
&cnt=0.
|
|
WHILE (!FILE.EXIST("&tfile"))&&(&cnt<100)
|
|
(
|
|
WAIT 200.ms
|
|
&cnt=&cnt+1.
|
|
); </while>
|
|
; Check to see if the count has been exceeded
|
|
IF &cnt>=100.
|
|
(
|
|
;ERROR
|
|
DIALOG.OK "TMPFILE for name does not exist. Please check &tfile."
|
|
); </if>
|
|
ELSE
|
|
(
|
|
|
|
OPEN #1 "&tfile"
|
|
|
|
;Read first two lines and throw them away
|
|
READ #1 %LINE &line
|
|
READ #1 %LINE &line
|
|
|
|
WHILE !FILE.EOF(1)
|
|
(
|
|
READ #1 %LINE &line
|
|
; Check the line is not empty
|
|
IF "&line"!=""
|
|
(
|
|
PRIVATE &tmp
|
|
|
|
; Extract the first column
|
|
&val=STRing.MID("&line",0.,49.)
|
|
; Trim any white space
|
|
&val=STRing.TRIM("&val")
|
|
|
|
&tmp=STRing.MID("&val",0.,3.)
|
|
IF "&suppress"=="YES"&&STRing.SCAN("&tmp","__",0.)!=-1
|
|
(
|
|
;Null block
|
|
)
|
|
ELSE
|
|
(
|
|
IF STRing.LENgth("&tlist")<=0.
|
|
(
|
|
&tlist="&val"
|
|
&oldval="&val"
|
|
)
|
|
ELSE
|
|
(
|
|
IF "&oldval"!="&val"
|
|
&tlist="&tlist"+","+"&val"
|
|
&oldval="&val"
|
|
); </else>
|
|
); </else>
|
|
) ;</if>
|
|
); </while>
|
|
CLOSE #1
|
|
); </else>
|
|
|
|
DIALOG.Set L1 "" "&tlist"
|
|
RETURN "&tlist"
|