home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Programming / GDBbundle-1.0-MIS / src / TextEdit / GdbBundle.bproj / Frame.m < prev    next >
Encoding:
Text File  |  1997-04-18  |  3.3 KB  |  134 lines

  1. /* Frame.m created by ovidiu on Sun 23-Mar-1997 */
  2.  
  3. #import <Foundation/Foundation.h>
  4. #import "GdbDisplayController.h"
  5. #import "DebuggerController_Protocol.h"
  6. #import "NSScannerAddition.h"
  7. #import "Stack.h"
  8. #import "Frame.h"
  9. #import "Variable.h"
  10.  
  11. @implementation Frame
  12.  
  13. + (Frame*)frameWithAnnotation:(NSString*)annotation stack:(Stack*)theStack
  14. {
  15.   NSScanner* scanner = [NSScanner scannerWithString:annotation];
  16.  
  17.   Frame* frame = [[self new] autorelease];
  18.  
  19.   if (![scanner scanAfterString:@"\032\032frame-begin"])
  20.     return nil;
  21.   [scanner scanInt:&frame->frameNumber];
  22.   [scanner scanHexInt:&frame->frameAddress];
  23.  
  24.   if (![scanner scanAfterString:@"\032\032frame-function-name\n"])
  25.     return nil;
  26.   if (![scanner scanUpToString:@"\n" intoString:&(frame->functionName)])
  27.     return nil;
  28.   [frame->functionName retain];
  29.  
  30.   [scanner scanAfterString:@"\032\032frame-source-file\n"];
  31.   [scanner scanUpToString:@"\n" intoString:&(frame->fileName)];
  32.   [frame->fileName retain];
  33.  
  34.   frame->stack = theStack;
  35.   return frame;
  36. }
  37.  
  38. - init
  39. {
  40.   self = [super init];
  41.   variables = [NSMutableArray new];
  42.   return self;
  43. }
  44.  
  45. - (void)dealloc
  46. {
  47.   [functionName release];
  48.   [super dealloc];
  49. }
  50.  
  51. - (void)invalidateCurrentVariables
  52. {
  53.   validVariables = NO;
  54. }
  55.  
  56. - (void)getVariablesFromGDB
  57. {
  58. #if 1
  59.   [variables removeAllObjects];
  60.   if (!validVariables) {
  61.     validVariables = YES;
  62. #else
  63.   if (![variables count]) {
  64. #endif
  65. //    NSLog (@"getVariablesFromGDB: frame number = %d", frameNumber);
  66.     [[self gdbController] executeGDBCommand:@"info typed-variables"
  67.                                       annotate:NO
  68.                                   notifyObject:self
  69.                                       selector:@selector(frameArguments:type:)];
  70.   }
  71. }
  72.  
  73. - (void)frameArguments:(NSString*)gdbOutput type:(GdbOutputType)type
  74. {
  75.   int i, count;
  76.   id gdbController;
  77.  
  78.   if (type != GDB_OUTPUT_ANNOTATION)
  79.     return;
  80.  
  81.   gdbController = [self gdbController];
  82.   [variables release];
  83.   variables = [[Variable variablesFromDescription:gdbOutput] retain];
  84.  
  85.   for (i = 0, count = [variables count]; i < count; i++)
  86.     [[variables objectAtIndex:i] setGdbDisplayController:gdbController];
  87.  
  88.   validVariables = YES;
  89.   [gdbController updateCurrentFrame];
  90. }
  91.  
  92. - (void)setFilename:(NSString*)_fileName
  93.           startLine:(int)_startLine
  94.             endLine:(int)_endLine
  95. {
  96.   [_fileName retain];
  97.   [fileName release];
  98.   fileName = _fileName;
  99.   startLine = _startLine;
  100.   endLine = _endLine;
  101. }
  102.  
  103. - (Variable*)variableAtIndex:(int)index
  104. {
  105.   return [variables objectAtIndex:index];
  106. }
  107.  
  108. - (void)selectLineInFile
  109. {
  110. //  NSLog (@"_selectLineInFile: gdbController = %x, fileName = %@, "
  111. //         @"startLine = %d, endLine = %d",
  112. //         [self gdbController], fileName, startLine, endLine);
  113.  
  114.   [stack setSelectedFrame:frameNumber];
  115.   if (fileName)
  116.     [[self gdbController] selectInFile:fileName startLine:startLine endLine:endLine];
  117. }
  118.  
  119. - (int)frameNumber            { return frameNumber; }
  120. - (NSString*)functionName        { return functionName; }
  121. - (NSString*)fileName            { return fileName; }
  122. - (GdbDisplayController*)gdbController    { return [stack gdbController]; }
  123. - (int)numberOfVariables        { return [variables count]; }
  124. - (BOOL)variablesAreValid        { return validVariables; }
  125. - (int)startLine            { return startLine; }
  126. - (int)endLine                { return endLine; }
  127.  
  128. - (NSString*)description
  129. {
  130.   return functionName;
  131. }
  132.  
  133. @end
  134.