Skip to content

Commit ed41c19

Browse files
authored
Merge pull request #1037 from flit/bugfix/lgtm_fixes
Fix a number of problems identified by LGTM
2 parents 5f930b4 + f6d0300 commit ed41c19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+87
-98
lines changed

.lgtm.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
path_classifiers:
2+
docs:
3+
- scripts/generate_command_help.py
4+
test:
5+
# Mark all code under the src/ directory as test related.
6+
# Really, the crc analyzer is not for test, but LGTL can't build embedded.
7+
- src
8+
- exclude: src/analyzer
9+

pyocd/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,10 @@ def do_gdbserver(self):
774774
if core_number not in core_list:
775775
continue
776776
gdb = GDBServer(session, core=core_number)
777-
session.subscribe(self._gdbserver_listening_cb, GDBServer.GDBSERVER_START_LISTENING_EVENT, gdb)
777+
# Only subscribe to the server for the first core, so echo messages aren't printed
778+
# multiple times.
779+
if not gdbs:
780+
session.subscribe(self._gdbserver_listening_cb, GDBServer.GDBSERVER_START_LISTENING_EVENT, gdb)
778781
session.gdbservers[core_number] = gdb
779782
gdbs.append(gdb)
780783
gdb.start()

pyocd/cache/memory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from intervaltree import (Interval, IntervalTree)
1818
import logging
1919

20-
from ..core import exceptions
2120
from ..utility import conversion
2221
from .metrics import CacheMetrics
2322

pyocd/commands/commands.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from .. import coresight
2323
from ..core.helpers import ConnectHelper
24-
from ..core import (exceptions, session)
24+
from ..core import exceptions
2525
from ..probe.tcp_probe_server import DebugProbeServer
2626
from ..core.target import Target
2727
from ..flash.loader import FlashLoader
@@ -44,7 +44,6 @@
4444
msb,
4545
bfx,
4646
bfi,
47-
round_up_div,
4847
)
4948
from .base import CommandBase
5049

@@ -1028,7 +1027,6 @@ def parse(self, args):
10281027

10291028
def execute(self):
10301029
try:
1031-
type = self.context.selected_core.get_breakpoint_type(self.addr)
10321030
self.context.selected_core.remove_breakpoint(self.addr)
10331031
self.context.selected_core.bp_manager.flush()
10341032
self.context.writei("Removed breakpoint at 0x%08x", self.addr)
@@ -1158,7 +1156,6 @@ def execute(self):
11581156
if self.show_core:
11591157
self.context.writei("Core %d is selected", self.context.selected_core.core_number)
11601158
return
1161-
original_core_ap = core_ap = self.context.selected_core.ap
11621159
self.context.selected_core = self.context.session.target.cores[self.core_num]
11631160
core_ap = self.context.selected_core.ap
11641161
self.context.selected_ap_address = core_ap.address
@@ -1625,7 +1622,6 @@ def print_disasm(context, code, start_addr, max_instructions=None):
16251622
pc = -1
16261623
md = capstone.Cs(capstone.CS_ARCH_ARM, capstone.CS_MODE_THUMB)
16271624

1628-
addrLine = 0
16291625
text = ''
16301626
n = 0
16311627
for i in md.disasm(code, start_addr):

pyocd/commands/execution_context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ def parse_command(self, cmdline):
354354
", ".join("'%s'" % c for c in all_matches)))
355355
else:
356356
raise exceptions.CommandError("unrecognized command '%s'" % cmd)
357-
return
358357

359358
return CommandInvocation(matched_command, args, self.execute_command)
360359

pyocd/commands/repl.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import print_function
1818
import logging
1919
import os
20-
import sys
2120
import six
2221
import traceback
2322
import atexit

pyocd/commands/values.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717
import logging
1818
import prettytable
19-
import textwrap
2019

2120
from .. import coresight
22-
from ..core import (exceptions, session)
21+
from ..core import exceptions
2322
from ..probe.debug_probe import DebugProbe
2423
from ..coresight.ap import MEM_AP
2524
from ..core.target import Target
@@ -531,11 +530,9 @@ def display(self, args):
531530
def modify(self, args):
532531
if len(args) < 1:
533532
raise exceptions.CommandError("no log level provided")
534-
return 1
535533
level_name = args[0].lower()
536534
if level_name not in self.LEVELS:
537535
raise exceptions.CommandError("log level must be one of {%s}" % ','.join(self.LEVELS.keys()))
538-
return 1
539536
level = self.LEVELS[level_name]
540537
if len(args) == 1:
541538
logging.getLogger().setLevel(level)
@@ -571,12 +568,10 @@ def display(self, args):
571568
def modify(self, args):
572569
if len(args) < 1:
573570
raise exceptions.CommandError("no clock frequency provided")
574-
return 1
575571
try:
576572
freq_Hz = convert_frequency(args[0])
577573
except:
578574
raise exceptions.CommandError("invalid frequency")
579-
return 1
580575
self.context.probe.set_clock(freq_Hz)
581576
if self.context.probe.wire_protocol == DebugProbe.Protocol.SWD:
582577
swd_jtag = 'SWD'

pyocd/core/memory_map.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ def __copy__(self):
249249
**self._attributes
250250
)
251251

252-
def __hash__(self):
253-
# Need to redefine __hash__ since we redefine __eq__.
254-
return super(MemoryRegion, self).__hash__()
252+
# Need to redefine __hash__ since we redefine __eq__.
253+
__hash__ = MemoryRangeBase.__hash__
255254

256255
def __eq__(self, other):
257256
# Include type and attributes in equality comparison.
@@ -411,6 +410,14 @@ def __copy__(self):
411410
clone._flm = self._flm
412411
return clone
413412

413+
# Need to redefine __hash__ since we redefine __eq__.
414+
__hash__ = MemoryRegion.__hash__
415+
416+
def __eq__(self, other):
417+
# Include flash algo, class, and flm in equality test.
418+
return super(FlashRegion, self).__eq__(other) and self.algo == other.algo and \
419+
self.flash_class == other.flash_class and self.flm == other.flm
420+
414421
def __repr__(self):
415422
return "<%s@0x%x name=%s type=%s start=0x%x end=0x%x length=0x%x access=%s blocksize=0x%x>" % (self.__class__.__name__, id(self), self.name, self.type, self.start, self.end, self.length, self.access, self.blocksize)
416423

pyocd/core/options_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pyOCD debugger
2-
# Copyright (c) 2019 Arm Limited
2+
# Copyright (c) 2019-2020 Arm Limited
33
# SPDX-License-Identifier: Apache-2.0
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -116,8 +116,7 @@ def is_set(self, key):
116116
for layer in self._layers:
117117
if key in layer:
118118
return True
119-
else:
120-
return False
119+
return False
121120

122121
def get_default(self, key):
123122
"""! @brief Return the default value for the specified option."""

pyocd/core/soc_target.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
# limitations under the License.
1616

1717
import logging
18-
import six
1918

2019
from .target import Target
21-
from .memory_map import MemoryType
22-
from . import exceptions
2320
from ..flash.eraser import FlashEraser
2421
from ..debug.cache import CachingDebugContext
2522
from ..debug.elf.elf import ELFBinaryFile

0 commit comments

Comments
 (0)