Commit 7525949a authored by Alex Birch's avatar Alex Birch

implement review feedback: avoid copying strings, prefer make_unique, use...

implement review feedback: avoid copying strings, prefer make_unique, use standard naming convention for private members
parent 74f2b9e4
...@@ -355,52 +355,87 @@ std::vector<std::unique_ptr<IPrintable>> BPFtrace::get_arg_values(std::vector<Fi ...@@ -355,52 +355,87 @@ std::vector<std::unique_ptr<IPrintable>> BPFtrace::get_arg_values(std::vector<Fi
switch (arg.type.size) switch (arg.type.size)
{ {
case 8: case 8:
arg_values.emplace_back(new PrintableInt(*(uint64_t*)(arg_data+arg.offset))); arg_values.push_back(
std::make_unique<PrintableInt>(
*(uint64_t*)(arg_data+arg.offset)));
break; break;
case 4: case 4:
arg_values.emplace_back(new PrintableInt(*(uint32_t*)(arg_data+arg.offset))); arg_values.push_back(
std::make_unique<PrintableInt>(
*(uint32_t*)(arg_data+arg.offset)));
break; break;
case 2: case 2:
arg_values.emplace_back(new PrintableInt(*(uint16_t*)(arg_data+arg.offset))); arg_values.push_back(
std::make_unique<PrintableInt>(
*(uint16_t*)(arg_data+arg.offset)));
break; break;
case 1: case 1:
arg_values.emplace_back(new PrintableInt(*(uint8_t*)(arg_data+arg.offset))); arg_values.push_back(
std::make_unique<PrintableInt>(
*(uint8_t*)(arg_data+arg.offset)));
break; break;
default: default:
abort(); abort();
} }
break; break;
case Type::string: case Type::string:
arg_values.emplace_back(new PrintableString( arg_values.push_back(
std::string((char *) arg_data+arg.offset))); std::make_unique<PrintableCString>(
(char *) arg_data+arg.offset));
break; break;
case Type::sym: case Type::sym:
arg_values.emplace_back(new PrintableString( arg_values.push_back(
resolve_sym(*(uint64_t*)(arg_data+arg.offset)).c_str())); std::make_unique<PrintableString>(
std::move(
resolve_sym(*(uint64_t*)(arg_data+arg.offset)))));
break; break;
case Type::usym: case Type::usym:
arg_values.emplace_back(new PrintableString( arg_values.push_back(
resolve_usym(*(uint64_t*)(arg_data+arg.offset), *(uint64_t*)(arg_data+arg.offset + 8)).c_str())); std::make_unique<PrintableString>(
std::move(
resolve_usym(
*(uint64_t*)(arg_data+arg.offset),
*(uint64_t*)(arg_data+arg.offset + 8)))));
break; break;
case Type::inet: case Type::inet:
name = strdup(resolve_inet(*(uint64_t*)(arg_data+arg.offset), *(uint64_t*)(arg_data+arg.offset+8)).c_str()); arg_values.push_back(
arg_values.push_back((uint64_t)name); std::make_unique<PrintableString>(
std::move(
resolve_inet(
*(uint64_t*)(arg_data+arg.offset),
*(uint64_t*)(arg_data+arg.offset+8)))));
break; break;
case Type::username: case Type::username:
arg_values.emplace_back(new PrintableString( arg_values.push_back(
resolve_uid(*(uint64_t*)(arg_data+arg.offset)).c_str())); std::make_unique<PrintableString>(
std::move(
resolve_uid(
*(uint64_t*)(arg_data+arg.offset)))));
break; break;
case Type::probe: case Type::probe:
arg_values.emplace_back(new PrintableString( arg_values.push_back(
resolve_probe(*(uint64_t*)(arg_data+arg.offset)).c_str())); std::make_unique<PrintableString>(
std::move(
resolve_probe(
*(uint64_t*)(arg_data+arg.offset)))));
break; break;
case Type::stack: case Type::stack:
arg_values.emplace_back(new PrintableString( arg_values.push_back(
get_stack(*(uint64_t*)(arg_data+arg.offset), false, 8).c_str())); std::make_unique<PrintableString>(
std::move(
get_stack(
*(uint64_t*)(arg_data+arg.offset),
false,
8))));
break; break;
case Type::ustack: case Type::ustack:
arg_values.emplace_back(new PrintableString( arg_values.push_back(
get_stack(*(uint64_t*)(arg_data+arg.offset), true, 8).c_str())); std::make_unique<PrintableString>(
std::move(
get_stack(
*(uint64_t*)(arg_data+arg.offset),
true,
8))));
break; break;
default: default:
abort(); abort();
......
...@@ -66,12 +66,17 @@ std::string verify_format_string(const std::string &fmt, std::vector<Field> args ...@@ -66,12 +66,17 @@ std::string verify_format_string(const std::string &fmt, std::vector<Field> args
uint64_t PrintableString::value() uint64_t PrintableString::value()
{ {
return (uint64_t)_value.c_str(); return (uint64_t)value_.c_str();
}
uint64_t PrintableCString::value()
{
return (uint64_t)value_;
} }
uint64_t PrintableInt::value() uint64_t PrintableInt::value()
{ {
return _value; return value_;
} }
} // namespace bpftrace } // namespace bpftrace
...@@ -21,19 +21,28 @@ public: ...@@ -21,19 +21,28 @@ public:
class PrintableString : public virtual IPrintable class PrintableString : public virtual IPrintable
{ {
public: public:
PrintableString(std::string value) : _value(value) { } PrintableString(std::string value) : value_(value) { }
uint64_t value(); uint64_t value();
private: private:
std::string _value; std::string value_;
};
class PrintableCString : public virtual IPrintable
{
public:
PrintableCString(char* value) : value_(value) { }
uint64_t value();
private:
char* value_;
}; };
class PrintableInt : public virtual IPrintable class PrintableInt : public virtual IPrintable
{ {
public: public:
PrintableInt(uint64_t value) : _value(value) { } PrintableInt(uint64_t value) : value_(value) { }
uint64_t value(); uint64_t value();
private: private:
uint64_t _value; uint64_t value_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment