Skip to content
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
14 changes: 8 additions & 6 deletions sdb/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ def call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
yield from self.__invalid_memory_objects_check(
result, not issubclass(self.__class__, SingleInputCommand))
except drgn.FaultError as err:
raise CommandError(self.name, f"invalid memory access: {str(err)}")
raise CommandError(self.name,
f"invalid memory access: {str(err)}") from err


class SingleInputCommand(Command):
Expand Down Expand Up @@ -409,15 +410,16 @@ def __init__(self,
tname = " ".join(self.args.type)
try:
self.type = target.get_type(tname)
except LookupError:
raise CommandError(self.name, f"could not find type '{tname}'")
except LookupError as err:
raise CommandError(self.name,
f"could not find type '{tname}'") from err

def _call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
for obj in objs:
try:
yield drgn.cast(self.type, obj)
except TypeError as err:
raise CommandError(self.name, str(err))
raise CommandError(self.name, str(err)) from err


class Dereference(Command):
Expand Down Expand Up @@ -546,8 +548,8 @@ def _call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
for symbol in self.args.symbols:
try:
yield Address.resolve_for_address(symbol)
except KeyError:
raise SymbolNotFoundError(self.name, symbol)
except KeyError as err:
raise SymbolNotFoundError(self.name, symbol) from err


class Walk(Command):
Expand Down
4 changes: 2 additions & 2 deletions sdb/commands/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def _call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
for addr in self.args.addrs:
try:
value_ = int(addr, 0)
except ValueError:
raise sdb.CommandInvalidInputError(self.name, addr)
except ValueError as err:
raise sdb.CommandInvalidInputError(self.name, addr) from err
yield sdb.create_object("void *", value_)
4 changes: 2 additions & 2 deletions sdb/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def _call(self, objs: Iterable[drgn.Object]) -> None:
if self.args.cmd is not None:
try:
all_cmds[self.args.cmd].help(self.args.cmd)
except KeyError:
raise sdb.error.CommandNotFoundError(self.args.cmd)
except KeyError as err:
raise sdb.error.CommandNotFoundError(self.args.cmd) from err
else:
cmds: Dict[str, Type[sdb.Command]] = {}
for k, v in all_cmds.items():
Expand Down
7 changes: 0 additions & 7 deletions sdb/commands/internal/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ class Table:

__slots__ = "fields", "rjustfields", "formatters", "maxfieldlen", "lines"

#
# The "yapf" tool expects 4 spaces for the continuation lines here,
# where "pylint" expects 8 spaces. To reconcile the difference in
# expectations of both tools, we disable the pylint error, and
# adhere to the yapf format.
#
# pylint: disable=bad-continuation
def __init__(
self,
fields: List[str],
Expand Down
5 changes: 3 additions & 2 deletions sdb/commands/linux/per_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class LxPerCpuCounterSum(sdb.SingleInputCommand):
def _call_one(self, obj: drgn.Object) -> Iterable[drgn.Object]:
try:
sum_ = drgn_percpu.percpu_counter_sum(obj)
except AttributeError:
raise sdb.CommandError(self.name, "input is not a percpu_counter")
except AttributeError as err:
raise sdb.CommandError(self.name,
"input is not a percpu_counter") from err
yield drgn.Object(sdb.get_prog(), type="s64", value=sum_)
8 changes: 4 additions & 4 deletions sdb/commands/stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,10 @@ def validate_args(self) -> None:
#
func = sdb.get_object(self.args.function)
sym = sdb.get_symbol(func.address_of_())
except KeyError:
except KeyError as err:
raise sdb.CommandError(
self.name, f"symbol '{self.args.function}' does not exist")
self.name,
f"symbol '{self.args.function}' does not exist") from err
if func.type_.kind != drgn.TypeKind.FUNCTION:
raise sdb.CommandError(
self.name, f"'{self.args.function}' is not a function")
Expand Down Expand Up @@ -356,10 +357,9 @@ def print_header(self) -> None:
# task state and program counters. Return a collection sorted by number
# of tasks per stack.
#
# Note: we disabled pyline C0330 due to https://github.com/PyCQA/pylint/issues/289
@staticmethod
def aggregate_stacks(
objs: Iterable[drgn.Object] # pylint: disable=C0330
objs: Iterable[drgn.Object]
) -> List[Tuple[Tuple[str, Tuple[int, ...]], List[drgn.Object]]]:
stack_aggr: Dict[Tuple[str, Tuple[int, ...]],
List[drgn.Object]] = defaultdict(list)
Expand Down
4 changes: 2 additions & 2 deletions sdb/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def invoke(myprog: drgn.Program, first_input: Iterable[drgn.Object],
raise CommandNotFoundError(name)
try:
pipeline.append(get_registered_commands()[name](args, name))
except SystemExit:
except SystemExit as cmd_exit:
#
# The passed in arguments to each command will be parsed in
# the command object's constructor. We use "argparse" to do
Expand All @@ -116,7 +116,7 @@ def invoke(myprog: drgn.Program, first_input: Iterable[drgn.Object],
# SDB session, we only abort this specific pipeline by raising
# a CommandArgumentsError.
#
raise CommandArgumentsError(name)
raise CommandArgumentsError(name) from cmd_exit
else:
assert cmd_type == parser.ExpressionType.SHELL_CMD
shell_cmd = cmd
Expand Down
5 changes: 3 additions & 2 deletions sdb/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ def type_canonicalize(t: drgn.Type) -> drgn.Type:

Note: function type's arguments and return types are not canonicalized.
"""
global prog
if t.kind == drgn.TypeKind.TYPEDEF:
return type_canonicalize(t.type)
if t.kind == drgn.TypeKind.POINTER:
return drgn.pointer_type(t.size, type_canonicalize(t.type))
return prog.pointer_type(type_canonicalize(t.type), t.size)
if t.kind == drgn.TypeKind.ARRAY:
return drgn.array_type(t.length, type_canonicalize(t.type))
return prog.array_type(type_canonicalize(t.type), t.length)
return t.unqualified()


Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_core_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=not-callable

from typing import Any

Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_linux_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=line-too-long
# pylint: disable=not-callable

from typing import Any

Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_spl_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=line-too-long
# pylint: disable=not-callable

from typing import Any

Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_zfs_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=line-too-long
# pylint: disable=not-callable

from typing import Any

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import sdb


def create_struct_type(name: str, member_names: List[str],
def create_struct_type(prog: drgn.Program, name: str, member_names: List[str],
member_types: List[drgn.Type]) -> drgn.Type:
"""
Creates a structure type given a list of member names and
a list of types like this:
```
create_struct_type(<name>, [<name_a>, <name_b> ...],
create_struct_type(<prog>, <name>, [<name_a>, <name_b> ...],
[<type_a>, <type_b>, ...])
```
returns a C structure:
Expand All @@ -52,7 +52,7 @@ def create_struct_type(name: str, member_names: List[str],
else:
bit_offset += 8 * type_.size
struct_size += type_.size
return drgn.struct_type(name, struct_size, member_list)
return prog.struct_type(name, struct_size, member_list)


def setup_basic_mock_program() -> drgn.Program:
Expand Down Expand Up @@ -97,13 +97,13 @@ def mock_type_find(kind: drgn.TypeKind, name: str,
# More complex types are added to the mocked_types table in
# an ad-hoc way here.
#
struct_type = create_struct_type('test_struct',
struct_type = create_struct_type(prog, 'test_struct',
['ts_int', 'ts_voidp', 'ts_array'],
[int_type, voidp_type, int_array_type])
mocked_types['test_struct'] = struct_type
structp_type = prog.type('struct test_struct *')
complex_struct_type = create_struct_type(
'complex_struct', ['cs_structp', 'cs_struct', 'cs_structp_null'],
prog, 'complex_struct', ['cs_structp', 'cs_struct', 'cs_structp_null'],
[structp_type, struct_type, structp_type])
mocked_types['complex_struct'] = complex_struct_type

Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#

# pylint: disable=missing-docstring
# pylint: disable=not-callable

from typing import List, Tuple

Expand Down