Skip to content

Commit

Permalink
Merge pull request iovisor#909 from goldshtn/tp-str-fixes
Browse files Browse the repository at this point in the history
trace, tplist, argdist: UDST probe miscellaneous fixes
  • Loading branch information
4ast committed Jan 17, 2017
2 parents 7e78f3a + dcf1675 commit e30eaec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion tools/argdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _generate_streq_function(self, string):
char needle[] = %s;
char haystack[sizeof(needle)];
bpf_probe_read(&haystack, sizeof(haystack), (void *)str);
for (int i = 0; i < sizeof(needle); ++i) {
for (int i = 0; i < sizeof(needle) - 1; ++i) {
if (needle[i] != haystack[i]) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/tplist.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def print_tracepoints():
def print_usdt_argument_details(location):
for idx in xrange(0, location.num_arguments):
arg = location.get_argument(idx)
print(" argument #%d %s" % (idx, arg))
print(" argument #%d %s" % (idx+1, arg))

def print_usdt_details(probe):
if args.verbosity > 0:
print(probe)
if args.verbosity > 1:
for idx in xrange(0, probe.num_locations):
loc = probe.get_location(idx)
print(" location #%d %s" % (idx, loc))
print(" location #%d %s" % (idx+1, loc))
print_usdt_argument_details(loc)
else:
print(" %d location(s)" % probe.num_locations)
Expand Down
46 changes: 24 additions & 22 deletions tools/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ def _generate_streq_function(self, string):
fname = "streq_%d" % Probe.streq_index
Probe.streq_index += 1
self.streq_functions += """
static inline bool %s(char const *ignored, unsigned long str) {
static inline bool %s(char const *ignored, uintptr_t str) {
char needle[] = %s;
char haystack[sizeof(needle)];
bpf_probe_read(&haystack, sizeof(haystack), (void *)str);
for (int i = 0; i < sizeof(needle); ++i) {
for (int i = 0; i < sizeof(needle) - 1; ++i) {
if (needle[i] != haystack[i]) {
return false;
}
Expand Down Expand Up @@ -354,33 +354,35 @@ def _generate_field_assign(self, idx):

def _generate_usdt_filter_read(self):
text = ""
if self.probe_type == "u":
for arg, _ in Probe.aliases.items():
if not (arg.startswith("arg") and
(arg in self.filter)):
continue
arg_index = int(arg.replace("arg", ""))
arg_ctype = self.usdt.get_probe_arg_ctype(
self.usdt_name, arg_index)
if not arg_ctype:
self._bail("Unable to determine type of {} "
"in the filter".format(arg))
text += """
if self.probe_type != "u":
return text
for arg, _ in Probe.aliases.items():
if not (arg.startswith("arg") and
(arg in self.filter)):
continue
arg_index = int(arg.replace("arg", ""))
arg_ctype = self.usdt.get_probe_arg_ctype(
self.usdt_name, arg_index - 1)
if not arg_ctype:
self._bail("Unable to determine type of {} "
"in the filter".format(arg))
text += """
{} {}_filter;
bpf_usdt_readarg({}, ctx, &{}_filter);
""".format(arg_ctype, arg, arg_index, arg)
self.filter = self.filter.replace(
arg, "{}_filter".format(arg))
""".format(arg_ctype, arg, arg_index, arg)
self.filter = self.filter.replace(
arg, "{}_filter".format(arg))
return text

def generate_program(self, include_self):
data_decl = self._generate_data_decl()
# kprobes don't have built-in pid filters, so we have to add
# it to the function body:
if len(self.library) == 0 and Probe.pid != -1:
if Probe.pid != -1:
pid_filter = """
if (__pid != %d) { return 0; }
""" % Probe.pid
# uprobes can have a built-in tgid filter passed to
# attach_uprobe, hence the check here -- for kprobes, we
# need to do the tgid test by hand:
elif len(self.library) == 0 and Probe.tgid != -1:
pid_filter = """
if (__tgid != %d) { return 0; }
Expand Down Expand Up @@ -542,12 +544,12 @@ def _attach_u(self, bpf):
bpf.attach_uretprobe(name=libpath,
sym=self.function,
fn_name=self.probe_name,
pid=Probe.pid)
pid=Probe.tgid)
else:
bpf.attach_uprobe(name=libpath,
sym=self.function,
fn_name=self.probe_name,
pid=Probe.pid)
pid=Probe.tgid)

class Tool(object):
examples = """
Expand Down

0 comments on commit e30eaec

Please sign in to comment.