Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argdist, trace: Support non-C identifier names #906

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions tools/argdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _validate_specifier(self):
if parts[0] not in ["r", "p", "t", "u"]:
self._bail("probe type must be 'p', 'r', 't', or 'u'" +
" but got '%s'" % parts[0])
if re.match(r"\w+\(.*\)", parts[2]) is None:
if re.match(r"\S+\(.*\)", parts[2]) is None:
self._bail(("function signature '%s' has an invalid " +
"format") % parts[2])

Expand All @@ -173,6 +173,9 @@ def _parse_exprs(self, exprs):
self._bail("no exprs specified")
self.exprs = exprs.split(',')

def _make_valid_identifier(self, ident):
return re.sub(r'[^A-Za-z0-9_]', '_', ident)

def __init__(self, tool, type, specifier):
self.usdt_ctx = None
self.streq_functions = ""
Expand All @@ -196,8 +199,9 @@ def __init__(self, tool, type, specifier):
self.tp_event = self.function
elif self.probe_type == "u":
self.library = parts[1]
self.probe_func_name = "%s_probe%d" % \
(self.function, Probe.next_probe_index)
self.probe_func_name = self._make_valid_identifier(
"%s_probe%d" % \
(self.function, Probe.next_probe_index))
self._enable_usdt_probe()
else:
self.library = parts[1]
Expand Down Expand Up @@ -233,10 +237,12 @@ def check(expr):
self.entry_probe_required = self.probe_type == "r" and \
(any(map(check, self.exprs)) or check(self.filter))

self.probe_func_name = "%s_probe%d" % \
(self.function, Probe.next_probe_index)
self.probe_hash_name = "%s_hash%d" % \
(self.function, Probe.next_probe_index)
self.probe_func_name = self._make_valid_identifier(
"%s_probe%d" % \
(self.function, Probe.next_probe_index))
self.probe_hash_name = self._make_valid_identifier(
"%s_hash%d" % \
(self.function, Probe.next_probe_index))
Probe.next_probe_index += 1

def _enable_usdt_probe(self):
Expand Down
3 changes: 1 addition & 2 deletions tools/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def __init__(self, probe, string_size, kernel_stack, user_stack):
self.probe_num = Probe.probe_count
self.probe_name = "probe_%s_%d" % \
(self._display_function(), self.probe_num)
if self.probe_name.find(".") > 0: # for golang
self.probe_name = self.probe_name.replace(".", "_DOT_")
self.probe_name = re.sub(r'[^A-Za-z0-9_]', '_', self.probe_name)

def __str__(self):
return "%s:%s:%s FLT=%s ACT=%s/%s" % (self.probe_type,
Expand Down