Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-10831]iOS 6: Fixing logging for device builds #2930

Merged
merged 5 commits into from
Sep 14, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 62 additions & 10 deletions iphone/Classes/TiBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@
#include <pthread.h>
#include <sys/time.h>

#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>

static bool ApplicationBeingDebugged(void)
// Returns true if the current process is being debugged (either
// running under the debugger or has a debugger attached post facto).
{
#ifdef TARGET_IPHONE_SIMULATOR
return 1;
#elif DEBUG
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;

// Initialize the flags so that, if sysctl fails for some bizarre
// reason, we get a predictable result.

info.kp_proc.p_flag = 0;

// Initialize mib, which tells sysctl the info we want, in this case
// we're looking for information about a specific process ID.

mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();

// Call sysctl.

size = sizeof(info);
junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
assert(junk == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really dont like assert. Just return 0 so it falls to the NSLog loop.


// We're being debugged if the P_TRACED flag is set.
return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
#else
return 0;
#endif
}

NSMutableArray* TiCreateNonRetainingArray()
{
CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
Expand Down Expand Up @@ -45,19 +89,27 @@ void TiLogMessage(NSString* str, ...) {
TiDebuggerLogMessage(OUT, message);
}
else {
const char* s = [message UTF8String];
if (s[0]=='[')
{
fprintf(stderr,"%s\n", s);
fflush(stderr);

if (ApplicationBeingDebugged()) {
const char* s = [message UTF8String];
if (s[0]=='[')
{
fprintf(stderr,"%s\n", s);
fflush(stderr);
}
else
{
fprintf(stderr,"[DEBUG] %s\n", s);
fflush(stderr);
}
}
else
{
fprintf(stderr,"[DEBUG] %s\n", s);
fflush(stderr);
else{
#pragma push
#undef NSLog
NSLog(@"%@",message);
#pragma pop
}
}

[message release];
}

Expand Down