; --------------------------------------------------------------------------------
; @Title: Core File Autoload Script
; @Description: 
; Autoloader script for loading shared objects by the Data.LOAD.CORE command
; @Author: KJM
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: autoload.cmm 12575 2018-05-08 08:47:15Z msamet $ 

// define local macros
 LOCAL &filename &basename &progname &symfilename &filepath &code &data &space

// get filename and relocation information
 // these parameters are passed from TRACE32 when calling this skript
 
 ENTRY &filename &type &code &data &space
 
 // &filename:      name of process/file
 // &type:          type of file: 1=process, 2=library
 // &code:          text segment address
 // &data:          data segment address
 
// get symbol file name and program name
 &basename=STRing.CUT(&filename,-STRing.LENgth(OS.FILE.EXTENSION(&filename)))
 IF (&type==1)
   &symfilename="&basename"
 IF (&type==2)
   &symfilename="&basename"+".so"
 &progname=OS.FILE.NAME("&basename")

// delete symbols if they already exist
 IF sYmbol.EXIST("\\&progname")
   sYmbol.Delete \\&progname
 GROUP.Delete "&progname"

// search file in source search path and open dialog when not there
 &filepath=sYmbol.SEARCHFILE("&symfilename")
 IF !OS.FILE("&filepath")
 (
   LOCAL &file
   &file=OS.FILE.NAME("&symfilename")
   WinPOS ,,,,,, filebox normal "Searching symbols for &filename"
   DIALOG.File "*\&file"
   ENTRY %LINE &filepath
   IF "&filepath"==""
     ENDDO
 )

// load symbol file (options for sourcepath, e.g. /STRIPPART may need to be added when required)

 IF (&type==1)  // processes
 (
   Data.LOAD.Elf "&filepath" /NoCODE /NoClear /LOCATEAT &code
   GROUP.Create "&progname" sYmbol.SECRANGE(\\&progname\.text) /GREEN
 )
 
 IF ((&type&0xffff)==2) // libraries
 (
   Data.LOAD.Elf &filepath &code /NoCODE /NoClear
 )
 
 ENDDO

