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

printf() only supports 7 arguments #1336

Closed
danobi opened this issue May 15, 2020 · 3 comments · Fixed by #1404
Closed

printf() only supports 7 arguments #1336

danobi opened this issue May 15, 2020 · 3 comments · Fixed by #1404
Labels
enhancement New feature or request, changes on existing features

Comments

@danobi
Copy link
Member

danobi commented May 15, 2020

Is your feature request related to a problem? Please describe.

It would be useful to have support for more arguments. I don't think there's a technical limit.

Describe the solution you'd like

More args

Describe alternative solutions or features you've considered

n/a

@danobi danobi added the enhancement New feature or request, changes on existing features label May 15, 2020
@danobi
Copy link
Member Author

danobi commented May 26, 2020

One way I thought of to support arbitrary number of arguments is to:

  • use a format string regex (see bpftrace::verify_format_string) to capture and pull out all format string tokens
  • format each token one by one in scratch buffer
  • add formatted string to accumulator, being careful to truncate if accumulated length goes past max size
  • add interposed text (ie not format string token) as appropriate, still being careful to truncate

The reason we can't do it all in one shot is b/c *printf family of functions need a fixed # of args known at compile time (b/c of the va_args) stuff. Same thing w/ c++ parameter packs and if we wanted to use fmt (https://fmt.dev/latest/api.html#printf-formatting) + parameter packs

@Birch-san
Copy link
Contributor

*printf family of functions need a fixed # of args known at compile time

Can we use *vprintf instead?

@danobi
Copy link
Member Author

danobi commented Jun 22, 2020

Can we use *vprintf instead?

I looked into this but there's no way to safely construct a va_list struct (according to the internet)

@fbs fbs added the has PR label Jul 2, 2020
suyuee added a commit to suyuee/bpftrace that referenced this issue Jul 8, 2020
This enables printf, cat and system to have more than 7 arguments. It can be
more user-friendly to allow any reasonable number of arguments for these builtin
calls which use formatted strings. Resolves bpftrace#1336.
danobi pushed a commit that referenced this issue Jul 8, 2020
This enables printf, cat and system to have more than 7 arguments. It can be
more user-friendly to allow any reasonable number of arguments for these builtin
calls which use formatted strings. Resolves #1336.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request, changes on existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants