u32 procwrap_attach(union trapped_args *args, void *pr_ctxt) { void *processor; int status = 0; struct dsp_processorattrin proc_attr_in, *attr_in = NULL; if (args->args_proc_attach.attr_in) { CP_FM_USR(&proc_attr_in, args->args_proc_attach.attr_in, status, 1); if (!status) attr_in = &proc_attr_in; else goto func_end; } status = proc_attach(args->args_proc_attach.processor_id, attr_in, &processor, pr_ctxt); CP_TO_USR(args->args_proc_attach.ph_processor, &processor, status, 1); func_end: return status; }
int main(int argc, char** argv) { struct sigaction action; int ch, i, count = 0; int ret, passed = 0; addr_t addr; memset(&tracee, 0, sizeof(tracee_t)); /* ** Catch sigint & sigquit */ action.sa_handler = quit_ftrace; action.sa_flags = SA_RESTART; if (sigaction(SIGQUIT, &action, NULL)) errexit("ftrace: sigaction(SIGQUIT), %s", ftrace_strerror(errno)); if (sigaction(SIGINT, &action, NULL)) errexit("ftrace: sigaction(SIGKILL), %s", ftrace_strerror(errno)); /* ** Count Args Before -p, -e or -c Option */ for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "-e") || !strcmp(argv[i], "-c") ) { if (i != argc - 1) argc = i + 2; break; } } if (atexit(clean_ftrace) == -1) errexit("ftrace: atexit:, %s", ftrace_strerror(errno)); for (count = 0; (ch = getopt(argc, argv,"hv:b:p:e:c:")) != -1; count++) { switch ((char) ch) { case 'b': /* ** Add Breakpoint */ tracee.brkps_toset = list_add(tracee.brkps_toset, optarg); if (tracee.brkps_toset == NULL) errexit("ftrace: list_add:, %s", ftrace_strerror(errno)); break; case 'p': passed = 1; /* ** Attach To Pid */ tracee.proc = proc_new(); if (tracee.proc == NULL) errexit("ftrace: proc_new:, %s", ftrace_strerror(errno)); if (proc_attach(tracee.proc, atoi(optarg)) == -1) errexit("ftrace: proc_attach:, %s", ftrace_strerror(errno)); if (*(argv + i + 2)) tracee.proc->path = *(argv + i + 2); else tracee.proc->path = proc_get_bin_path(tracee.proc); break; case 'e': passed = 1; /* ** Exec Process */ tracee.proc = proc_new(); if (tracee.proc == NULL) errexit("ftrace: proc_new:, %s", ftrace_strerror(errno)); if (proc_create(tracee.proc, optarg, argv + i + 1) == -1) errexit("ftrace: proc_create:, %s", ftrace_strerror(errno)); break; case 'c': passed = 1; /* ** Backtrace Core */ core_trace(optarg, *(argv + i + 2)); return (0); break; case 'v': verbose = atoi(optarg); if (verbose > 0 && verbose < 5) break; case 'h': default: errexit(USAGE); break; } if (passed == 1) break; } if (!passed) errexit(USAGE); /* ** Tracee Ready ! */ ret = init_loop(&tracee, &addr); if (tracer_quit) return (0); switch (ret) { case TRACEE_OK: if (tracing_loop(&tracee, addr) == -1) errexit("ftrace: tracing_loop:, %s", ftrace_strerror(errno)); break; case TRACEE_EXIT: return (0); default: errexit("ftrace: init_loop:, %s", ftrace_strerror(errno)); } return (0); }