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

Templated C++ functions cut off after opening parenthesis in template arguments. #173

Closed
SoftwareApe opened this issue May 25, 2020 · 6 comments

Comments

@SoftwareApe
Copy link
Contributor

Same issue as brendangregg/FlameGraph#215 on the original tool.

@jonhoo
Copy link
Owner

jonhoo commented May 25, 2020

Ah, yes, good catch! The Rust version of that code lives here:

fn tidy_generic(mut func: String) -> String {

It doesn't use regular expressions, but instead just walks the string in an equivalent way. Want to try putting up a PR that makes a similar change to the one you linked?

@SoftwareApe
Copy link
Contributor Author

Thank you for the pointer. I can take a look. I was actually grepping for regex, since I assumed it was regex, but couldn't find it 😅 .

@SoftwareApe
Copy link
Contributor Author

SoftwareApe commented May 25, 2020

So it's kind of obvious what's happening. In the C++ stacks you have std::function<bool (...

Then it finds this parenthesis, and because the preceding char isn't "." it assumes this isn't Go (so far so good), but then it truncates the string after the parenthesis.

Ergo, we'd have to detect C++ stacks. However the preceding char (in this case, maybe compiler dependent? Is a space.

I think the easiest would be, we count the template/angle brackets ("<" and ">") to see if we're inside a template parameter (either they're balanced or unbalanced).

Do you think this is feasible?

Alternatively, it seems you try to get rid of function parameters. Maybe we should just remove parameters up to the closing parenthesis, since something may follow. Although personally I find the function parameters are part of the function signature, so potentially interesting.

@jonhoo
Copy link
Owner

jonhoo commented May 25, 2020

Hmm, yeah, it's a tricky situation, and it's unfortunate we don't have more context. I think my inclination here is to only strip "arguments" (in parentheses) when they appear at the tail end of an expression. So I think your plan to not strip if we're inside <> will work well!

@SoftwareApe
Copy link
Contributor Author

I suggested a fix now. I added some tests for C++ stack collapse with std::function templates.

@SoftwareApe
Copy link
Contributor Author

I'm not sure what's up with the tests, but 4 of them were failing before I changed anything.

@jonhoo jonhoo closed this as completed in 2230ac7 May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants