Remove '-p' option now that scripts can filter by pid/tid.
- `args', tracepoint arguments support (requires kernel work)
- str(args->buf, args->count)
- 'argv'
-- $1 support
+- $2, $3, $n (with n > 1) support
Improvements:
-.\" $OpenBSD: bt.5,v 1.10 2020/12/07 20:14:35 anton Exp $
+.\" $OpenBSD: bt.5,v 1.11 2021/04/21 10:22:36 mpi Exp $
.\"
.\" Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 7 2020 $
+.Dd $Mdocdate: April 21 2021 $
.Dt BT 5
.Os
.Sh NAME
Variable names with special meaning:
.Pp
.Bl -tag -width "kstack " -compact -offset indent
+.It Va $N
+Command line argument
+.Va N
+after the script name.
.It Va argN
Argument
.Va N
-/* $OpenBSD: bt_parse.y,v 1.23 2021/02/08 09:46:45 mpi Exp $ */
+/* $OpenBSD: bt_parse.y,v 1.24 2021/04/21 10:22:36 mpi Exp $ */
/*
* Copyright (c) 2019-2021 Martin Pieuchot <mpi@openbsd.org>
%token <v.number> NUMBER
%type <v.string> gvar
+%type <v.number> value
%type <v.i> fval testop binop builtin
%type <v.i> BUILTIN F_DELETE F_PRINT FUNC0 FUNC1 FUNCN OP1 OP4
%type <v.i> MOP0 MOP1
%type <v.probe> probe probeval
%type <v.filter> predicate
%type <v.stmt> action stmt stmtlist
-%type <v.arg> expr vargs map mexpr printargs term condition
+%type <v.arg> expr vargs map mexpr printargs term variable
%type <v.rtype> beginend
%left '|'
| '|' { $$ = B_AT_OP_BOR; }
;
+value : NUMBER { $$ = $1; }
+ | '$' NUMBER { $$ = get_varg($2); }
+ ;
+
predicate : /* empty */ { $$ = NULL; }
- | '/' fval testop NUMBER '/' { $$ = bf_new($3, $2, $4); }
- | '/' NUMBER testop fval '/' { $$ = bf_new($3, $4, $2); }
- | '/' condition '/' { $$ = bc_new($2); }
+ | '/' fval testop value '/' { $$ = bf_new($3, $2, $4); }
+ | '/' value testop fval '/' { $$ = bf_new($3, $4, $2); }
+ | '/' variable '/' { $$ = bc_new($2); }
;
-condition : gvar { $$ = bv_get($1); }
- | map { $$ = $1; }
+variable : gvar { $$ = bv_get($1); }
+ | map
;
builtin : PID { $$ = B_AT_BI_PID; }
mexpr : MOP0 '(' ')' { $$ = ba_new(NULL, $1); }
| MOP1 '(' expr ')' { $$ = ba_new($3, $1); }
- | expr { $$ = $1; }
+ | expr
;
expr : CSTRING { $$ = ba_new($1, B_AT_STR); }
term : '(' term ')' { $$ = $2; }
| term binop term { $$ = ba_op($2, $1, $3); }
- | NUMBER { $$ = ba_new($1, B_AT_LONG); }
+ | value { $$ = ba_new($1, B_AT_LONG); }
| builtin { $$ = ba_new(NULL, $1); }
- | gvar { $$ = bv_get($1); }
- | map { $$ = $1; }
+ | variable
gvar : '@' STRING { $$ = $2; }
%%
+int
+get_varg(int index)
+{
+ extern int vargs[];
+
+ assert(index == 1);
+
+ return vargs[index - 1];
+}
+
/* Create a new rule, representing "probe / filter / { action }" */
struct bt_rule *
br_new(struct bt_probe *probe, struct bt_filter *filter, struct bt_stmt *head,
-.\" $OpenBSD: btrace.8,v 1.4 2021/03/21 06:44:24 jmc Exp $
+.\" $OpenBSD: btrace.8,v 1.5 2021/04/21 10:22:36 mpi Exp $
.\"
.\" Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: March 21 2021 $
+.Dd $Mdocdate: April 21 2021 $
.Dt BTRACE 8
.Os
.Sh NAME
.Sh SYNOPSIS
.Nm btrace
.Op Fl lnv
-.Op Fl p Ar pid
.Op Fl e Ar program | Ar file
.Sh DESCRIPTION
The
.It Fl n
No action.
Parse the program and then exit.
-.It Fl p Ar pid
-Enable tracing on the indicated process ID (only one
-.Fl p
-flag is permitted).
.It Fl v
Verbose mode.
Causes
-/* $OpenBSD: btrace.c,v 1.30 2021/03/21 01:24:35 jmatthew Exp $ */
+/* $OpenBSD: btrace.c,v 1.31 2021/04/21 10:22:36 mpi Exp $ */
/*
* Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org>
/*
* Main loop and rule evaluation.
*/
-void rules_do(int, int);
-void rules_setup(int, int);
+void rules_do(int);
+void rules_setup(int);
void rules_apply(struct dt_evt *);
void rules_teardown(int);
void rule_eval(struct bt_rule *, struct dt_evt *);
struct dtioc_probe_info *dt_dtpis; /* array of available probes */
size_t dt_ndtpi; /* # of elements in the array */
+int vargs[1];
int verbose = 0;
volatile sig_atomic_t quit_pending;
int fd = -1, ch, error = 0;
const char *filename = NULL, *btscript = NULL;
const char *errstr;
- int showprobes = 0, tracepid = -1, noaction = 0;
+ int showprobes = 0, noaction = 0;
setlocale(LC_ALL, "");
case 'n':
noaction = 1;
break;
- case 'p':
- if (tracepid != -1)
- usage();
- tracepid = strtonum(optarg, 1, INT_MAX, &errstr);
- if (errstr != NULL)
- errx(1, "invalid pid %s: %s", optarg, errstr);
- break;
case 'v':
verbose++;
break;
argv++;
}
+ if (argc == 1) {
+ vargs[0] = strtonum(*argv, 1, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(1, "invalid argument %s: %s", *argv, errstr);
+ argc--;
+ argv++;
+ }
+
if (argc != 0 || (btscript == NULL && !showprobes))
usage();
}
if (!TAILQ_EMPTY(&g_rules))
- rules_do(fd, tracepid);
+ rules_do(fd);
if (fd != -1)
close(fd);
}
void
-rules_do(int fd, int tracepid)
+rules_do(int fd)
{
struct sigaction sa;
if (sigaction(SIGINT, &sa, NULL))
err(1, "sigaction");
- rules_setup(fd, tracepid);
+ rules_setup(fd);
while (!quit_pending && g_nprobes > 0) {
static struct dt_evt devtbuf[64];
void
-rules_setup(int fd, int tracepid)
+rules_setup(int fd)
{
struct dtioc_probe_info *dtpi;
struct dtioc_req *dtrq;
dtrq->dtrq_filter.dtf_operand = dop2dt(df->bf_op);
dtrq->dtrq_filter.dtf_variable = dvar2dt(df->bf_var);
dtrq->dtrq_filter.dtf_value = df->bf_val;
- } else if (tracepid != -1) {
- dtrq->dtrq_filter.dtf_operand = DT_OP_EQ;
- dtrq->dtrq_filter.dtf_variable = DT_FV_PID;
- dtrq->dtrq_filter.dtf_value = tracepid;
}
dtrq->dtrq_rate = r->br_probe->bp_rate;