Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
probe_filter.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, 2014 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include <ctype.h>
20 #include <regex.h>
21 
22 #include "log.h"
23 #include "dwdebug.h"
24 #include "dwdebug_priv.h"
25 #include "target_api.h"
26 #include "target.h"
27 #include "target_os.h"
28 #include "probe.h"
29 #include "probe_api.h"
30 #include "glib_wrapper.h"
31 
32 /*
33  * Can only check pre/post_filters if @trigger provides probe_values.
34  */
35 int probe_filter_check(struct probe *probe,tid_t tid,struct probe *trigger,
36  int whence) {
37  struct target_nv_filter *tf;
38  char vstrbuf[1024];
39  int rc;
40  struct value *v;
41  GSList *gsltmp;
42  struct target_nv_filter_regex *tfr;
43 
44  if (whence == 0)
45  tf = probe->pre_filter;
46  else if (whence == 1)
47  tf = probe->post_filter;
48  else
49  return -1;
50 
51  /*
52  * Check the thread filter first.
53  */
54  if (probe->thread_filter) {
55  rc = target_thread_filter_check(probe->target,tid,probe->thread_filter);
56  if (rc) {
58  "thread filter check did not match tid %d probe tid %d ",
59  tid,probe->thread->tid);
61  return rc;
62  }
63  }
64 
65  if (!tf)
66  return 0;
67 
68  /*
69  * Check each filter by loading the value from @trigger.
70  */
71  v_g_slist_foreach(tf->value_regex_list,gsltmp,tfr) {
72  v = probe_value_get(trigger,tid,tfr->value_name);
73  if (!v) {
75  "could not load value name %s",tfr->value_name);
76  return -1;
77  }
78  rc = value_snprintf(v,vstrbuf,sizeof(vstrbuf));
79  if (regexec(&tfr->regex,(const char *)vstrbuf,0,NULL,0) == REG_NOMATCH) {
81  "failed to match name %s value '%s' with regex!\n",
82  tfr->value_name,vstrbuf);
83  return 1;
84  }
85  else {
87  "matched name %s value '%s' with regex\n",
88  tfr->value_name,vstrbuf);
89  }
90  }
91 
92  return 0;
93 }
94 
96  struct probe_ops *pops,
97  const char *name,
103  void *handler_data,
104  int autofree,int tracked) {
105  struct probe *fprobe;
106 
107  fprobe = probe_create(target,tid,pops,name,pre_handler,post_handler,
108  handler_data,autofree,tracked);
109  fprobe->pre_filter = pre_filter;
110  fprobe->post_filter = post_filter;
111  fprobe->thread_filter = thread_filter;
112 
113  return fprobe;
114 }
#define vwarnopt(level, area, flags, format,...)
Definition: log.h:37
result_t pre_handler(struct probe *probe, tid_t tid, void *data, struct probe *trigger, struct probe *base)
Definition: spf.c:903
int probe_filter_check(struct probe *probe, tid_t tid, struct probe *trigger, int whence)
Definition: probe_filter.c:35
int value_snprintf(struct value *value, char *buf, int buflen)
Definition: value.c:639
int32_t tid_t
Definition: common.h:36
Definition: log.h:190
char * name
Definition: probe.h:314
struct target_nv_filter * post_filter
Definition: probe.h:355
#define v_g_slist_foreach(gslhead, gslcur, elm)
Definition: glib_wrapper.h:60
struct probe * probe_create_filtered(struct target *target, tid_t tid, struct probe_ops *pops, const char *name, probe_handler_t pre_handler, struct target_nv_filter *pre_filter, probe_handler_t post_handler, struct target_nv_filter *post_filter, struct target_nv_filter *thread_filter, void *handler_data, int autofree, int tracked)
Definition: probe_filter.c:95
struct target_nv_filter * thread_filter
Definition: probe.h:357
result_t(* probe_handler_t)(struct probe *probe, tid_t tid, void *handler_data, struct probe *trigger, struct probe *base)
Definition: probe_api.h:70
tid_t tid
Definition: probe.h:344
action_whence_t whence
Definition: probe.h:407
#define LOGDUMPPROBE_NL(dl, la, lt, p)
Definition: probe.h:73
Definition: probe.h:308
struct probe * probe_create(struct target *target, tid_t tid, struct probe_ops *pops, const char *name, probe_handler_t pre_handler, probe_handler_t post_handler, void *handler_data, int autofree, int tracked)
Definition: probe.c:729
struct target_thread * thread
Definition: probe.h:343
#define vdebug(devel, areas, flags, format,...)
Definition: log.h:302
GSList * value_regex_list
Definition: target.h:685
struct target_nv_filter * pre_filter
Definition: probe.h:351
struct value * probe_value_get(struct probe *probe, tid_t tid, char *name)
Definition: probe_value.c:633
result_t post_handler(struct probe *probe, tid_t tid, void *data, struct probe *trigger, struct probe *base)
Definition: spf.c:908
Definition: log.h:71
uint8_t autofree
Definition: probe.h:364
struct target * target
Definition: probe.h:342
int target_thread_filter_check(struct target *target, tid_t tid, struct target_nv_filter *tf)
Definition: target.c:4295
uint8_t tracked
Definition: probe.h:376