How test whether Mac app is running in Xcode?

2013-10-15 Thread Bill Cheeseman
Is there any way to test whether an application is running in Xcode or some 
other compiler/debugger, and not as a free-standing application? And then to 
get the name of the compiler/debugger?

I'm currently testing #ifdef DEBUG and simply assuming that Xcode is the only 
compiler/debugger available on the Mac. But I understand that isn't true.

-- 

Bill Cheeseman

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How test whether Mac app is running in Xcode?

2013-10-15 Thread Daniel Höpfl

On 2013-10-15 13:12, Bill Cheeseman wrote:

Is there any way to test whether an application is running in Xcode or
some other compiler/debugger, and not as a free-standing application?
And then to get the name of the compiler/debugger?

I'm currently testing #ifdef DEBUG and simply assuming that Xcode is
the only compiler/debugger available on the Mac. But I understand that
isn't true.


#ifdef DEBUG is a compile time switch. You can run apps compiled with 
DEBUG defined outside the debugger, too.


If you really need to know if you are running with a debugger attached, 
the following might work (I did not test it!):


- fork into a new process, IPC to parent in place.
- regularly try:
int err = ptrace(PT_ATTACH, pid, (caddr_t)0, 0);
if (!err) ptrace(PT_CONTINUE, pid, (caddr_t)1, 0)
if (err == EBUSY) {
// Use IPC to inform parent: A debugger is attached.
}

I don't think there is a way to get the name of the process that is 
attached as debugger.


HTH,
   Daniel

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How test whether Mac app is running in Xcode?

2013-10-15 Thread Half Activist
I'd suggest you give a look at getppid(), and try to retrieve the parent's path 
using sysctl with KERN_PROCARGS2.
For more info try google: sysctl KERN_PROCARGS2.

Regards.

On Oct 15, 2013, at 1:12 PM, cocoa-dev-requ...@lists.apple.com wrote:

 Date: Tue, 15 Oct 2013 07:12:11 -0400
 From: Bill Cheeseman wjcheese...@gmail.com
 To: Cocoa-Dev Cocoa-Dev Mail cocoa-dev@lists.apple.com
 Subject: How test whether Mac app is running in Xcode?
 
 
 Is there any way to test whether an application is running in Xcode or some 
 other compiler/debugger, and not as a free-standing application? And then to 
 get the name of the compiler/debugger?
 
 I'm currently testing #ifdef DEBUG and simply assuming that Xcode is the only 
 compiler/debugger available on the Mac. But I understand that isn't true.
 
 -- 
 
 Bill Cheeseman

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How test whether Mac app is running in Xcode?

2013-10-15 Thread Jens Alfke

On Oct 15, 2013, at 4:12 AM, Bill Cheeseman wjcheese...@gmail.com wrote:

 Is there any way to test whether an application is running in Xcode or some 
 other compiler/debugger, and not as a free-standing application? And then to 
 get the name of the compiler/debugger?

Just curious: What is it you want to do with that information?

Keep in mind that technically there is no such thing as a ‘free-standing 
application’. Every user process has a parent. When you launch an app through 
‘normal’ means, like from the Finder or Dock, its parent will be the launchd 
process that owns your login session. It’s also possible for an app’s parent 
process to be a tool like Instruments that isn’t technically a debugger. Or you 
could launch the app from a shell in which case its parent process is that 
shell.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How test whether Mac app is running in Xcode?

2013-10-15 Thread Bill Cheeseman

On Oct 15, 2013, at 10:48 AM, Jens Alfke j...@mooseyard.com wrote:

 
 On Oct 15, 2013, at 4:12 AM, Bill Cheeseman wjcheese...@gmail.com wrote:
 
 Is there any way to test whether an application is running in Xcode or some 
 other compiler/debugger, and not as a free-standing application? And then to 
 get the name of the compiler/debugger?
 
 Just curious: What is it you want to do with that information?
 
 Keep in mind that technically there is no such thing as a ‘free-standing 
 application’. Every user process has a parent. When you launch an app through 
 ‘normal’ means, like from the Finder or Dock, its parent will be the launchd 
 process that owns your login session. It’s also possible for an app’s parent 
 process to be a tool like Instruments that isn’t technically a debugger. Or 
 you could launch the app from a shell in which case its parent process is 
 that shell.


Jens, 

I can't talk about the why? part of my question in public because it's an 
issue unique to Mavericks. Let me just say that a certain common category of 
applications is going to want to know how to do this in Mavericks, for good and 
sufficient reason.

But the is it running in Xcode (or Instruments or whatever)? question is not 
unique to Mavericks. What I find interesting is that NSWorkspace's 
-frontmostApplication and -menuBarOwningApplication and NSRunningApplication's 
currentApplication return different results in different circumstances. For 
example, when I launch an application I'm developing in debug mode in Xcode, 
two of these methods return my application and one of them returns Xcode. If I 
then call [NSApp activateIgnoringOtherApps:] and call these methods again, the 
mix changes -- they all return my application. I can't find a way to get my 
application back into the mode (?) it was in at launch so as to ensure that one 
of the methods consistently returns Xcode. My guess is that the fact that one 
of them returns Xcode at launch is a bug that nobody has noticed, and I 
therefore shouldn't rely on it anyway (otherwise, I would grab it and save it 
at launch time).

So I need a reliable way to find out. I know there is a way, because a certain 
function that is new in Mavericks does it behind the scenes and reports the 
result in a system alert, where the question whether it is running in Xcode (or 
whatever) is crucial. But I can't get the result using that function -- at 
least not in a straightforward way.

Bill

-- 

Bill Cheeseman

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How test whether Mac app is running in Xcode?

2013-10-15 Thread Jens Alfke

On Oct 15, 2013, at 9:10 AM, Bill Cheeseman wjcheese...@gmail.com wrote:

 I can't talk about the why? part of my question in public because it's an 
 issue unique to Mavericks. Let me just say that a certain common category of 
 applications is going to want to know how to do this in Mavericks, for good 
 and sufficient reason.

OK … sounds like you should take the question to Apple’s developer forums, 
then, where you can talk about 10.9.

 What I find interesting is that NSWorkspace's -frontmostApplication and 
 -menuBarOwningApplication and NSRunningApplication's currentApplication 
 return different results in different circumstances.  … My guess is that the 
 fact that one of them returns Xcode at launch is a bug that nobody has 
 noticed, and I therefore shouldn't rely on it anyway

I agree, it’s almost certainly a bug.

 So I need a reliable way to find out. I know there is a way

There’s definitely a way. As an existence proof, the first thing I thought of 
when you asked is the infamous behavior of iTunes — if you attach a debugger to 
iTunes and then try to play any DRM-protected content, iTunes will 
intentionally crash. It’s a way to deter people from either extracting the 
decoded media data, or reverse-engineering the DRM. (Probably not a very 
foolproof way...)

—Jens

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How test whether Mac app is running in Xcode?

2013-10-15 Thread Simone Tellini

Il giorno 15/ott/2013, alle ore 18:10, Bill Cheeseman wjcheese...@gmail.com 
ha scritto:

 But the is it running in Xcode (or Instruments or whatever)? question is 
 not unique to Mavericks. What I find interesting is that NSWorkspace's 
 -frontmostApplication and -menuBarOwningApplication and 
 NSRunningApplication's currentApplication return different results in 
 different circumstances. 


could you solve this problem simply by setting a specific argument/environment 
variable in your scheme and checking for its existence at runtime?

Otherwise, there's also this: 
https://developer.apple.com/library/mac/qa/qa1361/_index.html 

-- 
Simone Tellini
http://tellini.info




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How test whether Mac app is running in Xcode?

2013-10-15 Thread Jean-Daniel Dupas

Le 15 oct. 2013 à 18:50, Jens Alfke j...@mooseyard.com a écrit :

 
 On Oct 15, 2013, at 9:10 AM, Bill Cheeseman wjcheese...@gmail.com wrote:
 
 I can't talk about the why? part of my question in public because it's an 
 issue unique to Mavericks. Let me just say that a certain common category of 
 applications is going to want to know how to do this in Mavericks, for good 
 and sufficient reason.
 
 OK … sounds like you should take the question to Apple’s developer forums, 
 then, where you can talk about 10.9.
 
 What I find interesting is that NSWorkspace's -frontmostApplication and 
 -menuBarOwningApplication and NSRunningApplication's currentApplication 
 return different results in different circumstances.  … My guess is that the 
 fact that one of them returns Xcode at launch is a bug that nobody has 
 noticed, and I therefore shouldn't rely on it anyway
 
 I agree, it’s almost certainly a bug.
 
 So I need a reliable way to find out. I know there is a way
 
 There’s definitely a way. As an existence proof, the first thing I thought of 
 when you asked is the infamous behavior of iTunes — if you attach a debugger 
 to iTunes and then try to play any DRM-protected content, iTunes will 
 intentionally crash. It’s a way to deter people from either extracting the 
 decoded media data, or reverse-engineering the DRM. (Probably not a very 
 foolproof way...)


Nope.
The crash is not cause by iTunes.
iTunes tells the kernel it should not be attached, and the kernel kills it if 
somebody try to do it. iTunes never knows if somebody try to attach debug it.

-- Jean-Daniel





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com