Skip to content

Commit

Permalink
subcommands: disable debug.traceback option by default, unless debug …
Browse files Browse the repository at this point in the history
…logging is enabled (#1546)
  • Loading branch information
flit authored May 3, 2023
1 parent 1589e25 commit d3965a4
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
6 changes: 4 additions & 2 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ Log details of loaded .FLM flash algos.

<tr><td>debug.traceback</td>
<td>bool</td>
<td>True</td>
<td>False</td>
<td>
Print tracebacks for exceptions.
Print tracebacks for exceptions, including errors that are only logged as well as critical errors that cause pyocd to terminate.

Disabled by default, unless the log level is raised to Debug.
</td></tr>

<tr><td>enable_multicore_debug</td>
Expand Down
9 changes: 5 additions & 4 deletions pyocd/commands/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ def connect(self) -> bool:
connect_mode=connect_mode,
frequency=self.args.frequency,
options=options,
option_defaults=dict(
auto_unlock=False,
resume_on_disconnect=False,
)
option_defaults={
'auto_unlock': False,
'resume_on_disconnect': False,
'debug.traceback': logging.getLogger('pyocd').isEnabledFor(logging.DEBUG),
}
)

if not self._post_connect():
Expand Down
2 changes: 1 addition & 1 deletion pyocd/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class OptionInfo(NamedTuple):
"When switching between SWD and JTAG, use the SWJ sequence from ADIv5.2 that utilizes a new dormant state."),
OptionInfo('debug.log_flm_info', bool, False,
"Log details of loaded .FLM flash algos."),
OptionInfo('debug.traceback', bool, True,
OptionInfo('debug.traceback', bool, False,
"Print tracebacks for exceptions."),
OptionInfo('enable_multicore_debug', bool, False,
"Whether to put pyOCD into multicore debug mode. Doing so changes the default software reset type of "
Expand Down
17 changes: 15 additions & 2 deletions pyocd/subcommands/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pyOCD debugger
# Copyright (c) 2021 Chris Reed
# Copyright (c) 2021-2023 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +17,7 @@
import argparse
import logging
import prettytable
from typing import (List, Optional, Type)
from typing import (Any, Dict, List, Optional, Type)

from ..utility.cmdline import convert_frequency

Expand Down Expand Up @@ -169,4 +169,17 @@ def _get_pretty_table(self, fields: List[str], header: bool = None) -> prettytab
pt.vrules = prettytable.NONE
return pt

def _modified_option_defaults(self) -> Dict[str, Any]:
"""@brief Returns a dict of session option defaults.
@return A dict containing updated default values for session options, based on common
subcommand arguments. It is intended to be passed as the `option_defaults` argument when
creating a `Session` instance.
@precondition Logging must have been configured.
"""
return {
# Change 'debug.traceback' default to True if debug logging is enabled.
'debug.traceback': logging.getLogger('pyocd').isEnabledFor(logging.DEBUG),
}


4 changes: 3 additions & 1 deletion pyocd/subcommands/erase_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def invoke(self) -> int:
frequency=self._args.frequency,
blocking=(not self._args.no_wait),
connect_mode=self._args.connect_mode,
options=convert_session_options(self._args.options))
options=convert_session_options(self._args.options),
option_defaults=self._modified_option_defaults(),
)
if session is None:
LOG.error("No device available to erase")
return 1
Expand Down
4 changes: 3 additions & 1 deletion pyocd/subcommands/gdbserver_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def invoke(self) -> int:
target_override=self._args.target_override,
frequency=self._args.frequency,
connect_mode=self._args.connect_mode,
options=sessionOptions)
options=sessionOptions,
option_defaults=self._modified_option_defaults(),
)
if session is None:
LOG.error("No probe selected.")
return 1
Expand Down
4 changes: 3 additions & 1 deletion pyocd/subcommands/load_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def invoke(self) -> int:
frequency=self._args.frequency,
blocking=(not self._args.no_wait),
connect_mode=self._args.connect_mode,
options=convert_session_options(self._args.options))
options=convert_session_options(self._args.options),
option_defaults=self._modified_option_defaults(),
)
if session is None:
LOG.error("No target device available")
return 1
Expand Down
4 changes: 3 additions & 1 deletion pyocd/subcommands/reset_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def invoke(self) -> None:
connect_mode=self._args.connect_mode,
resume_on_disconnect=not self._args.halt,
reset_type=self._args.reset_type,
options=convert_session_options(self._args.options))
options=convert_session_options(self._args.options),
option_defaults=self._modified_option_defaults(),
)
if session is None:
LOG.error("No target device available to reset")
sys.exit(1)
Expand Down
4 changes: 3 additions & 1 deletion pyocd/subcommands/rtt_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def invoke(self) -> int:
frequency=self._args.frequency,
blocking=(not self._args.no_wait),
connect_mode=self._args.connect_mode,
options=convert_session_options(self._args.options))
options=convert_session_options(self._args.options),
option_defaults=self._modified_option_defaults(),
)

if session is None:
LOG.error("No target device available")
Expand Down

0 comments on commit d3965a4

Please sign in to comment.