Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

change CLI around --force-backtrace and --max-backtrace-len #198

Closed
japaric opened this issue May 12, 2021 · 10 comments · Fixed by #250
Closed

change CLI around --force-backtrace and --max-backtrace-len #198

japaric opened this issue May 12, 2021 · 10 comments · Fixed by #250
Assignees
Labels
breaking change fix / feature / improvement involves a breaking change and needs to wait until next minor version difficulty: easy Pretty easy to solve priority: low Low priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes topic: backtrace type: enhancement Enhancement or feature request
Milestone

Comments

@japaric
Copy link
Member

japaric commented May 12, 2021

We are going to change the CLI around --force-backtrace and --max-backtrace-len. The accepted proposal is #198 (comment) . This is only waiting on a PR to implement that proposal.


Original ticket:

(this is technically a breaking change so it should wait until v0.3.0)

--max-backtrace-len=0 is currently allowed. While working on PR #197 it wasn't clear to me what the semantics of --force-backtrace --max-backtrace-len=0 should be but I made --max-backtrace-len=0 never print a backtrace regardless of other flags and the presence of stack overflows or exceptions.

IMO, it'd be better to reject --max-backtrace-len=0 and only accepts lengths equal or greater than 1; that avoids the above ambiguity.

cc @Lotterleben

@japaric japaric added type: enhancement Enhancement or feature request topic: backtrace breaking change fix / feature / improvement involves a breaking change and needs to wait until next minor version labels May 12, 2021
@Urhengulas Urhengulas added this to Incoming in Issue Triage via automation May 12, 2021
@Urhengulas Urhengulas added difficulty: easy Pretty easy to solve priority: low Low priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes labels May 12, 2021
@Urhengulas Urhengulas moved this from Incoming to Triaged in Issue Triage May 12, 2021
@Lotterleben
Copy link

makes sense. I'm wondering, is there a case where one might not want any backtraces ever?

@japaric
Copy link
Member Author

japaric commented May 20, 2021

I'm wondering, is there a case where one might not want any backtraces ever?

we also print the backtrace to stdout, right? perhaps if you want to grep for something in the logs but not in the backtrace then it may be useful to completely disable the backtrace. this use case would be best served by the proposed JSON output (#178), IMO

@jonas-schievink
Copy link
Contributor

IMO it makes sense to reject --force-backtrace --max-backtrace-len=0, but I don't think --max-backtrace-len=0 by itself should be rejected. I would expect it to just turn off the backtrace (either completely, with no output referring to the backtrace, or in a way that just prints a backtrace with 0 frames).

@japaric japaric added this to the v0.3.0 milestone Jun 23, 2021
@japaric
Copy link
Member Author

japaric commented Jul 7, 2021

but I don't think --max-backtrace-len=0 by itself should be rejected. I would expect it to just turn off the backtrace

that sounds like 'some way to disable the backtrace' is a desirable thing.

perhaps we can harmonize this to work like Cargo's --color flag? --backtrace={auto,always,never}. auto is the current, default behavior (e.g. backtrace on panic, but not on exit). always is --force-backtrace (which is no longer needed with this scheme). never disables the backtrace completely.

THEN --max-backtrace-len can be limited to be greater than 1 and shall only be used with --backtrace={auto,always}. e.g. --max-backtrace-len=10 --backtrace=never would be an error.

OR we don't restrict mixing --max-backtrace-len and --backtrace=never (i.e. that's not an error) but simply ignore the --max-backtrace-len flag in that case.


Also, I'd like the default to be "no limit on backtrace length" (e.g. if the backtrace is the result of a hard to reproduce condition then you want all the info you can get your hands on; not just some arbitrary number of frames). Right now, the backtrace is limited to 50 frames and there's no good way to undo it -- I mean you can use --max-backtrace-len=999 or something like that but that looks a bit ridiculous.

We could make the default be 'the number of backtrace frames is not limited' OR we could make --max-backtrace-len=0 mean 'do not limit the backtrace size' and keep the max-backtrace-len default of 50 frames. I'd prefer the former option.

@jonas-schievink
Copy link
Contributor

We could also rename it to --backtrace-limit, and have 0 mean "unlimited", I believe that's what some tools do

@japaric
Copy link
Member Author

japaric commented Jul 29, 2021

OK, let me more concretely propose this:

  • --force-backtrace is removed
  • --backtrace-len is renamed to --backtrace-limit
  • --backtrace is added

The interaction between these flags is specified in the table below:

--backtrace= --backtrace-limit=N Backtrace is printed
never is ignored never
auto has an effect if program panics or stack overflows
always has an effect always

Additionally,

  • --backtrace flag is optional and defaults to auto
  • --backtrace-limit flag is optional and defaults to 50 (+)
  • --backtrace-limit=0 is accepted and means "no limit"

(+) rationale on setting a default limit: bugs in debug info (DWARF) generation can result in infinite backtraces that even the mature GDB can't handle / detect #127 (comment) so err on the side of caution and set a limit to avoid spamming frames to the console in presence of these bugs.

@jonas-schievink , @Lotterleben can I get a 'sounds good to me' / 'I have a concern' reaction on the above proposal as a comment -- I don't get notified about emoji reactions to comments so that would be easy to miss.

Changelog

  • 2021-08-02 changed default --backtrace-limit to 50.

@japaric japaric added status: needs decision and removed status: needs PR Issue just needs a Pull Request implementing the changes labels Jul 29, 2021
@jonas-schievink
Copy link
Contributor

an infinite backtrace is a bug in probe-run and it should be promptly fixed, instead of being papered over with an artificial --limit

I agree in principle, but we've seen programs that even resulted in an infinite backtrace in GDB, so I don't think this is realistic (#127 (comment)).

Everything else sounds good to me though!

@japaric
Copy link
Member Author

japaric commented Jul 29, 2021

Fair, I can compromise on keeping the 50 frames limit.

@Lotterleben
Copy link

Lotterleben commented Jul 29, 2021

+1 to what Jonas says. We also picked the 50 line limit quite arbitrarily, so I'd be OK with increasing it.

@japaric
Copy link
Member Author

japaric commented Aug 2, 2021

OK. That's two approvals. I'll amend my proposal; link it from the issue description as accepted and change this ticket status to 'needs PR'

@japaric japaric added status: needs PR Issue just needs a Pull Request implementing the changes and removed status: needs decision labels Aug 2, 2021
@japaric japaric changed the title [RFC] turn --max-backtrace-len=0 into a CLI parsing error change CLI around --force-backtrace and --max-backtrace-len Aug 2, 2021
@BriocheBerlin BriocheBerlin self-assigned this Aug 5, 2021
@bors bors bot closed this as completed in f889cbc Sep 2, 2021
Issue Triage automation moved this from Triaged to Closed Sep 2, 2021
bors bot added a commit to knurling-rs/defmt that referenced this issue Oct 19, 2021
547: Migration guide `v0.2.x` to `v0.3.0` r=japaric a=Urhengulas

Migration guide from `defmt v0.2.x` to version `v0.3.0`.

https://deploy-preview-547--admiring-dubinsky-56dff5.netlify.app/migration-02-03.html

Fixes #530.

### TODO
- [x] #505: Logger trait v2
- [x] #521: [3/n] Remove u24
- [x] #522: Replace `µs` hint with `us`
- [x] (no adaption needed) ~~#508: [5/n] Format trait v2~~
- [x] #519: `DEFMT_LOG`
- [x] #550: `defmt::flush()`
- [x] knurling-rs/probe-run#198, knurling-rs/probe-run#250, 

Co-authored-by: Johann Hemmann <johann.hemmann@code.berlin>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking change fix / feature / improvement involves a breaking change and needs to wait until next minor version difficulty: easy Pretty easy to solve priority: low Low priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes topic: backtrace type: enhancement Enhancement or feature request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

5 participants