• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
debugging a program raises an exception when reading a NSPipe ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

debugging a program raises an exception when reading a NSPipe ?


  • Subject: debugging a program raises an exception when reading a NSPipe ?
  • From: AurĂ©lien HugelĂ© <email@hidden>
  • Date: Tue, 17 Aug 2004 12:40:53 +0200

Hi lists, sorry for cross posting but i don' really know if my problem
is Cocoa or GDB...

here is the problem :

my program works fairly well, but it does need to run subtasks using a
NSTask. I get the result of the task using a NSPipe  and
fileHandleForReading to read.
Everything is fine until i run the debugger. With the debugger,
NSFileHandle raises an exception EVERY TIME, (and never raises it when
the program is not in debugged )

i've extracted the piece of code, to produce a simple test that just do
"ls -l" as a subtask to see in it still raises exception, and yes it
raises it too !!

here is the code :

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

     NSTask *task = [[NSTask alloc] init];
     NSPipe *pipe = [NSPipe pipe];
     NSFileHandle *readHandle = [pipe fileHandleForReading];
     NSData *listResultData = nil;

     // write handle is closed to this process
     // get the result of this task to the pipe
     [task setStandardOutput:pipe];
     [task setStandardError:[task standardOutput]];
     NSArray* args = [NSArray arrayWithObject:@"-l"];
     [task setArguments:args];
     [task setLaunchPath:@"/bin/ls"];

     [task launch];

     //read the output of the task  list
     NSMutableData* listResultDataComplete = [[NSMutableData alloc]
init];
     while((listResultData = [readHandle availableData]) &&
[listResultData length]) {
         [listResultDataComplete appendData:listResultData];
     }
     // we could have used this but there seems to be a risk with LARGE
results ?
     //listResultDataComplete = [readHandle readDataToEndOfFile]; //
there is a risk to fill the buffer ?


     NSString* resultString = [[[NSString alloc]
initWithData:listResultDataComplete encoding:NSASCIIStringEncoding]
autorelease];

     NSLog(@"result of subtask:\n%@",resultString);
     [pool release];
     return 0;
}


As you can see it is pretty simple ! and i insist that there is no bug
(well... i'm pretty sure there is none ;) since everything is ok when
not in debugger) in this code. The Exception is caused BY THE DEBUGGER
!

debug this program as a normal user ("gdb test", then "run"), it will
break on exception :
*** Uncaught exception: <NSFileHandleOperationException> ***
-[NSConcreteFileHandle availableData]: Interrupted system call

the backtrace is :
#0  0x90a5c740 in _NSRaiseError ()
#1  0x90a5c624 in +[NSException raise:format:] ()
#2  0x90a73d88 in -[NSConcreteFileHandle availableData] ()


can anybody help me to debug this program ? is it an XCode/GDB setting ?
I'm completely lost without debugger, and i can't even really debug my
program since it breaks at the very beginning because of this
problem...

thanks !
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: debugging a program raises an exception when reading a NSPipe ?
      • From: Jim Ingham <email@hidden>
  • Prev by Date: Re: Xcode 1.5 - how to select Find results?
  • Next by Date: Re: Xcode 1.5 - how to select Find results?
  • Previous by thread: Re: /usr/bin/cvs overwritten by Xcode 1.5 installer with outdated version
  • Next by thread: Re: debugging a program raises an exception when reading a NSPipe ?
  • Index(es):
    • Date
    • Thread