; --------------------------------------------------------------------------------
; @Title: Script to load libraries for GDB Run Mode
; @Description:
;  This script get the library relocation address from the maps file on the target
;  and loads the shared library symbols with this offset. Returns -1 if not found.
;  usage: DO getmaps.cmm <pid> <lib_name>
; @Author: KJM
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: getmaps.cmm 15147 2019-10-22 17:16:34Z rweiss $

LOCAL &pid &lib
ENTRY &pid &lib

LOCAL &offset &tmpfile
&offset=-1
&tmpfile=OS.TMPFILE()+"maps.&pid"

TASK.COPYUP /proc/&pid/maps "&tmpfile"

OPEN #1 "&tmpfile" /Read
RePeaT
(
  LOCAL &mapsline
  READ #1 %line &mapsline
  IF EOF()
    GOTO endloop
  IF STRing.SCAN("&mapsline","&lib",0)!=-1
  (
    LOCAL &tmp
    &tmp=STRing.SCAN("&mapsline","-",0)
    &offset=STRing.MID("&mapsline",0,&tmp)
    &offset="0x"+"&offset"
    GOTO endloop
  )
)
endloop:
CLOSE #1
DEL "&tmpfile"
ENDDO &offset
