home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / MachOViewer / Source / RCS / MachOView.m,v < prev    next >
Encoding:
Text File  |  1994-05-29  |  57.7 KB  |  2,790 lines

  1. head     1.18;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ediger:1.18;
  6. comment  @@;
  7.  
  8.  
  9. 1.18
  10. date     94.05.29.15.00.14;  author ediger;  state Exp;
  11. branches ;
  12. next     1.17;
  13.  
  14. 1.17
  15. date     94.05.28.16.17.55;  author ediger;  state Exp;
  16. branches ;
  17. next     1.16;
  18.  
  19. 1.16
  20. date     94.05.26.21.21.06;  author ediger;  state Exp;
  21. branches ;
  22. next     1.15;
  23.  
  24. 1.15
  25. date     94.05.23.20.32.13;  author ediger;  state Exp;
  26. branches ;
  27. next     1.14;
  28.  
  29. 1.14
  30. date     94.05.17.23.09.48;  author ediger;  state Exp;
  31. branches ;
  32. next     1.13;
  33.  
  34. 1.13
  35. date     94.05.10.22.41.07;  author ediger;  state Exp;
  36. branches ;
  37. next     1.12;
  38.  
  39. 1.12
  40. date     94.05.04.11.19.58;  author ediger;  state Exp;
  41. branches ;
  42. next     1.11;
  43.  
  44. 1.11
  45. date     94.05.03.10.20.01;  author ediger;  state Exp;
  46. branches ;
  47. next     1.10;
  48.  
  49. 1.10
  50. date     94.05.01.17.32.57;  author ediger;  state Exp;
  51. branches ;
  52. next     1.9;
  53.  
  54. 1.9
  55. date     94.02.07.21.37.17;  author ediger;  state Exp;
  56. branches ;
  57. next     1.8;
  58.  
  59. 1.8
  60. date     94.01.30.21.30.19;  author ediger;  state Exp;
  61. branches ;
  62. next     1.7;
  63.  
  64. 1.7
  65. date     94.01.30.16.27.34;  author ediger;  state Exp;
  66. branches ;
  67. next     1.6;
  68.  
  69. 1.6
  70. date     94.01.01.23.02.22;  author ediger;  state Exp;
  71. branches ;
  72. next     1.5;
  73.  
  74. 1.5
  75. date     93.12.31.17.32.28;  author ediger;  state Exp;
  76. branches ;
  77. next     1.4;
  78.  
  79. 1.4
  80. date     93.12.31.16.58.01;  author ediger;  state Exp;
  81. branches ;
  82. next     1.3;
  83.  
  84. 1.3
  85. date     93.12.30.19.01.37;  author ediger;  state Exp;
  86. branches ;
  87. next     1.2;
  88.  
  89. 1.2
  90. date     93.12.19.14.31.43;  author ediger;  state Exp;
  91. branches ;
  92. next     1.1;
  93.  
  94. 1.1
  95. date     93.12.19.12.57.04;  author ediger;  state Exp;
  96. branches ;
  97. next     ;
  98.  
  99.  
  100. desc
  101. @A Subclass of View that knows somewhat about Mach-O files,
  102. and how to show a graphic representation of a Mach-O file in core.
  103. @
  104.  
  105.  
  106. 1.18
  107. log
  108. @zero out a memory allocation to make it clear it's unused
  109. @
  110. text
  111. @
  112. #import <MachOView.h>
  113.  
  114. /* $Log:    MachOView.m,v $
  115. Revision 1.17  94/05/28  16:17:55  ediger
  116. finally got section names to draw acceptably.
  117.  
  118. Revision 1.16  94/05/26  21:21:06  ediger
  119. correct address bracket zooming, hi and lo address bracket checking
  120.  
  121. Revision 1.15  94/05/23  20:32:13  ediger
  122. lot's o' stuff to do address bracket zoom-in
  123.  
  124. Revision 1.14  94/05/17  23:09:48  ediger
  125. support for stacking of zoomed address ranges, changed types of
  126. some instance vars from id to pointer to that kind of object.
  127.  
  128. Revision 1.13  94/05/10  22:41:07  ediger
  129. support for displaying a "zooming box" by mouse drag
  130.  
  131. Revision 1.12  94/05/04  11:19:58  ediger
  132. rearrange drawSelf:: to be a bit more modular
  133.  
  134. Revision 1.10  94/05/01  17:32:57  ediger
  135. efficiency improvements
  136.  
  137. Revision 1.9  94/02/07  21:37:17  ediger
  138. Use of memory-mapped file object to manage file mapping,
  139. add display of segment names and use of matrix of buttons
  140. for choices of what to display.
  141.  
  142. Revision 1.7  94/01/30  16:27:34  ediger
  143. mostly correct address spacing
  144.  
  145. Revision 1.6  94/01/01  23:02:22  ediger
  146. broke address label spacing calcs into separate method.
  147.  
  148. Revision 1.5  93/12/31  17:32:28  ediger
  149. better address label spacing
  150.  
  151. Revision 1.3  93/12/30  19:01:37  ediger
  152. support for showing upper and lower addresses
  153. of memory mapped segments.
  154.  
  155. Revision 1.2  93/12/19  14:31:43  ediger
  156. corrected scaling and inclusion of mapped segments of library files
  157.  
  158. Revision 1.1  93/12/19  12:57:04  ediger
  159. Initial revision
  160.  
  161.  */
  162.  
  163. @@implementation MachOView
  164.  
  165. static char rcsident[] = "$Id: MachOView.m,v 1.17 94/05/28 16:17:55 ediger Exp Locker: ediger $";
  166.  
  167. #undef DEBUG
  168. #ifdef DEBUG
  169. #define D(c) c
  170. #define ENTER(m) fprintf(stderr, "enter %s\n", m);
  171. #define EXIT(m) fprintf(stderr, "exit %s\n", m);
  172. #else
  173. #define D(c)
  174. #define ENTER(m)
  175. #define EXIT(m)
  176. #endif
  177.  
  178. //M+    -findSizes
  179. //    PURPOSE:
  180. //        Sort through the addresses of the mapped segments in the Mach-O file
  181. //        to be represented, determining the high address, low address, and
  182. //        the number of bytes used in the address space.
  183. //
  184. //    EDITORIAL:
  185. //        Should only be called after using MachOFile instance var to
  186. //        open or re-open the Mach-O file being represented.
  187. //M-
  188. - findSizes
  189. {
  190.     int iSegments, iCC;
  191.     unsigned long ulBaseAddr, ulUpperAddr;
  192.     char bvBuf[64];
  193.  
  194.     ENTER("- findSizes");
  195.  
  196.     loAddr = (unsigned long)-1;  /* cheat */
  197.     sumAddr = hiAddr = 0;
  198.  
  199.     iSegments = [theFile mappedSegments];
  200.  
  201.     for (iCC = 0; iCC < iSegments; ++iCC)
  202.     {    id oSegment = [theFile mappedSegment:iCC];
  203.  
  204.         ulBaseAddr = [oSegment getBaseAddress];
  205.         if (loAddr > ulBaseAddr) loAddr = ulBaseAddr;
  206.         ulUpperAddr = [oSegment getUpperAddress];
  207.         if (hiAddr < ulUpperAddr) hiAddr = ulUpperAddr;
  208.         sumAddr += (ulUpperAddr - ulBaseAddr);
  209.     }
  210.  
  211.     sprintf(bvBuf, "0x%x", loAddr);
  212.     [minAddress setStringValue:bvBuf];
  213.     sprintf(bvBuf, "0x%x", hiAddr);
  214.     [maxAddress setStringValue:bvBuf];
  215.  
  216.     EXIT("- findSizes");
  217.     return self;
  218. }
  219.  
  220. //M+    -(char *)fileType
  221. //M-
  222. - (char *)fileType
  223. {
  224.     return [theFile fileType];
  225. }
  226.  
  227. //M+    -openFileNamed:(char *)fileName
  228. //
  229. //M-
  230. - openFileNamed:(char *)fileName
  231. {
  232.     ENTER("- openFileNamed:");
  233.     assert(NULL != fileName);
  234.  
  235.     [self freeInternals];
  236.  
  237.     currentFileName = strcpy(malloc(strlen(fileName) + 1), fileName);
  238.  
  239.     mappedFile = [[[MappedFile alloc] init] filename:currentFileName];
  240.     if (mappedFile == NULL || [mappedFile map] == FALSE)
  241.     {    [cpuType    setStringValue:"Problem opening"];
  242.         [cpuSubtype setStringValue:currentFileName];
  243.  
  244.     } else {
  245.         theFile = [[[MachOFile alloc]init]
  246.             fillFromAddress:[mappedFile address]];
  247.         if (NULL == theFile)
  248.         {    [cpuType    setStringValue:"Not a"];
  249.             [cpuSubtype setStringValue:"Mach-O file"];
  250.         } else {
  251.             int iSegments = [theFile mappedSegments];
  252.             addressMap = (struct addressMapping *)malloc(
  253.                 iSegments * sizeof(struct addressMapping));
  254.             bzero(addressMap, iSegments * sizeof(struct addressMapping));
  255.             [cpuType    setStringValue:[theFile cpuType]];
  256.             [cpuSubtype setStringValue:[theFile cpuSubtype]];
  257.             [[self findSizes] display];
  258.         }
  259.     }
  260.  
  261.     EXIT("- openFileNamed:");
  262.     return self;
  263. }
  264.  
  265. //M+    -toggleScaling:sender
  266. //    Action called by clicking on a button.  Changes the "toScale" instance
  267. //    variable, and calls -display, to reflect the change.
  268. //M-
  269. - toggleScaling:sender
  270. {
  271.     if (toScale)
  272.     {
  273.         toScale = FALSE;
  274.         showSectionNames  = FALSE;
  275.         [showSectionsButton setEnabled:NO];
  276.         [showSectionsButton setIntValue:0];
  277.  
  278.     } else {
  279.         toScale = TRUE;
  280.         [showSectionsButton setEnabled:YES];
  281.         [showSectionsButton setIntValue:0];
  282.     }
  283.  
  284.     [self display];
  285.  
  286.     return self;
  287. }
  288.  
  289.  
  290. //M+    -toggleAddresses:sender
  291. //    Action called by clicking on a button.  Changes the "showAddresses"
  292. //    instance variable, and calls -display, to reflect the change.
  293. //M-
  294. - toggleAddresses:sender
  295. {
  296.     if (showAddresses)
  297.         showAddresses  = FALSE;
  298.     else
  299.         showAddresses  = TRUE;
  300.  
  301.     [self display];
  302.  
  303.     return self;
  304. }
  305.  
  306. //M+    -toggleNames:sender
  307. //    Action called by clicking on a button.  Changes the "showNames"
  308. //    instance variable, and calls -display, to reflect the change.
  309. //M-
  310. - toggleNames:sender
  311. {
  312.     if (showNames)
  313.         showNames  = FALSE;
  314.     else
  315.         showNames  = TRUE;
  316.  
  317.     [self display];
  318.  
  319.     return self;
  320. }
  321.  
  322. //M+    -toggleThreads:sender
  323. //    Action called by clicking on a button.  Changes the "showThreads"
  324. //    instance variable, and calls -display, to reflect the change.
  325. //M-
  326. - toggleThreads:sender
  327. {
  328.     if (showThreads)
  329.         showThreads  = FALSE;
  330.     else
  331.         showThreads  = TRUE;
  332.  
  333.     [self display];
  334.  
  335.     return self;
  336. }
  337.  
  338. //M+    -toggleSections:sender
  339. //    Action called by clicking on a button.  Changes the "showSectionNames"
  340. //    instance variable, and calls -display, to reflect the change.
  341. //M-
  342. - toggleSections:sender
  343. {
  344.     int iSegments, iCC;
  345.  
  346.     if (showSectionNames)
  347.         showSectionNames  = FALSE;
  348.     else
  349.         showSectionNames  = TRUE;
  350.  
  351.     iSegments = [theFile mappedSegments];
  352.  
  353.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  354.     {
  355.         int             i;
  356.         SegmentCommand *oSegment  = [theFile mappedSegment:iCC];
  357.         int             iSection  = [oSegment numberOfSections];
  358.         struct section *spSection = [oSegment getSection:0];
  359.  
  360.         if (iSection > 0)
  361.         {
  362.             if (addressMap[iCC].sectionMap == NULL)
  363.                 addressMap[iCC].sectionMap =
  364.                     (struct sectionNameMapping *)malloc(
  365.                         iSection*sizeof(struct sectionNameMapping));
  366.  
  367.             assert(addressMap[iCC].sectionMap != NULL);
  368.  
  369.             for (i = 0; i < iSection; ++i)
  370.             {
  371.                 addressMap[iCC].sectionMap[i].sectionName
  372.                     = spSection[i].sectname;
  373.                 addressMap[iCC].sectionMap[i].sectionAddress
  374.                     = spSection[i].addr;
  375.             }
  376.  
  377.         } else
  378.             addressMap[iCC].sectionMap = NULL;
  379.     }
  380.  
  381.     [self display];
  382.  
  383.     return self;
  384. }
  385.  
  386. //M+    -toggleLibraries:sender
  387. //    PURPOSE:
  388. //    Action called by clicking on a button.  Changes the "showLibraries"
  389. //    instance variable, and calls -display, to reflect the change.
  390. //    EDITORIAL:
  391. //    Somewhat more elaborate than the other -toggle* methods, since the
  392. //    Mach-O file object instance variable gets completely redone.  This
  393. //    may be a case of bad design of the MachOFile object percolating up
  394. //    to here.
  395. //M-
  396. - toggleLibraries:sender;
  397. {
  398.     if (theFile != NULL)
  399.         [theFile free];
  400.     theFile = [[MachOFile alloc] init];
  401.  
  402.     if (NULL != addressMap)
  403.     {
  404.         int iSegments = [theFile mappedSegments];
  405.         while (--iSegments > -1)
  406.             if (addressMap[iSegments].sectionMap)
  407.                 free(addressMap[iSegments].sectionMap);
  408.  
  409.         free(addressMap);
  410.         addressMap = NULL;
  411.     }
  412.  
  413.     if (showLibraries)
  414.     {
  415.         showLibraries = FALSE;
  416.         [theFile unconsiderMappedFiles];
  417.     } else {
  418.         showLibraries = TRUE;
  419.         [theFile considerMappedFiles];
  420.     }
  421.  
  422.     [theFile fillFromAddress:[mappedFile address]];
  423.  
  424.     addressMap = (struct addressMapping *)malloc(
  425.         [theFile mappedSegments] * sizeof(struct addressMapping));
  426.     bzero(addressMap, [theFile mappedSegments] * sizeof(struct addressMapping));
  427.  
  428.     // since the MachOFile object has been redone, zoom state is meaningless.
  429.     if (NULL != zoomStack)
  430.     {
  431.         void *vp;
  432.  
  433.         while ((vp = [zoomStack pop]) != NULL)
  434.             free(vp);
  435.     }
  436.     [unzoomButton setEnabled:NO];
  437.     [zoomButton   setEnabled:NO];
  438.  
  439.     [[self findSizes] display];
  440.  
  441.     return self;
  442. }
  443.  
  444. //M+    -windowWillClose:sender
  445. //    PURPOSE:
  446. //        Ditch any memory-consuming instance vars when the window closes.
  447. //    EDITORIAL:
  448. //        one of the Window delegate methods
  449. //M-
  450. - windowWillClose:sender
  451. {
  452.     ENTER("- windowWillClose:");
  453.     [self freeInternals];
  454.     [zoomStack free];
  455.     EXIT("- windowWillClose:");
  456.     return self;
  457. }
  458.  
  459. //M+    -rescale
  460. //    PURPOSE:
  461. //        calculate the scaling instance vars
  462. //M-
  463. - rescale
  464. {
  465.     float ht;
  466.     ENTER("- rescale");
  467.  
  468.     ht = NX_HEIGHT(&bounds) - 25.0;
  469.  
  470.     scaleSlope      = ht/(float)(hiAddr - loAddr);
  471.     scaleYintercept = 5.0 - scaleSlope*(float)loAddr;
  472.  
  473.     smashedSlope      = ht/(float)sumAddr;
  474.     smashedYintercept = 0.0;
  475.  
  476.     EXIT("- rescale");
  477.     return self;
  478. }
  479.  
  480.  
  481. //M+    -initFrame:(const NXRect *)frameRect
  482. //    PURPOSE:
  483. //        Set a bunch of instance variables to some sensible values.
  484. //
  485. //    EDITORIAL:
  486. //        Override of a View method
  487. //M-
  488. - initFrame:(const NXRect *)frameRect
  489. {
  490.     ENTER("- initFrame:");
  491.     [super initFrame:frameRect];
  492.  
  493.     toScale       = TRUE;
  494.     showLibraries = FALSE;
  495.     showAddresses = TRUE;
  496.     showNames     = TRUE;
  497.     showThreads   = TRUE;
  498.     showSectionNames = FALSE;
  499.  
  500.     currentFileName = NULL;
  501.     addressMap      = NULL;
  502.     mappedFile      = NULL;
  503.     theFile         = NULL;
  504.     zoomStack = [[Queue alloc] init];
  505.  
  506.     theFont = [Font newFont:"Courier" size:(float)(LABEL_HT - LABEL_LEADING)
  507.         matrix:NX_IDENTITYMATRIX];
  508.  
  509.  
  510.     EXIT("- initFrame:");
  511.     return self;
  512. }
  513.  
  514. //M+    -drawSelf:(NXRect *)rects :(int)rectCount
  515. //
  516. //    EDITORIAL:
  517. //        Override of a View method.
  518. //        This is way too complicated.
  519. //M-
  520. - drawSelf:(NXRect *)rects :(int)rectCount
  521. {
  522.     int iSegments, iCC;
  523.     float xCoord, yCoord, yLast;
  524.     ENTER("- drawSelf::");
  525.  
  526.     [self rescale];
  527.  
  528.     // make background white and lines black
  529.     PSsetgray(NX_WHITE);
  530.     NXRectFill(&bounds);
  531.     PSsetgray(NX_BLACK);
  532.     NXFrameRect(&bounds);
  533.     PSsetgray(NX_BLACK);
  534.  
  535.     PSnewpath();
  536.     PSsetlinewidth(LINE_WDTH);
  537.  
  538.     [theFont set];
  539.  
  540.     iSegments = [theFile mappedSegments];
  541.  
  542.     if (iSegments == 0)
  543.         return self;
  544.  
  545.     /* stagger the lines representing memory allocations */
  546.     xCoord = NX_WIDTH(&bounds)/2.0 - ((float)iSegments/2.0)*LINE_STAGGER;
  547.     yCoord = VERT_MARGIN;
  548.     yLast  = [[theFile mappedSegment:iSegments - 1] getBaseAddress] - 1.0;
  549.  
  550.     /* count down so that the "not to scale" bit works */
  551.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  552.     {
  553.         id            oSegment    = [theFile mappedSegment:iCC];
  554.         unsigned long ulBaseAddr  = [oSegment getBaseAddress];
  555.         unsigned long ulUpperAddr = [oSegment getUpperAddress];
  556.  
  557.         if (ulBaseAddr > hiAddr)
  558.             break;  // don't need to check any higher
  559.  
  560.         if (
  561.             (ulUpperAddr <= hiAddr && ulBaseAddr >= loAddr) ||
  562.             (ulUpperAddr >= loAddr && ulBaseAddr <  loAddr) ||
  563.             (ulUpperAddr >  hiAddr && ulBaseAddr <  hiAddr)
  564.         )
  565.         {
  566.  
  567.             addressMap[iCC].baseAddress
  568.                 = (loAddr < ulBaseAddr)?ulBaseAddr:loAddr;
  569.             addressMap[iCC].endAddress
  570.                 = (hiAddr > ulUpperAddr)?ulUpperAddr:hiAddr;
  571.  
  572.             if (showNames)
  573.                 addressMap[iCC].segmentName  = [oSegment commandName];
  574.  
  575.             if (toScale)
  576.             {
  577.                 addressMap[iCC].yCoordBase = 
  578.                     (loAddr < ulBaseAddr)?
  579.                     scaleSlope*(float)ulBaseAddr + scaleYintercept
  580.                     : scaleSlope*(float)loAddr + scaleYintercept
  581.                     ;
  582.                 addressMap[iCC].yCoordTop  =
  583.                     (hiAddr > ulUpperAddr) ?
  584.                     scaleSlope*(float)ulUpperAddr + scaleYintercept
  585.                     : scaleSlope*(float)hiAddr + scaleYintercept
  586.                     ;
  587.  
  588.                 PSmoveto(xCoord, addressMap[iCC].yCoordBase);
  589.         
  590.                 PSlineto(xCoord, addressMap[iCC].yCoordTop);
  591.  
  592.             } else {
  593.  
  594.                 if (ulBaseAddr != yLast)
  595.                     PSmoveto(xCoord, yCoord + SEGMENT_GAP);
  596.                 else
  597.                     PSmoveto(xCoord, yCoord);
  598.  
  599.                 if (ulBaseAddr != yLast)
  600.                     addressMap[iCC].yCoordBase = yCoord + SEGMENT_GAP;
  601.                 else
  602.                     addressMap[iCC].yCoordBase = yCoord;
  603.  
  604.                 if (ulUpperAddr <= hiAddr && ulBaseAddr >= loAddr)
  605.                     yCoord += smashedSlope * (float)(ulUpperAddr - ulBaseAddr)
  606.                         + smashedYintercept;
  607.                 else if (ulUpperAddr >= loAddr && ulBaseAddr <  loAddr)
  608.                     yCoord += smashedSlope * (float)(ulUpperAddr - loAddr)
  609.                         + smashedYintercept;
  610.                 else if (ulUpperAddr >  hiAddr && ulBaseAddr <  hiAddr)
  611.                     yCoord += smashedSlope * (float)(hiAddr - ulBaseAddr)
  612.                         + smashedYintercept;
  613.  
  614.                 PSlineto(xCoord, yCoord);
  615.  
  616.                 addressMap[iCC].yCoordTop = yCoord;
  617.  
  618.                 yLast = ulUpperAddr;
  619.             }
  620.  
  621.             /* stagger to the right, on the way up */
  622.             xCoord += LINE_STAGGER;
  623.  
  624.         }
  625.     }
  626.  
  627.     PSstroke();
  628.  
  629.     if (yLooping)
  630.     {
  631.         // draw on the box marking the zooming zone
  632.         drawBox(sFirstMouseDown.x, sFirstMouseDown.y,
  633.             sMouseDown.x, sMouseDown.y);
  634.     } else {
  635.         [zoomButton setEnabled:NO];
  636.     }
  637.  
  638.     /* label the ends of each memory segment with its address */
  639.     if (TRUE == showAddresses)
  640.         [self drawAddresses];
  641.  
  642.     /* label the middle of each memory segment with its name */
  643.     if (TRUE == showNames)
  644.         [self drawSegmentNames];
  645.  
  646.     /* draw in little markers for threads program counters */
  647.     if (showThreads)
  648.         [self drawThreads];
  649.  
  650.     if (showSectionNames)
  651.         [self drawSectionNames];
  652.  
  653.     EXIT("- drawSelf::");
  654.     return self;
  655. }
  656.  
  657. //M+    -drawThreads
  658. //M-
  659. - drawThreads
  660. {
  661.     int iCC, iThreadCount = [theFile threads];
  662.     int iSegCount = [theFile mappedSegments];
  663.  
  664.     PSsetlinewidth(0.50);
  665.  
  666.     for (iCC = 0; iCC < iThreadCount; ++iCC)
  667.     {
  668.         float xCoord, yCoord;
  669.         int iSegNo = [theFile segmentOfThread:iCC];
  670.  
  671.         // iSegNo is -1 if there's no segment containing this thread's PC.
  672.         // abort(2) causes just this sort of situation.
  673.         if (iSegNo > -1)
  674.         {
  675.             unsigned long ulPCAddr = [[theFile thread:iCC] pc];
  676.  
  677.             if (ulPCAddr >= loAddr && ulPCAddr <= hiAddr)
  678.             {
  679.  
  680.                 xCoord = NX_WIDTH(&bounds)/2.0
  681.                 - ((float)[theFile mappedSegments]/2.0)*(LINE_STAGGER)
  682.                 + (float)(iSegCount - iSegNo) * LINE_STAGGER;
  683.  
  684.                 yCoord = addressMap[iSegNo].yCoordBase
  685.             + (addressMap[iSegNo].yCoordTop - addressMap[iSegNo].yCoordBase)
  686.             * ((float)ulPCAddr - addressMap[iSegNo].baseAddress)
  687.             / (addressMap[iSegNo].endAddress-addressMap[iSegNo].baseAddress);
  688.  
  689.                 drawLeftArrowHead(xCoord, yCoord, 8.0);
  690.             }
  691.         }
  692.     }
  693.  
  694.     return self;
  695. }
  696.  
  697. //M+    -spaceLabels
  698. //    Figure out the spacing of the address labels
  699. //    Fills in yCoordBaseLabel and yCoordTopLabel fields such that the
  700. //    addresses don't overlap, and don't end up out of the MachOView.
  701. //    yCoordBaseLabel field ends up as -1.0 if it is the same number
  702. //    as the yCoordTopLabel of the preceding (lower in memory) segment.
  703. //M-
  704. - spaceLabels
  705. {
  706.     float lastY;
  707.     float yLastAddress;
  708.     int   iCC, iSegments = [theFile mappedSegments];
  709.  
  710.     lastY = addressMap[iSegments - 1].baseAddress - 20.0;
  711.     yLastAddress = addressMap[iSegments - 1].yCoordBase - LABEL_HT;
  712.  
  713.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  714.     {
  715.         if (addressMap[iCC].baseAddress > hiAddr)
  716.             break;  // no need to go any higher
  717.  
  718.         if (
  719. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  720. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  721. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  722.         )
  723.         {
  724.  
  725.             if (addressMap[iCC].baseAddress != lastY)
  726.             {
  727.                 if (addressMap[iCC].yCoordBase < yLastAddress + LABEL_HT)
  728.                     addressMap[iCC].yCoordBaseLabel
  729.                         = yLastAddress + (LABEL_HT + 2.0);
  730.                 else
  731.                     addressMap[iCC].yCoordBaseLabel=addressMap[iCC].yCoordBase;
  732.  
  733.                 yLastAddress = addressMap[iCC].yCoordBaseLabel;
  734.  
  735.             } else {
  736.                 /* don't need to show this segment's base address */
  737.                 addressMap[iCC].yCoordBaseLabel = -1.0;
  738.             }
  739.  
  740.             if (addressMap[iCC].yCoordTop < yLastAddress + LABEL_HT)
  741.                 addressMap[iCC].yCoordTopLabel = yLastAddress + (LABEL_HT+2.0);
  742.             else
  743.                 addressMap[iCC].yCoordTopLabel = addressMap[iCC].yCoordTop;
  744.  
  745.             yLastAddress = addressMap[iCC].yCoordTopLabel;
  746.             lastY = addressMap[iCC].endAddress;
  747.  
  748.         }
  749.     }
  750.  
  751.     if (yLastAddress + LABEL_HT > NX_HEIGHT(&bounds))
  752.     {
  753.         yLastAddress = NX_HEIGHT(&bounds) - (LABEL_HT + 2.0);
  754.  
  755.         /* try to reshuffle address labels so everything fits */
  756.         for (iCC = 0; iCC < iSegments; ++iCC)
  757.         {
  758.  
  759.             if (addressMap[iCC].endAddress < loAddr)
  760.                 break;  // no need to go any lower
  761.  
  762.             if (
  763. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  764. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  765. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  766.             )
  767.             {
  768.  
  769.                 if (addressMap[iCC].yCoordTopLabel > yLastAddress)
  770.                 {
  771.                     addressMap[iCC].yCoordTopLabel = yLastAddress;
  772.                     yLastAddress -= (LABEL_HT + 2.0);
  773.                 } else if (0.0 > addressMap[iCC].yCoordTopLabel)
  774.                     continue;  // this label doesn't show.  go to next visible.
  775.                 else
  776.                     break;  /* slipped down into a gap */
  777.  
  778.                 if (addressMap[iCC].yCoordBaseLabel > yLastAddress)
  779.                 {
  780.                     addressMap[iCC].yCoordBaseLabel = yLastAddress;
  781.                     yLastAddress -= (LABEL_HT + 2.0);
  782.                 } else if (0.0 > addressMap[iCC].yCoordBaseLabel)
  783.                     continue;
  784.                 else
  785.                     break;
  786.             }
  787.         }
  788.     }
  789.  
  790.     return self;
  791. }
  792.  
  793. //M+    -spaceNames
  794. //    Figure out the spacing of the segment name labels
  795. //    Fills in yCoordBaseLabel field such that the
  796. //    names don't overlap, and don't end up out of the MachOView.
  797. //    Segment 
  798. //M-
  799. - spaceNames
  800. {
  801.     int   iCC, iSegments = [theFile mappedSegments];
  802.     float yLastAddress;
  803.  
  804.     yLastAddress = addressMap[iSegments - 1].yCoordBase - LABEL_HT;
  805.  
  806.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  807.     {
  808.             if (
  809. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  810. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  811. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  812.             )
  813.         {
  814.         /* space name across width of view */
  815.         addressMap[iCC].nameXcoord = NX_WIDTH(&bounds) - LABEL_MARGIN
  816.             - [theFont getWidthOf:addressMap[iCC].segmentName];
  817.  
  818.         /* put name in middle of segment vertically */
  819.         addressMap[iCC].nameYcoord =
  820.             (addressMap[iCC].yCoordBase + addressMap[iCC].yCoordTop)/2.0;
  821.  
  822.         /* handle overlaps */
  823.         if (addressMap[iCC].nameYcoord < yLastAddress + LABEL_HT)
  824.             addressMap[iCC].nameYcoord = yLastAddress + LABEL_HT;
  825.  
  826.         yLastAddress = addressMap[iCC].nameYcoord;
  827.         }
  828.     }
  829.  
  830.     if (yLastAddress + LABEL_HT > NX_HEIGHT(&bounds))
  831.     {
  832.         yLastAddress = NX_HEIGHT(&bounds) - (LABEL_HT + 2.0);
  833.  
  834.         /* try to reshuffle address labels so everything fits */
  835.         for (iCC = 0; iCC < iSegments; ++iCC)
  836.         {
  837.             if (
  838. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  839. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  840. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  841.             )
  842.             {
  843.             if (addressMap[iCC].nameYcoord > yLastAddress)
  844.             {
  845.                 addressMap[iCC].nameYcoord = yLastAddress;
  846.                 yLastAddress -= (LABEL_HT + 2.0);
  847.             } else
  848.                 break;  /* slipped down into a gap */
  849.             }
  850.         }
  851.     }
  852.  
  853.     return self;
  854. }
  855.  
  856. //M+    -free
  857. //M-
  858. - free
  859. {
  860.     ENTER("- free");
  861.     [self freeInternals];
  862.  
  863.     [zoomStack free];
  864.  
  865.     [super free];
  866.  
  867.     EXIT("- free");
  868.     return self;
  869. }
  870.  
  871. //M+ - freeInternals
  872. //M-
  873. - freeInternals
  874. {
  875.     ENTER("- freeInternals");
  876.     if (NULL != addressMap)
  877.     {
  878.         int iSegments = [theFile mappedSegments];
  879.         while (--iSegments > -1)
  880.             if (addressMap[iSegments].sectionMap)
  881.                 free(addressMap[iSegments].sectionMap);
  882.  
  883.         free(addressMap);
  884.         addressMap = NULL;
  885.     }
  886.  
  887.     if (NULL != currentFileName)
  888.     {
  889.         free(currentFileName);
  890.         currentFileName = NULL;
  891.     }
  892.  
  893.     if (NULL != theFile)
  894.     {
  895.         [theFile free];
  896.         theFile = NULL;
  897.     }
  898.  
  899.     if (NULL != mappedFile)
  900.     {
  901.         [mappedFile free];
  902.         mappedFile = NULL;
  903.     }
  904.  
  905.     if (NULL != zoomStack)
  906.     {    // free zoomStack's contents
  907.         void *vp;
  908.  
  909.         while ((vp = [zoomStack pop]) != NULL)
  910.             free(vp);
  911.     }
  912.  
  913.     EXIT("- freeInternals");
  914.     return self;
  915. }
  916.  
  917. //M+    -show:sender
  918. //M-
  919. - show:sender
  920. {
  921.     [theWindow makeKeyAndOrderFront:self];
  922.  
  923.     return self;
  924. }
  925.  
  926. //M+    -drawAddresses
  927. //M-
  928. - drawAddresses
  929. {
  930.     float yCoord, xCoord;
  931.     int   iCC, iSegments;
  932.  
  933.     iSegments = [theFile mappedSegments];
  934.  
  935.     /* figure out address label spacing */
  936.     [self spaceLabels];
  937.  
  938.     PSnewpath();
  939.     PSsetlinewidth(0.50);  /* thin lines to each segment */
  940.     [theFont set];
  941.  
  942.     yCoord = VERT_MARGIN;
  943.     xCoord = NX_WIDTH(&bounds)/2.0 - ((float)iSegments/2.0)*(LINE_STAGGER);
  944.  
  945.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  946.     {
  947.         char bvBuffer[256];
  948.  
  949.         if (addressMap[iCC].baseAddress > hiAddr)
  950.             break;  // no need to go any higher
  951.  
  952.         if (
  953. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  954. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  955. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  956.         )
  957.         {
  958.  
  959.             if (!(addressMap[iCC].yCoordBaseLabel < 0.0))
  960.             {    sprintf(bvBuffer, "0x%x",
  961.                     (unsigned int)addressMap[iCC].baseAddress);
  962.                 drawLabel(LABEL_MARGIN, addressMap[iCC].yCoordBaseLabel,
  963.                     bvBuffer, xCoord - (LINE_STAGGER - LABEL_MARGIN),
  964.                     addressMap[iCC].yCoordBase);
  965.             }
  966.  
  967.             sprintf(bvBuffer, "0x%x", (unsigned int)addressMap[iCC].endAddress);
  968.             drawLabel(LABEL_MARGIN, addressMap[iCC].yCoordTopLabel, bvBuffer,
  969.                 xCoord - (LINE_STAGGER - LABEL_MARGIN),
  970.                 addressMap[iCC].yCoordTop);
  971.  
  972.             xCoord += LINE_STAGGER;
  973.  
  974.         }
  975.     }
  976.  
  977.     PSstroke();
  978.  
  979.     return self;
  980. }
  981.  
  982. //M+    -drawSegmentNames
  983. //M-
  984. - drawSegmentNames
  985. {
  986.     float xCoord;
  987.     int iCC, iSegments;
  988.  
  989.     if (FALSE == showAddresses)
  990.         [self spaceLabels];
  991.  
  992.     [self spaceNames];
  993.  
  994.     PSnewpath();
  995.     PSsetlinewidth(0.50);
  996.     [theFont set];
  997.  
  998.     iSegments = [theFile mappedSegments];
  999.  
  1000.     xCoord = NX_WIDTH(&bounds)/2.0
  1001.         - ((float)iSegments/2.0)*(LINE_STAGGER) + 5.0;
  1002.  
  1003.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  1004.     {
  1005.         if (addressMap[iCC].baseAddress > hiAddr)
  1006.             break;  // no need to go any higher
  1007.  
  1008.         if (
  1009. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  1010. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  1011. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  1012.         )
  1013.         {
  1014.  
  1015.             xCoord += LINE_STAGGER;
  1016.             PSmoveto(
  1017.                 xCoord,
  1018.                 (addressMap[iCC].yCoordBase + addressMap[iCC].yCoordTop)/2.0);
  1019.             PSlineto(
  1020.                 addressMap[iCC].nameXcoord - 10.0,
  1021.                 addressMap[iCC].nameYcoord);
  1022.             PSmoveto(addressMap[iCC].nameXcoord, addressMap[iCC].nameYcoord);
  1023.             PSshow(addressMap[iCC].segmentName);
  1024.  
  1025.         }
  1026.     }
  1027.  
  1028.     PSstroke();
  1029.  
  1030.     return self;
  1031. }
  1032.  
  1033. //M+    -spaceSectionNames
  1034. //M-
  1035. - spaceSectionNames
  1036. {
  1037.     int   iCC, iSegments;
  1038.     float yLastAddress;
  1039.  
  1040.     iSegments = [theFile mappedSegments];
  1041.  
  1042.     yLastAddress = addressMap[iSegments - 1].yCoordBase - LABEL_HT;
  1043.  
  1044.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  1045.     {
  1046.         if (addressMap[iCC].baseAddress > hiAddr)
  1047.             break;  // no need to go any higher
  1048.  
  1049.         if (
  1050. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  1051. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  1052. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  1053.         )
  1054.         {
  1055.             SegmentCommand *oSegment = [theFile mappedSegment:iCC];
  1056.             int             iSection = [oSegment numberOfSections];
  1057.  
  1058.             if (iSection > 0 && addressMap[iCC].sectionMap != NULL)
  1059.             {
  1060.                 int   i;
  1061.  
  1062.                 for (i = 0; i < iSection; ++i)
  1063.                 {
  1064.                     if(
  1065.                         (addressMap[iCC].sectionMap[i].sectionAddress <= hiAddr)
  1066.                     &&    (addressMap[iCC].sectionMap[i].sectionAddress >= loAddr)
  1067.                     )
  1068.                     {
  1069.  
  1070.                         if (toScale)
  1071.                         {
  1072.                             addressMap[iCC].sectionMap[i].nameYcoord
  1073.         = scaleSlope*(float)addressMap[iCC].sectionMap[i].sectionAddress
  1074.             + scaleYintercept;
  1075.                         } else {
  1076.                             addressMap[iCC].sectionMap[i].nameYcoord
  1077.         = smashedSlope*(float)addressMap[iCC].sectionMap[i].sectionAddress
  1078.             + smashedYintercept;
  1079.                         }
  1080.  
  1081.                         if (addressMap[iCC].sectionMap[i].nameYcoord <= yLastAddress+LABEL_HT)
  1082.             addressMap[iCC].sectionMap[i].nameYcoord = yLastAddress + LABEL_HT;
  1083.  
  1084.                         yLastAddress = addressMap[iCC].sectionMap[i].nameYcoord;
  1085.  
  1086.                     }
  1087.  
  1088.                 }
  1089.             }
  1090.         }
  1091.     }
  1092.  
  1093.     return self;
  1094. }
  1095.  
  1096. //M+    -drawSectionNames
  1097. //M-
  1098. - drawSectionNames
  1099. {
  1100.     float xCoord;
  1101.     int iCC, iSegments;
  1102.  
  1103.     [self spaceSectionNames];
  1104.  
  1105.     PSnewpath();
  1106.     PSsetlinewidth(0.50);
  1107.     [theFont set];
  1108.  
  1109.     iSegments = [theFile mappedSegments];
  1110.  
  1111.     xCoord = NX_WIDTH(&bounds)/2.0
  1112.         - ((float)iSegments/2.0)*(LINE_STAGGER) + 5.0;
  1113.  
  1114.     for (iCC = iSegments - 1; iCC > -1; --iCC)
  1115.     {
  1116.         if (addressMap[iCC].baseAddress > hiAddr)
  1117.             break;  // no need to go any higher
  1118.  
  1119.         if (
  1120. (addressMap[iCC].endAddress <= hiAddr && addressMap[iCC].baseAddress >= loAddr)
  1121. ||(addressMap[iCC].endAddress >= loAddr && addressMap[iCC].baseAddress < loAddr)
  1122. ||(addressMap[iCC].endAddress > hiAddr && addressMap[iCC].baseAddress < hiAddr)
  1123.         )
  1124.         {
  1125.             SegmentCommand *oSegment = [theFile mappedSegment:iCC];
  1126.             int             iSection = [oSegment numberOfSections];
  1127.  
  1128.             if (iSection > 0 && addressMap[iCC].sectionMap != NULL)
  1129.             {
  1130.                 int             i;
  1131.                 for (i = 0; i < iSection; ++i)
  1132.                 {
  1133.                     if(
  1134.                         (addressMap[iCC].sectionMap[i].sectionAddress <= hiAddr)
  1135.                       &&(addressMap[iCC].sectionMap[i].sectionAddress >= loAddr)
  1136.                     )
  1137.                     {
  1138.                         float yCoord;
  1139.  
  1140.                         if (toScale)
  1141.                         {
  1142.                             yCoord
  1143.         = scaleSlope*(float)addressMap[iCC].sectionMap[i].sectionAddress
  1144.             + scaleYintercept;
  1145.                         } else {
  1146.                             yCoord
  1147.         = smashedSlope*(float)addressMap[iCC].sectionMap[i].sectionAddress
  1148.             + smashedYintercept;
  1149.                         }
  1150.                         PSmoveto(xCoord, yCoord);
  1151.                         PSlineto(xCoord + 10.0,
  1152.                             addressMap[iCC].sectionMap[i].nameYcoord);
  1153.                         PSmoveto(xCoord + 14.0,
  1154.                             addressMap[iCC].sectionMap[i].nameYcoord);
  1155.                         PSshow(addressMap[iCC].sectionMap[i].sectionName);
  1156.                     }
  1157.                 }
  1158.             }
  1159.  
  1160.             xCoord += LINE_STAGGER;
  1161.         }
  1162.     }
  1163.  
  1164.     PSstroke();
  1165.  
  1166.     return self;
  1167. }
  1168.  
  1169. //M+ - mouseDown:(NXEvent *)spTheEvent
  1170. //    PURPOSE:
  1171. //        draw a box following the user's mouse drags
  1172. //M-
  1173. - mouseDown:(NXEvent *)spTheEvent
  1174. {
  1175.     NXEvent *spNextEvent;
  1176.     int      iOldMask, iCheckMask, iDragged = 0;
  1177.     char     bvBuf[64];
  1178.  
  1179.     [self lockFocus];
  1180.  
  1181.     iOldMask = [window eventMask];
  1182.  
  1183.     iCheckMask = NX_MOUSEUPMASK | NX_MOUSEDRAGGEDMASK;
  1184.  
  1185.     [window setEventMask:(iOldMask|iCheckMask)];
  1186.  
  1187.     sFirstMouseDown = spTheEvent->location;
  1188.     [self convertPoint:&sFirstMouseDown fromView:nil];
  1189.  
  1190.     yLooping = 1;
  1191.     while (yLooping)
  1192.     {
  1193.         iDragged = 1;
  1194.         spNextEvent = [NXApp getNextEvent:iCheckMask];
  1195.  
  1196.         if ((yLooping = (spNextEvent->type != NX_MOUSEUP)))
  1197.         {
  1198.             sMouseDown = spTheEvent->location;
  1199.             [self convertPoint:&sMouseDown fromView:nil];
  1200.             [self display];
  1201.         }
  1202.     }
  1203.  
  1204.     [self unlockFocus];
  1205.  
  1206.     [window setEventMask:iOldMask];
  1207.  
  1208.     if (!iDragged)
  1209.         return self;
  1210.  
  1211.     // For sake of aesthetics, address 0x0 is not exactly at bottom of
  1212.     // view.  This lets the user drag an address of less than zero,
  1213.     // which ends up as a very high address in an unsigned long.
  1214.     // The next bits use the view coords to keep user from screwing up.
  1215.     if (sFirstMouseDown.y < VERT_MARGIN)
  1216.         sFirstMouseDown.y = VERT_MARGIN;
  1217.     if (sMouseDown.y < VERT_MARGIN)
  1218.         sMouseDown.y = VERT_MARGIN;
  1219.  
  1220.     // set displayed coords for user's inspection
  1221.     if (toScale)
  1222.     {
  1223.         hiAddrZoom =
  1224.         (unsigned long)((sFirstMouseDown.y - scaleYintercept)/scaleSlope);
  1225.         loAddrZoom =
  1226.         (unsigned long)((sMouseDown.y - scaleYintercept)/scaleSlope);
  1227.  
  1228.     } else {
  1229.         int iCC;
  1230.         int iSegments = [theFile mappedSegments];
  1231.         int iLoSet = 0, iHiSet = 0;
  1232.         // find out where the addresses dragged out are
  1233.  
  1234.         for (iCC = iSegments - 1;
  1235.             iCC > -1 && (!iLoSet || !iHiSet);
  1236.             --iCC)
  1237.         {
  1238.             if (!iLoSet && addressMap[iCC].yCoordBase <= sMouseDown.y
  1239.                 && addressMap[iCC].yCoordTop >= sMouseDown.y)
  1240.             {
  1241.                 loAddrZoom =
  1242.     (unsigned long)((sMouseDown.y - addressMap[iCC].yCoordBase)
  1243.     /(addressMap[iCC].yCoordTop - addressMap[iCC].yCoordBase)
  1244.     *(float)(addressMap[iCC].endAddress - addressMap[iCC].baseAddress))
  1245.     + addressMap[iCC].baseAddress;
  1246.                 iLoSet = 1;
  1247.  
  1248.             }
  1249.  
  1250.             if (!iHiSet && addressMap[iCC].yCoordBase <= sFirstMouseDown.y
  1251.                 && addressMap[iCC].yCoordTop >= sFirstMouseDown.y)
  1252.             {
  1253.                 hiAddrZoom =
  1254.     (unsigned long)((sFirstMouseDown.y - addressMap[iCC].yCoordBase)
  1255.     /(addressMap[iCC].yCoordTop - addressMap[iCC].yCoordBase)
  1256.     *(float)(addressMap[iCC].endAddress - addressMap[iCC].baseAddress))
  1257.     + addressMap[iCC].baseAddress;
  1258.                 iHiSet = 1;
  1259.             }
  1260.         }
  1261.  
  1262.         if (!iLoSet)
  1263.         {
  1264.             // sMouseDown.y not in range of any segment
  1265.             if (sMouseDown.y > addressMap[0].yCoordTop)
  1266.                 loAddrZoom = hiAddr;
  1267.             else
  1268.                 loAddrZoom = loAddr;
  1269.         }
  1270.  
  1271.         if (!iHiSet)
  1272.         {
  1273.             // sFirstMouseDown.y not in range of any segment
  1274.             if (sFirstMouseDown.y > addressMap[0].yCoordTop)
  1275.                 hiAddrZoom = hiAddr;
  1276.             else
  1277.                 hiAddrZoom = loAddr;
  1278.         }
  1279.         
  1280.     }
  1281.  
  1282.     // user may have dragged from bottom to top.
  1283.     if (hiAddrZoom < loAddrZoom)
  1284.     {    unsigned long ulTmp = hiAddrZoom; hiAddrZoom = loAddrZoom;
  1285.         loAddrZoom = ulTmp; }
  1286.  
  1287.     // clamp zoomed values no matter what they calculated out as
  1288.     if (hiAddrZoom > hiAddr)
  1289.         hiAddrZoom = hiAddr;
  1290.  
  1291.     if (loAddrZoom < loAddr)
  1292.         loAddrZoom = loAddr;
  1293.  
  1294.     sprintf(bvBuf, "0x%x", loAddrZoom);
  1295.     [minAddress setStringValue:bvBuf];
  1296.     sprintf(bvBuf, "0x%x", hiAddrZoom);
  1297.     [maxAddress setStringValue:bvBuf];
  1298.  
  1299.     [zoomButton setEnabled:YES];
  1300.  
  1301.     return self;
  1302. }
  1303.  
  1304. //M+ - zoom:sender
  1305. //    PURPOSE:
  1306. //        Do what needs to be done when user clicks on "zoom" button.
  1307. //        Essentially, it pushes the current state (high address displayed,
  1308. //        low address displayed, and amount of mapped address taked up)
  1309. //        on the zoom stack, recalcs the amount of address taken up
  1310. //        inside the new high and low addresses, then redisplays.
  1311. //M-
  1312. - zoom:sender
  1313. {
  1314.     struct zoomAddress *spZoom;
  1315.     int                 iCC;
  1316.  
  1317.     // save current "zoom state".
  1318.     spZoom = malloc(sizeof(struct zoomAddress));
  1319.     assert(spZoom != NULL);
  1320.     spZoom->hiAddr = hiAddr;
  1321.     spZoom->loAddr = loAddr;
  1322.     spZoom->sumAddr = sumAddr;
  1323.     [zoomStack push:(void *)spZoom];
  1324.  
  1325.     hiAddr = hiAddrZoom;
  1326.     loAddr = loAddrZoom;
  1327.  
  1328.     // recalculate the amount of the address used by file's mapped segments
  1329.     sumAddr = 0;
  1330.     for (iCC = [theFile mappedSegments] - 1; iCC > -1; --iCC)
  1331.     {
  1332.         id            oSegment = [theFile mappedSegment:iCC];
  1333.         unsigned long ulBaseAddr, ulUpperAddr;
  1334.  
  1335.         ulBaseAddr  = [oSegment getBaseAddress];
  1336.         ulUpperAddr = [oSegment getUpperAddress];
  1337.  
  1338.         if (ulBaseAddr > hiAddr)
  1339.             break;
  1340.  
  1341.         if (
  1342.           (ulUpperAddr <= hiAddr && ulBaseAddr >= loAddr)
  1343.         ||(ulUpperAddr >= loAddr && ulBaseAddr <  loAddr)
  1344.         ||(ulUpperAddr >  hiAddr && ulBaseAddr <  hiAddr)
  1345.         )
  1346.         {
  1347.                 sumAddr +=
  1348.                     (ulUpperAddr <= hiAddr ? ulUpperAddr : hiAddr)
  1349.                     -
  1350.                     (ulBaseAddr >= loAddr ? ulBaseAddr : loAddr);
  1351.         }
  1352.     }
  1353.  
  1354.     [unzoomButton setEnabled:YES];
  1355.  
  1356.     [self display];
  1357.  
  1358.     return self;
  1359. }
  1360.  
  1361. //M+ - unzoom:sender
  1362. //    PURPOSE:
  1363. //        "unzoom" a level.
  1364. //M-
  1365. - unzoom:sender
  1366. {
  1367.     char bvBuf[64];
  1368.     struct zoomAddress *spZoom;
  1369.  
  1370.     spZoom = (struct zoomAddress *)[zoomStack pop];
  1371.  
  1372.     loAddr = spZoom->loAddr;
  1373.     hiAddr = spZoom->hiAddr;
  1374.     sumAddr = spZoom->sumAddr;
  1375.     free(spZoom);
  1376.  
  1377.     sprintf(bvBuf, "0x%x", loAddr);
  1378.     [minAddress setStringValue:bvBuf];
  1379.     sprintf(bvBuf, "0x%x", hiAddr);
  1380.     [maxAddress setStringValue:bvBuf];
  1381.  
  1382.     if ([zoomStack isEmpty])
  1383.         [unzoomButton setEnabled:NO];
  1384.  
  1385.     [self display];
  1386.  
  1387.     return self;
  1388. }
  1389.  
  1390. @@end
  1391. @
  1392.  
  1393.  
  1394. 1.17
  1395. log
  1396. @finally got section names to draw acceptably.
  1397. @
  1398. text
  1399. @d5 3
  1400. d55 1
  1401. a55 1
  1402. static char rcsident[] = "$Id: MachOView.m,v 1.16 94/05/26 21:21:06 ediger Exp Locker: ediger $";
  1403. d263 2
  1404. a264 1
  1405.                 addressMap[iCC].sectionMap[i].sectionAddress = spSection[i].addr;
  1406. d294 5
  1407. d316 1
  1408. d320 1
  1409. a320 1
  1410.     {    // free zoomStack's contents
  1411. d537 1
  1412. a537 1
  1413.     if (showThreads && addressMap)
  1414. @
  1415.  
  1416.  
  1417. 1.16
  1418. log
  1419. @correct address bracket zooming, hi and lo address bracket checking
  1420. @
  1421. text
  1422. @d5 3
  1423. d52 1
  1424. a52 1
  1425. static char rcsident[] = "$Id: MachOView.m,v 1.15 94/05/23 20:32:13 ediger Exp Locker: ediger $";
  1426. d138 1
  1427. d140 2
  1428. a141 1
  1429.                 [theFile mappedSegments] * sizeof(struct addressMapping));
  1430. d159 1
  1431. d161 5
  1432. a165 1
  1433.     else
  1434. d167 3
  1435. d231 2
  1436. d238 29
  1437. d530 3
  1438. d758 5
  1439. d905 136
  1440. @
  1441.  
  1442.  
  1443. 1.15
  1444. log
  1445. @lot's o' stuff to do address bracket zoom-in
  1446. @
  1447. text
  1448. @d5 3
  1449. d49 1
  1450. a49 1
  1451. static char rcsident[] = "$Id: MachOView.m,v 1.14 94/05/17 23:09:48 ediger Exp Locker: ediger $";
  1452. a301 1
  1453.     float falseSize = (float)sumAddr;
  1454. d309 1
  1455. a309 1
  1456.     smashedSlope      = ht/falseSize;
  1457. d398 2
  1458. a399 2
  1459.             (ulUpperAddr >= loAddr && ulBaseAddr < loAddr)  ||
  1460.             (ulUpperAddr > hiAddr && ulBaseAddr < hiAddr)
  1461. d403 4
  1462. a406 6
  1463.             if (showAddresses || showNames)
  1464.             {    addressMap[iCC].baseAddress
  1465.                     = (loAddr < ulBaseAddr)?ulBaseAddr:loAddr;
  1466.                 addressMap[iCC].endAddress
  1467.                     = (hiAddr > ulUpperAddr)?ulUpperAddr:hiAddr;
  1468.             }
  1469. d435 4
  1470. a438 6
  1471.                 if (showAddresses || showNames)
  1472.                 {    if (ulBaseAddr != yLast)
  1473.                         addressMap[iCC].yCoordBase = yCoord + SEGMENT_GAP;
  1474.                     else
  1475.                         addressMap[iCC].yCoordBase = yCoord;
  1476.                 }
  1477. d440 9
  1478. a448 2
  1479.                 yCoord += smashedSlope*(float)(ulUpperAddr - ulBaseAddr)
  1480.                     + smashedYintercept;
  1481. d452 1
  1482. a452 2
  1483.                 if (showAddresses || showNames)
  1484.                     addressMap[iCC].yCoordTop = yCoord;
  1485. d868 1
  1486. a868 1
  1487.     int      iOldMask, iCheckMask;
  1488. d885 1
  1489. d900 3
  1490. d921 4
  1491. d926 46
  1492. a971 1
  1493.         // find out where the addresses dragged out are
  1494. d979 7
  1495. d1023 2
  1496. a1024 1
  1497.     {    id oSegment = [theFile mappedSegment:iCC];
  1498. d1030 8
  1499. a1037 1
  1500.         if (ulBaseAddr >= loAddr)
  1501. d1039 4
  1502. a1042 6
  1503.             if (ulUpperAddr <= hiAddr)
  1504.                 sumAddr += (ulUpperAddr - ulBaseAddr);
  1505.             else {
  1506.                 sumAddr += (hiAddr - ulBaseAddr);
  1507.                 break;  // don't need to check any higher
  1508.             }
  1509. @
  1510.  
  1511.  
  1512. 1.14
  1513. log
  1514. @support for stacking of zoomed address ranges, changed types of
  1515. some instance vars from id to pointer to that kind of object.
  1516. @
  1517. text
  1518. @d5 4
  1519. d46 1
  1520. a46 1
  1521. static char rcsident[] = "$Id: MachOView.m,v 1.13 94/05/10 22:41:07 ediger Exp Locker: ediger $";
  1522. a139 2
  1523.     zoomStack = [[Queue alloc] init];
  1524.  
  1525. d261 11
  1526. d287 1
  1527. a294 2
  1528. //    EDITORIAL:
  1529. //        has to be a method because it fiddles with instance vars.
  1530. d332 1
  1531. d338 1
  1532. a338 1
  1533.     zoomStack       = NULL;
  1534. a342 1
  1535.     //zoomStack = [[Queue alloc] init];
  1536. d376 3
  1537. d381 1
  1538. a381 1
  1539.     yCoord = 5.0;
  1540. d386 4
  1541. a389 1
  1542.     {    id oSegment = [theFile mappedSegment:iCC];
  1543. d391 2
  1544. a392 4
  1545.         if (showAddresses || showNames)
  1546.         {    addressMap[iCC].baseAddress = [oSegment getBaseAddress];
  1547.             addressMap[iCC].endAddress  = [oSegment getUpperAddress];
  1548.         }
  1549. d394 6
  1550. a399 2
  1551.         if (showNames)
  1552.             addressMap[iCC].segmentName  = [oSegment commandName];
  1553. a400 2
  1554.         if (toScale)
  1555.         {
  1556. d402 4
  1557. a405 4
  1558.             {    addressMap[iCC].yCoordBase = 
  1559.                 scaleSlope*(float)[oSegment getBaseAddress] + scaleYintercept;
  1560.                 addressMap[iCC].yCoordTop  =
  1561.                 scaleSlope*(float)[oSegment getUpperAddress] + scaleYintercept;
  1562. d408 2
  1563. a409 5
  1564.             PSmoveto(xCoord,
  1565.                 scaleSlope*(float)[oSegment getBaseAddress] + scaleYintercept);
  1566.     
  1567.             PSlineto(xCoord,
  1568.                 scaleSlope*(float)[oSegment getUpperAddress] + scaleYintercept);
  1569. d411 12
  1570. a422 2
  1571.         } else {
  1572.             unsigned long ulBase = [oSegment getBaseAddress];
  1573. d424 3
  1574. a426 4
  1575.             if (ulBase != yLast)
  1576.                 PSmoveto(xCoord, yCoord + SEGMENT_GAP);
  1577.             else
  1578.                 PSmoveto(xCoord, yCoord);
  1579. d428 4
  1580. a431 3
  1581.             if (showAddresses || showNames)
  1582.             {    if (ulBase != yLast)
  1583.                     addressMap[iCC].yCoordBase = yCoord + SEGMENT_GAP;
  1584. d433 1
  1585. a433 2
  1586.                     addressMap[iCC].yCoordBase = yCoord;
  1587.             }
  1588. d435 8
  1589. a442 2
  1590.             yCoord +=
  1591.                 smashedSlope*(float)([oSegment getUpperAddress] - ulBase)
  1592. d445 1
  1593. a445 1
  1594.             PSlineto(xCoord, yCoord);
  1595. d447 2
  1596. a448 2
  1597.             if (showAddresses || showNames)
  1598.                 addressMap[iCC].yCoordTop = yCoord;
  1599. d450 6
  1600. a455 1
  1601.             yLast = [oSegment getUpperAddress];
  1602. a456 3
  1603.  
  1604.         /* stagger to the right, on the way up */
  1605.         xCoord += LINE_STAGGER;
  1606. d504 6
  1607. a509 1
  1608.             xCoord = NX_WIDTH(&bounds)/2.0
  1609. d513 1
  1610. a513 1
  1611.             yCoord = addressMap[iSegNo].yCoordBase
  1612. d515 1
  1613. a515 1
  1614.             * ((float)[[theFile thread:iCC] pc]-addressMap[iSegNo].baseAddress)
  1615. d518 2
  1616. a519 1
  1617.             drawLeftArrowHead(xCoord, yCoord, 8.0);
  1618. d544 8
  1619. a551 1
  1620.         if (addressMap[iCC].baseAddress != lastY)
  1621. d553 18
  1622. a570 3
  1623.             if (addressMap[iCC].yCoordBase < yLastAddress + LABEL_HT)
  1624.                 addressMap[iCC].yCoordBaseLabel
  1625.                     = yLastAddress + (LABEL_HT + 2.0);
  1626. d572 1
  1627. a572 1
  1628.                 addressMap[iCC].yCoordBaseLabel = addressMap[iCC].yCoordBase;
  1629. d574 2
  1630. a575 1
  1631.             yLastAddress = addressMap[iCC].yCoordBaseLabel;
  1632. a576 3
  1633.         } else {
  1634.             /* don't need to show this segment's base address */
  1635.             addressMap[iCC].yCoordBaseLabel = -1.0;
  1636. a577 8
  1637.  
  1638.         if (addressMap[iCC].yCoordTop < yLastAddress + LABEL_HT)
  1639.             addressMap[iCC].yCoordTopLabel = yLastAddress + (LABEL_HT + 2.0);
  1640.         else
  1641.             addressMap[iCC].yCoordTopLabel = addressMap[iCC].yCoordTop;
  1642.  
  1643.         yLastAddress = addressMap[iCC].yCoordTopLabel;
  1644.         lastY = addressMap[iCC].endAddress;
  1645. d587 9
  1646. a595 1
  1647.             if (addressMap[iCC].yCoordTopLabel > yLastAddress)
  1648. a596 6
  1649.                 addressMap[iCC].yCoordTopLabel = yLastAddress;
  1650.                 yLastAddress -= (LABEL_HT + 2.0);
  1651.             } else if (0.0 > addressMap[iCC].yCoordTopLabel)
  1652.                 continue;  /* this label doesn't show.  go to next visible */
  1653.             else
  1654.                 break;  /* slipped down into a gap */
  1655. d598 18
  1656. a615 8
  1657.             if (addressMap[iCC].yCoordBaseLabel > yLastAddress)
  1658.             {
  1659.                 addressMap[iCC].yCoordBaseLabel = yLastAddress;
  1660.                 yLastAddress -= (LABEL_HT + 2.0);
  1661.             } else if (0.0 > addressMap[iCC].yCoordBaseLabel)
  1662.                 continue;
  1663.             else
  1664.                 break;
  1665. d637 6
  1666. d656 1
  1667. d666 6
  1668. d678 1
  1669. d692 2
  1670. d730 1
  1671. a730 1
  1672.     {
  1673. a734 3
  1674.  
  1675.         [zoomStack free];
  1676.         zoomStack = NULL;
  1677. d766 1
  1678. a766 1
  1679.     yCoord = 5.0;
  1680. d773 2
  1681. a774 7
  1682.         if (!(addressMap[iCC].yCoordBaseLabel < 0.0))
  1683.         {    sprintf(bvBuffer, "0x%x",
  1684.                 (unsigned int)addressMap[iCC].baseAddress);
  1685.             drawLabel(LABEL_MARGIN, addressMap[iCC].yCoordBaseLabel,
  1686.                 bvBuffer, xCoord - (LINE_STAGGER - LABEL_MARGIN),
  1687.                 addressMap[iCC].yCoordBase);
  1688.         }
  1689. d776 6
  1690. a781 4
  1691.         sprintf(bvBuffer, "0x%x", (unsigned int)addressMap[iCC].endAddress);
  1692.         drawLabel(LABEL_MARGIN, addressMap[iCC].yCoordTopLabel, bvBuffer,
  1693.             xCoord - (LINE_STAGGER - LABEL_MARGIN),
  1694.             addressMap[iCC].yCoordTop);
  1695. d783 16
  1696. a798 1
  1697.         xCoord += LINE_STAGGER;
  1698. d829 21
  1699. a849 9
  1700.         xCoord += LINE_STAGGER;
  1701.         PSmoveto(
  1702.             xCoord,
  1703.             (addressMap[iCC].yCoordBase + addressMap[iCC].yCoordTop)/2.0);
  1704.         PSlineto(
  1705.             addressMap[iCC].nameXcoord - 10.0,
  1706.             addressMap[iCC].nameYcoord);
  1707.         PSmoveto(addressMap[iCC].nameXcoord, addressMap[iCC].nameYcoord);
  1708.         PSshow(addressMap[iCC].segmentName);
  1709. d865 1
  1710. d895 9
  1711. a906 2
  1712.         char bvBuf[64];
  1713.  
  1714. d912 1
  1715. a912 3
  1716.         if (hiAddrZoom < loAddrZoom)
  1717.         {    unsigned long ulTmp = hiAddrZoom; hiAddrZoom = loAddrZoom;
  1718.             hiAddrZoom = ulTmp; }
  1719. d914 1
  1720. a914 4
  1721.         sprintf(bvBuf, "0x%x", loAddrZoom);
  1722.         [minAddress setStringValue:bvBuf];
  1723.         sprintf(bvBuf, "0x%x", hiAddrZoom);
  1724.         [maxAddress setStringValue:bvBuf];
  1725. d917 10
  1726. d933 6
  1727. d943 1
  1728. d945 1
  1729. d948 3
  1730. a950 3
  1731.     spZoom->hiAddr = hiAddrZoom;
  1732.     spZoom->loAddr = loAddrZoom;
  1733.  
  1734. d953 23
  1735. d978 2
  1736. d989 1
  1737. d993 4
  1738. d999 4
  1739. a1002 1
  1740.     spZoom = (struct zoomAddress *)[zoomStack tail];
  1741. a1003 18
  1742.     if (toScale)
  1743.     {
  1744.         char bvBuf[64];
  1745.  
  1746.         if (spZoom)
  1747.         {
  1748.             sprintf(bvBuf, "0x%x", spZoom->loAddr);
  1749.             [minAddress setStringValue:bvBuf];
  1750.             sprintf(bvBuf, "0x%x", spZoom->hiAddr);
  1751.             [maxAddress setStringValue:bvBuf];
  1752.         } else {
  1753.             sprintf(bvBuf, "0x%x", loAddr);
  1754.             [minAddress setStringValue:bvBuf];
  1755.             sprintf(bvBuf, "0x%x", hiAddr);
  1756.             [maxAddress setStringValue:bvBuf];
  1757.         }
  1758.     }
  1759.  
  1760. d1006 2
  1761. @
  1762.  
  1763.  
  1764. 1.13
  1765. log
  1766. @support for displaying a "zooming box" by mouse drag
  1767. @
  1768. text
  1769. @d5 3
  1770. d42 1
  1771. a42 1
  1772. static char rcsident[] = "$Id: MachOView.m,v 1.12 94/05/04 11:19:58 ediger Exp Locker: ediger $";
  1773. d44 11
  1774. d69 1
  1775. d71 2
  1776. d88 6
  1777. d109 1
  1778. d112 1
  1779. a112 2
  1780.     if (Nil != mappedFile)
  1781.         [mappedFile free];
  1782. a113 12
  1783.     if (Nil != theFile)
  1784.         [theFile free];
  1785.  
  1786.     if (NULL != currentFileName)
  1787.         free(currentFileName);
  1788.  
  1789.     if (NULL != addressMap)
  1790.     {
  1791.         free(addressMap);
  1792.         addressMap = NULL;
  1793.     }
  1794.  
  1795. d117 1
  1796. a117 1
  1797.     if (mappedFile == Nil || [mappedFile map] == FALSE)
  1798. d124 1
  1799. a124 1
  1800.         if (Nil == theFile)
  1801. d136 3
  1802. d235 1
  1803. a235 1
  1804.     if (theFile != Nil)
  1805. d272 3
  1806. a274 15
  1807.     if (theFile != Nil)
  1808.         [theFile free];
  1809.  
  1810.     if (mappedFile != Nil)
  1811.         [mappedFile free];
  1812.  
  1813.     if (theFont != Nil)
  1814.         [theFont free];  // not strictly necessary?
  1815.  
  1816.     if (currentFileName != NULL)
  1817.         free(currentFileName);
  1818.  
  1819.     if (addressMap != NULL)
  1820.         free(addressMap);
  1821.  
  1822. d288 1
  1823. d298 1
  1824. d312 1
  1825. d323 3
  1826. a325 2
  1827.     mappedFile      = Nil;
  1828.     theFile         = Nil;
  1829. d330 3
  1830. d346 1
  1831. d434 2
  1832. d450 1
  1833. a450 1
  1834.     D(printf("exit MachOView -drawSelf::\n");)
  1835. d613 16
  1836. a628 1
  1837.     if (addressMap == NULL)
  1838. d630 2
  1839. d634 1
  1840. d636 2
  1841. d639 2
  1842. a640 1
  1843.     if (Nil == theFile)
  1844. d642 2
  1845. d645 5
  1846. a649 1
  1847.     [super free];
  1848. d651 12
  1849. d758 4
  1850. d796 3
  1851. d800 17
  1852. d819 56
  1853. @
  1854.  
  1855.  
  1856. 1.12
  1857. log
  1858. @rearrange drawSelf:: to be a bit more modular
  1859. @
  1860. text
  1861. @d5 3
  1862. d39 1
  1863. a39 1
  1864. static char rcsident[] = "$Id: MachOView.m,v 1.10 94/05/01 17:32:57 ediger Exp Locker: ediger $";
  1865. d419 7
  1866. d707 37
  1867. @
  1868.  
  1869.  
  1870. 1.11
  1871. log
  1872. @support for drawing a marker at thread's program counter
  1873. @
  1874. text
  1875. @d418 1
  1876. a418 3
  1877.     {
  1878.         /* figure out address label spacing */
  1879.         [self spaceLabels];
  1880. a419 31
  1881.         PSnewpath();
  1882.         PSsetlinewidth(0.50);  /* thin lines to each segment */
  1883.         [theFont set];
  1884.  
  1885.         yCoord = 5.0;
  1886.         xCoord = NX_WIDTH(&bounds)/2.0 - ((float)iSegments/2.0)*(LINE_STAGGER);
  1887.  
  1888.         for (iCC = iSegments - 1; iCC > -1; --iCC)
  1889.         {
  1890.             char bvBuffer[256];
  1891.  
  1892.             if (!(addressMap[iCC].yCoordBaseLabel < 0.0))
  1893.             {    sprintf(bvBuffer, "0x%x",
  1894.                     (unsigned int)addressMap[iCC].baseAddress);
  1895.                 drawLabel(LABEL_MARGIN, addressMap[iCC].yCoordBaseLabel,
  1896.                     bvBuffer, xCoord - (LINE_STAGGER - LABEL_MARGIN),
  1897.                     addressMap[iCC].yCoordBase);
  1898.             }
  1899.  
  1900.             sprintf(bvBuffer, "0x%x", (unsigned int)addressMap[iCC].endAddress);
  1901.             drawLabel(LABEL_MARGIN, addressMap[iCC].yCoordTopLabel, bvBuffer,
  1902.                 xCoord - (LINE_STAGGER - LABEL_MARGIN),
  1903.                 addressMap[iCC].yCoordTop);
  1904.  
  1905.             xCoord += LINE_STAGGER;
  1906.         }
  1907.  
  1908.         PSstroke();
  1909.  
  1910.     }
  1911.  
  1912. d422 1
  1913. a422 4
  1914.     {
  1915.         if (FALSE == showAddresses)
  1916.             [self spaceLabels];
  1917.         [self spaceNames];
  1918. a423 21
  1919.         PSnewpath();
  1920.         PSsetlinewidth(0.50);
  1921.         [theFont set];
  1922.  
  1923.         xCoord = NX_WIDTH(&bounds)/2.0
  1924.             - ((float)iSegments/2.0)*(LINE_STAGGER) + 5.0;
  1925.         for (iCC = iSegments - 1; iCC > -1; --iCC)
  1926.         {
  1927.             xCoord += LINE_STAGGER;
  1928.             PSmoveto(
  1929.                 xCoord,
  1930.                 (addressMap[iCC].yCoordBase + addressMap[iCC].yCoordTop)/2.0);
  1931.             PSlineto(
  1932.                 addressMap[iCC].nameXcoord - 10.0,
  1933.                 addressMap[iCC].nameYcoord);
  1934.             PSmoveto(addressMap[iCC].nameXcoord, addressMap[iCC].nameYcoord);
  1935.             PSshow(addressMap[iCC].segmentName);
  1936.         }
  1937.         PSstroke();
  1938.     }
  1939.  
  1940. d610 83
  1941. @
  1942.  
  1943.  
  1944. 1.10
  1945. log
  1946. @efficiency improvements
  1947. @
  1948. text
  1949. @d5 3
  1950. d36 1
  1951. a36 1
  1952. static char rcsident[] = "$Id: MachOView.m,v 1.9 94/02/07 21:37:17 ediger Exp Locker: ediger $";
  1953. d174 32
  1954. d307 1
  1955. a307 1
  1956.     toScale = TRUE;
  1957. d310 2
  1958. a311 1
  1959.     showNames = TRUE;
  1960. d314 3
  1961. a316 3
  1962.     addressMap = NULL;
  1963.     mappedFile = Nil;
  1964.     theFile = Nil;
  1965. d482 36
  1966. a517 4
  1967. /*
  1968.     iSegments = [theFile threads];
  1969.     for (iCC = 0; iCC < iSegments; ++iCC)
  1970.     {    // how do I decide which seg the thread belongs to?
  1971. a518 1
  1972. */
  1973. a519 1
  1974.     D(printf("exit MachOView -drawSelf::\n");)
  1975. @
  1976.  
  1977.  
  1978. 1.9
  1979. log
  1980. @Use of memory-mapped file object to manage file mapping,
  1981. add display of segment names and use of matrix of buttons
  1982. for choices of what to display.
  1983. @
  1984. text
  1985. @d5 5
  1986. d33 1
  1987. a33 1
  1988. static char rcsident[] = "$Id: MachOView.m,v 1.7 94/01/30 16:27:34 ediger Exp Locker: ediger $";
  1989. d91 6
  1990. d111 2
  1991. d187 6
  1992. d204 3
  1993. d232 3
  1994. d278 1
  1995. a297 1
  1996.     struct addressMapping *spAddrMap = NULL;
  1997. a313 3
  1998.     if (showAddresses || showNames)
  1999.         spAddrMap = (struct addressMapping *)malloc(
  2000.             iSegments * sizeof(struct addressMapping));
  2001. d325 2
  2002. a326 2
  2003.         {    spAddrMap[iCC].baseAddress = [oSegment getBaseAddress];
  2004.             spAddrMap[iCC].endAddress  = [oSegment getUpperAddress];
  2005. d330 1
  2006. a330 1
  2007.             spAddrMap[iCC].segmentName  = [oSegment commandName];
  2008. d335 1
  2009. a335 1
  2010.             {    spAddrMap[iCC].yCoordBase = 
  2011. d337 1
  2012. a337 1
  2013.                 spAddrMap[iCC].yCoordTop  =
  2014. d357 1
  2015. a357 1
  2016.                     spAddrMap[iCC].yCoordBase = yCoord + SEGMENT_GAP;
  2017. d359 1
  2018. a359 1
  2019.                     spAddrMap[iCC].yCoordBase = yCoord;
  2020. d369 1
  2021. a369 1
  2022.                 spAddrMap[iCC].yCoordTop = yCoord;
  2023. d384 1
  2024. a384 1
  2025.         [self spaceLabels:spAddrMap];
  2026. d397 1
  2027. a397 1
  2028.             if (!(spAddrMap[iCC].yCoordBaseLabel < 0.0))
  2029. d399 2
  2030. a400 2
  2031.                     (unsigned int)spAddrMap[iCC].baseAddress);
  2032.                 drawLabel(LABEL_MARGIN, spAddrMap[iCC].yCoordBaseLabel,
  2033. d402 1
  2034. a402 1
  2035.                     spAddrMap[iCC].yCoordBase);
  2036. d405 2
  2037. a406 2
  2038.             sprintf(bvBuffer, "0x%x", (unsigned int)spAddrMap[iCC].endAddress);
  2039.             drawLabel(LABEL_MARGIN, spAddrMap[iCC].yCoordTopLabel, bvBuffer,
  2040. d408 1
  2041. a408 1
  2042.                 spAddrMap[iCC].yCoordTop);
  2043. d421 2
  2044. a422 2
  2045.             [self spaceLabels:spAddrMap];
  2046.         [self spaceNames:spAddrMap];
  2047. d435 1
  2048. a435 1
  2049.                 (spAddrMap[iCC].yCoordBase + spAddrMap[iCC].yCoordTop)/2.0);
  2050. d437 4
  2051. a440 4
  2052.                 spAddrMap[iCC].nameXcoord - 10.0,
  2053.                 spAddrMap[iCC].nameYcoord);
  2054.             PSmoveto(spAddrMap[iCC].nameXcoord, spAddrMap[iCC].nameYcoord);
  2055.             PSshow(spAddrMap[iCC].segmentName);
  2056. a452 3
  2057.     if (NULL != spAddrMap)
  2058.         free(spAddrMap);
  2059.  
  2060. d457 1
  2061. a457 1
  2062. //M+    -spaceLabels:(struct addressMapping *)aspAddrMap
  2063. d464 1
  2064. a464 1
  2065. - spaceLabels:(struct addressMapping *)aspAddrMap
  2066. d470 2
  2067. a471 2
  2068.     lastY = aspAddrMap[iSegments - 1].baseAddress - 20.0;
  2069.     yLastAddress = aspAddrMap[iSegments - 1].yCoordBase - LABEL_HT;
  2070. d475 1
  2071. a475 1
  2072.         if (aspAddrMap[iCC].baseAddress != lastY)
  2073. d477 2
  2074. a478 2
  2075.             if (aspAddrMap[iCC].yCoordBase < yLastAddress + LABEL_HT)
  2076.                 aspAddrMap[iCC].yCoordBaseLabel
  2077. d481 1
  2078. a481 1
  2079.                 aspAddrMap[iCC].yCoordBaseLabel = aspAddrMap[iCC].yCoordBase;
  2080. d483 1
  2081. a483 1
  2082.             yLastAddress = aspAddrMap[iCC].yCoordBaseLabel;
  2083. d487 1
  2084. a487 1
  2085.             aspAddrMap[iCC].yCoordBaseLabel = -1.0;
  2086. d490 2
  2087. a491 2
  2088.         if (aspAddrMap[iCC].yCoordTop < yLastAddress + LABEL_HT)
  2089.             aspAddrMap[iCC].yCoordTopLabel = yLastAddress + (LABEL_HT + 2.0);
  2090. d493 1
  2091. a493 1
  2092.             aspAddrMap[iCC].yCoordTopLabel = aspAddrMap[iCC].yCoordTop;
  2093. d495 2
  2094. a496 2
  2095.         yLastAddress = aspAddrMap[iCC].yCoordTopLabel;
  2096.         lastY = aspAddrMap[iCC].endAddress;
  2097. d506 1
  2098. a506 1
  2099.             if (aspAddrMap[iCC].yCoordTopLabel > yLastAddress)
  2100. d508 1
  2101. a508 1
  2102.                 aspAddrMap[iCC].yCoordTopLabel = yLastAddress;
  2103. d510 1
  2104. a510 1
  2105.             } else if (0.0 > aspAddrMap[iCC].yCoordTopLabel)
  2106. d515 1
  2107. a515 1
  2108.             if (aspAddrMap[iCC].yCoordBaseLabel > yLastAddress)
  2109. d517 1
  2110. a517 1
  2111.                 aspAddrMap[iCC].yCoordBaseLabel = yLastAddress;
  2112. d519 1
  2113. a519 1
  2114.             } else if (0.0 > aspAddrMap[iCC].yCoordBaseLabel)
  2115. d529 1
  2116. a529 1
  2117. //M+    -spaceNames:(struct addressMapping *)aspAddrMap
  2118. d535 1
  2119. a535 1
  2120. - spaceNames:(struct addressMapping *)aspAddrMap
  2121. d540 1
  2122. a540 1
  2123.     yLastAddress = aspAddrMap[iSegments - 1].yCoordBase - LABEL_HT;
  2124. d545 2
  2125. a546 2
  2126.         aspAddrMap[iCC].nameXcoord = NX_WIDTH(&bounds) - LABEL_MARGIN
  2127.             - [theFont getWidthOf:aspAddrMap[iCC].segmentName];
  2128. d549 2
  2129. a550 2
  2130.         aspAddrMap[iCC].nameYcoord =
  2131.             (aspAddrMap[iCC].yCoordBase + aspAddrMap[iCC].yCoordTop)/2.0;
  2132. d553 2
  2133. a554 2
  2134.         if (aspAddrMap[iCC].nameYcoord < yLastAddress + LABEL_HT)
  2135.             aspAddrMap[iCC].nameYcoord = yLastAddress + LABEL_HT;
  2136. d556 1
  2137. a556 1
  2138.         yLastAddress = aspAddrMap[iCC].nameYcoord;
  2139. a558 1
  2140. #ifdef SPAM
  2141. d566 6
  2142. a573 1
  2143. #endif
  2144. d582 6
  2145. d590 1
  2146. @
  2147.  
  2148.  
  2149. 1.8
  2150. log
  2151. @ditched doFont pswrap function, added theFont Font object instance
  2152. to get the benefits of using a Font.
  2153. @
  2154. text
  2155. @d2 1
  2156. a2 1
  2157. #import "MachOView.h"
  2158. a57 1
  2159.         D(printf("    -> 0x%lx - 0x%lx\n", ulUpperAddr, ulBaseAddr);)
  2160. d77 3
  2161. d88 5
  2162. a92 3
  2163.     if (Nil == (theFile = [[[MachOFile alloc]init]fillFromFileNamed:fileName]))
  2164.     {    [cpuType    setStringValue:"Not a"];
  2165.         [cpuSubtype setStringValue:"Mach-O file"];
  2166. d94 10
  2167. a103 3
  2168.         [cpuType    setStringValue:[theFile cpuType]];
  2169.         [cpuSubtype setStringValue:[theFile cpuSubtype]];
  2170.         [[self findSizes] display];
  2171. d110 2
  2172. a115 1
  2173.     {    [sender setTitle:"actual scale"];
  2174. d117 1
  2175. a117 2
  2176.     } else {
  2177.         [sender setTitle:"scale to fit"];
  2178. a118 1
  2179.     }
  2180. d127 2
  2181. a132 1
  2182.     {    [sender setTitle:"no addresses"];
  2183. d134 1
  2184. a134 2
  2185.     } else {
  2186.         [sender setTitle:"addresses"];
  2187. a135 1
  2188.     }
  2189. d142 16
  2190. d159 8
  2191. d170 4
  2192. d175 1
  2193. a175 1
  2194.     {    [sender setTitle:"libraries, too"];
  2195. d177 1
  2196. a178 1
  2197.         [sender setTitle:"no libraries"];
  2198. d180 1
  2199. d183 1
  2200. a183 2
  2201.     if (Nil != theFile)
  2202.         [theFile free];
  2203. d185 1
  2204. a185 6
  2205.     if (showLibraries)
  2206.     {    theFile = [[[[MachOFile alloc] init] considerMappedFiles]
  2207.             fillFromFileNamed:currentFileName];
  2208.     } else {
  2209.         theFile=[[[MachOFile alloc]init]fillFromFileNamed:currentFileName];
  2210.     }
  2211. a186 9
  2212.     if (Nil == theFile)
  2213.     {    [cpuType    setStringValue:"Not a"];
  2214.         [cpuSubtype setStringValue:"Mach-O file"];
  2215.     } else {
  2216.         [cpuType    setStringValue:[theFile cpuType]];
  2217.         [cpuSubtype setStringValue:[theFile cpuSubtype]];
  2218.         [[self findSizes]  display];
  2219.     }
  2220.  
  2221. d201 9
  2222. a234 7
  2223. //M+    -init
  2224. //M-
  2225. - init
  2226. {
  2227.     [super init];
  2228.     return self;
  2229. }
  2230. a235 1
  2231.  
  2232. d237 2
  2233. d246 1
  2234. d250 2
  2235. d253 2
  2236. d265 2
  2237. a266 1
  2238. //        Override of a View method
  2239. d289 1
  2240. a289 1
  2241.     if (showAddresses)
  2242. d302 1
  2243. a302 1
  2244.         if (showAddresses)
  2245. d307 3
  2246. d312 1
  2247. a312 1
  2248.             if (showAddresses)
  2249. d333 1
  2250. a333 1
  2251.             if (showAddresses)
  2252. d346 1
  2253. a346 1
  2254.             if (showAddresses)
  2255. a360 3
  2256.         float lastY = -1.0;
  2257.         float yLastAddress = 0.0 - LABEL_HT;
  2258.  
  2259. d395 28
  2260. d439 5
  2261. d468 1
  2262. a468 1
  2263.             aspAddrMap[iCC].yCoordBaseLabel = -1;
  2264. d506 45
  2265. @
  2266.  
  2267.  
  2268. 1.7
  2269. log
  2270. @mostly correct address spacing
  2271. @
  2272. text
  2273. @d5 3
  2274. d28 1
  2275. a28 1
  2276. static char rcsident[] = "$Id: MachOView.m,v 1.6 94/01/01 23:02:22 ediger Exp Locker: ediger $";
  2277. d225 3
  2278. a252 1
  2279.     doFont(LABEL_HT - LABEL_LEADING);  /* leave some leading */
  2280. d254 2
  2281. d334 1
  2282. a334 1
  2283.         doFont(LABEL_HT - LABEL_LEADING);
  2284. @
  2285.  
  2286.  
  2287. 1.6
  2288. log
  2289. @broke address label spacing calcs into separate method.
  2290. @
  2291. text
  2292. @d5 3
  2293. d25 1
  2294. a25 1
  2295. static char rcsident[] = "$Id: MachOView.m,v 1.5 93/12/31 17:32:28 ediger Exp Locker: ediger $";
  2296. a41 2
  2297.     D(printf("enter MachOView -findSizes\n");)
  2298.  
  2299. a45 1
  2300.     D(printf("MachOView -findSizes, %d segments\n", iSegments);)
  2301. a57 4
  2302.     D(printf("MachOView -findSizes, hi 0x%lx, lo 0x%lx, sum 0x%lx\n",
  2303.         hiAddr, loAddr, sumAddr);
  2304.       printf("exit MachOView -findSizes\n");)
  2305.  
  2306. a73 1
  2307.     D(printf("enter MachOView -openFileNamed:\"%s\"\n", fileName);)
  2308. a91 1
  2309.     D(printf("exit MachOView -openFileNamed:\"%s\"\n", fileName);)
  2310. a177 9
  2311. //M+    -windowDidResize:sender
  2312. //    EDITORIAL
  2313. //        one of the Window delegate methods
  2314. //M-
  2315. /*- windowDidResize:sender
  2316. {
  2317.     return self;
  2318. }*/
  2319.  
  2320. d233 1
  2321. a233 1
  2322.     float xCoord, yCoord;
  2323. d246 2
  2324. a247 2
  2325.     PSsetlinewidth(5.0);
  2326.     doFont(9.0);
  2327. d255 1
  2328. a255 1
  2329.     xCoord = NX_WIDTH(&bounds)/2.0 - (float)iSegments/2.0*8.0;
  2330. d257 1
  2331. d284 1
  2332. d286 5
  2333. a290 1
  2334.             PSmoveto(xCoord, yCoord);
  2335. d292 5
  2336. a296 1
  2337.                 spAddrMap[iCC].yCoordBase = yCoord;
  2338. d298 3
  2339. a300 3
  2340.             yCoord += smashedSlope*
  2341.                 (float)([oSegment getUpperAddress]
  2342.                     - [oSegment getBaseAddress]) + smashedYintercept;
  2343. d303 1
  2344. d307 1
  2345. d311 1
  2346. a311 1
  2347.         xCoord += 8.0;
  2348. d327 1
  2349. a327 1
  2350.         doFont(LABEL_HT);
  2351. d330 1
  2352. a330 1
  2353.         xCoord = NX_WIDTH(&bounds)/2.0 - (float)iSegments/2.0*8.0;
  2354. d336 1
  2355. a336 1
  2356.             if (!(spAddrMap[iCC].baseAddress < 0.0))
  2357. d339 3
  2358. a341 2
  2359.                 drawLabel(2.0, spAddrMap[iCC].yCoordBaseLabel, bvBuffer,
  2360.                     xCoord - 2.0, spAddrMap[iCC].yCoordBase);
  2361. d345 3
  2362. a347 2
  2363.             drawLabel(2.0, spAddrMap[iCC].yCoordTopLabel, bvBuffer,
  2364.                 xCoord - 2.0, spAddrMap[iCC].yCoordTop);
  2365. d349 1
  2366. a349 1
  2367.             xCoord += 8.0;
  2368. d356 8
  2369. d376 1
  2370. a376 1
  2371.     float yLastAddress = 5.0;
  2372. d379 2
  2373. a380 1
  2374.     lastY = aspAddrMap[0].baseAddress - 20.0;
  2375. d408 26
  2376. a433 2
  2377.     if (lastY > NX_HEIGHT(&bounds))
  2378.         printf("Need to rescale...\n");
  2379. @
  2380.  
  2381.  
  2382. 1.5
  2383. log
  2384. @better address label spacing
  2385. @
  2386. text
  2387. @d5 3
  2388. d22 1
  2389. a22 1
  2390. static char rcsident[] = "$Id: MachOView.m,v 1.3 93/12/30 19:01:37 ediger Exp Locker: ediger $";
  2391. d188 1
  2392. a188 1
  2393. - windowDidResize:sender
  2394. d191 1
  2395. a191 1
  2396. }
  2397. d285 1
  2398. a285 1
  2399.             {    spAddrMap[iCC].yCoord  = 
  2400. d287 1
  2401. a287 1
  2402.                 spAddrMap[iCC].yCoord2 =
  2403. d301 1
  2404. a301 1
  2405.                 spAddrMap[iCC].yCoord  = yCoord;
  2406. d309 1
  2407. a309 1
  2408.                 spAddrMap[iCC].yCoord2 = yCoord;
  2409. d319 1
  2410. a321 1
  2411.         /* label the ends of each memory segment with its address */
  2412. d325 3
  2413. d339 6
  2414. a344 3
  2415.             if (spAddrMap[iCC].baseAddress != lastY)
  2416.             {
  2417.                 sprintf(bvBuffer, "0x%x", spAddrMap[iCC].baseAddress);
  2418. d346 3
  2419. a348 4
  2420.                 if (spAddrMap[iCC].yCoord < yLastAddress + LABEL_HT)
  2421.                     yLastAddress += (LABEL_HT + 2.0);
  2422.                 else
  2423.                     yLastAddress = spAddrMap[iCC].yCoord;
  2424. d350 2
  2425. a351 3
  2426.                 drawLabel(2.0, yLastAddress, bvBuffer, xCoord - 2.0,
  2427.                     spAddrMap[iCC].yCoord);
  2428.             }
  2429. d353 1
  2430. a353 1
  2431.             sprintf(bvBuffer, "0x%x", spAddrMap[iCC].endAddress);
  2432. d355 26
  2433. a380 2
  2434.             if (spAddrMap[iCC].yCoord2 < yLastAddress + LABEL_HT)
  2435.                 yLastAddress += (LABEL_HT + 2.0);
  2436. d382 1
  2437. a382 1
  2438.                 yLastAddress = spAddrMap[iCC].yCoord2;
  2439. d384 1
  2440. a384 2
  2441.             drawLabel(2.0, yLastAddress, bvBuffer, xCoord - 2.0,
  2442.                 spAddrMap[iCC].yCoord2);
  2443. d386 3
  2444. a388 2
  2445.             xCoord += 8.0;
  2446.             lastY = spAddrMap[iCC].endAddress;
  2447. d391 4
  2448. a394 1
  2449.         PSstroke();
  2450. d396 2
  2451. a397 3
  2452.         if (NULL != spAddrMap)
  2453.             free(spAddrMap);
  2454.  
  2455. d400 3
  2456. a402 1
  2457.     D(printf("exit MachOView -drawSelf::\n");)
  2458. @
  2459.  
  2460.  
  2461. 1.4
  2462. log
  2463. @Address labeling cleaned up
  2464. @
  2465. text
  2466. @d201 1
  2467. a201 1
  2468.     ht = NX_HEIGHT(&bounds) - 10.0;
  2469. d320 1
  2470. a320 1
  2471.         float yInterval, yLastAddress = -1.0;
  2472. d324 1
  2473. a324 1
  2474.         doFont(10.0);
  2475. a327 1
  2476.         yInterval = (NX_HEIGHT(&bounds) - 20.0)/(float)iSegments;
  2477. d330 2
  2478. a331 1
  2479.         {    char bvBuffer[256];
  2480. d334 2
  2481. a335 1
  2482.             {    sprintf(bvBuffer, "0x%x", spAddrMap[iCC].baseAddress);
  2483. d337 7
  2484. a343 3
  2485.                 if (spAddrMap[iCC].yCoord - 
  2486.                 drawLabel(2.0, yCoord, bvBuffer,
  2487.                      xCoord - 2.0 , spAddrMap[iCC].yCoord);
  2488. d345 1
  2489. a345 1
  2490.             yCoord += yInterval;
  2491. d347 9
  2492. a355 2
  2493.             drawLabel(2.0, yCoord, bvBuffer,
  2494.                 xCoord - 2.0, spAddrMap[iCC].yCoord2);
  2495. @
  2496.  
  2497.  
  2498. 1.3
  2499. log
  2500. @support for showing upper and lower addresses
  2501. of memory mapped segments.
  2502. @
  2503. text
  2504. @d5 4
  2505. d19 1
  2506. a19 1
  2507. static char rcsident[] = "$Id: MachOView.m,v 1.2 93/12/19 14:31:43 ediger Exp Locker: ediger $";
  2508. d26 1
  2509. d70 1
  2510. a101 1
  2511.     BOOL settingChanged = FALSE;
  2512. a104 1
  2513.         settingChanged = TRUE;
  2514. a107 1
  2515.         settingChanged = TRUE;
  2516. d110 1
  2517. a110 2
  2518.     if (settingChanged)
  2519.         [self display];
  2520. a119 2
  2521.     BOOL settingChanged = FALSE;
  2522.  
  2523. a122 1
  2524.         settingChanged = TRUE;
  2525. a125 1
  2526.         settingChanged = TRUE;
  2527. d128 1
  2528. a128 2
  2529.     if (settingChanged)
  2530.         [self display];
  2531. a136 2
  2532.     BOOL settingChanged = FALSE;
  2533.  
  2534. a139 1
  2535.         settingChanged = TRUE;
  2536. a142 1
  2537.         settingChanged = TRUE;
  2538. d145 2
  2539. a146 4
  2540.     if (settingChanged)
  2541.     {
  2542.         if (Nil != theFile)
  2543.             [theFile free];
  2544. d148 6
  2545. a153 5
  2546.         if (showLibraries)
  2547.             theFile = [[[[MachOFile alloc] init] considerMappedFiles]
  2548.                 fillFromFileNamed:currentFileName];
  2549.         else
  2550.             theFile=[[[MachOFile alloc]init]fillFromFileNamed:currentFileName];
  2551. d155 7
  2552. a161 8
  2553.         if (Nil == theFile)
  2554.         {    [cpuType    setStringValue:"Not a"];
  2555.             [cpuSubtype setStringValue:"Mach-O file"];
  2556.         } else {
  2557.             [cpuType    setStringValue:[theFile cpuType]];
  2558.             [cpuSubtype setStringValue:[theFile cpuSubtype]];
  2559.             [[self findSizes]  display];
  2560.         }
  2561. a186 4
  2562.     D(printf("MachOView -windowDidResize:\n");)
  2563.  
  2564.     //[self display];
  2565.  
  2566. d203 1
  2567. a203 1
  2568.     scaleSlope = ht/(float)(hiAddr - loAddr);
  2569. d206 1
  2570. a206 1
  2571.     smashedSlope = ht/falseSize;
  2572. d245 1
  2573. a245 1
  2574.     float xCoord, yCoord, yInterval;
  2575. a247 6
  2576.     D(printf("enter MachOView -drawSelf::\n");
  2577.       printf("width %f, height %f\n", NX_WIDTH(&bounds),
  2578.         NX_HEIGHT(&bounds));
  2579.       printf("sum of addresses 0x%lx\n", sumAddr);
  2580.     )
  2581.  
  2582. a249 5
  2583.     D(
  2584.       printf("scaled slope %f, intercept %f\n", scaleSlope, scaleYintercept);
  2585.       printf("smashed slope %f, intercept %f\n", smashedSlope, smashedYintercept);
  2586.     )
  2587.  
  2588. d319 2
  2589. d324 1
  2590. a324 1
  2591.         doFont(9.0);
  2592. d333 7
  2593. a339 3
  2594.             sprintf(bvBuffer, "0x%x", spAddrMap[iCC].baseAddress);
  2595.             drawLabel(2.0, yCoord, bvBuffer,
  2596.                  xCoord - 2.0 , spAddrMap[iCC].yCoord);
  2597. d343 1
  2598. a343 1
  2599.                 xCoord - 10.0, spAddrMap[iCC].yCoord2);
  2600. d345 1
  2601. @
  2602.  
  2603.  
  2604. 1.2
  2605. log
  2606. @corrected scaling and inclusion of mapped segments of library files
  2607. @
  2608. text
  2609. @d5 3
  2610. d15 1
  2611. a15 1
  2612. static char rcsident[] = "$Id: MachOView.m,v 1.1 93/12/19 12:57:04 ediger Exp Locker: ediger $";
  2613. d24 1
  2614. a24 1
  2615. //        openor re-open the Mach-O file being represented.
  2616. d98 1
  2617. a98 2
  2618.     {
  2619.         [sender setTitle:"actual scale"];
  2620. d113 23
  2621. d143 1
  2622. a143 2
  2623.     {
  2624.         [sender setTitle:"libraries, too"];
  2625. a183 2
  2626.     D(printf("enter MachOView -windowWillClose:%x\n", (unsigned int)sender);)
  2627.  
  2628. a186 1
  2629.     D(printf("exit MachOView -windowWillClose:%x\n", (unsigned int)sender);)
  2630. a213 2
  2631.     D(printf("enter MachOView -rescale\n");)
  2632.  
  2633. a221 2
  2634.     D(printf("exit MachOView -rescale\n");)
  2635.  
  2636. a228 1
  2637.     D(printf("MachOView -init\n");)
  2638. a240 1
  2639.     D(printf("enter MachOView -initFrame:\n");)
  2640. d244 1
  2641. d246 1
  2642. a246 1
  2643.     D(printf("exit  MachOView -initFrame:\n");)
  2644. d258 2
  2645. a259 1
  2646.     float xCoord, yCoord;
  2647. d283 1
  2648. d286 3
  2649. a288 1
  2650.     D(printf("MachOView -drawSelf::, %d segments\n", iSegments);)
  2651. d295 1
  2652. a295 1
  2653.     for (iCC = [theFile mappedSegments] - 1; iCC > -1; --iCC)
  2654. d298 5
  2655. d305 7
  2656. a313 2
  2657.             D(printf("moveto (%f, %f)\n", xCoord,
  2658.                 scaleSlope*(float)[oSegment getBaseAddress] + scaleYintercept);)
  2659. a316 2
  2660.             D(printf("lineto (%f, %f)\n", xCoord,
  2661.                 scaleSlope*(float)[oSegment getUpperAddress] + scaleYintercept);)
  2662. a317 5
  2663.             D(printf("    -> (0x%lx - 0x%lx = 0x%lx)\n",
  2664.                 [oSegment getUpperAddress],
  2665.                 [oSegment getBaseAddress],
  2666.                 [oSegment getUpperAddress] - [oSegment getBaseAddress]
  2667.             );)
  2668. d321 2
  2669. a322 1
  2670.             D(printf("moveto (%f, %f)\n", xCoord, yCoord);)
  2671. d329 2
  2672. a330 1
  2673.             D(printf("lineto (%f, %f)\n", xCoord, yCoord);)
  2674. a331 5
  2675.             D(printf("    -> (0x%lx - 0x%lx = 0x%lx)\n",
  2676.                 [oSegment getUpperAddress],
  2677.                 [oSegment getBaseAddress],
  2678.                 [oSegment getUpperAddress] - [oSegment getBaseAddress]
  2679.             );)
  2680. d340 32
  2681. a379 1
  2682.     D(printf("MachOView -free\n");)
  2683. d383 1
  2684. a390 1
  2685.     D(printf("MachOView, -show:%x\n", (unsigned int)sender);)
  2686. d392 1
  2687. @
  2688.  
  2689.  
  2690. 1.1
  2691. log
  2692. @Initial revision
  2693. @
  2694. text
  2695. @d4 4
  2696. a7 1
  2697. /* $Log$
  2698. d12 1
  2699. a12 1
  2700. static char rcsident[] = "$Id$";
  2701. d14 9
  2702. d30 3
  2703. d47 1
  2704. a47 1
  2705.     D(    printf("MachOView -findSizes, hi 0x%x, lo 0x%x, sum 0x%x\n",
  2706. d49 1
  2707. a49 1
  2708.         printf("exit MachOView -findSizes\n");)
  2709. d54 2
  2710. d61 2
  2711. d74 1
  2712. a74 2
  2713.     currentFileName = malloc(strlen(fileName) + 1);
  2714.     strcpy(currentFileName, fileName);
  2715. d82 1
  2716. a82 2
  2717.         [self findSizes];
  2718.         [self windowDidResize:self];
  2719. d89 2
  2720. a105 2
  2721.     {
  2722.         [self windowDidResize:self];
  2723. a106 1
  2724.     }
  2725. d111 2
  2726. d119 1
  2727. a119 1
  2728.         [sender setTitle:"no libraries"];
  2729. d123 1
  2730. a123 1
  2731.         [sender setTitle:"libraries, too"];
  2732. d145 1
  2733. a145 3
  2734.             [self findSizes];
  2735.             [self windowDidResize:self];
  2736.             [self display];
  2737. d152 6
  2738. d169 4
  2739. d175 15
  2740. d191 1
  2741. d193 1
  2742. a193 1
  2743.     D(printf("MachOView -windowDidResize:\n");)
  2744. d197 2
  2745. a198 9
  2746.     if (toScale)
  2747.     {
  2748.         slope = ht/(float)(hiAddr - loAddr);
  2749.         yintercept = 5.0 - slope*(float)loAddr;
  2750.     } else {
  2751.         float falseSize = (float)sumAddr;
  2752.         slope = ht/falseSize;
  2753.         yintercept = 0.0;
  2754.     }
  2755. d200 2
  2756. a201 2
  2757.     D(printf("MachOView -windowDidResize:, slope %f, intercept %f\n",
  2758.         slope, yintercept);)
  2759. d203 2
  2760. d208 2
  2761. d218 5
  2762. a226 2
  2763.     loAddr = (unsigned long)-1;  /* cheat */
  2764.     sumAddr = hiAddr = 0;
  2765. d234 5
  2766. a247 1
  2767.       printf("slope %f, intercept %f\n", slope, yintercept);
  2768. d250 7
  2769. d281 1
  2770. a281 1
  2771.                 slope*(float)[oSegment getBaseAddress] + yintercept);
  2772. d283 1
  2773. a283 1
  2774.                 slope*(float)[oSegment getBaseAddress] + yintercept);)
  2775. d286 1
  2776. a286 1
  2777.                 slope*(float)[oSegment getUpperAddress] + yintercept);
  2778. d288 1
  2779. a288 1
  2780.                 slope*(float)[oSegment getUpperAddress] + yintercept);)
  2781. d300 1
  2782. a300 1
  2783.             yCoord += slope*
  2784. d302 1
  2785. a302 1
  2786.                     - [oSegment getBaseAddress]) + yintercept;
  2787. d324 2
  2788. d335 2
  2789. @
  2790.