*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
-cc -I. -DKERNEL_PRIVATE -O -o sc_usage sc_usage.c -lncurses
+cc -I. -DPRIVATE -D__APPLE_PRIVATE -O -o sc_usage sc_usage.c -lncurses
*/
#define Default_DELAY 1 /* default delay interval */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
+#include <sys/ptrace.h>
#include <libc.h>
#include <termios.h>
#define MAX_NESTED 8
#define MAX_FAULTS 5
-/* If NUMPARMS from kernel changes, it will be reflected in PATHLENGTH as well */
+
#define NUMPARMS 23
-#define PATHLENGTH (NUMPARMS*sizeof(long))
+
char *state_name[] = {
"Dont Know",
int vfslookup;
int curpri;
long *pathptr;
- char pathname[PATHLENGTH + 1];
+ long pathname[NUMPARMS + 1];
struct entry th_entry[MAX_NESTED];
};
void set_remove();
void set_numbufs();
void set_init();
+void quit(char *);
+int argtopid(char *);
+int argtoi(int, char*, char*, int);
/*
}
int
-exit_usage(myname) {
+exit_usage(char *myname) {
fprintf(stderr, "Usage: %s [-c codefile] [-e] [-l] [-sn] pid | cmd | -E execute path\n", myname);
fprintf(stderr, " -c name of codefile containing mappings for syscalls\n");
hours = minutes / 60;
if (minutes < 100) { // up to 100 minutes
- sprintf(p, "%2ld:%02ld.%03ld", minutes, seconds % 60,
- usec_to_1000ths(useconds));
+ sprintf(p, "%2ld:%02ld.%03ld", minutes, (unsigned long)(seconds % 60),
+ (unsigned long)usec_to_1000ths(useconds));
}
else if (hours < 100) { // up to 100 hours
- sprintf(p, "%2ld:%02ld:%02ld ", hours, minutes % 60,
- seconds % 60);
+ sprintf(p, "%2ld:%02ld:%02ld ", hours, (minutes % 60),
+ (unsigned long)(seconds % 60));
}
else {
sprintf(p, "%4ld hrs ", hours);
}
}
-
+int
main(argc, argv)
int argc;
char *argv[];
char ch;
char *ptr;
int delay = Default_DELAY;
- int length;
void screen_update();
void sort_scalls();
void sc_tab_init();
void getdivisor();
void reset_counters();
- int argtopid();
- int argtoi();
- int quit();
if ( geteuid() != 0 ) {
printf("'sc_usage' must be run as root...\n");
exit(1);
case 0: /* child */
setsid();
- ptrace(0,0,0,0); /* PT_TRACE_ME */
+ ptrace(0,(pid_t)0,(caddr_t)0,0); /* PT_TRACE_ME */
execve(argv[optind], &argv[optind], environ);
perror("execve:");
exit(1);
set_pidcheck(pid, 1);
set_enable(1);
if (execute_flag)
- ptrace(7, pid, 1, 0); /* PT_CONTINUE */
+ ptrace(7, pid, (caddr_t)1, 0); /* PT_CONTINUE */
getdivisor();
if (delay == 0)
while (1) {
int i;
- int cnt;
char c;
void sample_sc();
clen = strlen(tbuf);
sprintf(&tbuf[clen], " %3ld:%02ld:%02ld\n",
- hours, minutes % 60, elapsed_secs % 60);
+ (long)hours, (long)(minutes % 60), (long)(elapsed_secs % 60));
if (tbuf[COLS-2] != '\n') {
tbuf[COLS-1] = '\n';
for (i = 0; i < num_of_threads; i++, ti++) {
struct entry *te;
+ char *p;
uint64_t now;
int secs, time_secs, time_usecs;
clen = strlen(tbuf);
/* print the tail end of the pathname */
- plen = strlen(ti->pathname);
+ p = (char *)ti->pathname;
+
+ plen = strlen(p);
if (plen > 34)
plen -= 34;
else
plen = 0;
- sprintf(&tbuf[clen], " %-34.34s ", &ti->pathname[plen]);
+ sprintf(&tbuf[clen], " %-34.34s ", &p[plen]);
clen += strlen(&tbuf[clen]);
int msgcode_indx=0;
char name[56];
FILE *fp;
- int quit();
if ((fp = fopen(codefile,"r")) == (FILE *)0) {
printf("Failed to open code description file %s\n", codefile);
if ((unsigned long)(((double)now - te->otime) / divisor) > 5000000) {
ti->thread = 0;
ti->vfslookup = 0;
- ti->pathptr = (long *)0;
+ ti->pathptr = (long *)NULL;
ti->pathname[0] = 0;
num_of_threads--;
}
th_state[i].depth = 0;
th_state[i].thread = 0;
th_state[i].vfslookup = 0;
- th_state[i].pathptr = (long *)0;
+ th_state[i].pathptr = (long *)NULL;
th_state[i].pathname[0] = 0;
}
num_of_threads = 0;
struct sc_entry *se;
struct entry *te;
- thread = kd[i].arg5 & KDBG_THREAD_MASK;
+ thread = kd[i].arg5;
debugid = kd[i].debugid;
type = kd[i].debugid & DBG_FUNC_MASK;
switched_out = (struct th_info *)0;
switched_in = (struct th_info *)0;
- now = (((uint64_t)kd[i].timestamp.tv_sec) << 32) |
- (uint64_t)((unsigned int)(kd[i].timestamp.tv_nsec));
+ now = kd[i].timestamp & KDBG_TIMESTAMP_MASK;
+
baseid = debugid & 0xffff0000;
if (type == vfs_lookup) {
if (ti->vfslookup == 1) {
ti->vfslookup++;
- memset(&ti->pathname[0], 0, (PATHLENGTH + 1));
- sargptr = (long *)&ti->pathname[0];
+ sargptr = ti->pathname;
*sargptr++ = kd[i].arg2;
*sargptr++ = kd[i].arg3;
*sargptr++ = kd[i].arg4;
+ /*
+ * NULL terminate the 'string'
+ */
+ *sargptr = 0;
+
ti->pathptr = sargptr;
} else if (ti->vfslookup > 1) {
handle.
*/
- if ((long *)sargptr >= (long *)&ti->pathname[PATHLENGTH])
+ if (sargptr >= &ti->pathname[NUMPARMS])
continue;
/*
if (debugid & DBG_FUNC_START)
{
- (long *)ti->pathptr = (long *)&ti->pathname[PATHLENGTH];
+ ti->pathptr = &ti->pathname[NUMPARMS];
continue;
}
*sargptr++ = kd[i].arg2;
*sargptr++ = kd[i].arg3;
*sargptr++ = kd[i].arg4;
+ /*
+ * NULL terminate the 'string'
+ */
+ *sargptr = 0;
+
ti->pathptr = sargptr;
}
continue;
code = (debugid >> 2) & 0x1ff;
else if (baseid == msc_base)
code = 512 + ((debugid >> 2) & 0x1ff);
- else if (baseid == mach_sched || baseid == mach_stkhandoff) {
- switched_out = find_thread(kd[i].arg1);
+ else if (type == mach_sched || type == mach_stkhandoff) {
+ switched_out = find_thread(kd[i].arg5);
switched_in = find_thread(kd[i].arg2);
if (in_idle) {
delta_otime_secs += secs;
}
-
-quit(s)
-char *s;
+void
+quit(char *s)
{
if (trace_enabled)
set_enable(0);
}
+int
argtopid(str)
char *str;
{
}
return (0);
}
-
+
+int
argtoi(flag, req, str, base)
int flag;
char *req, *str;