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

Fix runtime tests for aarch64 #3185

Merged
merged 2 commits into from
Jun 17, 2024
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
6 changes: 3 additions & 3 deletions src/attached_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ bool AttachedProbe::resolve_offset_uprobe(bool safe_mode)

sym.name = "";
option.use_debug_file = 1;
option.use_symbol_type = 0xffffffff;
option.use_symbol_type = BCC_SYM_ALL_TYPES ^ (1 << STT_NOTYPE);

if (symbol.empty()) {
sym.address = probe_.address;
Expand Down Expand Up @@ -550,7 +550,7 @@ static std::string find_vmlinux(const struct vmlinux_location *locs,
{
struct bcc_symbol_option option = {};
option.use_debug_file = 0;
option.use_symbol_type = BCC_SYM_ALL_TYPES;
option.use_symbol_type = BCC_SYM_ALL_TYPES ^ (1 << STT_NOTYPE);
struct utsname buf;

uname(&buf);
Expand Down Expand Up @@ -1084,7 +1084,7 @@ static void resolve_offset_uprobe_multi(const std::string &path,
std::sort(std::begin(syms), std::end(syms));

option.use_debug_file = 1;
option.use_symbol_type = 0xffffffff;
option.use_symbol_type = BCC_SYM_ALL_TYPES ^ (1 << STT_NOTYPE);

std::vector<struct addr_offset> addrs;
std::set<uint64_t> set;
Expand Down
6 changes: 6 additions & 0 deletions src/dwarf_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,17 @@ SizedType Dwarf::get_stype(lldb::SBType type, bool resolve_structs)
switch (inner_type.GetBasicType()) {
case lldb::eBasicTypeChar:
case lldb::eBasicTypeSignedChar:
case lldb::eBasicTypeUnsignedChar:
#if LLVM_VERSION_MAJOR >= 15
case lldb::eBasicTypeChar8:
#endif
return CreateString(length);
default:
return CreateArray(length, inner_stype);
}
}
case lldb::eTypeClassTypedef:
return get_stype(type.GetTypedefedType(), resolve_structs);
default:
return CreateNone();
}
Expand Down
10 changes: 2 additions & 8 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ std::string addrspacestr(AddrSpace as)
std::string typestr(Type t)
{
switch (t) {
// clang-format off
// clang-format off
case Type::none: return "none"; break;
case Type::voidtype: return "void"; break;
case Type::integer: return "integer"; break;
Expand Down Expand Up @@ -252,14 +252,8 @@ uint64_t asyncactionint(AsyncAction a)
// Type wrappers
SizedType CreateInteger(size_t bits, bool is_signed)
{
// Zero sized integers are not usually valid. However, during semantic
// analysis when we're inferring types, the first pass may not have
// enough information to figure out the exact size of the integer. Later
// passes infer the exact size.
assert(bits == 0 || bits == 1 || bits == 8 || bits == 16 || bits == 32 ||
bits == 64);
auto t = SizedType(Type::integer, 0, is_signed);
t.size_bits_ = bits;
t.SetIntBitWidth(bits);
return t;
}

Expand Down
26 changes: 20 additions & 6 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,27 @@ class SizedType {
return size_bits_ / 8;
}

void SetSize(size_t size)
void SetSize(size_t byte_size)
{
size_bits_ = size * 8;
if (IsIntTy()) {
assert(size == 0 || size == 1 || size == 8 || size == 16 || size == 32 ||
size == 64);
}
if (IsIntTy())
SetIntBitWidth(byte_size * 8);
else
size_bits_ = byte_size * 8;
}

void SetIntBitWidth(size_t bits)
{
assert(IsIntTy());
// Truncate integers too large to fit in BPF registers (64-bits).
if (bits > 64)
bits = 64;
// Zero sized integers are not usually valid. However, during semantic
// analysis when we're inferring types, the first pass may not have
// enough information to figure out the exact size of the integer. Later
// passes infer the exact size.
assert(bits == 0 || bits == 1 || bits == 8 || bits == 16 || bits == 32 ||
bits == 64);
size_bits_ = bits;
ajor marked this conversation as resolved.
Show resolved Hide resolved
}

size_t GetIntBitWidth() const
Expand Down
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ std::map<uintptr_t, elf_symbol, std::greater<>> get_symbol_table_for_elf(
};
struct bcc_symbol_option option;
memset(&option, 0, sizeof(option));
option.use_symbol_type = BCC_SYM_ALL_TYPES;
option.use_symbol_type = BCC_SYM_ALL_TYPES ^ (1 << STT_NOTYPE);
bcc_elf_foreach_sym(
elf_file.c_str(), sym_resolve_callback, &option, &symbol_table);

Expand Down
27 changes: 27 additions & 0 deletions tests/runtime/dwarf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ REQUIRES_FEATURE dwarf
TIMEOUT 5
BEFORE ./testprogs/uprobe_test

# NAME uprobe arg by index - 128-bits integer
# PROG uprobe:./testprogs/uprobe_test:uprobeFunctionUint128 { printf("x = %x\ny = %x\nz = %x\nw = %x\n", arg0, arg1, arg2, arg3); exit(); }
# EXPECT x = 9abcdef0
# y = efefefef
# z = cdcdcdcd
# w = abababab
# REQUIRES_FEATURE dwarf
# TIMEOUT 5
# BEFORE ./testprogs/uprobe_test

# NAME uprobe arg by name - 128-bits integer
# PROG uprobe:./testprogs/uprobe_test:uprobeFunctionUint128 { printf("x = %x\ny = %x\nz = %x\nw = %x\n", args.x, args.y, args.z, args.w); exit(); }
# EXPECT x = 9abcdef0
# y = efefefef
# z = cdcdcdcd
# w = abababab
# REQUIRES_FEATURE dwarf
# TIMEOUT 5
# BEFORE ./testprogs/uprobe_test

NAME uprobe arg by name - struct with 128-bits integer
PROG uprobe:./testprogs/uprobe_test:uprobeFunction2 { printf("foo1->d = %x\n", args.foo1->d); exit(); }
EXPECT foo1->d = 9abcdef0
REQUIRES_FEATURE dwarf
TIMEOUT 5
BEFORE ./testprogs/uprobe_test

NAME uprobe skip inlined function
PROG config = { probe_inline = 0 }
uprobe:./testprogs/inline_function:square { @count++ }
Expand Down
1 change: 1 addition & 0 deletions tests/runtime/engine/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def found_all_children(lines):
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
errors='backslashreplace',
env=env,
start_new_session=True,
universal_newlines=True,
Expand Down
2 changes: 1 addition & 1 deletion tests/runtime/other
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ AFTER ./testprogs/syscall nanosleep 1e8

NAME positional ustack
RUN {{BPFTRACE}} -e 'u:./testprogs/uprobe_loop:uprobeFunction1 { printf("%s\n%s\n", ustack(), ustack($1)); exit(); }' 1
EXPECT_REGEX .*uprobeFunction1\+[0-9]+\n\s+spin\+[0-9]+\n\s+main\+[0-9]+\n.*\n\n\n\s+uprobeFunction1\+[0-9]+
EXPECT_REGEX .*uprobeFunction1\+[0-9]+\n\s+spin\+[0-9]+\n\s+main\+[0-9]+\n(?s:.*)\n\n\n\s+uprobeFunction1\+[0-9]+
TIMEOUT 5
# Required to skip function prologue
REQUIRES_FEATURE dwarf
Expand Down
2 changes: 1 addition & 1 deletion tests/testprogs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(testprog_cflags "-g -O0")
set(testprog_cflags "-g -O0 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer")
if(LLVM_VERSION_MAJOR VERSION_LESS 13)
# CI's GCC compile the testprogs using DWARF version 5
# LLDB doesn't support DWARF5 before version 13, so we force DWARF4
Expand Down
23 changes: 21 additions & 2 deletions tests/testprogs/uprobe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
int a;
char b[10];
int c[3];
__int128_t d;
};

int uprobeFunction1(int *n, char c __attribute__((unused)))
Expand Down Expand Up @@ -50,6 +51,14 @@
*/
// clang-format on

__uint128_t uprobeFunctionUint128(__uint128_t x,
__uint128_t y __attribute__((unused)),
__uint128_t z __attribute__((unused)),
__uint128_t w)
{
return x + w;
}

int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
{
usleep(1000000);
Expand All @@ -58,9 +67,19 @@
char c = 'x';
uprobeFunction1(&n, c);

struct Foo foo1 = { .a = 123, .b = "hello", .c = { 1, 2, 3 } };
struct Foo foo2 = { .a = 456, .b = "world", .c = { 4, 5, 6 } };
struct Foo foo1 = {
.a = 123, .b = "hello", .c = { 1, 2, 3 }, .d = 0x123456789ABCDEF0
};
struct Foo foo2 = {
.a = 456, .b = "world", .c = { 4, 5, 6 }, .d = 0xFEDCBA9876543210
};
uprobeFunction2(&foo1, &foo2);

__uint128_t x = 0x123456789ABCDEF0;
__uint128_t y = 0xEFEFEFEFEFEFEFEF;
__uint128_t z = 0xCDCDCDCDCDCDCDCD;
__uint128_t w = 0xABABABABABABABAB;
uprobeFunctionUint128(x, y, z, w);

Check warning

Code scanning / CodeQL

Expression has no effect Warning test

This expression has no effect (because
uprobeFunctionUint128
has no external side effects).

return 0;
}
Loading