• 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
gdb problem with DYLD_INSERT_LIBRARIES and pthread in dylib constructor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gdb problem with DYLD_INSERT_LIBRARIES and pthread in dylib constructor


  • Subject: gdb problem with DYLD_INSERT_LIBRARIES and pthread in dylib constructor
  • From: Jeff Johnson <email@hidden>
  • Date: Wed, 15 Jul 2009 14:07:04 -0500

Hi. I'm experiencing a strange problem with gdb. I'm testing a version of a dylib that has a long-running pthread created in the constructor. This can be simulated with the example code at the end. If I use DYLD_INSERT_LIBRARIES to load the dylib on the command line, it works fine:

$ DYLD_INSERT_LIBRARIES=/path/to/my.dylib /path/to/the/executable

However, I'm unable to run it in gdb:

$ gdb /path/to/the/executable
(gdb) set environment DYLD_INSERT_LIBRARIES=/path/to/my.dylib
(gdb) run

When I do that, I always get the following:

/bin/bash: /usr/bin/arch: Operation not supported
/bin/bash: /usr/bin/arch: Unknown error: 0
Program exited with code 01.

On the other hand, if I uncomment the pthread_join line, it works fine. In other words, if the pthread is done before the constructor returns, it works, but if the pthread is still running, it dies. The nature of the executable doesn't seem to matter, it can be as simple as this:

int main(int argc, char *argv[]) {
	while (1) ;
	return 0;
}

Is there something I need to do in gdb to get this to work? Or am I doing something wrong in the dylib? Are pthreads not supported in constructors?

-Jeff


#include <pthread.h> #include <unistd.h>

static void *MyThread(void *arg) {
	sleep(10);
	return NULL;
}

static __attribute__((constructor)) int LoadMyStuff(void) {
static int didLoad = 0;
if (!didLoad) {
didLoad = 1;
pthread_t aThread;
pthread_create(&aThread, NULL, MyThread, NULL);
//pthread_join(aThread, NULL);
}
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: gdb problem with DYLD_INSERT_LIBRARIES and pthread in dylib constructor
      • From: Greg Parker <email@hidden>
  • Prev by Date: Re: 2048 bug
  • Next by Date: Re: gdb problem with DYLD_INSERT_LIBRARIES and pthread in dylib constructor
  • Previous by thread: Re: 2048 bug
  • Next by thread: Re: gdb problem with DYLD_INSERT_LIBRARIES and pthread in dylib constructor
  • Index(es):
    • Date
    • Thread