home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / loadmap.icn < prev    next >
Text File  |  2000-07-29  |  4KB  |  145 lines

  1. ############################################################################
  2. #
  3. #    File:     loadmap.icn
  4. #
  5. #    Subject:  Program to show load map of UNIX object file
  6. #
  7. #    Author:   Stephen B. Wampler
  8. #
  9. #    Date:     December 13, 1985
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program produces a formatted listing of selected symbol classes
  18. #  from a compiled file.  The listing is by class, and gives the
  19. #  name, starting address, and length of the region associated with
  20. #  each symbol.
  21. #  
  22. #     The options are:
  23. #  
  24. #      -a Display the absolute symbols.
  25. #  
  26. #      -b Display the BSS segment symbols.
  27. #  
  28. #      -c Display the common segment symbols.
  29. #  
  30. #      -d Display the data segment symbols.
  31. #  
  32. #      -t Display the text segment symbols.
  33. #  
  34. #      -u Display the undefined symbols.
  35. #  
  36. #  If no options are specified, -t is assumed.
  37. #  
  38. #  If the address of a symbol cannot be determined, ???? is given in
  39. #  its place.
  40. #  
  41. ############################################################################
  42. #  
  43. #  Notes:
  44. #
  45. #     The size of the last region in a symbol class is suspect and is
  46. #  usually given as rem.
  47. #  
  48. #     Output is not particularly exciting on a stripped file.
  49. #  
  50. ############################################################################
  51. #
  52. #  Requires: UNIX
  53. #
  54. ############################################################################
  55.  
  56. record entry(name,address)
  57.  
  58. procedure main(args)
  59.    local maptype, arg, file, nm, ldmap, tname, line, text, data, bss
  60.    local SPACE, COLON, DIGITS, HEXDIGITS, usize, address, name, nmtype
  61.    initial {
  62.       if *args = 0 then stop("usage: loadmap [-t -d -b -u -a -c -l] file")
  63.       SPACE := '\t '
  64.       COLON := ':'
  65.       DIGITS := '0123456789'
  66.       HEXDIGITS := DIGITS ++ 'abcdef'
  67.       ldmap := table(6)
  68.       ldmap["u"] := []
  69.       ldmap["d"] := []
  70.       ldmap["a"] := []
  71.       ldmap["b"] := []
  72.       ldmap["t"] := []
  73.       ldmap["c"] := []
  74.       tname := table(6)
  75.       tname["u"] := "Undefined symbols"
  76.       tname["a"] := "Absolute locations"
  77.       tname["t"] := "Text segment symbols"
  78.       tname["d"] := "Data segment symbols"
  79.       tname["b"] := "BSS segment symbols"
  80.       tname["c"] := "Common symbols"
  81.       nmtype := "nm -gno "
  82.       }
  83.    maptype := ""
  84.    every arg := !args do
  85.       if arg[1] ~== "-" then file := arg
  86.       else if arg == "-l" then nmtype := "nm -no "
  87.       else if arg[1] == "-" then maptype ||:= (!"ltdbuac" == arg[2:0]) |
  88.          stop("usage:  loadmap [-t -d -b -u -a -c -l] file")
  89.    maptype := if *maptype = 0 then "t" else string(cset(maptype))
  90.    write("\n",file,"\n")
  91.    usize := open("size " || file,"rp") | stop("loadmap: cannot execute size")
  92.    !usize ? {
  93.       writes("Text space: ",right(text := tab(many(DIGITS)),6),"   ")
  94.       move(1)
  95.       writes("Initialized Data: ",right(data := tab(many(DIGITS)),6),"   ")
  96.       move(1)
  97.       write("Uninitialized Data: ",right(bss := tab(many(DIGITS)),6))
  98.       }
  99.    close(usize)
  100.    nm := open(nmtype || file,"rp") | stop("loadmap: cannot execute nm")
  101.    every line := !nm do
  102.       line ? {
  103.          tab(upto(COLON)) & move(1)
  104.          address := integer("16r" || tab(many(HEXDIGITS))) | "????"
  105.          tab(many(SPACE))
  106.          type := map(move(1))
  107.          tab(many(SPACE))
  108.          name := tab(0)
  109.          if find(type,maptype) then put(ldmap[type],entry(name,address))
  110.          }
  111.    every type := !maptype do {
  112.       if *ldmap[type] > 0 then {
  113.          write("\n\n\n")
  114.          write(tname[type],":")
  115.          write()
  116.          show(ldmap[type],(type == "t" & text) |
  117.             (type == "d" & data) | (type == "b" & bss) | &null,
  118.             ldmap[type][1].address)
  119.          }
  120.       }
  121. end
  122.  
  123. procedure show(l,ssize,base)
  124.    local i1, i2, nrows
  125.    static ncols
  126.    initial ncols := 3
  127.    write(repl(repl(" ",3) || left("name",9) || right("addr",7) ||
  128.       right("size",6),ncols))
  129.    write()
  130.    nrows := (*l + (ncols - 1)) / ncols
  131.    every i1 := 1 to nrows do {
  132.       every i2 := i1 to *l by nrows do
  133.          writes(repl(" ",3),left(l[i2].name,9),right(l[i2].address,7),
  134.             right(area(l[i2 + 1].address,l[i2].address) |
  135.             if /ssize then "rem" else base + ssize - l[i2].address,6))
  136.          write()
  137.          }
  138.    return
  139. end
  140.  
  141. procedure area(high,low)
  142.    if integer(low) & integer(high) then return high - low
  143.    else return "????"
  144. end
  145.