| |
| |
| |
| |
| |
| |
| |
| |
| |
| %{ |
| #define STAP_NEED_CONTEXT_SUBEXPRESSION 1 |
| %} |
| |
| |
| |
| |
| |
| |
| |
| |
| function matched_str:string() { return matched(0) } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function matched:string(n:long) |
| %{ |
| int start_ix, end_ix; |
| int start, end, length; |
| |
| if (!CONTEXT->last_match.result) { |
| snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| "Attempted to get subexpression %lld from failed match", (long long) STAP_ARG_n); |
| CONTEXT->last_error = CONTEXT->error_buffer; |
| } |
| |
| start_ix = 2 * STAP_ARG_n, end_ix = start_ix + 1; |
| |
| if (end_ix >= CONTEXT->last_match.num_final_tags) { |
| snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| "Attempted to get nonexistent subexpression %lld", (long long) STAP_ARG_n); |
| CONTEXT->last_error = CONTEXT->error_buffer; |
| } |
| |
| start = CONTEXT->last_match.tag_vals[start_ix]; |
| end = CONTEXT->last_match.tag_vals[end_ix]; |
| |
| |
| if (start < 0 || end < 0) { |
| |
| start = end = 0; |
| |
| |
| |
| } |
| |
| if (start > end) { |
| |
| snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| "BUG: inverted coordinates for subexpression %lld", (long long) STAP_ARG_n); |
| CONTEXT->last_error = CONTEXT->error_buffer; |
| } |
| |
| length = end - start; |
| |
| |
| |
| strlcpy(STAP_RETVALUE, CONTEXT->last_match.matched_str + start, length + 1); |
| %} |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function ngroups:long() |
| %{ |
| if (!CONTEXT->last_match.result) { |
| snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| "Attempted to get subexpression count from failed match"); |
| CONTEXT->last_error = CONTEXT->error_buffer; |
| } |
| |
| STAP_RETVALUE = CONTEXT->last_match.num_final_tags / 2; |
| %} |
| |
| |
| |
| |