-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Small int prep work #1532
Small int prep work #1532
Conversation
This pull request introduces 1 alert when merging 579a41d into 2ed1ed5 - view on LGTM.com new alerts:
|
CHANGELOG.md
Outdated
@@ -64,6 +64,8 @@ and this project adheres to | |||
- [#1530](https://github.com/iovisor/bpftrace/pull/1530) | |||
- Fix pointer arithmetic for positional parameters | |||
- [#1514](https://github.com/iovisor/bpftrace/pull/1514) | |||
- Printing of small integers with `printf` | |||
- [#1531](https://github.com/iovisor/bpftrace/pull/1531) |
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.
off by 1
c7de39d
to
883c72d
Compare
I am happy to test these changes, once it is rebased on master (after addrspace integration), which could solve few things for us. Thank you |
883c72d
to
438e649
Compare
ready for review now :) |
ok. I will check and test this. Thnx |
I do see the following additional failures. [ FAILED ] array.array element access - assign to map |
There is an endianness issue here while printing. I will provide the detailed debug output for analysis. Similarly the case for commit #1509 . Also these failures are related to printf. |
Thanks, didn't expect that to happen in this PR. I'll dig into it |
This seems to be tricky:
|
I think #1533 will fix that. But might be better to close this and merge that in one go to avoid regressions. Or i could add a setter for the size attribute here and have it update size_bits when needed. Eventually I hope to get rid of thee option to override size completely. |
ok. Fine with both. If #1533 is complex and takes long, then we could probably have a setter for the size attribute. Thanks. |
438e649
to
f22545b
Compare
Updated to iniclude a setter/getter. |
ok. will check. Thanks. |
fec3690
to
4ef17bf
Compare
@sumanthkorikkar think I got it fixed :) |
src/ast/codegen_llvm.cpp
Outdated
// When dereferencing a 32-bit integer, only read in 32-bits, etc. | ||
int size = type.IsPtrTy() ? type.GetPointeeTy()->GetSize() | ||
: type.GetSize(); | ||
auto as = type.IsPtrTy() ? type.GetAS() : AddrSpace::kernel; |
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.
Do we need to set AddrSpace::kernel here?
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.
If this is a valid case: *(int64)somintaddr. Then it would resolve to probe kernel
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 this should remain backwards compatibility with how integer dereference works currently. As the old probe_read helpers are deprecated we shouldn't rely on them anymore, so we eneed to set the AS here.
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 think, this will resolve to probe kernel then, which is not correct. uprobe:./testprogs/intptrcast:fn { $a=*(reg("r15")+160);
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 don't think that differs from current behaviour where its also broken. But would be good to discuss in a separate issue
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.
updated
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, I didn't know bpf_probe_read was dropped in some architectures... If addrspace is none, then bpftrace emits a warning. So, how about keeping addrspace::none in this case and use bpf_probe_read_kernel() if bpf_probe_read() is not available. A user can use uptr() to change the behavior if needed. And maybe we can add a better auto-detect mechanism in another PR.
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.
maybe we need to change this depending on whether arch has overlapping addrspace?
https://github.com/iovisor/bpftrace/blob/e6bbb9a925e405c1ec87790490d81227ac122032/src/ast/irbuilderbpf.cpp#L74-L79
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.
As this PR has some massive refactoring changes and a printf fix I don't want to block this on this discussion/change right now so I've restored the original AS behaviour. For non overlapping arch we should probably get autodetection working properly but that is too much for this PR. We can continue the discussion in #1507 :)
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.
ok
Did this fix all the test issues @sumanthkorikkar ? |
Most of the issues reported works. Thanks. There are few other issues. Checking if they are related to this and will let you know soon. |
For these two failures, Didnt get an idea yet.
For these, doing (int64*) instead of (int16*) works.
|
#1566 Added for usdt_sized_args |
Interesting thanks! Is this a regression compared to master? Can you attach/mail me 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.
LGTM (aside from addrspace), just some questions
src/ast/codegen_llvm.cpp
Outdated
|
||
size_t len = std::min(binop.left->type.size, binop.right->type.size); | ||
expr_ = b_.CreateStrncmp(ctx_, | ||
left_string, | ||
left_as, | ||
right_string, | ||
right_as, | ||
len, | ||
len + 1, |
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.
Intentional change?
@@ -718,28 +718,59 @@ std::vector<std::unique_ptr<IPrintable>> BPFtrace::get_arg_values(const std::vec | |||
switch (arg.type.type) | |||
{ | |||
case Type::integer: | |||
switch (arg.type.size) | |||
if (arg.type.IsSigned()) |
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.
The reason this fix works is b/c we're forcing a sign extension here, right? If so, can you add that information to the commit message?
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.
@danobi I've removed the confusing cast hack thing and just have Printables handle the actual printing, should be easier to make sense of now.
36639bd
to
c972d32
Compare
These don't seem related to this PR, happens on my master build too. |
Ok. I will check these 2 failures in another PR. Thanks. Printf conversion works on s390x. |
c972d32
to
40218ba
Compare
Looks like the debian embedded build broke somehow, doesn't look related |
e318a46
to
34a5eb7
Compare
Directly modifying the size field is tricky as other fields (like size_bits) will have to be updated too. By making the field private and hiding it behind a getter and setter that logic will only have to exist in one place. Ideally we disallow modifying size completely but that will require some more changes.
When resizing an integer we have to insert a cast to ensure the sign extension happens (for signed ints), just modifying the `size` isn't enough.
The integer conversion causes signed integers to be printed wrong as they're not correctly sign extended: ``` bpftrace -e 'BEGIN { printf("%d", (int16)-123); exit() ;}' Attaching 1 probe... 65413 ```
ce58c09
to
2e6a1e4
Compare
This is based on #1509, so that will have to land first.
This is some more prep work for #1091. Main things:
if
nesting in the codegen into separate functionskptr(uint64 *)
as discussed in Define pointer arithmetic #1507. E.g.$x = *123
=>$x = * (uint64*)123;
SizedType.size
attribute private