-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add built-in function for formatting MAC addresses #1647
Conversation
The codegen validator is currently failing with an error that I don't understand:
Fiddling with the codegen types, I can even get this:
... which seems odd. If I remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet! Some comments.
Don't really like the name, don't really know anything better either.
4060588
to
dcd57db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I think it will have some issues with less common types
Changelog and refguide entries need to be added at some point too
auto macaddr = call.vargs->front(); | ||
auto scoped_del = accept(macaddr); | ||
|
||
b_.CreateProbeRead(ctx_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC arrays can end up on stack already so this would probe read from the stack in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should I check for that case? I see that shouldBeOnStackAlready
doesn't include arrays, so it wouldn't be enough to branch on that. But I'm thinking that we need to branch on something and then store (instead of probe read) if the arg is already on the stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it would have to load/memcpy instead of probe reading.
I dont know the best way to check, arrays need some love. I'd be ok with this probe reading for now too, can always fix it in the future.
tests/semantic_analyser.cpp
Outdated
{ | ||
std::string structs = "struct mac { char addr[6]; }; "; | ||
|
||
test(structs + "kprobe:f { macaddr((struct mac*)arg0); }", 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need some tests (and runtime tests) for the other supported cases too, like
macaddr(arg0)
macaddr((struct X)y)
macaddr(somekindofarray)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you meant for these two:
macaddr((struct X)y)
How would it differ from this line? Do you mean a cast to a non-pointer struct type?
macaddr(somekindofarray)
The line below this one is testing an array, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh woops, codeblock makes the difference
macaddr(arg0)
macaddr(*(struct mac*)y)
macaddr(somekindofarray)
macaddr(somekindofarray)
The line below this one is testing an array, no?
I'm not sure, I just want to make sure it works for data that has already been loaded onto the stack (so no probe_read required).
@fbs ping |
Sorry, missed this one, busy times :( |
All good! I should have time this week to finish testing the different cases, update the docs, etc. |
e7120f1
to
87f1ea2
Compare
@fbs ready for another look when you have a moment |
87f1ea2
to
26c2d9c
Compare
@acj sorry for all the delays. Can you rebase this so we can get it in? |
26c2d9c
to
56ba7bd
Compare
@fbs All good. Here's the diff addressing the type changes and fixing a logging typo: --- src/ast/semantic_analyser.cpp
+++ src/ast/semantic_analyser.cpp
@@ -1194,14 +1194,14 @@ void SemanticAnalyser::visit(Call &call)
auto &arg = call.vargs->at(0);
- if (!arg->type.IsIntTy() && !arg->type.IsArray() && !arg->type.IsPtrTy())
+ if (!arg->type.IsIntTy() && !arg->type.IsArrayTy() &&
+ !arg->type.IsByteArray() && !arg->type.IsPtrTy() &&
+ !arg->type.IsRecordTy())
LOG(ERROR, call.loc, err_)
- << "() only supports array or pointer arguments"
+ << call.func << "() only supports array or pointer arguments"
<< " (" << arg->type.type << " provided)";
auto type = arg->type;
-
- if (arg->type.IsArray() && type.GetSize() != 6)
+ if ((type.IsArrayTy() || type.IsByteArray()) && type.GetSize() != 6)
LOG(ERROR, call.loc, err_)
<< call.func << "() argument must be 6 bytes in size"; |
src/ast/semantic_analyser.cpp
Outdated
|
||
if (!arg->type.IsIntTy() && !arg->type.IsArrayTy() && | ||
!arg->type.IsByteArray() && !arg->type.IsPtrTy() && | ||
!arg->type.IsRecordTy()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type::record
should only be structs not struct pointers so this should be removed right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good catch. Fixed in latest commit
56ba7bd
to
b1e7f73
Compare
This adds a helper function named
macaddr
(tentative name) that formats MAC addresses in the canonical hex style, e.g.00:1C:42:B5:20:09
. Resolves #1575.WIP, but feedback is welcome and appreciated.
Checklist
docs/reference_guide.md
CHANGELOG.md