- cmd = (struct load_command *) &mh[1];
- for (i = 0; i < mh->ncmds; i++) {
- if (cmd->cmd == LC_SEGMENT) {
- struct segment_command *orig_sg = (struct segment_command *) cmd;
-
- if (strcmp(SEG_TEXT, orig_sg->segname) == 0)
- orig_ts = orig_sg;
- else if (strcmp(SEG_LINKEDIT, orig_sg->segname) == 0)
- orig_le = orig_sg;
- else if (strcmp("", orig_sg->segname) == 0)
- orig_ts = orig_sg; /* kexts have a single unnamed segment */
- }
- else if (cmd->cmd == LC_SYMTAB)
- orig_st = (struct symtab_command *) cmd;
-
- cmd = (struct load_command *) ((caddr_t) cmd + cmd->cmdsize);
- }
-
- if ((orig_ts == NULL) || (orig_st == NULL) || (orig_le == NULL))
- return;
-
- sym = (struct nlist *)orig_le->vmaddr;
- strings = ((char *)sym) + orig_st->nsyms * sizeof(struct nlist);
-
- for (i = 0; i < orig_st->nsyms; i++) {
- uint8_t n_type = sym[i].n_type & (N_TYPE | N_EXT);
- char *name = strings + sym[i].n_un.n_strx;
- char *prev_name;
- unsigned long best;
- unsigned int j;
-
- /* Check that the symbol is a global and that it has a name. */
- if (((N_SECT | N_EXT) != n_type && (N_ABS | N_EXT) != n_type))
- continue;
-
- if (0 == sym[i].n_un.n_strx) /* iff a null, "", name. */
- continue;
-
- /* Lop off omnipresent leading underscore. */
- if (*name == '_')
- name += 1;
-
- if (strstr(name, "_dtrace_probe$")) {
- sdt_probedesc_t *sdpd = kmem_alloc(sizeof(sdt_probedesc_t), KM_SLEEP);
- int len = strlen(name) + 1;
-
- sdpd->sdpd_name = kmem_alloc(len, KM_SLEEP);
- strncpy(sdpd->sdpd_name, name, len); /* NUL termination is ensured. */
-
- prev_name = "<unknown>";
- best = 0;
- for (j = 0; j < orig_st->nsyms; j++) {
- uint8_t n_type = sym[j].n_type & (N_TYPE | N_EXT);
- char *name = strings + sym[j].n_un.n_strx;
-
- if (((N_SECT | N_EXT) != n_type && (N_ABS | N_EXT) != n_type))
- continue;
-
- if (0 == sym[j].n_un.n_strx) /* iff a null, "", name. */
- continue;
-
- if (*name == '_')
- name += 1;
- if (strstr(name, "_dtrace_probe$"))
- continue;
-
- if (*(unsigned long *)sym[i].n_value <= (unsigned long)sym[j].n_value)
- continue;
-
- if ((unsigned long)sym[j].n_value > best) {
- best = (unsigned long)sym[j].n_value;
- prev_name = name;
- }
+ cmd = (struct load_command*) &mh[1];
+ for (i = 0; i < mh->ncmds; i++) {
+ if (cmd->cmd == LC_SEGMENT_KERNEL) {
+ kernel_segment_command_t *orig_sg = (kernel_segment_command_t *) cmd;
+
+ if (LIT_STRNEQL(orig_sg->segname, SEG_TEXT))
+ orig_ts = orig_sg;
+ else if (LIT_STRNEQL(orig_sg->segname, SEG_LINKEDIT))
+ orig_le = orig_sg;
+ else if (LIT_STRNEQL(orig_sg->segname, ""))
+ orig_ts = orig_sg; /* kexts have a single unnamed segment */
+ }
+ else if (cmd->cmd == LC_SYMTAB)
+ orig_st = (struct symtab_command *) cmd;
+
+ cmd = (struct load_command *) ((uintptr_t) cmd + cmd->cmdsize);
+ }
+
+ if ((orig_ts == NULL) || (orig_st == NULL) || (orig_le == NULL))
+ return;
+
+ sym = (kernel_nlist_t *)(orig_le->vmaddr + orig_st->symoff - orig_le->fileoff);
+ strings = (char *)(orig_le->vmaddr + orig_st->stroff - orig_le->fileoff);
+
+ for (i = 0; i < orig_st->nsyms; i++) {
+ uint8_t n_type = sym[i].n_type & (N_TYPE | N_EXT);
+ char *name = strings + sym[i].n_un.n_strx;
+ const char *prev_name;
+ unsigned long best;
+ unsigned int j;
+
+ /* Check that the symbol is a global and that it has a name. */
+ if (((N_SECT | N_EXT) != n_type && (N_ABS | N_EXT) != n_type))
+ continue;
+
+ if (0 == sym[i].n_un.n_strx) /* iff a null, "", name. */
+ continue;
+
+ /* Lop off omnipresent leading underscore. */
+ if (*name == '_')
+ name += 1;
+
+ if (strncmp(name, DTRACE_PROBE_PREFIX, sizeof(DTRACE_PROBE_PREFIX) - 1) == 0) {
+ sdt_probedesc_t *sdpd = kmem_alloc(sizeof(sdt_probedesc_t), KM_SLEEP);
+ int len = strlen(name) + 1;
+
+ sdpd->sdpd_name = kmem_alloc(len, KM_SLEEP);
+ strncpy(sdpd->sdpd_name, name, len); /* NUL termination is ensured. */
+
+ prev_name = "<unknown>";
+ best = 0;
+
+ /*
+ * Find the symbol immediately preceding the sdt probe site just discovered,
+ * that symbol names the function containing the sdt probe.
+ */
+ for (j = 0; j < orig_st->nsyms; j++) {
+ uint8_t jn_type = sym[j].n_type & N_TYPE;
+ char *jname = strings + sym[j].n_un.n_strx;
+
+ if ((N_SECT != jn_type && N_ABS != jn_type))
+ continue;
+
+ if (0 == sym[j].n_un.n_strx) /* iff a null, "", name. */
+ continue;
+
+ if (*jname == '_')
+ jname += 1;
+
+ if (*(unsigned long *)sym[i].n_value <= (unsigned long)sym[j].n_value)
+ continue;
+
+ if ((unsigned long)sym[j].n_value > best) {
+ best = (unsigned long)sym[j].n_value;
+ prev_name = jname;